-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
50 lines (40 loc) · 1.17 KB
/
main.c
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
#include "prompt.h"
#include "iomanip.h"
#include "syscall.h"
#include <signal.h>
#define MAX_USER_INPUT 510
int get_user_input(int return_code,char* user_input) {
//prints the formatted prompt
char tempInput[MAX_USER_INPUT];
char* prompt = get_prompt_string(return_code);
printf("%s", prompt);
scanf("%[^\n]", user_input);
strncpy(tempInput, user_input, MAX_USER_INPUT);
//checks to see if exit was called.
if (user_input == NULL || (int)*user_input == 0) {
while(getchar() != '\n');
return 0;
}
else if(compare_input_to_word(input_to_token(tempInput, " ")[0],"exit") == 1) {
exit(0);
}
else {
//breaks the input into array of strings seperated by the delimiter - " ".
return_code = execute(user_input);
}
//empties the buffer of newline characters.
while(getchar() != '\n');
//frees the space we've allocated for the prompt
free(prompt);
return return_code;
}
int main() {
signal(SIGINT, SIG_IGN);
int return_code = 0;
char *user_input = (char*)malloc(sizeof(char)*MAX_USER_INPUT);
user_input = (char*)memset(user_input,MAX_USER_INPUT*sizeof(char), 0);
while(1) {
return_code = get_user_input(return_code, user_input);
strcpy(user_input,"");
}
}