/[james]/archive/boot/boot.c
ViewVC logotype

Annotation of /archive/boot/boot.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 24 - (hide annotations) (download) (as text)
Thu Mar 13 12:45:43 2003 UTC (21 years, 7 months ago) by james
File MIME type: text/x-csrc
File size: 3468 byte(s)
Initial import.

1 james 24 /*
2     * boot.c
3     */
4    
5     #include <stdio.h>
6     #include <stdlib.h>
7     #include <string.h>
8    
9     #include <hourglass.h>
10     #include <os.h>
11     #include <osmodule.h>
12     #include <wimp.h>
13     #include <wimpreadsysinfo.h>
14    
15     int main(int argc, char *argv[])
16     {
17     FILE *file, *log;
18     int error = 0, tasks, len;
19     char command[200], s1[300], s2[200];
20     os_error *err;
21     wimp_t task = 0;
22    
23     if (argc < 3)
24     {
25     fprintf(stderr, "\007Syntax: boot <script> <log>\n");
26     return 1;
27     }
28    
29     file = fopen(argv[1], "r");
30     if (!file)
31     {
32     fprintf(stderr, "boot: unable to open '%s' for input\n", argv[1]);
33     return 1;
34     }
35    
36     log = fopen(argv[2], "w");
37     if (!file)
38     {
39     fprintf(stderr, "boot: unable to open '%s' for output\n", argv[2]);
40     return 1;
41     }
42    
43     xhourglass_on();
44    
45     if ((err = xwimpreadsysinfo_task_count(&tasks)) != NULL)
46     fprintf(log, "Wimp_ReadSysInfo error %i: %s\n", err->errnum, err->errmess);
47    
48     if (tasks > 0)
49     if ((err = xwimp_initialise(wimp_VERSION_RO2, "Boot", NULL, NULL, &task)) != NULL)
50     fprintf(log, "Wimp_Initialise error %i: %s\n", err->errnum, err->errmess);
51    
52     fseek(file, SEEK_END, 0);
53     len = ftell(file);
54     rewind(file);
55    
56     while (fscanf(file, "%s", command) != EOF)
57     {
58     if (strcmp(command, "sysvar") == 0)
59     {
60     fscanf(file, "%s ", s1);
61     fgets(s2, 300, file);
62     s2[strlen(s2)-1] = 0;
63     fprintf(log, "sysvar %s %s\n", s1, s2);
64     if ((err = xos_set_var_val(s1, s2, (int) strlen(s2), 0,
65     os_VARTYPE_LITERAL_STRING, NULL, NULL)) != NULL)
66     {
67     fprintf(log, " error %i: %s\n", err->errnum, err->errmess);
68     error = 1;
69     }
70     }
71     else if (strcmp(command, "module") == 0)
72     {
73     fscanf(file, " ");
74     fgets(s1, 300, file);
75     s1[strlen(s1)-1] = 0;
76     // fscanf(file, "%s", s1);
77     fprintf(log, "module %s\n", s1);
78     if ((err = xosmodule_load(s1)) != NULL)
79     {
80     fprintf(log, " error %i: %s\n", err->errnum, err->errmess);
81     error = 1;
82     }
83     }
84     else if (strcmp(command, "oscli") == 0)
85     {
86     fscanf(file, " ");
87     fgets(s1, 300, file);
88     s1[strlen(s1)-1] = 0;
89     fprintf(log, "oscli %s\n", s1);
90     system(s1); /* good reason for this */
91     /* if ((err = xos_cli(s1)) != NULL)
92     {
93     fprintf(log, " error %i: %s\n", err->errnum, err->errmess);
94     error = 1;
95     }*/
96     }
97     else if (strcmp(command, "start") == 0)
98     {
99     fscanf(file, " ");
100     fgets(s1, 300, file);
101     s1[strlen(s1)-1] = 0;
102     fprintf(log, "start %s\n", s1);
103     if ((err = xwimp_start_task(s1, NULL)) != NULL)
104     {
105     fprintf(log, " error 0x%x: %s\n", err->errnum, err->errmess);
106     error = 1;
107     }
108     }
109     else if (strcmp(command, "echo") == 0)
110     {
111     fscanf(file, " ");
112     fgets(s1, 300, file);
113     s1[strlen(s1)-1] = 0;
114     fprintf(log, "echo %s\n", s1);
115     printf("%s\n", s1);
116     }
117     else
118     {
119     fgets(s1, 300, file);
120     fprintf(log, "unknown command %s\n", command);
121     error = 1;
122     }
123     xhourglass_percentage(ftell(file) * 100 / len);
124     }
125    
126     fclose(log);
127     fclose(file);
128    
129     if (task > 0)
130     {
131     if (error)
132     {
133     sprintf(s1, "Filer_Run %s", argv[2]);
134     xwimp_start_task(s1, NULL);
135     }
136     if ((err = xwimp_close_down(task)) != NULL)
137     fprintf(log, "Wimp_CloseDown error 0x%x: %s\n", err->errnum, err->errmess);
138     }
139     else if (error)
140     {
141     fprintf(stderr, "\007Errors occurred, log file '%s'\007\n", argv[2]);
142     }
143    
144     xhourglass_smash();
145    
146     return 0;
147     }

  ViewVC Help
Powered by ViewVC 1.1.26