Changeset 900 for vendor/gnumake/current/read.c
- Timestamp:
- May 23, 2007, 5:13:11 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/read.c
r501 r900 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') … … 251 248 { 252 249 struct dep *d = alloc_dep (); 253 d->file = enter_file ( *p);250 d->file = enter_file (strcache_add (*p)); 254 251 d->file->dontcare = 1; 255 252 /* Tell update_goal_chain to bail out as soon as this file is … … 278 275 struct conditionals *save = conditionals; 279 276 280 bzero ((char *) new, sizeof (*new));277 memset (new, '\0', sizeof (*new)); 281 278 conditionals = new; 282 279 … … 301 298 302 299 static int 303 eval_makefile (c har *filename, int flags)300 eval_makefile (const char *filename, int flags) 304 301 { 305 302 struct dep *deps; … … 307 304 const struct floc *curfile; 308 305 char *expanded = 0; 309 char *included = 0;310 306 int makefile_errno; 311 307 int r; 312 308 313 ebuf.floc.filenm = strcache_add (filename); 309 filename = strcache_add (filename); 310 ebuf.floc.filenm = filename; 314 311 ebuf.floc.lineno = 1; 315 312 … … 348 345 if (ebuf.fp == 0 && (flags & RM_INCLUDED) && *filename != '/') 349 346 { 350 registerunsigned int i;347 unsigned int i; 351 348 for (i = 0; include_directories[i] != 0; ++i) 352 349 { 353 included = concat (include_directories[i], "/", filename);350 const char *included = concat (include_directories[i], "/", filename); 354 351 ebuf.fp = fopen (included, "r"); 355 352 if (ebuf.fp) 356 353 { 357 filename = included;354 filename = strcache_add (included); 358 355 break; 359 356 } 360 free (included); 361 } 362 /* If we're not using it, we already freed it above. */ 363 if (filename != included) 364 included = 0; 357 } 365 358 } 366 359 … … 371 364 deps->file = lookup_file (filename); 372 365 if (deps->file == 0) 373 deps->file = enter_file ( xstrdup (filename));366 deps->file = enter_file (filename); 374 367 filename = deps->file->name; 375 368 deps->changed = flags; … … 379 372 if (expanded) 380 373 free (expanded); 381 if (included)382 free (included);383 374 384 375 /* If the makefile can't be found at all, give up entirely. */ … … 470 461 long nlines = 0; 471 462 int two_colon = 0; 472 char *pattern = 0, *pattern_percent; 463 const char *pattern = 0; 464 const char *pattern_percent; 473 465 struct floc *fstart; 474 466 struct floc fi; … … 487 479 commands_idx = 0; \ 488 480 no_targets = 0; \ 489 if (pattern) { free(pattern); pattern = 0; }\481 pattern = 0; \ 490 482 } while (0) 491 483 … … 512 504 unsigned int linelen; 513 505 char *line; 514 intlen;506 unsigned int wlen; 515 507 char *p; 516 508 char *p2; … … 533 525 /* Check for a shell command line first. 534 526 If it is not one, we can stop treating tab specially. */ 535 if (line[0] == '\t')527 if (line[0] == cmd_prefix) 536 528 { 537 529 if (no_targets) … … 558 550 commands = xrealloc (commands, commands_len); 559 551 } 560 bcopy (line, &commands[commands_idx], linelen);552 memcpy (&commands[commands_idx], line, linelen); 561 553 commands_idx += linelen; 562 554 commands[commands_idx++] = '\n'; … … 574 566 collapsed_length = linelen+1; 575 567 if (collapsed) 576 free ( (char *)collapsed);577 collapsed = (char *)xmalloc (collapsed_length);568 free (collapsed); 569 collapsed = xmalloc (collapsed_length); 578 570 } 579 571 strcpy (collapsed, line); … … 583 575 584 576 /* Compare a word, both length and contents. */ 585 #define word1eq(s) ( len == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))577 #define word1eq(s) (wlen == sizeof(s)-1 && strneq (s, p, sizeof(s)-1)) 586 578 p = collapsed; 587 579 while (isspace ((unsigned char)*p)) … … 598 590 for (p2 = p+1; *p2 != '\0' && !isspace ((unsigned char)*p2); ++p2) 599 591 ; 600 len = p2 - p;592 wlen = p2 - p; 601 593 602 594 /* Find the start of the second token. If it looks like a target or … … 621 613 if (!in_ignored_define) 622 614 { 623 int i = conditional_line (p, len, fstart);615 int i = conditional_line (p, wlen, fstart); 624 616 if (i != -2) 625 617 { … … 713 705 else 714 706 { 715 unsigned int len; 707 unsigned int l; 708 const char *cp; 716 709 char *ap; 717 710 718 711 /* Expand the line so we can use indirect and constructed 719 712 variable names in an export command. */ 720 p2= ap = allocated_variable_expand (p2);721 722 for (p = find_next_token (& p2, &len); p != 0;723 p = find_next_token (& p2, &len))713 cp = ap = allocated_variable_expand (p2); 714 715 for (p = find_next_token (&cp, &l); p != 0; 716 p = find_next_token (&cp, &l)) 724 717 { 725 v = lookup_variable (p, l en);718 v = lookup_variable (p, l); 726 719 if (v == 0) 727 v = define_variable_loc (p, len, "", o_file, 0, 728 fstart); 720 v = define_variable_loc (p, l, "", o_file, 0, fstart); 729 721 v->export = v_export; 730 722 } … … 742 734 else 743 735 { 744 unsigned int l en;736 unsigned int l; 745 737 struct variable *v; 738 const char *cp; 746 739 char *ap; 747 740 748 741 /* Expand the line so we can use indirect and constructed 749 742 variable names in an unexport command. */ 750 p2= ap = allocated_variable_expand (p2);751 752 for (p = find_next_token (& p2, &len); p != 0;753 p = find_next_token (& p2, &len))743 cp = ap = allocated_variable_expand (p2); 744 745 for (p = find_next_token (&cp, &l); p != 0; 746 p = find_next_token (&cp, &l)) 754 747 { 755 v = lookup_variable (p, l en);748 v = lookup_variable (p, l); 756 749 if (v == 0) 757 v = define_variable_loc (p, l en, "", o_file, 0, fstart);750 v = define_variable_loc (p, l, "", o_file, 0, fstart); 758 751 759 752 v->export = v_noexport; … … 768 761 if (word1eq ("vpath")) 769 762 { 770 char *pattern; 771 unsigned int len; 772 p2 = variable_expand (p2); 773 p = find_next_token (&p2, &len); 763 const char *cp; 764 char *vpat; 765 unsigned int l; 766 cp = variable_expand (p2); 767 p = find_next_token (&cp, &l); 774 768 if (p != 0) 775 769 { 776 pattern = savestring (p, len);777 p = find_next_token (& p2, &len);770 vpat = savestring (p, l); 771 p = find_next_token (&cp, &l); 778 772 /* No searchpath means remove all previous 779 773 selective VPATH's with the same pattern. */ … … 781 775 else 782 776 /* No pattern means remove all previous selective VPATH's. */ 783 pattern= 0;784 construct_vpath_list ( pattern, p);785 if ( pattern!= 0)786 free ( pattern);777 vpat = 0; 778 construct_vpath_list (vpat, p); 779 if (vpat != 0) 780 free (vpat); 787 781 788 782 goto rule_complete; … … 829 823 { 830 824 struct nameseq *next = files->next; 831 c har *name = files->name;825 const char *name = files->name; 832 826 int r; 833 827 834 free ( (char *)files);828 free (files); 835 829 files = next; 836 830 … … 839 833 if (!r && !noerror) 840 834 error (fstart, "%s: %s", name, strerror (errno)); 841 free (name);842 835 } 843 836 … … 855 848 was no preceding target, and the line might have been usable as a 856 849 variable definition. But now we know it is definitely lossage. */ 857 if (line[0] == '\t')850 if (line[0] == cmd_prefix) 858 851 fatal(fstart, _("commands commence before first target")); 859 852 … … 873 866 int exported; 874 867 char *cmdleft, *semip, *lb_next; 875 unsigned int len,plen = 0;868 unsigned int plen = 0; 876 869 char *colonp; 877 870 const char *end, *beg; /* Helpers for whitespace stripping. */ … … 902 895 beginning, expanding as we go, and looking for "interesting" 903 896 chars. The first word is always expandable. */ 904 wtype = get_next_mword(line, NULL, &lb_next, & len);897 wtype = get_next_mword(line, NULL, &lb_next, &wlen); 905 898 switch (wtype) 906 899 { … … 923 916 } 924 917 925 p2 = variable_expand_string(NULL, lb_next, len);918 p2 = variable_expand_string(NULL, lb_next, wlen); 926 919 927 920 while (1) 928 921 { 929 lb_next += len;922 lb_next += wlen; 930 923 if (cmdleft == 0) 931 924 { … … 972 965 break; 973 966 974 wtype = get_next_mword(lb_next, NULL, &lb_next, & len);967 wtype = get_next_mword(lb_next, NULL, &lb_next, &wlen); 975 968 if (wtype == w_eol) 976 969 break; … … 978 971 p2 += strlen(p2); 979 972 *(p2++) = ' '; 980 p2 = variable_expand_string(p2, lb_next, len);973 p2 = variable_expand_string(p2, lb_next, wlen); 981 974 /* We don't need to worry about cmdleft here, because if it was 982 975 found in the variable_buffer the entire buffer has already … … 1033 1026 unsigned int l = p2 - variable_buffer; 1034 1027 plen = strlen (p2); 1035 (void) variable_buffer_output (p2+plen, 1036 lb_next, strlen (lb_next)+1); 1028 variable_buffer_output (p2+plen, lb_next, strlen (lb_next)+1); 1037 1029 p2 = variable_buffer + l; 1038 1030 } … … 1041 1033 comes after it looks like a variable definition. */ 1042 1034 1043 wtype = get_next_mword (p2, NULL, &p, & len);1035 wtype = get_next_mword (p2, NULL, &p, &wlen); 1044 1036 1045 1037 v_origin = o_file; … … 1050 1042 { 1051 1043 v_origin = o_override; 1052 wtype = get_next_mword (p+ len, NULL, &p, &len);1044 wtype = get_next_mword (p+wlen, NULL, &p, &wlen); 1053 1045 } 1054 1046 else if (word1eq ("export")) 1055 1047 { 1056 1048 exported = 1; 1057 wtype = get_next_mword (p+ len, NULL, &p, &len);1049 wtype = get_next_mword (p+wlen, NULL, &p, &wlen); 1058 1050 } 1059 1051 } 1060 1052 1061 1053 if (wtype != w_eol) 1062 wtype = get_next_mword (p+ len, NULL, NULL, NULL);1054 wtype = get_next_mword (p+wlen, NULL, NULL, NULL); 1063 1055 1064 1056 if (wtype == w_varassign) … … 1135 1127 { 1136 1128 int check_again; 1137 1138 1129 do { 1139 1130 check_again = 0; … … 1157 1148 else if (target->next != 0) 1158 1149 fatal (fstart, _("multiple target patterns")); 1150 pattern_percent = find_percent_cached (&target->name); 1159 1151 pattern = target->name; 1160 pattern_percent = find_percent (pattern);1161 1152 if (pattern_percent == 0) 1162 1153 fatal (fstart, _("target pattern contains no `%%'")); 1163 free ( (char *)target);1154 free (target); 1164 1155 } 1165 1156 else … … 1175 1166 /* Put all the prerequisites here; they'll be parsed later. */ 1176 1167 deps = alloc_dep (); 1177 deps->name = s avestring(beg, end - beg + 1);1168 deps->name = strcache_add_len (beg, end - beg + 1); 1178 1169 } 1179 1170 else … … 1184 1175 { 1185 1176 /* Semicolon means rest of line is a command. */ 1186 unsigned int l en= strlen (cmdleft);1177 unsigned int l = strlen (cmdleft); 1187 1178 1188 1179 cmds_started = fstart->lineno; 1189 1180 1190 1181 /* Add this command line to the buffer. */ 1191 if (l en+ 2 > commands_len)1182 if (l + 2 > commands_len) 1192 1183 { 1193 commands_len = (l en+ 2) * 2;1194 commands = (char *)xrealloc (commands, commands_len);1184 commands_len = (l + 2) * 2; 1185 commands = xrealloc (commands, commands_len); 1195 1186 } 1196 bcopy (cmdleft, commands, len);1197 commands_idx += l en;1187 memcpy (commands, cmdleft, l); 1188 commands_idx += l; 1198 1189 commands[commands_idx++] = '\n'; 1199 1190 } … … 1217 1208 if (**default_goal_name == '\0' && set_default) 1218 1209 { 1219 c har*name;1210 const char *name; 1220 1211 struct dep *d; 1221 1212 struct nameseq *t = filenames; … … 1252 1243 for (d2 = suffix_file->deps; d2 != 0; d2 = d2->next) 1253 1244 { 1254 register unsigned int len= strlen (dep_name (d2));1255 if (!strneq (name, dep_name (d2), l en))1245 unsigned int l = strlen (dep_name (d2)); 1246 if (!strneq (name, dep_name (d2), l)) 1256 1247 continue; 1257 if (streq (name + l en, dep_name (d)))1248 if (streq (name + l, dep_name (d))) 1258 1249 { 1259 1250 reject = 1; … … 1294 1285 1295 1286 if (collapsed) 1296 free ( (char *)collapsed);1297 free ( (char *)commands);1287 free (collapsed); 1288 free (commands); 1298 1289 1299 1290 return 1; … … 1329 1320 int nlevels = 1; 1330 1321 unsigned int length = 100; 1331 char *definition = (char *)xmalloc (length);1322 char *definition = xmalloc (length); 1332 1323 unsigned int idx = 0; 1333 1324 char *p; 1334 1325 1335 1326 /* Expand the variable name. */ 1336 char *var = (char *)alloca (namelen + 1);1337 bcopy (name, var, namelen);1327 char *var = alloca (namelen + 1); 1328 memcpy (var, name, namelen); 1338 1329 var[namelen] = '\0'; 1339 1330 var = variable_expand (var); … … 1361 1352 1362 1353 /* Stop if we find an 'endef' */ 1363 if (line[0] != '\t')1354 if (line[0] != cmd_prefix) 1364 1355 { 1365 1356 p = next_token (line); … … 1404 1395 { 1405 1396 length = (idx + len) * 2; 1406 definition = (char *)xrealloc (definition, length + 1);1397 definition = xrealloc (definition, length + 1); 1407 1398 } 1408 1399 1409 bcopy (line, &definition[idx], len);1400 memcpy (&definition[idx], line, len); 1410 1401 idx += len; 1411 1402 /* Separate lines with a newline. */ … … 1535 1526 { 1536 1527 conditionals->allocated = 5; 1537 conditionals->ignoring = (char *)xmalloc (conditionals->allocated);1538 conditionals->seen_else = (char *)xmalloc (conditionals->allocated);1528 conditionals->ignoring = xmalloc (conditionals->allocated); 1529 conditionals->seen_else = xmalloc (conditionals->allocated); 1539 1530 } 1540 1531 … … 1543 1534 { 1544 1535 conditionals->allocated += 5; 1545 conditionals->ignoring = (char *)1546 xrealloc (conditionals->ignoring,conditionals->allocated);1547 conditionals->seen_else = (char *)1548 xrealloc (conditionals->seen_else,conditionals->allocated);1536 conditionals->ignoring = xrealloc (conditionals->ignoring, 1537 conditionals->allocated); 1538 conditionals->seen_else = xrealloc (conditionals->seen_else, 1539 conditionals->allocated); 1549 1540 } 1550 1541 … … 1590 1581 else 1591 1582 { 1592 /* " Ifeq" or "ifneq". */1583 /* "ifeq" or "ifneq". */ 1593 1584 char *s1, *s2; 1594 unsigned int l en;1585 unsigned int l; 1595 1586 char termin = *line == '(' ? ',' : *line; 1596 1587 … … 1632 1623 /* We must allocate a new copy of the expanded string because 1633 1624 variable_expand re-uses the same buffer. */ 1634 l en= strlen (s2);1635 s1 = (char *) alloca (len+ 1);1636 bcopy (s2, s1, len+ 1);1625 l = strlen (s2); 1626 s1 = alloca (l + 1); 1627 memcpy (s1, s2, l + 1); 1637 1628 1638 1629 if (termin != ',') … … 1647 1638 if (termin == ')') 1648 1639 { 1649 registerint count = 0;1640 int count = 0; 1650 1641 s2 = next_token (line); 1651 1642 for (line = s2; *line != '\0'; ++line) … … 1782 1773 { 1783 1774 struct variable *v; 1784 registerchar *name = filenames->name;1785 c har *fname;1786 c har *percent;1775 const char *name = filenames->name; 1776 const char *fname; 1777 const char *percent; 1787 1778 struct pattern_var *p; 1788 1779 1789 1780 nextf = filenames->next; 1790 free ( (char *)filenames);1781 free (filenames); 1791 1782 1792 1783 /* If it's a pattern target, then add it to the pattern-specific 1793 1784 variable list. */ 1794 percent = find_percent (name);1785 percent = find_percent_cached (&name); 1795 1786 if (percent) 1796 1787 { … … 1820 1811 f = lookup_file (name); 1821 1812 if (!f) 1822 f = enter_file ( name);1813 f = enter_file (strcache_add (name)); 1823 1814 else if (f->double_colon) 1824 1815 f = f->double_colon; … … 1857 1848 } 1858 1849 } 1859 1860 /* Free name if not needed further. */1861 if (name != fname && (name < fname || name > fname + strlen (fname)))1862 free (name);1863 1850 } 1864 1851 } … … 1877 1864 1878 1865 static void 1879 record_files (struct nameseq *filenames, char *pattern, char *pattern_percent, 1880 struct dep *deps, unsigned int cmds_started, char *commands, 1866 record_files (struct nameseq *filenames, const char *pattern, 1867 const char *pattern_percent, struct dep *deps, 1868 unsigned int cmds_started, char *commands, 1881 1869 unsigned int commands_idx, int two_colon, 1882 1870 const struct floc *flocp) … … 1885 1873 int implicit = 0; 1886 1874 unsigned int max_targets = 0, target_idx = 0; 1887 c har **targets = 0, **target_percents = 0;1875 const char **targets = 0, **target_percents = 0; 1888 1876 struct commands *cmds; 1889 1877 … … 1897 1885 if (commands_idx > 0) 1898 1886 { 1899 cmds = (struct commands *)xmalloc (sizeof (struct commands));1887 cmds = xmalloc (sizeof (struct commands)); 1900 1888 cmds->fileinfo.filenm = flocp->filenm; 1901 1889 cmds->fileinfo.lineno = cmds_started; … … 1908 1896 for (; filenames != 0; filenames = nextf) 1909 1897 { 1910 c har *name = filenames->name;1898 const char *name = filenames->name; 1911 1899 struct file *f; 1912 1900 struct dep *this = 0; 1913 c har *implicit_percent;1901 const char *implicit_percent; 1914 1902 1915 1903 nextf = filenames->next; … … 1924 1912 second_expansion = 1; 1925 1913 1926 implicit_percent = find_percent (name);1914 implicit_percent = find_percent_cached (&name); 1927 1915 implicit |= implicit_percent != 0; 1928 1916 1929 if (implicit && pattern != 0)1930 fatal (flocp, _("mixed implicit and static pattern rules"));1931 1932 if (implicit && implicit_percent == 0)1933 fatal (flocp, _("mixed implicit and normal rules"));1934 1935 1917 if (implicit) 1936 { 1918 { 1919 if (pattern != 0) 1920 fatal (flocp, _("mixed implicit and static pattern rules")); 1921 1922 if (implicit_percent == 0) 1923 fatal (flocp, _("mixed implicit and normal rules")); 1924 1937 1925 if (targets == 0) 1938 1926 { 1939 1927 max_targets = 5; 1940 targets = (char **)xmalloc (5 * sizeof (char *));1941 target_percents = (char **)xmalloc (5 * sizeof (char *));1928 targets = xmalloc (5 * sizeof (char *)); 1929 target_percents = xmalloc (5 * sizeof (char *)); 1942 1930 target_idx = 0; 1943 1931 } … … 1945 1933 { 1946 1934 max_targets += 5; 1947 targets = (char **) xrealloc ((char *) targets, 1948 max_targets * sizeof (char *)); 1949 target_percents 1950 = (char **) xrealloc ((char *) target_percents, 1951 max_targets * sizeof (char *)); 1935 targets = xrealloc (targets, max_targets * sizeof (char *)); 1936 target_percents = xrealloc (target_percents, 1937 max_targets * sizeof (char *)); 1952 1938 } 1953 1939 targets[target_idx] = name; … … 1976 1962 /* Single-colon. Combine these dependencies 1977 1963 with others in file's existing record, if any. */ 1978 f = enter_file ( name);1964 f = enter_file (strcache_add (name)); 1979 1965 1980 1966 if (f->double_colon) … … 2082 2068 fatal (flocp, 2083 2069 _("target file `%s' has both : and :: entries"), f->name); 2084 f = enter_file ( name);2070 f = enter_file (strcache_add (name)); 2085 2071 /* If there was an existing entry and it was a double-colon entry, 2086 2072 enter_file will have returned a new one, making it the prev … … 2101 2087 if (pattern) 2102 2088 { 2103 static c har *percent = "%";2089 static const char *percent = "%"; 2104 2090 char *buffer = variable_expand (""); 2105 char *o = patsubst_expand (buffer, name, pattern, percent,2106 pattern_percent+1, percent+1);2107 f->stem = s avestring(buffer, o - buffer);2091 char *o = patsubst_expand_pat (buffer, name, pattern, percent, 2092 pattern_percent+1, percent+1); 2093 f->stem = strcache_add_len (buffer, o - buffer); 2108 2094 if (this) 2109 2095 { 2110 2096 this->staticpattern = 1; 2111 this->stem = xstrdup (f->stem);2097 this->stem = f->stem; 2112 2098 } 2113 2099 } 2114 2100 2115 /* Free name if not needed further. */ 2116 if (f != 0 && name != f->name 2117 && (name < f->name || name > f->name + strlen (f->name))) 2118 { 2119 free (name); 2120 name = f->name; 2121 } 2101 name = f->name; 2122 2102 2123 2103 /* If this target is a default target, update DEFAULT_GOAL_FILE. */ … … 2130 2110 if (implicit) 2131 2111 { 2132 targets[target_idx] = 0;2133 target_percents[target_idx] = 0;2134 2112 if (deps) 2135 2113 deps->need_2nd_expansion = second_expansion; 2136 create_pattern_rule (targets, target_percents, t wo_colon, deps, cmds, 1);2137 free ((char *) target_percents);2114 create_pattern_rule (targets, target_percents, target_idx, 2115 two_colon, deps, cmds, 1); 2138 2116 } 2139 2117 } … … 2154 2132 { 2155 2133 unsigned int string_len = 0; 2156 registerchar *p = string;2134 char *p = string; 2157 2135 2158 2136 if (ignorevars) … … 2213 2191 { 2214 2192 /* Search for more backslashes. */ 2215 registerint i = -2;2193 int i = -2; 2216 2194 while (&p[i] >= string && p[i] == '\\') 2217 2195 --i; … … 2222 2200 /* The number of backslashes is now -I. 2223 2201 Copy P over itself to swallow half of them. */ 2224 bcopy (&p[i / 2], &p[i], (string_len - (p - string)) - (i /2) + 1);2225 p += i /2;2202 memmove (&p[i], &p[i/2], (string_len - (p - string)) - (i/2) + 1); 2203 p += i/2; 2226 2204 if (i % 2 == 0) 2227 2205 /* All the backslashes quoted each other; the STOPCHAR was … … 2240 2218 } 2241 2219 2242 /* Search PATTERN for an unquoted % . */2220 /* Search PATTERN for an unquoted % and handle quoting. */ 2243 2221 2244 2222 char * … … 2246 2224 { 2247 2225 return find_char_unquote (pattern, '%', 0, 0, 0); 2226 } 2227 2228 /* Search STRING for an unquoted % and handle quoting. Returns a pointer to 2229 the % or NULL if no % was found. 2230 This version is used with strings in the string cache: if there's a need to 2231 modify the string a new version will be added to the string cache and 2232 *STRING will be set to that. */ 2233 2234 const char * 2235 find_percent_cached (const char **string) 2236 { 2237 const char *p = *string; 2238 char *new = 0; 2239 int slen; 2240 2241 /* If the first char is a % return now. This lets us avoid extra tests 2242 inside the loop. */ 2243 if (*p == '%') 2244 return p; 2245 2246 while (1) 2247 { 2248 while (*p != '\0' && *p != '%') 2249 ++p; 2250 2251 if (*p == '\0') 2252 break; 2253 2254 /* See if this % is escaped with a backslash; if not we're done. */ 2255 if (p[-1] != '\\') 2256 break; 2257 2258 { 2259 /* Search for more backslashes. */ 2260 char *pv; 2261 int i = -2; 2262 2263 while (&p[i] >= *string && p[i] == '\\') 2264 --i; 2265 ++i; 2266 2267 /* At this point we know we'll need to allocate a new string. 2268 Make a copy if we haven't yet done so. */ 2269 if (! new) 2270 { 2271 slen = strlen (*string); 2272 new = alloca (slen + 1); 2273 memcpy (new, *string, slen + 1); 2274 p = new + (p - *string); 2275 *string = new; 2276 } 2277 2278 /* At this point *string, p, and new all point into the same string. 2279 Get a non-const version of p so we can modify new. */ 2280 pv = new + (p - *string); 2281 2282 /* The number of backslashes is now -I. 2283 Copy P over itself to swallow half of them. */ 2284 memmove (&pv[i], &pv[i/2], (slen - (pv - new)) - (i/2) + 1); 2285 p += i/2; 2286 2287 /* If the backslashes quoted each other; the % was unquoted. */ 2288 if (i % 2 == 0) 2289 break; 2290 } 2291 } 2292 2293 /* If we had to change STRING, add it to the strcache. */ 2294 if (new) 2295 { 2296 *string = strcache_add (*string); 2297 p = *string + (p - new); 2298 } 2299 2300 /* If we didn't find a %, return NULL. Otherwise return a ptr to it. */ 2301 return (*p == '\0') ? NULL : p; 2248 2302 } 2249 2303 … … 2268 2322 struct nameseq *new1, *lastnew1; 2269 2323 char *p = *stringp; 2270 char *q;2271 char *name;2272 2324 2273 2325 #ifdef VMS … … 2279 2331 while (1) 2280 2332 { 2333 const char *name; 2334 char *q; 2335 2281 2336 /* Skip whitespace; see if any more names are left. */ 2282 2337 p = next_token (p); … … 2286 2341 break; 2287 2342 2288 /* Yes, find end ofnext name. */2343 /* There are, so find the end of the next name. */ 2289 2344 q = p; 2290 2345 p = find_char_unquote (q, stopchar, VMS_COMMA, 1, 0); … … 2298 2353 && !(isspace ((unsigned char)p[1]) || !p[1] 2299 2354 || isspace ((unsigned char)p[-1]))) 2300 {2301 2355 p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0); 2302 }2303 2356 #endif 2304 2357 #ifdef HAVE_DOS_PATHS … … 2334 2387 if (q == p) 2335 2388 /* ".///" was stripped to "". */ 2336 #if def VMS2389 #if defined(VMS) 2337 2390 continue; 2391 #elif defined(_AMIGA) 2392 name = ""; 2338 2393 #else 2339 #ifdef _AMIGA 2340 name = savestring ("", 0); 2341 #else 2342 name = savestring ("./", 2); 2343 #endif 2394 name = "./"; 2344 2395 #endif 2345 2396 else … … 2365 2416 *q2++ = *q1++; 2366 2417 } 2367 name = s avestring(qbase, p1 - qbase);2418 name = strcache_add_len (qbase, p1 - qbase); 2368 2419 free (qbase); 2369 2420 } 2370 2421 #else 2371 name = s avestring(q, p - q);2422 name = strcache_add_len (q, p - q); 2372 2423 #endif 2373 2424 2374 2425 /* Add it to the front of the chain. */ 2375 new1 = (struct nameseq *)xmalloc (size);2426 new1 = xmalloc (size); 2376 2427 new1->name = name; 2377 2428 new1->next = new; … … 2416 2467 /* Copy "lib(" into LIBNAME. */ 2417 2468 ++paren; 2418 libname = (char *)alloca (paren - n->name + 1);2419 bcopy (n->name, libname, paren - n->name);2469 libname = alloca (paren - n->name + 1); 2470 memcpy (libname, n->name, paren - n->name); 2420 2471 libname[paren - n->name] = '\0'; 2421 2472 … … 2425 2476 Edit it out of the chain and free its storage. */ 2426 2477 lastn->next = n->next; 2427 free (n->name); 2428 free ((char *) n); 2478 free (n); 2429 2479 /* LASTN->next is the new stopping elt for the loop below. */ 2430 2480 n = lastn->next; … … 2433 2483 { 2434 2484 /* Replace N's name with the full archive reference. */ 2435 name = concat (libname, paren, ")"); 2436 free (n->name); 2437 n->name = name; 2485 n->name = strcache_add (concat (libname, paren, ")")); 2438 2486 } 2439 2487 … … 2448 2496 lastn = new1; 2449 2497 new1 = new1->next; 2450 free (lastn->name); 2451 free ((char *) lastn); 2498 free (lastn); 2452 2499 } 2453 2500 else 2454 2501 { 2455 2502 /* Replace also NEW1->name, which already has closing `)'. */ 2456 name = concat (libname, new1->name, ""); 2457 free (new1->name); 2458 new1->name = name; 2503 new1->name = strcache_add (concat (libname, new1->name, "")); 2459 2504 new1 = new1->next; 2460 2505 } … … 2466 2511 while (new1 != n) 2467 2512 { 2468 name = concat (libname, new1->name, ")"); 2469 free (new1->name); 2470 new1->name = name; 2513 new1->name = strcache_add (concat (libname, new1->name, ")")); 2471 2514 lastnew1 = new1; 2472 2515 new1 = new1->next; … … 2636 2679 unsigned long off = p - start; 2637 2680 ebuf->size *= 2; 2638 start = ebuf->buffer = ebuf->bufstart = (char *) xrealloc (start, 2639 ebuf->size); 2681 start = ebuf->buffer = ebuf->bufstart = xrealloc (start, ebuf->size); 2640 2682 p = start + off; 2641 2683 end = start + ebuf->size; … … 2840 2882 2841 2883 void 2842 construct_include_path (c har **arg_dirs)2884 construct_include_path (const char **arg_dirs) 2843 2885 { 2844 register unsigned int i;2845 2886 #ifdef VAXC /* just don't ask ... */ 2846 2887 stat_t stbuf; … … 2848 2889 struct stat stbuf; 2849 2890 #endif 2850 /* Table to hold the dirs. */ 2851 2852 register unsigned int defsize = (sizeof (default_include_directories) 2853 / sizeof (default_include_directories[0])); 2854 register unsigned int max = 5; 2855 register char **dirs = (char **) xmalloc ((5 + defsize) * sizeof (char *)); 2856 register unsigned int idx = 0; 2891 const char **dirs; 2892 const char **cpp; 2893 unsigned int idx; 2894 2895 /* Compute the number of pointers we need in the table. */ 2896 idx = sizeof (default_include_directories) / sizeof (const char *); 2897 if (arg_dirs) 2898 for (cpp = arg_dirs; *cpp != 0; ++cpp) 2899 ++idx; 2857 2900 2858 2901 #ifdef __MSDOS__ 2859 defsize++; 2902 /* Add one for $DJDIR. */ 2903 ++idx; 2860 2904 #endif 2861 2905 2906 dirs = xmalloc (idx * sizeof (const char *)); 2907 2908 idx = 0; 2909 max_incl_len = 0; 2910 2862 2911 /* First consider any dirs specified with -I switches. 2863 Ignore dirs that don't exist. */2864 2865 if (arg_dirs != 0)2912 Ignore any that don't exist. Remember the maximum string length. */ 2913 2914 if (arg_dirs) 2866 2915 while (*arg_dirs != 0) 2867 2916 { 2868 char *dir = *arg_dirs++; 2917 const char *dir = *(arg_dirs++); 2918 char *expanded = 0; 2869 2919 int e; 2870 2920 2871 2921 if (dir[0] == '~') 2872 2922 { 2873 char *expanded = tilde_expand (dir);2923 expanded = tilde_expand (dir); 2874 2924 if (expanded != 0) 2875 2925 dir = expanded; … … 2878 2928 EINTRLOOP (e, stat (dir, &stbuf)); 2879 2929 if (e == 0 && S_ISDIR (stbuf.st_mode)) 2880 { 2881 if (idx == max - 1) 2882 { 2883 max += 5; 2884 dirs = (char **) 2885 xrealloc ((char *) dirs, (max + defsize) * sizeof (char *)); 2886 } 2887 dirs[idx++] = dir; 2888 } 2889 else if (dir != arg_dirs[-1]) 2890 free (dir); 2930 { 2931 unsigned int len = strlen (dir); 2932 /* If dir name is written with trailing slashes, discard them. */ 2933 while (len > 1 && dir[len - 1] == '/') 2934 --len; 2935 if (len > max_incl_len) 2936 max_incl_len = len; 2937 dirs[idx++] = strcache_add_len (dir, len); 2938 } 2939 2940 if (expanded) 2941 free (expanded); 2891 2942 } 2892 2943 2893 /* Now add at the end the standard default dirs. */2944 /* Now add the standard default dirs at the end. */ 2894 2945 2895 2946 #ifdef __MSDOS__ 2896 2947 { 2897 /* The environment variable $DJDIR holds the root of the 2898 DJGPP directorytree; add ${DJDIR}/include. */2948 /* The environment variable $DJDIR holds the root of the DJGPP directory 2949 tree; add ${DJDIR}/include. */ 2899 2950 struct variable *djdir = lookup_variable ("DJDIR", 5); 2900 2951 2901 2952 if (djdir) 2902 2953 { 2903 char *defdir = (char *) xmalloc (strlen (djdir->value) + 8 + 1); 2954 unsigned int len = strlen (djdir->value) + 8; 2955 char *defdir = alloca (len + 1); 2904 2956 2905 2957 strcat (strcpy (defdir, djdir->value), "/include"); 2906 dirs[idx++] = defdir; 2958 dirs[idx++] = strcache_add (defdir); 2959 2960 if (len > max_incl_len) 2961 max_incl_len = len; 2907 2962 } 2908 2963 } 2909 2964 #endif 2910 2965 2911 for ( i = 0; default_include_directories[i] != 0; ++i)2966 for (cpp = default_include_directories; *cpp != 0; ++cpp) 2912 2967 { 2913 2968 int e; 2914 2969 2915 EINTRLOOP (e, stat ( default_include_directories[i], &stbuf));2970 EINTRLOOP (e, stat (*cpp, &stbuf)); 2916 2971 if (e == 0 && S_ISDIR (stbuf.st_mode)) 2917 dirs[idx++] = default_include_directories[i]; 2972 { 2973 unsigned int len = strlen (*cpp); 2974 /* If dir name is written with trailing slashes, discard them. */ 2975 while (len > 1 && (*cpp)[len - 1] == '/') 2976 --len; 2977 if (len > max_incl_len) 2978 max_incl_len = len; 2979 dirs[idx++] = strcache_add_len (*cpp, len - 1); 2980 } 2918 2981 } 2919 2982 2920 2983 dirs[idx] = 0; 2921 2984 2922 /* Now compute the maximum length of any name in it. Also add each 2923 dir to the .INCLUDE_DIRS variable. */ 2924 2925 max_incl_len = 0; 2926 for (i = 0; i < idx; ++i) 2927 { 2928 unsigned int len = strlen (dirs[i]); 2929 /* If dir name is written with a trailing slash, discard it. */ 2930 if (dirs[i][len - 1] == '/') 2931 /* We can't just clobber a null in because it may have come from 2932 a literal string and literal strings may not be writable. */ 2933 dirs[i] = savestring (dirs[i], len - 1); 2934 if (len > max_incl_len) 2935 max_incl_len = len; 2936 2937 /* Append to .INCLUDE_DIRS. */ 2938 do_variable_definition (NILF, ".INCLUDE_DIRS", dirs[i], 2939 o_default, f_append, 0); 2940 } 2985 /* Now add each dir to the .INCLUDE_DIRS variable. */ 2986 2987 for (cpp = dirs; *cpp != 0; ++cpp) 2988 do_variable_definition (NILF, ".INCLUDE_DIRS", *cpp, 2989 o_default, f_append, 0); 2941 2990 2942 2991 include_directories = dirs; … … 2948 2997 2949 2998 char * 2950 tilde_expand (c har *name)2999 tilde_expand (const char *name) 2951 3000 { 2952 3001 #ifndef VMS … … 2973 3022 home_dir = getenv ("HOME"); 2974 3023 } 2975 # if !defined(_AMIGA) && !defined(WINDOWS32)3024 # if !defined(_AMIGA) && !defined(WINDOWS32) 2976 3025 if (home_dir == 0 || home_dir[0] == '\0') 2977 3026 { … … 2986 3035 } 2987 3036 } 2988 # endif /* !AMIGA && !WINDOWS32 */3037 # endif /* !AMIGA && !WINDOWS32 */ 2989 3038 if (home_dir != 0) 2990 3039 { 2991 char *new = concat (home_dir, "", name + 1);3040 char *new = xstrdup (concat (home_dir, "", name + 1)); 2992 3041 if (is_variable) 2993 3042 free (home_dir); … … 2995 3044 } 2996 3045 } 2997 # if !defined(_AMIGA) && !defined(WINDOWS32)3046 # if !defined(_AMIGA) && !defined(WINDOWS32) 2998 3047 else 2999 3048 { … … 3008 3057 return xstrdup (pwent->pw_dir); 3009 3058 else 3010 return concat (pwent->pw_dir, "/", userend + 1);3059 return xstrdup (concat (pwent->pw_dir, "/", userend + 1)); 3011 3060 } 3012 3061 else if (userend != 0) 3013 3062 *userend = '/'; 3014 3063 } 3015 # endif /* !AMIGA && !WINDOWS32 */3064 # endif /* !AMIGA && !WINDOWS32 */ 3016 3065 #endif /* !VMS */ 3017 3066 return 0; … … 3031 3080 multi_glob (struct nameseq *chain, unsigned int size) 3032 3081 { 3033 extern void dir_setup_glob ();3034 registerstruct nameseq *new = 0;3035 registerstruct nameseq *old;3082 void dir_setup_glob (glob_t *); 3083 struct nameseq *new = 0; 3084 struct nameseq *old; 3036 3085 struct nameseq *nexto; 3037 3086 glob_t gl; … … 3041 3090 for (old = chain; old != 0; old = nexto) 3042 3091 { 3092 const char *gname; 3043 3093 #ifndef NO_ARCHIVES 3044 char *memname; 3094 char *arname = 0; 3095 char *memname = 0; 3045 3096 #endif 3046 3047 3097 nexto = old->next; 3048 3049 if (old->name[0] == '~') 3098 gname = old->name; 3099 3100 if (gname[0] == '~') 3050 3101 { 3051 3102 char *newname = tilde_expand (old->name); 3052 3103 if (newname != 0) 3053 { 3054 free (old->name); 3055 old->name = newname; 3056 } 3104 gname = newname; 3057 3105 } 3058 3106 3059 3107 #ifndef NO_ARCHIVES 3060 if (ar_name ( old->name))3108 if (ar_name (gname)) 3061 3109 { 3062 /* OLD->name is an archive member reference. 3063 Replace it with the archive file name, 3064 and save the member name in MEMNAME. 3065 We will glob on the archive name and then 3066 reattach MEMNAME later. */ 3067 char *arname; 3068 ar_parse_name (old->name, &arname, &memname); 3069 free (old->name); 3070 old->name = arname; 3071 } 3072 else 3073 memname = 0; 3110 /* OLD->name is an archive member reference. Replace it with the 3111 archive file name, and save the member name in MEMNAME. We will 3112 glob on the archive name and then reattach MEMNAME later. */ 3113 ar_parse_name (gname, &arname, &memname); 3114 gname = arname; 3115 } 3074 3116 #endif /* !NO_ARCHIVES */ 3075 3117 3076 switch (glob ( old->name, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl))3118 switch (glob (gname, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl)) 3077 3119 { 3078 3120 case 0: /* Success. */ 3079 3121 { 3080 registerint i = gl.gl_pathc;3122 int i = gl.gl_pathc; 3081 3123 while (i-- > 0) 3082 3124 { … … 3087 3129 struct nameseq *found 3088 3130 = ar_glob (gl.gl_pathv[i], memname, size); 3089 if ( found == 0)3131 if (! found) 3090 3132 { 3091 3133 /* No matches. Use MEMNAME as-is. */ 3092 3134 unsigned int alen = strlen (gl.gl_pathv[i]); 3093 3135 unsigned int mlen = strlen (memname); 3094 struct nameseq *elt 3095 = (struct nameseq *)xmalloc (size);3096 if (size > sizeof (struct nameseq))3097 bzero (((char *) elt) + sizeof (struct nameseq), 3098 size - sizeof (struct nameseq));3099 elt->name = (char *) xmalloc (alen + 1 + mlen + 2);3100 bcopy (gl.gl_pathv[i], elt->name, alen);3101 elt->name[alen] = '(';3102 bcopy (memname, &elt->name[alen + 1], mlen);3103 elt->name[alen + 1 + mlen] = ')';3104 elt->name[alen + 1 + mlen + 1] = '\0';3136 char *name; 3137 struct nameseq *elt = xmalloc (size); 3138 memset (elt, '\0', size); 3139 3140 name = alloca (alen + 1 + mlen + 2); 3141 memcpy (name, gl.gl_pathv[i], alen); 3142 name[alen] = '('; 3143 memcpy (name+alen+1, memname, mlen); 3144 name[alen + 1 + mlen] = ')'; 3145 name[alen + 1 + mlen + 1] = '\0'; 3146 elt->name = strcache_add (name); 3105 3147 elt->next = new; 3106 3148 new = elt; … … 3118 3160 new = found; 3119 3161 } 3120 3121 free (memname);3122 3162 } 3123 3163 else 3124 3164 #endif /* !NO_ARCHIVES */ 3125 3165 { 3126 struct nameseq *elt = (struct nameseq *) xmalloc (size); 3127 if (size > sizeof (struct nameseq)) 3128 bzero (((char *) elt) + sizeof (struct nameseq), 3129 size - sizeof (struct nameseq)); 3130 elt->name = xstrdup (gl.gl_pathv[i]); 3166 struct nameseq *elt = xmalloc (size); 3167 memset (elt, '\0', size); 3168 elt->name = strcache_add (gl.gl_pathv[i]); 3131 3169 elt->next = new; 3132 3170 new = elt; … … 3134 3172 } 3135 3173 globfree (&gl); 3136 free (old->name); 3137 free ((char *)old); 3174 free (old); 3138 3175 break; 3139 3176 } … … 3148 3185 break; 3149 3186 } 3187 3188 #ifndef NO_ARCHIVES 3189 if (arname) 3190 free (arname); 3191 #endif 3150 3192 } 3151 3193
Note:
See TracChangeset
for help on using the changeset viewer.