Stdin support
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user