Changeset 3138 for vendor/gnumake/current/read.c
- Timestamp:
- Mar 12, 2018, 8:32:29 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/read.c
r2596 r3138 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" … … 33 29 34 30 35 #ifndef WINDOWS32 31 #ifdef WINDOWS32 32 #include <windows.h> 33 #include "sub_proc.h" 34 #else /* !WINDOWS32 */ 36 35 #ifndef _AMIGA 37 36 #ifndef VMS … … 54 53 unsigned int size; /* Malloc'd size of buffer. */ 55 54 FILE *fp; /* File, or NULL if this is an internal buffer. */ 56 struct floc floc;/* Info on the file in fp (if any). */55 floc floc; /* Info on the file in fp (if any). */ 57 56 }; 58 57 … … 77 76 78 77 79 /* A `struct conditionals' contains the information describing78 /* A 'struct conditionals' contains the information describing 80 79 all the active conditionals in a makefile. 81 80 82 The global variable `conditionals' contains the conditionals81 The global variable 'conditionals' contains the conditionals 83 82 information for the current makefile. It is initialized from 84 the static structure `toplevel_conditionals' and is later changed83 the static structure 'toplevel_conditionals' and is later changed 85 84 to new structures for included makefiles. */ 86 85 87 86 struct conditionals 88 87 { 89 unsigned int if_cmds; 90 unsigned int allocated; 91 char *ignoring; 88 unsigned int if_cmds; /* Depth of conditional nesting. */ 89 unsigned int allocated; /* Elts allocated in following arrays. */ 90 char *ignoring; /* Are we ignoring or interpreting? 92 91 0=interpreting, 1=not yet interpreted, 93 92 2=already interpreted */ 94 char *seen_else; /* Have we already seen an `else'? */93 char *seen_else; /* Have we already seen an 'else'? */ 95 94 }; 96 95 … … 128 127 makefile currently being read in. */ 129 128 130 const structfloc *reading_file = 0;131 132 /* The chain of makefiles read by read_makefile. */133 134 static struct dep *read_makefiles = 0;135 136 static inteval_makefile (const char *filename, int flags);129 const floc *reading_file = 0; 130 131 /* The chain of files read by read_all_makefiles. */ 132 133 static struct goaldep *read_files = 0; 134 135 static struct goaldep *eval_makefile (const char *filename, int flags); 137 136 static void eval (struct ebuffer *buffer, int flags); 138 137 … … 142 141 static struct variable *do_define (char *name, enum variable_origin origin, 143 142 struct ebuffer *ebuf); 144 static int conditional_line (char *line, int len, const structfloc *flocp);143 static int conditional_line (char *line, int len, const floc *flocp); 145 144 static void record_files (struct nameseq *filenames, const char *pattern, 146 145 const char *pattern_percent, char *depstr, 147 146 unsigned int cmds_started, char *commands, 148 147 unsigned int commands_idx, int two_colon, 149 c onst struct floc *flocp);148 char prefix, const floc *flocp); 150 149 static void record_target_var (struct nameseq *filenames, char *defn, 151 150 enum variable_origin origin, 152 151 struct vmodifiers *vmod, 153 const structfloc *flocp);152 const floc *flocp); 154 153 static enum make_word_type get_next_mword (char *buffer, char *delim, 155 154 char **startp, unsigned int *length); 156 155 static void remove_comments (char *line); 157 static char *find_char_unquote (char *string, int stop1, int stop2,158 int blank, int ignorevars);156 static char *find_char_unquote (char *string, int map); 157 static char *unescape_char (char *string, int c); 159 158 160 159 … … 162 161 P must point to the word to be tested, and WLEN must be the length. 163 162 */ 164 #define word1eq(s) (wlen == sizeof(s)-1 && strneq (s, p, sizeof(s)-1))165 166 167 168 /* Read in all the makefiles and return the chain of their names. */169 170 struct dep *163 #define word1eq(s) (wlen == CSTRLEN (s) && strneq (s, p, CSTRLEN (s))) 164 165 166 167 /* Read in all the makefiles and return a chain of targets to rebuild. */ 168 169 struct goaldep * 171 170 read_all_makefiles (const char **makefiles) 172 171 { … … 205 204 while ((name = find_next_token ((const char **)&p, &length)) != 0) 206 205 { 207 208 209 206 if (*p != '\0') 207 *p++ = '\0'; 208 eval_makefile (name, RM_NO_DEFAULT_GOAL|RM_INCLUDED|RM_DONTCARE); 210 209 } 211 210 … … 218 217 while (*makefiles != 0) 219 218 { 220 struct dep *tail = read_makefiles; 221 register struct dep *d; 222 223 if (! eval_makefile (*makefiles, 0)) 224 perror_with_name ("", *makefiles); 225 226 /* Find the right element of read_makefiles. */ 227 d = read_makefiles; 228 while (d->next != tail) 229 d = d->next; 230 231 /* Use the storage read_makefile allocates. */ 232 *makefiles = dep_name (d); 233 ++num_makefiles; 234 ++makefiles; 219 struct goaldep *d = eval_makefile (*makefiles, 0); 220 221 if (errno) 222 perror_with_name ("", *makefiles); 223 224 /* Reuse the storage allocated for the read_file. */ 225 *makefiles = dep_name (d); 226 ++num_makefiles; 227 ++makefiles; 235 228 } 236 229 … … 239 232 if (num_makefiles == 0) 240 233 { 241 static c har *default_makefiles[] =234 static const char *default_makefiles[] = 242 235 #ifdef VMS 243 /* all lower case since readdir() (the vms version) 'lowercasifies' */ 244 { "makefile.vms", "gnumakefile.", "makefile.", 0 }; 236 /* all lower case since readdir() (the vms version) 'lowercasifies' */ 237 /* TODO: Above is not always true, this needs more work */ 238 { "makefile.vms", "gnumakefile", "makefile", 0 }; 245 239 #else 246 240 #ifdef _AMIGA 247 241 { "GNUmakefile", "Makefile", "SMakefile", 0 }; 248 242 #else /* !Amiga && !VMS */ 249 { "GNUmakefile", "makefile", "Makefile", 0 }; 243 #ifdef WINDOWS32 244 { "GNUmakefile", "makefile", "Makefile", "makefile.mak", 0 }; 245 #else /* !Amiga && !VMS && !WINDOWS32 */ 246 { "GNUmakefile", "makefile", "Makefile", 0 }; 247 #endif /* !Amiga && !VMS && !WINDOWS32 */ 250 248 #endif /* AMIGA */ 251 249 #endif /* VMS */ 252 registerchar **p = default_makefiles;250 const char **p = default_makefiles; 253 251 while (*p != 0 && !file_exists_p (*p)) 254 252 ++p; 255 253 256 254 if (*p != 0) 257 { 258 if (! eval_makefile (*p, 0)) 259 perror_with_name ("", *p); 260 } 255 { 256 eval_makefile (*p, 0); 257 if (errno) 258 perror_with_name ("", *p); 259 } 261 260 else 262 { 263 /* No default makefile was found. Add the default makefiles to the 264 `read_makefiles' chain so they will be updated if possible. */ 265 struct dep *tail = read_makefiles; 266 /* Add them to the tail, after any MAKEFILES variable makefiles. */ 267 while (tail != 0 && tail->next != 0) 268 tail = tail->next; 269 for (p = default_makefiles; *p != 0; ++p) 270 { 271 struct dep *d = alloc_dep (); 272 d->file = enter_file (strcache_add (*p)); 273 d->dontcare = 1; 274 /* Tell update_goal_chain to bail out as soon as this file is 275 made, and main not to die if we can't make this file. */ 276 d->changed = RM_DONTCARE; 277 if (tail == 0) 278 read_makefiles = d; 279 else 280 tail->next = d; 281 tail = d; 282 } 283 if (tail != 0) 284 tail->next = 0; 285 } 286 } 287 288 return read_makefiles; 261 { 262 /* No default makefile was found. Add the default makefiles to the 263 'read_files' chain so they will be updated if possible. */ 264 struct goaldep *tail = read_files; 265 /* Add them to the tail, after any MAKEFILES variable makefiles. */ 266 while (tail != 0 && tail->next != 0) 267 tail = tail->next; 268 for (p = default_makefiles; *p != 0; ++p) 269 { 270 struct goaldep *d = alloc_goaldep (); 271 d->file = enter_file (strcache_add (*p)); 272 /* Tell update_goal_chain to bail out as soon as this file is 273 made, and main not to die if we can't make this file. */ 274 d->flags = RM_DONTCARE; 275 if (tail == 0) 276 read_files = d; 277 else 278 tail->next = d; 279 tail = d; 280 } 281 if (tail != 0) 282 tail->next = 0; 283 } 284 } 285 286 return read_files; 289 287 } 290 288 … … 309 307 { 310 308 /* Free any space allocated by conditional_line. */ 311 if (conditionals->ignoring) 312 free (conditionals->ignoring); 313 if (conditionals->seen_else) 314 free (conditionals->seen_else); 309 free (conditionals->ignoring); 310 free (conditionals->seen_else); 315 311 316 312 /* Restore state. */ … … 319 315 320 316 321 static int317 static struct goaldep * 322 318 eval_makefile (const char *filename, int flags) 323 319 { 324 struct dep *deps;320 struct goaldep *deps; 325 321 struct ebuffer ebuf; 326 const structfloc *curfile;322 const floc *curfile; 327 323 char *expanded = 0; 328 324 int makefile_errno; 329 325 330 filename = strcache_add (filename); 331 ebuf.floc.filenm = filename; 326 ebuf.floc.filenm = filename; /* Use the original file name. */ 332 327 ebuf.floc.lineno = 1; 328 ebuf.floc.offset = 0; 333 329 334 330 if (ISDB (DB_VERBOSE)) 335 331 { 336 printf (_("Reading makefile `%s'"), filename);332 printf (_("Reading makefile '%s'"), filename); 337 333 if (flags & RM_NO_DEFAULT_GOAL) 338 334 printf (_(" (no default goal)")); 339 335 if (flags & RM_INCLUDED) 340 336 printf (_(" (search path)")); 341 337 if (flags & RM_DONTCARE) 342 338 printf (_(" (don't care)")); 343 339 if (flags & RM_NO_TILDE) 344 340 printf (_(" (no ~ expansion)")); 345 341 puts ("..."); 346 342 } … … 348 344 /* First, get a stream to read. */ 349 345 350 /* Expand ~ in FILENAME unless it came from `include',346 /* Expand ~ in FILENAME unless it came from 'include', 351 347 in which case it was already done. */ 352 348 if (!(flags & RM_NO_TILDE) && filename[0] == '~') … … 354 350 expanded = tilde_expand (filename); 355 351 if (expanded != 0) 356 filename = expanded; 357 } 358 359 ebuf.fp = fopen (filename, "r"); 352 filename = expanded; 353 } 354 355 ENULLLOOP (ebuf.fp, fopen (filename, "r")); 356 360 357 /* Save the error code so we print the right message later. */ 361 358 makefile_errno = errno; 362 359 360 /* Check for unrecoverable errors: out of mem or FILE slots. */ 361 switch (makefile_errno) 362 { 363 #ifdef EMFILE 364 case EMFILE: 365 #endif 366 #ifdef ENFILE 367 case ENFILE: 368 #endif 369 case ENOMEM: 370 { 371 const char *err = strerror (makefile_errno); 372 OS (fatal, reading_file, "%s", err); 373 } 374 } 375 363 376 /* If the makefile wasn't found and it's either a makefile from 364 the `MAKEFILES' variable or an included makefile,377 the 'MAKEFILES' variable or an included makefile, 365 378 search the included makefile search path for this makefile. */ 366 379 if (ebuf.fp == 0 && (flags & RM_INCLUDED) && *filename != '/') … … 368 381 unsigned int i; 369 382 for (i = 0; include_directories[i] != 0; ++i) 370 371 383 { 384 const char *included = concat (3, include_directories[i], 372 385 "/", filename); 373 ebuf.fp = fopen (included, "r"); 374 if (ebuf.fp) 375 { 376 filename = strcache_add (included); 377 break; 378 } 379 } 380 } 386 ebuf.fp = fopen (included, "r"); 387 if (ebuf.fp) 388 { 389 filename = included; 390 break; 391 } 392 } 393 } 394 395 /* Now we have the final name for this makefile. Enter it into 396 the cache. */ 397 filename = strcache_add (filename); 381 398 382 399 /* Add FILENAME to the chain of read makefiles. */ 383 deps = alloc_ dep ();384 deps->next = read_ makefiles;385 read_ makefiles = deps;400 deps = alloc_goaldep (); 401 deps->next = read_files; 402 read_files = deps; 386 403 deps->file = lookup_file (filename); 387 404 if (deps->file == 0) 388 405 deps->file = enter_file (filename); 389 406 filename = deps->file->name; 390 deps->changed = flags; 391 if (flags & RM_DONTCARE) 392 deps->dontcare = 1; 393 394 if (expanded) 395 free (expanded); 407 deps->flags = flags; 408 409 free (expanded); 396 410 397 411 /* If the makefile can't be found at all, give up entirely. */ … … 400 414 { 401 415 /* If we did some searching, errno has the error from the last 402 attempt, rather from FILENAME itself. Restore it in case the403 416 attempt, rather from FILENAME itself. Store it in case the 417 caller wants to use it in a message. */ 404 418 errno = makefile_errno; 405 return 0;419 return deps; 406 420 } 407 421 … … 433 447 alloca (0); 434 448 435 return 1; 449 errno = 0; 450 return deps; 436 451 } 437 452 438 453 void 439 eval_buffer (char *buffer )454 eval_buffer (char *buffer, const floc *flocp) 440 455 { 441 456 struct ebuffer ebuf; 442 457 struct conditionals *saved; 443 458 struct conditionals new; 444 const structfloc *curfile;459 const floc *curfile; 445 460 446 461 /* Evaluate the buffer */ … … 450 465 ebuf.fp = NULL; 451 466 452 if (reading_file) 467 if (flocp) 468 ebuf.floc = *flocp; 469 else if (reading_file) 453 470 ebuf.floc = *reading_file; 454 471 else 455 ebuf.floc.filenm = NULL; 472 { 473 ebuf.floc.filenm = NULL; 474 ebuf.floc.lineno = 1; 475 ebuf.floc.offset = 0; 476 } 456 477 457 478 curfile = reading_file; … … 488 509 489 510 /* Find the start of the next token. If there isn't one we're done. */ 490 line = next_token(line);511 NEXT_TOKEN (line); 491 512 if (*line == '\0') 492 513 return (char *)line; … … 497 518 int wlen; 498 519 const char *p2; 499 enum variable_flavor flavor;500 501 p2 = parse_variable_definition (p, & flavor);520 struct variable v; 521 522 p2 = parse_variable_definition (p, &v); 502 523 503 524 /* If this is a variable assignment, we're done. */ … … 560 581 unsigned int cmds_started, tgts_started; 561 582 int ignoring = 0, in_ignored_define = 0; 562 int no_targets = 0; 583 int no_targets = 0; /* Set when reading a rule without targets. */ 563 584 struct nameseq *filenames = 0; 564 585 char *depstr = 0; 565 586 long nlines = 0; 566 587 int two_colon = 0; 588 char prefix = cmd_prefix; 567 589 const char *pattern = 0; 568 590 const char *pattern_percent; 569 structfloc *fstart;570 structfloc fi;571 572 #define record_waiting_files() 573 do 574 { 575 if (filenames != 0) 591 floc *fstart; 592 floc fi; 593 594 #define record_waiting_files() \ 595 do \ 596 { \ 597 if (filenames != 0) \ 576 598 { \ 577 fi.lineno = tgts_started; \ 578 record_files (filenames, pattern, pattern_percent, depstr, \ 599 fi.lineno = tgts_started; \ 600 fi.offset = 0; \ 601 record_files (filenames, pattern, pattern_percent, depstr, \ 579 602 cmds_started, commands, commands_idx, two_colon, \ 580 &fi);\581 filenames = 0; 603 prefix, &fi); \ 604 filenames = 0; \ 582 605 } \ 583 commands_idx = 0; 606 commands_idx = 0; \ 584 607 no_targets = 0; \ 585 608 pattern = 0; \ … … 598 621 599 622 When you see a "continue" in the loop below, that means we are moving on 600 to the next line _without_ ending any rule that we happen to be working 601 with at the moment. If you see a "goto rule_complete", then the 602 statement we just parsed also finishes the previous rule. */ 623 to the next line. If you see record_waiting_files(), then the statement 624 we are parsing also finishes the previous rule. */ 603 625 604 626 commands = xmalloc (200); … … 622 644 break; 623 645 646 line = ebuf->buffer; 647 648 /* If this is the first line, check for a UTF-8 BOM and skip it. */ 649 if (ebuf->floc.lineno == 1 && line[0] == (char)0xEF 650 && line[1] == (char)0xBB && line[2] == (char)0xBF) 651 { 652 line += 3; 653 if (ISDB(DB_BASIC)) 654 { 655 if (ebuf->floc.filenm) 656 printf (_("Skipping UTF-8 BOM in makefile '%s'\n"), 657 ebuf->floc.filenm); 658 else 659 printf (_("Skipping UTF-8 BOM in makefile buffer\n")); 660 } 661 } 662 624 663 /* If this line is empty, skip it. */ 625 line = ebuf->buffer;626 664 if (line[0] == '\0') 627 665 continue; … … 630 668 631 669 /* Check for a shell command line first. 632 If it is not one, we can stop treating tabspecially. */670 If it is not one, we can stop treating cmd_prefix specially. */ 633 671 if (line[0] == cmd_prefix) 634 { 635 if (no_targets) 636 /* Ignore the commands in a rule with no targets. */ 637 continue; 638 639 /* If there is no preceding rule line, don't treat this line 640 as a command, even though it begins with a recipe prefix. 641 SunOS 4 make appears to behave this way. */ 642 643 if (filenames != 0) 644 { 645 if (ignoring) 646 /* Yep, this is a shell command, and we don't care. */ 647 continue; 648 649 /* Append this command line to the line being accumulated. 650 Strip command prefix chars that appear after newlines. */ 651 if (commands_idx == 0) 652 cmds_started = ebuf->floc.lineno; 653 654 if (linelen + commands_idx > commands_len) 655 { 656 commands_len = (linelen + commands_idx) * 2; 657 commands = xrealloc (commands, commands_len); 658 } 659 p = &commands[commands_idx]; 660 p2 = line + 1; 661 while (--linelen) 672 { 673 if (no_targets) 674 /* Ignore the commands in a rule with no targets. */ 675 continue; 676 677 /* If there is no preceding rule line, don't treat this line 678 as a command, even though it begins with a recipe prefix. 679 SunOS 4 make appears to behave this way. */ 680 681 if (filenames != 0) 682 { 683 if (ignoring) 684 /* Yep, this is a shell command, and we don't care. */ 685 continue; 686 687 if (commands_idx == 0) 688 cmds_started = ebuf->floc.lineno; 689 690 /* Append this command line to the line being accumulated. 691 Skip the initial command prefix character. */ 692 if (linelen + commands_idx > commands_len) 662 693 { 663 ++commands_idx; 664 *(p++) = *p2; 665 if (p2[0] == '\n' && p2[1] == cmd_prefix) 666 { 667 ++p2; 668 --linelen; 669 } 670 ++p2; 694 commands_len = (linelen + commands_idx) * 2; 695 commands = xrealloc (commands, commands_len); 671 696 } 672 *p = '\n';673 ++commands_idx;674 675 676 677 697 memcpy (&commands[commands_idx], line + 1, linelen - 1); 698 commands_idx += linelen - 1; 699 commands[commands_idx++] = '\n'; 700 continue; 701 } 702 } 678 703 679 704 /* This line is not a shell command line. Don't worry about whitespace. … … 682 707 683 708 if (collapsed_length < linelen+1) 684 { 685 collapsed_length = linelen+1; 686 if (collapsed) 687 free (collapsed); 709 { 710 collapsed_length = linelen+1; 711 free (collapsed); 688 712 /* Don't need xrealloc: we don't need to preserve the content. */ 689 690 713 collapsed = xmalloc (collapsed_length); 714 } 691 715 strcpy (collapsed, line); 692 716 /* Collapse continuation lines. */ … … 696 720 /* Get rid if starting space (including formfeed, vtab, etc.) */ 697 721 p = collapsed; 698 while (isspace ((unsigned char)*p)) 699 ++p; 722 NEXT_TOKEN (p); 700 723 701 724 /* See if this is a variable assignment. We need to do this early, to 702 725 allow variables with names like 'ifdef', 'export', 'private', etc. */ 703 p = parse_var_assignment (p, &vmod);726 p = parse_var_assignment (p, &vmod); 704 727 if (vmod.assign_v) 705 728 { … … 708 731 709 732 /* If we're ignoring then we're done now. */ 710 733 if (ignoring) 711 734 { 712 735 if (vmod.define_v) … … 715 738 } 716 739 740 /* Variable assignment ends the previous rule. */ 741 record_waiting_files (); 742 717 743 if (vmod.undefine_v) 718 744 { 719 745 do_undefine (p, origin, ebuf); 720 721 /* This line has been dealt with. */ 722 goto rule_complete; 746 continue; 723 747 } 724 748 else if (vmod.define_v) … … 735 759 736 760 /* This line has been dealt with. */ 737 goto rule_complete;761 continue; 738 762 } 739 763 740 764 /* If this line is completely empty, ignore it. */ 741 765 if (*p == '\0') 742 766 continue; 743 767 744 768 p2 = end_of_token (p); 745 769 wlen = p2 - p; 746 p2 = next_token(p2);770 NEXT_TOKEN (p2); 747 771 748 772 /* If we're in an ignored define, skip this line (but maybe get out). */ 749 773 if (in_ignored_define) 750 774 { 751 775 /* See if this is an endef line (plus optional comment). */ 752 if (word1eq ("endef") && (*p2 == '\0' || *p2 == '#'))776 if (word1eq ("endef") && STOP_SET (*p2, MAP_COMMENT|MAP_NUL)) 753 777 in_ignored_define = 0; 754 778 755 756 779 continue; 780 } 757 781 758 782 /* Check for conditional state changes. */ … … 762 786 { 763 787 if (i == -1) 764 fatal (fstart, _("invalid syntax in conditional"));788 O (fatal, fstart, _("invalid syntax in conditional")); 765 789 766 790 ignoring = i; … … 771 795 /* Nothing to see here... move along. */ 772 796 if (ignoring) 773 797 continue; 774 798 775 799 /* Manage the "export" keyword used outside of variable assignment 776 800 as well as "unexport". */ 777 801 if (word1eq ("export") || word1eq ("unexport")) 778 802 { 779 803 int exporting = *p == 'u' ? 0 : 1; 780 804 805 /* Export/unexport ends the previous rule. */ 806 record_waiting_files (); 807 781 808 /* (un)export by itself causes everything to be (un)exported. */ 782 809 if (*p2 == '\0') 783 810 export_all_variables = exporting; 784 811 else … … 797 824 struct variable *v = lookup_variable (p, l); 798 825 if (v == 0) 799 v = define_variable_ loc(p, l, "", o_file, 0, fstart);826 v = define_variable_global (p, l, "", o_file, 0, fstart); 800 827 v->export = exporting ? v_export : v_noexport; 801 828 } … … 803 830 free (ap); 804 831 } 805 goto rule_complete;806 832 continue; 833 } 807 834 808 835 /* Handle the special syntax for vpath. */ 809 836 if (word1eq ("vpath")) 810 837 { 811 838 const char *cp; 812 char *vpat; 813 unsigned int l; 814 cp = variable_expand (p2); 815 p = find_next_token (&cp, &l); 816 if (p != 0) 817 { 818 vpat = xstrndup (p, l); 819 p = find_next_token (&cp, &l); 820 /* No searchpath means remove all previous 821 selective VPATH's with the same pattern. */ 822 } 823 else 824 /* No pattern means remove all previous selective VPATH's. */ 825 vpat = 0; 826 construct_vpath_list (vpat, p); 827 if (vpat != 0) 828 free (vpat); 829 830 goto rule_complete; 831 } 839 char *vpat; 840 unsigned int l; 841 842 /* vpath ends the previous rule. */ 843 record_waiting_files (); 844 845 cp = variable_expand (p2); 846 p = find_next_token (&cp, &l); 847 if (p != 0) 848 { 849 vpat = xstrndup (p, l); 850 p = find_next_token (&cp, &l); 851 /* No searchpath means remove all previous 852 selective VPATH's with the same pattern. */ 853 } 854 else 855 /* No pattern means remove all previous selective VPATH's. */ 856 vpat = 0; 857 construct_vpath_list (vpat, p); 858 free (vpat); 859 860 continue; 861 } 832 862 833 863 /* Handle include and variants. */ 834 864 if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude")) 835 836 /* We have found an `include' line specifying a nested837 838 865 { 866 /* We have found an 'include' line specifying a nested 867 makefile to be read at this point. */ 868 struct conditionals *save; 839 869 struct conditionals new_conditionals; 840 struct nameseq *files; 841 /* "-include" (vs "include") says no error if the file does not 842 exist. "sinclude" is an alias for this from SGI. */ 843 int noerror = (p[0] != 'i'); 844 845 p = allocated_variable_expand (p2); 870 struct nameseq *files; 871 /* "-include" (vs "include") says no error if the file does not 872 exist. "sinclude" is an alias for this from SGI. */ 873 int noerror = (p[0] != 'i'); 874 875 /* Include ends the previous rule. */ 876 record_waiting_files (); 877 878 p = allocated_variable_expand (p2); 846 879 847 880 /* If no filenames, it's a no-op. */ 848 881 if (*p == '\0') 849 882 { 850 883 free (p); … … 852 885 } 853 886 854 855 856 files = PARSE_FILE_SEQ (&p2, struct nameseq, '\0', NULL,887 /* Parse the list of file names. Don't expand archive references! */ 888 p2 = p; 889 files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL, 857 890 PARSEFS_NOAR); 858 free (p); 859 860 /* Save the state of conditionals and start 861 the included makefile with a clean slate. */ 862 save = install_conditionals (&new_conditionals); 863 864 /* Record the rules that are waiting so they will determine 865 the default goal before those in the included makefile. */ 866 record_waiting_files (); 867 868 /* Read each included makefile. */ 869 while (files != 0) 870 { 871 struct nameseq *next = files->next; 872 const char *name = files->name; 891 free (p); 892 893 /* Save the state of conditionals and start 894 the included makefile with a clean slate. */ 895 save = install_conditionals (&new_conditionals); 896 897 /* Record the rules that are waiting so they will determine 898 the default goal before those in the included makefile. */ 899 record_waiting_files (); 900 901 /* Read each included makefile. */ 902 while (files != 0) 903 { 904 struct nameseq *next = files->next; 905 int flags = (RM_INCLUDED | RM_NO_TILDE 906 | (noerror ? RM_DONTCARE : 0) 907 | (set_default ? 0 : RM_NO_DEFAULT_GOAL)); 908 909 struct goaldep *d = eval_makefile (files->name, flags); 910 911 if (errno) 912 { 913 d->error = (unsigned short)errno; 914 d->floc = *fstart; 915 } 916 917 free_ns (files); 918 files = next; 919 } 920 921 /* Restore conditional state. */ 922 restore_conditionals (save); 923 924 continue; 925 } 926 927 /* Handle the load operations. */ 928 if (word1eq ("load") || word1eq ("-load")) 929 { 930 /* A 'load' line specifies a dynamic object to load. */ 931 struct nameseq *files; 932 int noerror = (p[0] == '-'); 933 934 /* Load ends the previous rule. */ 935 record_waiting_files (); 936 937 p = allocated_variable_expand (p2); 938 939 /* If no filenames, it's a no-op. */ 940 if (*p == '\0') 941 { 942 free (p); 943 continue; 944 } 945 946 /* Parse the list of file names. 947 Don't expand archive references or strip "./" */ 948 p2 = p; 949 files = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_NUL, NULL, 950 PARSEFS_NOAR); 951 free (p); 952 953 /* Load each file. */ 954 while (files != 0) 955 { 956 struct nameseq *next = files->next; 957 const char *name = files->name; 958 struct goaldep *deps; 873 959 int r; 874 960 875 free_ns (files); 876 files = next; 877 878 r = eval_makefile (name, 879 (RM_INCLUDED | RM_NO_TILDE 880 | (noerror ? RM_DONTCARE : 0) 881 | (set_default ? 0 : RM_NO_DEFAULT_GOAL))); 882 if (!r && !noerror) 883 error (fstart, "%s: %s", name, strerror (errno)); 884 } 885 886 /* Restore conditional state. */ 887 restore_conditionals (save); 888 889 goto rule_complete; 890 } 961 /* Load the file. 0 means failure. */ 962 r = load_file (&ebuf->floc, &name, noerror); 963 if (! r && ! noerror) 964 OS (fatal, &ebuf->floc, _("%s: failed to load"), name); 965 966 free_ns (files); 967 files = next; 968 969 /* Return of -1 means a special load: don't rebuild it. */ 970 if (r == -1) 971 continue; 972 973 /* It succeeded, so add it to the list "to be rebuilt". */ 974 deps = alloc_goaldep (); 975 deps->next = read_files; 976 read_files = deps; 977 deps->file = lookup_file (name); 978 if (deps->file == 0) 979 deps->file = enter_file (name); 980 deps->file->loaded = 1; 981 } 982 983 continue; 984 } 891 985 892 986 /* This line starts with a tab but was not caught above because there … … 894 988 variable definition. But now we know it is definitely lossage. */ 895 989 if (line[0] == cmd_prefix) 896 fatal(fstart, _("recipe commences before first target"));990 O (fatal, fstart, _("recipe commences before first target")); 897 991 898 992 /* This line describes some target files. This is complicated by 899 993 the existence of target-specific variables, because we can't 900 994 expand the entire line until we know if we have one or not. So 901 we expand the line word by word until we find the first `:',995 we expand the line word by word until we find the first ':', 902 996 then check to see if it's a target-specific variable. 903 997 904 In this algorithm, `lb_next' will point to the beginning of the905 unexpanded parts of the input buffer, while `p2' points to the998 In this algorithm, 'lb_next' will point to the beginning of the 999 unexpanded parts of the input buffer, while 'p2' points to the 906 1000 parts of the expanded buffer we haven't searched yet. */ 907 1001 … … 920 1014 /* Search the line for an unquoted ; that is not after an 921 1015 unquoted #. */ 922 cmdleft = find_char_unquote (line, ';', '#', 0, 1);1016 cmdleft = find_char_unquote (line, MAP_SEMI|MAP_COMMENT|MAP_VARIABLE); 923 1017 if (cmdleft != 0 && *cmdleft == '#') 924 1018 { … … 938 1032 beginning, expanding as we go, and looking for "interesting" 939 1033 chars. The first word is always expandable. */ 940 wtype = get_next_mword (line, NULL, &lb_next, &wlen);1034 wtype = get_next_mword (line, NULL, &lb_next, &wlen); 941 1035 switch (wtype) 942 1036 { 943 1037 case w_eol: 944 1038 if (cmdleft != 0) 945 fatal(fstart, _("missing rule before recipe"));1039 O (fatal, fstart, _("missing rule before recipe")); 946 1040 /* This line contained something but turned out to be nothing 947 1041 but whitespace (a comment?). */ … … 959 1053 } 960 1054 961 p2 = variable_expand_string (NULL, lb_next, wlen);1055 p2 = variable_expand_string (NULL, lb_next, wlen); 962 1056 963 1057 while (1) … … 967 1061 { 968 1062 /* Look for a semicolon in the expanded line. */ 969 cmdleft = find_char_unquote (p2, ';', 0, 0, 0);1063 cmdleft = find_char_unquote (p2, MAP_SEMI); 970 1064 971 1065 if (cmdleft != 0) … … 973 1067 unsigned long p2_off = p2 - variable_buffer; 974 1068 unsigned long cmd_off = cmdleft - variable_buffer; 975 char *pend = p2 + strlen (p2);1069 char *pend = p2 + strlen (p2); 976 1070 977 1071 /* Append any remnants of lb, then cut the line short … … 983 1077 and into a command script. However, the old parser 984 1078 expanded the whole line, so we continue that for 985 backwards-compatib lity. Also, it wouldn't be1079 backwards-compatibility. Also, it wouldn't be 986 1080 entirely consistent, since we do an unconditional 987 1081 expand below once we know we don't have a 988 1082 target-specific variable. */ 989 (void)variable_expand_string (pend, lb_next, (long)-1);990 lb_next += strlen (lb_next);1083 (void)variable_expand_string (pend, lb_next, (long)-1); 1084 lb_next += strlen (lb_next); 991 1085 p2 = variable_buffer + p2_off; 992 1086 cmdleft = variable_buffer + cmd_off + 1; … … 994 1088 } 995 1089 996 colonp = find_char_unquote (p2, ':', 0, 0, 0);1090 colonp = find_char_unquote (p2, MAP_COLON); 997 1091 #ifdef HAVE_DOS_PATHS 998 1092 /* The drive spec brain-damage strikes again... */ … … 1003 1097 colonp > p2 && isalpha ((unsigned char)colonp[-1]) && 1004 1098 (colonp == p2 + 1 || strchr (" \t(", colonp[-2]) != 0)) 1005 colonp = find_char_unquote (colonp + 1, ':', 0, 0, 0);1099 colonp = find_char_unquote (colonp + 1, MAP_COLON); 1006 1100 #endif 1007 1101 if (colonp != 0) 1008 1102 break; 1009 1103 1010 wtype = get_next_mword (lb_next, NULL, &lb_next, &wlen);1104 wtype = get_next_mword (lb_next, NULL, &lb_next, &wlen); 1011 1105 if (wtype == w_eol) 1012 1106 break; 1013 1107 1014 p2 += strlen (p2);1108 p2 += strlen (p2); 1015 1109 *(p2++) = ' '; 1016 p2 = variable_expand_string (p2, lb_next, wlen);1110 p2 = variable_expand_string (p2, lb_next, wlen); 1017 1111 /* We don't need to worry about cmdleft here, because if it was 1018 1112 found in the variable_buffer the entire buffer has already … … 1027 1121 if (wtype == w_eol) 1028 1122 { 1029 if (*p2 != '\0') 1030 /* There's no need to be ivory-tower about this: check for 1031 one of the most common bugs found in makefiles... */ 1032 fatal (fstart, _("missing separator%s"), 1033 (cmd_prefix == '\t' && !strneq(line, " ", 8)) 1034 ? "" : _(" (did you mean TAB instead of 8 spaces?)")); 1035 continue; 1123 if (*p2 == '\0') 1124 continue; 1125 1126 /* There's no need to be ivory-tower about this: check for 1127 one of the most common bugs found in makefiles... */ 1128 if (cmd_prefix == '\t' && strneq (line, " ", 8)) 1129 O (fatal, fstart, _("missing separator (did you mean TAB instead of 8 spaces?)")); 1130 else 1131 O (fatal, fstart, _("missing separator")); 1036 1132 } 1037 1133 1038 1134 /* Make the colon the end-of-string so we know where to stop 1039 looking for targets. */1135 looking for targets. Start there again once we're done. */ 1040 1136 *colonp = '\0'; 1041 filenames = PARSE_FILE_SEQ (&p2, struct nameseq, '\0', NULL, 0); 1042 *p2 = ':'; 1137 filenames = PARSE_SIMPLE_SEQ (&p2, struct nameseq); 1138 *colonp = ':'; 1139 p2 = colonp; 1043 1140 1044 1141 if (!filenames) … … 1077 1174 if (semip) 1078 1175 { 1079 unsigned int l = p - variable_buffer;1176 unsigned int l = p2 - variable_buffer; 1080 1177 *(--semip) = ';'; 1081 1178 collapse_continuations (semip); 1082 1179 variable_buffer_output (p2 + strlen (p2), 1083 1180 semip, strlen (semip)+1); 1084 p = variable_buffer + l;1181 p2 = variable_buffer + l; 1085 1182 } 1086 1183 record_target_var (filenames, p2, … … 1093 1190 /* This is a normal target, _not_ a target-specific variable. 1094 1191 Unquote any = in the dependency list. */ 1095 find_char_unquote (lb_next, '=', 0, 0, 0); 1192 find_char_unquote (lb_next, MAP_EQUALS); 1193 1194 /* Remember the command prefix for this target. */ 1195 prefix = cmd_prefix; 1096 1196 1097 1197 /* We have some targets, so don't ignore the following commands. */ … … 1108 1208 if (cmdleft == 0) 1109 1209 { 1110 cmdleft = find_char_unquote (p2, ';', 0, 0, 0);1210 cmdleft = find_char_unquote (p2, MAP_SEMI); 1111 1211 if (cmdleft != 0) 1112 1212 *(cmdleft++) = '\0'; … … 1114 1214 } 1115 1215 1116 /* Is this a static pattern rule: `target: %targ: %dep; ...'? */1216 /* Is this a static pattern rule: 'target: %targ: %dep; ...'? */ 1117 1217 p = strchr (p2, ':'); 1118 1218 while (p != 0 && p[-1] == '\\') … … 1140 1240 OR a space around the :. 1141 1241 */ 1142 if (p && !(isspace ((unsigned char)p[1]) || !p[1] 1143 || isspace ((unsigned char)p[-1]))) 1242 if (p && !(ISSPACE (p[1]) || !p[1] || ISSPACE (p[-1]))) 1144 1243 p = 0; 1145 1244 #endif … … 1162 1261 { 1163 1262 struct nameseq *target; 1164 target = PARSE_FILE_SEQ (&p2, struct nameseq, ':', NULL,1263 target = PARSE_FILE_SEQ (&p2, struct nameseq, MAP_COLON, NULL, 1165 1264 PARSEFS_NOGLOB); 1166 1265 ++p2; 1167 1266 if (target == 0) 1168 fatal (fstart, _("missing target pattern"));1267 O (fatal, fstart, _("missing target pattern")); 1169 1268 else if (target->next != 0) 1170 fatal (fstart, _("multiple target patterns"));1269 O (fatal, fstart, _("multiple target patterns")); 1171 1270 pattern_percent = find_percent_cached (&target->name); 1172 1271 pattern = target->name; 1173 1272 if (pattern_percent == 0) 1174 fatal (fstart, _("target pattern contains no `%%'"));1273 O (fatal, fstart, _("target pattern contains no '%%'")); 1175 1274 free_ns (target); 1176 1275 } … … 1225 1324 if (set_default && default_goal_var->value[0] == '\0') 1226 1325 { 1227 const char *name;1228 1326 struct dep *d; 1229 1327 struct nameseq *t = filenames; … … 1232 1330 { 1233 1331 int reject = 0; 1234 name = t->name;1332 const char *name = t->name; 1235 1333 1236 1334 /* We have nothing to do if this is an implicit rule. */ … … 1238 1336 break; 1239 1337 1240 /* See if this target's name does not start with a `.',1338 /* See if this target's name does not start with a '.', 1241 1339 unless it contains a slash. */ 1242 1340 if (*name == '.' && strchr (name, '/') == 0 … … 1287 1385 1288 1386 /* We get here except in the case that we just read a rule line. 1289 Record now the last rule we read, so following spurious 1290 commands are properly diagnosed. */ 1291 rule_complete: 1387 Record now the last rule we read, so following spurious 1388 commands are properly diagnosed. */ 1292 1389 record_waiting_files (); 1293 1390 } 1294 1391 1295 #undef 1392 #undef word1eq 1296 1393 1297 1394 if (conditionals->if_cmds) 1298 fatal (fstart, _("missing `endif'"));1395 O (fatal, fstart, _("missing 'endif'")); 1299 1396 1300 1397 /* At eof, record the last rule. */ 1301 1398 record_waiting_files (); 1302 1399 1303 if (collapsed) 1304 free (collapsed); 1400 free (collapsed); 1305 1401 free (commands); 1306 1402 } … … 1316 1412 char *comment; 1317 1413 1318 comment = find_char_unquote (line, '#', 0, 0, 0);1414 comment = find_char_unquote (line, MAP_COMMENT); 1319 1415 1320 1416 if (comment != 0) … … 1323 1419 } 1324 1420 1325 /* Execute a `undefine' directive.1421 /* Execute a 'undefine' directive. 1326 1422 The undefine line has already been read, and NAME is the name of 1327 1423 the variable to be undefined. */ … … 1336 1432 name = next_token (var); 1337 1433 if (*name == '\0') 1338 fatal (&ebuf->floc, _("empty variable name"));1434 O (fatal, &ebuf->floc, _("empty variable name")); 1339 1435 p = name + strlen (name) - 1; 1340 while (p > name && isblank ((unsigned char)*p))1436 while (p > name && ISBLANK (*p)) 1341 1437 --p; 1342 1438 p[1] = '\0'; … … 1346 1442 } 1347 1443 1348 /* Execute a `define' directive.1444 /* Execute a 'define' directive. 1349 1445 The first line has already been read, and NAME is the name of 1350 1446 the variable to be defined. The following lines remain to be read. */ … … 1354 1450 { 1355 1451 struct variable *v; 1356 enum variable_flavor flavor;1357 structfloc defstart;1452 struct variable var; 1453 floc defstart; 1358 1454 int nlevels = 1; 1359 1455 unsigned int length = 100; 1360 1456 char *definition = xmalloc (length); 1361 1457 unsigned int idx = 0; 1362 char *p, * var;1458 char *p, *n; 1363 1459 1364 1460 defstart = ebuf->floc; 1365 1461 1366 p = parse_variable_definition (name, & flavor);1462 p = parse_variable_definition (name, &var); 1367 1463 if (p == NULL) 1368 1464 /* No assignment token, so assume recursive. */ 1369 flavor = f_recursive;1465 var.flavor = f_recursive; 1370 1466 else 1371 1467 { 1372 if ( *(next_token (p))!= '\0')1373 error (&defstart, _("extraneous text after `define' directive"));1468 if (var.value[0] != '\0') 1469 O (error, &defstart, _("extraneous text after 'define' directive")); 1374 1470 1375 1471 /* Chop the string before the assignment token to get the name. */ 1376 p[flavor == f_recursive ? -1 : -2] = '\0';1472 var.name[var.length] = '\0'; 1377 1473 } 1378 1474 1379 1475 /* Expand the variable name and find the beginning (NAME) and end. */ 1380 var= allocated_variable_expand (name);1381 name = next_token ( var);1382 if ( *name== '\0')1383 fatal (&defstart, _("empty variable name"));1476 n = allocated_variable_expand (name); 1477 name = next_token (n); 1478 if (name[0] == '\0') 1479 O (fatal, &defstart, _("empty variable name")); 1384 1480 p = name + strlen (name) - 1; 1385 while (p > name && isblank ((unsigned char)*p))1481 while (p > name && ISBLANK (*p)) 1386 1482 --p; 1387 1483 p[1] = '\0'; … … 1396 1492 /* If there is nothing left to be eval'd, there's no 'endef'!! */ 1397 1493 if (nlines < 0) 1398 fatal (&defstart, _("missing `endef', unterminated `define'"));1494 O (fatal, &defstart, _("missing 'endef', unterminated 'define'")); 1399 1495 1400 1496 ebuf->floc.lineno += nlines; … … 1411 1507 1412 1508 /* If this is another 'define', increment the level count. */ 1413 if ((len == 6 || (len > 6 && isblank ((unsigned char)p[6])))1509 if ((len == 6 || (len > 6 && ISBLANK (p[6]))) 1414 1510 && strneq (p, "define", 6)) 1415 1511 ++nlevels; … … 1417 1513 /* If this is an 'endef', decrement the count. If it's now 0, 1418 1514 we've found the last one. */ 1419 else if ((len == 5 || (len > 5 && isblank ((unsigned char)p[5])))1515 else if ((len == 5 || (len > 5 && ISBLANK (p[5]))) 1420 1516 && strneq (p, "endef", 5)) 1421 1517 { … … 1423 1519 remove_comments (p); 1424 1520 if (*(next_token (p)) != '\0') 1425 error (&ebuf->floc,1426 _("extraneous text after `endef' directive"));1521 O (error, &ebuf->floc, 1522 _("extraneous text after 'endef' directive")); 1427 1523 1428 1524 if (--nlevels == 0) … … 1451 1547 definition[idx - 1] = '\0'; 1452 1548 1453 v = do_variable_definition (&defstart, name, definition, origin, flavor, 0); 1549 v = do_variable_definition (&defstart, name, 1550 definition, origin, var.flavor, 0); 1454 1551 free (definition); 1455 free ( var);1552 free (n); 1456 1553 return (v); 1457 1554 } … … 1471 1568 1472 1569 static int 1473 conditional_line (char *line, int len, const structfloc *flocp)1570 conditional_line (char *line, int len, const floc *flocp) 1474 1571 { 1475 c har *cmdname;1572 const char *cmdname; 1476 1573 enum { c_ifdef, c_ifndef, c_ifeq, c_ifneq, c_else, c_endif } cmdtype; 1477 1574 unsigned int i; … … 1479 1576 1480 1577 /* Compare a word, both length and contents. */ 1481 #define word1eq(s) (len == sizeof(s)-1 && strneq (s, line, sizeof(s)-1))1482 #define 1578 #define word1eq(s) (len == CSTRLEN (s) && strneq (s, line, CSTRLEN (s))) 1579 #define chkword(s, t) if (word1eq (s)) { cmdtype = (t); cmdname = (s); } 1483 1580 1484 1581 /* Make sure this line is a conditional. */ … … 1493 1590 1494 1591 /* Found one: skip past it and any whitespace after it. */ 1495 line = next_token (line + len); 1496 1497 #define EXTRANEOUS() error (flocp, _("Extraneous text after `%s' directive"), cmdname) 1592 line += len; 1593 NEXT_TOKEN (line); 1594 1595 #define EXTRATEXT() OS (error, flocp, _("extraneous text after '%s' directive"), cmdname) 1596 #define EXTRACMD() OS (fatal, flocp, _("extraneous '%s'"), cmdname) 1498 1597 1499 1598 /* An 'endif' cannot contain extra text, and reduces the if-depth by 1 */ … … 1501 1600 { 1502 1601 if (*line != '\0') 1503 EXTRANEOUS();1602 EXTRATEXT (); 1504 1603 1505 1604 if (!conditionals->if_cmds) 1506 fatal (flocp, _("extraneous `%s'"), cmdname);1605 EXTRACMD (); 1507 1606 1508 1607 --conditionals->if_cmds; … … 1518 1617 1519 1618 if (!conditionals->if_cmds) 1520 fatal (flocp, _("extraneous `%s'"), cmdname);1619 EXTRACMD (); 1521 1620 1522 1621 o = conditionals->if_cmds - 1; 1523 1622 1524 1623 if (conditionals->seen_else[o]) 1525 fatal (flocp, _("only one `else' per conditional"));1624 O (fatal, flocp, _("only one 'else' per conditional")); 1526 1625 1527 1626 /* Change the state of ignorance. */ … … 1549 1648 1550 1649 /* Find the length of the next word. */ 1551 for (p = line+1; *p != '\0' && !isspace ((unsigned char)*p); ++p)1650 for (p = line+1; ! STOP_SET (*p, MAP_SPACE|MAP_NUL); ++p) 1552 1651 ; 1553 1652 len = p - line; 1554 1653 1555 1654 /* If it's 'else' or 'endif' or an illegal conditional, fail. */ 1556 if (word1eq ("else") || word1eq("endif")1655 if (word1eq ("else") || word1eq ("endif") 1557 1656 || conditional_line (line, len, flocp) < 0) 1558 EXTRANEOUS();1657 EXTRATEXT (); 1559 1658 else 1560 1659 { … … 1586 1685 } 1587 1686 1588 /* Record that we have seen an `if...' but no `else' so far. */1687 /* Record that we have seen an 'if...' but no 'else' so far. */ 1589 1688 conditionals->seen_else[o] = 0; 1590 1689 … … 1593 1692 if (conditionals->ignoring[i]) 1594 1693 { 1595 1596 1597 1598 1599 1694 /* We are already ignoring, so just push a level to match the next 1695 "else" or "endif", and keep ignoring. We don't want to expand 1696 variables in the condition. */ 1697 conditionals->ignoring[o] = 1; 1698 return 1; 1600 1699 } 1601 1700 … … 1613 1712 p = end_of_token (var); 1614 1713 i = p - var; 1615 p = next_token(p);1714 NEXT_TOKEN (p); 1616 1715 if (*p != '\0') 1617 1716 return -1; 1618 1717 1619 1718 var[i] = '\0'; … … 1633 1732 1634 1733 if (termin != ',' && termin != '"' && termin != '\'') 1635 1734 return -1; 1636 1735 1637 1736 s1 = ++line; 1638 1737 /* Find the end of the first string. */ 1639 1738 if (termin == ',') 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1739 { 1740 int count = 0; 1741 for (; *line != '\0'; ++line) 1742 if (*line == '(') 1743 ++count; 1744 else if (*line == ')') 1745 --count; 1746 else if (*line == ',' && count <= 0) 1747 break; 1748 } 1650 1749 else 1651 1652 1750 while (*line != '\0' && *line != termin) 1751 ++line; 1653 1752 1654 1753 if (*line == '\0') 1655 1754 return -1; 1656 1755 1657 1756 if (termin == ',') 1658 1659 1660 1661 while (isblank ((unsigned char)p[-1]))1662 1663 1664 1757 { 1758 /* Strip blanks after the first string. */ 1759 char *p = line++; 1760 while (ISBLANK (p[-1])) 1761 --p; 1762 *p = '\0'; 1763 } 1665 1764 else 1666 1765 *line++ = '\0'; 1667 1766 1668 1767 s2 = variable_expand (s1); 1669 1768 /* We must allocate a new copy of the expanded string because 1670 1769 variable_expand re-uses the same buffer. */ 1671 1770 l = strlen (s2); 1672 1771 s1 = alloca (l + 1); … … 1674 1773 1675 1774 if (termin != ',') 1676 1677 line = next_token(line);1775 /* Find the start of the second string. */ 1776 NEXT_TOKEN (line); 1678 1777 1679 1778 termin = termin == ',' ? ')' : *line; 1680 1779 if (termin != ')' && termin != '"' && termin != '\'') 1681 1780 return -1; 1682 1781 1683 1782 /* Find the end of the second string. */ 1684 1783 if (termin == ')') 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1784 { 1785 int count = 0; 1786 s2 = next_token (line); 1787 for (line = s2; *line != '\0'; ++line) 1788 { 1789 if (*line == '(') 1790 ++count; 1791 else if (*line == ')') 1792 { 1793 if (count <= 0) 1794 break; 1795 else 1796 --count; 1797 } 1798 } 1799 } 1701 1800 else 1702 1703 1704 1705 1706 1707 1801 { 1802 ++line; 1803 s2 = line; 1804 while (*line != '\0' && *line != termin) 1805 ++line; 1806 } 1708 1807 1709 1808 if (*line == '\0') 1710 1711 1712 * line= '\0';1713 line = next_token (++line);1809 return -1; 1810 1811 *(line++) = '\0'; 1812 NEXT_TOKEN (line); 1714 1813 if (*line != '\0') 1715 EXTRANEOUS();1814 EXTRATEXT (); 1716 1815 1717 1816 s2 = variable_expand (s2); … … 1741 1840 record_target_var (struct nameseq *filenames, char *defn, 1742 1841 enum variable_origin origin, struct vmodifiers *vmod, 1743 const structfloc *flocp)1842 const floc *flocp) 1744 1843 { 1745 1844 struct nameseq *nextf; … … 1755 1854 struct variable *v; 1756 1855 const char *name = filenames->name; 1757 const char *fname;1758 1856 const char *percent; 1759 1857 struct pattern_var *p; … … 1780 1878 else 1781 1879 v->value = xstrdup (v->value); 1782 1783 fname = p->target;1784 1880 } 1785 1881 else … … 1798 1894 1799 1895 initialize_file_variables (f, 1); 1800 fname = f->name;1801 1896 1802 1897 current_variable_set_list = f->variables; 1803 1898 v = try_variable_definition (flocp, defn, origin, 1); 1804 1899 if (!v) 1805 fatal (flocp, _("Malformed target-specific variable definition"));1900 O (fatal, flocp, _("Malformed target-specific variable definition")); 1806 1901 current_variable_set_list = global; 1807 1902 } … … 1817 1912 { 1818 1913 struct variable *gv; 1819 int len = strlen (v->name);1914 int len = strlen (v->name); 1820 1915 1821 1916 gv = lookup_variable (v->name, len); 1822 if (gv && (gv->origin == o_env_override || gv->origin == o_command)) 1917 if (gv && v != gv 1918 && (gv->origin == o_env_override || gv->origin == o_command)) 1823 1919 { 1824 if (v->value != 0) 1825 free (v->value); 1920 free (v->value); 1826 1921 v->value = xstrdup (gv->value); 1827 1922 v->origin = gv->origin; … … 1838 1933 by COMMANDS and COMMANDS_IDX, coming from FILENAME:COMMANDS_STARTED. 1839 1934 TWO_COLON is nonzero if a double colon was used. 1840 If not nil, PATTERN is the `%' pattern to make this1935 If not nil, PATTERN is the '%' pattern to make this 1841 1936 a static pattern rule, and PATTERN_PERCENT is a pointer 1842 to the `%' within it.1937 to the '%' within it. 1843 1938 1844 1939 The links of FILENAMES are freed, and so are any names in it … … 1850 1945 unsigned int cmds_started, char *commands, 1851 1946 unsigned int commands_idx, int two_colon, 1852 c onst struct floc *flocp)1947 char prefix, const floc *flocp) 1853 1948 { 1854 1949 struct commands *cmds; … … 1862 1957 See Savannah bug # 12124. */ 1863 1958 if (snapped_deps) 1864 fatal (flocp, _("prerequisites cannot be defined in recipes"));1959 O (fatal, flocp, _("prerequisites cannot be defined in recipes")); 1865 1960 1866 1961 /* Determine if this is a pattern rule or not. */ … … 1874 1969 cmds->fileinfo.filenm = flocp->filenm; 1875 1970 cmds->fileinfo.lineno = cmds_started; 1971 cmds->fileinfo.offset = 0; 1876 1972 cmds->commands = xstrndup (commands, commands_idx); 1877 1973 cmds->command_lines = 0; 1974 cmds->recipe_prefix = prefix; 1878 1975 } 1879 1976 else … … 1884 1981 if (depstr == 0) 1885 1982 deps = 0; 1886 else if (second_expansion && strchr (depstr, '$'))1887 {1888 deps = alloc_dep ();1889 deps->name = depstr;1890 deps->need_2nd_expansion = 1;1891 deps->staticpattern = pattern != 0;1892 }1893 1983 else 1894 1984 { 1895 deps = split_prereqs (depstr); 1896 free (depstr); 1897 1898 /* We'll enter static pattern prereqs later when we have the stem. We 1899 don't want to enter pattern rules at all so that we don't think that 1900 they ought to exist (make manual "Implicit Rule Search Algorithm", 1901 item 5c). */ 1902 if (! pattern && ! implicit_percent) 1903 deps = enter_prereqs (deps, NULL); 1985 depstr = unescape_char (depstr, ':'); 1986 if (second_expansion && strchr (depstr, '$')) 1987 { 1988 deps = alloc_dep (); 1989 deps->name = depstr; 1990 deps->need_2nd_expansion = 1; 1991 deps->staticpattern = pattern != 0; 1992 } 1993 else 1994 { 1995 deps = split_prereqs (depstr); 1996 free (depstr); 1997 1998 /* We'll enter static pattern prereqs later when we have the stem. 1999 We don't want to enter pattern rules at all so that we don't 2000 think that they ought to exist (make manual "Implicit Rule Search 2001 Algorithm", item 5c). */ 2002 if (! pattern && ! implicit_percent) 2003 deps = enter_prereqs (deps, NULL); 2004 } 1904 2005 } 1905 2006 … … 1915 2016 1916 2017 if (pattern != 0) 1917 fatal (flocp, _("mixed implicit and static pattern rules"));2018 O (fatal, flocp, _("mixed implicit and static pattern rules")); 1918 2019 1919 2020 /* Count the targets to create an array of target names. … … 1938 2039 1939 2040 if (implicit_percent == 0) 1940 fatal (flocp, _("mixed implicit and normal rules"));1941 1942 1943 2041 O (fatal, flocp, _("mixed implicit and normal rules")); 2042 2043 targets[c] = name; 2044 target_pats[c] = implicit_percent; 1944 2045 ++c; 1945 2046 … … 1971 2072 posix_pedantic = 1; 1972 2073 define_variable_cname (".SHELLFLAGS", "-ec", o_default, 0); 2074 /* These default values are based on IEEE Std 1003.1-2008. */ 2075 define_variable_cname ("ARFLAGS", "-rv", o_default, 0); 2076 define_variable_cname ("CC", "c99", o_default, 0); 2077 define_variable_cname ("CFLAGS", "-O", o_default, 0); 2078 define_variable_cname ("FC", "fort77", o_default, 0); 2079 define_variable_cname ("FFLAGS", "-O 1", o_default, 0); 2080 define_variable_cname ("SCCSGETFLAGS", "-s", o_default, 0); 1973 2081 } 1974 2082 else if (streq (name, ".SECONDEXPANSION")) 1975 2083 second_expansion = 1; 1976 #if !defined (WINDOWS32) && !defined(__MSDOS__) && !defined (__EMX__)2084 #if !defined (__MSDOS__) && !defined (__EMX__) 1977 2085 else if (streq (name, ".ONESHELL")) 1978 2086 one_shell = 1; … … 1980 2088 1981 2089 /* If this is a static pattern rule: 1982 `targets: target%pattern: prereq%pattern; recipe',2090 'targets: target%pattern: prereq%pattern; recipe', 1983 2091 make sure the pattern matches this target name. */ 1984 2092 if (pattern && !pattern_matches (pattern, pattern_percent, name)) 1985 error (flocp, _("target `%s' doesn't match the target pattern"), name); 2093 OS (error, flocp, 2094 _("target '%s' doesn't match the target pattern"), name); 1986 2095 else if (deps) 1987 2096 /* If there are multiple targets, copy the chain DEPS for all but the … … 1992 2101 /* Find or create an entry in the file database for this target. */ 1993 2102 if (!two_colon) 1994 { 1995 /* Single-colon. Combine this rule with the file's existing record, 1996 if any. */ 1997 f = enter_file (strcache_add (name)); 1998 if (f->double_colon) 1999 fatal (flocp, 2000 _("target file `%s' has both : and :: entries"), f->name); 2001 2002 /* If CMDS == F->CMDS, this target was listed in this rule 2003 more than once. Just give a warning since this is harmless. */ 2004 if (cmds != 0 && cmds == f->cmds) 2005 error (flocp, 2006 _("target `%s' given more than once in the same rule."), 2007 f->name); 2008 2009 /* Check for two single-colon entries both with commands. 2010 Check is_target so that we don't lose on files such as .c.o 2011 whose commands were preinitialized. */ 2012 else if (cmds != 0 && f->cmds != 0 && f->is_target) 2013 { 2014 error (&cmds->fileinfo, 2015 _("warning: overriding recipe for target `%s'"), 2103 { 2104 /* Single-colon. Combine this rule with the file's existing record, 2105 if any. */ 2106 f = enter_file (strcache_add (name)); 2107 if (f->double_colon) 2108 OS (fatal, flocp, 2109 _("target file '%s' has both : and :: entries"), f->name); 2110 2111 /* If CMDS == F->CMDS, this target was listed in this rule 2112 more than once. Just give a warning since this is harmless. */ 2113 if (cmds != 0 && cmds == f->cmds) 2114 OS (error, flocp, 2115 _("target '%s' given more than once in the same rule"), 2116 f->name); 2117 2118 /* Check for two single-colon entries both with commands. 2119 Check is_target so that we don't lose on files such as .c.o 2120 whose commands were preinitialized. */ 2121 else if (cmds != 0 && f->cmds != 0 && f->is_target) 2122 { 2123 size_t l = strlen (f->name); 2124 error (&cmds->fileinfo, l, 2125 _("warning: overriding recipe for target '%s'"), 2016 2126 f->name); 2017 error (&f->cmds->fileinfo,2018 _("warning: ignoring old recipe for target `%s'"),2127 error (&f->cmds->fileinfo, l, 2128 _("warning: ignoring old recipe for target '%s'"), 2019 2129 f->name); 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2130 } 2131 2132 /* Defining .DEFAULT with no deps or cmds clears it. */ 2133 if (f == default_file && this == 0 && cmds == 0) 2134 f->cmds = 0; 2135 if (cmds != 0) 2136 f->cmds = cmds; 2137 2138 /* Defining .SUFFIXES with no dependencies clears out the list of 2139 suffixes. */ 2140 if (f == suffix_file && this == 0) 2141 { 2032 2142 free_dep_chain (f->deps); 2033 2034 2035 2143 f->deps = 0; 2144 } 2145 } 2036 2146 else 2037 2038 2039 2040 2041 2042 2043 2044 fatal (flocp,2045 _("target file `%s' has both : and :: entries"), f->name);2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2147 { 2148 /* Double-colon. Make a new record even if there already is one. */ 2149 f = lookup_file (name); 2150 2151 /* Check for both : and :: rules. Check is_target so we don't lose 2152 on default suffix rules or makefiles. */ 2153 if (f != 0 && f->is_target && !f->double_colon) 2154 OS (fatal, flocp, 2155 _("target file '%s' has both : and :: entries"), f->name); 2156 2157 f = enter_file (strcache_add (name)); 2158 /* If there was an existing entry and it was a double-colon entry, 2159 enter_file will have returned a new one, making it the prev 2160 pointer of the old one, and setting its double_colon pointer to 2161 the first one. */ 2162 if (f->double_colon == 0) 2163 /* This is the first entry for this name, so we must set its 2164 double_colon pointer to itself. */ 2165 f->double_colon = f; 2166 2167 f->cmds = cmds; 2168 } 2059 2169 2060 2170 f->is_target = 1; 2061 2171 2062 2172 /* If this is a static pattern rule, set the stem to the part of its 2063 name that matched the `%' in the pattern, so you can use $* in the2173 name that matched the '%' in the pattern, so you can use $* in the 2064 2174 commands. If we didn't do it before, enter the prereqs now. */ 2065 2175 if (pattern) … … 2119 2229 name = filenames->name; 2120 2230 if (find_percent_cached (&name)) 2121 fatal (flocp, _("mixed implicit and normal rules")); 2231 O (error, flocp, 2232 _("*** mixed implicit and normal rules: deprecated syntax")); 2122 2233 } 2123 2234 } … … 2134 2245 2135 2246 static char * 2136 find_char_unquote (char *string, int stop1, int stop2, int blank, 2137 int ignorevars) 2247 find_char_unquote (char *string, int map) 2138 2248 { 2139 2249 unsigned int string_len = 0; 2140 2250 char *p = string; 2141 2251 2142 if (ignorevars)2143 ignorevars = '$';2252 /* Always stop on NUL. */ 2253 map |= MAP_NUL; 2144 2254 2145 2255 while (1) 2146 2256 { 2147 if (stop2 && blank) 2148 while (*p != '\0' && *p != ignorevars && *p != stop1 && *p != stop2 2149 && ! isblank ((unsigned char) *p)) 2150 ++p; 2151 else if (stop2) 2152 while (*p != '\0' && *p != ignorevars && *p != stop1 && *p != stop2) 2153 ++p; 2154 else if (blank) 2155 while (*p != '\0' && *p != ignorevars && *p != stop1 2156 && ! isblank ((unsigned char) *p)) 2157 ++p; 2158 else 2159 while (*p != '\0' && *p != ignorevars && *p != stop1) 2160 ++p; 2257 while (! STOP_SET (*p, map)) 2258 ++p; 2161 2259 2162 2260 if (*p == '\0') 2163 2261 break; 2164 2262 2165 2263 /* If we stopped due to a variable reference, skip over its contents. */ 2166 if ( *p == ignorevars)2264 if (STOP_SET (*p, MAP_VARIABLE)) 2167 2265 { 2168 2266 char openparen = p[1]; 2267 2268 /* Check if '$' is the last character in the string. */ 2269 if (openparen == '\0') 2270 break; 2169 2271 2170 2272 p += 2; … … 2195 2297 2196 2298 if (p > string && p[-1] == '\\') 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2299 { 2300 /* Search for more backslashes. */ 2301 int i = -2; 2302 while (&p[i] >= string && p[i] == '\\') 2303 --i; 2304 ++i; 2305 /* Only compute the length if really needed. */ 2306 if (string_len == 0) 2307 string_len = strlen (string); 2308 /* The number of backslashes is now -I. 2309 Copy P over itself to swallow half of them. */ 2310 memmove (&p[i], &p[i/2], (string_len - (p - string)) - (i/2) + 1); 2311 p += i/2; 2312 if (i % 2 == 0) 2313 /* All the backslashes quoted each other; the STOPCHAR was 2314 unquoted. */ 2315 return p; 2316 2317 /* The STOPCHAR was quoted by a backslash. Look for another. */ 2318 } 2217 2319 else 2218 2219 2320 /* No backslash in sight. */ 2321 return p; 2220 2322 } 2221 2323 … … 2224 2326 } 2225 2327 2328 /* Unescape a character in a string. The string is compressed onto itself. */ 2329 2330 static char * 2331 unescape_char (char *string, int c) 2332 { 2333 char *p = string; 2334 char *s = string; 2335 2336 while (*s != '\0') 2337 { 2338 if (*s == '\\') 2339 { 2340 char *e = s; 2341 int l; 2342 2343 /* We found a backslash. See if it's escaping our character. */ 2344 while (*e == '\\') 2345 ++e; 2346 l = e - s; 2347 2348 if (*e != c || l%2 == 0) 2349 { 2350 /* It's not; just take it all without unescaping. */ 2351 memmove (p, s, l); 2352 p += l; 2353 2354 // If we hit the end of the string, we're done 2355 if (*e == '\0') 2356 break; 2357 } 2358 else if (l > 1) 2359 { 2360 /* It is, and there's >1 backslash. Take half of them. */ 2361 l /= 2; 2362 memmove (p, s, l); 2363 p += l; 2364 } 2365 2366 s = e; 2367 } 2368 2369 *(p++) = *(s++); 2370 } 2371 2372 *p = '\0'; 2373 return string; 2374 } 2375 2226 2376 /* Search PATTERN for an unquoted % and handle quoting. */ 2227 2377 … … 2229 2379 find_percent (char *pattern) 2230 2380 { 2231 return find_char_unquote (pattern, '%', 0, 0, 0);2381 return find_char_unquote (pattern, MAP_PERCENT); 2232 2382 } 2233 2383 … … 2252 2402 while (1) 2253 2403 { 2254 while ( *p != '\0' && *p != '%')2404 while (! STOP_SET (*p, MAP_PERCENT|MAP_NUL)) 2255 2405 ++p; 2256 2406 … … 2322 2472 */ 2323 2473 2324 static unsignedlong2474 static long 2325 2475 readstring (struct ebuffer *ebuf) 2326 2476 { … … 2394 2544 len = strlen (p); 2395 2545 if (len == 0) 2396 2397 2398 2399 2400 2401 2402 error (&ebuf->floc,2403 2404 2405 2406 2546 { 2547 /* This only happens when the first thing on the line is a '\0'. 2548 It is a pretty hopeless case, but (wonder of wonders) Athena 2549 lossage strikes again! (xmkmf puts NULs in its makefiles.) 2550 There is nothing really to be done; we synthesize a newline so 2551 the following line doesn't appear to be part of this line. */ 2552 O (error, &ebuf->floc, 2553 _("warning: NUL character seen; rest of line ignored")); 2554 p[0] = '\n'; 2555 len = 1; 2556 } 2407 2557 2408 2558 /* Jump past the text we just read. */ … … 2423 2573 { 2424 2574 --p; 2425 p[-1] = '\n';2575 memmove (p-1, p, strlen (p) + 1); 2426 2576 } 2427 2577 #endif … … 2429 2579 backslash = 0; 2430 2580 for (p2 = p - 2; p2 >= start; --p2) 2431 2432 2433 2581 { 2582 if (*p2 != '\\') 2583 break; 2434 2584 backslash = !backslash; 2435 2585 } 2436 2586 2437 2587 if (!backslash) 2438 2439 2440 2441 2588 { 2589 p[-1] = '\0'; 2590 break; 2591 } 2442 2592 2443 2593 /* It was a backslash/newline combo. If we have more space, read … … 2483 2633 w_dcolon A double-colon 2484 2634 w_semicolon A semicolon 2485 w_varassign A variable assignment operator (=, :=, +=, or ?=)2635 w_varassign A variable assignment operator (=, :=, ::=, +=, ?=, or !=) 2486 2636 2487 2637 Note that this function is only used when reading certain parts of the … … 2497 2647 2498 2648 /* Skip any leading whitespace. */ 2499 while ( isblank ((unsigned char)*p))2649 while (ISBLANK (*p)) 2500 2650 ++p; 2501 2651 … … 2522 2672 case ':': 2523 2673 ++p; 2524 wtype = w_dcolon; 2674 if (p[1] != '=') 2675 wtype = w_dcolon; 2676 else 2677 { 2678 wtype = w_varassign; 2679 ++p; 2680 } 2525 2681 break; 2526 2682 … … 2534 2690 case '+': 2535 2691 case '?': 2692 case '!': 2536 2693 if (*p == '=') 2537 2694 { … … 2553 2710 /* This is some non-operator word. A word consists of the longest 2554 2711 string of characters that doesn't contain whitespace, one of [:=#], 2555 or [?+ ]=, or one of the chars in the DELIM string. */2712 or [?+!]=, or one of the chars in the DELIM string. */ 2556 2713 2557 2714 /* We start out assuming a static word; if we see a variable we'll … … 2575 2732 case ':': 2576 2733 #ifdef HAVE_DOS_PATHS 2577 2578 2579 2580 2581 2582 2734 /* A word CAN include a colon in its drive spec. The drive 2735 spec is allowed either at the beginning of a word, or as part 2736 of the archive member name, like in "libfoo.a(d:/foo/bar.o)". */ 2737 if (!(p - beg >= 2 2738 && (*p == '/' || *p == '\\') && isalpha ((unsigned char)p[-2]) 2739 && (p - beg == 2 || p[-3] == '('))) 2583 2740 #endif 2584 2741 goto done_word; 2585 2742 2586 2743 case '$': … … 2588 2745 if (c == '$') 2589 2746 break; 2747 if (c == '\0') 2748 goto done_word; 2590 2749 2591 2750 /* This is a variable reference, so note that it's expandable. … … 2657 2816 construct_include_path (const char **arg_dirs) 2658 2817 { 2659 #ifdef VAXC 2818 #ifdef VAXC /* just don't ask ... */ 2660 2819 stat_t stbuf; 2661 2820 #else … … 2688 2847 while (*arg_dirs != 0) 2689 2848 { 2690 2849 const char *dir = *(arg_dirs++); 2691 2850 char *expanded = 0; 2692 2851 int e; 2693 2852 2694 2695 2696 2697 2698 2699 2853 if (dir[0] == '~') 2854 { 2855 expanded = tilde_expand (dir); 2856 if (expanded != 0) 2857 dir = expanded; 2858 } 2700 2859 2701 2860 EINTRLOOP (e, stat (dir, &stbuf)); 2702 2861 if (e == 0 && S_ISDIR (stbuf.st_mode)) 2703 2862 { 2704 2863 unsigned int len = strlen (dir); … … 2711 2870 } 2712 2871 2713 if (expanded) 2714 free (expanded); 2872 free (expanded); 2715 2873 } 2716 2874 … … 2726 2884 { 2727 2885 unsigned int len = strlen (djdir->value) + 8; 2728 2729 2730 2731 2886 char *defdir = alloca (len + 1); 2887 2888 strcat (strcpy (defdir, djdir->value), "/include"); 2889 dirs[idx++] = strcache_add (defdir); 2732 2890 2733 2891 if (len > max_incl_len) … … 2775 2933 if (name[1] == '/' || name[1] == '\0') 2776 2934 { 2777 extern char *getenv ();2778 2935 char *home_dir; 2779 2936 int is_variable; 2780 2937 2781 2938 { 2782 2783 2784 2785 2786 2787 2788 2939 /* Turn off --warn-undefined-variables while we expand HOME. */ 2940 int save = warn_undefined_variables_flag; 2941 warn_undefined_variables_flag = 0; 2942 2943 home_dir = allocated_variable_expand ("$(HOME)"); 2944 2945 warn_undefined_variables_flag = save; 2789 2946 } 2790 2947 2791 2948 is_variable = home_dir[0] != '\0'; 2792 2949 if (!is_variable) 2793 2794 2795 2796 2950 { 2951 free (home_dir); 2952 home_dir = getenv ("HOME"); 2953 } 2797 2954 # if !defined(_AMIGA) && !defined(WINDOWS32) 2798 2955 if (home_dir == 0 || home_dir[0] == '\0') 2799 { 2800 extern char *getlogin (); 2801 char *logname = getlogin (); 2802 home_dir = 0; 2803 if (logname != 0) 2804 { 2805 struct passwd *p = getpwnam (logname); 2806 if (p != 0) 2807 home_dir = p->pw_dir; 2808 } 2809 } 2956 { 2957 char *logname = getlogin (); 2958 home_dir = 0; 2959 if (logname != 0) 2960 { 2961 struct passwd *p = getpwnam (logname); 2962 if (p != 0) 2963 home_dir = p->pw_dir; 2964 } 2965 } 2810 2966 # endif /* !AMIGA && !WINDOWS32 */ 2811 2967 if (home_dir != 0) 2812 2813 2814 2815 2816 2817 2968 { 2969 char *new = xstrdup (concat (2, home_dir, name + 1)); 2970 if (is_variable) 2971 free (home_dir); 2972 return new; 2973 } 2818 2974 } 2819 2975 # if !defined(_AMIGA) && !defined(WINDOWS32) … … 2823 2979 char *userend = strchr (name + 1, '/'); 2824 2980 if (userend != 0) 2825 2981 *userend = '\0'; 2826 2982 pwent = getpwnam (name + 1); 2827 2983 if (pwent != 0) 2828 2829 2830 2831 2832 2833 2984 { 2985 if (userend == 0) 2986 return xstrdup (pwent->pw_dir); 2987 else 2988 return xstrdup (concat (3, pwent->pw_dir, "/", userend + 1)); 2989 } 2834 2990 else if (userend != 0) 2835 2991 *userend = '/'; 2836 2992 } 2837 2993 # endif /* !AMIGA && !WINDOWS32 */ … … 2865 3021 2866 3022 void * 2867 parse_file_seq (char **stringp, unsigned int size, int stop char,3023 parse_file_seq (char **stringp, unsigned int size, int stopmap, 2868 3024 const char *prefix, int flags) 2869 3025 { 2870 extern void dir_setup_glob (glob_t *glob);2871 2872 3026 /* tmp points to tmpbuf after the prefix, if any. 2873 3027 tp is the end of the buffer. */ 2874 3028 static char *tmpbuf = NULL; 2875 static int tmpbuf_len = 0; 2876 2877 int cachep = (! (flags & PARSEFS_NOCACHE)); 3029 3030 int cachep = NONE_SET (flags, PARSEFS_NOCACHE); 2878 3031 2879 3032 struct nameseq *new = 0; … … 2890 3043 char *tp; 2891 3044 2892 #ifdef VMS 2893 # define VMS_COMMA ',' 2894 #else 2895 # define VMS_COMMA 0 2896 #endif 3045 /* Always stop on NUL. */ 3046 stopmap |= MAP_NUL; 2897 3047 2898 3048 if (size < sizeof (struct nameseq)) 2899 3049 size = sizeof (struct nameseq); 2900 3050 2901 if ( ! (flags &PARSEFS_NOGLOB))3051 if (NONE_SET (flags, PARSEFS_NOGLOB)) 2902 3052 dir_setup_glob (&gl); 2903 3053 2904 3054 /* Get enough temporary space to construct the largest possible target. */ 2905 3055 { 3056 static int tmpbuf_len = 0; 2906 3057 int l = strlen (*stringp) + 1; 2907 3058 if (l > tmpbuf_len) … … 2920 3071 const char **nlist = 0; 2921 3072 char *tildep = 0; 3073 int globme = 1; 2922 3074 #ifndef NO_ARCHIVES 2923 3075 char *arname = 0; … … 2929 3081 2930 3082 /* Skip whitespace; at the end of the string or STOPCHAR we're done. */ 2931 p = next_token(p);2932 if ( *p == '\0' || *p == stopchar)2933 3083 NEXT_TOKEN (p); 3084 if (STOP_SET (*p, stopmap)) 3085 break; 2934 3086 2935 3087 /* There are names left, so find the end of the next name. 2936 3088 Throughout this iteration S points to the start. */ 2937 3089 s = p; 2938 p = find_char_unquote (p, stop char, VMS_COMMA, 1, 0);3090 p = find_char_unquote (p, stopmap|MAP_VMSCOMMA|MAP_BLANK); 2939 3091 #ifdef VMS 2940 3092 /* convert comma separated list to space separated */ 2941 3093 if (p && *p == ',') 2942 3094 *p =' '; 2943 3095 #endif 2944 3096 #ifdef _AMIGA 2945 if (stopchar == ':' && p && *p == ':' 2946 && !(isspace ((unsigned char)p[1]) || !p[1] 2947 || isspace ((unsigned char)p[-1]))) 2948 p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0); 3097 if (p && STOP_SET (*p, stopmap & MAP_COLON) 3098 && !(ISSPACE (p[1]) || !p[1] || ISSPACE (p[-1]))) 3099 p = find_char_unquote (p+1, stopmap|MAP_VMSCOMMA|MAP_BLANK); 2949 3100 #endif 2950 3101 #ifdef HAVE_DOS_PATHS … … 2953 3104 Note that tokens separated by spaces should be treated as separate 2954 3105 tokens since make doesn't allow path names with spaces */ 2955 if (stop char == ':')2956 while (p != 0 && ! isspace ((unsigned char)*p) &&3106 if (stopmap | MAP_COLON) 3107 while (p != 0 && !ISSPACE (*p) && 2957 3108 (p[1] == '\\' || p[1] == '/') && isalpha ((unsigned char)p[-1])) 2958 p = find_char_unquote (p + 1, stop char, VMS_COMMA, 1, 0);3109 p = find_char_unquote (p + 1, stopmap|MAP_VMSCOMMA|MAP_BLANK); 2959 3110 #endif 2960 3111 if (p == 0) 2961 3112 p = s + strlen (s); 2962 3113 2963 3114 /* Strip leading "this directory" references. */ 2964 if ( ! (flags &PARSEFS_NOSTRIP))3115 if (NONE_SET (flags, PARSEFS_NOSTRIP)) 2965 3116 #ifdef VMS 2966 /* Skip leading `[]'s. */ 2967 while (p - s > 2 && s[0] == '[' && s[1] == ']') 2968 #else 2969 /* Skip leading `./'s. */ 2970 while (p - s > 2 && s[0] == '.' && s[1] == '/') 3117 /* Skip leading '[]'s. should only be one set or bug somwhere else */ 3118 if (p - s > 2 && s[0] == '[' && s[1] == ']') 3119 s += 2; 3120 /* Skip leading '<>'s. should only be one set or bug somwhere else */ 3121 if (p - s > 2 && s[0] == '<' && s[1] == '>') 3122 s += 2; 2971 3123 #endif 2972 { 3124 /* Skip leading './'s. */ 3125 while (p - s > 2 && s[0] == '.' && s[1] == '/') 3126 { 2973 3127 /* Skip "./" and all following slashes. */ 2974 2975 2976 2977 3128 s += 2; 3129 while (*s == '/') 3130 ++s; 3131 } 2978 3132 2979 3133 /* Extract the filename just found, and skip it. … … 2982 3136 if (s == p) 2983 3137 { 2984 /* The name was stripped to empty ("./"). */ 2985 #if defined(VMS) 2986 continue; 2987 #elif defined(_AMIGA) 3138 /* The name was stripped to empty ("./"). */ 3139 #if defined(_AMIGA) 2988 3140 /* PDS-- This cannot be right!! */ 2989 3141 tp[0] = '\0'; … … 2997 3149 } 2998 3150 else 2999 3151 { 3000 3152 #ifdef VMS 3001 3153 /* VMS filenames can have a ':' in them but they have to be '\'ed but we need … … 3003 3155 * xstrdup called because S may be read-only string constant. 3004 3156 */ 3005 3006 3007 3008 3157 char *n = tp; 3158 while (s < p) 3159 { 3160 if (s[0] == '\\' && s[1] == ':') 3009 3161 ++s; 3010 3011 3162 *(n++) = *(s++); 3163 } 3012 3164 n[0] = '\0'; 3013 3165 nlen = strlen (tp); … … 3028 3180 3029 3181 TP == TMP means we're not already in an archive group. Ignore 3030 something starting with `(', as that cannot actually be an3182 something starting with '(', as that cannot actually be an 3031 3183 archive-member reference (and treating it as such results in an empty 3032 3184 file name, which causes much lossage). Also if it ends in ")" then … … 3036 3188 character, so ensure there's some word ending like that before 3037 3189 considering this an archive group. */ 3038 if ( ! (flags &PARSEFS_NOAR)3190 if (NONE_SET (flags, PARSEFS_NOAR) 3039 3191 && tp == tmpbuf && tp[0] != '(' && tp[nlen-1] != ')') 3040 3192 { … … 3044 3196 /* This looks like the first element in an open archive group. 3045 3197 A valid group MUST have ')' as the last character. */ 3046 const char *e = p + nlen;3198 const char *e = p; 3047 3199 do 3048 3200 { 3049 e = next_token (e); 3201 const char *o = e; 3202 NEXT_TOKEN (e); 3050 3203 /* Find the end of this word. We don't want to unquote and 3051 3204 we don't care about quoting since we're looking for the 3052 3205 last char in the word. */ 3053 while (*e != '\0' && *e != stopchar && *e != VMS_COMMA 3054 && ! isblank ((unsigned char) *e)) 3206 while (! STOP_SET (*e, stopmap|MAP_BLANK|MAP_VMSCOMMA)) 3055 3207 ++e; 3208 /* If we didn't move, we're done now. */ 3209 if (e == o) 3210 break; 3056 3211 if (e[-1] == ')') 3057 3212 { … … 3062 3217 tp = n + 1; 3063 3218 3064 /* If we have just "lib(", part of something like3065 "lib( a b)", go to the next item. */3066 if (! nlen)3067 continue;3068 3069 3219 /* We can stop looking now. */ 3070 3220 break; … … 3072 3222 } 3073 3223 while (*e != '\0'); 3224 3225 /* If we have just "lib(", part of something like "lib( a b)", 3226 go to the next item. */ 3227 if (! nlen) 3228 continue; 3074 3229 } 3075 3230 } … … 3098 3253 /* If we're not globbing we're done: add it to the end of the chain. 3099 3254 Go to the next item in the string. */ 3100 if ( flags & PARSEFS_NOGLOB)3101 { 3102 NEWELT (concat (2, prefix, t p));3255 if (ANY_SET (flags, PARSEFS_NOGLOB)) 3256 { 3257 NEWELT (concat (2, prefix, tmpbuf)); 3103 3258 continue; 3104 3259 } … … 3107 3262 TP is a string in tmpbuf. NLEN is no longer used. 3108 3263 We may need to do more work: after this NAME will be set. */ 3109 name = t p;3264 name = tmpbuf; 3110 3265 3111 3266 /* Expand tilde if applicable. */ 3112 if (t p[0] == '~')3113 3114 tildep = tilde_expand (tp);3115 3267 if (tmpbuf[0] == '~') 3268 { 3269 tildep = tilde_expand (tmpbuf); 3270 if (tildep != 0) 3116 3271 name = tildep; 3117 3272 } 3118 3273 3119 3274 #ifndef NO_ARCHIVES … … 3121 3276 file name, and save the member name in MEMNAME. We will glob on the 3122 3277 archive name and then reattach MEMNAME later. */ 3123 if ( ! (flags &PARSEFS_NOAR) && ar_name (name))3124 3125 3126 3127 3278 if (NONE_SET (flags, PARSEFS_NOAR) && ar_name (name)) 3279 { 3280 ar_parse_name (name, &arname, &memname); 3281 name = arname; 3282 } 3128 3283 #endif /* !NO_ARCHIVES */ 3129 3284 3130 switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl)) 3131 { 3132 case GLOB_NOSPACE: 3133 fatal (NILF, _("virtual memory exhausted")); 3134 3135 case 0: 3136 /* Success. */ 3137 i = gl.gl_pathc; 3138 nlist = (const char **)gl.gl_pathv; 3139 break; 3140 3141 case GLOB_NOMATCH: 3142 /* If we want only existing items, skip this one. */ 3143 if (flags & PARSEFS_EXISTS) 3144 { 3145 i = 0; 3146 break; 3147 } 3148 /* FALLTHROUGH */ 3149 3150 default: 3151 /* By default keep this name. */ 3285 /* glob() is expensive: don't call it unless we need to. */ 3286 if (NONE_SET (flags, PARSEFS_EXISTS) && strpbrk (name, "?*[") == NULL) 3287 { 3288 globme = 0; 3152 3289 i = 1; 3153 3290 nlist = &name; 3154 break; 3155 } 3291 } 3292 else 3293 switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl)) 3294 { 3295 case GLOB_NOSPACE: 3296 OUT_OF_MEM(); 3297 3298 case 0: 3299 /* Success. */ 3300 i = gl.gl_pathc; 3301 nlist = (const char **)gl.gl_pathv; 3302 break; 3303 3304 case GLOB_NOMATCH: 3305 /* If we want only existing items, skip this one. */ 3306 if (ANY_SET (flags, PARSEFS_EXISTS)) 3307 { 3308 i = 0; 3309 break; 3310 } 3311 /* FALLTHROUGH */ 3312 3313 default: 3314 /* By default keep this name. */ 3315 i = 1; 3316 nlist = &name; 3317 break; 3318 } 3156 3319 3157 3320 /* For each matched element, add it to the list. */ … … 3168 3331 { 3169 3332 /* We got a chain of items. Attach them. */ 3170 (*newp)->next = found; 3333 if (*newp) 3334 (*newp)->next = found; 3335 else 3336 *newp = found; 3171 3337 3172 3338 /* Find and set the new end. Massage names if necessary. */ … … 3190 3356 NEWELT (concat (2, prefix, nlist[i])); 3191 3357 3192 globfree (&gl); 3358 if (globme) 3359 globfree (&gl); 3193 3360 3194 3361 #ifndef NO_ARCHIVES 3195 if (arname) 3196 free (arname); 3362 free (arname); 3197 3363 #endif 3198 3364 3199 if (tildep) 3200 free (tildep); 3365 free (tildep); 3201 3366 } 3202 3367
Note:
See TracChangeset
for help on using the changeset viewer.