I think that using the GNU Readline library for a command-line prompt is good and I want that functionality for my shell that I'm working on. Now readline works for me (my environment is CLion, CMake, Ubuntu, BSD, C, flex-lexer and lemon-parser) but I also need flex and yacc to work at the same time to scan and parse the input but the codes seem "incompatible" - are they really?
params[0] = NULL;
printf("> ");
i=1;
do {
lexCode = yylex(scanner);
/* snprintf(shell_prompt, sizeof(shell_prompt), "%s:%s $ ", getenv("USER"), getcwd(NULL, 1024));
Display prompt and read input (NB: input must be freed after use)...*/
text = strdup(yyget_text(scanner));
/*
input = readline(text);
if (!input)
break;
add_history(input);
free(input);*/
printf("lexcode %i Text %s\n", lexCode, text);
if (lexCode == 4) {
params[i++] = mystring;
if (strcmp(text, "\'\0")) {
params[i++] = mystring;
}
} else
if (lexCode != EOL) {
params[i++] = text;
printf("B%s\n", text);
}
Parse(shellParser, lexCode, text);
if (lexCode == EOL) {
dump_argv("Before exec_arguments", i, params);
exec_arguments(i, params);
corpse_collector();
Parse(shellParser, 0, NULL);
i=1;
}
} while (lexCode > 0);
if (-1 == lexCode) {
fprintf(stderr, "The scanner encountered an error.\n");
}
The above code has the parsing and scanning working and commented out the readline functionality that won't work if I want both at the same time. Can I make it work?