- Set up the real-mode IDT.
[AROS.git] / workbench / utilities / Installer / main.c
blob028a08273a1168633e3a2136600311e8536a2011
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Installer V43.3
6 Lang: english
7 */
9 #define DEBUG 1
10 #include "Installer.h"
11 #include "main.h"
12 #include "cleanup.h"
13 #include "locale.h"
14 #include "gui.h"
15 #include "parse.h"
16 #include "variables.h"
17 #include "execute.h"
19 #include "version.h"
22 #ifdef DEBUG
23 char test_script[] = "SYS:Tests/Installer/test.script";
24 #endif /* DEBUG */
26 char *filename = NULL;
27 BPTR inputfile;
28 char buffer[MAXARGSIZE];
29 int error = 0, grace_exit = 0;
31 InstallerPrefs preferences;
32 ScriptArg script;
34 IPTR args[TOTAL_ARGS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
35 UBYTE **tooltypes;
38 * MAIN
40 int main(int argc, char *argv[])
42 struct RDArgs *rda = NULL;
43 char *ttemp, *tstring;
45 ScriptArg *currentarg, *dummy;
46 int nextarg, endoffile, count;
48 Locale_Initialize();
50 if (argc != 0)
51 { /* Invoked from Shell */
52 preferences.fromcli = TRUE;
53 /* evaluate args with RDArgs(); */
54 rda = ReadArgs(ARG_TEMPLATE, args, NULL);
55 if (rda == NULL)
57 PrintFault(IoErr(), INSTALLER_NAME);
58 exit(-1);
61 /* open script file */
62 if (args[ARG_SCRIPT])
64 filename = (STRPTR)args[ARG_SCRIPT];
66 else
68 fprintf(stderr, "No SCRIPT specified!\n");
69 #ifdef DEBUG
70 fprintf(stderr, "Using %s instead...\n", test_script);
71 filename = test_script;
72 #else
73 FreeArgs(rda);
74 exit(-1);
75 #endif /* DEBUG */
78 else
79 { /* Invoked from Workbench */
80 preferences.fromcli = FALSE;
81 tooltypes = ArgArrayInit(argc, (UBYTE **)argv);
83 /* open script file */
84 ttemp = ArgString(tooltypes, "SCRIPT", NULL);
85 if (ttemp == NULL)
87 #ifdef DEBUG
88 fprintf(stderr, "No SCRIPT ToolType in Icon!\n");
89 ttemp = test_script;
90 #else
91 ArgArrayDone();
92 exit(-1);
93 #endif /* DEBUG */
95 filename = ttemp;
98 inputfile = Open(filename, MODE_OLDFILE);
99 if (inputfile == BNULL)
101 #ifdef DEBUG
102 fprintf(stderr, "Error opening script <%s>\n",filename);
103 PrintFault(IoErr(), INSTALLER_NAME);
104 #endif /* DEBUG */
105 exit(-1);
108 preferences.welcome = FALSE;
109 preferences.transcriptstream = BNULL;
110 preferences.pretend = 0;
112 if (argc)
114 preferences.debug = TRUE;
115 if (args[ARG_NOLOG])
117 preferences.novicelog = FALSE;
119 else
121 preferences.novicelog = TRUE;
123 preferences.transcriptfile = StrDup((args[ARG_LOGFILE]) ? (char *)args[ARG_LOGFILE] : "install_log_file");
124 preferences.nopretend = (int)args[ARG_NOPRETEND];
125 if (args[ARG_MINUSER])
127 preferences.minusrlevel = _NOVICE;
128 if (strcasecmp("average", (char *)args[ARG_MINUSER]) == 0)
130 preferences.minusrlevel = _AVERAGE;
132 else if (strcasecmp("expert", (char *)args[ARG_MINUSER]) == 0)
134 preferences.minusrlevel = _EXPERT;
136 else
138 preferences.minusrlevel = _NOVICE;
141 else
143 preferences.minusrlevel = _NOVICE;
145 if (args[ARG_DEFUSER])
147 preferences.defusrlevel = preferences.minusrlevel;
148 if (strcasecmp("average", (char *)args[ARG_DEFUSER]) == 0)
150 preferences.defusrlevel = _AVERAGE;
152 else if (strcasecmp("expert", (char *)args[ARG_DEFUSER]) == 0)
154 preferences.defusrlevel = _EXPERT;
156 else
158 preferences.defusrlevel = _NOVICE;
161 else
163 preferences.defusrlevel = _NOVICE;
165 if (preferences.defusrlevel < preferences.minusrlevel)
167 preferences.defusrlevel = preferences.minusrlevel;
170 else
172 preferences.debug = TRUE;
174 /* Create a log file in Novice mode? (TRUE) */
175 if (strcmp("TRUE", ArgString(tooltypes, "LOG", "TRUE")) == 0)
177 preferences.novicelog = TRUE;
179 else
181 preferences.novicelog = FALSE;
184 /* Write to which LOGFILE? */
185 preferences.transcriptfile = StrDup(ArgString(tooltypes, "LOGFILE", "install_log_file"));
186 /* Is PRETEND possible? */
187 preferences.nopretend = (strcmp("TRUE", ArgString(tooltypes, "PRETEND", "TRUE")) != 0);
188 ttemp = ArgString(tooltypes, "MINUSER", "NOVICE");
189 tstring = NULL;
190 preferences.minusrlevel = _NOVICE;
191 if (strcasecmp("average", ttemp) == 0)
193 preferences.minusrlevel = _AVERAGE;
194 tstring = StrDup("AVERAGE");
196 else if (strcasecmp("expert", ttemp) == 0)
198 preferences.minusrlevel = _EXPERT;
199 tstring = StrDup("EXPERT");
201 if (tstring == NULL)
203 tstring = StrDup("NOVICE");
206 ttemp = ArgString(tooltypes, "DEFUSER", tstring);
207 preferences.defusrlevel = preferences.minusrlevel;
208 if (strcasecmp("average", ttemp) == 0)
210 preferences.defusrlevel = _AVERAGE;
212 else if (strcasecmp("expert", ttemp) == 0)
214 preferences.defusrlevel = _EXPERT;
216 if (preferences.defusrlevel < preferences.minusrlevel)
218 preferences.defusrlevel = preferences.minusrlevel;
220 FreeVec(tstring);
221 if (preferences.defusrlevel < preferences.minusrlevel)
223 preferences.defusrlevel = preferences.minusrlevel;
227 preferences.copyfail = COPY_FAIL;
228 preferences.copyflags = 0;
230 preferences.onerror.cmd = NULL;
231 preferences.onerror.next = NULL;
232 preferences.onerror.parent = NULL;
233 preferences.onerrorparent = NULL;
234 for ( count = 0 ; count < NUMERRORS ; count++ )
236 dummy = &(preferences.trap[count]);
237 dummy->cmd = NULL;
238 dummy->next = NULL;
239 dummy->parent = NULL;
240 preferences.trapparent[count] = NULL;
243 /* Init GUI -- i.e open empty window */
244 init_gui();
246 line = 1;
248 endoffile = FALSE;
249 script.arg = NULL;
250 script.cmd = NULL;
251 script.next = NULL;
252 script.parent = NULL;
253 script.intval = 0;
254 script.ignore = 0;
255 currentarg = script.cmd;
256 /* parse script file */
259 /* Allocate space for script cmd and save first one to scriptroot */
260 if (script.cmd == NULL)
262 script.cmd = (ScriptArg *)AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
263 if (script.cmd == NULL)
265 end_alloc();
267 currentarg = script.cmd;
268 currentarg->parent = &script;
270 else
272 currentarg->next = (ScriptArg *)AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
273 if (currentarg->next == NULL)
275 end_alloc();
277 currentarg->next->parent = currentarg->parent;
278 currentarg = currentarg->next;
280 /* Set initial values */
281 currentarg->arg = NULL;
282 currentarg->cmd = NULL;
283 currentarg->next = NULL;
284 currentarg->intval = 0;
285 currentarg->ignore = 0;
287 nextarg = FALSE;
290 count = Read(inputfile, &buffer[0], 1);
291 if (count == 0)
293 endoffile = TRUE;
296 if (!isspace(buffer[0]) && (endoffile == FALSE))
298 /* This is text, is it valid ? */
299 switch(buffer[0])
301 case SEMICOLON: /* A comment, ok - Go on with next line */
304 count = Read(inputfile, &buffer[0], 1);
305 } while (buffer[0] != LINEFEED && count != 0);
306 line++;
307 if (count == 0)
309 endoffile = TRUE;
311 break;
313 case LBRACK: /* A command (...) , parse the content of braces */
314 currentarg->cmd = (ScriptArg *)AllocVec(sizeof(ScriptArg), MEMF_PUBLIC);
315 if (currentarg->cmd == NULL)
317 end_alloc();
319 dummy = currentarg->cmd;
320 dummy->parent = currentarg;
321 dummy->arg = NULL;
322 dummy->ignore = 0;
323 dummy->intval = 0;
324 dummy->cmd = NULL;
325 dummy->next = NULL;
326 parse_file(currentarg->cmd);
327 nextarg = TRUE;
328 break;
330 default: /* Plain text or closing bracket is not allowed */
331 Close(inputfile);
332 show_parseerror("Too many closing brackets!", line);
333 cleanup();
334 exit(-1);
335 break;
338 else
340 if (buffer[0] == LINEFEED)
342 line++;
345 } while (nextarg != TRUE && !endoffile);
346 } while (!endoffile);
348 /* Okay, we (again) have allocated one ScriptArg too much, so get rid of it */
349 currentarg = script.cmd;
350 if (currentarg->next != NULL)
352 while (currentarg->next->next != NULL)
354 currentarg = currentarg->next;
356 FreeVec(currentarg->next);
357 currentarg->next = NULL;
360 Close(inputfile);
362 if (preferences.transcriptfile != NULL)
364 /* open transcript file */
365 preferences.transcriptstream = Open(preferences.transcriptfile, MODE_NEWFILE);
366 if (preferences.transcriptstream == BNULL)
368 PrintFault(IoErr(), INSTALLER_NAME);
369 cleanup();
370 exit(-1);
374 /* Set variables which are not constant */
375 set_preset_variables(argc);
377 /* NOTE: Now everything from commandline(ReadArgs)/ToolTypes(Workbench)
378 will become invalid!
380 if (argc != 0)
381 { /* Finally free ReadArgs struct (set_preset_variables() needed them) */
382 FreeArgs(rda);
384 else
385 { /* Or free tooltypes array if started from WB */
386 ArgArrayDone();
389 /* If the script does not contain a (welcome) section, call the default one */
390 if (preferences.welcome == FALSE)
392 request_userlevel(NULL);
396 /* Don't bother NOVICE */
397 if (get_var_int("@user-level") == _NOVICE)
399 preferences.copyflags &= ~COPY_ASKUSER;
401 else
403 preferences.copyflags |= COPY_ASKUSER;
406 /* execute parsed script */
407 execute_script(script.cmd, 0);
409 #ifdef DEBUG
410 dump_varlist();
411 #endif /* DEBUG */
413 final_report();
414 cleanup();
416 return error;