/[cvs]/joko/Uni/BSArch/03/win32/min_shell.c
ViewVC logotype

Contents of /joko/Uni/BSArch/03/win32/min_shell.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations)
Thu Jun 15 23:16:01 2006 UTC (18 years, 3 months ago) by joko
Branch: MAIN
Changes since 1.8: +19 -2 lines
File MIME type: text/plain
now runs processes in background

1 /* $Id: min_shell.c,v 1.8 2006/06/15 23:09:44 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 int command_length;
37
38 // strip newlines
39 chomp(command);
40
41 // ... and action
42 execute_command(command);
43 }
44
45 }
46
47
48 void execute_command(char * command) {
49
50 BOOL background = FALSE;
51 int command_length;
52
53 printf("process_command: %s\n", command);
54
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

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed