-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
61 lines (52 loc) · 1.69 KB
/
main.c
File metadata and controls
61 lines (52 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "./include/utils.h"
#include "./include/parser.h"
#include "./include/builtin.h"
#include "./include/executor.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
int main(void){
char* prompt = get_prompt();
load_commands_history();
char* input = NULL;
command command;
int result;
while(1){
printf("%s ", prompt);
if(input)
free(input);
input = read_input();
command = parse_command(input);
if(errno == UNEXPECTED_CHARACTER){
printf("Un caractère inattendu est présent\n");
continue;
}
//chanign things to test API github
result = execute(command);
switch(result){
case EXIT_COMMAND :
free(prompt);
free(input);
set_canonical_mode(STDIN_FILENO, 1); //reactivating the canonical mode for the terminal
exit(EXIT_SUCCESS);
break;
case REFRESH_PROMPT:
free(prompt);
prompt = get_prompt();
break;
case -1 :
printf("Impossible d'exécuter la commande. Une erreur est survenue\n");
break;
case -2 :
printf("impossible de créer un processus fils pour exécuter la commande\n");
break;
case -3:
printf("Le processus fils a été terminé par le signal : %d\n", sigNum);
break;
case -4:
printf("Le processus fils a été arrêté par le signal : %d\n", sigNum);
break;
}
}
}