revert between 56095 -> 55830 in arch
[AROS.git] / workbench / utilities / Installer / variables.c
blob3ea77c5c183ae6ae56f39e665dba5986edd79040
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /* variables.c -- Here are all functions related to variables */
8 #include "Installer.h"
9 #include "texts.h"
10 #include "main.h"
11 #include "gui.h"
12 #include "cleanup.h"
13 #include "variables.h"
15 /* External variables */
16 extern InstallerPrefs preferences;
17 extern IPTR args[TOTAL_ARGS];
18 extern UBYTE **tooltypes;
21 int numvariables = 0;
22 struct VariableList *variables = NULL;
26 * Get entry of variable in global list
28 struct VariableList *find_var(char *name)
30 int i;
32 /* Check if variable is in list */
33 for ( i = 0 ; i < numvariables && strcmp(name, variables[i].varsymbol) != 0 ; i++ );
34 if (i == numvariables)
36 return NULL;
38 else
40 return &(variables[i]);
46 * Return the value of a variable
47 * string if non-NULL else integer
49 void *get_variable(char *name)
51 struct VariableList *entry;
53 /* Find variable in lists */
54 entry = find_var(name);
56 /* Return Pointer to value */
57 if (entry != NULL)
59 if (entry->vartext == NULL)
61 return (void *)(entry->varinteger);
63 else
65 return (void *)entry->vartext;
68 else
70 return NULL;
76 * Get the string value of a variable
78 char *get_var_arg(char *name)
80 struct VariableList *entry;
82 /* Find variable in lists */
83 entry = find_var(name);
85 if (entry != NULL)
87 return entry->vartext;
89 else
91 return NULL;
97 * Get the integer value of a variable
99 long int get_var_int(char *name)
101 struct VariableList *entry;
103 /* Find variable in lists */
104 entry = find_var(name);
106 if (entry != NULL)
108 return entry->varinteger;
110 else
112 return 0;
118 * Set the value of a variable
119 * Add variable to global list if not existent
121 void set_variable(char *name, char *text, long int intval)
123 int i;
125 /* Check if variable is in list */
126 for ( i = 0 ; i < numvariables && strcmp(name, variables[i].varsymbol) != 0 ; i++ );
127 if (i == numvariables)
129 /* Enlarge list for one additional element */
130 numvariables++;
131 variables = realloc(variables, sizeof(struct VariableList) * numvariables);
132 outofmem(variables);
133 variables[i].varsymbol = NULL;
134 variables[i].vartext = NULL;
136 else
138 /* Free space for strings to be replaced in dynamic list */
139 free(variables[i].vartext);
140 variables[i].vartext = NULL;
143 /* Change values in list */
145 /* Duplicate variable name if it does not exist yet */
147 if (variables[i].varsymbol == NULL)
149 variables[i].varsymbol = strdup(name);
150 outofmem(variables[i].varsymbol);
153 /* Duplicate variable text if existent */
154 if (text != NULL)
156 variables[i].vartext = strdup(text);
157 outofmem(variables[i].vartext);
160 /* Set integer value */
161 variables[i].varinteger = intval;
167 * Set initial variables at INIT stage
169 void set_preset_variables(int argc)
171 STRPTR ttemp;
173 if (argc)
174 { /* Started from Shell */
175 if (args[ARG_APPNAME])
177 set_variable("@app-name", (STRPTR)args[ARG_APPNAME], 0);
179 else
181 set_variable("@app-name", "DemoApp", 0);
184 if (args[ARG_LANGUAGE])
186 set_variable("@language", (char *)args[ARG_LANGUAGE], 0);
188 else
190 set_variable("@language", "english", 0);
193 else
194 { /* Started from Workbench */
195 ttemp = ArgString(tooltypes, "APPNAME", NULL);
196 if (ttemp)
198 set_variable("@app-name", ttemp, 0);
200 else
202 set_variable("@app-name", "DemoApp", 0);
204 set_variable("@language", ArgString(tooltypes, "LANGUAGE", "english"), 0);
207 set_variable("@abort-button", ABORT_BUTTON, 0);
208 set_variable("@default-dest", DEFAULT_DEST, 0);
209 set_variable("@installer-version", NULL, (INSTALLER_VERSION << 16) + INSTALLER_REVISION);
210 set_variable("@user-level", NULL, preferences.defusrlevel);
211 set_variable("@pretend", NULL, preferences.pretend);
213 /* Set help texts */
214 set_variable("@askchoice-help", ASKCHOICE_HELP, 0);
215 set_variable("@asknumber-help", ASKNUMBER_HELP, 0);
216 set_variable("@askoptions-help", ASKOPTIONS_HELP, 0);
217 set_variable("@askstring-help", ASKSTRING_HELP, 0);
219 /* Set other variables to (NULL|0) */
220 set_variable("@askdir-help", NULL, 0);
221 set_variable("@askdisk-help", NULL, 0);
222 set_variable("@askfile-help", NULL, 0);
223 set_variable("@copyfiles-help", NULL, 0);
224 set_variable("@copylib-help", NULL, 0);
225 set_variable("@each-name", NULL, 0);
226 set_variable("@each-type", NULL, 0);
227 set_variable("@error-msg", NULL, 0);
228 set_variable("@execute-dir", NULL, 0);
229 set_variable("@icon", NULL, 0);
230 set_variable("@ioerr", NULL, 0);
231 set_variable("@makedir-help", NULL, 0);
232 set_variable("@special-msg", NULL, 0);
233 set_variable("@startup-help", NULL, 0);
237 #ifdef DEBUG
239 * Dump values of all variables
241 void dump_varlist()
243 int i;
245 printf("DUMP of all %d variables:\n", numvariables);
246 for ( i = 0 ; i < numvariables ; i++ )
248 printf("%s = %s | %ld\n", variables[i].varsymbol, variables[i].vartext, variables[i].varinteger);
252 #endif /* DEBUG */
256 * Free the memory allocated by global varlist
258 void free_varlist()
260 int i;
262 for ( i = 0 ; i < numvariables ; i++ )
264 free(variables[i].varsymbol);
265 free(variables[i].vartext);
267 free(variables);