Changeset 2591 for trunk/src/kmk/read.c
- Timestamp:
- Jun 17, 2012, 10:45:31 PM (13 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk
- Property svn:ignore
-
old new 13 13 stamp-* 14 14 makebook* 15 15 16 .*gdbinit 17 .gdb_history 18 16 19 *.dep 17 20 *.dvi … … 31 34 *.pg 32 35 *.pgs 36 33 37 README 34 38 README.DOS 35 39 README.W32 40 README.OS2 36 41 aclocal.m4 37 42 autom4te.cache … … 52 57 config.h.W32 53 58 config.h-vms 59 54 60 loadavg 55 61 loadavg.c 56 62 make 63 57 64 .deps 58 65 .dep_segment 66 ID 67 TAGS 68 59 69 _* 60 70 sun4 … … 72 82 sol2 73 83 i486-linux 84 74 85 customs 86 75 87 install-sh 76 88 mkinstalldirs 89 90 .directive.asc
-
- Property svn:ignore
-
trunk/src/kmk/read.c
r2548 r2591 1 1 /* Reading and parsing of makefiles for GNU Make. 2 2 Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software4 Foundation, Inc.3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 4 2010 Free Software Foundation, Inc. 5 5 This file is part of GNU Make. 6 6 … … 60 60 FILE *fp; /* File, or NULL if this is an internal buffer. */ 61 61 struct floc floc; /* Info on the file in fp (if any). */ 62 }; 63 64 /* Track the modifiers we can have on variable assignments */ 65 66 struct vmodifiers 67 { 68 unsigned int assign_v:1; 69 unsigned int define_v:1; 70 unsigned int undefine_v:1; 71 unsigned int export_v:1; 72 unsigned int override_v:1; 73 unsigned int private_v:1; 62 74 }; 63 75 … … 149 161 150 162 static int eval_makefile (const char *filename, int flags); 151 static inteval (struct ebuffer *buffer, int flags);163 static void eval (struct ebuffer *buffer, int flags); 152 164 153 165 static long readline (struct ebuffer *ebuf); 154 static void do_define (char *name, unsigned int namelen, 155 enum variable_origin origin, struct ebuffer *ebuf); 166 static void do_undefine (char *name, enum variable_origin origin, 167 struct ebuffer *ebuf); 168 static struct variable *do_define (char *name IF_WITH_VALUE_LENGTH_PARAM(char *eos), 169 enum variable_origin origin, struct ebuffer *ebuf); 156 170 #ifndef CONFIG_WITH_VALUE_LENGTH 157 171 static int conditional_line (char *line, int len, const struct floc *flocp); … … 159 173 static int conditional_line (char *line, char *eol, int len, const struct floc *flocp); 160 174 #endif 161 #ifndef CONFIG_WITH_INCLUDEDEP162 175 static void record_files (struct nameseq *filenames, const char *pattern, 163 const char *pattern_percent, struct dep *deps,176 const char *pattern_percent, char *depstr, 164 177 unsigned int cmds_started, char *commands, 165 178 unsigned int commands_idx, int two_colon, 166 179 const struct floc *flocp); 167 #endif /* !KMK */168 180 static void record_target_var (struct nameseq *filenames, char *defn, 169 enum variable_origin origin, int enabled, 181 enum variable_origin origin, 182 struct vmodifiers *vmod, 170 183 const struct floc *flocp); 171 184 static enum make_word_type get_next_mword (char *buffer, char *delim, … … 198 211 199 212 213 /* Compare a word, both length and contents. 214 P must point to the word to be tested, and WLEN must be the length. 215 */ 216 #define word1eq(s) (wlen == sizeof(s)-1 && strneq (s, p, sizeof(s)-1)) 217 218 219 200 220 /* Read in all the makefiles and return the chain of their names. */ 201 221 … … 208 228 we will be reading. */ 209 229 210 define_variable ("MAKEFILE_LIST", sizeof ("MAKEFILE_LIST")-1, "", o_file, 0);230 define_variable_cname ("MAKEFILE_LIST", "", o_file, 0); 211 231 212 232 DB (DB_BASIC, (_("Reading makefiles...\n"))); … … 320 340 struct dep *d = alloc_dep (); 321 341 d->file = enter_file (strcache_add (*p)); 322 d-> file->dontcare = 1;342 d->dontcare = 1; 323 343 /* Tell update_goal_chain to bail out as soon as this file is 324 344 made, and main not to die if we can't make this file. */ … … 388 408 char *expanded = 0; 389 409 int makefile_errno; 390 int r;391 410 392 411 filename = strcache_add (filename); … … 431 450 for (i = 0; include_directories[i] != 0; ++i) 432 451 { 433 const char *included = concat (include_directories[i], "/", filename); 452 const char *included = concat (3, include_directories[i], 453 "/", filename); 434 454 ebuf.fp = fopen (included, "r"); 435 455 if (ebuf.fp) … … 455 475 deps->changed = flags; 456 476 if (flags & RM_DONTCARE) 457 deps-> file->dontcare = 1;477 deps->dontcare = 1; 458 478 459 479 if (expanded) … … 470 490 return 0; 471 491 } 492 493 /* Set close-on-exec to avoid leaking the makefile to children, such as 494 $(shell ...). */ 495 #ifdef HAVE_FILENO 496 CLOSE_ON_EXEC (fileno (ebuf.fp)); 497 #endif 472 498 473 499 /* Add this makefile to the list. */ … … 506 532 reading_file = &ebuf.floc; 507 533 508 r =eval (&ebuf, !(flags & RM_NO_DEFAULT_GOAL));534 eval (&ebuf, !(flags & RM_NO_DEFAULT_GOAL)); 509 535 510 536 reading_file = curfile; … … 519 545 free (ebuf.bufstart); 520 546 alloca (0); 521 return r; 547 548 return 1; 522 549 } 523 550 524 int 551 void 525 552 #ifndef CONFIG_WITH_VALUE_LENGTH 526 553 eval_buffer (char *buffer) … … 533 560 struct conditionals new; 534 561 const struct floc *curfile; 535 int r;536 562 537 563 /* Evaluate the buffer */ … … 547 573 ebuf.fp = NULL; 548 574 549 ebuf.floc = *reading_file; 575 if (reading_file) 576 ebuf.floc = *reading_file; 577 else 578 ebuf.floc.filenm = NULL; 550 579 551 580 curfile = reading_file; … … 554 583 saved = install_conditionals (&new); 555 584 556 r =eval (&ebuf, 1);585 eval (&ebuf, 1); 557 586 558 587 restore_conditionals (saved); … … 561 590 562 591 alloca (0); 563 return r;564 592 } 565 593 566 594 595 /* Check LINE to see if it's a variable assignment or undefine. 596 597 It might use one of the modifiers "export", "override", "private", or it 598 might be one of the conditional tokens like "ifdef", "include", etc. 599 600 If it's not a variable assignment or undefine, VMOD.V_ASSIGN is 0. 601 Returns LINE. 602 603 Returns a pointer to the first non-modifier character, and sets VMOD 604 based on the modifiers found if any, plus V_ASSIGN is 1. 605 */ 606 static char * 607 parse_var_assignment (const char *line, struct vmodifiers *vmod) 608 { 609 const char *p; 610 memset (vmod, '\0', sizeof (*vmod)); 611 612 /* Find the start of the next token. If there isn't one we're done. */ 613 line = next_token (line); 614 if (*line == '\0') 615 return (char *)line; 616 617 p = line; 618 while (1) 619 { 620 int wlen; 621 const char *p2; 622 enum variable_flavor flavor; 623 624 p2 = parse_variable_definition (p, &flavor); 625 626 /* If this is a variable assignment, we're done. */ 627 if (p2) 628 break; 629 630 /* It's not a variable; see if it's a modifier. */ 631 p2 = end_of_token (p); 632 wlen = p2 - p; 633 634 if (word1eq ("export")) 635 vmod->export_v = 1; 636 else if (word1eq ("override")) 637 vmod->override_v = 1; 638 else if (word1eq ("private")) 639 vmod->private_v = 1; 640 else if (word1eq ("define")) 641 { 642 /* We can't have modifiers after 'define' */ 643 vmod->define_v = 1; 644 p = next_token (p2); 645 break; 646 } 647 else if (word1eq ("undefine")) 648 { 649 /* We can't have modifiers after 'undefine' */ 650 vmod->undefine_v = 1; 651 p = next_token (p2); 652 break; 653 } 654 else 655 /* Not a variable or modifier: this is not a variable assignment. */ 656 return (char *)line; 657 658 /* It was a modifier. Try the next word. */ 659 p = next_token (p2); 660 if (*p == '\0') 661 return (char *)line; 662 } 663 664 /* Found a variable assignment or undefine. */ 665 vmod->assign_v = 1; 666 return (char *)p; 667 } 668 669 567 670 568 671 /* Read file FILENAME as a makefile and add its contents to the data base. … … 570 673 SET_DEFAULT is true if we are allowed to set the default goal. */ 571 674 572 573 static int 675 static void 574 676 eval (struct ebuffer *ebuf, int set_default) 575 677 { … … 583 685 int no_targets = 0; /* Set when reading a rule without targets. */ 584 686 struct nameseq *filenames = 0; 585 struct dep *deps= 0;687 char *depstr = 0; 586 688 long nlines = 0; 587 689 int two_colon = 0; … … 604 706 { \ 605 707 fi.lineno = tgts_started; \ 606 record_files (filenames, pattern, pattern_percent, deps ,\708 record_files (filenames, pattern, pattern_percent, depstr, \ 607 709 cmds_started, commands, commands_idx, two_colon, \ 608 710 &fi); \ 711 filenames = 0; \ 609 712 } \ 610 filenames = 0; \611 713 commands_idx = 0; \ 612 714 no_targets = 0; \ … … 642 744 char *p; 643 745 char *p2; 644 746 struct vmodifiers vmod; 747 748 /* At the top of this loop, we are starting a brand new line. */ 645 749 /* Grab the next line to be evaluated */ 646 750 ebuf->floc.lineno += nlines; … … 672 776 673 777 /* If there is no preceding rule line, don't treat this line 674 as a command, even though it begins with a tab character.778 as a command, even though it begins with a recipe prefix. 675 779 SunOS 4 make appears to behave this way. */ 676 780 … … 711 815 } 712 816 713 /* This line is not a shell command line. Don't worry about tabs.817 /* This line is not a shell command line. Don't worry about whitespace. 714 818 Get more space if we need it; we don't need to preserve the current 715 819 contents of the buffer. */ … … 720 824 if (collapsed) 721 825 free (collapsed); 826 /* Don't need xrealloc: we don't need to preserve the content. */ 722 827 collapsed = xmalloc (collapsed_length); 723 828 } … … 736 841 #endif 737 842 738 /* Compare a word, both length and contents. */ 739 #define word1eq(s) (wlen == sizeof(s)-1 && strneq (s, p, sizeof(s)-1)) 843 /* Get rid if starting space (including formfeed, vtab, etc.) */ 740 844 p = collapsed; 741 845 while (isspace ((unsigned char)*p)) 742 ++p; 743 744 if (*p == '\0') 745 /* This line is completely empty--ignore it. */ 746 continue; 747 748 /* Find the end of the first token. Note we don't need to worry about 749 * ":" here since we compare tokens by length (so "export" will never 750 * be equal to "export:"). 751 */ 752 for (p2 = p+1; *p2 != '\0' && !isspace ((unsigned char)*p2); ++p2) 753 ; 754 wlen = p2 - p; 755 756 /* Find the start of the second token. If it looks like a target or 757 variable definition it can't be a preprocessor token so skip 758 them--this allows variables/targets named `ifdef', `export', etc. */ 759 while (isspace ((unsigned char)*p2)) 760 ++p2; 761 762 if ((p2[0] == ':' || p2[0] == '+' || p2[0] == '=') && p2[1] == '\0') 846 ++p; 847 848 /* See if this is a variable assignment. We need to do this early, to 849 allow variables with names like 'ifdef', 'export', 'private', etc. */ 850 p = parse_var_assignment(p, &vmod); 851 if (vmod.assign_v) 763 852 { 764 /* It can't be a preprocessor token so skip it if we're ignoring */ 765 if (ignoring) 766 continue; 767 768 goto skip_conditionals; 769 } 770 771 /* We must first check for conditional and `define' directives before 772 ignoring anything, since they control what we will do with 773 following lines. */ 774 775 if (!in_ignored_define) 776 { 777 #ifndef CONFIG_WITH_VALUE_LENGTH 778 int i = conditional_line (p, wlen, fstart); 779 #else 780 int i = conditional_line (p, eol, wlen, fstart); 781 #endif 782 if (i != -2) 853 struct variable *v; 854 enum variable_origin origin = vmod.override_v ? o_override : o_file; 855 856 /* If we're ignoring then we're done now. */ 857 if (ignoring) 783 858 { 784 if (i == -1) 785 fatal (fstart, _("invalid syntax in conditional")); 786 787 ignoring = i; 859 if (vmod.define_v) 860 in_ignored_define = 1; 788 861 continue; 789 862 } 790 } 791 792 if (word1eq ("endef")) 863 864 if (vmod.undefine_v) 865 { 866 do_undefine (p, origin, ebuf); 867 868 /* This line has been dealt with. */ 869 goto rule_complete; 870 } 871 else if (vmod.define_v) 872 v = do_define (p IF_WITH_VALUE_LENGTH_PARAM(NULL), origin, ebuf); 873 else 874 v = try_variable_definition (fstart, p IF_WITH_VALUE_LENGTH_PARAM(NULL), origin, 0); 875 876 assert (v != NULL); 877 878 if (vmod.export_v) 879 v->export = v_export; 880 if (vmod.private_v) 881 v->private_var = 1; 882 883 /* This line has been dealt with. */ 884 goto rule_complete; 885 } 886 887 /* If this line is completely empty, ignore it. */ 888 if (*p == '\0') 889 continue; 890 891 p2 = end_of_token (p); 892 wlen = p2 - p; 893 p2 = next_token (p2); 894 895 /* If we're in an ignored define, skip this line (but maybe get out). */ 896 if (in_ignored_define) 793 897 { 794 if (!in_ignored_define) 795 fatal (fstart, _("extraneous `endef'")); 796 in_ignored_define = 0; 898 /* See if this is an endef line (plus optional comment). */ 899 if (word1eq ("endef") && (*p2 == '\0' || *p2 == '#')) 900 in_ignored_define = 0; 901 797 902 continue; 798 903 } 799 904 800 if (word1eq ("define")) 801 { 802 if (ignoring) 803 in_ignored_define = 1; 804 else 805 { 806 if (*p2 == '\0') 807 fatal (fstart, _("empty variable name")); 808 809 /* Let the variable name be the whole rest of the line, 810 with trailing blanks stripped (comments have already been 811 removed), so it could be a complex variable/function 812 reference that might contain blanks. */ 813 p = strchr (p2, '\0'); 814 while (isblank ((unsigned char)p[-1])) 815 --p; 816 do_define (p2, p - p2, o_file, ebuf); 817 } 818 continue; 819 } 820 821 if (word1eq ("override")) 822 { 823 if (*p2 == '\0') 824 error (fstart, _("empty `override' directive")); 825 826 if (strneq (p2, "define", 6) 827 && (isblank ((unsigned char)p2[6]) || p2[6] == '\0')) 828 { 829 if (ignoring) 830 in_ignored_define = 1; 831 else 832 { 833 p2 = next_token (p2 + 6); 834 if (*p2 == '\0') 835 fatal (fstart, _("empty variable name")); 836 837 /* Let the variable name be the whole rest of the line, 838 with trailing blanks stripped (comments have already been 839 removed), so it could be a complex variable/function 840 reference that might contain blanks. */ 841 p = strchr (p2, '\0'); 842 while (isblank ((unsigned char)p[-1])) 843 --p; 844 do_define (p2, p - p2, o_override, ebuf); 845 } 846 } 847 else if (!ignoring 905 /* Check for conditional state changes. */ 906 { 848 907 #ifndef CONFIG_WITH_VALUE_LENGTH 849 && !try_variable_definition (fstart, p2, o_override, 0)) 850 #else 851 && !try_variable_definition (fstart, p2, eol, o_override, 0)) 852 #endif 853 error (fstart, _("invalid `override' directive")); 854 855 continue; 856 } 908 int i = conditional_line (p, wlen, fstart); 909 #else 910 int i = conditional_line (p, eol, wlen, fstart); 911 #endif 912 if (i != -2) 913 { 914 if (i == -1) 915 fatal (fstart, _("invalid syntax in conditional")); 916 917 ignoring = i; 918 continue; 919 } 920 } 921 922 /* Nothing to see here... move along. */ 923 if (ignoring) 924 continue; 925 857 926 #ifdef CONFIG_WITH_LOCAL_VARIABLES 858 859 927 if (word1eq ("local")) 860 928 { … … 880 948 while (isblank ((unsigned char)p[-1])) 881 949 --p; 882 do_define (p2 , p - p2, o_local, ebuf);950 do_define (p2 IF_WITH_VALUE_LENGTH_PARAM(p), o_local, ebuf); 883 951 } 884 952 } 885 953 else if (!ignoring 886 # ifndef CONFIG_WITH_VALUE_LENGTH 887 && !try_variable_definition (fstart, p2, o_local, 0)) 888 # else 889 && !try_variable_definition (fstart, p2, eol, o_local, 0)) 890 # endif 954 && !try_variable_definition (fstart, p2 IF_WITH_VALUE_LENGTH_PARAM(eol), o_local, 0)) 891 955 error (fstart, _("invalid `local' directive")); 892 956 … … 894 958 } 895 959 #endif /* CONFIG_WITH_LOCAL_VARIABLES */ 896 897 if (ignoring)898 /* Ignore the line. We continue here so conditionals899 can appear in the middle of a rule. */900 continue;901 960 902 961 #ifdef KMK … … 918 977 919 978 #endif /* KMK */ 920 if (word1eq ("export")) 979 980 /* Manage the "export" keyword used outside of variable assignment 981 as well as "unexport". */ 982 if (word1eq ("export") || word1eq ("unexport")) 921 983 { 922 /* 'export' by itself causes everything to be exported. */ 984 int exporting = *p == 'u' ? 0 : 1; 985 986 /* (un)export by itself causes everything to be (un)exported. */ 923 987 if (*p2 == '\0') 924 export_all_variables = 1;988 export_all_variables = exporting; 925 989 else 926 990 { 927 struct variable *v; 928 991 unsigned int l; 992 const char *cp; 993 char *ap; 994 995 /* Expand the line so we can use indirect and constructed 996 variable names in an (un)export command. */ 929 997 #ifndef CONFIG_WITH_VALUE_LENGTH 930 v = try_variable_definition (fstart, p2, o_file, 0); 931 #else 932 v = try_variable_definition (fstart, p2, eol, o_file, 0); 933 #endif 934 if (v != 0) 935 v->export = v_export; 936 else 998 cp = ap = allocated_variable_expand (p2); 999 #else 1000 unsigned int buf_len; 1001 cp = ap = allocated_variable_expand_3 (p2, eol - p2, NULL, &buf_len); 1002 #endif 1003 1004 for (p = find_next_token (&cp, &l); p != 0; 1005 p = find_next_token (&cp, &l)) 937 1006 { 938 unsigned int l;939 const char *cp;940 char *ap;941 942 /* Expand the line so we can use indirect and constructed943 variable names in an export command. */ 1007 struct variable *v = lookup_variable (p, l); 1008 if (v == 0) 1009 v = define_variable_loc (p, l, "", o_file, 0, fstart); 1010 v->export = exporting ? v_export : v_noexport; 1011 } 1012 944 1013 #ifndef CONFIG_WITH_VALUE_LENGTH 945 cp = ap = allocated_variable_expand (p2); 946 #else 947 unsigned int buf_len; 948 cp = ap = allocated_variable_expand_3 (p2, eol - p2, NULL, &buf_len); 949 #endif 950 951 for (p = find_next_token (&cp, &l); p != 0; 952 p = find_next_token (&cp, &l)) 953 { 954 v = lookup_variable (p, l); 955 if (v == 0) 956 v = define_variable_loc (p, l, "", o_file, 0, fstart); 957 v->export = v_export; 958 } 959 960 #ifndef CONFIG_WITH_VALUE_LENGTH 961 free (ap); 962 #else 963 recycle_variable_buffer (ap, buf_len); 964 #endif 965 } 1014 free (ap); 1015 #else 1016 recycle_variable_buffer (ap, buf_len); 1017 #endif 966 1018 } 967 1019 goto rule_complete; 968 1020 } 969 1021 970 if (word1eq ("unexport")) 971 { 972 if (*p2 == '\0') 973 export_all_variables = 0; 974 else 975 { 976 unsigned int l; 977 struct variable *v; 978 const char *cp; 979 char *ap; 980 981 /* Expand the line so we can use indirect and constructed 982 variable names in an unexport command. */ 983 #ifndef CONFIG_WITH_VALUE_LENGTH 984 cp = ap = allocated_variable_expand (p2); 985 #else 986 unsigned int buf_len; 987 cp = ap = allocated_variable_expand_3 (p2, eol - p2, NULL, &buf_len); 988 #endif 989 990 for (p = find_next_token (&cp, &l); p != 0; 991 p = find_next_token (&cp, &l)) 992 { 993 v = lookup_variable (p, l); 994 if (v == 0) 995 v = define_variable_loc (p, l, "", o_file, 0, fstart); 996 997 v->export = v_noexport; 998 } 999 1000 #ifndef CONFIG_WITH_VALUE_LENGTH 1001 free (ap); 1002 #else 1003 recycle_variable_buffer (ap, buf_len); 1004 #endif 1005 } 1006 goto rule_complete; 1007 } 1008 1009 skip_conditionals: 1022 /* Handle the special syntax for vpath. */ 1010 1023 if (word1eq ("vpath")) 1011 1024 { … … 1017 1030 if (p != 0) 1018 1031 { 1019 vpat = savestring(p, l);1032 vpat = xstrndup (p, l); 1020 1033 p = find_next_token (&cp, &l); 1021 1034 /* No searchpath means remove all previous … … 1069 1082 #endif /* CONFIG_WITH_INCLUDEDEP */ 1070 1083 1084 /* Handle include and variants. */ 1071 1085 if (word1eq ("include") || word1eq ("-include") || word1eq ("sinclude")) 1072 1086 { … … 1098 1112 } 1099 1113 1100 /* Parse the list of file names. */1114 /* Parse the list of file names. Don't expand archive references! */ 1101 1115 p2 = p; 1102 #ifndef CONFIG_WITH_ALLOC_CACHES 1103 files = multi_glob (parse_file_seq (&p2, '\0', 1104 sizeof (struct nameseq), 1105 1), 1106 sizeof (struct nameseq)); 1107 #else 1108 files = multi_glob (parse_file_seq (&p2, '\0', &nameseq_cache, 1), 1109 &nameseq_cache); 1110 #endif 1116 files = PARSE_FILE_SEQ (&p2, struct nameseq, '\0', NULL, 1117 PARSEFS_NOAR); 1111 1118 #ifndef CONFIG_WITH_VALUE_LENGTH 1112 1119 free (p); … … 1130 1137 int r; 1131 1138 1132 #ifndef CONFIG_WITH_ALLOC_CACHES 1133 free (files); 1134 #else 1135 alloccache_free (&nameseq_cache, files); 1136 #endif 1139 free_ns (files); 1137 1140 files = next; 1138 1141 1139 r = eval_makefile (name, (RM_INCLUDED | RM_NO_TILDE 1140 | (noerror ? RM_DONTCARE : 0))); 1142 r = eval_makefile (name, 1143 (RM_INCLUDED | RM_NO_TILDE 1144 | (noerror ? RM_DONTCARE : 0) 1145 | (set_default ? 0 : RM_NO_DEFAULT_GOAL))); 1141 1146 if (!r && !noerror) 1142 1147 error (fstart, "%s: %s", name, strerror (errno)); … … 1148 1153 goto rule_complete; 1149 1154 } 1150 1151 #ifndef CONFIG_WITH_VALUE_LENGTH1152 if (try_variable_definition (fstart, p, o_file, 0))1153 #else1154 if (try_variable_definition (fstart, p, eol, o_file, 0))1155 #endif1156 /* This line has been dealt with. */1157 goto rule_complete;1158 1155 1159 1156 /* This line starts with a tab but was not caught above because there … … 1175 1172 { 1176 1173 enum make_word_type wtype; 1177 enum variable_origin v_origin;1178 int exported;1179 1174 char *cmdleft, *semip, *lb_next; 1180 1175 unsigned int plen = 0; … … 1347 1342 looking for targets. */ 1348 1343 *colonp = '\0'; 1349 #ifndef CONFIG_WITH_ALLOC_CACHES 1350 filenames = multi_glob (parse_file_seq (&p2, '\0', 1351 sizeof (struct nameseq), 1352 1), 1353 sizeof (struct nameseq)); 1354 #else 1355 filenames = multi_glob (parse_file_seq (&p2, '\0', &nameseq_cache, 1), 1356 &nameseq_cache); 1357 #endif 1344 filenames = PARSE_FILE_SEQ (&p2, struct nameseq, '\0', NULL, 0); 1358 1345 *p2 = ':'; 1359 1346 … … 1386 1373 } 1387 1374 1388 /* See if it's an "override" or "export" keyword; if so see if what 1389 comes after it looks like a variable definition. */ 1390 1391 wtype = get_next_mword (p2, NULL, &p, &wlen); 1392 1393 v_origin = o_file; 1394 exported = 0; 1395 if (wtype == w_static) 1396 { 1397 if (word1eq ("override")) 1398 { 1399 v_origin = o_override; 1400 wtype = get_next_mword (p+wlen, NULL, &p, &wlen); 1401 } 1402 else if (word1eq ("export")) 1403 { 1404 exported = 1; 1405 wtype = get_next_mword (p+wlen, NULL, &p, &wlen); 1406 } 1407 } 1408 1409 if (wtype != w_eol) 1410 wtype = get_next_mword (p+wlen, NULL, NULL, NULL); 1411 1412 if (wtype == w_varassign) 1375 p2 = parse_var_assignment (p2, &vmod); 1376 if (vmod.assign_v) 1413 1377 { 1414 1378 /* If there was a semicolon found, add it back, plus anything … … 1418 1382 unsigned int l = p - variable_buffer; 1419 1383 *(--semip) = ';'; 1384 #ifndef CONFIG_WITH_VALUE_LENGTH 1385 collapse_continuations (semip); 1386 #else 1387 collapse_continuations (semip, strlen(semip)); /** @todo fix this */ 1388 #endif 1420 1389 variable_buffer_output (p2 + strlen (p2), 1421 1390 semip, strlen (semip)+1); 1422 1391 p = variable_buffer + l; 1423 1392 } 1424 record_target_var (filenames, p, v_origin, exported, fstart); 1393 record_target_var (filenames, p2, 1394 vmod.override_v ? o_override : o_file, 1395 &vmod, fstart); 1425 1396 filenames = 0; 1426 1397 continue; … … 1463 1434 while (p != 0 && p[-1] == '\\') 1464 1435 { 1465 registerchar *q = &p[-1];1466 registerint backslash = 0;1436 char *q = &p[-1]; 1437 int backslash = 0; 1467 1438 while (*q-- == '\\') 1468 1439 backslash = !backslash; … … 1507 1478 { 1508 1479 struct nameseq *target; 1509 #ifndef CONFIG_WITH_ALLOC_CACHES 1510 target = parse_file_seq (&p2, ':', sizeof (struct nameseq), 1); 1511 #else 1512 target = parse_file_seq (&p2, ':', &nameseq_cache, 1); 1513 #endif 1480 target = PARSE_FILE_SEQ (&p2, struct nameseq, ':', NULL, 1481 PARSEFS_NOGLOB); 1514 1482 ++p2; 1515 1483 if (target == 0) … … 1521 1489 if (pattern_percent == 0) 1522 1490 fatal (fstart, _("target pattern contains no `%%' (target `%s')"), target->name); /* bird */ 1523 #ifndef CONFIG_WITH_ALLOC_CACHES 1524 free (target); 1525 #else 1526 alloccache_free (&nameseq_cache, target); 1527 #endif 1491 free_ns (target); 1528 1492 } 1529 1493 else … … 1535 1499 strip_whitespace (&beg, &end); 1536 1500 1501 /* Put all the prerequisites here; they'll be parsed later. */ 1537 1502 if (beg <= end && *beg != '\0') 1538 { 1539 /* Put all the prerequisites here; they'll be parsed later. */ 1540 deps = alloc_dep (); 1541 #ifndef CONFIG_WITH_VALUE_LENGTH 1542 deps->name = strcache_add_len (beg, end - beg + 1); 1543 #else /* CONFIG_WITH_VALUE_LENGTH */ 1544 { 1545 /* Make sure the strcache_add_len input is terminated so it 1546 doesn't have to make a temporary copy on the stack. */ 1547 char saved = end[1]; 1548 ((char *)end)[1] = '\0'; 1549 deps->name = strcache_add_len (beg, end - beg + 1); 1550 ((char *)end)[1] = saved; 1551 } 1552 #endif /* CONFIG_WITH_VALUE_LENGTH */ 1553 } 1503 depstr = xstrndup (beg, end - beg + 1); 1554 1504 else 1555 deps = 0;1505 depstr = 0; 1556 1506 1557 1507 commands_idx = 0; … … 1587 1537 Because the target is not recorded until after ifeq directive is 1588 1538 evaluated the .DEFAULT_GOAL does not contain foo yet as one 1589 would expect. Because of this we have to move some of the logic 1590 here. */ 1591 1592 if (**default_goal_name == '\0' && set_default) 1539 would expect. Because of this we have to move the logic here. */ 1540 1541 if (set_default && default_goal_var->value[0] == '\0') 1593 1542 { 1594 1543 const char *name; … … 1680 1629 free (collapsed); 1681 1630 free (commands); 1682 1683 return 1;1684 1631 } 1685 1632 … … 1758 1705 #endif /* CONFIG_WITH_VALUE_LENGTH */ 1759 1706 1707 /* Execute a `undefine' directive. 1708 The undefine line has already been read, and NAME is the name of 1709 the variable to be undefined. */ 1710 1711 static void 1712 do_undefine (char *name, enum variable_origin origin, struct ebuffer *ebuf) 1713 { 1714 char *p, *var; 1715 1716 /* Expand the variable name and find the beginning (NAME) and end. */ 1717 var = allocated_variable_expand (name); 1718 name = next_token (var); 1719 if (*name == '\0') 1720 fatal (&ebuf->floc, _("empty variable name")); 1721 p = name + strlen (name) - 1; 1722 while (p > name && isblank ((unsigned char)*p)) 1723 --p; 1724 p[1] = '\0'; 1725 1726 undefine_variable_global (name, p - name + 1, origin); 1727 free (var); 1728 } 1729 1760 1730 /* Execute a `define' directive. 1761 1731 The first line has already been read, and NAME is the name of 1762 1732 the variable to be defined. The following lines remain to be read. */ 1763 1733 1764 static void1765 do_define (char *name , unsigned int namelen,1734 static struct variable * 1735 do_define (char *name IF_WITH_VALUE_LENGTH_PARAM(char *eos), 1766 1736 enum variable_origin origin, struct ebuffer *ebuf) 1767 1737 { 1738 struct variable *v; 1739 enum variable_flavor flavor; 1768 1740 struct floc defstart; 1769 long nlines = 0;1770 1741 int nlevels = 1; 1771 1742 unsigned int length = 100; 1772 1743 char *definition = xmalloc (length); 1773 1744 unsigned int idx = 0; 1774 char *p; 1775 1776 /* Expand the variable name. */ 1777 char *var = alloca (namelen + 1); 1778 memcpy (var, name, namelen); 1779 var[namelen] = '\0'; 1780 var = variable_expand (var); 1745 char *p, *var; 1781 1746 1782 1747 defstart = ebuf->floc; 1783 1748 1749 p = parse_variable_definition (name, &flavor); 1750 if (p == NULL) 1751 /* No assignment token, so assume recursive. */ 1752 flavor = f_recursive; 1753 else 1754 { 1755 if (*(next_token (p)) != '\0') 1756 error (&defstart, _("extraneous text after `define' directive")); 1757 1758 /* Chop the string before the assignment token to get the name. */ 1759 p[flavor == f_recursive ? -1 : -2] = '\0'; 1760 } 1761 1762 /* Expand the variable name and find the beginning (NAME) and end. */ 1763 var = allocated_variable_expand (name); 1764 name = next_token (var); 1765 if (*name == '\0') 1766 fatal (&defstart, _("empty variable name")); 1767 p = name + strlen (name) - 1; 1768 while (p > name && isblank ((unsigned char)*p)) 1769 --p; 1770 p[1] = '\0'; 1771 1772 /* Now read the value of the variable. */ 1784 1773 while (1) 1785 1774 { 1786 1775 unsigned int len; 1787 1776 char *line; 1788 1789 nlines = readline (ebuf); 1777 long nlines = readline (ebuf); 1778 1779 /* If there is nothing left to be eval'd, there's no 'endef'!! */ 1780 if (nlines < 0) 1781 fatal (&defstart, _("missing `endef', unterminated `define'")); 1782 1790 1783 ebuf->floc.lineno += nlines; 1791 1792 /* If there is nothing left to eval, we're done. */1793 if (nlines < 0)1794 break;1795 1796 1784 line = ebuf->buffer; 1797 1785 … … 1803 1791 1804 1792 /* If the line doesn't begin with a tab, test to see if it introduces 1805 another define, or ends one. */ 1806 1807 /* Stop if we find an 'endef' */ 1793 another define, or ends one. Stop if we find an 'endef' */ 1808 1794 if (line[0] != cmd_prefix) 1809 1795 { … … 1832 1818 ebuf->eol = remove_comments (p, ebuf->eol); 1833 1819 #endif 1834 if (* next_token (p) != '\0')1820 if (*(next_token (p)) != '\0') 1835 1821 error (&ebuf->floc, 1836 _(" Extraneous text after `endef' directive"));1822 _("extraneous text after `endef' directive")); 1837 1823 1838 1824 if (--nlevels == 0) 1839 { 1840 /* Define the variable. */ 1841 if (idx == 0) 1842 definition[0] = '\0'; 1843 else 1844 definition[idx - 1] = '\0'; 1845 1846 /* Always define these variables in the global set. */ 1847 define_variable_global (var, strlen (var), definition, 1848 origin, 1, &defstart); 1849 free (definition); 1850 return; 1851 } 1825 break; 1852 1826 } 1853 1827 } 1854 1828 1855 /* Otherwise add this line to the variable definition. */1829 /* Add this line to the variable definition. */ 1856 1830 #ifndef CONFIG_WITH_VALUE_LENGTH 1857 1831 len = strlen (line); … … 1872 1846 } 1873 1847 1874 /* No `endef'!! */ 1875 fatal (&defstart, _("missing `endef', unterminated `define'")); 1876 1877 /* NOTREACHED */ 1878 return; 1848 /* We've got what we need; define the variable. */ 1849 if (idx == 0) 1850 definition[0] = '\0'; 1851 else 1852 definition[idx - 1] = '\0'; 1853 1854 v = do_variable_definition (&defstart, name, definition, origin, flavor, 0); 1855 free (definition); 1856 free (var); 1857 return (v); 1879 1858 } 1880 1859 … … 2267 2246 2268 2247 2269 /* Remove duplicate dependencies in CHAIN. */2270 #ifndef CONFIG_WITH_STRCACHE22271 2272 static unsigned long2273 dep_hash_1 (const void *key)2274 {2275 return_STRING_HASH_1 (dep_name ((struct dep const *) key));2276 }2277 2278 static unsigned long2279 dep_hash_2 (const void *key)2280 {2281 return_STRING_HASH_2 (dep_name ((struct dep const *) key));2282 }2283 2284 static int2285 dep_hash_cmp (const void *x, const void *y)2286 {2287 struct dep *dx = (struct dep *) x;2288 struct dep *dy = (struct dep *) y;2289 int cmp = strcmp (dep_name (dx), dep_name (dy));2290 2291 /* If the names are the same but ignore_mtimes are not equal, one of these2292 is an order-only prerequisite and one isn't. That means that we should2293 remove the one that isn't and keep the one that is. */2294 2295 if (!cmp && dx->ignore_mtime != dy->ignore_mtime)2296 dx->ignore_mtime = dy->ignore_mtime = 0;2297 2298 return cmp;2299 }2300 2301 #else /* CONFIG_WITH_STRCACHE2 */2302 2303 /* Exploit the fact that all names are in the string cache. This means equal2304 names shall have the same storage and there is no need for hashing or2305 comparing. Use the address as the first hash, avoiding any touching of2306 the name, and the length as the second. */2307 2308 static unsigned long2309 dep_hash_1 (const void *key)2310 {2311 const char *name = dep_name ((struct dep const *) key);2312 assert (strcache2_is_cached (&file_strcache, name));2313 return (size_t) name / sizeof(void *);2314 }2315 2316 static unsigned long2317 dep_hash_2 (const void *key)2318 {2319 const char *name = dep_name ((struct dep const *) key);2320 return strcache2_get_len (&file_strcache, name);2321 }2322 2323 static int2324 dep_hash_cmp (const void *x, const void *y)2325 {2326 struct dep *dx = (struct dep *) x;2327 struct dep *dy = (struct dep *) y;2328 const char *dxname = dep_name (dx);2329 const char *dyname = dep_name (dy);2330 int cmp = dxname == dyname ? 0 : 1;2331 2332 /* check preconds: both cached and the cache contains no duplicates. */2333 assert (strcache2_is_cached (&file_strcache, dxname));2334 assert (strcache2_is_cached (&file_strcache, dyname));2335 assert (cmp == 0 || strcmp (dxname, dyname) != 0);2336 2337 /* If the names are the same but ignore_mtimes are not equal, one of these2338 is an order-only prerequisite and one isn't. That means that we should2339 remove the one that isn't and keep the one that is. */2340 2341 if (!cmp && dx->ignore_mtime != dy->ignore_mtime)2342 dx->ignore_mtime = dy->ignore_mtime = 0;2343 2344 return cmp;2345 }2346 2347 #endif /* CONFIG_WITH_STRCACHE2 */2348 2349 void2350 uniquize_deps (struct dep *chain)2351 {2352 struct hash_table deps;2353 register struct dep **depp;2354 2355 hash_init (&deps, 500, dep_hash_1, dep_hash_2, dep_hash_cmp);2356 2357 /* Make sure that no dependencies are repeated. This does not2358 really matter for the purpose of updating targets, but it2359 might make some names be listed twice for $^ and $?. */2360 2361 depp = &chain;2362 while (*depp)2363 {2364 struct dep *dep = *depp;2365 struct dep **dep_slot = (struct dep **) hash_find_slot (&deps, dep);2366 if (HASH_VACANT (*dep_slot))2367 {2368 hash_insert_at (&deps, dep, dep_slot);2369 depp = &dep->next;2370 }2371 else2372 {2373 /* Don't bother freeing duplicates.2374 It's dangerous and little benefit accrues. */2375 *depp = dep->next;2376 }2377 }2378 2379 hash_free (&deps, 0);2380 }2381 2382 2383 2248 /* Record target-specific variable values for files FILENAMES. 2384 2249 TWO_COLON is nonzero if a double colon was used. … … 2392 2257 static void 2393 2258 record_target_var (struct nameseq *filenames, char *defn, 2394 enum variable_origin origin, int exported,2259 enum variable_origin origin, struct vmodifiers *vmod, 2395 2260 const struct floc *flocp) 2396 2261 { … … 2412 2277 2413 2278 nextf = filenames->next; 2414 #ifndef CONFIG_WITH_ALLOC_CACHES 2415 free (filenames); 2416 #else 2417 alloccache_free (&nameseq_cache, filenames); 2418 #endif 2279 free_ns (filenames); 2419 2280 2420 2281 /* If it's a pattern target, then add it to the pattern-specific … … 2428 2289 /* I don't think this can fail since we already determined it was a 2429 2290 variable definition. */ 2430 #ifndef CONFIG_WITH_VALUE_LENGTH 2431 v = parse_variable_definition (&p->variable, defn); 2432 #else 2433 v = parse_variable_definition (&p->variable, defn, NULL); 2434 #endif 2291 v = assign_variable_definition (&p->variable, defn IF_WITH_VALUE_LENGTH_PARAM(NULL)); 2435 2292 assert (v != 0); 2436 2293 2294 v->origin = origin; 2437 2295 if (v->flavor == f_simple) 2438 2296 v->value = allocated_variable_expand (v->value); … … 2468 2326 2469 2327 current_variable_set_list = f->variables; 2470 #ifndef CONFIG_WITH_VALUE_LENGTH 2471 v = try_variable_definition (flocp, defn, origin, 1); 2472 #else 2473 v = try_variable_definition (flocp, defn, NULL, origin, 1); 2474 #endif 2328 v = try_variable_definition (flocp, defn IF_WITH_VALUE_LENGTH_PARAM(NULL), origin, 1); 2475 2329 if (!v) 2476 error(flocp, _("Malformed target-specific variable definition"));2330 fatal (flocp, _("Malformed target-specific variable definition")); 2477 2331 current_variable_set_list = global; 2478 2332 } 2479 2333 2480 2334 /* Set up the variable to be *-specific. */ 2481 v->origin = origin;2482 2335 v->per_target = 1; 2483 v->export = exported ? v_export : v_default; 2336 v->private_var = vmod->private_v; 2337 v->export = vmod->export_v ? v_export : v_default; 2484 2338 2485 2339 /* If it's not an override, check to see if there was a command-line 2486 2340 setting. If so, reset the value. */ 2487 if ( origin != o_override)2341 if (v->origin != o_override) 2488 2342 { 2489 2343 struct variable *gv; … … 2507 2361 v->value = xstrdup (gv->value); 2508 2362 #else 2509 v->value = savestring(gv->value, gv->value_length);2363 v->value = xstrndup (gv->value, gv->value_length); 2510 2364 v->value_length = gv->value_length; 2511 2365 #endif … … 2530 2384 that are not incorporated into other data structures. */ 2531 2385 2532 #ifndef CONFIG_WITH_INCLUDEDEP2533 2386 static void 2534 #else2535 void2536 #endif2537 2387 record_files (struct nameseq *filenames, const char *pattern, 2538 const char *pattern_percent, struct dep *deps,2388 const char *pattern_percent, char *depstr, 2539 2389 unsigned int cmds_started, char *commands, 2540 2390 unsigned int commands_idx, int two_colon, 2541 2391 const struct floc *flocp) 2542 2392 { 2543 struct nameseq *nextf;2544 int implicit = 0;2545 unsigned int max_targets = 0, target_idx = 0;2546 const char **targets = 0, **target_percents = 0;2547 struct commands *cmds;2548 2393 #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET 2549 2394 struct file *prev_file = 0; … … 2551 2396 multi_mode = !two_colon && !pattern ? m_unsettled : m_no; 2552 2397 #endif 2398 struct commands *cmds; 2399 struct dep *deps; 2400 const char *implicit_percent; 2401 const char *name; 2553 2402 2554 2403 /* If we've already snapped deps, that means we're in an eval being … … 2559 2408 fatal (flocp, _("prerequisites cannot be defined in recipes")); 2560 2409 2410 /* Determine if this is a pattern rule or not. */ 2411 name = filenames->name; 2412 implicit_percent = find_percent_cached (&name); 2413 2414 /* If there's a recipe, set up a struct for it. */ 2561 2415 if (commands_idx > 0) 2562 2416 { … … 2568 2422 cmds->fileinfo.filenm = flocp->filenm; 2569 2423 cmds->fileinfo.lineno = cmds_started; 2570 cmds->commands = savestring(commands, commands_idx);2424 cmds->commands = xstrndup (commands, commands_idx); 2571 2425 cmds->command_lines = 0; 2572 2426 #ifdef CONFIG_WITH_MEMORY_OPTIMIZATIONS … … 2575 2429 } 2576 2430 else 2577 cmds = 0; 2578 2579 for (; filenames != 0; filenames = nextf) 2431 cmds = 0; 2432 2433 /* If there's a prereq string then parse it--unless it's eligible for 2nd 2434 expansion: if so, snap_deps() will do it. */ 2435 if (depstr == 0) 2436 deps = 0; 2437 else if (second_expansion && strchr (depstr, '$')) 2580 2438 { 2581 const char *name = filenames->name; 2439 deps = alloc_dep (); 2440 deps->name = depstr; 2441 deps->need_2nd_expansion = 1; 2442 deps->staticpattern = pattern != 0; 2443 } 2444 else 2445 { 2446 deps = split_prereqs (depstr); 2447 free (depstr); 2448 2449 /* We'll enter static pattern prereqs later when we have the stem. We 2450 don't want to enter pattern rules at all so that we don't think that 2451 they ought to exist (make manual "Implicit Rule Search Algorithm", 2452 item 5c). */ 2453 if (! pattern && ! implicit_percent) 2454 deps = enter_prereqs (deps, NULL); 2455 } 2456 2457 /* For implicit rules, _all_ the targets must have a pattern. That means we 2458 can test the first one to see if we're working with an implicit rule; if 2459 so we handle it specially. */ 2460 2461 if (implicit_percent) 2462 { 2463 struct nameseq *nextf; 2464 const char **targets, **target_pats; 2465 unsigned int c; 2466 2467 if (pattern != 0) 2468 fatal (flocp, _("mixed implicit and static pattern rules")); 2469 2470 /* Count the targets to create an array of target names. 2471 We already have the first one. */ 2472 nextf = filenames->next; 2473 free_ns (filenames); 2474 filenames = nextf; 2475 2476 for (c = 1; nextf; ++c, nextf = nextf->next) 2477 ; 2478 targets = xmalloc (c * sizeof (const char *)); 2479 target_pats = xmalloc (c * sizeof (const char *)); 2480 2481 targets[0] = name; 2482 target_pats[0] = implicit_percent; 2483 2484 c = 1; 2485 while (filenames) 2486 { 2487 name = filenames->name; 2488 implicit_percent = find_percent_cached (&name); 2489 2490 if (implicit_percent == 0) 2491 fatal (flocp, _("mixed implicit and normal rules")); 2492 2493 targets[c] = name; 2494 target_pats[c] = implicit_percent; 2495 ++c; 2496 2497 nextf = filenames->next; 2498 free_ns (filenames); 2499 filenames = nextf; 2500 } 2501 2502 create_pattern_rule (targets, target_pats, c, two_colon, deps, cmds, 1); 2503 2504 return; 2505 } 2506 2507 2508 /* Walk through each target and create it in the database. 2509 We already set up the first target, above. */ 2510 while (1) 2511 { 2512 struct nameseq *nextf = filenames->next; 2582 2513 struct file *f; 2583 2514 struct dep *this = 0; 2584 const char *implicit_percent; 2585 2586 nextf = filenames->next; 2587 #ifndef CONFIG_WITH_ALLOC_CACHES 2588 free (filenames); 2589 #else 2590 alloccache_free (&nameseq_cache, filenames); 2591 #endif 2515 2516 free_ns (filenames); 2592 2517 2593 2518 /* Check for special targets. Do it here instead of, say, snap_deps() 2594 2519 so that we can immediately use the value. */ 2595 2596 2520 if (streq (name, ".POSIX")) 2597 posix_pedantic = 1; 2521 { 2522 posix_pedantic = 1; 2523 define_variable_cname (".SHELLFLAGS", "-ec", o_default, 0); 2524 } 2598 2525 else if (streq (name, ".SECONDEXPANSION")) 2599 2526 second_expansion = 1; … … 2602 2529 second_target_expansion = 1; 2603 2530 #endif 2604 2605 implicit_percent = find_percent_cached (&name); 2606 implicit |= implicit_percent != 0; 2607 2608 if (implicit) 2609 { 2610 if (pattern != 0) 2611 fatal (flocp, _("mixed implicit and static pattern rules")); 2612 2613 if (implicit_percent == 0) 2614 fatal (flocp, _("mixed implicit and normal rules")); 2615 2616 if (targets == 0) 2617 { 2618 max_targets = 5; 2619 targets = xmalloc (5 * sizeof (char *)); 2620 target_percents = xmalloc (5 * sizeof (char *)); 2621 target_idx = 0; 2622 } 2623 else if (target_idx == max_targets - 1) 2624 { 2625 max_targets += 5; 2626 targets = xrealloc ((void *)targets, max_targets * sizeof (char *)); 2627 target_percents = xrealloc ((void *)target_percents, 2628 max_targets * sizeof (char *)); 2629 } 2630 targets[target_idx] = name; 2631 target_percents[target_idx] = implicit_percent; 2632 ++target_idx; 2633 continue; 2634 } 2531 #if !defined(WINDOWS32) && !defined (__MSDOS__) && !defined (__EMX__) 2532 else if (streq (name, ".ONESHELL")) 2533 one_shell = 1; 2534 #endif 2635 2535 2636 2536 #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET … … 2670 2570 } 2671 2571 multi_mode = name[1] == '\0' ? m_yes : m_yes_maybe; 2672 continue;2572 goto l_next; 2673 2573 } 2674 2574 } … … 2678 2578 2679 2579 /* If this is a static pattern rule: 2680 `targets: target%pattern: dep%pattern; cmds',2580 `targets: target%pattern: prereq%pattern; recipe', 2681 2581 make sure the pattern matches this target name. */ 2682 2582 if (pattern && !pattern_matches (pattern, pattern_percent, name)) 2683 2583 error (flocp, _("target `%s' doesn't match the target pattern"), name); 2684 2584 else if (deps) 2685 { 2686 /* If there are multiple filenames, copy the chain DEPS for all but 2687 the last one. It is not safe for the same deps to go in more 2688 than one place in the database. */ 2689 this = nextf != 0 ? copy_dep_chain (deps) : deps; 2690 this->need_2nd_expansion = (second_expansion 2691 && strchr (this->name, '$')); 2692 } 2693 2585 /* If there are multiple targets, copy the chain DEPS for all but the 2586 last one. It is not safe for the same deps to go in more than one 2587 place in the database. */ 2588 this = nextf != 0 ? copy_dep_chain (deps) : deps; 2589 2590 /* Find or create an entry in the file database for this target. */ 2694 2591 if (!two_colon) 2695 2592 { 2696 /* Single-colon. Combine th ese dependencies2697 with others in file's existing record,if any. */2593 /* Single-colon. Combine this rule with the file's existing record, 2594 if any. */ 2698 2595 #ifndef KMK 2699 2596 f = enter_file (strcache_add (name)); … … 2701 2598 f = enter_file (name); 2702 2599 #endif 2703 2704 2600 if (f->double_colon) 2705 2601 fatal (flocp, … … 2726 2622 } 2727 2623 2728 f->is_target = 1;2729 2730 2624 /* Defining .DEFAULT with no deps or cmds clears it. */ 2731 2625 if (f == default_file && this == 0 && cmds == 0) … … 2759 2653 free_dep_chain (f->deps); 2760 2654 f->deps = 0; 2761 }2762 else if (this != 0)2763 {2764 /* Add the file's old deps and the new ones in THIS together. */2765 2766 if (f->deps != 0)2767 {2768 struct dep **d_ptr = &f->deps;2769 2770 while ((*d_ptr)->next != 0)2771 d_ptr = &(*d_ptr)->next;2772 2773 if (cmds != 0)2774 /* This is the rule with commands, so put its deps2775 last. The rationale behind this is that $< expands to2776 the first dep in the chain, and commands use $<2777 expecting to get the dep that rule specifies. However2778 the second expansion algorithm reverses the order thus2779 we need to make it last here. */2780 (*d_ptr)->next = this;2781 else2782 {2783 /* This is the rule without commands. Put its2784 dependencies at the end but before dependencies from2785 the rule with commands (if any). This way everything2786 appears in makefile order. */2787 2788 if (f->cmds != 0)2789 {2790 #ifndef KMK /* bugfix: Don't chop the chain! */2791 this->next = *d_ptr;2792 *d_ptr = this;2793 #else /* KMK */2794 struct dep *this_last = this;2795 while (this_last->next)2796 this_last = this_last->next;2797 this_last->next = *d_ptr;2798 *d_ptr = this;2799 #endif /* KMK */2800 }2801 else2802 (*d_ptr)->next = this;2803 }2804 }2805 else2806 f->deps = this;2807 2808 /* This is a hack. I need a way to communicate to snap_deps()2809 that the last dependency line in this file came with commands2810 (so that logic in snap_deps() can put it in front and all2811 this $< -logic works). I cannot simply rely on file->cmds2812 being not 0 because of the cases like the following:2813 2814 foo: bar2815 foo:2816 ...2817 2818 I am going to temporarily "borrow" UPDATING member in2819 `struct file' for this. */2820 2821 if (cmds != 0)2822 f->updating = 1;2823 2655 } 2824 2656 } … … 2832 2664 #endif /* CONFIG_WITH_STRCACHE2 */ 2833 2665 2834 /* Check for both : and :: rules. Check is_target so 2835 we don't loseon default suffix rules or makefiles. */2666 /* Check for both : and :: rules. Check is_target so we don't lose 2667 on default suffix rules or makefiles. */ 2836 2668 if (f != 0 && f->is_target && !f->double_colon) 2837 2669 fatal (flocp, 2838 2670 _("target file `%s' has both : and :: entries"), f->name); 2671 2839 2672 #ifndef KMK 2840 2673 f = enter_file (strcache_add (name)); … … 2850 2683 double_colon pointer to itself. */ 2851 2684 f->double_colon = f; 2852 f->is_target = 1; 2853 f->deps = this; 2685 2854 2686 f->cmds = cmds; 2855 2687 } 2856 2688 2689 f->is_target = 1; 2690 2857 2691 /* If this is a static pattern rule, set the stem to the part of its 2858 2692 name that matched the `%' in the pattern, so you can use $* in the 2859 commands. */2693 commands. If we didn't do it before, enter the prereqs now. */ 2860 2694 if (pattern) 2861 2695 { … … 2869 2703 if (this) 2870 2704 { 2871 this->staticpattern = 1; 2872 this->stem = f->stem; 2705 if (! this->need_2nd_expansion) 2706 this = enter_prereqs (this, f->stem); 2707 else 2708 this->stem = f->stem; 2873 2709 } 2874 2710 } 2875 2711 2712 /* Add the dependencies to this file entry. */ 2713 if (this != 0) 2714 { 2715 /* Add the file's old deps and the new ones in THIS together. */ 2716 if (f->deps == 0) 2717 f->deps = this; 2718 else if (cmds != 0) 2719 { 2720 struct dep *d = this; 2721 2722 /* If this rule has commands, put these deps first. */ 2723 while (d->next != 0) 2724 d = d->next; 2725 2726 d->next = f->deps; 2727 f->deps = this; 2728 } 2729 else 2730 { 2731 struct dep *d = f->deps; 2732 2733 /* A rule without commands: put its prereqs at the end. */ 2734 while (d->next != 0) 2735 d = d->next; 2736 2737 d->next = this; 2738 } 2739 } 2740 2876 2741 name = f->name; 2877 2742 2878 /* If this target is a default target, update DEFAULT_GOAL_FILE. */ 2879 if (streq (*default_goal_name, name) 2880 && (default_goal_file == 0 2881 || ! streq (default_goal_file->name, name)))2882 default_goal_file = f;2883 }2884 2885 if (implicit)2886 { 2887 if (deps)2888 deps->need_2nd_expansion = second_expansion;2889 create_pattern_rule (targets, target_percents, target_idx,2890 two_colon, deps, cmds, 1);2743 #ifdef CONFIG_WITH_EXPLICIT_MULTITARGET 2744 l_next: 2745 #endif 2746 /* All done! Set up for the next one. */ 2747 if (nextf == 0) 2748 break; 2749 2750 filenames = nextf; 2751 2752 /* Reduce escaped percents. If there are any unescaped it's an error */ 2753 name = filenames->name; 2754 if (find_percent_cached (&name)) 2755 fatal (flocp, _("mixed implicit and normal rules")); 2891 2756 } 2892 2757 } … … 3111 2976 3112 2977 3113 /* Parse a string into a sequence of filenames represented as a3114 chain of struct nameseq's in reverse order and return that chain.3115 3116 The string is passed as STRINGP, the address of a string pointer.3117 The string pointer is updated to point at the first character3118 not parsed, which either is a null char or equals STOPCHAR.3119 3120 SIZE is how big to construct chain elements.3121 This is useful if we want them actually to be other structures3122 that have room for additional info.3123 3124 If STRIP is nonzero, strip `./'s off the beginning. */3125 3126 #ifndef CONFIG_WITH_ALLOC_CACHES3127 struct nameseq *3128 parse_file_seq (char **stringp, int stopchar, unsigned int size, int strip)3129 #else3130 struct nameseq *3131 parse_file_seq (char **stringp, int stopchar, struct alloccache *cache, int strip)3132 #endif3133 {3134 struct nameseq *new = 0;3135 struct nameseq *new1;3136 #ifndef NO_ARCHIVES /* bird: MSC warning */3137 struct nameseq *lastnew1;3138 #endif3139 char *p = *stringp;3140 3141 #ifdef VMS3142 # define VMS_COMMA ','3143 #else3144 # define VMS_COMMA 03145 #endif3146 3147 while (1)3148 {3149 const char *name;3150 char *q;3151 3152 /* Skip whitespace; see if any more names are left. */3153 p = next_token (p);3154 if (*p == '\0')3155 break;3156 if (*p == stopchar)3157 break;3158 3159 /* There are, so find the end of the next name. */3160 q = p;3161 p = find_char_unquote (q, stopchar, VMS_COMMA, 1, 0);3162 #ifdef VMS3163 /* convert comma separated list to space separated */3164 if (p && *p == ',')3165 *p =' ';3166 #endif3167 #ifdef _AMIGA3168 if (stopchar == ':' && p && *p == ':'3169 && !(isspace ((unsigned char)p[1]) || !p[1]3170 || isspace ((unsigned char)p[-1])))3171 p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0);3172 #endif3173 #ifdef HAVE_DOS_PATHS3174 /* For DOS paths, skip a "C:\..." or a "C:/..." until we find the3175 first colon which isn't followed by a slash or a backslash.3176 Note that tokens separated by spaces should be treated as separate3177 tokens since make doesn't allow path names with spaces */3178 if (stopchar == ':')3179 while (p != 0 && !isspace ((unsigned char)*p) &&3180 (p[1] == '\\' || p[1] == '/') && isalpha ((unsigned char)p[-1]))3181 p = find_char_unquote (p + 1, stopchar, VMS_COMMA, 1, 0);3182 #endif3183 if (p == 0)3184 p = q + strlen (q);3185 3186 if (strip)3187 #ifdef VMS3188 /* Skip leading `[]'s. */3189 while (p - q > 2 && q[0] == '[' && q[1] == ']')3190 #else3191 /* Skip leading `./'s. */3192 while (p - q > 2 && q[0] == '.' && q[1] == '/')3193 #endif3194 {3195 q += 2; /* Skip "./". */3196 while (q < p && *q == '/')3197 /* Skip following slashes: ".//foo" is "foo", not "/foo". */3198 ++q;3199 }3200 3201 /* Extract the filename just found, and skip it. */3202 3203 if (q == p)3204 /* ".///" was stripped to "". */3205 #if defined(VMS)3206 continue;3207 #elif defined(_AMIGA)3208 name = "";3209 #else3210 name = "./";3211 #endif3212 else3213 #ifdef VMS3214 /* VMS filenames can have a ':' in them but they have to be '\'ed but we need3215 * to remove this '\' before we can use the filename.3216 * Savestring called because q may be read-only string constant.3217 */3218 {3219 char *qbase = xstrdup (q);3220 char *pbase = qbase + (p-q);3221 char *q1 = qbase;3222 char *q2 = q1;3223 char *p1 = pbase;3224 3225 while (q1 != pbase)3226 {3227 if (*q1 == '\\' && *(q1+1) == ':')3228 {3229 q1++;3230 p1--;3231 }3232 *q2++ = *q1++;3233 }3234 name = strcache_add_len (qbase, p1 - qbase);3235 free (qbase);3236 }3237 #elif !defined (CONFIG_WITH_VALUE_LENGTH) || defined (CONFIG_WITH_STRCACHE2)3238 name = strcache_add_len (q, p - q);3239 #else /* CONFIG_WITH_VALUE_LENGTH */3240 {3241 /* Make sure it's terminated, strcache_add_len has to make a3242 temp copy on the stack otherwise. */3243 char saved = *p;3244 if (!saved)3245 *p = '\0';3246 name = strcache_add_len (q, p - q);3247 if (saved)3248 *p = saved;3249 }3250 #endif /* CONFIG_WITH_VALUE_LENGTH */3251 3252 /* Add it to the front of the chain. */3253 #ifndef CONFIG_WITH_ALLOC_CACHES3254 new1 = xmalloc (size);3255 memset (new1, '\0', size);3256 #else3257 new1 = (struct nameseq *) alloccache_calloc (cache);3258 #endif3259 new1->name = name;3260 new1->next = new;3261 new = new1;3262 }3263 3264 #ifndef NO_ARCHIVES3265 3266 /* Look for multi-word archive references.3267 They are indicated by a elt ending with an unmatched `)' and3268 an elt further down the chain (i.e., previous in the file list)3269 with an unmatched `(' (e.g., "lib(mem"). */3270 3271 new1 = new;3272 lastnew1 = 0;3273 while (new1 != 0)3274 if (new1->name[0] != '(' /* Don't catch "(%)" and suchlike. */3275 && new1->name[strlen (new1->name) - 1] == ')'3276 && strchr (new1->name, '(') == 0)3277 {3278 /* NEW1 ends with a `)' but does not contain a `('.3279 Look back for an elt with an opening `(' but no closing `)'. */3280 3281 struct nameseq *n = new1->next, *lastn = new1;3282 char *paren = 0;3283 while (n != 0 && (paren = strchr (n->name, '(')) == 0)3284 {3285 lastn = n;3286 n = n->next;3287 }3288 if (n != 03289 /* Ignore something starting with `(', as that cannot actually3290 be an archive-member reference (and treating it as such3291 results in an empty file name, which causes much lossage). */3292 && n->name[0] != '(')3293 {3294 /* N is the first element in the archive group.3295 Its name looks like "lib(mem" (with no closing `)'). */3296 3297 char *libname;3298 3299 /* Copy "lib(" into LIBNAME. */3300 ++paren;3301 libname = alloca (paren - n->name + 1);3302 memcpy (libname, n->name, paren - n->name);3303 libname[paren - n->name] = '\0';3304 3305 if (*paren == '\0')3306 {3307 /* N was just "lib(", part of something like "lib( a b)".3308 Edit it out of the chain and free its storage. */3309 lastn->next = n->next;3310 #ifndef CONFIG_WITH_ALLOC_CACHES3311 free (n);3312 #else3313 alloccache_free (cache, n);3314 #endif3315 /* LASTN->next is the new stopping elt for the loop below. */3316 n = lastn->next;3317 }3318 else3319 {3320 /* Replace N's name with the full archive reference. */3321 n->name = strcache_add (concat (libname, paren, ")"));3322 }3323 3324 if (new1->name[1] == '\0')3325 {3326 /* NEW1 is just ")", part of something like "lib(a b )".3327 Omit it from the chain and free its storage. */3328 if (lastnew1 == 0)3329 new = new1->next;3330 else3331 lastnew1->next = new1->next;3332 lastn = new1;3333 new1 = new1->next;3334 #ifndef CONFIG_WITH_ALLOC_CACHES3335 free (lastn);3336 #else3337 alloccache_free (cache, lastn);3338 #endif3339 }3340 else3341 {3342 /* Replace also NEW1->name, which already has closing `)'. */3343 new1->name = strcache_add (concat (libname, new1->name, ""));3344 new1 = new1->next;3345 }3346 3347 /* Trace back from NEW1 (the end of the list) until N3348 (the beginning of the list), rewriting each name3349 with the full archive reference. */3350 3351 while (new1 != n)3352 {3353 new1->name = strcache_add (concat (libname, new1->name, ")"));3354 lastnew1 = new1;3355 new1 = new1->next;3356 }3357 }3358 else3359 {3360 /* No frobnication happening. Just step down the list. */3361 lastnew1 = new1;3362 new1 = new1->next;3363 }3364 }3365 else3366 {3367 lastnew1 = new1;3368 new1 = new1->next;3369 }3370 3371 #endif3372 3373 *stringp = p;3374 return new;3375 }3376 3377 3378 2978 /* Find the next line of text in an eval buffer, combining continuation lines 3379 2979 into one line. … … 3412 3012 { 3413 3013 int backslash = 0; 3414 c har *bol = eol;3415 c har *p;3014 const char *bol = eol; 3015 const char *p; 3416 3016 3417 3017 /* Find the next newline. At EOS, stop. */ 3418 3018 #ifndef CONFIG_WITH_VALUE_LENGTH 3419 eol = p= strchr (eol , '\n');3019 p = eol = strchr (eol , '\n'); 3420 3020 #else 3421 3021 p = (char *)memchr (eol, '\n', end - eol); 3422 3022 assert (!memchr (eol, '\0', p != 0 ? p - eol : end - eol)); 3423 eol = p;3023 eol = (char *)p; 3424 3024 #endif 3425 3025 if (!eol) … … 3933 3533 if (home_dir != 0) 3934 3534 { 3935 char *new = xstrdup (concat ( home_dir, "", name + 1));3535 char *new = xstrdup (concat (2, home_dir, name + 1)); 3936 3536 if (is_variable) 3937 3537 free (home_dir); … … 3952 3552 return xstrdup (pwent->pw_dir); 3953 3553 else 3954 return xstrdup (concat ( pwent->pw_dir, "/", userend + 1));3554 return xstrdup (concat (3, pwent->pw_dir, "/", userend + 1)); 3955 3555 } 3956 3556 else if (userend != 0) … … 3962 3562 } 3963 3563 3964 /* Given a chain of struct nameseq's describing a sequence of filenames, 3965 in reverse of the intended order, return a new chain describing the 3966 result of globbing the filenames. The new chain is in forward order. 3967 The links of the old chain are freed or used in the new chain. 3968 Likewise for the names in the old chain. 3564 3565 /* Parse a string into a sequence of filenames represented as a chain of 3566 struct nameseq's and return that chain. Optionally expand the strings via 3567 glob(). 3568 3569 The string is passed as STRINGP, the address of a string pointer. 3570 The string pointer is updated to point at the first character 3571 not parsed, which either is a null char or equals STOPCHAR. 3969 3572 3970 3573 SIZE is how big to construct chain elements. 3971 3574 This is useful if we want them actually to be other structures 3972 that have room for additional info. */ 3973 3575 that have room for additional info. 3576 3577 PREFIX, if non-null, is added to the beginning of each filename. 3578 3579 FLAGS allows one or more of the following bitflags to be set: 3580 PARSEFS_NOSTRIP - Do no strip './'s off the beginning 3581 PARSEFS_NOAR - Do not check filenames for archive references 3582 PARSEFS_NOGLOB - Do not expand globbing characters 3583 PARSEFS_EXISTS - Only return globbed files that actually exist 3584 (cannot also set NOGLOB) 3585 PARSEFS_NOCACHE - Do not add filenames to the strcache (caller frees) 3586 */ 3587 3588 void * 3589 parse_file_seq (char **stringp, unsigned int size, int stopchar, 3590 const char *prefix, int flags 3591 IF_WITH_ALLOC_CACHES_PARAM(struct alloccache *alloc_cache) ) 3592 { 3593 extern void dir_setup_glob (glob_t *glob); 3594 3595 /* tmp points to tmpbuf after the prefix, if any. 3596 tp is the end of the buffer. */ 3597 static char *tmpbuf = NULL; 3598 static int tmpbuf_len = 0; 3599 3600 int cachep = (! (flags & PARSEFS_NOCACHE)); 3601 3602 struct nameseq *new = 0; 3603 struct nameseq **newp = &new; 3974 3604 #ifndef CONFIG_WITH_ALLOC_CACHES 3975 struct nameseq * 3976 multi_glob (struct nameseq *chain, unsigned int size) 3977 #else 3978 struct nameseq * 3979 multi_glob (struct nameseq *chain, struct alloccache *cache) 3980 #endif 3981 { 3982 void dir_setup_glob (glob_t *); 3983 struct nameseq *new = 0; 3984 struct nameseq *old; 3985 struct nameseq *nexto; 3605 #define NEWELT(_n) do { \ 3606 const char *__n = (_n); \ 3607 *newp = xcalloc (size); \ 3608 (*newp)->name = (cachep ? strcache_add (__n) : xstrdup (__n)); \ 3609 newp = &(*newp)->next; \ 3610 } while(0) 3611 #else 3612 # define NEWELT(_n) do { \ 3613 const char *__n = (_n); \ 3614 *newp = alloccache_calloc (alloc_cache); \ 3615 (*newp)->name = (cachep ? strcache_add (__n) : xstrdup (__n)); \ 3616 newp = &(*newp)->next; \ 3617 } while(0) 3618 #endif 3619 3620 char *p; 3986 3621 glob_t gl; 3987 #if defined(KMK) || defined(__EMX__) /* speed optimization */ 3988 int rc; 3989 #endif 3990 3991 dir_setup_glob (&gl); 3992 3993 for (old = chain; old != 0; old = nexto) 3622 char *tp; 3623 3624 #ifdef VMS 3625 # define VMS_COMMA ',' 3626 #else 3627 # define VMS_COMMA 0 3628 #endif 3629 3630 if (size < sizeof (struct nameseq)) 3631 size = sizeof (struct nameseq); 3632 3633 if (! (flags & PARSEFS_NOGLOB)) 3634 dir_setup_glob (&gl); 3635 3636 /* Get enough temporary space to construct the largest possible target. */ 3637 { 3638 int l = strlen (*stringp) + 1; 3639 if (l > tmpbuf_len) 3640 { 3641 tmpbuf = xrealloc (tmpbuf, l); 3642 tmpbuf_len = l; 3643 } 3644 } 3645 tp = tmpbuf; 3646 3647 /* Parse STRING. P will always point to the end of the parsed content. */ 3648 p = *stringp; 3649 while (1) 3994 3650 { 3995 const char *gname; 3651 const char *name; 3652 const char **nlist = 0; 3653 char *tildep = 0; 3996 3654 #ifndef NO_ARCHIVES 3997 3655 char *arname = 0; 3998 3656 char *memname = 0; 3999 3657 #endif 4000 nexto = old->next; 4001 gname = old->name; 4002 4003 if (gname[0] == '~') 3658 char *s; 3659 int nlen; 3660 int i; 3661 3662 /* Skip whitespace; at the end of the string or STOPCHAR we're done. */ 3663 p = next_token (p); 3664 if (*p == '\0' || *p == stopchar) 3665 break; 3666 3667 /* There are names left, so find the end of the next name. 3668 Throughout this iteration S points to the start. */ 3669 s = p; 3670 p = find_char_unquote (p, stopchar, VMS_COMMA, 1, 0); 3671 #ifdef VMS 3672 /* convert comma separated list to space separated */ 3673 if (p && *p == ',') 3674 *p =' '; 3675 #endif 3676 #ifdef _AMIGA 3677 if (stopchar == ':' && p && *p == ':' 3678 && !(isspace ((unsigned char)p[1]) || !p[1] 3679 || isspace ((unsigned char)p[-1]))) 3680 p = find_char_unquote (p+1, stopchar, VMS_COMMA, 1, 0); 3681 #endif 3682 #ifdef HAVE_DOS_PATHS 3683 /* For DOS paths, skip a "C:\..." or a "C:/..." until we find the 3684 first colon which isn't followed by a slash or a backslash. 3685 Note that tokens separated by spaces should be treated as separate 3686 tokens since make doesn't allow path names with spaces */ 3687 if (stopchar == ':') 3688 while (p != 0 && !isspace ((unsigned char)*p) && 3689 (p[1] == '\\' || p[1] == '/') && isalpha ((unsigned char)p[-1])) 3690 p = find_char_unquote (p + 1, stopchar, VMS_COMMA, 1, 0); 3691 #endif 3692 if (p == 0) 3693 p = s + strlen (s); 3694 3695 /* Strip leading "this directory" references. */ 3696 if (! (flags & PARSEFS_NOSTRIP)) 3697 #ifdef VMS 3698 /* Skip leading `[]'s. */ 3699 while (p - s > 2 && s[0] == '[' && s[1] == ']') 3700 #else 3701 /* Skip leading `./'s. */ 3702 while (p - s > 2 && s[0] == '.' && s[1] == '/') 3703 #endif 3704 { 3705 /* Skip "./" and all following slashes. */ 3706 s += 2; 3707 while (*s == '/') 3708 ++s; 3709 } 3710 3711 /* Extract the filename just found, and skip it. 3712 Set NAME to the string, and NLEN to its length. */ 3713 3714 if (s == p) 3715 { 3716 /* The name was stripped to empty ("./"). */ 3717 #if defined(VMS) 3718 continue; 3719 #elif defined(_AMIGA) 3720 /* PDS-- This cannot be right!! */ 3721 tp[0] = '\0'; 3722 nlen = 0; 3723 #else 3724 tp[0] = '.'; 3725 tp[1] = '/'; 3726 tp[2] = '\0'; 3727 nlen = 2; 3728 #endif 3729 } 3730 else 4004 3731 { 4005 char *newname = tilde_expand (old->name); 4006 if (newname != 0) 4007 gname = newname; 3732 #ifdef VMS 3733 /* VMS filenames can have a ':' in them but they have to be '\'ed but we need 3734 * to remove this '\' before we can use the filename. 3735 * xstrdup called because S may be read-only string constant. 3736 */ 3737 char *n = tp; 3738 while (s < p) 3739 { 3740 if (s[0] == '\\' && s[1] == ':') 3741 ++s; 3742 *(n++) = *(s++); 3743 } 3744 n[0] = '\0'; 3745 nlen = strlen (tp); 3746 #else 3747 nlen = p - s; 3748 memcpy (tp, s, nlen); 3749 tp[nlen] = '\0'; 3750 #endif 3751 } 3752 3753 /* At this point, TP points to the element and NLEN is its length. */ 3754 3755 #ifndef NO_ARCHIVES 3756 /* If this is the start of an archive group that isn't complete, set up 3757 to add the archive prefix for future files. A file list like: 3758 "libf.a(x.o y.o z.o)" needs to be expanded as: 3759 "libf.a(x.o) libf.a(y.o) libf.a(z.o)" 3760 3761 TP == TMP means we're not already in an archive group. Ignore 3762 something starting with `(', as that cannot actually be an 3763 archive-member reference (and treating it as such results in an empty 3764 file name, which causes much lossage). Also if it ends in ")" then 3765 it's a complete reference so we don't need to treat it specially. 3766 3767 Finally, note that archive groups must end with ')' as the last 3768 character, so ensure there's some word ending like that before 3769 considering this an archive group. */ 3770 if (! (flags & PARSEFS_NOAR) 3771 && tp == tmpbuf && tp[0] != '(' && tp[nlen-1] != ')') 3772 { 3773 char *n = strchr (tp, '('); 3774 if (n) 3775 { 3776 /* This looks like the first element in an open archive group. 3777 A valid group MUST have ')' as the last character. */ 3778 const char *e = p + nlen; 3779 do 3780 { 3781 e = next_token (e); 3782 /* Find the end of this word. We don't want to unquote and 3783 we don't care about quoting since we're looking for the 3784 last char in the word. */ 3785 while (*e != '\0' && *e != stopchar && *e != VMS_COMMA 3786 && ! isblank ((unsigned char) *e)) 3787 ++e; 3788 if (e[-1] == ')') 3789 { 3790 /* Found the end, so this is the first element in an 3791 open archive group. It looks like "lib(mem". 3792 Reset TP past the open paren. */ 3793 nlen -= (n + 1) - tp; 3794 tp = n + 1; 3795 3796 /* If we have just "lib(", part of something like 3797 "lib( a b)", go to the next item. */ 3798 if (! nlen) 3799 continue; 3800 3801 /* We can stop looking now. */ 3802 break; 3803 } 3804 } 3805 while (*e != '\0'); 3806 } 3807 } 3808 3809 /* If we are inside an archive group, make sure it has an end. */ 3810 if (tp > tmpbuf) 3811 { 3812 if (tp[nlen-1] == ')') 3813 { 3814 /* This is the natural end; reset TP. */ 3815 tp = tmpbuf; 3816 3817 /* This is just ")", something like "lib(a b )": skip it. */ 3818 if (nlen == 1) 3819 continue; 3820 } 3821 else 3822 { 3823 /* Not the end, so add a "fake" end. */ 3824 tp[nlen++] = ')'; 3825 tp[nlen] = '\0'; 3826 } 3827 } 3828 #endif 3829 3830 /* If we're not globbing we're done: add it to the end of the chain. 3831 Go to the next item in the string. */ 3832 if (flags & PARSEFS_NOGLOB) 3833 { 3834 NEWELT (concat (2, prefix, tp)); 3835 continue; 3836 } 3837 3838 /* If we get here we know we're doing glob expansion. 3839 TP is a string in tmpbuf. NLEN is no longer used. 3840 We may need to do more work: after this NAME will be set. */ 3841 name = tp; 3842 3843 /* Expand tilde if applicable. */ 3844 if (tp[0] == '~') 3845 { 3846 tildep = tilde_expand (tp); 3847 if (tildep != 0) 3848 name = tildep; 4008 3849 } 4009 3850 4010 3851 #ifndef NO_ARCHIVES 4011 if (ar_name (gname)) 3852 /* If NAME is an archive member reference replace it with the archive 3853 file name, and save the member name in MEMNAME. We will glob on the 3854 archive name and then reattach MEMNAME later. */ 3855 if (! (flags & PARSEFS_NOAR) && ar_name (name)) 4012 3856 { 4013 /* OLD->name is an archive member reference. Replace it with the 4014 archive file name, and save the member name in MEMNAME. We will 4015 glob on the archive name and then reattach MEMNAME later. */ 4016 ar_parse_name (gname, &arname, &memname); 4017 gname = arname; 3857 ar_parse_name (name, &arname, &memname); 3858 name = arname; 4018 3859 } 4019 3860 #endif /* !NO_ARCHIVES */ 4020 3861 4021 #if defined(KMK) || defined(__EMX__) /* speed optimization */ 4022 if (!strpbrk(gname, "*?[")) 4023 { 4024 gl.gl_pathc = 1; 4025 gl.gl_pathv = (char **)&gname; 4026 rc = 0; 4027 } 4028 else 4029 rc = glob (gname, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl); 4030 switch (rc) 4031 #else 4032 switch (glob (gname, GLOB_NOCHECK|GLOB_ALTDIRFUNC, NULL, &gl)) 4033 #endif 3862 switch (glob (name, GLOB_NOSORT|GLOB_ALTDIRFUNC, NULL, &gl)) 4034 3863 { 4035 case 0: /* Success. */4036 {4037 int i = gl.gl_pathc;4038 while (i-- > 0)4039 {4040 #ifndef NO_ARCHIVES4041 if (memname != 0)4042 {4043 /* Try to glob on MEMNAME within the archive. */4044 struct nameseq *found4045 = ar_glob (gl.gl_pathv[i], memname, size);4046 if (! found)4047 {4048 /* No matches. Use MEMNAME as-is. */4049 unsigned int alen = strlen (gl.gl_pathv[i]);4050 unsigned int mlen = strlen (memname);4051 char *name;4052 struct nameseq *elt = xmalloc (size);4053 memset (elt, '\0', size);4054 4055 name = alloca (alen + 1 + mlen + 2);4056 memcpy (name, gl.gl_pathv[i], alen);4057 name[alen] = '(';4058 memcpy (name+alen+1, memname, mlen);4059 name[alen + 1 + mlen] = ')';4060 name[alen + 1 + mlen + 1] = '\0';4061 elt->name = strcache_add (name);4062 elt->next = new;4063 new = elt;4064 }4065 else4066 {4067 /* Find the end of the FOUND chain. */4068 struct nameseq *f = found;4069 while (f->next != 0)4070 f = f->next;4071 4072 /* Attach the chain being built to the end of the FOUND4073 chain, and make FOUND the new NEW chain. */4074 f->next = new;4075 new = found;4076 }4077 }4078 else4079 #endif /* !NO_ARCHIVES */4080 {4081 #ifndef CONFIG_WITH_ALLOC_CACHES4082 struct nameseq *elt = xmalloc (size);4083 memset (elt, '\0', size);4084 #else4085 struct nameseq *elt = alloccache_calloc (cache);4086 #endif4087 elt->name = strcache_add (gl.gl_pathv[i]);4088 elt->next = new;4089 new = elt;4090 }4091 }4092 #if defined(KMK) || defined(__EMX__) /* speed optimization */4093 if (gl.gl_pathv != (char **)&gname)4094 #endif4095 globfree (&gl);4096 #ifndef CONFIG_WITH_ALLOC_CACHES4097 free (old);4098 #else4099 alloccache_free (cache, old);4100 #endif4101 break;4102 }4103 4104 3864 case GLOB_NOSPACE: 4105 3865 fatal (NILF, _("virtual memory exhausted")); 4106 break; 3866 3867 case 0: 3868 /* Success. */ 3869 i = gl.gl_pathc; 3870 nlist = (const char **)gl.gl_pathv; 3871 break; 3872 3873 case GLOB_NOMATCH: 3874 /* If we want only existing items, skip this one. */ 3875 if (flags & PARSEFS_EXISTS) 3876 { 3877 i = 0; 3878 break; 3879 } 3880 /* FALLTHROUGH */ 4107 3881 4108 3882 default: 4109 old->next = new; 4110 new = old; 4111 break; 3883 /* By default keep this name. */ 3884 i = 1; 3885 nlist = &name; 3886 break; 4112 3887 } 3888 3889 /* For each matched element, add it to the list. */ 3890 while (i-- > 0) 3891 #ifndef NO_ARCHIVES 3892 if (memname != 0) 3893 { 3894 /* Try to glob on MEMNAME within the archive. */ 3895 struct nameseq *found = ar_glob (nlist[i], memname, size); 3896 if (! found) 3897 /* No matches. Use MEMNAME as-is. */ 3898 NEWELT (concat (5, prefix, nlist[i], "(", memname, ")")); 3899 else 3900 { 3901 /* We got a chain of items. Attach them. */ 3902 (*newp)->next = found; 3903 3904 /* Find and set the new end. Massage names if necessary. */ 3905 while (1) 3906 { 3907 if (! cachep) 3908 found->name = xstrdup (concat (2, prefix, name)); 3909 else if (prefix) 3910 found->name = strcache_add (concat (2, prefix, name)); 3911 3912 if (found->next == 0) 3913 break; 3914 3915 found = found->next; 3916 } 3917 newp = &found->next; 3918 } 3919 } 3920 else 3921 #endif /* !NO_ARCHIVES */ 3922 NEWELT (concat (2, prefix, nlist[i])); 3923 3924 globfree (&gl); 4113 3925 4114 3926 #ifndef NO_ARCHIVES … … 4116 3928 free (arname); 4117 3929 #endif 3930 3931 if (tildep) 3932 free (tildep); 4118 3933 } 4119 3934 3935 *stringp = p; 4120 3936 return new; 4121 3937 }
Note:
See TracChangeset
for help on using the changeset viewer.