10 |
#define MAX_COMMAND_LENGTH 1024 |
#define MAX_COMMAND_LENGTH 1024 |
11 |
|
|
12 |
int main(int argc, char * argv[]) { |
int main(int argc, char * argv[]) { |
13 |
|
|
14 |
|
// interactive mode with prompt |
15 |
if (argc == 1) { |
if (argc == 1) { |
16 |
//printf("No arguments given."); |
//printf("No arguments given."); |
17 |
//exit(EXIT_FAILURE); |
//exit(EXIT_FAILURE); |
20 |
os_start_process(filename, background); |
os_start_process(filename, background); |
21 |
} |
} |
22 |
|
|
23 |
|
// scripting mode |
24 |
if (argc == 2) { |
if (argc == 2) { |
25 |
FILE * script = fopen(argv[1], "r"); |
FILE * script = fopen(argv[1], "r"); |
26 |
run_commands(script); |
run_commands(script); |
32 |
|
|
33 |
char command[MAX_COMMAND_LENGTH]; |
char command[MAX_COMMAND_LENGTH]; |
34 |
|
|
35 |
fgets(command, MAX_COMMAND_LENGTH, fp); |
while (fgets(command, MAX_COMMAND_LENGTH, fp)) { |
36 |
chomp(command); |
int command_length; |
37 |
|
|
38 |
|
// strip newlines |
39 |
|
chomp(command); |
40 |
|
|
41 |
|
// ... and action |
42 |
|
execute_command(command); |
43 |
|
} |
44 |
|
|
|
execute_command(command); |
|
45 |
} |
} |
46 |
|
|
47 |
|
|
48 |
void execute_command(char * command) { |
void execute_command(char * command) { |
49 |
|
|
50 |
|
BOOL background = FALSE; |
51 |
|
int command_length; |
52 |
|
|
53 |
printf("process_command: %s\n", command); |
printf("process_command: %s\n", command); |
54 |
os_start_process(command, 0); |
|
55 |
|
// background or foreground? |
56 |
|
command_length = strlen(command); |
57 |
|
if (command[command_length-1] == '&') { |
58 |
|
command[command_length-1] = '\0'; |
59 |
|
background = TRUE; |
60 |
|
} |
61 |
|
|
62 |
|
os_start_process(command, background); |
63 |
} |
} |
64 |
|
|