Snoopy: print correct title for OpenResource patch.
[AROS.git] / workbench / utilities / Installer / main.c
blob445e902fb36d6447958f328691f4914b6546bb0b
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;
44 ScriptArg *currentarg, *dummy;
45 int nextarg, endoffile, count;
47 Locale_Initialize();
49 if (argc != 0)
50 { /* Invoked from Shell */
51 preferences.fromcli = TRUE;
52 /* evaluate args with RDArgs(); */
53 rda = ReadArgs(ARG_TEMPLATE, args, NULL);
54 if (rda == NULL)
56 PrintFault(IoErr(), INSTALLER_NAME);
57 exit(-1);
60 /* open script file */
61 if (args[ARG_SCRIPT])
63 filename = (STRPTR)args[ARG_SCRIPT];
65 else
67 fprintf(stderr, "No SCRIPT specified!\n");
68 #ifdef DEBUG
69 fprintf(stderr, "Using %s instead...\n", test_script);
70 filename = test_script;
71 #else
72 FreeArgs(rda);
73 exit(-1);
74 #endif /* DEBUG */
77 else
79 STRPTR ttemp;
81 /* Invoked from Workbench */
82 preferences.fromcli = FALSE;
83 tooltypes = ArgArrayInit(argc, (UBYTE **)argv);
85 /* open script file */
86 ttemp = ArgString(tooltypes, "SCRIPT", NULL);
87 if (ttemp == NULL)
89 #ifdef DEBUG
90 fprintf(stderr, "No SCRIPT ToolType in Icon!\n");
91 ttemp = test_script;
92 #else
93 ArgArrayDone();
94 exit(-1);
95 #endif /* DEBUG */
97 filename = ttemp;
100 inputfile = Open(filename, MODE_OLDFILE);
101 if (inputfile == BNULL)
103 #ifdef DEBUG
104 fprintf(stderr, "Error opening script <%s>\n",filename);
105 PrintFault(IoErr(), INSTALLER_NAME);
106 #endif /* DEBUG */
107 exit(-1);
110 preferences.welcome = FALSE;
111 preferences.transcriptstream = BNULL;
112 preferences.pretend = 0;
114 if (argc)
116 preferences.debug = TRUE;
117 if (args[ARG_NOLOG])
119 preferences.novicelog = FALSE;
121 else
123 preferences.novicelog = TRUE;
125 preferences.transcriptfile = strdup((args[ARG_LOGFILE]) ? (char *)args[ARG_LOGFILE] : "install_log_file");
126 preferences.nopretend = (int)args[ARG_NOPRETEND];
127 if (args[ARG_MINUSER])
129 preferences.minusrlevel = _NOVICE;
130 if (strcasecmp("average", (char *)args[ARG_MINUSER]) == 0)
132 preferences.minusrlevel = _AVERAGE;
134 else if (strcasecmp("expert", (char *)args[ARG_MINUSER]) == 0)
136 preferences.minusrlevel = _EXPERT;
138 else
140 preferences.minusrlevel = _NOVICE;
143 else
145 preferences.minusrlevel = _NOVICE;
147 if (args[ARG_DEFUSER])
149 preferences.defusrlevel = preferences.minusrlevel;
150 if (strcasecmp("average", (char *)args[ARG_DEFUSER]) == 0)
152 preferences.defusrlevel = _AVERAGE;
154 else if (strcasecmp("expert", (char *)args[ARG_DEFUSER]) == 0)
156 preferences.defusrlevel = _EXPERT;
158 else
160 preferences.defusrlevel = _NOVICE;
163 else
165 preferences.defusrlevel = _NOVICE;
167 if (preferences.defusrlevel < preferences.minusrlevel)
169 preferences.defusrlevel = preferences.minusrlevel;
172 else
174 STRPTR ttemp, tstring;
176 preferences.debug = TRUE;
178 /* Create a log file in Novice mode? (TRUE) */
179 if (strcmp("TRUE", ArgString(tooltypes, "LOG", "TRUE")) == 0)
181 preferences.novicelog = TRUE;
183 else
185 preferences.novicelog = FALSE;
188 /* Write to which LOGFILE? */
189 preferences.transcriptfile = strdup(ArgString(tooltypes, "LOGFILE", "install_log_file"));
190 /* Is PRETEND possible? */
191 preferences.nopretend = (strcmp("TRUE", ArgString(tooltypes, "PRETEND", "TRUE")) != 0);
192 ttemp = ArgString(tooltypes, "MINUSER", "NOVICE");
193 tstring = "NOVICE";
194 preferences.minusrlevel = _NOVICE;
195 if (strcasecmp("average", ttemp) == 0)
197 preferences.minusrlevel = _AVERAGE;
198 tstring = "AVERAGE";
200 else if (strcasecmp("expert", ttemp) == 0)
202 preferences.minusrlevel = _EXPERT;
203 tstring = "EXPERT";
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;
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 *)malloc(sizeof(ScriptArg));
263 if (script.cmd == NULL)
265 end_alloc();
267 currentarg = script.cmd;
268 currentarg->parent = &script;
270 else
272 currentarg->next = (ScriptArg *)malloc(sizeof(ScriptArg));
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 *)malloc(sizeof(ScriptArg));
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 free(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;