| 277 | } |
| 278 | |
| 279 | void 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 | |
| 324 | static void variable_del(struct variable *v) |
| 325 | { |
no test coverage detected