| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: parse.c,v 1.401 2020/10/26 21:34:10 rillig Exp $ */ | | 1 | /* $NetBSD: parse.c,v 1.402 2020/10/28 00:38:37 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1988, 1989, 1990, 1993 | | 4 | * Copyright (c) 1988, 1989, 1990, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Adam de Boor. | | 8 | * Adam de Boor. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -58,90 +58,76 @@ | | | @@ -58,90 +58,76 @@ |
58 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | | 58 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
59 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 59 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
60 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 60 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
61 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 61 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
62 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 62 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
63 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 63 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
64 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 64 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
65 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 65 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
66 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 66 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
67 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 67 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
68 | * SUCH DAMAGE. | | 68 | * SUCH DAMAGE. |
69 | */ | | 69 | */ |
70 | | | 70 | |
71 | /*- | | 71 | /* |
72 | * parse.c -- | | 72 | * Parsing of makefiles. |
73 | * Functions to parse a makefile. | | 73 | * |
| | | 74 | * Parse_File is the main entry point and controls most of the other |
| | | 75 | * functions in this module. |
74 | * | | 76 | * |
75 | * One function, Parse_Init, must be called before any functions | | 77 | * The directories for the .include "..." directive are kept in |
76 | * in this module are used. After that, the function Parse_File is the | | 78 | * 'parseIncPath', while those for .include <...> are kept in 'sysIncPath'. |
77 | * main entry point and controls most of the other functions in this | | 79 | * The targets currently being defined are kept in 'targets'. |
78 | * module. | | | |
79 | * | | | |
80 | * Most important structures are kept in Lsts. Directories for | | | |
81 | * the .include "..." function are kept in the 'parseIncPath' Lst, while | | | |
82 | * those for the .include <...> are kept in the 'sysIncPath' Lst. The | | | |
83 | * targets currently being defined are kept in the 'targets' Lst. | | | |
84 | * | | | |
85 | * The variables 'fname' and 'lineno' are used to track the name | | | |
86 | * of the current file and the line number in that file so that error | | | |
87 | * messages can be more meaningful. | | | |
88 | * | | 80 | * |
89 | * Interface: | | 81 | * Interface: |
90 | * Parse_Init Initialization function which must be | | 82 | * Parse_Init Initialize the module |
91 | * called before anything else in this module | | | |
92 | * is used. | | | |
93 | * | | 83 | * |
94 | * Parse_End Clean up the module | | 84 | * Parse_End Clean up the module |
95 | * | | 85 | * |
96 | * Parse_File Function used to parse a makefile. It must | | 86 | * Parse_File Parse a top-level makefile. Included files are |
97 | * be given the name of the file, which should | | 87 | * handled by Parse_include_file though. |
98 | * already have been opened, and a function | | 88 | * |
99 | * to call to read a character from the file. | | 89 | * Parse_IsVar Return TRUE if the given line is a variable |
100 | * | | 90 | * assignment. Used by MainParseArgs to determine if |
101 | * Parse_IsVar Returns TRUE if the given line is a | | 91 | * an argument is a target or a variable assignment. |
102 | * variable assignment. Used by MainParseArgs | | 92 | * Used internally for pretty much the same thing. |
103 | * to determine if an argument is a target | | 93 | * |
104 | * or a variable assignment. Used internally | | 94 | * Parse_Error Report a parse error, a warning or an informational |
105 | * for pretty much the same thing... | | 95 | * message. |
106 | * | | | |
107 | * Parse_Error Function called when an error occurs in | | | |
108 | * parsing. Used by the variable and | | | |
109 | * conditional modules. | | | |
110 | * | | 96 | * |
111 | * Parse_MainName Returns a Lst of the main target to create. | | 97 | * Parse_MainName Returns a list of the main target to create. |
112 | */ | | 98 | */ |
113 | | | 99 | |
114 | #include <sys/types.h> | | 100 | #include <sys/types.h> |
115 | #include <sys/mman.h> | | 101 | #include <sys/mman.h> |
116 | #include <sys/stat.h> | | 102 | #include <sys/stat.h> |
117 | #include <errno.h> | | 103 | #include <errno.h> |
118 | #include <stdarg.h> | | 104 | #include <stdarg.h> |
119 | #include <stdint.h> | | 105 | #include <stdint.h> |
120 | | | 106 | |
121 | #ifndef MAP_FILE | | 107 | #ifndef MAP_FILE |
122 | #define MAP_FILE 0 | | 108 | #define MAP_FILE 0 |
123 | #endif | | 109 | #endif |
124 | #ifndef MAP_COPY | | 110 | #ifndef MAP_COPY |
125 | #define MAP_COPY MAP_PRIVATE | | 111 | #define MAP_COPY MAP_PRIVATE |
126 | #endif | | 112 | #endif |
127 | | | 113 | |
128 | #include "make.h" | | 114 | #include "make.h" |
129 | #include "dir.h" | | 115 | #include "dir.h" |
130 | #include "job.h" | | 116 | #include "job.h" |
131 | #include "pathnames.h" | | 117 | #include "pathnames.h" |
132 | | | 118 | |
133 | /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ | | 119 | /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ |
134 | MAKE_RCSID("$NetBSD: parse.c,v 1.401 2020/10/26 21:34:10 rillig Exp $"); | | 120 | MAKE_RCSID("$NetBSD: parse.c,v 1.402 2020/10/28 00:38:37 rillig Exp $"); |
135 | | | 121 | |
136 | /* types and constants */ | | 122 | /* types and constants */ |
137 | | | 123 | |
138 | /* | | 124 | /* |
139 | * Structure for a file being read ("included file") | | 125 | * Structure for a file being read ("included file") |
140 | */ | | 126 | */ |
141 | typedef struct IFile { | | 127 | typedef struct IFile { |
142 | char *fname; /* name of file */ | | 128 | char *fname; /* name of file */ |
143 | Boolean fromForLoop; /* simulated .include by the .for loop */ | | 129 | Boolean fromForLoop; /* simulated .include by the .for loop */ |
144 | int lineno; /* current line number in file */ | | 130 | int lineno; /* current line number in file */ |
145 | int first_lineno; /* line number of start of text */ | | 131 | int first_lineno; /* line number of start of text */ |
146 | unsigned int cond_depth; /* 'if' nesting when file opened */ | | 132 | unsigned int cond_depth; /* 'if' nesting when file opened */ |
147 | Boolean depending; /* state of doing_depend on EOF */ | | 133 | Boolean depending; /* state of doing_depend on EOF */ |