Merge branch 'vendor/WPA_SUPPLICANT'
[dragonfly.git] / contrib / bmake / nonints.h
1 /*      $NetBSD: nonints.h,v 1.203 2021/02/14 21:32:58 rillig Exp $     */
2
3 /*
4  * Copyright (c) 1988, 1989, 1990, 1993
5  *      The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Adam de Boor.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  *      from: @(#)nonints.h     8.3 (Berkeley) 3/19/94
35  */
36
37 /*
38  * Copyright (c) 1989 by Berkeley Softworks
39  * All rights reserved.
40  *
41  * This code is derived from software contributed to Berkeley by
42  * Adam de Boor.
43  *
44  * Redistribution and use in source and binary forms, with or without
45  * modification, are permitted provided that the following conditions
46  * are met:
47  * 1. Redistributions of source code must retain the above copyright
48  *    notice, this list of conditions and the following disclaimer.
49  * 2. Redistributions in binary form must reproduce the above copyright
50  *    notice, this list of conditions and the following disclaimer in the
51  *    documentation and/or other materials provided with the distribution.
52  * 3. All advertising materials mentioning features or use of this software
53  *    must display the following acknowledgement:
54  *      This product includes software developed by the University of
55  *      California, Berkeley and its contributors.
56  * 4. Neither the name of the University nor the names of its contributors
57  *    may be used to endorse or promote products derived from this software
58  *    without specific prior written permission.
59  *
60  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
61  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
64  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70  * SUCH DAMAGE.
71  *
72  *      from: @(#)nonints.h     8.3 (Berkeley) 3/19/94
73  */
74
75 /* arch.c */
76 void Arch_Init(void);
77 void Arch_End(void);
78
79 Boolean Arch_ParseArchive(char **, GNodeList *, GNode *);
80 void Arch_Touch(GNode *);
81 void Arch_TouchLib(GNode *);
82 void Arch_UpdateMTime(GNode *gn);
83 void Arch_UpdateMemberMTime(GNode *gn);
84 void Arch_FindLib(GNode *, SearchPath *);
85 Boolean Arch_LibOODate(GNode *);
86 Boolean Arch_IsLib(GNode *);
87
88 /* compat.c */
89 int Compat_RunCommand(const char *, GNode *, StringListNode *);
90 void Compat_Run(GNodeList *);
91 void Compat_Make(GNode *, GNode *);
92
93 /* cond.c */
94 CondEvalResult Cond_EvalCondition(const char *, Boolean *);
95 CondEvalResult Cond_EvalLine(const char *);
96 void Cond_restore_depth(unsigned int);
97 unsigned int Cond_save_depth(void);
98
99 /* dir.c; see also dir.h */
100
101 MAKE_INLINE const char *
102 str_basename(const char *pathname)
103 {
104         const char *lastSlash = strrchr(pathname, '/');
105         return lastSlash != NULL ? lastSlash + 1 : pathname;
106 }
107
108 MAKE_INLINE SearchPath *
109 SearchPath_New(void)
110 {
111         SearchPath *path = bmake_malloc(sizeof *path);
112         Lst_Init(&path->dirs);
113         return path;
114 }
115
116 void SearchPath_Free(SearchPath *);
117
118 /* for.c */
119 int For_Eval(const char *);
120 Boolean For_Accum(const char *);
121 void For_Run(int);
122
123 /* job.c */
124 #ifdef WAIT_T
125 void JobReapChild(pid_t, WAIT_T, Boolean);
126 #endif
127
128 /* main.c */
129 Boolean GetBooleanVar(const char *, Boolean);
130 void Main_ParseArgLine(const char *);
131 char *Cmd_Exec(const char *, const char **);
132 void Error(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2);
133 void Fatal(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD;
134 void Punt(const char *, ...) MAKE_ATTR_PRINTFLIKE(1, 2) MAKE_ATTR_DEAD;
135 void DieHorribly(void) MAKE_ATTR_DEAD;
136 void Finish(int) MAKE_ATTR_DEAD;
137 int eunlink(const char *);
138 void execDie(const char *, const char *);
139 char *getTmpdir(void);
140 Boolean ParseBoolean(const char *, Boolean);
141 char *cached_realpath(const char *, char *);
142
143 /* parse.c */
144 void Parse_Init(void);
145 void Parse_End(void);
146
147 typedef enum VarAssignOp {
148         VAR_NORMAL,             /* = */
149         VAR_SUBST,              /* := */
150         VAR_SHELL,              /* != or :sh= */
151         VAR_APPEND,             /* += */
152         VAR_DEFAULT             /* ?= */
153 } VarAssignOp;
154
155 typedef struct VarAssign {
156         char *varname;          /* unexpanded */
157         VarAssignOp op;
158         const char *value;      /* unexpanded */
159 } VarAssign;
160
161 typedef char *(*ReadMoreProc)(void *, size_t *);
162
163 void Parse_Error(ParseErrorLevel, const char *, ...) MAKE_ATTR_PRINTFLIKE(2, 3);
164 Boolean Parse_IsVar(const char *, VarAssign *out_var);
165 void Parse_DoVar(VarAssign *, GNode *);
166 void Parse_AddIncludeDir(const char *);
167 void Parse_File(const char *, int);
168 void Parse_SetInput(const char *, int, int, ReadMoreProc, void *);
169 void Parse_MainName(GNodeList *);
170 int Parse_GetFatals(void);
171
172 /* str.c */
173
174 /* A read-only string that may need to be freed after use. */
175 typedef struct FStr {
176         const char *str;
177         void *freeIt;
178 } FStr;
179
180 /* A modifiable string that may need to be freed after use. */
181 typedef struct MFStr {
182         char *str;
183         void *freeIt;
184 } MFStr;
185
186 typedef struct Words {
187         char **words;
188         size_t len;
189         void *freeIt;
190 } Words;
191
192 /* Return a string that is the sole owner of str. */
193 MAKE_INLINE FStr
194 FStr_InitOwn(char *str)
195 {
196         return (FStr){ str, str };
197 }
198
199 /* Return a string that refers to the shared str. */
200 MAKE_INLINE FStr
201 FStr_InitRefer(const char *str)
202 {
203         return (FStr){ str, NULL };
204 }
205
206 MAKE_INLINE void
207 FStr_Done(FStr *fstr)
208 {
209         free(fstr->freeIt);
210 #ifdef CLEANUP
211         fstr->str = NULL;
212         fstr->freeIt = NULL;
213 #endif
214 }
215
216 /* Return a string that is the sole owner of str. */
217 MAKE_INLINE MFStr
218 MFStr_InitOwn(char *str)
219 {
220         return (MFStr){ str, str };
221 }
222
223 /* Return a string that refers to the shared str. */
224 MAKE_INLINE MFStr
225 MFStr_InitRefer(char *str)
226 {
227         return (MFStr){ str, NULL };
228 }
229
230 MAKE_INLINE void
231 MFStr_Done(MFStr *mfstr)
232 {
233         free(mfstr->freeIt);
234 #ifdef CLEANUP
235         mfstr->str = NULL;
236         mfstr->freeIt = NULL;
237 #endif
238 }
239
240 Words Str_Words(const char *, Boolean);
241 MAKE_INLINE void
242 Words_Free(Words w)
243 {
244         free(w.words);
245         free(w.freeIt);
246 }
247
248 char *str_concat2(const char *, const char *);
249 char *str_concat3(const char *, const char *, const char *);
250 char *str_concat4(const char *, const char *, const char *, const char *);
251 Boolean Str_Match(const char *, const char *);
252
253 #ifndef HAVE_STRLCPY
254 /* strlcpy.c */
255 size_t strlcpy(char *, const char *, size_t);
256 #endif
257
258 /* suff.c */
259 void Suff_Init(void);
260 void Suff_End(void);
261
262 void Suff_ClearSuffixes(void);
263 Boolean Suff_IsTransform(const char *);
264 GNode *Suff_AddTransform(const char *);
265 void Suff_EndTransform(GNode *);
266 void Suff_AddSuffix(const char *, GNode **);
267 SearchPath *Suff_GetPath(const char *);
268 void Suff_DoPaths(void);
269 void Suff_AddInclude(const char *);
270 void Suff_AddLib(const char *);
271 void Suff_FindDeps(GNode *);
272 SearchPath *Suff_FindPath(GNode *);
273 void Suff_SetNull(const char *);
274 void Suff_PrintAll(void);
275
276 /* targ.c */
277 void Targ_Init(void);
278 void Targ_End(void);
279
280 void Targ_Stats(void);
281 GNodeList *Targ_List(void);
282 GNode *GNode_New(const char *);
283 GNode *Targ_FindNode(const char *);
284 GNode *Targ_GetNode(const char *);
285 GNode *Targ_NewInternalNode(const char *);
286 GNode *Targ_GetEndNode(void);
287 void Targ_FindList(GNodeList *, StringList *);
288 Boolean Targ_Precious(const GNode *);
289 void Targ_SetMain(GNode *);
290 void Targ_PrintCmds(GNode *);
291 void Targ_PrintNode(GNode *, int);
292 void Targ_PrintNodes(GNodeList *, int);
293 const char *Targ_FmtTime(time_t);
294 void Targ_PrintType(int);
295 void Targ_PrintGraph(int);
296 void Targ_Propagate(void);
297 const char *GNodeMade_Name(GNodeMade);
298
299 /* var.c */
300 void Var_Init(void);
301 void Var_End(void);
302
303 typedef enum VarEvalFlags {
304         VARE_NONE               = 0,
305
306         /*
307          * Expand and evaluate variables during parsing.
308          *
309          * TODO: Document what Var_Parse and Var_Subst return when this flag
310          * is not set.
311          */
312         VARE_WANTRES            = 1 << 0,
313
314         /*
315          * Treat undefined variables as errors.
316          * Must only be used in combination with VARE_WANTRES.
317          */
318         VARE_UNDEFERR           = 1 << 1,
319
320         /*
321          * Keep '$$' as '$$' instead of reducing it to a single '$'.
322          *
323          * Used in variable assignments using the ':=' operator.  It allows
324          * multiple such assignments to be chained without accidentally
325          * expanding '$$file' to '$file' in the first assignment and
326          * interpreting it as '${f}' followed by 'ile' in the next assignment.
327          */
328         VARE_KEEP_DOLLAR        = 1 << 2,
329
330         /*
331          * Keep undefined variables as-is instead of expanding them to an
332          * empty string.
333          *
334          * Example for a ':=' assignment:
335          *      CFLAGS = $(.INCLUDES)
336          *      CFLAGS := -I.. $(CFLAGS)
337          *      # If .INCLUDES (an undocumented special variable, by the
338          *      # way) is still undefined, the updated CFLAGS becomes
339          *      # "-I.. $(.INCLUDES)".
340          */
341         VARE_KEEP_UNDEF         = 1 << 3
342 } VarEvalFlags;
343
344 typedef enum VarSetFlags {
345         VAR_SET_NONE            = 0,
346
347         /* do not export */
348         VAR_SET_NO_EXPORT       = 1 << 0,
349
350         /* Make the variable read-only. No further modification is possible,
351          * except for another call to Var_Set with the same flag. */
352         VAR_SET_READONLY        = 1 << 1
353 } VarSetFlags;
354
355 /* The state of error handling returned by Var_Parse. */
356 typedef enum VarParseResult {
357
358         /* Both parsing and evaluation succeeded. */
359         VPR_OK,
360
361         /* Parsing or evaluating failed, with an error message. */
362         VPR_ERR,
363
364         /*
365          * Parsing succeeded, undefined expressions are allowed and the
366          * expression was still undefined after applying all modifiers.
367          * No error message is printed in this case.
368          *
369          * Some callers handle this case differently, so return this
370          * information to them, for now.
371          *
372          * TODO: Replace this with a new flag VARE_KEEP_UNDEFINED.
373          */
374         VPR_UNDEF
375
376 } VarParseResult;
377
378 typedef enum VarExportMode {
379         /* .export-env */
380         VEM_ENV,
381         /* .export: Initial export or update an already exported variable. */
382         VEM_PLAIN,
383         /* .export-literal: Do not expand the variable value. */
384         VEM_LITERAL
385 } VarExportMode;
386
387 void Var_Delete(GNode *, const char *);
388 void Var_DeleteExpand(GNode *, const char *);
389 void Var_Undef(const char *);
390 void Var_Set(GNode *, const char *, const char *);
391 void Var_SetExpand(GNode *, const char *, const char *);
392 void Var_SetWithFlags(GNode *, const char *, const char *, VarSetFlags);
393 void Var_SetExpandWithFlags(GNode *, const char *, const char *, VarSetFlags);
394 void Var_Append(GNode *, const char *, const char *);
395 void Var_AppendExpand(GNode *, const char *, const char *);
396 Boolean Var_Exists(GNode *, const char *);
397 Boolean Var_ExistsExpand(GNode *, const char *);
398 FStr Var_Value(GNode *, const char *);
399 const char *GNode_ValueDirect(GNode *, const char *);
400 VarParseResult Var_Parse(const char **, GNode *, VarEvalFlags, FStr *);
401 VarParseResult Var_Subst(const char *, GNode *, VarEvalFlags, char **);
402 void Var_Stats(void);
403 void Var_Dump(GNode *);
404 void Var_ReexportVars(void);
405 void Var_Export(VarExportMode, const char *);
406 void Var_ExportVars(const char *);
407 void Var_UnExport(Boolean, const char *);
408
409 void Global_Set(const char *, const char *);
410 void Global_SetExpand(const char *, const char *);
411 void Global_Append(const char *, const char *);
412 void Global_Delete(const char *);
413
414 /* util.c */
415 typedef void (*SignalProc)(int);
416 SignalProc bmake_signal(int, SignalProc);