-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmain.c
83 lines (64 loc) · 1.65 KB
/
smain.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <sys/signal.h>
#include "util.h"
#include "disp.h"
#include "operation.h"
// Declaring all the functions to be used in the file
int main();
int loop();
/*
* Setup part of the code, that is executed first and compiles various parts of
* the shell together.
*/
int main() {
// Load from the configuration file?
// Run the program loop
loop();
// EXIT, Somehow I guess
}
/*
* The REPL part of the shell. Large overview by definition, minor details
* must be handled by various modules as constructed
*/
int loop() {
size_t bsize = 0;
char *line = (char*)malloc(bsize);
char *command = (char*)malloc(bsize);
char **commands;
char **argv;
int argc;
int status, i, num;
signal(SIGINT, sig_int);
signal(SIGSTOP, sig_stop);
signal(SIGTSTP, sig_tstp);
// Print any process IDs
do {
// FLOW: Display prompt and get input
prompt();
getline(&line, &bsize, stdin);
// FLOW: Split lines into multiple commands by ';' etc
// and count them into num (passed as a pointer)
commands = splitlines(line, &num);
// printf("NUM SHOULD BE:%d\n", num);
// FLOW: Process each command extracted
for(i = 0; i < num; i++) {
strcpy(command, commands[i]);
// FLOW: Get all tokens in the each command
// and store the count in argc
argv = parseline(command, &argc);
// Dealing with no input in line
if (argc == 1 && argv[0] == NULL)
continue;
// FLOW: Execute the command - get the exit status
status = run(argv, argc);
if(status == 0)
break;
}
} while(status != 0);
return 0;
}