Changeset 3140 for trunk/src/kmk/read.c
- Timestamp:
- Mar 14, 2018, 10:28:10 PM (7 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk
-
Property svn:mergeinfo
set to
/vendor/gnumake/current merged eligible
-
Property svn:mergeinfo
set to
-
trunk/src/kmk/read.c
r2857 r3140 1 1 /* Reading and parsing of makefiles for GNU Make. 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 4 2010 Free Software Foundation, Inc. 2 Copyright (C) 1988-2016 Free Software Foundation, Inc. 5 3 This file is part of GNU Make. 6 4 … … 17 15 this program. If not, see <http://www.gnu.org/licenses/>. */ 18 16 19 #include "make .h"17 #include "makeint.h" 20 18 21 19 #include <assert.h> 22 20 23 #include <glob.h> 24 21 #include "filedef.h" 25 22 #include "dep.h" 26 #include "filedef.h"27 23 #include "job.h" 28 24 #include "commands.h" … … 35 31 #endif 36 32 37 #ifndef WINDOWS32 33 #ifdef WINDOWS32 34 #include <windows.h> 35 #include "sub_proc.h" 36 #else /* !WINDOWS32 */ 38 37 #ifndef _AMIGA 39 38 #ifndef VMS … … 59 58 unsigned int size; /* Malloc'd size of buffer. */ 60 59 FILE *fp; /* File, or NULL if this is an internal buffer. */ 61 struct floc floc;/* Info on the file in fp (if any). */60 floc floc; /* Info on the file in fp (if any). */ 62 61 }; 63 62 … … 82 81 83 82 84 /* A `struct conditionals' contains the information describing83 /* A 'struct conditionals' contains the information describing 85 84 all the active conditionals in a makefile. 86 85 87 The global variable `conditionals' contains the conditionals86 The global variable 'conditionals' contains the conditionals 88 87 information for the current makefile. It is initialized from 89 the static structure `toplevel_conditionals' and is later changed88 the static structure 'toplevel_conditionals' and is later changed 90 89 to new structures for included makefiles. */ 91 90 92 91 struct conditionals 93 92 { 94 unsigned int if_cmds; 95 unsigned int allocated; 96 char *ignoring; 93 unsigned int if_cmds; /* Depth of conditional nesting. */ 94 unsigned int allocated; /* Elts allocated in following arrays. */ 95 char *ignoring; /* Are we ignoring or interpreting? 97 96 0=interpreting, 1=not yet interpreted, 98 97 2=already interpreted */ 99 char *seen_else; /* Have we already seen an `else'? */98 char *seen_else; /* Have we already seen an 'else'? */ 100 99 #ifdef KMK 101 100 char ignoring_first[8]; … … 154 153 makefile currently being read in. */ 155 154 156 const structfloc *reading_file = 0;157 158 /* The chain of makefiles read by read_makefile. */159 160 static struct dep *read_makefiles = 0;161 162 static inteval_makefile (const char *filename, int flags);155 const floc *reading_file = 0; 156 157 /* The chain of files read by read_all_makefiles. */ 158 159 static struct goaldep *read_files = 0; 160 161 static struct goaldep *eval_makefile (const char *filename, int flags); 163 162 static void eval (struct ebuffer *buffer, int flags); 164 163 … … 169 168 enum variable_origin origin, struct ebuffer *ebuf); 170 169 #ifndef CONFIG_WITH_VALUE_LENGTH 171 static int conditional_line (char *line, int len, const structfloc *flocp);172 #else 173 static int conditional_line (char *line, char *eol, int len, const structfloc *flocp);170 static int conditional_line (char *line, int len, const floc *flocp); 171 #else 172 static int conditional_line (char *line, char *eol, int len, const floc *flocp); 174 173 #endif 175 174 static void record_files (struct nameseq *filenames, const char *pattern, … … 177 176 unsigned int cmds_started, char *commands, 178 177 unsigned int commands_idx, int two_colon, 179 c onst struct floc *flocp);178 char prefix, const floc *flocp); 180 179 static void record_target_var (struct nameseq *filenames, char *defn, 181 180 enum variable_origin origin, 182 181 struct vmodifiers *vmod, 183 const structfloc *flocp);182 const floc *flocp); 184 183 static enum make_word_type get_next_mword (char *buffer, char *delim, 185 184 char **startp, unsigned int *length); 186 185 #ifndef CONFIG_WITH_VALUE_LENGTH 187 186 static void remove_comments (char *line); 188 static char *find_char_unquote (char *string, int stop1, int stop2, 189 int blank, int ignorevars); 190 #else /* CONFIG_WITH_VALUE_LENGTH */ 191 __inline static char *remove_comments (char *line, char *eol); 192 __inline static char *find_char_unquote_0 (char *string, int stop1, char **eosp); 193 static char * find_char_unquote_2 (char *string, int stop1, int stop2, 194 int blank, int ignorevars, 195 unsigned int string_len); 196 MY_INLINE char * 197 find_char_unquote (char *string, int stop1, int stop2, int blank, int ignorevars) 198 { 199 if (!stop2 && !blank && !ignorevars) 200 { 201 char *p = strchr (string, stop1); 202 if (!p) 203 return NULL; 204 if (p <= string || p[-1] != '\\') 205 return p; 206 /* fall back on find_char_unquote_2 */ 207 } 208 return find_char_unquote_2 (string, stop1, stop2, blank, ignorevars, 0); 209 } 187 static char *find_char_unquote (char *string, int map); 188 #else /* CONFIG_WITH_VALUE_LENGTH */ 189 static char *remove_comments (char *line, char *eos); 190 static char *find_char_unquote (char *string, int map, unsigned int string_len); 191 K_INLINE char *find_char_unquote_0 (char *string, int stop1, int map, char **eosp); 210 192 #endif /* CONFIG_WITH_VALUE_LENGTH */ 193 static char *unescape_char (char *string, int c); 211 194 212 195 … … 214 197 P must point to the word to be tested, and WLEN must be the length. 215 198 */ 216 #define word1eq(s) (wlen == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))217 218 219 220 /* Read in all the makefiles and return the chain of their names. */221 222 struct dep *199 #define word1eq(s) (wlen == CSTRLEN (s) && strneq (s, p, CSTRLEN (s))) 200 201 202 203 /* Read in all the makefiles and return a chain of targets to rebuild. */ 204 205 struct goaldep * 223 206 read_all_makefiles (const char **makefiles) 224 207 { … … 261 244 while ((name = find_next_token ((const char **)&p, &length)) != 0) 262 245 { 263 264 265 246 if (*p != '\0') 247 *p++ = '\0'; 248 eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE); 266 249 } 267 250 … … 274 257 while (*makefiles != 0) 275 258 { 276 struct dep *tail = read_makefiles; 277 register struct dep *d; 278 279 if (! eval_makefile (*makefiles, 0)) 280 perror_with_name ("", *makefiles); 281 282 /* Find the right element of read_makefiles. */ 283 d = read_makefiles; 284 while (d->next != tail) 285 d = d->next; 286 287 /* Use the storage read_makefile allocates. */ 288 *makefiles = dep_name (d); 289 ++num_makefiles; 290 ++makefiles; 259 struct goaldep *d = eval_makefile (*makefiles, 0); 260 261 if (errno) 262 perror_with_name ("", *makefiles); 263 264 /* Reuse the storage allocated for the read_file. */ 265 *makefiles = dep_name (d); 266 ++num_makefiles; 267 ++makefiles; 291 268 } 292 269 … … 295 272 if (num_makefiles == 0) 296 273 { 297 static c har *default_makefiles[] =274 static const char *default_makefiles[] = 298 275 #ifdef VMS 299 /* all lower case since readdir() (the vms version) 'lowercasifies' */ 276 /* all lower case since readdir() (the vms version) 'lowercasifies' */ 277 /* TODO: Above is not always true, this needs more work */ 300 278 # ifdef KMK 301 279 { "makefile.kmk", "makefile.vms", "gnumakefile.", "makefile.", 0 }; 302 280 # else 303 { "makefile.vms", "gnumakefile.", "makefile.", 0 };281 { "makefile.vms", "gnumakefile", "makefile", 0 }; 304 282 # endif 305 283 #else 306 284 #ifdef _AMIGA 307 /* what's the deal here? no dots? */308 285 # ifdef KMK 309 286 { "Makefile.kmk", "makefile.kmk", "GNUmakefile", "Makefile", "SMakefile", 0 }; 310 287 # else 311 288 { "GNUmakefile", "Makefile", "SMakefile", 0 }; 312 289 # endif 313 290 #else /* !Amiga && !VMS */ 291 #ifdef WINDOWS32 314 292 # ifdef KMK 315 { "Makefile.kmk", "makefile.kmk", "GNUmakefile", "makefile", "Makefile", 0 };293 { "Makefile.kmk", "makefile.kmk", "GNUmakefile", "makefile", "Makefile", "makefile.mak", 0 }; 316 294 # else 317 { "GNUmakefile", "makefile", "Makefile", 0 }; 295 { "GNUmakefile", "makefile", "Makefile", "makefile.mak", 0 }; 296 # endif 297 #else /* !Amiga && !VMS && !WINDOWS32 */ 298 # ifdef KMK 299 { "Makefile.kmk", "makefile.kmk", "GNUmakefile", "makefile", "Makefile", 0 }; 300 # else 301 { "GNUmakefile", "makefile", "Makefile", 0 }; 318 302 # endif 303 #endif /* !Amiga && !VMS && !WINDOWS32 */ 319 304 #endif /* AMIGA */ 320 305 #endif /* VMS */ 321 registerchar **p = default_makefiles;306 const char **p = default_makefiles; 322 307 while (*p != 0 && !file_exists_p (*p)) 323 308 ++p; 324 309 325 310 if (*p != 0) 326 { 327 if (! eval_makefile (*p, 0)) 328 perror_with_name ("", *p); 329 } 311 { 312 eval_makefile (*p, 0); 313 if (errno) 314 perror_with_name ("", *p); 315 } 330 316 else 331 { 332 /* No default makefile was found. Add the default makefiles to the 333 `read_makefiles' chain so they will be updated if possible. */ 334 struct dep *tail = read_makefiles; 335 /* Add them to the tail, after any MAKEFILES variable makefiles. */ 336 while (tail != 0 && tail->next != 0) 337 tail = tail->next; 338 for (p = default_makefiles; *p != 0; ++p) 339 { 340 struct dep *d = alloc_dep (); 341 d->file = enter_file (strcache_add (*p)); 342 d->dontcare = 1; 343 /* Tell update_goal_chain to bail out as soon as this file is 344 made, and main not to die if we can't make this file. */ 345 d->changed = RM_DONTCARE; 346 if (tail == 0) 347 read_makefiles = d; 348 else 349 tail->next = d; 350 tail = d; 351 } 352 if (tail != 0) 353 tail->next = 0; 354 } 317 { 318 /* No default makefile was found. Add the default makefiles to the 319 'read_files' chain so they will be updated if possible. */ 320 struct goaldep *tail = read_files; 321 /* Add them to the tail, after any MAKEFILES variable makefiles. */ 322 while (tail != 0 && tail->next != 0) 323 tail = tail->next; 324 for (p = default_makefiles; *p != 0; ++p) 325 { 326 struct goaldep *d = alloc_goaldep (); 327 d->file = enter_file (strcache_add (*p)); 328 /* Tell update_goal_chain to bail out as soon as this file is 329 made, and main not to die if we can't make this file. */ 330 d->flags = RM_DONTCARE; 331 if (tail == 0) 332 read_files = d; 333 else 334 tail->next = d; 335 tail = d; 336 } 337 if (tail != 0) 338 tail->next = 0; 339 } 355 340 } 356 341 357 return read_ makefiles;342 return read_files; 358 343 } 359 344 … … 386 371 /* Free any space allocated by conditional_line. */ 387 372 #ifdef KMK 388 389 #endif 390 { 391 if (conditionals->ignoring)392 free (conditionals->ignoring);393 if (conditionals->seen_else) 394 free (conditionals->seen_else);395 } 373 if (conditionals->allocated > sizeof (conditionals->ignoring_first)) 374 { 375 #endif 376 free (conditionals->ignoring); 377 free (conditionals->seen_else); 378 #ifdef KMK 379 } 380 #endif 396 381 397 382 /* Restore state. */ … … 400 385 401 386 402 static int387 static struct goaldep * 403 388 eval_makefile (const char *filename, int flags) 404 389 { 405 struct dep *deps;390 struct goaldep *deps; 406 391 struct ebuffer ebuf; 407 const structfloc *curfile;392 const floc *curfile; 408 393 char *expanded = 0; 409 394 int makefile_errno; 410 395 411 filename = strcache_add (filename); 412 ebuf.floc.filenm = filename; 396 ebuf.floc.filenm = filename; /* Use the original file name. */ 413 397 ebuf.floc.lineno = 1; 398 ebuf.floc.offset = 0; 414 399 415 400 if (ISDB (DB_VERBOSE)) 416 401 { 417 printf (_("Reading makefile `%s'"), filename);402 printf (_("Reading makefile '%s'"), filename); 418 403 if (flags & RM_NO_DEFAULT_GOAL) 419 404 printf (_(" (no default goal)")); 420 405 if (flags & RM_INCLUDED) 421 406 printf (_(" (search path)")); 422 407 if (flags & RM_DONTCARE) 423 408 printf (_(" (don't care)")); 424 409 if (flags & RM_NO_TILDE) 425 410 printf (_(" (no ~ expansion)")); 426 411 puts ("..."); 427 412 } … … 429 414 /* First, get a stream to read. */ 430 415 431 /* Expand ~ in FILENAME unless it came from `include',416 /* Expand ~ in FILENAME unless it came from 'include', 432 417 in which case it was already done. */ 433 418 if (!(flags & RM_NO_TILDE) && filename[0] == '~') … … 435 420 expanded = tilde_expand (filename); 436 421 if (expanded != 0) 437 422 filename = expanded; 438 423 } 439 424 440 ebuf.fp = fopen (filename, "r"); 425 ENULLLOOP (ebuf.fp, fopen (filename, "r")); 426 441 427 /* Save the error code so we print the right message later. */ 442 428 makefile_errno = errno; 443 429 430 /* Check for unrecoverable errors: out of mem or FILE slots. */ 431 switch (makefile_errno) 432 { 433 #ifdef EMFILE 434 case EMFILE: 435 #endif 436 #ifdef ENFILE 437 case ENFILE: 438 #endif 439 case ENOMEM: 440 { 441 const char *err = strerror (makefile_errno); 442 OS (fatal, reading_file, "%s", err); 443 } 444 } 445 444 446 /* If the makefile wasn't found and it's either a makefile from 445 the `MAKEFILES' variable or an included makefile,447 the 'MAKEFILES' variable or an included makefile, 446 448 search the included makefile search path for this makefile. */ 447 449 if (ebuf.fp == 0 && (flags & RM_INCLUDED) && *filename != '/') … … 449 451 unsigned int i; 450 452 for (i = 0; include_directories[i] != 0; ++i) 451 452 453 { 454 const char *included = concat (3, include_directories[i], 453 455 "/", filename); 454 455 456 457 filename = strcache_add (included);458 459 460 456 ebuf.fp = fopen (included, "r"); 457 if (ebuf.fp) 458 { 459 filename = included; 460 break; 461 } 462 } 461 463 } 462 464 465 /* Now we have the final name for this makefile. Enter it into 466 the cache. */ 467 filename = strcache_add (filename); 468 463 469 /* Add FILENAME to the chain of read makefiles. */ 464 deps = alloc_ dep ();465 deps->next = read_ makefiles;466 read_ makefiles = deps;470 deps = alloc_goaldep (); 471 deps->next = read_files; 472 read_files = deps; 467 473 #ifndef CONFIG_WITH_STRCACHE2 468 474 deps->file = lookup_file (filename); … … 473 479 deps->file = enter_file (filename); 474 480 filename = deps->file->name; 475 deps->changed = flags; 476 if (flags & RM_DONTCARE) 477 deps->dontcare = 1; 478 479 if (expanded) 480 free (expanded); 481 deps->flags = flags; 482 483 free (expanded); 481 484 482 485 /* If the makefile can't be found at all, give up entirely. */ … … 485 488 { 486 489 /* If we did some searching, errno has the error from the last 487 attempt, rather from FILENAME itself. Restore it in case the488 490 attempt, rather from FILENAME itself. Store it in case the 491 caller wants to use it in a message. */ 489 492 errno = makefile_errno; 490 return 0;493 return deps; 491 494 } 492 495 … … 576 579 alloca (0); 577 580 578 return 1; 581 errno = 0; 582 return deps; 579 583 } 580 584 581 585 void 582 #ifndef CONFIG_WITH_VALUE_LENGTH 583 eval_buffer (char *buffer) 584 #else 585 eval_buffer (char *buffer, char *eos) 586 #endif 586 eval_buffer (char *buffer, const floc *flocp IF_WITH_VALUE_LENGTH_PARAM(char *eos)) 587 587 { 588 588 struct ebuffer ebuf; 589 589 struct conditionals *saved; 590 590 struct conditionals new; 591 const structfloc *curfile;591 const floc *curfile; 592 592 593 593 /* Evaluate the buffer */ … … 603 603 ebuf.fp = NULL; 604 604 605 if (reading_file) 605 if (flocp) 606 ebuf.floc = *flocp; 607 else if (reading_file) 606 608 ebuf.floc = *reading_file; 607 609 else 608 ebuf.floc.filenm = NULL; 610 { 611 ebuf.floc.filenm = NULL; 612 ebuf.floc.lineno = 1; 613 ebuf.floc.offset = 0; 614 } 609 615 610 616 curfile = reading_file; … … 641 647 642 648 /* Find the start of the next token. If there isn't one we're done. */ 643 line = next_token(line);649 NEXT_TOKEN (line); 644 650 if (*line == '\0') 645 651 return (char *)line; … … 650 656 int wlen; 651 657 const char *p2; 652 enum variable_flavor flavor;653 654 p2 = parse_variable_definition (p, & flavor);658 struct variable v; 659 660 p2 = parse_variable_definition (p, &v); 655 661 656 662 /* If this is a variable assignment, we're done. */ … … 713 719 unsigned int cmds_started, tgts_started; 714 720 int ignoring = 0, in_ignored_define = 0; 715 int no_targets = 0; 721 int no_targets = 0; /* Set when reading a rule without targets. */ 716 722 struct nameseq *filenames = 0; 717 723 char *depstr = 0; 718 724 long nlines = 0; 719 725 int two_colon = 0; 726 char prefix = cmd_prefix; 720 727 const char *pattern = 0; 721 728 const char *pattern_percent; 722 structfloc *fstart;723 structfloc fi;729 floc *fstart; 730 floc fi; 724 731 #ifdef CONFIG_WITH_VALUE_LENGTH 725 732 unsigned int tmp_len; … … 730 737 #endif 731 738 732 #define record_waiting_files() 733 do 734 { 735 if (filenames != 0) 739 #define record_waiting_files() \ 740 do \ 741 { \ 742 if (filenames != 0) \ 736 743 { \ 737 fi.lineno = tgts_started; \ 738 record_files (filenames, pattern, pattern_percent, depstr, \ 744 fi.lineno = tgts_started; \ 745 fi.offset = 0; \ 746 record_files (filenames, pattern, pattern_percent, depstr, \ 739 747 cmds_started, commands, commands_idx, two_colon, \ 740 &fi);\741 filenames = 0; 748 prefix, &fi); \ 749 filenames = 0; \ 742 750 } \ 743 commands_idx = 0; 751 commands_idx = 0; \ 744 752 no_targets = 0; \ 745 753 pattern = 0; \ … … 758 766 759 767 When you see a "continue" in the loop below, that means we are moving on 760 to the next line _without_ ending any rule that we happen to be working 761 with at the moment. If you see a "goto rule_complete", then the 762 statement we just parsed also finishes the previous rule. */ 768 to the next line. If you see record_waiting_files(), then the statement 769 we are parsing also finishes the previous rule. */ 763 770 764 771 commands = xmalloc (200); … … 785 792 break; 786 793 794 line = ebuf->buffer; 795 796 /* If this is the first line, check for a UTF-8 BOM and skip it. */ 797 if (ebuf->floc.lineno == 1 && line[0] == (char)0xEF 798 && line[1] == (char)0xBB && line[2] == (char)0xBF) 799 { 800 line += 3; 801 if (ISDB(DB_BASIC)) 802 { 803 if (ebuf->floc.filenm) 804 printf (_("Skipping UTF-8 BOM in makefile '%s'\n"), 805 ebuf->floc.filenm); 806 else 807 printf (_("Skipping UTF-8 BOM in makefile buffer\n")); 808 } 809 } 810 787 811 /* If this line is empty, skip it. */ 788 line = ebuf->buffer;789 812 if (line[0] == '\0') 790 813 continue; … … 798 821 799 822 /* Check for a shell command line first. 800 If it is not one, we can stop treating tabspecially. */823 If it is not one, we can stop treating cmd_prefix specially. */ 801 824 if (line[0] == cmd_prefix) 802 { 803 if (no_targets) 804 /* Ignore the commands in a rule with no targets. */ 805 continue; 806 807 /* If there is no preceding rule line, don't treat this line 808 as a command, even though it begins with a recipe prefix. 809 SunOS 4 make appears to behave this way. */ 810 811 if (filenames != 0) 812 { 813 if (ignoring) 814 /* Yep, this is a shell command, and we don't care. */ 815 continue; 816 817 /* Append this command line to the line being accumulated. 818 Strip command prefix chars that appear after newlines. */ 819 if (commands_idx == 0) 820 cmds_started = ebuf->floc.lineno; 821 822 if (linelen + commands_idx > commands_len) 823 { 824 commands_len = (linelen + commands_idx) * 2; 825 commands = xrealloc (commands, commands_len); 826 } 827 p = &commands[commands_idx]; 828 p2 = line + 1; 829 while (--linelen) 825 { 826 if (no_targets) 827 /* Ignore the commands in a rule with no targets. */ 828 continue; 829 830 /* If there is no preceding rule line, don't treat this line 831 as a command, even though it begins with a recipe prefix. 832 SunOS 4 make appears to behave this way. */ 833 834 if (filenames != 0) 835 { 836 if (ignoring) 837 /* Yep, this is a shell command, and we don't care. */ 838 continue; 839 840 if (commands_idx == 0) 841 cmds_started = ebuf->floc.lineno; 842 843 /* Append this command line to the line being accumulated. 844 Skip the initial command prefix character. */ 845 if (linelen + commands_idx > commands_len) 830 846 { 831 ++commands_idx; 832 *(p++) = *p2; 833 if (p2[0] == '\n' && p2[1] == cmd_prefix) 834 { 835 ++p2; 836 --linelen; 837 } 838 ++p2; 847 commands_len = (linelen + commands_idx) * 2; 848 commands = xrealloc (commands, commands_len); 839 849 } 840 *p = '\n';841 ++commands_idx;842 843 844 845 850 memcpy (&commands[commands_idx], line + 1, linelen - 1); 851 commands_idx += linelen - 1; 852 commands[commands_idx++] = '\n'; 853 continue; 854 } 855 } 846 856 847 857 /* This line is not a shell command line. Don't worry about whitespace. … … 850 860 851 861 if (collapsed_length < linelen+1) 852 { 853 collapsed_length = linelen+1; 854 if (collapsed) 855 free (collapsed); 862 { 863 collapsed_length = linelen+1; 864 free (collapsed); 856 865 /* Don't need xrealloc: we don't need to preserve the content. */ 857 858 866 collapsed = xmalloc (collapsed_length); 867 } 859 868 #ifndef CONFIG_WITH_VALUE_LENGTH 860 869 strcpy (collapsed, line); … … 873 882 /* Get rid if starting space (including formfeed, vtab, etc.) */ 874 883 p = collapsed; 875 while (isspace ((unsigned char)*p)) 876 ++p; 884 NEXT_TOKEN (p); 877 885 878 886 /* See if this is a variable assignment. We need to do this early, to 879 887 allow variables with names like 'ifdef', 'export', 'private', etc. */ 880 p = parse_var_assignment (p, &vmod);888 p = parse_var_assignment (p, &vmod); 881 889 if (vmod.assign_v) 882 890 { … … 885 893 886 894 /* If we're ignoring then we're done now. */ 887 895 if (ignoring) 888 896 { 889 897 if (vmod.define_v) … … 892 900 } 893 901 902 /* Variable assignment ends the previous rule. */ 903 record_waiting_files (); 904 894 905 if (vmod.undefine_v) 895 906 { 896 907 do_undefine (p, origin, ebuf); 897 898 /* This line has been dealt with. */ 899 goto rule_complete; 908 continue; 900 909 } 901 910 else if (vmod.define_v) … … 912 921 913 922 /* This line has been dealt with. */ 914 goto rule_complete;923 continue; 915 924 } 916 925 917 926 /* If this line is completely empty, ignore it. */ 918 927 if (*p == '\0') 919 928 continue; 920 929 921 930 p2 = end_of_token (p); 922 931 wlen = p2 - p; 923 p2 = next_token(p2);932 NEXT_TOKEN (p2); 924 933 925 934 /* If we're in an ignored define, skip this line (but maybe get out). */ 926 935 if (in_ignored_define) 927 936 { 928 937 /* See if this is an endef line (plus optional comment). */ 929 if (word1eq ("endef") && (*p2 == '\0' || *p2 == '#'))938 if (word1eq ("endef") && STOP_SET (*p2, MAP_COMMENT|MAP_NUL)) 930 939 in_ignored_define = 0; 931 940 932 933 941 continue; 942 } 934 943 935 944 /* Check for conditional state changes. */ … … 943 952 { 944 953 if (i == -1) 945 fatal (fstart, _("invalid syntax in conditional"));954 O (fatal, fstart, _("invalid syntax in conditional")); 946 955 947 956 ignoring = i; … … 952 961 /* Nothing to see here... move along. */ 953 962 if (ignoring) 954 963 continue; 955 964 956 965 #ifdef CONFIG_WITH_LOCAL_VARIABLES … … 958 967 { 959 968 if (*p2 == '\0') 960 error (fstart, _("empty `local' directive"));969 O (error, fstart, _("empty `local' directive")); 961 970 962 971 if (strneq (p2, "define", 6) 963 && ( isblank ((unsigned char)p2[6]) || p2[6] == '\0'))972 && (ISBLANK (p2[6]) || p2[6] == '\0')) 964 973 { 965 974 if (ignoring) … … 969 978 p2 = next_token (p2 + 6); 970 979 if (*p2 == '\0') 971 fatal (fstart, _("empty variable name"));980 O (fatal, fstart, _("empty variable name")); 972 981 973 982 /* Let the variable name be the whole rest of the line, … … 976 985 reference that might contain blanks. */ 977 986 p = strchr (p2, '\0'); 978 while ( isblank ((unsigned char)p[-1]))987 while (ISBLANK (p[-1])) 979 988 --p; 980 989 do_define (p2 IF_WITH_VALUE_LENGTH_PARAM(p), o_local, ebuf); … … 983 992 else if (!ignoring 984 993 && !try_variable_definition (fstart, p2 IF_WITH_VALUE_LENGTH_PARAM(eol), o_local, 0)) 985 error (fstart, _("invalid `local' directive"));994 O (error, fstart, _("invalid `local' directive")); 986 995 987 996 continue; … … 998 1007 { 999 1008 if (krc != 0) 1000 error (fstart, _("krc=%d"), krc);1009 ON (error, fstart, _("krc=%d"), krc); 1001 1010 continue; 1002 1011 } … … 1007 1016 as well as "unexport". */ 1008 1017 if (word1eq ("export") || word1eq ("unexport")) 1009 1018 { 1010 1019 int exporting = *p == 'u' ? 0 : 1; 1011 1020 1021 /* Export/unexport ends the previous rule. */ 1022 record_waiting_files (); 1023 1012 1024 /* (un)export by itself causes everything to be (un)exported. */ 1013 1025 if (*p2 == '\0') 1014 1026 export_all_variables = exporting; 1015 1027 else … … 1033 1045 struct variable *v = lookup_variable (p, l); 1034 1046 if (v == 0) 1035 v = define_variable_ loc(p, l, "", o_file, 0, fstart);1047 v = define_variable_global (p, l, "", o_file, 0, fstart); 1036 1048 v->export = exporting ? v_export : v_noexport; 1037 1049 } … … 1043 1055 #endif 1044 1056 } 1045 goto rule_complete;1046 1057 continue; 1058 } 1047 1059 1048 1060 /* Handle the special syntax for vpath. */ 1049 1061 if (word1eq ("vpath")) 1050 1062 { 1051 1063 const char *cp; 1052 char *vpat; 1053 unsigned int l; 1054 cp = variable_expand (p2); 1055 p = find_next_token (&cp, &l); 1056 if (p != 0) 1057 { 1058 vpat = xstrndup (p, l); 1059 p = find_next_token (&cp, &l); 1060 /* No searchpath means remove all previous 1061 selective VPATH's with the same pattern. */ 1062 } 1063 else 1064 /* No pattern means remove all previous selective VPATH's. */ 1065 vpat = 0; 1066 construct_vpath_list (vpat, p); 1067 if (vpat != 0) 1068 free (vpat); 1069 1070 goto rule_complete; 1071 } 1064 char *vpat; 1065 unsigned int l; 1066 1067 /* vpath ends the previous rule. */ 1068 record_waiting_files (); 1069 1070 cp = variable_expand (p2); 1071 p = find_next_token (&cp, &l); 1072 if (p != 0) 1073 { 1074 vpat = xstrndup (p, l); 1075 p = find_next_token (&cp, &l); 1076 /* No searchpath means remove all previous 1077 selective VPATH's with the same pattern. */ 1078 } 1079 else 1080 /* No pattern means remove all previous selective VPATH's. */ 1081 vpat = 0; 1082 construct_vpath_list (vpat, p); 1083 free (vpat); 1084 1085 continue; 1086 } 1072 1087 1073 1088 #ifdef CONFIG_WITH_INCLUDEDEP … … 1092 1107 free_me = name = allocated_variable_expand_3 (name, eol - name, &name_len, &buf_len); 1093 1108 eol = name + name_len; 1094 while ( isspace ((unsigned char)*name))1109 while (ISSPACE (*name)) 1095 1110 ++name; 1096 1111 } 1097 1112 1098 while (eol > name && isspace ((unsigned char)eol[-1]))1113 while (eol > name && ISSPACE (eol[-1])) 1099 1114 --eol; 1100 1115 … … 1104 1119 if (free_me) 1105 1120 recycle_variable_buffer (free_me, buf_len); 1106 goto rule_complete;1121 continue; 1107 1122 } 1108 1123 #endif /* CONFIG_WITH_INCLUDEDEP */ … … 1110 1125 /* Handle include and variants. */ 1111 1126 if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude")) 1112 1113 /* We have found an `include' line specifying a nested1114 1115 1127 { 1128 /* We have found an 'include' line specifying a nested 1129 makefile to be read at this point. */ 1130 struct conditionals *save; 1116 1131 struct conditionals new_conditionals; 1117 struct nameseq *files; 1118 /* "-include" (vs "include") says no error if the file does not 1119 exist. "sinclude" is an alias for this from SGI. */ 1120 int noerror = (p[0] != 'i'); 1132 struct nameseq *files; 1133 /* "-include" (vs "include") says no error if the file does not 1134 exist. "sinclude" is an alias for this from SGI. */ 1135 int noerror = (p[0] != 'i'); 1136 #ifdef CONFIG_WITH_VALUE_LENGTH 1137 unsigned int buf_len; 1138 #endif 1139 1140 /* Include ends the previous rule. */ 1141 record_waiting_files (); 1121 1142 1122 1143 #ifndef CONFIG_WITH_VALUE_LENGTH 1123 p = allocated_variable_expand (p2); 1124 #else 1125 unsigned int buf_len; 1144 p = allocated_variable_expand (p2); 1145 #else 1126 1146 p = allocated_variable_expand_3 (p2, eol - p2, NULL, &buf_len); 1127 1147 #endif 1128 1148 1149 1129 1150 /* If no filenames, it's a no-op. */ 1130 1151 if (*p == '\0') 1131 1152 { 1132 1153 #ifndef CONFIG_WITH_VALUE_LENGTH … … 1138 1159 } 1139 1160 1140 1141 1142 files = PARSE_FILE_SEQ (&p2, struct nameseq, '\0', NULL,1161 /* Parse the list of file names. Don't expand archive references! */ 1162 p2 = p; 1163 files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL, 1143 1164 PARSEFS_NOAR); 1144 1165 #ifndef CONFIG_WITH_VALUE_LENGTH 1145 1166 free (p); 1146 1167 #else 1147 1168 recycle_variable_buffer (p, buf_len); 1148 1169 #endif 1149 1170 1150 /* Save the state of conditionals and start 1151 the included makefile with a clean slate. */ 1152 save = install_conditionals (&new_conditionals); 1153 1154 /* Record the rules that are waiting so they will determine 1155 the default goal before those in the included makefile. */ 1156 record_waiting_files (); 1157 1158 /* Read each included makefile. */ 1159 while (files != 0) 1160 { 1161 struct nameseq *next = files->next; 1162 const char *name = files->name; 1171 /* Save the state of conditionals and start 1172 the included makefile with a clean slate. */ 1173 save = install_conditionals (&new_conditionals); 1174 1175 /* Record the rules that are waiting so they will determine 1176 the default goal before those in the included makefile. */ 1177 record_waiting_files (); 1178 1179 /* Read each included makefile. */ 1180 while (files != 0) 1181 { 1182 struct nameseq *next = files->next; 1183 int flags = (RM_INCLUDED | RM_NO_TILDE 1184 | (noerror ? RM_DONTCARE : 0) 1185 | (set_default ? 0 : RM_NO_DEFAULT_GOAL)); 1186 1187 struct goaldep *d = eval_makefile (files->name, flags); 1188 1189 if (errno) 1190 { 1191 d->error = (unsigned short)errno; 1192 d->floc = *fstart; 1193 } 1194 1195 free_ns (files); 1196 files = next; 1197 } 1198 1199 /* Restore conditional state. */ 1200 restore_conditionals (save); 1201 1202 continue; 1203 } 1204 1205 /* Handle the load operations. */ 1206 if (word1eq ("load") || word1eq ("-load")) 1207 { 1208 /* A 'load' line specifies a dynamic object to load. */ 1209 struct nameseq *files; 1210 int noerror = (p[0] == '-'); 1211 1212 /* Load ends the previous rule. */ 1213 record_waiting_files (); 1214 1215 p = allocated_variable_expand (p2); 1216 1217 /* If no filenames, it's a no-op. */ 1218 if (*p == '\0') 1219 { 1220 free (p); 1221 continue; 1222 } 1223 1224 /* Parse the list of file names. 1225 Don't expand archive references or strip "./" */ 1226 p2 = p; 1227 files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL, 1228 PARSEFS_NOAR); 1229 free (p); 1230 1231 /* Load each file. */ 1232 while (files != 0) 1233 { 1234 struct nameseq *next = files->next; 1235 const char *name = files->name; 1236 struct goaldep *deps; 1163 1237 int r; 1164 1238 1165 free_ns (files); 1166 files = next; 1167 1168 r = eval_makefile (name, 1169 (RM_INCLUDED | RM_NO_TILDE 1170 | (noerror ? RM_DONTCARE : 0) 1171 | (set_default ? 0 : RM_NO_DEFAULT_GOAL))); 1172 if (!r && !noerror) 1173 error (fstart, "%s: %s", name, strerror (errno)); 1174 } 1175 1176 /* Restore conditional state. */ 1177 restore_conditionals (save); 1178 1179 goto rule_complete; 1180 } 1239 /* Load the file. 0 means failure. */ 1240 r = load_file (&ebuf->floc, &name, noerror); 1241 if (! r && ! noerror) 1242 OS (fatal, &ebuf->floc, _("%s: failed to load"), name); 1243 1244 free_ns (files); 1245 files = next; 1246 1247 /* Return of -1 means a special load: don't rebuild it. */ 1248 if (r == -1) 1249 continue; 1250 1251 /* It succeeded, so add it to the list "to be rebuilt". */ 1252 deps = alloc_goaldep (); 1253 deps->next = read_files; 1254 read_files = deps; 1255 deps->file = lookup_file (name); 1256 if (deps->file == 0) 1257 deps->file = enter_file (name); 1258 deps->file->loaded = 1; 1259 } 1260 1261 continue; 1262 } 1181 1263 1182 1264 /* This line starts with a tab but was not caught above because there … … 1184 1266 variable definition. But now we know it is definitely lossage. */ 1185 1267 if (line[0] == cmd_prefix) 1186 fatal(fstart, _("recipe commences before first target"));1268 O (fatal, fstart, _("recipe commences before first target")); 1187 1269 1188 1270 /* This line describes some target files. This is complicated by 1189 1271 the existence of target-specific variables, because we can't 1190 1272 expand the entire line until we know if we have one or not. So 1191 we expand the line word by word until we find the first `:',1273 we expand the line word by word until we find the first ':', 1192 1274 then check to see if it's a target-specific variable. 1193 1275 1194 In this algorithm, `lb_next' will point to the beginning of the1195 unexpanded parts of the input buffer, while `p2' points to the1276 In this algorithm, 'lb_next' will point to the beginning of the 1277 unexpanded parts of the input buffer, while 'p2' points to the 1196 1278 parts of the expanded buffer we haven't searched yet. */ 1197 1279 … … 1210 1292 /* Search the line for an unquoted ; that is not after an 1211 1293 unquoted #. */ 1212 #ifndef CONFIG_WITH_VALUE_LENGTH 1213 cmdleft = find_char_unquote (line, ';', '#', 0, 1); 1214 #else 1215 cmdleft = find_char_unquote_2 (line, ';', '#', 0, 1, ebuf->eol - line); 1216 #endif 1294 cmdleft = find_char_unquote (line, MAP_SEMI|MAP_COMMENT|MAP_VARIABLE IF_WITH_VALUE_LENGTH_PARAM(ebuf->eol - line)); 1217 1295 if (cmdleft != 0 && *cmdleft == '#') 1218 1296 { … … 1236 1314 beginning, expanding as we go, and looking for "interesting" 1237 1315 chars. The first word is always expandable. */ 1238 wtype = get_next_mword (line, NULL, &lb_next, &wlen);1316 wtype = get_next_mword (line, NULL, &lb_next, &wlen); 1239 1317 switch (wtype) 1240 1318 { 1241 1319 case w_eol: 1242 1320 if (cmdleft != 0) 1243 fatal(fstart, _("missing rule before recipe"));1321 O (fatal, fstart, _("missing rule before recipe")); 1244 1322 /* This line contained something but turned out to be nothing 1245 1323 but whitespace (a comment?). */ … … 1257 1335 } 1258 1336 1259 1260 1337 #ifndef CONFIG_WITH_VALUE_LENGTH 1261 p2 = variable_expand_string (NULL, lb_next, wlen);1338 p2 = variable_expand_string (NULL, lb_next, wlen); 1262 1339 #else 1263 1340 p2 = variable_expand_string_2 (NULL, lb_next, wlen, &eol); … … 1272 1349 /* Look for a semicolon in the expanded line. */ 1273 1350 #ifndef CONFIG_WITH_VALUE_LENGTH 1274 cmdleft = find_char_unquote (p2, ';', 0, 0, 0);1275 #else 1276 cmdleft = find_char_unquote_0 (p2, ';', &eol);1351 cmdleft = find_char_unquote (p2, MAP_SEMI); 1352 #else 1353 cmdleft = find_char_unquote_0 (p2, ';', MAP_SEMI, &eol); 1277 1354 #endif 1278 1355 … … 1282 1359 unsigned long cmd_off = cmdleft - variable_buffer; 1283 1360 #ifndef CONFIG_WITH_VALUE_LENGTH 1284 char *pend = p2 + strlen (p2);1361 char *pend = p2 + strlen (p2); 1285 1362 #endif 1286 1363 … … 1293 1370 and into a command script. However, the old parser 1294 1371 expanded the whole line, so we continue that for 1295 backwards-compatib lity. Also, it wouldn't be1372 backwards-compatibility. Also, it wouldn't be 1296 1373 entirely consistent, since we do an unconditional 1297 1374 expand below once we know we don't have a 1298 1375 target-specific variable. */ 1299 1376 #ifndef CONFIG_WITH_VALUE_LENGTH 1300 (void)variable_expand_string (pend, lb_next, (long)-1);1301 lb_next += strlen (lb_next);1377 (void)variable_expand_string (pend, lb_next, (long)-1); 1378 lb_next += strlen (lb_next); 1302 1379 #else 1303 1380 tmp_len = strlen (lb_next); … … 1311 1388 1312 1389 #ifndef CONFIG_WITH_VALUE_LENGTH 1313 colonp = find_char_unquote (p2, ':', 0, 0, 0);1314 #else 1315 colonp = find_char_unquote_0 (p2, ':', &eol);1390 colonp = find_char_unquote (p2, MAP_COLON); 1391 #else 1392 colonp = find_char_unquote_0 (p2, ':', MAP_COLON, &eol); 1316 1393 #endif 1317 1394 #ifdef HAVE_DOS_PATHS … … 1324 1401 (colonp == p2 + 1 || strchr (" \t(", colonp[-2]) != 0)) 1325 1402 # ifndef CONFIG_WITH_VALUE_LENGTH 1326 colonp = find_char_unquote (colonp + 1, ':', 0, 0, 0);1403 colonp = find_char_unquote (colonp + 1, MAP_COLON); 1327 1404 # else 1328 colonp = find_char_unquote_0 (colonp + 1, ':', &eol);1405 colonp = find_char_unquote_0 (colonp + 1, ':', MAP_COLON, &eol); 1329 1406 # endif 1330 1407 #endif … … 1332 1409 break; 1333 1410 1334 wtype = get_next_mword (lb_next, NULL, &lb_next, &wlen);1411 wtype = get_next_mword (lb_next, NULL, &lb_next, &wlen); 1335 1412 if (wtype == w_eol) 1336 1413 break; 1337 1414 1338 1415 #ifndef CONFIG_WITH_VALUE_LENGTH 1339 p2 += strlen (p2);1416 p2 += strlen (p2); 1340 1417 *(p2++) = ' '; 1341 p2 = variable_expand_string (p2, lb_next, wlen);1418 p2 = variable_expand_string (p2, lb_next, wlen); 1342 1419 #else 1343 1420 *(eol++) = ' '; … … 1356 1433 if (wtype == w_eol) 1357 1434 { 1358 if (*p2 != '\0') 1359 /* There's no need to be ivory-tower about this: check for 1360 one of the most common bugs found in makefiles... */ 1361 fatal (fstart, _("missing separator%s"), 1362 (cmd_prefix == '\t' && !strneq(line, " ", 8)) 1363 ? "" : _(" (did you mean TAB instead of 8 spaces?)")); 1364 continue; 1435 if (*p2 == '\0') 1436 continue; 1437 1438 /* There's no need to be ivory-tower about this: check for 1439 one of the most common bugs found in makefiles... */ 1440 if (cmd_prefix == '\t' && strneq (line, " ", 8)) 1441 O (fatal, fstart, _("missing separator (did you mean TAB instead of 8 spaces?)")); 1442 else 1443 O (fatal, fstart, _("missing separator")); 1365 1444 } 1366 1445 1367 1446 /* Make the colon the end-of-string so we know where to stop 1368 looking for targets. */1447 looking for targets. Start there again once we're done. */ 1369 1448 *colonp = '\0'; 1370 filenames = PARSE_FILE_SEQ (&p2, struct nameseq, '\0', NULL, 0); 1371 *p2 = ':'; 1449 filenames = PARSE_SIMPLE_SEQ (&p2, struct nameseq); 1450 *colonp = ':'; 1451 p2 = colonp; 1372 1452 1373 1453 if (!filenames) … … 1406 1486 if (semip) 1407 1487 { 1408 unsigned int l = p - variable_buffer;1488 unsigned int l = p2 - variable_buffer; 1409 1489 *(--semip) = ';'; 1410 1490 #ifndef CONFIG_WITH_VALUE_LENGTH … … 1415 1495 variable_buffer_output (p2 + strlen (p2), 1416 1496 semip, strlen (semip)+1); 1417 p = variable_buffer + l;1497 p2 = variable_buffer + l; 1418 1498 } 1419 1499 record_target_var (filenames, p2, … … 1426 1506 /* This is a normal target, _not_ a target-specific variable. 1427 1507 Unquote any = in the dependency list. */ 1428 find_char_unquote (lb_next, '=', 0, 0, 0); 1508 #ifndef CONFIG_WITH_VALUE_LENGTH 1509 find_char_unquote (lb_next, MAP_EQUALS); 1510 #else 1511 { 1512 char *tmp_eos = strchr(lb_next, '\0'); /** @todo see if we can optimize this away... */ 1513 find_char_unquote_0 (lb_next, '=', MAP_EQUALS, &tmp_eos); 1514 } 1515 #endif 1516 1517 /* Remember the command prefix for this target. */ 1518 prefix = cmd_prefix; 1429 1519 1430 1520 /* We have some targets, so don't ignore the following commands. */ … … 1447 1537 { 1448 1538 #ifndef CONFIG_WITH_VALUE_LENGTH 1449 cmdleft = find_char_unquote (p2, ';', 0, 0, 0);1450 #else 1451 cmdleft = find_char_unquote_0 (p2, ';', &eos);1539 cmdleft = find_char_unquote (p2, MAP_SEMI); 1540 #else 1541 cmdleft = find_char_unquote_0 (p2, ';', MAP_SEMI, &eos); 1452 1542 #endif 1453 1543 if (cmdleft != 0) … … 1456 1546 } 1457 1547 1458 /* Is this a static pattern rule: `target: %targ: %dep; ...'? */1548 /* Is this a static pattern rule: 'target: %targ: %dep; ...'? */ 1459 1549 p = strchr (p2, ':'); 1460 1550 while (p != 0 && p[-1] == '\\') … … 1482 1572 OR a space around the :. 1483 1573 */ 1484 if (p && !(isspace ((unsigned char)p[1]) || !p[1] 1485 || isspace ((unsigned char)p[-1]))) 1574 if (p && !(ISSPACE (p[1]) || !p[1] || ISSPACE (p[-1]))) 1486 1575 p = 0; 1487 1576 #endif … … 1504 1593 { 1505 1594 struct nameseq *target; 1506 target = PARSE_FILE_SEQ (&p2, struct nameseq, ':', NULL,1595 target = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_COLON, NULL, 1507 1596 PARSEFS_NOGLOB); 1508 1597 ++p2; 1509 1598 if (target == 0) 1510 fatal (fstart, _("missing target pattern"));1599 O (fatal, fstart, _("missing target pattern")); 1511 1600 else if (target->next != 0) 1512 fatal (fstart, _("multiple target patterns (target `%s')"), target->name); /* bird*/1601 OS (fatal, fstart, _("multiple target patterns (target '%s')"), target->name); /* bird added target */ 1513 1602 pattern_percent = find_percent_cached (&target->name); 1514 1603 pattern = target->name; 1515 1604 if (pattern_percent == 0) 1516 fatal (fstart, _("target pattern contains no `%%' (target `%s')"), target->name); /* bird*/1605 OS (fatal, fstart, _("target pattern contains no '%%' (target '%s')"), target->name); /* bird added target */ 1517 1606 free_ns (target); 1518 1607 } … … 1567 1656 if (set_default && default_goal_var->value[0] == '\0') 1568 1657 { 1569 const char *name;1570 1658 struct dep *d; 1571 1659 struct nameseq *t = filenames; … … 1574 1662 { 1575 1663 int reject = 0; 1576 name = t->name;1664 const char *name = t->name; 1577 1665 1578 1666 /* We have nothing to do if this is an implicit rule. */ … … 1580 1668 break; 1581 1669 1582 /* See if this target's name does not start with a `.',1670 /* See if this target's name does not start with a '.', 1583 1671 unless it contains a slash. */ 1584 1672 if (*name == '.' && strchr (name, '/') == 0 … … 1633 1721 1634 1722 /* We get here except in the case that we just read a rule line. 1635 Record now the last rule we read, so following spurious 1636 commands are properly diagnosed. */ 1637 rule_complete: 1723 Record now the last rule we read, so following spurious 1724 commands are properly diagnosed. */ 1638 1725 record_waiting_files (); 1639 1726 } 1640 1727 1641 #undef 1728 #undef word1eq 1642 1729 1643 1730 if (conditionals->if_cmds) 1644 fatal (fstart, _("missing `endif'"));1731 O (fatal, fstart, _("missing 'endif'")); 1645 1732 #ifdef KMK 1646 1733 1647 1734 if (kdata != NULL) 1648 fatal (fstart, _("missing `kBuild-endef-*'"));1735 O (fatal, fstart, _("missing `kBuild-endef-*'")); 1649 1736 #endif 1650 1737 … … 1652 1739 record_waiting_files (); 1653 1740 1654 if (collapsed) 1655 free (collapsed); 1741 free (collapsed); 1656 1742 free (commands); 1657 1743 } … … 1665 1751 static void 1666 1752 remove_comments (char *line) 1753 #else 1754 static char * 1755 remove_comments (char *line, char *eos) 1756 #endif 1667 1757 { 1668 1758 char *comment; 1669 1759 1670 comment = find_char_unquote (line, '#', 0, 0, 0); 1760 #ifndef CONFIG_WITH_VALUE_LENGTH 1761 comment = find_char_unquote (line, MAP_COMMENT); 1671 1762 1672 1763 if (comment != 0) 1673 1764 /* Cut off the line at the #. */ 1674 1765 *comment = '\0'; 1766 #else 1767 comment = find_char_unquote_0 (line, '#', MAP_COMMENT, &eos); 1768 if (comment) 1769 { 1770 /* Cut off the line at the #. */ 1771 *comment = '\0'; 1772 return comment; 1773 } 1774 return eos; 1775 #endif 1675 1776 } 1676 #else /* CONFIG_WITH_VALUE_LENGTH */ 1677 __inline static char * 1678 remove_comments (char *line, char *eol) 1679 { 1680 unsigned int string_len = eol - line; 1681 register int ch; 1682 char *p; 1683 1684 /* Hope for simple (no comments). */ 1685 p = memchr (line, '#', string_len); 1686 if (!p) 1687 return eol; 1688 1689 /* Found potential comment, enter the slow route. */ 1690 for (;;) 1691 { 1692 if (p > line && p[-1] == '\\') 1693 { 1694 /* Search for more backslashes. */ 1695 int i = -2; 1696 while (&p[i] >= line && p[i] == '\\') 1697 --i; 1698 ++i; 1699 1700 /* The number of backslashes is now -I. 1701 Copy P over itself to swallow half of them. */ 1702 memmove (&p[i], &p[i/2], (string_len - (p - line)) - (i/2) + 1); 1703 p += i/2; 1704 if (i % 2 == 0) 1705 { 1706 /* All the backslashes quoted each other; the STOPCHAR was 1707 unquoted. */ 1708 *p = '\0'; 1709 return p; 1710 } 1711 1712 /* The '#' was quoted by a backslash. Look for another. */ 1713 } 1714 else 1715 { 1716 /* No backslash in sight. */ 1717 *p = '\0'; 1718 return p; 1719 } 1720 1721 /* lazy, string_len isn't correct so do it the slow way. */ 1722 while ((ch = *p) != '#') 1723 { 1724 if (ch == '\0') 1725 return p; 1726 ++p; 1727 } 1728 } 1729 /* won't ever get here. */ 1730 } 1731 #endif /* CONFIG_WITH_VALUE_LENGTH */ 1732 1733 /* Execute a `undefine' directive. 1777 1778 /* Execute a 'undefine' directive. 1734 1779 The undefine line has already been read, and NAME is the name of 1735 1780 the variable to be undefined. */ … … 1744 1789 name = next_token (var); 1745 1790 if (*name == '\0') 1746 fatal (&ebuf->floc, _("empty variable name"));1791 O (fatal, &ebuf->floc, _("empty variable name")); 1747 1792 p = name + strlen (name) - 1; 1748 while (p > name && isblank ((unsigned char)*p))1793 while (p > name && ISBLANK (*p)) 1749 1794 --p; 1750 1795 p[1] = '\0'; … … 1754 1799 } 1755 1800 1756 /* Execute a `define' directive.1801 /* Execute a 'define' directive. 1757 1802 The first line has already been read, and NAME is the name of 1758 1803 the variable to be defined. The following lines remain to be read. */ … … 1763 1808 { 1764 1809 struct variable *v; 1765 enum variable_flavor flavor;1766 structfloc defstart;1810 struct variable var; 1811 floc defstart; 1767 1812 int nlevels = 1; 1768 1813 unsigned int length = 100; 1769 1814 char *definition = xmalloc (length); 1770 1815 unsigned int idx = 0; 1771 char *p, * var;1816 char *p, *n; 1772 1817 1773 1818 defstart = ebuf->floc; 1774 1819 1775 p = parse_variable_definition (name, & flavor);1820 p = parse_variable_definition (name, &var); 1776 1821 if (p == NULL) 1777 1822 /* No assignment token, so assume recursive. */ 1778 flavor = f_recursive;1823 var.flavor = f_recursive; 1779 1824 else 1780 1825 { 1781 if ( *(next_token (p))!= '\0')1782 error (&defstart, _("extraneous text after `define' directive"));1826 if (var.value[0] != '\0') 1827 O (error, &defstart, _("extraneous text after 'define' directive")); 1783 1828 1784 1829 /* Chop the string before the assignment token to get the name. */ 1785 p[flavor == f_recursive ? -1 : -2] = '\0'; 1830 #ifndef CONFIG_WITH_STRCACHE2 1831 var.name[var.length] = '\0'; 1832 #else 1833 assert (!strcache2_is_cached (&variable_strcache, var.name)); 1834 ((char *)var.name)[var.length] = '\0'; 1835 #endif 1786 1836 } 1787 1837 1788 1838 /* Expand the variable name and find the beginning (NAME) and end. */ 1789 var= allocated_variable_expand (name);1790 name = next_token ( var);1791 if ( *name== '\0')1792 fatal (&defstart, _("empty variable name"));1839 n = allocated_variable_expand (name); 1840 name = next_token (n); 1841 if (name[0] == '\0') 1842 O (fatal, &defstart, _("empty variable name")); 1793 1843 p = name + strlen (name) - 1; 1794 while (p > name && isblank ((unsigned char)*p))1844 while (p > name && ISBLANK (*p)) 1795 1845 --p; 1796 1846 p[1] = '\0'; … … 1805 1855 /* If there is nothing left to be eval'd, there's no 'endef'!! */ 1806 1856 if (nlines < 0) 1807 fatal (&defstart, _("missing `endef', unterminated `define'"));1857 O (fatal, &defstart, _("missing 'endef', unterminated 'define'")); 1808 1858 1809 1859 ebuf->floc.lineno += nlines; … … 1829 1879 1830 1880 /* If this is another 'define', increment the level count. */ 1831 if ((len == 6 || (len > 6 && isblank ((unsigned char)p[6])))1881 if ((len == 6 || (len > 6 && ISBLANK (p[6]))) 1832 1882 && strneq (p, "define", 6)) 1833 1883 ++nlevels; … … 1835 1885 /* If this is an 'endef', decrement the count. If it's now 0, 1836 1886 we've found the last one. */ 1837 else if ((len == 5 || (len > 5 && isblank ((unsigned char)p[5])))1887 else if ((len == 5 || (len > 5 && ISBLANK (p[5]))) 1838 1888 && strneq (p, "endef", 5)) 1839 1889 { … … 1845 1895 #endif 1846 1896 if (*(next_token (p)) != '\0') 1847 error (&ebuf->floc,1848 _("extraneous text after `endef' directive"));1897 O (error, &ebuf->floc, 1898 _("extraneous text after 'endef' directive")); 1849 1899 1850 1900 if (--nlevels == 0) … … 1879 1929 1880 1930 #ifndef CONFIG_WITH_VALUE_LENGTH 1881 v = do_variable_definition (&defstart, name, definition, origin, flavor, 0); 1931 v = do_variable_definition (&defstart, name, 1932 definition, origin, var.flavor, 0); 1882 1933 #else 1883 1934 v = do_variable_definition_2 (&defstart, name, definition, 1884 idx ? idx - 1 : idx, flavor == f_simple,1885 0 /* free_value */, origin, flavor,1935 idx ? idx - 1 : idx, var.flavor == f_simple, 1936 0 /* free_value */, origin, var.flavor, 1886 1937 0 /*target_var*/); 1887 1938 #endif 1888 1939 free (definition); 1889 free ( var);1940 free (n); 1890 1941 return (v); 1891 1942 } … … 1905 1956 1906 1957 static int 1907 #ifndef CONFIG_WITH_VALUE_LENGTH 1908 conditional_line (char *line, int len, const struct floc *flocp) 1909 #else 1910 conditional_line (char *line, char *eol, int len, const struct floc *flocp) 1911 #endif 1958 conditional_line (char *line IF_WITH_VALUE_LENGTH_PARAM(char *eol), int len, const floc *flocp) 1912 1959 { 1913 c har *cmdname;1960 const char *cmdname; 1914 1961 enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq, 1915 1962 #ifdef CONFIG_WITH_SET_CONDITIONALS … … 1928 1975 1929 1976 /* Compare a word, both length and contents. */ 1930 #define word1eq(s) (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1))1931 #define 1977 #define word1eq(s) (len == CSTRLEN (s) && strneq (s, line, CSTRLEN (s))) 1978 #define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); } 1932 1979 1933 1980 /* Make sure this line is a conditional. */ … … 1949 1996 1950 1997 /* Found one: skip past it and any whitespace after it. */ 1951 line = next_token (line + len); 1952 1953 #define EXTRANEOUS() error (flocp, _("Extraneous text after `%s' directive"), cmdname) 1998 line += len; 1999 NEXT_TOKEN (line); 2000 2001 #define EXTRATEXT() OS (error, flocp, _("extraneous text after '%s' directive"), cmdname) 2002 #define EXTRACMD() OS (fatal, flocp, _("extraneous '%s'"), cmdname) 1954 2003 1955 2004 /* An 'endif' cannot contain extra text, and reduces the if-depth by 1 */ … … 1957 2006 { 1958 2007 if (*line != '\0') 1959 EXTRANEOUS();2008 EXTRATEXT (); 1960 2009 1961 2010 if (!conditionals->if_cmds) 1962 fatal (flocp, _("extraneous `%s'"), cmdname);2011 EXTRACMD (); 1963 2012 1964 2013 --conditionals->if_cmds; … … 1974 2023 1975 2024 if (!conditionals->if_cmds) 1976 fatal (flocp, _("extraneous `%s'"), cmdname);2025 EXTRACMD (); 1977 2026 1978 2027 o = conditionals->if_cmds - 1; 1979 2028 1980 2029 if (conditionals->seen_else[o]) 1981 fatal (flocp, _("only one `else' per conditional"));2030 O (fatal, flocp, _("only one 'else' per conditional")); 1982 2031 1983 2032 /* Change the state of ignorance. */ … … 2005 2054 2006 2055 /* Find the length of the next word. */ 2007 for (p = line+1; *p != '\0' && !isspace ((unsigned char)*p); ++p)2056 for (p = line+1; ! STOP_SET (*p, MAP_SPACE|MAP_NUL); ++p) 2008 2057 ; 2009 2058 len = p - line; 2010 2059 2011 2060 /* If it's 'else' or 'endif' or an illegal conditional, fail. */ 2012 if (word1eq("else") || word1eq("endif") 2013 #ifndef CONFIG_WITH_VALUE_LENGTH 2014 || conditional_line (line, len, flocp) < 0) 2015 #else 2016 || conditional_line (line, eol, len, flocp) < 0) 2017 #endif 2018 EXTRANEOUS (); 2061 if (word1eq ("else") || word1eq ("endif") 2062 || conditional_line (line IF_WITH_VALUE_LENGTH_PARAM(eol), len, flocp) < 0) 2063 EXTRATEXT (); 2019 2064 else 2020 2065 { … … 2068 2113 } 2069 2114 2070 /* Record that we have seen an `if...' but no `else' so far. */2115 /* Record that we have seen an 'if...' but no 'else' so far. */ 2071 2116 conditionals->seen_else[o] = 0; 2072 2117 … … 2075 2120 if (conditionals->ignoring[i]) 2076 2121 { 2077 2078 2079 2080 2081 2122 /* We are already ignoring, so just push a level to match the next 2123 "else" or "endif", and keep ignoring. We don't want to expand 2124 variables in the condition. */ 2125 conditionals->ignoring[o] = 1; 2126 return 1; 2082 2127 } 2083 2128 … … 2099 2144 p = end_of_token (var); 2100 2145 i = p - var; 2101 p = next_token(p);2146 NEXT_TOKEN (p); 2102 2147 if (*p != '\0') 2103 2148 return -1; 2104 2149 2105 2150 var[i] = '\0'; … … 2137 2182 2138 2183 if (termin != ',' && termin != '"' && termin != '\'') 2139 2184 return -1; 2140 2185 2141 2186 s1 = ++line; 2142 2187 /* Find the end of the first string. */ 2143 2188 if (termin == ',') 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2189 { 2190 int count = 0; 2191 for (; *line != '\0'; ++line) 2192 if (*line == '(') 2193 ++count; 2194 else if (*line == ')') 2195 --count; 2196 else if (*line == ',' && count <= 0) 2197 break; 2198 } 2154 2199 else 2155 2156 2200 while (*line != '\0' && *line != termin) 2201 ++line; 2157 2202 2158 2203 if (*line == '\0') 2159 2204 return -1; 2160 2205 2161 2206 if (termin == ',') 2162 2163 2164 2165 while (isblank ((unsigned char)p[-1]))2166 2167 2207 { 2208 /* Strip blanks after the first string. */ 2209 char *p = line++; 2210 while (ISBLANK (p[-1])) 2211 --p; 2212 *p = '\0'; 2168 2213 #ifdef CONFIG_WITH_VALUE_LENGTH 2169 2214 l = p - s1; 2170 2215 #endif 2171 2216 } 2172 2217 else 2173 2218 { … … 2175 2220 l = line - s1; 2176 2221 #endif 2177 2222 *line++ = '\0'; 2178 2223 } 2179 2224 … … 2181 2226 s2 = variable_expand (s1); 2182 2227 /* We must allocate a new copy of the expanded string because 2183 2228 variable_expand re-uses the same buffer. */ 2184 2229 l = strlen (s2); 2185 2230 s1 = alloca (l + 1); … … 2190 2235 2191 2236 if (termin != ',') 2192 2193 line = next_token(line);2237 /* Find the start of the second string. */ 2238 NEXT_TOKEN (line); 2194 2239 2195 2240 termin = termin == ',' ? ')' : *line; 2196 2241 if (termin != ')' && termin != '"' && termin != '\'') 2197 2242 return -1; 2198 2243 2199 2244 /* Find the end of the second string. */ 2200 2245 if (termin == ')') 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2246 { 2247 int count = 0; 2248 s2 = next_token (line); 2249 for (line = s2; *line != '\0'; ++line) 2250 { 2251 if (*line == '(') 2252 ++count; 2253 else if (*line == ')') 2254 { 2255 if (count <= 0) 2256 break; 2257 else 2258 --count; 2259 } 2260 } 2261 } 2217 2262 else 2218 2219 2220 2221 2222 2223 2263 { 2264 ++line; 2265 s2 = line; 2266 while (*line != '\0' && *line != termin) 2267 ++line; 2268 } 2224 2269 2225 2270 if (*line == '\0') 2226 return -1; 2227 2228 *line = '\0'; 2271 return -1; 2272 2229 2273 #ifdef CONFIG_WITH_VALUE_LENGTH 2230 2274 l = line - s2; 2231 2275 #endif 2232 line = next_token (++line); 2276 *(line++) = '\0'; 2277 NEXT_TOKEN (line); 2233 2278 if (*line != '\0') 2234 EXTRANEOUS();2279 EXTRATEXT (); 2235 2280 2236 2281 #ifndef CONFIG_WITH_VALUE_LENGTH … … 2291 2336 record_target_var (struct nameseq *filenames, char *defn, 2292 2337 enum variable_origin origin, struct vmodifiers *vmod, 2293 const structfloc *flocp)2338 const floc *flocp) 2294 2339 { 2295 2340 struct nameseq *nextf; … … 2305 2350 struct variable *v; 2306 2351 const char *name = filenames->name; 2307 const char *fname;2308 2352 const char *percent; 2309 2353 struct pattern_var *p; 2354 #ifdef CONFIG_WITH_VALUE_LENGTH 2355 const char *fname; 2356 #endif 2310 2357 2311 2358 nextf = filenames->next; … … 2339 2386 v->value_alloc_len = v->value_length + 1; 2340 2387 #endif 2341 2342 fname = p->target;2343 2388 } 2344 2389 else … … 2365 2410 2366 2411 initialize_file_variables (f, 1); 2367 fname = f->name;2368 2412 2369 2413 current_variable_set_list = f->variables; 2370 2414 v = try_variable_definition (flocp, defn IF_WITH_VALUE_LENGTH_PARAM(NULL), origin, 1); 2371 2415 if (!v) 2372 fatal (flocp, _("Malformed target-specific variable definition"));2416 O (fatal, flocp, _("Malformed target-specific variable definition")); 2373 2417 current_variable_set_list = global; 2374 2418 } … … 2385 2429 struct variable *gv; 2386 2430 #ifndef CONFIG_WITH_STRCACHE2 2387 int len = strlen (v->name);2431 int len = strlen (v->name); 2388 2432 #else 2389 2433 int len = !percent … … 2393 2437 2394 2438 gv = lookup_variable (v->name, len); 2395 if (gv && (gv->origin == o_env_override || gv->origin == o_command)) 2439 if (gv && v != gv 2440 && (gv->origin == o_env_override || gv->origin == o_command)) 2396 2441 { 2397 2442 #ifdef CONFIG_WITH_RDONLY_VARIABLE_VALUE 2398 2443 assert (!v->rdonly_val); /* paranoia */ 2399 2444 #endif 2400 if (v->value != 0) 2401 free (v->value); 2445 free (v->value); 2402 2446 #ifndef CONFIG_WITH_VALUE_LENGTH 2403 2447 v->value = xstrdup (gv->value); … … 2420 2464 by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED. 2421 2465 TWO_COLON is nonzero if a double colon was used. 2422 If not nil, PATTERN is the `%' pattern to make this2466 If not nil, PATTERN is the '%' pattern to make this 2423 2467 a static pattern rule, and PATTERN_PERCENT is a pointer 2424 to the `%' within it.2468 to the '%' within it. 2425 2469 2426 2470 The links of FILENAMES are freed, and so are any names in it … … 2432 2476 unsigned int cmds_started, char *commands, 2433 2477 unsigned int commands_idx, int two_colon, 2434 c onst struct floc *flocp)2478 char prefix, const floc *flocp) 2435 2479 { 2436 2480 #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET … … 2449 2493 See Savannah bug # 12124. */ 2450 2494 if (snapped_deps) 2451 fatal (flocp, _("prerequisites cannot be defined in recipes"));2495 O (fatal, flocp, _("prerequisites cannot be defined in recipes")); 2452 2496 2453 2497 /* Determine if this is a pattern rule or not. */ … … 2465 2509 cmds->fileinfo.filenm = flocp->filenm; 2466 2510 cmds->fileinfo.lineno = cmds_started; 2511 cmds->fileinfo.offset = 0; 2467 2512 cmds->commands = xstrndup (commands, commands_idx); 2468 2513 cmds->command_lines = 0; 2514 cmds->recipe_prefix = prefix; 2469 2515 #ifdef CONFIG_WITH_MEMORY_OPTIMIZATIONS 2470 2516 cmds->refs = 0; … … 2478 2524 if (depstr == 0) 2479 2525 deps = 0; 2480 else if (second_expansion && strchr (depstr, '$'))2481 {2482 deps = alloc_dep ();2483 deps->name = depstr;2484 deps->need_2nd_expansion = 1;2485 deps->staticpattern = pattern != 0;2486 }2487 2526 else 2488 2527 { 2489 deps = split_prereqs (depstr); 2490 free (depstr); 2491 2492 /* We'll enter static pattern prereqs later when we have the stem. We 2493 don't want to enter pattern rules at all so that we don't think that 2494 they ought to exist (make manual "Implicit Rule Search Algorithm", 2495 item 5c). */ 2496 if (! pattern && ! implicit_percent) 2497 deps = enter_prereqs (deps, NULL); 2528 depstr = unescape_char (depstr, ':'); 2529 if (second_expansion && strchr (depstr, '$')) 2530 { 2531 deps = alloc_dep (); 2532 deps->name = depstr; 2533 deps->need_2nd_expansion = 1; 2534 deps->staticpattern = pattern != 0; 2535 } 2536 else 2537 { 2538 deps = split_prereqs (depstr); 2539 free (depstr); 2540 2541 /* We'll enter static pattern prereqs later when we have the stem. 2542 We don't want to enter pattern rules at all so that we don't 2543 think that they ought to exist (make manual "Implicit Rule Search 2544 Algorithm", item 5c). */ 2545 if (! pattern && ! implicit_percent) 2546 deps = enter_prereqs (deps, NULL); 2547 } 2498 2548 } 2499 2549 … … 2509 2559 2510 2560 if (pattern != 0) 2511 fatal (flocp, _("mixed implicit and static pattern rules"));2561 O (fatal, flocp, _("mixed implicit and static pattern rules")); 2512 2562 2513 2563 /* Count the targets to create an array of target names. … … 2532 2582 2533 2583 if (implicit_percent == 0) 2534 fatal (flocp, _("mixed implicit and normal rules"));2535 2536 2537 2584 O (fatal, flocp, _("mixed implicit and normal rules")); 2585 2586 targets[c] = name; 2587 target_pats[c] = implicit_percent; 2538 2588 ++c; 2539 2589 … … 2565 2615 posix_pedantic = 1; 2566 2616 define_variable_cname (".SHELLFLAGS", "-ec", o_default, 0); 2617 /* These default values are based on IEEE Std 1003.1-2008. */ 2618 define_variable_cname ("ARFLAGS", "-rv", o_default, 0); 2619 define_variable_cname ("CC", "c99", o_default, 0); 2620 define_variable_cname ("CFLAGS", "-O", o_default, 0); 2621 define_variable_cname ("FC", "fort77", o_default, 0); 2622 define_variable_cname ("FFLAGS", "-O 1", o_default, 0); 2623 define_variable_cname ("SCCSGETFLAGS", "-s", o_default, 0); 2567 2624 } 2568 2625 else if (streq (name, ".SECONDEXPANSION")) … … 2572 2629 second_target_expansion = 1; 2573 2630 #endif 2574 #if !defined (WINDOWS32) && !defined(__MSDOS__) && !defined (__EMX__)2631 #if !defined (__MSDOS__) && !defined (__EMX__) 2575 2632 else if (streq (name, ".ONESHELL")) 2576 2633 one_shell = 1; … … 2621 2678 2622 2679 /* If this is a static pattern rule: 2623 `targets: target%pattern: prereq%pattern; recipe',2680 'targets: target%pattern: prereq%pattern; recipe', 2624 2681 make sure the pattern matches this target name. */ 2625 2682 if (pattern && !pattern_matches (pattern, pattern_percent, name)) 2626 error (flocp, _("target `%s' doesn't match the target pattern"), name); 2683 OS (error, flocp, 2684 _("target '%s' doesn't match the target pattern"), name); 2627 2685 else if (deps) 2628 2686 /* If there are multiple targets, copy the chain DEPS for all but the … … 2633 2691 /* Find or create an entry in the file database for this target. */ 2634 2692 if (!two_colon) 2635 2636 2637 2693 { 2694 /* Single-colon. Combine this rule with the file's existing record, 2695 if any. */ 2638 2696 #ifndef KMK 2639 2697 f = enter_file (strcache_add (name)); 2640 2698 #else /* KMK - the name is already in the cache, don't waste time. */ 2641 2699 f = enter_file (name); 2642 2700 #endif 2643 if (f->double_colon) 2644 fatal (flocp, 2645 _("target file `%s' has both : and :: entries"), f->name); 2646 2647 /* If CMDS == F->CMDS, this target was listed in this rule 2648 more than once. Just give a warning since this is harmless. */ 2649 if (cmds != 0 && cmds == f->cmds) 2650 error (flocp, 2651 _("target `%s' given more than once in the same rule."), 2652 f->name); 2653 2654 /* Check for two single-colon entries both with commands. 2655 Check is_target so that we don't lose on files such as .c.o 2656 whose commands were preinitialized. */ 2657 else if (cmds != 0 && f->cmds != 0 && f->is_target) 2658 { 2659 error (&cmds->fileinfo, 2660 _("warning: overriding recipe for target `%s'"), 2701 if (f->double_colon) 2702 OS (fatal, flocp, 2703 _("target file '%s' has both : and :: entries"), f->name); 2704 2705 /* If CMDS == F->CMDS, this target was listed in this rule 2706 more than once. Just give a warning since this is harmless. */ 2707 if (cmds != 0 && cmds == f->cmds) 2708 OS (error, flocp, 2709 _("target '%s' given more than once in the same rule"), 2710 f->name); 2711 2712 /* Check for two single-colon entries both with commands. 2713 Check is_target so that we don't lose on files such as .c.o 2714 whose commands were preinitialized. */ 2715 else if (cmds != 0 && f->cmds != 0 && f->is_target) 2716 { 2717 size_t l = strlen (f->name); 2718 error (&cmds->fileinfo, l, 2719 _("warning: overriding recipe for target '%s'"), 2661 2720 f->name); 2662 error (&f->cmds->fileinfo,2663 _("warning: ignoring old recipe for target `%s'"),2721 error (&f->cmds->fileinfo, l, 2722 _("warning: ignoring old recipe for target '%s'"), 2664 2723 f->name); 2665 2666 2667 2668 2669 2670 2671 2724 } 2725 2726 /* Defining .DEFAULT with no deps or cmds clears it. */ 2727 if (f == default_file && this == 0 && cmds == 0) 2728 f->cmds = 0; 2729 if (cmds != 0) 2730 f->cmds = cmds; 2672 2731 2673 2732 #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET … … 2684 2743 2685 2744 if (f == suffix_file) 2686 error (flocp,2687 2745 O (error, flocp, 2746 _(".SUFFIXES encountered in an explicit multi target rule")); 2688 2747 } 2689 2748 prev_file = f; 2690 2749 #endif 2691 2750 2692 2693 2694 2695 2751 /* Defining .SUFFIXES with no dependencies clears out the list of 2752 suffixes. */ 2753 if (f == suffix_file && this == 0) 2754 { 2696 2755 free_dep_chain (f->deps); 2697 2698 2699 2756 f->deps = 0; 2757 } 2758 } 2700 2759 else 2701 2702 2760 { 2761 /* Double-colon. Make a new record even if there already is one. */ 2703 2762 #ifndef CONFIG_WITH_STRCACHE2 2704 2763 f = lookup_file (name); … … 2707 2766 #endif /* CONFIG_WITH_STRCACHE2 */ 2708 2767 2709 2710 2711 2712 fatal (flocp,2713 _("target file `%s' has both : and :: entries"), f->name);2768 /* Check for both : and :: rules. Check is_target so we don't lose 2769 on default suffix rules or makefiles. */ 2770 if (f != 0 && f->is_target && !f->double_colon) 2771 OS (fatal, flocp, 2772 _("target file '%s' has both : and :: entries"), f->name); 2714 2773 2715 2774 #ifndef KMK 2716 2775 f = enter_file (strcache_add (name)); 2717 2776 #else /* KMK - the name is already in the cache, don't waste time. */ 2718 2719 #endif 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2777 f = enter_file (name); 2778 #endif 2779 /* If there was an existing entry and it was a double-colon entry, 2780 enter_file will have returned a new one, making it the prev 2781 pointer of the old one, and setting its double_colon pointer to 2782 the first one. */ 2783 if (f->double_colon == 0) 2784 /* This is the first entry for this name, so we must set its 2785 double_colon pointer to itself. */ 2786 f->double_colon = f; 2787 2788 f->cmds = cmds; 2789 } 2731 2790 2732 2791 f->is_target = 1; 2733 2792 2734 2793 /* If this is a static pattern rule, set the stem to the part of its 2735 name that matched the `%' in the pattern, so you can use $* in the2794 name that matched the '%' in the pattern, so you can use $* in the 2736 2795 commands. If we didn't do it before, enter the prereqs now. */ 2737 2796 if (pattern) … … 2796 2855 name = filenames->name; 2797 2856 if (find_percent_cached (&name)) 2798 fatal (flocp, _("mixed implicit and normal rules")); 2857 O (error, flocp, 2858 _("*** mixed implicit and normal rules: deprecated syntax")); 2799 2859 } 2800 2860 } … … 2810 2870 STOPCHAR _cannot_ be '$' if IGNOREVARS is true. */ 2811 2871 2812 #ifndef CONFIG_WITH_VALUE_LENGTH2813 2872 static char * 2814 find_char_unquote (char *string, int stop1, int stop2, int blank, 2815 int ignorevars) 2816 #else 2817 static char * 2818 find_char_unquote_2 (char *string, int stop1, int stop2, int blank, 2819 int ignorevars, unsigned int string_len) 2820 #endif 2873 find_char_unquote (char *string, int map IF_WITH_VALUE_LENGTH_PARAM(unsigned int string_len)) 2821 2874 { 2822 2875 #ifndef CONFIG_WITH_VALUE_LENGTH … … 2824 2877 #endif 2825 2878 char *p = string; 2826 register int ch; /* bird: 'optimiziations' */2827 2879 #ifdef CONFIG_WITH_VALUE_LENGTH 2828 2880 assert (string_len == 0 || string_len == strlen (string)); 2829 2881 #endif 2830 2882 2831 if (ignorevars)2832 ignorevars = '$';2883 /* Always stop on NUL. */ 2884 map |= MAP_NUL; 2833 2885 2834 2886 while (1) 2835 2887 { 2836 if (stop2 && blank) 2837 while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1 && ch != stop2 2838 && ! isblank ((unsigned char) ch)) 2839 ++p; 2840 else if (stop2) 2841 while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1 && ch != stop2) 2842 ++p; 2843 else if (blank) 2844 while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1 2845 && ! isblank ((unsigned char) ch)) 2846 ++p; 2847 else 2848 while ((ch = *p) != '\0' && ch != ignorevars && ch != stop1) 2849 ++p; 2850 2851 if (ch == '\0') 2852 break; 2888 while (! STOP_SET (*p, map)) 2889 ++p; 2890 2891 if (*p == '\0') 2892 break; 2853 2893 2854 2894 /* If we stopped due to a variable reference, skip over its contents. */ 2855 if ( ch == ignorevars)2895 if (STOP_SET (*p, MAP_VARIABLE)) 2856 2896 { 2857 2897 char openparen = p[1]; 2898 2899 /* Check if '$' is the last character in the string. */ 2900 if (openparen == '\0') 2901 break; 2858 2902 2859 2903 p += 2; … … 2864 2908 unsigned int pcount = 1; 2865 2909 char closeparen = (openparen == '(' ? ')' : '}'); 2910 char ch; /* bird */ 2866 2911 2867 2912 while ((ch = *p)) … … 2884 2929 2885 2930 if (p > string && p[-1] == '\\') 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2931 { 2932 /* Search for more backslashes. */ 2933 int i = -2; 2934 while (&p[i] >= string && p[i] == '\\') 2935 --i; 2936 ++i; 2937 /* Only compute the length if really needed. */ 2938 if (string_len == 0) 2939 string_len = strlen (string); 2940 /* The number of backslashes is now -I. 2941 Copy P over itself to swallow half of them. */ 2942 memmove (&p[i], &p[i/2], (string_len - (p - string)) - (i/2) + 1); 2943 p += i/2; 2944 if (i % 2 == 0) 2945 /* All the backslashes quoted each other; the STOPCHAR was 2946 unquoted. */ 2947 return p; 2948 2949 /* The STOPCHAR was quoted by a backslash. Look for another. */ 2950 } 2906 2951 else 2907 2908 2952 /* No backslash in sight. */ 2953 return p; 2909 2954 } 2910 2955 … … 2914 2959 2915 2960 #ifdef CONFIG_WITH_VALUE_LENGTH 2916 /* Special case version of find_char_unquote that only takes stop 1.2917 This is so common that it makes a lot of sense to specialize this. 2918 */ 2919 __inline staticchar *2920 find_char_unquote_0 (char *string, int stop1, char **eosp)2961 /* Special case version of find_char_unquote that only takes stop character. 2962 This is so common that it makes a lot of sense to specialize this. */ 2963 2964 K_INLINE char * 2965 find_char_unquote_0 (char *string, int stop1, int map, char **eosp) 2921 2966 { 2922 2967 unsigned int string_len = *eosp - string; 2923 char *p = (char *)memchr (string, stop1, string_len); 2968 char *p; 2969 2924 2970 assert (strlen (string) == string_len); 2971 assert (!(map & MAP_VARIABLE) && map != 0); 2972 assert ((stopchar_map[(unsigned char)stop1] & map) == map); 2973 2974 p = (char *)memchr (string, stop1, string_len); 2925 2975 if (!p) 2926 2976 return NULL; 2927 if (p <= string || p[-1] != '\\') 2977 if (p <= string || p[-1] != '\\') 2928 2978 return p; 2929 2979 2930 p = find_char_unquote _2 (string, stop1, 0, 0, 0, string_len);2980 p = find_char_unquote (string, map, string_len); 2931 2981 *eosp = memchr (string, '\0', string_len); 2932 2982 return p; … … 2934 2984 #endif 2935 2985 2986 /* Unescape a character in a string. The string is compressed onto itself. */ 2987 2988 static char * 2989 unescape_char (char *string, int c) 2990 { 2991 char *p = string; 2992 char *s = string; 2993 2994 while (*s != '\0') 2995 { 2996 if (*s == '\\') 2997 { 2998 char *e = s; 2999 int l; 3000 3001 /* We found a backslash. See if it's escaping our character. */ 3002 while (*e == '\\') 3003 ++e; 3004 l = e - s; 3005 3006 if (*e != c || l%2 == 0) 3007 { 3008 /* It's not; just take it all without unescaping. */ 3009 memmove (p, s, l); 3010 p += l; 3011 3012 // If we hit the end of the string, we're done 3013 if (*e == '\0') 3014 break; 3015 } 3016 else if (l > 1) 3017 { 3018 /* It is, and there's >1 backslash. Take half of them. */ 3019 l /= 2; 3020 memmove (p, s, l); 3021 p += l; 3022 } 3023 3024 s = e; 3025 } 3026 3027 *(p++) = *(s++); 3028 } 3029 3030 *p = '\0'; 3031 return string; 3032 } 3033 2936 3034 /* Search PATTERN for an unquoted % and handle quoting. */ 2937 3035 … … 2939 3037 find_percent (char *pattern) 2940 3038 { 2941 return find_char_unquote (pattern, '%', 0, 0, 0); 3039 #ifndef CONFIG_WITH_VALUE_LENGTH 3040 return find_char_unquote (pattern, MAP_PERCENT); 3041 #else 3042 char *eos = strchr(pattern, '\0'); 3043 return find_char_unquote_0 (pattern, '%', MAP_PERCENT, &eos); 3044 #endif 2942 3045 } 2943 3046 … … 2962 3065 while (1) 2963 3066 { 2964 while ( *p != '\0' && *p != '%')3067 while (! STOP_SET (*p, MAP_PERCENT|MAP_NUL)) 2965 3068 ++p; 2966 3069 … … 3032 3135 */ 3033 3136 3034 static unsignedlong3137 static long 3035 3138 readstring (struct ebuffer *ebuf) 3036 3139 { … … 3125 3228 len = strlen (p); 3126 3229 if (len == 0) 3127 3128 3129 3130 3131 3132 3133 error (&ebuf->floc,3134 3135 3136 3137 3230 { 3231 /* This only happens when the first thing on the line is a '\0'. 3232 It is a pretty hopeless case, but (wonder of wonders) Athena 3233 lossage strikes again! (xmkmf puts NULs in its makefiles.) 3234 There is nothing really to be done; we synthesize a newline so 3235 the following line doesn't appear to be part of this line. */ 3236 O (error, &ebuf->floc, 3237 _("warning: NUL character seen; rest of line ignored")); 3238 p[0] = '\n'; 3239 len = 1; 3240 } 3138 3241 3139 3242 /* Jump past the text we just read. */ … … 3154 3257 { 3155 3258 --p; 3156 p[-1] = '\n';3259 memmove (p-1, p, strlen (p) + 1); 3157 3260 } 3158 3261 #endif … … 3160 3263 backslash = 0; 3161 3264 for (p2 = p - 2; p2 >= start; --p2) 3162 3163 3164 3265 { 3266 if (*p2 != '\\') 3267 break; 3165 3268 backslash = !backslash; 3166 3269 } 3167 3270 3168 3271 if (!backslash) 3169 3170 3272 { 3273 p[-1] = '\0'; 3171 3274 #ifdef CONFIG_WITH_VALUE_LENGTH 3172 3275 ebuf->eol = p - 1; 3173 3276 #endif 3174 3175 3277 break; 3278 } 3176 3279 3177 3280 /* It was a backslash/newline combo. If we have more space, read … … 3225 3328 w_dcolon A double-colon 3226 3329 w_semicolon A semicolon 3227 w_varassign A variable assignment operator (=, :=, +=, >=, or ?=)3330 w_varassign A variable assignment operator (=, :=, ::=, +=, >=, ?=, or !=) 3228 3331 3229 3332 Note that this function is only used when reading certain parts of the … … 3239 3342 3240 3343 /* Skip any leading whitespace. */ 3241 while ( isblank ((unsigned char)*p))3344 while (ISBLANK (*p)) 3242 3345 ++p; 3243 3346 … … 3264 3367 case ':': 3265 3368 ++p; 3266 wtype = w_dcolon; 3369 if (p[1] != '=') 3370 wtype = w_dcolon; 3371 else 3372 { 3373 wtype = w_varassign; 3374 ++p; 3375 } 3267 3376 break; 3268 3377 … … 3276 3385 case '+': 3277 3386 case '?': 3387 case '!': 3278 3388 #ifdef CONFIG_WITH_PREPEND_ASSIGNMENT 3279 3389 case '>': … … 3298 3408 /* This is some non-operator word. A word consists of the longest 3299 3409 string of characters that doesn't contain whitespace, one of [:=#], 3300 or [?+ ]=, or one of the chars in the DELIM string. */3410 or [?+!]=, or one of the chars in the DELIM string. */ 3301 3411 3302 3412 /* We start out assuming a static word; if we see a variable we'll … … 3320 3430 case ':': 3321 3431 #ifdef HAVE_DOS_PATHS 3322 3323 3324 3325 3326 3327 3328 #endif 3329 3432 /* A word CAN include a colon in its drive spec. The drive 3433 spec is allowed either at the beginning of a word, or as part 3434 of the archive member name, like in "libfoo.a(d:/foo/bar.o)". */ 3435 if (!(p - beg >= 2 3436 && (*p == '/' || *p == '\\') && isalpha ((unsigned char)p[-2]) 3437 && (p - beg == 2 || p[-3] == '('))) 3438 #endif 3439 goto done_word; 3330 3440 3331 3441 case '$': … … 3333 3443 if (c == '$') 3334 3444 break; 3445 if (c == '\0') 3446 goto done_word; 3335 3447 3336 3448 /* This is a variable reference, so note that it's expandable. … … 3405 3517 construct_include_path (const char **arg_dirs) 3406 3518 { 3407 #ifdef VAXC 3519 #ifdef VAXC /* just don't ask ... */ 3408 3520 stat_t stbuf; 3409 3521 #else … … 3440 3552 while (*arg_dirs != 0) 3441 3553 { 3442 3554 const char *dir = *(arg_dirs++); 3443 3555 char *expanded = 0; 3444 3556 int e; 3445 3557 3446 3447 3448 3449 3450 3451 3558 if (dir[0] == '~') 3559 { 3560 expanded = tilde_expand (dir); 3561 if (expanded != 0) 3562 dir = expanded; 3563 } 3452 3564 3453 3565 EINTRLOOP (e, stat (dir, &stbuf)); 3454 3566 if (e == 0 && S_ISDIR (stbuf.st_mode)) 3455 3567 { 3456 3568 unsigned int len = strlen (dir); … … 3463 3575 } 3464 3576 3465 if (expanded) 3466 free (expanded); 3577 free (expanded); 3467 3578 } 3468 3579 … … 3478 3589 { 3479 3590 unsigned int len = strlen (djdir->value) + 8; 3480 3481 3482 3483 3591 char *defdir = alloca (len + 1); 3592 3593 strcat (strcpy (defdir, djdir->value), "/include"); 3594 dirs[idx++] = strcache_add (defdir); 3484 3595 3485 3596 if (len > max_incl_len) … … 3536 3647 if (name[1] == '/' || name[1] == '\0') 3537 3648 { 3538 extern char *getenv ();3539 3649 char *home_dir; 3540 3650 int is_variable; 3541 3651 3542 3652 { 3543 3544 3545 3653 /* Turn off --warn-undefined-variables while we expand HOME. */ 3654 int save = warn_undefined_variables_flag; 3655 warn_undefined_variables_flag = 0; 3546 3656 3547 3657 #ifndef CONFIG_WITH_VALUE_LENGTH 3548 3549 #else 3550 3551 #endif 3552 3553 3658 home_dir = allocated_variable_expand ("$(HOME)"); 3659 #else 3660 home_dir = allocated_variable_expand_2 (STRING_SIZE_TUPLE("$(HOME)"), NULL); 3661 #endif 3662 3663 warn_undefined_variables_flag = save; 3554 3664 } 3555 3665 3556 3666 is_variable = home_dir[0] != '\0'; 3557 3667 if (!is_variable) 3558 3559 3560 3561 3668 { 3669 free (home_dir); 3670 home_dir = getenv ("HOME"); 3671 } 3562 3672 # if !defined(_AMIGA) && !defined(WINDOWS32) 3563 3673 if (home_dir == 0 || home_dir[0] == '\0') 3564 { 3565 extern char *getlogin (); 3566 char *logname = getlogin (); 3567 home_dir = 0; 3568 if (logname != 0) 3569 { 3570 struct passwd *p = getpwnam (logname); 3571 if (p != 0) 3572 home_dir = p->pw_dir; 3573 } 3574 } 3674 { 3675 char *logname = getlogin (); 3676 home_dir = 0; 3677 if (logname != 0) 3678 { 3679 struct passwd *p = getpwnam (logname); 3680 if (p != 0) 3681 home_dir = p->pw_dir; 3682 } 3683 } 3575 3684 # endif /* !AMIGA && !WINDOWS32 */ 3576 3685 if (home_dir != 0) 3577 3578 3579 3580 3581 3582 3686 { 3687 char *new = xstrdup (concat (2, home_dir, name + 1)); 3688 if (is_variable) 3689 free (home_dir); 3690 return new; 3691 } 3583 3692 } 3584 3693 # if !defined(_AMIGA) && !defined(WINDOWS32) … … 3588 3697 char *userend = strchr (name + 1, '/'); 3589 3698 if (userend != 0) 3590 3699 *userend = '\0'; 3591 3700 pwent = getpwnam (name + 1); 3592 3701 if (pwent != 0) 3593 3594 3595 3596 3597 3598 3702 { 3703 if (userend == 0) 3704 return xstrdup (pwent->pw_dir); 3705 else 3706 return xstrdup (concat (3, pwent->pw_dir, "/", userend + 1)); 3707 } 3599 3708 else if (userend != 0) 3600 3709 *userend = '/'; 3601 3710 } 3602 3711 # endif /* !AMIGA && !WINDOWS32 */ … … 3630 3739 3631 3740 void * 3632 parse_file_seq (char **stringp, unsigned int size, int stop char,3741 parse_file_seq (char **stringp, unsigned int size, int stopmap, 3633 3742 const char *prefix, int flags 3634 3743 IF_WITH_ALLOC_CACHES_PARAM(struct alloccache *alloc_cache) ) 3635 3744 { 3636 extern void dir_setup_glob (glob_t *glob);3637 3638 3745 /* tmp points to tmpbuf after the prefix, if any. 3639 3746 tp is the end of the buffer. */ 3640 3747 static char *tmpbuf = NULL; 3641 static int tmpbuf_len = 0; 3642 3643 int cachep = (! (flags & PARSEFS_NOCACHE)); 3748 3749 int cachep = NONE_SET (flags, PARSEFS_NOCACHE); 3644 3750 3645 3751 struct nameseq *new = 0; … … 3665 3771 char *tp; 3666 3772 3667 #ifdef VMS 3668 # define VMS_COMMA ',' 3669 #else 3670 # define VMS_COMMA 0 3671 #endif 3773 /* Always stop on NUL. */ 3774 stopmap |= MAP_NUL; 3672 3775 3673 3776 if (size < sizeof (struct nameseq)) 3674 3777 size = sizeof (struct nameseq); 3675 3778 3676 if ( ! (flags &PARSEFS_NOGLOB))3779 if (NONE_SET (flags, PARSEFS_NOGLOB)) 3677 3780 dir_setup_glob (&gl); 3678 3781 3679 3782 /* Get enough temporary space to construct the largest possible target. */ 3680 3783 { 3784 static int tmpbuf_len = 0; 3681 3785 int l = strlen (*stringp) + 1; 3682 3786 if (l > tmpbuf_len) … … 3695 3799 const char **nlist = 0; 3696 3800 char *tildep = 0; 3801 int globme = 1; 3697 3802 #ifndef NO_ARCHIVES 3698 3803 char *arname = 0; … … 3704 3809 3705 3810 /* Skip whitespace; at the end of the string or STOPCHAR we're done. */ 3706 p = next_token(p);3707 if ( *p == '\0' || *p == stopchar)3708 3811 NEXT_TOKEN (p); 3812 if (STOP_SET (*p, stopmap)) 3813 break; 3709 3814 3710 3815 /* There are names left, so find the end of the next name. 3711 3816 Throughout this iteration S points to the start. */ 3712 3817 s = p; 3713 p = find_char_unquote (p, stop char, VMS_COMMA, 1, 0);3818 p = find_char_unquote (p, stopmap|MAP_VMSCOMMA|MAP_BLANK IF_WITH_VALUE_LENGTH_PARAM(0)); 3714 3819 #ifdef VMS 3715 3820 /* convert comma separated list to space separated */ 3716 3821 if (p && *p == ',') 3717 3822 *p =' '; 3718 3823 #endif 3719 3824 #ifdef _AMIGA 3720 if (stopchar == ':' && p && *p == ':' 3721 && !(isspace ((unsigned char)p[1]) || !p[1] 3722 || isspace ((unsigned char)p[-1]))) 3723 p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0); 3825 if (p && STOP_SET (*p, stopmap & MAP_COLON) 3826 && !(ISSPACE (p[1]) || !p[1] || ISSPACE (p[-1]))) 3827 p = find_char_unquote (p+1, stopmap|MAP_VMSCOMMA|MAP_BLANK); 3724 3828 #endif 3725 3829 #ifdef HAVE_DOS_PATHS … … 3728 3832 Note that tokens separated by spaces should be treated as separate 3729 3833 tokens since make doesn't allow path names with spaces */ 3730 if (stop char == ':')3731 while (p != 0 && ! isspace ((unsigned char)*p) &&3834 if (stopmap | MAP_COLON) 3835 while (p != 0 && !ISSPACE (*p) && 3732 3836 (p[1] == '\\' || p[1] == '/') && isalpha ((unsigned char)p[-1])) 3733 p = find_char_unquote (p + 1, stop char, VMS_COMMA, 1, 0);3837 p = find_char_unquote (p + 1, stopmap|MAP_VMSCOMMA|MAP_BLANK IF_WITH_VALUE_LENGTH_PARAM(0)); 3734 3838 #endif 3735 3839 if (p == 0) 3736 3840 p = s + strlen (s); 3737 3841 3738 3842 /* Strip leading "this directory" references. */ 3739 if ( ! (flags &PARSEFS_NOSTRIP))3843 if (NONE_SET (flags, PARSEFS_NOSTRIP)) 3740 3844 #ifdef VMS 3741 /* Skip leading `[]'s. */ 3742 while (p - s > 2 && s[0] == '[' && s[1] == ']') 3743 #else 3744 /* Skip leading `./'s. */ 3745 while (p - s > 2 && s[0] == '.' && s[1] == '/') 3746 #endif 3747 { 3845 /* Skip leading '[]'s. should only be one set or bug somwhere else */ 3846 if (p - s > 2 && s[0] == '[' && s[1] == ']') 3847 s += 2; 3848 /* Skip leading '<>'s. should only be one set or bug somwhere else */ 3849 if (p - s > 2 && s[0] == '<' && s[1] == '>') 3850 s += 2; 3851 #endif 3852 /* Skip leading './'s. */ 3853 while (p - s > 2 && s[0] == '.' && s[1] == '/') 3854 { 3748 3855 /* Skip "./" and all following slashes. */ 3749 3750 3751 3752 3856 s += 2; 3857 while (*s == '/') 3858 ++s; 3859 } 3753 3860 3754 3861 /* Extract the filename just found, and skip it. … … 3757 3864 if (s == p) 3758 3865 { 3759 /* The name was stripped to empty ("./"). */ 3760 #if defined(VMS) 3761 continue; 3762 #elif defined(_AMIGA) 3866 /* The name was stripped to empty ("./"). */ 3867 #if defined(_AMIGA) 3763 3868 /* PDS-- This cannot be right!! */ 3764 3869 tp[0] = '\0'; … … 3772 3877 } 3773 3878 else 3774 3879 { 3775 3880 #ifdef VMS 3776 3881 /* VMS filenames can have a ':' in them but they have to be '\'ed but we need … … 3778 3883 * xstrdup called because S may be read-only string constant. 3779 3884 */ 3780 3781 3782 3783 3885 char *n = tp; 3886 while (s < p) 3887 { 3888 if (s[0] == '\\' && s[1] == ':') 3784 3889 ++s; 3785 3786 3890 *(n++) = *(s++); 3891 } 3787 3892 n[0] = '\0'; 3788 3893 nlen = strlen (tp); … … 3803 3908 3804 3909 TP == TMP means we're not already in an archive group. Ignore 3805 something starting with `(', as that cannot actually be an3910 something starting with '(', as that cannot actually be an 3806 3911 archive-member reference (and treating it as such results in an empty 3807 3912 file name, which causes much lossage). Also if it ends in ")" then … … 3811 3916 character, so ensure there's some word ending like that before 3812 3917 considering this an archive group. */ 3813 if ( ! (flags &PARSEFS_NOAR)3918 if (NONE_SET (flags, PARSEFS_NOAR) 3814 3919 && tp == tmpbuf && tp[0] != '(' && tp[nlen-1] != ')') 3815 3920 { … … 3819 3924 /* This looks like the first element in an open archive group. 3820 3925 A valid group MUST have ')' as the last character. */ 3821 const char *e = p + nlen;3926 const char *e = p; 3822 3927 do 3823 3928 { 3824 e = next_token (e); 3929 const char *o = e; 3930 NEXT_TOKEN (e); 3825 3931 /* Find the end of this word. We don't want to unquote and 3826 3932 we don't care about quoting since we're looking for the 3827 3933 last char in the word. */ 3828 while (*e != '\0' && *e != stopchar && *e != VMS_COMMA 3829 && ! isblank ((unsigned char) *e)) 3934 while (! STOP_SET (*e, stopmap|MAP_BLANK|MAP_VMSCOMMA)) 3830 3935 ++e; 3936 /* If we didn't move, we're done now. */ 3937 if (e == o) 3938 break; 3831 3939 if (e[-1] == ')') 3832 3940 { … … 3837 3945 tp = n + 1; 3838 3946 3839 /* If we have just "lib(", part of something like3840 "lib( a b)", go to the next item. */3841 if (! nlen)3842 continue;3843 3844 3947 /* We can stop looking now. */ 3845 3948 break; … … 3847 3950 } 3848 3951 while (*e != '\0'); 3952 3953 /* If we have just "lib(", part of something like "lib( a b)", 3954 go to the next item. */ 3955 if (! nlen) 3956 continue; 3849 3957 } 3850 3958 } … … 3873 3981 /* If we're not globbing we're done: add it to the end of the chain. 3874 3982 Go to the next item in the string. */ 3875 if ( flags & PARSEFS_NOGLOB)3876 { 3877 NEWELT (concat (2, prefix, t p));3983 if (ANY_SET (flags, PARSEFS_NOGLOB)) 3984 { 3985 NEWELT (concat (2, prefix, tmpbuf)); 3878 3986 continue; 3879 3987 } … … 3882 3990 TP is a string in tmpbuf. NLEN is no longer used. 3883 3991 We may need to do more work: after this NAME will be set. */ 3884 name = t p;3992 name = tmpbuf; 3885 3993 3886 3994 /* Expand tilde if applicable. */ 3887 if (t p[0] == '~')3888 3889 tildep = tilde_expand (tp);3890 3995 if (tmpbuf[0] == '~') 3996 { 3997 tildep = tilde_expand (tmpbuf); 3998 if (tildep != 0) 3891 3999 name = tildep; 3892 4000 } 3893 4001 3894 4002 #ifndef NO_ARCHIVES … … 3896 4004 file name, and save the member name in MEMNAME. We will glob on the 3897 4005 archive name and then reattach MEMNAME later. */ 3898 if ( ! (flags &PARSEFS_NOAR) && ar_name (name))3899 3900 3901 3902 4006 if (NONE_SET (flags, PARSEFS_NOAR) && ar_name (name)) 4007 { 4008 ar_parse_name (name, &arname, &memname); 4009 name = arname; 4010 } 3903 4011 #endif /* !NO_ARCHIVES */ 3904 4012 3905 switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl)) 3906 { 3907 case GLOB_NOSPACE: 3908 fatal (NILF, _("virtual memory exhausted")); 3909 3910 case 0: 3911 /* Success. */ 3912 i = gl.gl_pathc; 3913 nlist = (const char **)gl.gl_pathv; 3914 break; 3915 3916 case GLOB_NOMATCH: 3917 /* If we want only existing items, skip this one. */ 3918 if (flags & PARSEFS_EXISTS) 3919 { 3920 i = 0; 3921 break; 3922 } 3923 /* FALLTHROUGH */ 3924 3925 default: 3926 /* By default keep this name. */ 4013 /* glob() is expensive: don't call it unless we need to. */ 4014 if (NONE_SET (flags, PARSEFS_EXISTS) && strpbrk (name, "?*[") == NULL) 4015 { 4016 globme = 0; 3927 4017 i = 1; 3928 4018 nlist = &name; 3929 break; 3930 } 4019 } 4020 else 4021 switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl)) 4022 { 4023 case GLOB_NOSPACE: 4024 OUT_OF_MEM(); 4025 4026 case 0: 4027 /* Success. */ 4028 i = gl.gl_pathc; 4029 nlist = (const char **)gl.gl_pathv; 4030 break; 4031 4032 case GLOB_NOMATCH: 4033 /* If we want only existing items, skip this one. */ 4034 if (ANY_SET (flags, PARSEFS_EXISTS)) 4035 { 4036 i = 0; 4037 break; 4038 } 4039 /* FALLTHROUGH */ 4040 4041 default: 4042 /* By default keep this name. */ 4043 i = 1; 4044 nlist = &name; 4045 break; 4046 } 3931 4047 3932 4048 /* For each matched element, add it to the list. */ … … 3943 4059 { 3944 4060 /* We got a chain of items. Attach them. */ 3945 (*newp)->next = found; 4061 if (*newp) 4062 (*newp)->next = found; 4063 else 4064 *newp = found; 3946 4065 3947 4066 /* Find and set the new end. Massage names if necessary. */ … … 3965 4084 NEWELT (concat (2, prefix, nlist[i])); 3966 4085 4086 if (globme) 3967 4087 globfree (&gl); 3968 4088 3969 4089 #ifndef NO_ARCHIVES 3970 if (arname) 3971 free (arname); 3972 #endif 3973 3974 if (tildep) 3975 free (tildep); 4090 free (arname); 4091 #endif 4092 4093 free (tildep); 3976 4094 } 3977 4095
Note:
See TracChangeset
for help on using the changeset viewer.