2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
10 #include "Installer.h"
16 #include "variables.h"
23 char test_script
[] = "SYS:Tests/Installer/test.script";
26 char *filename
= NULL
;
28 char buffer
[MAXARGSIZE
];
29 int error
= 0, grace_exit
= 0;
31 InstallerPrefs preferences
;
34 IPTR args
[TOTAL_ARGS
] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
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
;
51 { /* Invoked from Shell */
52 preferences
.fromcli
= TRUE
;
53 /* evaluate args with RDArgs(); */
54 rda
= ReadArgs(ARG_TEMPLATE
, args
, NULL
);
57 PrintFault(IoErr(), INSTALLER_NAME
);
61 /* open script file */
64 filename
= (STRPTR
)args
[ARG_SCRIPT
];
68 fprintf(stderr
, "No SCRIPT specified!\n");
70 fprintf(stderr
, "Using %s instead...\n", test_script
);
71 filename
= test_script
;
79 { /* Invoked from Workbench */
80 preferences
.fromcli
= FALSE
;
81 tooltypes
= ArgArrayInit(argc
, (UBYTE
**)argv
);
83 /* open script file */
84 ttemp
= ArgString(tooltypes
, "SCRIPT", NULL
);
88 fprintf(stderr
, "No SCRIPT ToolType in Icon!\n");
98 inputfile
= Open(filename
, MODE_OLDFILE
);
99 if (inputfile
== BNULL
)
102 fprintf(stderr
, "Error opening script <%s>\n",filename
);
103 PrintFault(IoErr(), INSTALLER_NAME
);
108 preferences
.welcome
= FALSE
;
109 preferences
.transcriptstream
= BNULL
;
110 preferences
.pretend
= 0;
114 preferences
.debug
= TRUE
;
117 preferences
.novicelog
= FALSE
;
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
;
138 preferences
.minusrlevel
= _NOVICE
;
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
;
158 preferences
.defusrlevel
= _NOVICE
;
163 preferences
.defusrlevel
= _NOVICE
;
165 if (preferences
.defusrlevel
< preferences
.minusrlevel
)
167 preferences
.defusrlevel
= preferences
.minusrlevel
;
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
;
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");
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");
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
;
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
]);
239 dummy
->parent
= NULL
;
240 preferences
.trapparent
[count
] = NULL
;
243 /* Init GUI -- i.e open empty window */
252 script
.parent
= NULL
;
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
)
267 currentarg
= script
.cmd
;
268 currentarg
->parent
= &script
;
272 currentarg
->next
= (ScriptArg
*)AllocVec(sizeof(ScriptArg
), MEMF_PUBLIC
);
273 if (currentarg
->next
== NULL
)
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;
290 count
= Read(inputfile
, &buffer
[0], 1);
296 if (!isspace(buffer
[0]) && (endoffile
== FALSE
))
298 /* This is text, is it valid ? */
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);
313 case LBRACK
: /* A command (...) , parse the content of braces */
314 currentarg
->cmd
= (ScriptArg
*)AllocVec(sizeof(ScriptArg
), MEMF_PUBLIC
);
315 if (currentarg
->cmd
== NULL
)
319 dummy
= currentarg
->cmd
;
320 dummy
->parent
= currentarg
;
326 parse_file(currentarg
->cmd
);
330 default: /* Plain text or closing bracket is not allowed */
332 show_parseerror("Too many closing brackets!", line
);
340 if (buffer
[0] == LINEFEED
)
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
;
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
);
374 /* Set variables which are not constant */
375 set_preset_variables(argc
);
377 /* NOTE: Now everything from commandline(ReadArgs)/ToolTypes(Workbench)
381 { /* Finally free ReadArgs struct (set_preset_variables() needed them) */
385 { /* Or free tooltypes array if started from WB */
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
;
403 preferences
.copyflags
|= COPY_ASKUSER
;
406 /* execute parsed script */
407 execute_script(script
.cmd
, 0);