2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
6 /* variables.c -- Here are all functions related to variables */
13 #include "variables.h"
15 /* External variables */
16 extern InstallerPrefs preferences
;
17 extern IPTR args
[TOTAL_ARGS
];
18 extern UBYTE
**tooltypes
;
22 struct VariableList
*variables
= NULL
;
26 * Get entry of variable in global list
28 struct VariableList
*find_var(char *name
)
32 /* Check if variable is in list */
33 for ( i
= 0 ; i
< numvariables
&& strcmp(name
, variables
[i
].varsymbol
) != 0 ; i
++ );
34 if (i
== numvariables
)
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 */
59 if (entry
->vartext
== NULL
)
61 return (void *)(entry
->varinteger
);
65 return (void *)entry
->vartext
;
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
);
87 return entry
->vartext
;
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
);
108 return entry
->varinteger
;
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
)
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 */
131 variables
= realloc(variables
, sizeof(struct VariableList
) * numvariables
);
133 variables
[i
].varsymbol
= NULL
;
134 variables
[i
].vartext
= NULL
;
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 */
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
)
174 { /* Started from Shell */
175 if (args
[ARG_APPNAME
])
177 set_variable("@app-name", (STRPTR
)args
[ARG_APPNAME
], 0);
181 set_variable("@app-name", "DemoApp", 0);
184 if (args
[ARG_LANGUAGE
])
186 set_variable("@language", (char *)args
[ARG_LANGUAGE
], 0);
190 set_variable("@language", "english", 0);
194 { /* Started from Workbench */
195 ttemp
= ArgString(tooltypes
, "APPNAME", NULL
);
198 set_variable("@app-name", ttemp
, 0);
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
);
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);
239 * Dump values of all variables
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
);
256 * Free the memory allocated by global varlist
262 for ( i
= 0 ; i
< numvariables
; i
++ )
264 free(variables
[i
].varsymbol
);
265 free(variables
[i
].vartext
);