Changeset 903 for trunk/src/gmakenew/read.c
- Timestamp:
- May 23, 2007, 7:31:19 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmakenew/read.c
r530 r903 38 38 #include <pwd.h> 39 39 #else 40 struct passwd *getpwnam PARAMS ((char *name));40 struct passwd *getpwnam (char *name); 41 41 #endif 42 42 #endif … … 89 89 /* Default directories to search for include files in */ 90 90 91 static c har *default_include_directories[] =91 static const char *default_include_directories[] = 92 92 { 93 93 #if defined(WINDOWS32) && !defined(INCLUDEDIR) 94 /* 95 * This completely up to the user when they install MSVC or other packages. 96 * This is defined as a placeholder. 97 */ 98 #define INCLUDEDIR "." 94 /* This completely up to the user when they install MSVC or other packages. 95 This is defined as a placeholder. */ 96 # define INCLUDEDIR "." 99 97 #endif 100 98 INCLUDEDIR, … … 109 107 /* List of directories to search for include files in */ 110 108 111 static c har **include_directories;109 static const char **include_directories; 112 110 113 111 /* Maximum length of an element of the above. */ … … 124 122 static struct dep *read_makefiles = 0; 125 123 126 static int eval_makefile PARAMS ((char *filename, int flags)); 127 static int eval PARAMS ((struct ebuffer *buffer, int flags)); 128 129 static long readline PARAMS ((struct ebuffer *ebuf)); 130 static void do_define PARAMS ((char *name, unsigned int namelen, 131 enum variable_origin origin, 132 struct ebuffer *ebuf)); 133 static int conditional_line PARAMS ((char *line, int len, const struct floc *flocp)); 134 static void record_files PARAMS ((struct nameseq *filenames, char *pattern, char *pattern_percent, 135 struct dep *deps, unsigned int cmds_started, char *commands, 136 unsigned int commands_idx, int two_colon, 137 const struct floc *flocp)); 138 static void record_target_var PARAMS ((struct nameseq *filenames, char *defn, 139 enum variable_origin origin, 140 int enabled, 141 const struct floc *flocp)); 142 static enum make_word_type get_next_mword PARAMS ((char *buffer, char *delim, 143 char **startp, unsigned int *length)); 144 static void remove_comments PARAMS ((char *line)); 145 static char *find_char_unquote PARAMS ((char *string, int stop1, 146 int stop2, int blank, int ignorevars)); 124 static int eval_makefile (const char *filename, int flags); 125 static int eval (struct ebuffer *buffer, int flags); 126 127 static long readline (struct ebuffer *ebuf); 128 static void do_define (char *name, unsigned int namelen, 129 enum variable_origin origin, struct ebuffer *ebuf); 130 static int conditional_line (char *line, int len, const struct floc *flocp); 131 static void record_files (struct nameseq *filenames, const char *pattern, 132 const char *pattern_percent, struct dep *deps, 133 unsigned int cmds_started, char *commands, 134 unsigned int commands_idx, int two_colon, 135 const struct floc *flocp); 136 static void record_target_var (struct nameseq *filenames, char *defn, 137 enum variable_origin origin, int enabled, 138 const struct floc *flocp); 139 static enum make_word_type get_next_mword (char *buffer, char *delim, 140 char **startp, unsigned int *length); 141 static void remove_comments (char *line); 142 static char *find_char_unquote (char *string, int stop1, int stop2, 143 int blank, int ignorevars); 147 144 148 145 … … 150 147 151 148 struct dep * 152 read_all_makefiles (c har **makefiles)149 read_all_makefiles (const char **makefiles) 153 150 { 154 151 unsigned int num_makefiles = 0; … … 184 181 p = value; 185 182 186 while ((name = find_next_token ( &p, &length)) != 0)183 while ((name = find_next_token ((const char **)&p, &length)) != 0) 187 184 { 188 185 if (*p != '\0') … … 227 224 # else 228 225 { "makefile.vms", "gnumakefile.", "makefile.", 0 }; 229 # endif 226 # endif 230 227 #else 231 228 #ifdef _AMIGA … … 264 261 { 265 262 struct dep *d = alloc_dep (); 266 d->file = enter_file ( *p);263 d->file = enter_file (strcache_add (*p)); 267 264 d->file->dontcare = 1; 268 265 /* Tell update_goal_chain to bail out as soon as this file is … … 291 288 struct conditionals *save = conditionals; 292 289 293 bzero ((char *) new, sizeof (*new));290 memset (new, '\0', sizeof (*new)); 294 291 conditionals = new; 295 292 … … 314 311 315 312 static int 316 eval_makefile (c har *filename, int flags)313 eval_makefile (const char *filename, int flags) 317 314 { 318 315 struct dep *deps; … … 320 317 const struct floc *curfile; 321 318 char *expanded = 0; 322 char *included = 0;323 319 int makefile_errno; 324 320 int r; 325 321 326 ebuf.floc.filenm = strcache_add (filename); 322 filename = strcache_add (filename); 323 ebuf.floc.filenm = filename; 327 324 ebuf.floc.lineno = 1; 328 325 … … 361 358 if (ebuf.fp == 0 && (flags & RM_INCLUDED) && *filename != '/') 362 359 { 363 registerunsigned int i;360 unsigned int i; 364 361 for (i = 0; include_directories[i] != 0; ++i) 365 362 { 366 included = concat (include_directories[i], "/", filename);363 const char *included = concat (include_directories[i], "/", filename); 367 364 ebuf.fp = fopen (included, "r"); 368 365 if (ebuf.fp) 369 366 { 370 filename = included;367 filename = strcache_add (included); 371 368 break; 372 369 } 373 free (included);374 370 } 375 /* If we're not using it, we already freed it above. */376 if (filename != included)377 included = 0;378 371 } 379 372 … … 384 377 deps->file = lookup_file (filename); 385 378 if (deps->file == 0) 386 deps->file = enter_file ( xstrdup (filename));379 deps->file = enter_file (filename); 387 380 filename = deps->file->name; 388 381 deps->changed = flags; … … 392 385 if (expanded) 393 386 free (expanded); 394 if (included)395 free (included);396 387 397 388 /* If the makefile can't be found at all, give up entirely. */ … … 463 454 #ifdef CONFIG_WITH_INCLUDEDEP 464 455 /* no nonsense dependency file including. */ 465 void 466 eval_include_dep (char *name, struct floc *f)456 void 457 eval_include_dep (const char *name, struct floc *f) 467 458 { 468 459 FILE *fp; … … 501 492 } 502 493 503 /* allocate a buffer and read the file. \r\n -> \n conversion 494 /* allocate a buffer and read the file. \r\n -> \n conversion 504 495 make this intersting ... */ 505 496 buf = xmalloc (max_size + 1); … … 544 535 long nlines = 0; 545 536 int two_colon = 0; 546 char *pattern = 0, *pattern_percent; 537 const char *pattern = 0; 538 const char *pattern_percent; 547 539 struct floc *fstart; 548 540 struct floc fi; … … 561 553 commands_idx = 0; \ 562 554 no_targets = 0; \ 563 if (pattern) { free(pattern); pattern = 0; }\555 pattern = 0; \ 564 556 } while (0) 565 557 … … 586 578 unsigned int linelen; 587 579 char *line; 588 intlen;580 unsigned int wlen; 589 581 char *p; 590 582 char *p2; … … 607 599 /* Check for a shell command line first. 608 600 If it is not one, we can stop treating tab specially. */ 609 if (line[0] == '\t')601 if (line[0] == cmd_prefix) 610 602 { 611 603 if (no_targets) … … 632 624 commands = xrealloc (commands, commands_len); 633 625 } 634 bcopy (line, &commands[commands_idx], linelen);626 memcpy (&commands[commands_idx], line, linelen); 635 627 commands_idx += linelen; 636 628 commands[commands_idx++] = '\n'; … … 648 640 collapsed_length = linelen+1; 649 641 if (collapsed) 650 free ( (char *)collapsed);651 collapsed = (char *)xmalloc (collapsed_length);642 free (collapsed); 643 collapsed = xmalloc (collapsed_length); 652 644 } 653 645 strcpy (collapsed, line); … … 657 649 658 650 /* Compare a word, both length and contents. */ 659 #define word1eq(s) ( len == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))651 #define word1eq(s) (wlen == sizeof(s)-1 && strneq (s, p, sizeof(s)-1)) 660 652 p = collapsed; 661 653 while (isspace ((unsigned char)*p)) … … 672 664 for (p2 = p+1; *p2 != '\0' && !isspace ((unsigned char)*p2); ++p2) 673 665 ; 674 len = p2 - p;666 wlen = p2 - p; 675 667 676 668 /* Find the start of the second token. If it looks like a target or … … 695 687 if (!in_ignored_define) 696 688 { 697 int i = conditional_line (p, len, fstart);689 int i = conditional_line (p, wlen, fstart); 698 690 if (i != -2) 699 691 { … … 787 779 else 788 780 { 789 unsigned int len; 781 unsigned int l; 782 const char *cp; 790 783 char *ap; 791 784 792 785 /* Expand the line so we can use indirect and constructed 793 786 variable names in an export command. */ 794 p2= ap = allocated_variable_expand (p2);795 796 for (p = find_next_token (& p2, &len); p != 0;797 p = find_next_token (& p2, &len))787 cp = ap = allocated_variable_expand (p2); 788 789 for (p = find_next_token (&cp, &l); p != 0; 790 p = find_next_token (&cp, &l)) 798 791 { 799 v = lookup_variable (p, l en);792 v = lookup_variable (p, l); 800 793 if (v == 0) 801 v = define_variable_loc (p, len, "", o_file, 0, 802 fstart); 794 v = define_variable_loc (p, l, "", o_file, 0, fstart); 803 795 v->export = v_export; 804 796 } … … 816 808 else 817 809 { 818 unsigned int l en;810 unsigned int l; 819 811 struct variable *v; 812 const char *cp; 820 813 char *ap; 821 814 822 815 /* Expand the line so we can use indirect and constructed 823 816 variable names in an unexport command. */ 824 p2= ap = allocated_variable_expand (p2);825 826 for (p = find_next_token (& p2, &len); p != 0;827 p = find_next_token (& p2, &len))817 cp = ap = allocated_variable_expand (p2); 818 819 for (p = find_next_token (&cp, &l); p != 0; 820 p = find_next_token (&cp, &l)) 828 821 { 829 v = lookup_variable (p, l en);822 v = lookup_variable (p, l); 830 823 if (v == 0) 831 v = define_variable_loc (p, l en, "", o_file, 0, fstart);824 v = define_variable_loc (p, l, "", o_file, 0, fstart); 832 825 833 826 v->export = v_noexport; … … 842 835 if (word1eq ("vpath")) 843 836 { 844 char *pattern; 845 unsigned int len; 846 p2 = variable_expand (p2); 847 p = find_next_token (&p2, &len); 837 const char *cp; 838 char *vpat; 839 unsigned int l; 840 cp = variable_expand (p2); 841 p = find_next_token (&cp, &l); 848 842 if (p != 0) 849 843 { 850 pattern = savestring (p, len);851 p = find_next_token (& p2, &len);844 vpat = savestring (p, l); 845 p = find_next_token (&cp, &l); 852 846 /* No searchpath means remove all previous 853 847 selective VPATH's with the same pattern. */ … … 855 849 else 856 850 /* No pattern means remove all previous selective VPATH's. */ 857 pattern= 0;858 construct_vpath_list ( pattern, p);859 if ( pattern!= 0)860 free ( pattern);851 vpat = 0; 852 construct_vpath_list (vpat, p); 853 if (vpat != 0) 854 free (vpat); 861 855 862 856 goto rule_complete; … … 926 920 { 927 921 struct nameseq *next = files->next; 928 c har *name = files->name;922 const char *name = files->name; 929 923 int r; 930 924 931 free ( (char *)files);925 free (files); 932 926 files = next; 933 927 … … 936 930 if (!r && !noerror) 937 931 error (fstart, "%s: %s", name, strerror (errno)); 938 free (name);939 932 } 940 933 … … 952 945 was no preceding target, and the line might have been usable as a 953 946 variable definition. But now we know it is definitely lossage. */ 954 if (line[0] == '\t')947 if (line[0] == cmd_prefix) 955 948 fatal(fstart, _("commands commence before first target")); 956 949 … … 970 963 int exported; 971 964 char *cmdleft, *semip, *lb_next; 972 unsigned int len,plen = 0;965 unsigned int plen = 0; 973 966 char *colonp; 974 967 const char *end, *beg; /* Helpers for whitespace stripping. */ … … 999 992 beginning, expanding as we go, and looking for "interesting" 1000 993 chars. The first word is always expandable. */ 1001 wtype = get_next_mword(line, NULL, &lb_next, & len);994 wtype = get_next_mword(line, NULL, &lb_next, &wlen); 1002 995 switch (wtype) 1003 996 { … … 1020 1013 } 1021 1014 1022 p2 = variable_expand_string(NULL, lb_next, len);1015 p2 = variable_expand_string(NULL, lb_next, wlen); 1023 1016 1024 1017 while (1) 1025 1018 { 1026 lb_next += len;1019 lb_next += wlen; 1027 1020 if (cmdleft == 0) 1028 1021 { … … 1069 1062 break; 1070 1063 1071 wtype = get_next_mword(lb_next, NULL, &lb_next, & len);1064 wtype = get_next_mword(lb_next, NULL, &lb_next, &wlen); 1072 1065 if (wtype == w_eol) 1073 1066 break; … … 1075 1068 p2 += strlen(p2); 1076 1069 *(p2++) = ' '; 1077 p2 = variable_expand_string(p2, lb_next, len);1070 p2 = variable_expand_string(p2, lb_next, wlen); 1078 1071 /* We don't need to worry about cmdleft here, because if it was 1079 1072 found in the variable_buffer the entire buffer has already … … 1130 1123 unsigned int l = p2 - variable_buffer; 1131 1124 plen = strlen (p2); 1132 (void) variable_buffer_output (p2+plen, 1133 lb_next, strlen (lb_next)+1); 1125 variable_buffer_output (p2+plen, lb_next, strlen (lb_next)+1); 1134 1126 p2 = variable_buffer + l; 1135 1127 } … … 1138 1130 comes after it looks like a variable definition. */ 1139 1131 1140 wtype = get_next_mword (p2, NULL, &p, & len);1132 wtype = get_next_mword (p2, NULL, &p, &wlen); 1141 1133 1142 1134 v_origin = o_file; … … 1147 1139 { 1148 1140 v_origin = o_override; 1149 wtype = get_next_mword (p+ len, NULL, &p, &len);1141 wtype = get_next_mword (p+wlen, NULL, &p, &wlen); 1150 1142 } 1151 1143 else if (word1eq ("export")) 1152 1144 { 1153 1145 exported = 1; 1154 wtype = get_next_mword (p+ len, NULL, &p, &len);1146 wtype = get_next_mword (p+wlen, NULL, &p, &wlen); 1155 1147 } 1156 1148 } 1157 1149 1158 1150 if (wtype != w_eol) 1159 wtype = get_next_mword (p+ len, NULL, NULL, NULL);1151 wtype = get_next_mword (p+wlen, NULL, NULL, NULL); 1160 1152 1161 1153 if (wtype == w_varassign) … … 1232 1224 { 1233 1225 int check_again; 1234 1235 1226 do { 1236 1227 check_again = 0; … … 1254 1245 else if (target->next != 0) 1255 1246 fatal (fstart, _("multiple target patterns (target `%s')"), target->name); /* bird */ 1247 pattern_percent = find_percent_cached (&target->name); 1256 1248 pattern = target->name; 1257 pattern_percent = find_percent (pattern);1258 1249 if (pattern_percent == 0) 1259 1250 fatal (fstart, _("target pattern contains no `%%' (target `%s')"), target->name); /* bird */ 1260 free ( (char *)target);1251 free (target); 1261 1252 } 1262 1253 else … … 1272 1263 /* Put all the prerequisites here; they'll be parsed later. */ 1273 1264 deps = alloc_dep (); 1274 deps->name = s avestring(beg, end - beg + 1);1265 deps->name = strcache_add_len (beg, end - beg + 1); 1275 1266 } 1276 1267 else … … 1281 1272 { 1282 1273 /* Semicolon means rest of line is a command. */ 1283 unsigned int l en= strlen (cmdleft);1274 unsigned int l = strlen (cmdleft); 1284 1275 1285 1276 cmds_started = fstart->lineno; 1286 1277 1287 1278 /* Add this command line to the buffer. */ 1288 if (l en+ 2 > commands_len)1279 if (l + 2 > commands_len) 1289 1280 { 1290 commands_len = (l en+ 2) * 2;1291 commands = (char *)xrealloc (commands, commands_len);1281 commands_len = (l + 2) * 2; 1282 commands = xrealloc (commands, commands_len); 1292 1283 } 1293 bcopy (cmdleft, commands, len);1294 commands_idx += l en;1284 memcpy (commands, cmdleft, l); 1285 commands_idx += l; 1295 1286 commands[commands_idx++] = '\n'; 1296 1287 } … … 1314 1305 if (**default_goal_name == '\0' && set_default) 1315 1306 { 1316 c har*name;1307 const char *name; 1317 1308 struct dep *d; 1318 1309 struct nameseq *t = filenames; … … 1349 1340 for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next) 1350 1341 { 1351 register unsigned int len= strlen (dep_name (d2));1352 if (!strneq (name, dep_name (d2), l en))1342 unsigned int l = strlen (dep_name (d2)); 1343 if (!strneq (name, dep_name (d2), l)) 1353 1344 continue; 1354 if (streq (name + l en, dep_name (d)))1345 if (streq (name + l, dep_name (d))) 1355 1346 { 1356 1347 reject = 1; … … 1391 1382 1392 1383 if (collapsed) 1393 free ( (char *)collapsed);1394 free ( (char *)commands);1384 free (collapsed); 1385 free (commands); 1395 1386 1396 1387 return 1; … … 1426 1417 int nlevels = 1; 1427 1418 unsigned int length = 100; 1428 char *definition = (char *)xmalloc (length);1419 char *definition = xmalloc (length); 1429 1420 unsigned int idx = 0; 1430 1421 char *p; 1431 1422 1432 1423 /* Expand the variable name. */ 1433 char *var = (char *)alloca (namelen + 1);1434 bcopy (name, var, namelen);1424 char *var = alloca (namelen + 1); 1425 memcpy (var, name, namelen); 1435 1426 var[namelen] = '\0'; 1436 1427 var = variable_expand (var); … … 1458 1449 1459 1450 /* Stop if we find an 'endef' */ 1460 if (line[0] != '\t')1451 if (line[0] != cmd_prefix) 1461 1452 { 1462 1453 p = next_token (line); … … 1501 1492 { 1502 1493 length = (idx + len) * 2; 1503 definition = (char *)xrealloc (definition, length + 1);1494 definition = xrealloc (definition, length + 1); 1504 1495 } 1505 1496 1506 bcopy (line, &definition[idx], len);1497 memcpy (&definition[idx], line, len); 1507 1498 idx += len; 1508 1499 /* Separate lines with a newline. */ … … 1632 1623 { 1633 1624 conditionals->allocated = 5; 1634 conditionals->ignoring = (char *)xmalloc (conditionals->allocated);1635 conditionals->seen_else = (char *)xmalloc (conditionals->allocated);1625 conditionals->ignoring = xmalloc (conditionals->allocated); 1626 conditionals->seen_else = xmalloc (conditionals->allocated); 1636 1627 } 1637 1628 … … 1640 1631 { 1641 1632 conditionals->allocated += 5; 1642 conditionals->ignoring = (char *)1643 xrealloc (conditionals->ignoring,conditionals->allocated);1644 conditionals->seen_else = (char *)1645 xrealloc (conditionals->seen_else,conditionals->allocated);1633 conditionals->ignoring = xrealloc (conditionals->ignoring, 1634 conditionals->allocated); 1635 conditionals->seen_else = xrealloc (conditionals->seen_else, 1636 conditionals->allocated); 1646 1637 } 1647 1638 … … 1687 1678 else 1688 1679 { 1689 /* " Ifeq" or "ifneq". */1680 /* "ifeq" or "ifneq". */ 1690 1681 char *s1, *s2; 1691 unsigned int l en;1682 unsigned int l; 1692 1683 char termin = *line == '(' ? ',' : *line; 1693 1684 … … 1729 1720 /* We must allocate a new copy of the expanded string because 1730 1721 variable_expand re-uses the same buffer. */ 1731 l en= strlen (s2);1732 s1 = (char *) alloca (len+ 1);1733 bcopy (s2, s1, len+ 1);1722 l = strlen (s2); 1723 s1 = alloca (l + 1); 1724 memcpy (s1, s2, l + 1); 1734 1725 1735 1726 if (termin != ',') … … 1744 1735 if (termin == ')') 1745 1736 { 1746 registerint count = 0;1737 int count = 0; 1747 1738 s2 = next_token (line); 1748 1739 for (line = s2; *line != '\0'; ++line) … … 1879 1870 { 1880 1871 struct variable *v; 1881 registerchar *name = filenames->name;1882 c har *fname;1883 c har *percent;1872 const char *name = filenames->name; 1873 const char *fname; 1874 const char *percent; 1884 1875 struct pattern_var *p; 1885 1876 1886 1877 nextf = filenames->next; 1887 free ( (char *)filenames);1878 free (filenames); 1888 1879 1889 1880 /* If it's a pattern target, then add it to the pattern-specific 1890 1881 variable list. */ 1891 percent = find_percent (name);1882 percent = find_percent_cached (&name); 1892 1883 if (percent) 1893 1884 { … … 1917 1908 f = lookup_file (name); 1918 1909 if (!f) 1919 f = enter_file ( name);1910 f = enter_file (strcache_add (name)); 1920 1911 else if (f->double_colon) 1921 1912 f = f->double_colon; … … 1954 1945 } 1955 1946 } 1956 1957 /* Free name if not needed further. */1958 if (name != fname && (name < fname || name > fname + strlen (fname)))1959 free (name);1960 1947 } 1961 1948 } … … 1974 1961 1975 1962 static void 1976 record_files (struct nameseq *filenames, char *pattern, char *pattern_percent, 1977 struct dep *deps, unsigned int cmds_started, char *commands, 1963 record_files (struct nameseq *filenames, const char *pattern, 1964 const char *pattern_percent, struct dep *deps, 1965 unsigned int cmds_started, char *commands, 1978 1966 unsigned int commands_idx, int two_colon, 1979 1967 const struct floc *flocp) … … 1982 1970 int implicit = 0; 1983 1971 unsigned int max_targets = 0, target_idx = 0; 1984 c har **targets = 0, **target_percents = 0;1972 const char **targets = 0, **target_percents = 0; 1985 1973 struct commands *cmds; 1986 1974 … … 1994 1982 if (commands_idx > 0) 1995 1983 { 1996 cmds = (struct commands *)xmalloc (sizeof (struct commands));1984 cmds = xmalloc (sizeof (struct commands)); 1997 1985 cmds->fileinfo.filenm = flocp->filenm; 1998 1986 cmds->fileinfo.lineno = cmds_started; … … 2005 1993 for (; filenames != 0; filenames = nextf) 2006 1994 { 2007 c har *name = filenames->name;1995 const char *name = filenames->name; 2008 1996 struct file *f; 2009 1997 struct dep *this = 0; 2010 c har *implicit_percent;1998 const char *implicit_percent; 2011 1999 2012 2000 nextf = filenames->next; … … 2021 2009 second_expansion = 1; 2022 2010 2023 implicit_percent = find_percent (name);2011 implicit_percent = find_percent_cached (&name); 2024 2012 implicit |= implicit_percent != 0; 2025 2013 2026 if (implicit && pattern != 0)2027 fatal (flocp, _("mixed implicit and static pattern rules"));2028 2029 if (implicit && implicit_percent == 0)2030 fatal (flocp, _("mixed implicit and normal rules"));2031 2032 2014 if (implicit) 2033 { 2015 { 2016 if (pattern != 0) 2017 fatal (flocp, _("mixed implicit and static pattern rules")); 2018 2019 if (implicit_percent == 0) 2020 fatal (flocp, _("mixed implicit and normal rules")); 2021 2034 2022 if (targets == 0) 2035 2023 { 2036 2024 max_targets = 5; 2037 targets = (char **)xmalloc (5 * sizeof (char *));2038 target_percents = (char **)xmalloc (5 * sizeof (char *));2025 targets = xmalloc (5 * sizeof (char *)); 2026 target_percents = xmalloc (5 * sizeof (char *)); 2039 2027 target_idx = 0; 2040 2028 } … … 2042 2030 { 2043 2031 max_targets += 5; 2044 targets = (char **) xrealloc ((char *) targets, 2045 max_targets * sizeof (char *)); 2046 target_percents 2047 = (char **) xrealloc ((char *) target_percents, 2048 max_targets * sizeof (char *)); 2032 targets = xrealloc (targets, max_targets * sizeof (char *)); 2033 target_percents = xrealloc (target_percents, 2034 max_targets * sizeof (char *)); 2049 2035 } 2050 2036 targets[target_idx] = name; … … 2073 2059 /* Single-colon. Combine these dependencies 2074 2060 with others in file's existing record, if any. */ 2075 f = enter_file ( name);2061 f = enter_file (strcache_add (name)); 2076 2062 2077 2063 if (f->double_colon) … … 2179 2165 fatal (flocp, 2180 2166 _("target file `%s' has both : and :: entries"), f->name); 2181 f = enter_file ( name);2167 f = enter_file (strcache_add (name)); 2182 2168 /* If there was an existing entry and it was a double-colon entry, 2183 2169 enter_file will have returned a new one, making it the prev … … 2198 2184 if (pattern) 2199 2185 { 2200 static c har *percent = "%";2186 static const char *percent = "%"; 2201 2187 char *buffer = variable_expand (""); 2202 char *o = patsubst_expand (buffer, name, pattern, percent,2203 pattern_percent+1, percent+1);2204 f->stem = s avestring(buffer, o - buffer);2188 char *o = patsubst_expand_pat (buffer, name, pattern, percent, 2189 pattern_percent+1, percent+1); 2190 f->stem = strcache_add_len (buffer, o - buffer); 2205 2191 if (this) 2206 2192 { 2207 2193 this->staticpattern = 1; 2208 this->stem = xstrdup (f->stem);2194 this->stem = f->stem; 2209 2195 } 2210 2196 } 2211 2197 2212 /* Free name if not needed further. */ 2213 if (f != 0 && name != f->name 2214 && (name < f->name || name > f->name + strlen (f->name))) 2215 { 2216 free (name); 2217 name = f->name; 2218 } 2198 name = f->name; 2219 2199 2220 2200 /* If this target is a default target, update DEFAULT_GOAL_FILE. */ … … 2227 2207 if (implicit) 2228 2208 { 2229 targets[target_idx] = 0;2230 target_percents[target_idx] = 0;2231 2209 if (deps) 2232 2210 deps->need_2nd_expansion = second_expansion; 2233 create_pattern_rule (targets, target_percents, t wo_colon, deps, cmds, 1);2234 free ((char *) target_percents);2211 create_pattern_rule (targets, target_percents, target_idx, 2212 two_colon, deps, cmds, 1); 2235 2213 } 2236 2214 } … … 2251 2229 { 2252 2230 unsigned int string_len = 0; 2253 registerchar *p = string;2231 char *p = string; 2254 2232 register int ch; /* bird: 'optimiziations' */ 2255 2233 … … 2311 2289 { 2312 2290 /* Search for more backslashes. */ 2313 registerint i = -2;2291 int i = -2; 2314 2292 while (&p[i] >= string && p[i] == '\\') 2315 2293 --i; … … 2320 2298 /* The number of backslashes is now -I. 2321 2299 Copy P over itself to swallow half of them. */ 2322 bcopy (&p[i / 2], &p[i], (string_len - (p - string)) - (i /2) + 1);2323 p += i /2;2300 memmove (&p[i], &p[i/2], (string_len - (p - string)) - (i/2) + 1); 2301 p += i/2; 2324 2302 if (i % 2 == 0) 2325 2303 /* All the backslashes quoted each other; the STOPCHAR was … … 2338 2316 } 2339 2317 2340 /* Search PATTERN for an unquoted % . */2318 /* Search PATTERN for an unquoted % and handle quoting. */ 2341 2319 2342 2320 char * … … 2344 2322 { 2345 2323 return find_char_unquote (pattern, '%', 0, 0, 0); 2324 } 2325 2326 /* Search STRING for an unquoted % and handle quoting. Returns a pointer to 2327 the % or NULL if no % was found. 2328 This version is used with strings in the string cache: if there's a need to 2329 modify the string a new version will be added to the string cache and 2330 *STRING will be set to that. */ 2331 2332 const char * 2333 find_percent_cached (const char **string) 2334 { 2335 const char *p = *string; 2336 char *new = 0; 2337 int slen; 2338 2339 /* If the first char is a % return now. This lets us avoid extra tests 2340 inside the loop. */ 2341 if (*p == '%') 2342 return p; 2343 2344 while (1) 2345 { 2346 while (*p != '\0' && *p != '%') 2347 ++p; 2348 2349 if (*p == '\0') 2350 break; 2351 2352 /* See if this % is escaped with a backslash; if not we're done. */ 2353 if (p[-1] != '\\') 2354 break; 2355 2356 { 2357 /* Search for more backslashes. */ 2358 char *pv; 2359 int i = -2; 2360 2361 while (&p[i] >= *string && p[i] == '\\') 2362 --i; 2363 ++i; 2364 2365 /* At this point we know we'll need to allocate a new string. 2366 Make a copy if we haven't yet done so. */ 2367 if (! new) 2368 { 2369 slen = strlen (*string); 2370 new = alloca (slen + 1); 2371 memcpy (new, *string, slen + 1); 2372 p = new + (p - *string); 2373 *string = new; 2374 } 2375 2376 /* At this point *string, p, and new all point into the same string. 2377 Get a non-const version of p so we can modify new. */ 2378 pv = new + (p - *string); 2379 2380 /* The number of backslashes is now -I. 2381 Copy P over itself to swallow half of them. */ 2382 memmove (&pv[i], &pv[i/2], (slen - (pv - new)) - (i/2) + 1); 2383 p += i/2; 2384 2385 /* If the backslashes quoted each other; the % was unquoted. */ 2386 if (i % 2 == 0) 2387 break; 2388 } 2389 } 2390 2391 /* If we had to change STRING, add it to the strcache. */ 2392 if (new) 2393 { 2394 *string = strcache_add (*string); 2395 p = *string + (p - new); 2396 } 2397 2398 /* If we didn't find a %, return NULL. Otherwise return a ptr to it. */ 2399 return (*p == '\0') ? NULL : p; 2346 2400 } 2347 2401 … … 2367 2421 #ifndef NO_ARCHIVES /* bird: MSC warning */ 2368 2422 struct nameseq *lastnew1; 2369 #endif 2423 #endif 2370 2424 char *p = *stringp; 2371 char *q;2372 char *name;2373 2425 2374 2426 #ifdef VMS … … 2380 2432 while (1) 2381 2433 { 2434 const char *name; 2435 char *q; 2436 2382 2437 /* Skip whitespace; see if any more names are left. */ 2383 2438 p = next_token (p); … … 2387 2442 break; 2388 2443 2389 /* Yes, find end ofnext name. */2444 /* There are, so find the end of the next name. */ 2390 2445 q = p; 2391 2446 p = find_char_unquote (q, stopchar, VMS_COMMA, 1, 0); … … 2399 2454 && !(isspace ((unsigned char)p[1]) || !p[1] 2400 2455 || isspace ((unsigned char)p[-1]))) 2401 {2402 2456 p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0); 2403 }2404 2457 #endif 2405 2458 #ifdef HAVE_DOS_PATHS … … 2435 2488 if (q == p) 2436 2489 /* ".///" was stripped to "". */ 2437 #if def VMS2490 #if defined(VMS) 2438 2491 continue; 2492 #elif defined(_AMIGA) 2493 name = ""; 2439 2494 #else 2440 #ifdef _AMIGA 2441 name = savestring ("", 0); 2442 #else 2443 name = savestring ("./", 2); 2444 #endif 2495 name = "./"; 2445 2496 #endif 2446 2497 else … … 2466 2517 *q2++ = *q1++; 2467 2518 } 2468 name = s avestring(qbase, p1 - qbase);2519 name = strcache_add_len (qbase, p1 - qbase); 2469 2520 free (qbase); 2470 2521 } 2471 2522 #else 2472 name = s avestring(q, p - q);2523 name = strcache_add_len (q, p - q); 2473 2524 #endif 2474 2525 2475 2526 /* Add it to the front of the chain. */ 2476 new1 = (struct nameseq *)xmalloc (size);2527 new1 = xmalloc (size); 2477 2528 new1->name = name; 2478 2529 new1->next = new; … … 2517 2568 /* Copy "lib(" into LIBNAME. */ 2518 2569 ++paren; 2519 libname = (char *)alloca (paren - n->name + 1);2520 bcopy (n->name, libname, paren - n->name);2570 libname = alloca (paren - n->name + 1); 2571 memcpy (libname, n->name, paren - n->name); 2521 2572 libname[paren - n->name] = '\0'; 2522 2573 … … 2526 2577 Edit it out of the chain and free its storage. */ 2527 2578 lastn->next = n->next; 2528 free (n->name); 2529 free ((char *) n); 2579 free (n); 2530 2580 /* LASTN->next is the new stopping elt for the loop below. */ 2531 2581 n = lastn->next; … … 2534 2584 { 2535 2585 /* Replace N's name with the full archive reference. */ 2536 name = concat (libname, paren, ")"); 2537 free (n->name); 2538 n->name = name; 2586 n->name = strcache_add (concat (libname, paren, ")")); 2539 2587 } 2540 2588 … … 2549 2597 lastn = new1; 2550 2598 new1 = new1->next; 2551 free (lastn->name); 2552 free ((char *) lastn); 2599 free (lastn); 2553 2600 } 2554 2601 else 2555 2602 { 2556 2603 /* Replace also NEW1->name, which already has closing `)'. */ 2557 name = concat (libname, new1->name, ""); 2558 free (new1->name); 2559 new1->name = name; 2604 new1->name = strcache_add (concat (libname, new1->name, "")); 2560 2605 new1 = new1->next; 2561 2606 } … … 2567 2612 while (new1 != n) 2568 2613 { 2569 name = concat (libname, new1->name, ")"); 2570 free (new1->name); 2571 new1->name = name; 2614 new1->name = strcache_add (concat (libname, new1->name, ")")); 2572 2615 lastnew1 = new1; 2573 2616 new1 = new1->next; … … 2737 2780 unsigned long off = p - start; 2738 2781 ebuf->size *= 2; 2739 start = ebuf->buffer = ebuf->bufstart = (char *) xrealloc (start, 2740 ebuf->size); 2782 start = ebuf->buffer = ebuf->bufstart = xrealloc (start, ebuf->size); 2741 2783 p = start + off; 2742 2784 end = start + ebuf->size; … … 2941 2983 2942 2984 void 2943 construct_include_path (c har **arg_dirs)2985 construct_include_path (const char **arg_dirs) 2944 2986 { 2945 register unsigned int i;2946 2987 #ifdef VAXC /* just don't ask ... */ 2947 2988 stat_t stbuf; … … 2949 2990 struct stat stbuf; 2950 2991 #endif 2951 /* Table to hold the dirs. */ 2952 2953 register unsigned int defsize = (sizeof (default_include_directories) 2954 / sizeof (default_include_directories[0])); 2955 register unsigned int max = 5; 2956 register char **dirs = (char **) xmalloc ((5 + defsize) * sizeof (char *)); 2957 register unsigned int idx = 0; 2992 const char **dirs; 2993 const char **cpp; 2994 unsigned int idx; 2995 2996 /* Compute the number of pointers we need in the table. */ 2997 idx = sizeof (default_include_directories) / sizeof (const char *); 2998 if (arg_dirs) 2999 for (cpp = arg_dirs; *cpp != 0; ++cpp) 3000 ++idx; 2958 3001 2959 3002 #ifdef __MSDOS__ 2960 defsize++; 3003 /* Add one for $DJDIR. */ 3004 ++idx; 2961 3005 #endif 2962 3006 3007 dirs = xmalloc (idx * sizeof (const char *)); 3008 3009 idx = 0; 3010 max_incl_len = 0; 3011 2963 3012 /* First consider any dirs specified with -I switches. 2964 Ignore dirs that don't exist. */2965 2966 if (arg_dirs != 0)3013 Ignore any that don't exist. Remember the maximum string length. */ 3014 3015 if (arg_dirs) 2967 3016 while (*arg_dirs != 0) 2968 3017 { 2969 char *dir = *arg_dirs++; 3018 const char *dir = *(arg_dirs++); 3019 char *expanded = 0; 2970 3020 int e; 2971 3021 2972 3022 if (dir[0] == '~') 2973 3023 { 2974 char *expanded = tilde_expand (dir);3024 expanded = tilde_expand (dir); 2975 3025 if (expanded != 0) 2976 3026 dir = expanded; … … 2979 3029 EINTRLOOP (e, stat (dir, &stbuf)); 2980 3030 if (e == 0 && S_ISDIR (stbuf.st_mode)) 2981 { 2982 if (idx == max - 1) 2983 { 2984 max += 5; 2985 dirs = (char **) 2986 xrealloc ((char *) dirs, (max + defsize) * sizeof (char *)); 2987 } 2988 dirs[idx++] = dir; 2989 } 2990 else if (dir != arg_dirs[-1]) 2991 free (dir); 3031 { 3032 unsigned int len = strlen (dir); 3033 /* If dir name is written with trailing slashes, discard them. */ 3034 while (len > 1 && dir[len - 1] == '/') 3035 --len; 3036 if (len > max_incl_len) 3037 max_incl_len = len; 3038 dirs[idx++] = strcache_add_len (dir, len); 3039 } 3040 3041 if (expanded) 3042 free (expanded); 2992 3043 } 2993 3044 2994 /* Now add at the end the standard default dirs. */3045 /* Now add the standard default dirs at the end. */ 2995 3046 2996 3047 #ifdef __MSDOS__ 2997 3048 { 2998 /* The environment variable $DJDIR holds the root of the 2999 DJGPP directorytree; add ${DJDIR}/include. */3049 /* The environment variable $DJDIR holds the root of the DJGPP directory 3050 tree; add ${DJDIR}/include. */ 3000 3051 struct variable *djdir = lookup_variable ("DJDIR", 5); 3001 3052 3002 3053 if (djdir) 3003 3054 { 3004 char *defdir = (char *) xmalloc (strlen (djdir->value) + 8 + 1); 3055 unsigned int len = strlen (djdir->value) + 8; 3056 char *defdir = alloca (len + 1); 3005 3057 3006 3058 strcat (strcpy (defdir, djdir->value), "/include"); 3007 dirs[idx++] = defdir; 3059 dirs[idx++] = strcache_add (defdir); 3060 3061 if (len > max_incl_len) 3062 max_incl_len = len; 3008 3063 } 3009 3064 } 3010 3065 #endif 3011 3066 3012 for ( i = 0; default_include_directories[i] != 0; ++i)3067 for (cpp = default_include_directories; *cpp != 0; ++cpp) 3013 3068 { 3014 3069 int e; 3015 3070 3016 EINTRLOOP (e, stat ( default_include_directories[i], &stbuf));3071 EINTRLOOP (e, stat (*cpp, &stbuf)); 3017 3072 if (e == 0 && S_ISDIR (stbuf.st_mode)) 3018 dirs[idx++] = default_include_directories[i]; 3073 { 3074 unsigned int len = strlen (*cpp); 3075 /* If dir name is written with trailing slashes, discard them. */ 3076 while (len > 1 && (*cpp)[len - 1] == '/') 3077 --len; 3078 if (len > max_incl_len) 3079 max_incl_len = len; 3080 dirs[idx++] = strcache_add_len (*cpp, len - 1); 3081 } 3019 3082 } 3020 3083 3021 3084 dirs[idx] = 0; 3022 3085 3023 /* Now compute the maximum length of any name in it. Also add each 3024 dir to the .INCLUDE_DIRS variable. */ 3025 3026 max_incl_len = 0; 3027 for (i = 0; i < idx; ++i) 3028 { 3029 unsigned int len = strlen (dirs[i]); 3030 /* If dir name is written with a trailing slash, discard it. */ 3031 if (dirs[i][len - 1] == '/') 3032 /* We can't just clobber a null in because it may have come from 3033 a literal string and literal strings may not be writable. */ 3034 dirs[i] = savestring (dirs[i], len - 1); 3035 if (len > max_incl_len) 3036 max_incl_len = len; 3037 3038 /* Append to .INCLUDE_DIRS. */ 3039 do_variable_definition (NILF, ".INCLUDE_DIRS", dirs[i], 3040 o_default, f_append, 0); 3041 } 3086 /* Now add each dir to the .INCLUDE_DIRS variable. */ 3087 3088 for (cpp = dirs; *cpp != 0; ++cpp) 3089 do_variable_definition (NILF, ".INCLUDE_DIRS", *cpp, 3090 o_default, f_append, 0); 3042 3091 3043 3092 include_directories = dirs; … … 3049 3098 3050 3099 char * 3051 tilde_expand (c har *name)3100 tilde_expand (const char *name) 3052 3101 { 3053 3102 #ifndef VMS … … 3074 3123 home_dir = getenv ("HOME"); 3075 3124 } 3076 # if !defined(_AMIGA) && !defined(WINDOWS32)3125 # if !defined(_AMIGA) && !defined(WINDOWS32) 3077 3126 if (home_dir == 0 || home_dir[0] == '\0') 3078 3127 { … … 3087 3136 } 3088 3137 } 3089 # endif /* !AMIGA && !WINDOWS32 */3138 # endif /* !AMIGA && !WINDOWS32 */ 3090 3139 if (home_dir != 0) 3091 3140 { 3092 char *new = concat (home_dir, "", name + 1);3141 char *new = xstrdup (concat (home_dir, "", name + 1)); 3093 3142 if (is_variable) 3094 3143 free (home_dir); … … 3096 3145 } 3097 3146 } 3098 # if !defined(_AMIGA) && !defined(WINDOWS32)3147 # if !defined(_AMIGA) && !defined(WINDOWS32) 3099 3148 else 3100 3149 { … … 3109 3158 return xstrdup (pwent->pw_dir); 3110 3159 else 3111 return concat (pwent->pw_dir, "/", userend + 1);3160 return xstrdup (concat (pwent->pw_dir, "/", userend + 1)); 3112 3161 } 3113 3162 else if (userend != 0) 3114 3163 *userend = '/'; 3115 3164 } 3116 # endif /* !AMIGA && !WINDOWS32 */3165 # endif /* !AMIGA && !WINDOWS32 */ 3117 3166 #endif /* !VMS */ 3118 3167 return 0; … … 3132 3181 multi_glob (struct nameseq *chain, unsigned int size) 3133 3182 { 3134 extern void dir_setup_glob ();3135 registerstruct nameseq *new = 0;3136 registerstruct nameseq *old;3183 void dir_setup_glob (glob_t *); 3184 struct nameseq *new = 0; 3185 struct nameseq *old; 3137 3186 struct nameseq *nexto; 3138 3187 glob_t gl; … … 3145 3194 for (old = chain; old != 0; old = nexto) 3146 3195 { 3196 const char *gname; 3147 3197 #ifndef NO_ARCHIVES 3148 char *memname; 3198 char *arname = 0; 3199 char *memname = 0; 3149 3200 #endif 3150 3151 3201 nexto = old->next; 3152 3153 if (old->name[0] == '~') 3202 gname = old->name; 3203 3204 if (gname[0] == '~') 3154 3205 { 3155 3206 char *newname = tilde_expand (old->name); 3156 3207 if (newname != 0) 3157 { 3158 free (old->name); 3159 old->name = newname; 3160 } 3208 gname = newname; 3161 3209 } 3162 3210 3163 3211 #ifndef NO_ARCHIVES 3164 if (ar_name ( old->name))3212 if (ar_name (gname)) 3165 3213 { 3166 /* OLD->name is an archive member reference. 3167 Replace it with the archive file name, 3168 and save the member name in MEMNAME. 3169 We will glob on the archive name and then 3170 reattach MEMNAME later. */ 3171 char *arname; 3172 ar_parse_name (old->name, &arname, &memname); 3173 free (old->name); 3174 old->name = arname; 3214 /* OLD->name is an archive member reference. Replace it with the 3215 archive file name, and save the member name in MEMNAME. We will 3216 glob on the archive name and then reattach MEMNAME later. */ 3217 ar_parse_name (gname, &arname, &memname); 3218 gname = arname; 3175 3219 } 3176 else3177 memname = 0;3178 3220 #endif /* !NO_ARCHIVES */ 3179 3221 3180 3222 #if defined(KMK) || defined(__EMX__) /* speed optimization */ 3181 if (!strpbrk( old->name, "*?["))3223 if (!strpbrk(gname, "*?[")) 3182 3224 { 3183 3225 gl.gl_pathc = 1; 3184 gl.gl_pathv = &old->name;3226 gl.gl_pathv = (char *)&gname; 3185 3227 rc = 0; 3186 3228 } 3187 3229 else 3188 rc = glob ( old->name, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl);3230 rc = glob (gname, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl); 3189 3231 switch (rc) 3190 3232 #else 3191 switch (glob ( old->name, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl))3233 switch (glob (gname, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl)) 3192 3234 #endif 3193 3235 { 3194 3236 case 0: /* Success. */ 3195 3237 { 3196 registerint i = gl.gl_pathc;3238 int i = gl.gl_pathc; 3197 3239 while (i-- > 0) 3198 3240 { … … 3203 3245 struct nameseq *found 3204 3246 = ar_glob (gl.gl_pathv[i], memname, size); 3205 if ( found == 0)3247 if (! found) 3206 3248 { 3207 3249 /* No matches. Use MEMNAME as-is. */ 3208 3250 unsigned int alen = strlen (gl.gl_pathv[i]); 3209 3251 unsigned int mlen = strlen (memname); 3210 struct nameseq *elt 3211 = (struct nameseq *)xmalloc (size);3212 if (size > sizeof (struct nameseq))3213 bzero (((char *) elt) + sizeof (struct nameseq), 3214 size - sizeof (struct nameseq));3215 elt->name = (char *) xmalloc (alen + 1 + mlen + 2);3216 bcopy (gl.gl_pathv[i], elt->name, alen);3217 elt->name[alen] = '(';3218 bcopy (memname, &elt->name[alen + 1], mlen);3219 elt->name[alen + 1 + mlen] = ')';3220 elt->name[alen + 1 + mlen + 1] = '\0';3252 char *name; 3253 struct nameseq *elt = xmalloc (size); 3254 memset (elt, '\0', size); 3255 3256 name = alloca (alen + 1 + mlen + 2); 3257 memcpy (name, gl.gl_pathv[i], alen); 3258 name[alen] = '('; 3259 memcpy (name+alen+1, memname, mlen); 3260 name[alen + 1 + mlen] = ')'; 3261 name[alen + 1 + mlen + 1] = '\0'; 3262 elt->name = strcache_add (name); 3221 3263 elt->next = new; 3222 3264 new = elt; … … 3234 3276 new = found; 3235 3277 } 3236 3237 free (memname);3238 3278 } 3239 3279 else 3240 3280 #endif /* !NO_ARCHIVES */ 3241 3281 { 3242 struct nameseq *elt = (struct nameseq *) xmalloc (size); 3243 if (size > sizeof (struct nameseq)) 3244 bzero (((char *) elt) + sizeof (struct nameseq), 3245 size - sizeof (struct nameseq)); 3246 elt->name = xstrdup (gl.gl_pathv[i]); 3282 struct nameseq *elt = xmalloc (size); 3283 memset (elt, '\0', size); 3284 elt->name = strcache_add (gl.gl_pathv[i]); 3247 3285 elt->next = new; 3248 3286 new = elt; … … 3250 3288 } 3251 3289 #if defined(KMK) || defined(__EMX__) /* speed optimization */ 3252 if (gl.gl_pathv != & old->name)3290 if (gl.gl_pathv != &gname) 3253 3291 #endif 3254 3292 globfree (&gl); 3255 free (old->name); 3256 free ((char *)old); 3293 free (old); 3257 3294 break; 3258 3295 } … … 3267 3304 break; 3268 3305 } 3306 3307 #ifndef NO_ARCHIVES 3308 if (arname) 3309 free (arname); 3310 #endif 3269 3311 } 3270 3312
Note:
See TracChangeset
for help on using the changeset viewer.