2022-09-18 06:46:23 +00:00
|
|
|
/*
|
2022-09-18 15:35:26 +00:00
|
|
|
* @Author: 1ridic
|
|
|
|
* @Date: 2022-09-18 14:13:53
|
|
|
|
* @Last Modified by: 1ridic
|
2022-09-20 14:29:59 +00:00
|
|
|
* @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>
|
2022-09-20 13:04:55 +00:00
|
|
|
#include <readline/readline.h>
|
|
|
|
#include <readline/history.h>
|
2022-09-18 05:14:30 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2022-09-20 13:04:55 +00:00
|
|
|
#include "loop.h"
|
|
|
|
#include "exec.h"
|
|
|
|
#include "line.h"
|
2022-09-18 15:35:26 +00:00
|
|
|
|
|
|
|
int status;
|
2022-09-18 05:14:30 +00:00
|
|
|
|
2022-09-20 14:29:59 +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 15:35:26 +00:00
|
|
|
|
2022-09-18 05:14:30 +00:00
|
|
|
char *line;
|
|
|
|
char **args;
|
2022-09-20 13:04:55 +00:00
|
|
|
line = readline(ANSI_COLOR_GREEN"> "ANSI_COLOR_RESET);
|
|
|
|
add_history(line);
|
2022-09-18 05:14:30 +00:00
|
|
|
args = splitLine(line);
|
2022-09-18 15:35:26 +00:00
|
|
|
status = commandExec(args);
|
2022-09-18 05:14:30 +00:00
|
|
|
free(line);
|
|
|
|
free(args);
|
|
|
|
return 0;
|
|
|
|
}
|