Changeset 2591 for trunk/src/kmk/variable.c
- Timestamp:
- Jun 17, 2012, 10:45:31 PM (13 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk
- Property svn:ignore
-
old new 13 13 stamp-* 14 14 makebook* 15 15 16 .*gdbinit 17 .gdb_history 18 16 19 *.dep 17 20 *.dvi … … 31 34 *.pg 32 35 *.pgs 36 33 37 README 34 38 README.DOS 35 39 README.W32 40 README.OS2 36 41 aclocal.m4 37 42 autom4te.cache … … 52 57 config.h.W32 53 58 config.h-vms 59 54 60 loadavg 55 61 loadavg.c 56 62 make 63 57 64 .deps 58 65 .dep_segment 66 ID 67 TAGS 68 59 69 _* 60 70 sun4 … … 72 82 sol2 73 83 i486-linux 84 74 85 customs 86 75 87 install-sh 76 88 mkinstalldirs 89 90 .directive.asc
-
- Property svn:ignore
-
trunk/src/kmk/variable.c
r2554 r2591 1 1 /* Internals of variables for GNU Make. 2 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software4 Foundation, Inc.3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 4 2010 Free Software Foundation, Inc. 5 5 This file is part of GNU Make. 6 6 … … 47 47 static struct pattern_var *pattern_vars; 48 48 49 /* Pointer to last struct in the chain, so we can add onto the end. */ 50 51 static struct pattern_var *last_pattern_var; 52 53 /* Create a new pattern-specific variable struct. */ 49 /* Pointer to the last struct in the pack of a specific size, from 1 to 255.*/ 50 51 static struct pattern_var *last_pattern_vars[256]; 52 53 /* Create a new pattern-specific variable struct. The new variable is 54 inserted into the PATTERN_VARS list in the shortest patterns first 55 order to support the shortest stem matching (the variables are 56 matched in the reverse order so the ones with the longest pattern 57 will be considered first). Variables with the same pattern length 58 are inserted in the definition order. */ 54 59 55 60 struct pattern_var * 56 61 create_pattern_var (const char *target, const char *suffix) 57 62 { 63 register unsigned int len = strlen (target); 58 64 register struct pattern_var *p = xmalloc (sizeof (struct pattern_var)); 59 65 60 if (last_pattern_var != 0) 61 last_pattern_var->next = p; 66 if (pattern_vars != 0) 67 { 68 if (len < 256 && last_pattern_vars[len] != 0) 69 { 70 p->next = last_pattern_vars[len]->next; 71 last_pattern_vars[len]->next = p; 72 } 73 else 74 { 75 /* Find the position where we can insert this variable. */ 76 register struct pattern_var **v; 77 78 for (v = &pattern_vars; ; v = &(*v)->next) 79 { 80 /* Insert at the end of the pack so that patterns with the 81 same length appear in the order they were defined .*/ 82 83 if (*v == 0 || (*v)->len > len) 84 { 85 p->next = *v; 86 *v = p; 87 break; 88 } 89 } 90 } 91 } 62 92 else 63 pattern_vars = p; 64 last_pattern_var = p; 65 p->next = 0; 93 { 94 pattern_vars = p; 95 p->next = 0; 96 } 66 97 67 98 p->target = target; 68 p->len = strlen (target);99 p->len = len; 69 100 p->suffix = suffix + 1; 101 102 if (len < 256) 103 last_pattern_vars[len] = p; 70 104 71 105 return p; … … 170 204 static struct variable_set global_variable_set; 171 205 static struct variable_set_list global_setlist 172 = { 0, &global_variable_set };206 = { 0, &global_variable_set, 0 }; 173 207 struct variable_set_list *current_variable_set_list = &global_setlist; 174 208 … … 344 378 #endif 345 379 #ifndef CONFIG_WITH_STRCACHE2 346 v->name = savestring(name, length);380 v->name = xstrndup (name, length); 347 381 #else 348 382 v->name = name; /* already cached. */ … … 387 421 v->per_target = 0; 388 422 v->append = 0; 423 v->private_var = 0; 389 424 v->export = v_default; 390 425 MAKE_STATS_2(v->changes = 0); … … 414 449 } 415 450 451 452 453 /* Undefine variable named NAME in SET. LENGTH is the length of NAME, which 454 does not need to be null-terminated. ORIGIN specifies the origin of the 455 variable (makefile, command line or environment). */ 456 457 static void 458 free_variable_name_and_value (const void *item); 459 460 void 461 undefine_variable_in_set (const char *name, unsigned int length, 462 enum variable_origin origin, 463 struct variable_set *set) 464 { 465 struct variable *v; 466 struct variable **var_slot; 467 struct variable var_key; 468 469 if (set == NULL) 470 set = &global_variable_set; 471 472 var_key.name = (char *) name; 473 var_key.length = length; 474 var_slot = (struct variable **) hash_find_slot (&set->table, &var_key); 475 476 if (env_overrides && origin == o_env) 477 origin = o_env_override; 478 479 v = *var_slot; 480 if (! HASH_VACANT (v)) 481 { 482 if (env_overrides && v->origin == o_env) 483 /* V came from in the environment. Since it was defined 484 before the switches were parsed, it wasn't affected by -e. */ 485 v->origin = o_env_override; 486 487 /* If the definition is from a stronger source than this one, don't 488 undefine it. */ 489 if ((int) origin >= (int) v->origin) 490 { 491 hash_delete_at (&set->table, var_slot); 492 free_variable_name_and_value (v); 493 } 494 } 495 } 416 496 417 497 /* If the variable passed in is "special", handle its special nature. … … 515 595 516 596 517 #if def KMK/* bird: speed */597 #if 0 /*FIX THIS - def KMK*/ /* bird: speed */ 518 598 MY_INLINE struct variable * 519 599 lookup_cached_variable (const char *name) … … 646 726 lookup_variable (const char *name, unsigned int length) 647 727 { 648 #if ndef KMK728 #if 1 /*FIX THIS - ndef KMK*/ 649 729 const struct variable_set_list *setlist; 650 730 struct variable var_key; … … 652 732 struct variable *v; 653 733 #endif /* KMK */ 734 int is_parent = 0; 654 735 #ifdef CONFIG_WITH_STRCACHE2 655 736 const char *cached_name; … … 662 743 name = cached_name; 663 744 #endif /* CONFIG_WITH_STRCACHE2 */ 664 #if ndef KMK745 #if 1 /*FIX THIS - ndef KMK */ 665 746 666 747 var_key.name = (char *) name; … … 678 759 v = (struct variable *) hash_find_item_strcached ((struct hash_table *) &set->table, &var_key); 679 760 # endif /* CONFIG_WITH_STRCACHE2 */ 680 if (v )761 if (v && (!is_parent || !v->private_var)) 681 762 return v->special ? lookup_special_var (v) : v; 763 764 is_parent |= setlist->next_is_parent; 682 765 } 683 766 … … 747 830 #endif /* VMS */ 748 831 749 #if !defined (KMK) || defined(VMS)750 832 return 0; 751 #endif752 833 } 753 834 … … 838 919 initialize_file_variables (file->double_colon, reading); 839 920 l->next = file->double_colon->variables; 921 l->next_is_parent = 0; 840 922 return; 841 923 } … … 848 930 l->next = file->parent->variables; 849 931 } 932 l->next_is_parent = 1; 850 933 851 934 /* If we're not reading makefiles and we haven't looked yet, see if … … 900 983 v->per_target = p->variable.per_target; 901 984 v->export = p->variable.export; 985 v->private_var = p->variable.private_var; 902 986 } 903 987 while ((p = lookup_pattern_var (p, file->name)) != 0); … … 913 997 { 914 998 file->pat_variables->next = l->next; 999 file->pat_variables->next_is_parent = l->next_is_parent; 915 1000 l->next = file->pat_variables; 1001 l->next_is_parent = 0; 916 1002 } 917 1003 } … … 949 1035 setlist->set = set; 950 1036 setlist->next = current_variable_set_list; 1037 setlist->next_is_parent = 0; 951 1038 952 1039 return setlist; … … 1031 1118 global_setlist.set = setlist->set; 1032 1119 global_setlist.next = setlist->next; 1120 global_setlist.next_is_parent = setlist->next_is_parent; 1033 1121 } 1034 1122 … … 1169 1257 1170 1258 sprintf (buf, "%u", makelevel); 1171 (void) define_variable (MAKELEVEL_NAME, MAKELEVEL_LENGTH, buf, o_env, 0);1259 define_variable_cname (MAKELEVEL_NAME, buf, o_env, 0); 1172 1260 1173 1261 sprintf (buf, "%s%s%s", … … 1178 1266 ? "" : remote_description); 1179 1267 #ifndef KMK 1180 (void) define_variable ("MAKE_VERSION", 12, buf, o_default, 0);1268 define_variable_cname ("MAKE_VERSION", buf, o_default, 0); 1181 1269 #else /* KMK */ 1182 1270 1183 1271 /* Define KMK_VERSION to indicate kMk. */ 1184 (void) define_variable ("KMK_VERSION", 11, buf, o_default, 0);1272 define_variable_cname ("KMK_VERSION", buf, o_default, 0); 1185 1273 1186 1274 /* Define KBUILD_VERSION* */ 1187 1275 sprintf (buf, "%d", KBUILD_VERSION_MAJOR); 1188 define_variable ("KBUILD_VERSION_MAJOR", sizeof ("KBUILD_VERSION_MAJOR") - 1, 1189 buf, o_default, 0); 1276 define_variable_cname ("KBUILD_VERSION_MAJOR", buf, o_default, 0); 1190 1277 sprintf (buf, "%d", KBUILD_VERSION_MINOR); 1191 define_variable ("KBUILD_VERSION_MINOR", sizeof("KBUILD_VERSION_MINOR") - 1, 1192 buf, o_default, 0); 1278 define_variable_cname ("KBUILD_VERSION_MINOR", buf, o_default, 0); 1193 1279 sprintf (buf, "%d", KBUILD_VERSION_PATCH); 1194 define_variable ("KBUILD_VERSION_PATCH", sizeof ("KBUILD_VERSION_PATCH") - 1, 1195 buf, o_default, 0); 1280 define_variable_cname ("KBUILD_VERSION_PATCH", buf, o_default, 0); 1196 1281 sprintf (buf, "%d", KBUILD_SVN_REV); 1197 define_variable ("KBUILD_KMK_REVISION", sizeof ("KBUILD_KMK_REVISION") - 1, 1198 buf, o_default, 0); 1282 define_variable_cname ("KBUILD_KMK_REVISION", buf, o_default, 0); 1199 1283 1200 1284 sprintf (buf, "%d.%d.%d-r%d", KBUILD_VERSION_MAJOR, KBUILD_VERSION_MINOR, 1201 1285 KBUILD_VERSION_PATCH, KBUILD_SVN_REV); 1202 define_variable ("KBUILD_VERSION", sizeof ("KBUILD_VERSION") - 1, 1203 buf, o_default, 0); 1286 define_variable_cname ("KBUILD_VERSION", buf, o_default, 0); 1204 1287 1205 1288 /* The host defaults. The BUILD_* stuff will be replaced by KBUILD_* soon. */ … … 1210 1293 error (NULL, _("KBUILD_HOST and BUILD_PLATFORM differs, using KBUILD_HOST=%s."), val); 1211 1294 if (!envvar1) 1212 define_variable ("KBUILD_HOST", sizeof ("KBUILD_HOST") - 1, 1213 val, o_default, 0); 1295 define_variable_cname ("KBUILD_HOST", val, o_default, 0); 1214 1296 if (!envvar2) 1215 define_variable ("BUILD_PLATFORM", sizeof ("BUILD_PLATFORM") - 1, 1216 val, o_default, 0); 1297 define_variable_cname ("BUILD_PLATFORM", val, o_default, 0); 1217 1298 1218 1299 envvar1 = lookup_variable (STRING_SIZE_TUPLE ("KBUILD_HOST_ARCH")); … … 1222 1303 error (NULL, _("KBUILD_HOST_ARCH and BUILD_PLATFORM_ARCH differs, using KBUILD_HOST_ARCH=%s."), val); 1223 1304 if (!envvar1) 1224 define_variable ("KBUILD_HOST_ARCH", sizeof ("KBUILD_HOST_ARCH") - 1, 1225 val, o_default, 0); 1305 define_variable_cname ("KBUILD_HOST_ARCH", val, o_default, 0); 1226 1306 if (!envvar2) 1227 define_variable ("BUILD_PLATFORM_ARCH", sizeof ("BUILD_PLATFORM_ARCH") - 1, 1228 val, o_default, 0); 1307 define_variable_cname ("BUILD_PLATFORM_ARCH", val, o_default, 0); 1229 1308 1230 1309 envvar1 = lookup_variable (STRING_SIZE_TUPLE ("KBUILD_HOST_CPU")); … … 1234 1313 error (NULL, _("KBUILD_HOST_CPU and BUILD_PLATFORM_CPU differs, using KBUILD_HOST_CPU=%s."), val); 1235 1314 if (!envvar1) 1236 define_variable ("KBUILD_HOST_CPU", sizeof ("KBUILD_HOST_CPU") - 1, 1237 val, o_default, 0); 1315 define_variable_cname ("KBUILD_HOST_CPU", val, o_default, 0); 1238 1316 if (!envvar2) 1239 define_variable ("BUILD_PLATFORM_CPU", sizeof ("BUILD_PLATFORM_CPU") - 1, 1240 val, o_default, 0); 1317 define_variable_cname ("BUILD_PLATFORM_CPU", val, o_default, 0); 1241 1318 1242 1319 /* The host kernel version. */ … … 1277 1354 1278 1355 sprintf (buf, "%lu.%lu.%lu.%lu", ulMajor, ulMinor, ulPatch, ul4th); 1279 define_variable ("KBUILD_HOST_VERSION", sizeof ("KBUILD_HOST_VERSION") - 1, 1280 buf, o_default, 0); 1356 define_variable_cname ("KBUILD_HOST_VERSION", buf, o_default, 0); 1281 1357 1282 1358 sprintf (buf, "%lu", ulMajor); 1283 define_variable ("KBUILD_HOST_VERSION_MAJOR", sizeof ("KBUILD_HOST_VERSION_MAJOR") - 1, 1284 buf, o_default, 0); 1359 define_variable_cname ("KBUILD_HOST_VERSION_MAJOR", buf, o_default, 0); 1285 1360 1286 1361 sprintf (buf, "%lu", ulMinor); 1287 define_variable ("KBUILD_HOST_VERSION_MINOR", sizeof ("KBUILD_HOST_VERSION_MINOR") - 1, 1288 buf, o_default, 0); 1362 define_variable_cname ("KBUILD_HOST_VERSION_MINOR", buf, o_default, 0); 1289 1363 1290 1364 sprintf (buf, "%lu", ulPatch); 1291 define_variable ("KBUILD_HOST_VERSION_PATCH", sizeof ("KBUILD_HOST_VERSION_PATCH") - 1, 1292 buf, o_default, 0); 1365 define_variable_cname ("KBUILD_HOST_VERSION_PATCH", buf, o_default, 0); 1293 1366 1294 1367 /* The kBuild locations. */ 1295 define_variable ("KBUILD_PATH", sizeof ("KBUILD_PATH") - 1, 1296 get_kbuild_path (), o_default, 0); 1297 define_variable ("KBUILD_BIN_PATH", sizeof ("KBUILD_BIN_PATH") - 1, 1298 get_kbuild_bin_path (), o_default, 0); 1299 1300 define_variable ("PATH_KBUILD", sizeof ("PATH_KBUILD") - 1, 1301 get_kbuild_path (), o_default, 0); 1302 define_variable ("PATH_KBUILD_BIN", sizeof ("PATH_KBUILD_BIN") - 1, 1303 get_kbuild_bin_path (), o_default, 0); 1368 define_variable_cname ("KBUILD_PATH", get_kbuild_path (), o_default, 0); 1369 define_variable_cname ("KBUILD_BIN_PATH", get_kbuild_bin_path (), o_default, 0); 1370 1371 define_variable_cname ("PATH_KBUILD", get_kbuild_path (), o_default, 0); 1372 define_variable_cname ("PATH_KBUILD_BIN", get_kbuild_bin_path (), o_default, 0); 1304 1373 1305 1374 /* Define KMK_FEATURES to indicate various working KMK features. */ … … 1330 1399 && defined (CONFIG_WITH_DEFINED_FUNCTIONS) \ 1331 1400 && defined (KMK_HELPERS) 1332 (void) define_variable ("KMK_FEATURES", 12,1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1401 define_variable_cname ("KMK_FEATURES", 1402 "append-dash-n abspath includedep-queue install-hard-linking umask" 1403 " kBuild-define" 1404 " rsort" 1405 " abspathex" 1406 " toupper tolower" 1407 " defined" 1408 " comp-vars comp-cmds comp-cmds-ex" 1409 " stack" 1410 " math-int" 1411 " xargs" 1412 " explicit-multitarget" 1413 " dot-must-make" 1414 " prepend-assignment" 1415 " set-conditionals intersects" 1416 " date" 1417 " file-size" 1418 " expr if-expr select" 1419 " where" 1420 " which" 1421 " evalctx evalval evalvalctx evalcall evalcall2 eval-opt-var" 1422 " make-stats" 1423 " commands" 1424 " printf" 1425 " for while" 1426 " root" 1427 " length insert pos lastpos substr translate" 1428 " kb-src-tool kb-obj-base kb-obj-suff kb-src-prop kb-src-one kb-exp-tmpl" 1429 " firstdefined lastdefined" 1430 , o_default, 0); 1362 1431 # else /* MSC can't deal with strings mixed with #if/#endif, thus the slow way. */ 1363 1432 # error "All features should be enabled by default!" … … 1442 1511 strcat (buf, " kb-src-tool kb-obj-base kb-obj-suff kb-src-prop kb-src-one kb-exp-tmpl"); 1443 1512 # endif 1444 (void) define_variable ("KMK_FEATURES", 12, buf, o_default, 0);1513 define_variable_cname ("KMK_FEATURES", buf, o_default, 0); 1445 1514 # endif 1446 1515 … … 1449 1518 #ifdef CONFIG_WITH_KMK_BUILTIN 1450 1519 /* The supported kMk Builtin commands. */ 1451 (void) define_variable ("KMK_BUILTIN", 11, "append cat chmod cp cmp echo expr install kDepIDB ln md5sum mkdir mv printf rm rmdir sleep test", o_default, 0);1520 define_variable_cname ("KMK_BUILTIN", "append cat chmod cp cmp echo expr install kDepIDB ln md5sum mkdir mv printf rm rmdir sleep test", o_default, 0); 1452 1521 #endif 1453 1522 … … 1461 1530 struct variable *comp = lookup_variable ("COMSPEC", 7); 1462 1531 1463 /* Make $MAKESHELL override $SHELLeven if -e is in effect. */1532 /* $(MAKESHELL) overrides $(SHELL) even if -e is in effect. */ 1464 1533 if (mshp) 1465 1534 (void) define_variable (shell_str, shlen, … … 1467 1536 else if (comp) 1468 1537 { 1469 /* $ COMSPEC shouldn't override $SHELL. */1538 /* $(COMSPEC) shouldn't override $(SHELL). */ 1470 1539 struct variable *shp = lookup_variable (shell_str, shlen); 1471 1540 … … 1526 1595 /* This won't override any definition, but it will provide one if there 1527 1596 isn't one there. */ 1528 v = define_variable ("SHELL", 5, default_shell, o_default, 0);1597 v = define_variable_cname ("SHELL", default_shell, o_default, 0); 1529 1598 #ifdef __MSDOS__ 1530 1599 v->export = v_export; /* Export always SHELL. */ … … 1555 1624 1556 1625 /* Make sure MAKEFILES gets exported if it is set. */ 1557 v = define_variable ("MAKEFILES", 9, "", o_default, 0);1626 v = define_variable_cname ("MAKEFILES", "", o_default, 0); 1558 1627 v->export = v_ifset; 1559 1628 … … 1562 1631 1563 1632 #ifdef VMS 1564 define_variable ("@D", 2, "$(dir $@)", o_automatic, 1);1565 define_variable ("%D", 2, "$(dir $%)", o_automatic, 1);1566 define_variable ("*D", 2, "$(dir $*)", o_automatic, 1);1567 define_variable ("<D", 2, "$(dir $<)", o_automatic, 1);1568 define_variable ("?D", 2, "$(dir $?)", o_automatic, 1);1569 define_variable ("^D", 2, "$(dir $^)", o_automatic, 1);1570 define_variable ("+D", 2, "$(dir $+)", o_automatic, 1);1633 define_variable_cname ("@D", "$(dir $@)", o_automatic, 1); 1634 define_variable_cname ("%D", "$(dir $%)", o_automatic, 1); 1635 define_variable_cname ("*D", "$(dir $*)", o_automatic, 1); 1636 define_variable_cname ("<D", "$(dir $<)", o_automatic, 1); 1637 define_variable_cname ("?D", "$(dir $?)", o_automatic, 1); 1638 define_variable_cname ("^D", "$(dir $^)", o_automatic, 1); 1639 define_variable_cname ("+D", "$(dir $+)", o_automatic, 1); 1571 1640 #else 1572 define_variable ("@D", 2, "$(patsubst %/,%,$(dir $@))", o_automatic, 1);1573 define_variable ("%D", 2, "$(patsubst %/,%,$(dir $%))", o_automatic, 1);1574 define_variable ("*D", 2, "$(patsubst %/,%,$(dir $*))", o_automatic, 1);1575 define_variable ("<D", 2, "$(patsubst %/,%,$(dir $<))", o_automatic, 1);1576 define_variable ("?D", 2, "$(patsubst %/,%,$(dir $?))", o_automatic, 1);1577 define_variable ("^D", 2, "$(patsubst %/,%,$(dir $^))", o_automatic, 1);1578 define_variable ("+D", 2, "$(patsubst %/,%,$(dir $+))", o_automatic, 1);1579 #endif 1580 define_variable ("@F", 2, "$(notdir $@)", o_automatic, 1);1581 define_variable ("%F", 2, "$(notdir $%)", o_automatic, 1);1582 define_variable ("*F", 2, "$(notdir $*)", o_automatic, 1);1583 define_variable ("<F", 2, "$(notdir $<)", o_automatic, 1);1584 define_variable ("?F", 2, "$(notdir $?)", o_automatic, 1);1585 define_variable ("^F", 2, "$(notdir $^)", o_automatic, 1);1586 define_variable ("+F", 2, "$(notdir $+)", o_automatic, 1);1641 define_variable_cname ("@D", "$(patsubst %/,%,$(dir $@))", o_automatic, 1); 1642 define_variable_cname ("%D", "$(patsubst %/,%,$(dir $%))", o_automatic, 1); 1643 define_variable_cname ("*D", "$(patsubst %/,%,$(dir $*))", o_automatic, 1); 1644 define_variable_cname ("<D", "$(patsubst %/,%,$(dir $<))", o_automatic, 1); 1645 define_variable_cname ("?D", "$(patsubst %/,%,$(dir $?))", o_automatic, 1); 1646 define_variable_cname ("^D", "$(patsubst %/,%,$(dir $^))", o_automatic, 1); 1647 define_variable_cname ("+D", "$(patsubst %/,%,$(dir $+))", o_automatic, 1); 1648 #endif 1649 define_variable_cname ("@F", "$(notdir $@)", o_automatic, 1); 1650 define_variable_cname ("%F", "$(notdir $%)", o_automatic, 1); 1651 define_variable_cname ("*F", "$(notdir $*)", o_automatic, 1); 1652 define_variable_cname ("<F", "$(notdir $<)", o_automatic, 1); 1653 define_variable_cname ("?F", "$(notdir $?)", o_automatic, 1); 1654 define_variable_cname ("^F", "$(notdir $^)", o_automatic, 1); 1655 define_variable_cname ("+F", "$(notdir $+)", o_automatic, 1); 1587 1656 #ifdef CONFIG_WITH_LAZY_DEPS_VARS 1588 1657 define_variable ("^", 1, "$(deps $@)", o_automatic, 1); … … 1753 1822 convert_Path_to_windows32(value, ';'); 1754 1823 #endif 1755 *result++ = xstrdup (concat ( v->name, "=", value));1824 *result++ = xstrdup (concat (3, v->name, "=", value)); 1756 1825 free (value); 1757 1826 } … … 1763 1832 convert_Path_to_windows32(v->value, ';'); 1764 1833 #endif 1765 *result++ = xstrdup (concat ( v->name, "=", v->value));1834 *result++ = xstrdup (concat (3, v->name, "=", v->value)); 1766 1835 } 1767 1836 } … … 1954 2023 value_len = strlen (value); 1955 2024 if (!free_value) 1956 p = alloc_value = savestring(value, value_len);2025 p = alloc_value = xstrndup (value, value_len); 1957 2026 else 1958 2027 { … … 2048 2117 unsigned int oldlen, vallen; 2049 2118 const char *val; 2050 char *tp ;2119 char *tp = NULL; 2051 2120 2052 2121 val = value; … … 2061 2130 memory for the expansion as we may still need the rest of the 2062 2131 buffer if we're looking at a target-specific variable. */ 2063 val = alloc_value= allocated_variable_expand (val);2132 val = tp = allocated_variable_expand (val); 2064 2133 2065 2134 oldlen = strlen (v->value); 2066 2135 vallen = strlen (val); 2067 tp = alloca(oldlen + 1 + vallen + 1);2136 p = alloc_value = xmalloc (oldlen + 1 + vallen + 1); 2068 2137 # ifdef CONFIG_WITH_PREPEND_ASSIGNMENT 2069 2138 if (org_flavor == f_prepend) 2070 2139 { 2071 memcpy ( tp, val, vallen);2072 tp[oldlen] = ' ';2073 memcpy (& tp[oldlen + 1], v->value, oldlen + 1);2140 memcpy (alloc_value, val, vallen); 2141 alloc_value[oldlen] = ' '; 2142 memcpy (&alloc_value[oldlen + 1], v->value, oldlen + 1); 2074 2143 } 2075 2144 else 2076 2145 # endif /* CONFIG_WITH_PREPEND_ASSIGNMENT */ 2077 2146 { 2078 memcpy ( tp, v->value, oldlen);2079 tp[oldlen] = ' ';2080 memcpy (& tp[oldlen + 1], val, vallen + 1);2147 memcpy (alloc_value, v->value, oldlen); 2148 alloc_value[oldlen] = ' '; 2149 memcpy (&alloc_value[oldlen + 1], val, vallen + 1); 2081 2150 } 2082 p = tp; 2151 2152 if (tp) 2153 free (tp); 2083 2154 #endif /* !CONFIG_WITH_VALUE_LENGTH */ 2084 2155 } … … 2193 2264 else 2194 2265 { 2195 if (alloc_value) 2196 free (alloc_value); 2266 char *tp = alloc_value; 2197 2267 2198 2268 alloc_value = allocated_variable_expand (p); 2269 2199 2270 if (find_and_set_default_shell (alloc_value)) 2200 2271 { … … 2212 2283 else 2213 2284 v = lookup_variable (varname, varname_len); 2285 2286 if (tp) 2287 free (tp); 2214 2288 } 2215 2289 } … … 2250 2324 2251 2325 2252 /* Try to interpret LINE (a null-terminated string) as a variable definition. 2253 2254 ORIGIN may be o_file, o_override, o_env, o_env_override, 2255 or o_command specifying that the variable definition comes 2256 from a makefile, an override directive, the environment with 2257 or without the -e switch, or the command line. 2258 2259 See the comments for parse_variable_definition(). 2260 2261 If LINE was recognized as a variable definition, a pointer to its `struct 2262 variable' is returned. If LINE is not a variable definition, NULL is 2263 returned. */ 2264 2265 struct variable * 2266 #ifndef CONFIG_WITH_VALUE_LENGTH 2267 parse_variable_definition (struct variable *v, char *line) 2268 #else 2269 parse_variable_definition (struct variable *v, char *line, char *eos) 2270 #endif 2271 { 2272 register int c; 2273 register char *p = line; 2274 register char *beg; 2275 register char *end; 2276 enum variable_flavor flavor = f_bogus; 2277 #ifndef CONFIG_WITH_VALUE_LENGTH 2278 char *name; 2279 #endif 2326 /* Parse P (a null-terminated string) as a variable definition. 2327 2328 If it is not a variable definition, return NULL. 2329 2330 If it is a variable definition, return a pointer to the char after the 2331 assignment token and set *FLAVOR to the type of variable assignment. */ 2332 2333 char * 2334 parse_variable_definition (const char *p, enum variable_flavor *flavor) 2335 { 2336 int wspace = 0; 2337 2338 p = next_token (p); 2280 2339 2281 2340 while (1) 2282 2341 { 2283 c = *p++; 2342 int c = *p++; 2343 2344 /* If we find a comment or EOS, it's not a variable definition. */ 2284 2345 if (c == '\0' || c == '#') 2285 return 0; 2286 if (c == '=') 2346 return NULL; 2347 2348 if (c == '$') 2287 2349 { 2288 end = p - 1; 2289 flavor = f_recursive; 2290 break; 2291 } 2292 else if (c == ':') 2293 if (*p == '=') 2294 { 2295 end = p++ - 1; 2296 flavor = f_simple; 2297 break; 2298 } 2299 else 2300 /* A colon other than := is a rule line, not a variable defn. */ 2301 return 0; 2302 else if (c == '+' && *p == '=') 2303 { 2304 end = p++ - 1; 2305 flavor = f_append; 2306 break; 2307 } 2308 #ifdef CONFIG_WITH_PREPEND_ASSIGNMENT 2309 else if (c == '<' && *p == '=') 2310 { 2311 end = p++ - 1; 2312 flavor = f_prepend; 2313 break; 2314 } 2315 #endif 2316 else if (c == '?' && *p == '=') 2317 { 2318 end = p++ - 1; 2319 flavor = f_conditional; 2320 break; 2321 } 2322 else if (c == '$') 2323 { 2324 /* This might begin a variable expansion reference. Make sure we 2325 don't misrecognize chars inside the reference as =, := or +=. */ 2350 /* This begins a variable expansion reference. Make sure we don't 2351 treat chars inside the reference as assignment tokens. */ 2326 2352 char closeparen; 2327 2353 int count; … … 2332 2358 closeparen = '}'; 2333 2359 else 2334 continue; /* Nope. */ 2360 /* '$$' or '$X'. Either way, nothing special to do here. */ 2361 continue; 2335 2362 2336 2363 /* P now points past the opening paren or brace. … … 2347 2374 } 2348 2375 } 2376 continue; 2349 2377 } 2350 } 2351 v->flavor = flavor; 2378 2379 /* If we find whitespace skip it, and remember we found it. */ 2380 if (isblank ((unsigned char)c)) 2381 { 2382 wspace = 1; 2383 p = next_token (p); 2384 c = *p; 2385 if (c == '\0') 2386 return NULL; 2387 ++p; 2388 } 2389 2390 2391 if (c == '=') 2392 { 2393 *flavor = f_recursive; 2394 return (char *)p; 2395 } 2396 2397 /* Match assignment variants (:=, +=, ?=) */ 2398 if (*p == '=') 2399 { 2400 switch (c) 2401 { 2402 case ':': 2403 *flavor = f_simple; 2404 break; 2405 case '+': 2406 *flavor = f_append; 2407 break; 2408 #ifdef CONFIG_WITH_PREPEND_ASSIGNMENT 2409 case '<': 2410 *flavor = f_prepend; 2411 break; 2412 #endif 2413 case '?': 2414 *flavor = f_conditional; 2415 break; 2416 default: 2417 /* If we skipped whitespace, non-assignments means no var. */ 2418 if (wspace) 2419 return NULL; 2420 2421 /* Might be assignment, or might be $= or #=. Check. */ 2422 continue; 2423 } 2424 return (char *)++p; 2425 } 2426 else if (c == ':') 2427 /* A colon other than := is a rule line, not a variable defn. */ 2428 return NULL; 2429 2430 /* If we skipped whitespace, non-assignments means no var. */ 2431 if (wspace) 2432 return NULL; 2433 } 2434 2435 return (char *)p; 2436 } 2437 2438 2439 /* Try to interpret LINE (a null-terminated string) as a variable definition. 2440 2441 If LINE was recognized as a variable definition, a pointer to its `struct 2442 variable' is returned. If LINE is not a variable definition, NULL is 2443 returned. */ 2444 2445 struct variable * 2446 assign_variable_definition (struct variable *v, char *line IF_WITH_VALUE_LENGTH_PARAM(char *eos)) 2447 { 2448 char *beg; 2449 char *end; 2450 enum variable_flavor flavor; 2451 #ifndef CONFIG_WITH_VALUE_LENGTH 2452 char *name; 2453 #endif 2352 2454 2353 2455 beg = next_token (line); 2456 line = parse_variable_definition (beg, &flavor); 2457 if (!line) 2458 return NULL; 2459 2460 end = line - (flavor == f_recursive ? 1 : 2); 2354 2461 while (end > beg && isblank ((unsigned char)end[-1])) 2355 2462 --end; 2356 p = next_token (p); 2357 v->value = p; 2463 line = next_token (line); 2464 v->value = line; 2465 v->flavor = flavor; 2358 2466 #ifdef CONFIG_WITH_VALUE_LENGTH 2359 2467 v->value_alloc_len = ~(unsigned int)0; 2360 v->value_length = eos != NULL ? eos - p: -1;2361 assert (eos == NULL || strchr ( p, '\0') == eos);2468 v->value_length = eos != NULL ? eos - line : -1; 2469 assert (eos == NULL || strchr (line, '\0') == eos); 2362 2470 # ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE 2363 2471 v->rdonly_val = 0; … … 2389 2497 or without the -e switch, or the command line. 2390 2498 2391 See the comments for parse_variable_definition().2499 See the comments for assign_variable_definition(). 2392 2500 2393 2501 If LINE was recognized as a variable definition, a pointer to its `struct … … 2396 2504 2397 2505 struct variable * 2398 #ifndef CONFIG_WITH_VALUE_LENGTH 2399 try_variable_definition (const struct floc *flocp, char *line,2506 try_variable_definition (const struct floc *flocp, char *line 2507 IF_WITH_VALUE_LENGTH_PARAM(char *eos), 2400 2508 enum variable_origin origin, int target_var) 2401 #else2402 try_variable_definition (const struct floc *flocp, char *line, char *eos,2403 enum variable_origin origin, int target_var)2404 #endif2405 2509 { 2406 2510 struct variable v; … … 2413 2517 2414 2518 #ifndef CONFIG_WITH_VALUE_LENGTH 2415 if (! parse_variable_definition (&v, line))2519 if (!assign_variable_definition (&v, line)) 2416 2520 return 0; 2417 2521 … … 2419 2523 origin, v.flavor, target_var); 2420 2524 #else 2421 if (! parse_variable_definition (&v, line, eos))2525 if (!assign_variable_definition (&v, line, eos)) 2422 2526 return 0; 2423 2527 … … 2486 2590 fputs ("# ", stdout); 2487 2591 fputs (origin, stdout); 2592 if (v->private_var) 2593 fputs (" private", stdout); 2488 2594 if (v->fileinfo.filenm) 2489 2595 printf (_(" (from `%s', line %lu)"), … … 2514 2620 else 2515 2621 { 2516 registerchar *p;2622 char *p; 2517 2623 2518 2624 printf ("%s %s= ", v->name, v->recursive ? v->append ? "+" : "" : ":"); … … 2660 2766 */ 2661 2767 convert_Path_to_windows32 (path, ';'); 2662 environ_path = xstrdup (concat ( "PATH", "=", path));2768 environ_path = xstrdup (concat (3, "PATH", "=", path)); 2663 2769 putenv (environ_path); 2664 2770 free (path);
Note:
See TracChangeset
for help on using the changeset viewer.