dish/loop.c

43 lines
830 B
C
Raw Normal View History

2022-09-18 06:46:23 +00:00
/*
* @Author: 1ridic
* @Date: 2022-09-18 14:13:53
* @Last Modified by: 1ridic
* @Last Modified time: 2022-09-20 22:26:59
2022-09-18 06:46:23 +00:00
*/
2022-09-18 05:14:30 +00:00
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
2022-09-18 05:14:30 +00:00
#include <stdlib.h>
#include <string.h>
#include "loop.h"
#include "exec.h"
#include "line.h"
int status;
2022-09-18 05:14:30 +00:00
void SIGINT_Handler(int dummy) {
#ifdef DEBUG
fprintf(stdout,"\ndebug: SIGINT\n");
#endif
/* Move to a new line */
fprintf(stdout,"\n");
/* Regenerate the prompt on a newline */
rl_on_new_line();
/* Clear the previous text */
rl_replace_line("", 0);
rl_redisplay();
return;
}
2022-09-18 05:14:30 +00:00
int loop() {
2022-09-18 05:14:30 +00:00
char *line;
char **args;
line = readline(ANSI_COLOR_GREEN"> "ANSI_COLOR_RESET);
add_history(line);
2022-09-18 05:14:30 +00:00
args = splitLine(line);
status = commandExec(args);
2022-09-18 05:14:30 +00:00
free(line);
free(args);
return 0;
}