Changeset 903 for trunk/src/gmakenew/variable.c
- Timestamp:
- May 23, 2007, 7:31:19 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmakenew/variable.c
r821 r903 43 43 44 44 struct pattern_var * 45 create_pattern_var (char *target, char *suffix) 46 { 47 register struct pattern_var *p 48 = (struct pattern_var *) xmalloc (sizeof (struct pattern_var)); 45 create_pattern_var (const char *target, const char *suffix) 46 { 47 register struct pattern_var *p = xmalloc (sizeof (struct pattern_var)); 49 48 50 49 if (last_pattern_var != 0) … … 65 64 66 65 static struct pattern_var * 67 lookup_pattern_var (struct pattern_var *start, c har *target)66 lookup_pattern_var (struct pattern_var *start, const char *target) 68 67 { 69 68 struct pattern_var *p; … … 72 71 for (p = start ? start->next : pattern_vars; p != 0; p = p->next) 73 72 { 74 c har *stem;73 const char *stem; 75 74 unsigned int stemlen; 76 75 … … 278 277 279 278 #ifndef VARIABLE_BUCKETS 279 # ifdef KMK /* Move to Makefile.kmk? */ 280 # define VARIABLE_BUCKETS 16384 281 # else /*!KMK*/ 280 282 #define VARIABLE_BUCKETS 523 283 # endif /*!KMK*/ 281 284 #endif 282 285 #ifndef PERFILE_VARIABLE_BUCKETS … … 298 301 init_hash_global_variable_set (void) 299 302 { 300 hash_init (&global_variable_set.table, 301 #ifdef KMK /* FIMXE: just redefine the bucket size! */ 302 16384, 303 #else 304 VARIABLE_BUCKETS, 305 #endif 303 hash_init (&global_variable_set.table, VARIABLE_BUCKETS, 306 304 variable_hash_1, variable_hash_2, variable_hash_cmp); 307 305 } … … 317 315 struct variable * 318 316 define_variable_in_set (const char *name, unsigned int length, 319 c har *value, unsigned int value_length, int duplicate_value,317 const char *value, unsigned int value_length, int duplicate_value, 320 318 enum variable_origin origin, int recursive, 321 319 struct variable_set *set, const struct floc *flocp) … … 323 321 struct variable * 324 322 define_variable_in_set (const char *name, unsigned int length, 325 c har *value, enum variable_origin origin,323 const char *value, enum variable_origin origin, 326 324 int recursive, struct variable_set *set, 327 325 const struct floc *flocp) … … 368 366 if (v->value != 0) 369 367 free (v->value); 370 v->value = value;368 v->value = (char *)value; 371 369 v->value_alloc_len = value_length + 1; 372 370 } … … 399 397 /* Create a new variable definition and add it to the hash table. */ 400 398 401 v = (struct variable *)xmalloc (sizeof (struct variable));399 v = xmalloc (sizeof (struct variable)); 402 400 v->name = savestring (name, length); 403 401 v->length = length; … … 416 414 { 417 415 v->value_alloc_len = value_length + 1; 418 v->value = value;416 v->value = (char *)value; 419 417 } 420 418 else … … 531 529 } 532 530 533 bcopy (v->name, p, l);531 memcpy (p, v->name, l); 534 532 p += l; 535 533 *(p++) = ' '; … … 698 696 parent of FILE's variable set. 699 697 700 If we're READ inga makefile, don't do the pattern variable search now,698 If we're READING a makefile, don't do the pattern variable search now, 701 699 since the pattern variable might not have been defined yet. */ 702 700 … … 710 708 l = (struct variable_set_list *) 711 709 xmalloc (sizeof (struct variable_set_list)); 712 l->set = (struct variable_set *)xmalloc (sizeof (struct variable_set));710 l->set = xmalloc (sizeof (struct variable_set)); 713 711 hash_init (&l->set->table, PERFILE_VARIABLE_BUCKETS, 714 712 variable_hash_1, variable_hash_2, variable_hash_cmp); … … 806 804 register struct variable_set *set; 807 805 808 set = (struct variable_set *)xmalloc (sizeof (struct variable_set));806 set = xmalloc (sizeof (struct variable_set)); 809 807 hash_init (&set->table, SMALL_SCOPE_VARIABLE_BUCKETS, 810 808 variable_hash_1, variable_hash_2, variable_hash_cmp); … … 831 829 hash_map (&list->set->table, free_variable_name_and_value); 832 830 hash_free (&list->set->table, 1); 833 free ( (char *)list->set);834 free ( (char *)list);831 free (list->set); 832 free (list); 835 833 } 836 834 … … 888 886 889 887 /* Free the one we no longer need. */ 890 free ( (char *)setlist);888 free (setlist); 891 889 hash_map (&set->table, free_variable_name_and_value); 892 890 hash_free (&set->table, 1); 893 free ( (char *)set);891 free (set); 894 892 } 895 893 … … 1036 1034 /* Define KMK_FEATURES to indicate various working KMK features. */ 1037 1035 # if defined(CONFIG_WITH_TOUPPER_TOLOWER) \ 1036 && defined(CONFIG_WITH_RSORT) \ 1038 1037 && defined(CONFIG_WITH_ABSPATHEX) \ 1039 1038 && defined(CONFIG_WITH_VALUE_LENGTH) && defined(CONFIG_WITH_COMPARE) \ … … 1043 1042 && defined(KMK_HELPERS) 1044 1043 (void) define_variable ("KMK_FEATURES", 12, 1045 "append-dash-n " 1046 "abspath abspathex" 1044 "append-dash-n abspath" 1045 " rsort" 1046 " abspathex" 1047 1047 " toupper tolower" 1048 1048 " comp-vars comp-cmds" … … 1054 1054 # else /* MSC can't deal with strings mixed with #if/#endif, thus the slow way. */ 1055 1055 strcpy(buf, "append-dash-n abspath"); 1056 # if defined(CONFIG_WITH_RSORT) 1057 strcat(buf, " rsort"); 1058 # endif 1056 1059 # if defined(CONFIG_WITH_ABSPATHEX) 1057 1060 strcat(buf, " abspathex"); … … 1316 1319 hash_delete (&table, &makelevel_key); 1317 1320 1318 result = result_0 = (char **)xmalloc ((table.ht_fill + 2) * sizeof (char *));1321 result = result_0 = xmalloc ((table.ht_fill + 2) * sizeof (char *)); 1319 1322 1320 1323 v_slot = (struct variable **) table.ht_vec; … … 1337 1340 convert_Path_to_windows32(value, ';'); 1338 1341 #endif 1339 *result++ = concat (v->name, "=", value);1342 *result++ = xstrdup (concat (v->name, "=", value)); 1340 1343 free (value); 1341 1344 } … … 1347 1350 convert_Path_to_windows32(v->value, ';'); 1348 1351 #endif 1349 *result++ = concat (v->name, "=", v->value);1352 *result++ = xstrdup (concat (v->name, "=", v->value)); 1350 1353 } 1351 1354 } 1352 1355 1353 *result = (char *)xmalloc (100);1354 (void)sprintf (*result, "%s=%u", MAKELEVEL_NAME, makelevel + 1);1356 *result = xmalloc (100); 1357 sprintf (*result, "%s=%u", MAKELEVEL_NAME, makelevel + 1); 1355 1358 *++result = 0; 1356 1359 … … 1363 1366 #ifdef CONFIG_WITH_VALUE_LENGTH 1364 1367 static struct variable * 1365 do_variable_definition_append (const struct floc *flocp, struct variable *v, c har *value,1368 do_variable_definition_append (const struct floc *flocp, struct variable *v, const char *value, 1366 1369 enum variable_origin origin) 1367 1370 { … … 1430 1433 struct variable * 1431 1434 do_variable_definition (const struct floc *flocp, const char *varname, 1432 c har *value, enum variable_origin origin,1435 const char *value, enum variable_origin origin, 1433 1436 enum variable_flavor flavor, int target_var) 1434 1437 { 1435 char *p, *alloc_value = NULL; 1438 const char *p; 1439 char *alloc_value = NULL; 1436 1440 struct variable *v; 1437 1441 int append = 0; … … 1507 1511 1508 1512 unsigned int oldlen, vallen; 1509 char *val; 1513 const char *val; 1514 char *tp; 1510 1515 1511 1516 val = value; … … 1524 1529 oldlen = strlen (v->value); 1525 1530 vallen = strlen (val); 1526 p = (char *) alloca (oldlen + 1 + vallen + 1); 1527 bcopy (v->value, p, oldlen); 1528 p[oldlen] = ' '; 1529 bcopy (val, &p[oldlen + 1], vallen + 1); 1531 tp = alloca (oldlen + 1 + vallen + 1); 1532 memcpy (tp, v->value, oldlen); 1533 tp[oldlen] = ' '; 1534 memcpy (&tp[oldlen + 1], val, vallen + 1); 1535 p = tp; 1530 1536 #endif /* !CONFIG_WITH_VALUE_LENGTH */ 1531 1537 } … … 1554 1560 1555 1561 /* See if we can find "/bin/sh.exe", "/bin/sh.com", etc. */ 1556 if (__dosexec_find_on_path (p, (char **)0, shellpath))1562 if (__dosexec_find_on_path (p, NULL, shellpath)) 1557 1563 { 1558 char *p; 1559 1560 for (p = shellpath; *p; p++) 1561 { 1562 if (*p == '\\') 1563 *p = '/'; 1564 } 1564 char *tp; 1565 1566 for (tp = shellpath; *tp; tp++) 1567 if (*tp == '\\') 1568 *tp = '/'; 1569 1565 1570 v = define_variable_loc (varname, varname_len, 1566 1571 shellpath, origin, flavor == f_recursive, … … 1569 1574 else 1570 1575 { 1571 c har *shellbase, *bslash;1576 const char *shellbase, *bslash; 1572 1577 struct variable *pathv = lookup_variable ("PATH", 4); 1573 1578 char *path_string; … … 1590 1595 if (pathv) 1591 1596 pathlen = strlen (pathv->value); 1592 path_string = (char *)xmalloc (5 + pathlen + 2 + 1);1597 path_string = xmalloc (5 + pathlen + 2 + 1); 1593 1598 /* On MSDOS, current directory is considered as part of $PATH. */ 1594 1599 sprintf (path_string, "PATH=.;%s", pathv ? pathv->value : ""); 1595 1600 fake_env[0] = path_string; 1596 fake_env[1] = (char *)0;1601 fake_env[1] = 0; 1597 1602 if (__dosexec_find_on_path (shellbase, fake_env, shellpath)) 1598 1603 { 1599 char *p; 1600 1601 for (p = shellpath; *p; p++) 1602 { 1603 if (*p == '\\') 1604 *p = '/'; 1605 } 1604 char *tp; 1605 1606 for (tp = shellpath; *tp; tp++) 1607 if (*tp == '\\') 1608 *tp = '/'; 1609 1606 1610 v = define_variable_loc (varname, varname_len, 1607 1611 shellpath, origin, … … 1773 1777 1774 1778 /* Expand the name, so "$(foo)bar = baz" works. */ 1775 name = (char *)alloca (end - beg + 1);1776 bcopy (beg, name, end - beg);1779 name = alloca (end - beg + 1); 1780 memcpy (name, beg, end - beg); 1777 1781 name[end - beg] = '\0'; 1778 1782 v->name = allocated_variable_expand (name); … … 1827 1831 print_variable (const void *item, void *arg) 1828 1832 { 1829 const struct variable *v = (struct variable *)item;1830 const char *prefix = (char *)arg;1833 const struct variable *v = item; 1834 const char *prefix = arg; 1831 1835 const char *origin; 1832 1836 … … 1942 1946 1943 1947 void 1944 print_file_variables ( struct file *file)1948 print_file_variables (const struct file *file) 1945 1949 { 1946 1950 if (file->variables != 0) … … 1969 1973 */ 1970 1974 convert_Path_to_windows32 (path, ';'); 1971 environ_path = concat ("PATH", "=", path);1975 environ_path = xstrdup (concat ("PATH", "=", path)); 1972 1976 putenv (environ_path); 1973 1977 free (path);
Note:
See TracChangeset
for help on using the changeset viewer.