recherche du pbm dans heredoc

This commit is contained in:
hugogogo
2021-12-05 14:16:11 +01:00
parent 0171de26e9
commit 10a8ecaae8
6 changed files with 20 additions and 54 deletions

View File

@@ -4,40 +4,38 @@
#include <string.h>
#include <readline/readline.h>
#define CYAN "\001\e[1;36m\002"
#define WHITE "\001\e[1;37m\002"
#define RESET "\001\e[0m\002"
int main(void)
{
char *prompt;
char *line_input;
char *heredoc;
char *delimiter;
char *here_line;
//prompt = WHITE"mybash a very long prompt to test the output in case of a redirection in a file> "RESET;
prompt = WHITE"mybash> "RESET;
line_input = NULL;
while (1)
{
if (line_input)
free(line_input);
line_input = readline(prompt);
line_input = readline(WHITE"mybash> "RESET);
if (line_input)
{
if (!strncmp(line_input, "echo ", 5))
heredoc = strstr(line_input, " << ");
if (heredoc)
{
write(1, line_input + 5, strlen(line_input) - 5);
write(1, "\n", 1);
delimiter = heredoc + strlen(" << ");
while(1)
{
here_line = NULL;
here_line = readline(CYAN"> "RESET);
if (!strncmp(here_line, delimiter, strlen(here_line) + 1))
break ;
}
}
}
if (!line_input)
{
write(2, "exit\n", 5);
exit(0);
}
}
/*
prompt = WHITE"mybash a very long prompt to test the output in case of a redirection in a file, style longer than that even> "RESET;
write(1, prompt, strlen(prompt));
write(1, "\n", 1);
*/
return (0);
}