Changeset 531 for trunk/src/gmake/variable.c
- Timestamp:
- Sep 18, 2006, 1:49:49 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/variable.c
r530 r531 314 314 that it should be recursively re-expanded. */ 315 315 316 #ifdef CONFIG_WITH_VALUE_LENGTH 316 317 struct variable * 317 318 define_variable_in_set (const char *name, unsigned int length, 318 char *value, enum variable_origin origin, 319 int recursive, struct variable_set *set, 319 char *value, unsigned int value_length, int duplicate_value, 320 enum variable_origin origin, int recursive, 321 struct variable_set *set, const struct floc *flocp) 322 #else 323 struct variable * 324 define_variable_in_set (const char *name, unsigned int length, 325 char *value, enum variable_origin origin, 326 int recursive, struct variable_set *set, 320 327 const struct floc *flocp) 328 #endif 321 329 { 322 330 struct variable *v; … … 352 360 { 353 361 #ifdef CONFIG_WITH_VALUE_LENGTH 354 v->value_length = strlen (value); 355 v->value = xrealloc (v->value, v->value_length + 1); 356 bcopy (value, v->value, v->value_length + 1); 362 if (value_length == ~0U) 363 value_length = strlen (value); 364 else 365 assert (value_length == strlen (value)); 366 v->value_length = value_length; 367 if (!duplicate_value) 368 { 369 if (v->value != 0) 370 free (v->value); 371 v->value = value; 372 } 373 else 374 { 375 v->value = xrealloc (v->value, v->value_length + 1); 376 bcopy (value, v->value, v->value_length + 1); 377 } 357 378 #else 358 379 if (v->value != 0) … … 381 402 hash_insert_at (&set->table, v, var_slot); 382 403 #ifdef CONFIG_WITH_VALUE_LENGTH 383 v->value_length = strlen (value); 384 v->value = xmalloc (v->value_length + 1); 385 bcopy (value, v->value, v->value_length + 1); 404 if (value_length == ~0U) 405 value_length = strlen (value); 406 else 407 assert (value_length == strlen (value)); 408 v->value_length = value_length; 409 if (!duplicate_value) 410 v->value = value; 411 else 412 { 413 v->value = xmalloc (v->value_length + 1); 414 bcopy (value, v->value, v->value_length + 1); 415 } 386 416 #else 387 417 v->value = xstrdup (value); … … 1044 1074 v->value = xstrdup (default_shell); 1045 1075 #ifdef CONFIG_WITH_VALUE_LENGTH 1046 v->value_length = -1;1076 v->value_length = strlen (v->value); 1047 1077 #endif 1048 1078 } … … 1244 1274 int conditional = 0; 1245 1275 const size_t varname_len = strlen (varname); /* bird */ 1276 # ifdef CONFIG_WITH_VALUE_LENGTH 1277 unsigned int value_len = ~0U; 1278 # endif 1246 1279 1247 1280 /* Calculate the variable's new value in VALUE. */ … … 1308 1341 1309 1342 val = value; 1343 #ifdef CONFIG_WITH_VALUE_LENGTH 1344 if (v->recursive) 1345 { 1346 /* The previous definition of the variable was recursive. 1347 The new value is the unexpanded old and new values. */ 1348 flavor = f_recursive; 1349 oldlen = v->value_length; assert (oldlen == strlen (v->value)); 1350 vallen = strlen (val); 1351 1352 value_len = oldlen + 1 + vallen; 1353 p = alloc_value = xmalloc (value_len + 1); 1354 memcpy (p, v->value, oldlen); 1355 p[oldlen] = ' '; 1356 memcpy (&p[oldlen + 1], val, vallen + 1); 1357 } 1358 else 1359 { 1360 /* The previous definition of the variable was simple. 1361 The new value comes from the old value, which was expanded 1362 when it was set; and from the expanded new value. Allocate 1363 memory for the expansion as we may still need the rest of the 1364 buffer if we're looking at a target-specific variable. */ 1365 char *buf; 1366 unsigned int len; 1367 install_variable_buffer (&buf, &len); 1368 1369 p = variable_buffer; 1370 if ( v->value && *v->value ) 1371 { 1372 p = variable_buffer_output (p, v->value, v->value_length); 1373 p = variable_buffer_output (p, " ", 1); 1374 } 1375 p = variable_expand_string (p, val, (long)-1); 1376 1377 p = strchr (p, '\0'); /* returns adjusted start, not end. */ 1378 alloc_value = variable_buffer; 1379 value_len = p - alloc_value; 1380 p = alloc_value; 1381 1382 variable_buffer = NULL; /* hackish */ 1383 restore_variable_buffer (buf, len); 1384 } 1385 #else /* !CONFIG_WITH_VALUE_LENGTH */ 1310 1386 if (v->recursive) 1311 1387 /* The previous definition of the variable was recursive. … … 1320 1396 val = alloc_value = allocated_variable_expand (val); 1321 1397 1322 #ifdef CONFIG_WITH_VALUE_LENGTH 1323 oldlen = v->value_length; 1324 assert(oldlen == strlen (v->value)); 1325 #endif 1398 oldlen = strlen (v->value); 1326 1399 vallen = strlen (val); 1327 1400 p = (char *) alloca (oldlen + 1 + vallen + 1); … … 1329 1402 p[oldlen] = ' '; 1330 1403 bcopy (val, &p[oldlen + 1], vallen + 1); 1404 #endif /* !CONFIG_WITH_VALUE_LENGTH */ 1331 1405 } 1332 1406 } … … 1430 1504 { 1431 1505 v = define_variable_in_set (varname, varname_len, default_shell, 1506 # ifdef CONFIG_WITH_VALUE_LENGTH 1507 ~0U, 1 /* duplicate_value */, 1508 # endif 1432 1509 origin, flavor == f_recursive, 1433 1510 (target_var … … 1439 1516 else 1440 1517 v = lookup_variable (varname, varname_len); 1518 # ifdef CONFIG_WITH_VALUE_LENGTH 1519 if (alloc_value) 1520 free (alloc_value); 1521 # endif 1441 1522 } 1442 1523 else … … 1450 1531 1451 1532 v = define_variable_in_set (varname, varname_len, p, 1533 #ifdef CONFIG_WITH_VALUE_LENGTH 1534 value_len, !alloc_value, 1535 #endif 1452 1536 origin, flavor == f_recursive, 1453 1537 (target_var … … 1457 1541 v->conditional = conditional; 1458 1542 1543 #ifndef CONFIG_WITH_VALUE_LENGTH 1459 1544 if (alloc_value) 1460 1545 free (alloc_value); 1546 #endif 1461 1547 1462 1548 return v;
Note:
See TracChangeset
for help on using the changeset viewer.