Stdin support

This commit is contained in:
2025-01-25 14:19:01 +01:00
parent d0697da15e
commit c0f5be662a
2 changed files with 42 additions and 14 deletions
+23 -7
View File
@@ -38,17 +38,33 @@
#include <string.h>
#include <unistd.h>
char * get_prompt_from_stdin() {
char * prompt = malloc(1024 * 1024 * 10 + 1);
prompt[0] = 0;
int index = 0;
char c = 0;
while ((c = getchar()) != EOF) {
prompt[index++] = c;
}
prompt[index++] = 0;
return prompt;
}
char *get_prompt_from_args(int c, char **argv) {
char *prompt = malloc(1024 * 1024 + 1);
prompt[0] = 0;
for (int i = 1; i < c; i++) {
if (argv[i][0] == '-')
if (!strcmp(argv[i],"--stdin")){
free(prompt);
prompt = get_prompt_from_stdin();
break;
strncat(prompt, argv[i], 1024 * 1024);
if (i < c - 1) {
strncat(prompt, " ", 1024 * 1024);
} else {
strncat(prompt, ".", 1024 * 1024);
}else{
strncat(prompt, argv[i], 1024 * 1024);
if (i < c - 1) {
strncat(prompt, " ", 1024 * 1024);
} else {
strncat(prompt, ".", 1024 * 1024);
}
}
}
if (!*prompt) {
@@ -211,4 +227,4 @@ int main(int argc, char *argv[]) {
repl();
return 0;
}
}