| 1 |
/* $Id: min_shell.c,v 1.7 2006/06/15 22:58:58 joko Exp $ */ |
| 2 |
|
| 3 |
#include <stdlib.h> |
| 4 |
#include <stdio.h> |
| 5 |
#include <errno.h> |
| 6 |
|
| 7 |
#include "min_shell.h" |
| 8 |
|
| 9 |
|
| 10 |
#define MAX_COMMAND_LENGTH 1024 |
| 11 |
|
| 12 |
int main(int argc, char * argv[]) { |
| 13 |
|
| 14 |
// interactive mode with prompt |
| 15 |
if (argc == 1) { |
| 16 |
//printf("No arguments given."); |
| 17 |
//exit(EXIT_FAILURE); |
| 18 |
char filename[255] = "abc\0"; |
| 19 |
BOOL background = 0; |
| 20 |
os_start_process(filename, background); |
| 21 |
} |
| 22 |
|
| 23 |
// scripting mode |
| 24 |
if (argc == 2) { |
| 25 |
FILE * script = fopen(argv[1], "r"); |
| 26 |
run_commands(script); |
| 27 |
fclose(script); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
void run_commands(FILE * fp) { |
| 32 |
|
| 33 |
char command[MAX_COMMAND_LENGTH]; |
| 34 |
|
| 35 |
while (fgets(command, MAX_COMMAND_LENGTH, fp)) { |
| 36 |
chomp(command); |
| 37 |
execute_command(command); |
| 38 |
} |
| 39 |
|
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
void execute_command(char * command) { |
| 44 |
printf("process_command: %s\n", command); |
| 45 |
os_start_process(command, 0); |
| 46 |
} |
| 47 |
|