MCPcopy Create free account
hub / github.com/Entware/Entware / variable_add

Function variable_add

scripts/config/preprocess.c:279–322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

277}
278
279void variable_add(const char *name, const char *value,
280 enum variable_flavor flavor)
281{
282 struct variable *v;
283 char *new_value;
284 bool append = false;
285
286 v = variable_lookup(name);
287 if (v) {
288 /* For defined variables, += inherits the existing flavor */
289 if (flavor == VAR_APPEND) {
290 flavor = v->flavor;
291 append = true;
292 } else {
293 free(v->value);
294 }
295 } else {
296 /* For undefined variables, += assumes the recursive flavor */
297 if (flavor == VAR_APPEND)
298 flavor = VAR_RECURSIVE;
299
300 v = xmalloc(sizeof(*v));
301 v->name = xstrdup(name);
302 v->exp_count = 0;
303 list_add_tail(&v->node, &variable_list);
304 }
305
306 v->flavor = flavor;
307
308 if (flavor == VAR_SIMPLE)
309 new_value = expand_string(value);
310 else
311 new_value = xstrdup(value);
312
313 if (append) {
314 v->value = xrealloc(v->value,
315 strlen(v->value) + strlen(new_value) + 2);
316 strcat(v->value, " ");
317 strcat(v->value, new_value);
318 free(new_value);
319 } else {
320 v->value = new_value;
321 }
322}
323
324static void variable_del(struct variable *v)
325{

Callers 1

yyparseFunction · 0.85

Calls 6

variable_lookupFunction · 0.85
xmallocFunction · 0.85
xstrdupFunction · 0.85
expand_stringFunction · 0.85
xreallocFunction · 0.85
list_add_tailFunction · 0.70

Tested by

no test coverage detected