| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: parse.c,v 1.506 2020/12/20 14:48:35 rillig Exp $ */ | | 1 | /* $NetBSD: parse.c,v 1.507 2020/12/20 14:52:16 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. |
| @@ -107,27 +107,27 @@ | | | @@ -107,27 +107,27 @@ |
107 | #ifndef MAP_FILE | | 107 | #ifndef MAP_FILE |
108 | #define MAP_FILE 0 | | 108 | #define MAP_FILE 0 |
109 | #endif | | 109 | #endif |
110 | #ifndef MAP_COPY | | 110 | #ifndef MAP_COPY |
111 | #define MAP_COPY MAP_PRIVATE | | 111 | #define MAP_COPY MAP_PRIVATE |
112 | #endif | | 112 | #endif |
113 | | | 113 | |
114 | #include "make.h" | | 114 | #include "make.h" |
115 | #include "dir.h" | | 115 | #include "dir.h" |
116 | #include "job.h" | | 116 | #include "job.h" |
117 | #include "pathnames.h" | | 117 | #include "pathnames.h" |
118 | | | 118 | |
119 | /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ | | 119 | /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ |
120 | MAKE_RCSID("$NetBSD: parse.c,v 1.506 2020/12/20 14:48:35 rillig Exp $"); | | 120 | MAKE_RCSID("$NetBSD: parse.c,v 1.507 2020/12/20 14:52:16 rillig Exp $"); |
121 | | | 121 | |
122 | /* types and constants */ | | 122 | /* types and constants */ |
123 | | | 123 | |
124 | /* | | 124 | /* |
125 | * Structure for a file being read ("included file") | | 125 | * Structure for a file being read ("included file") |
126 | */ | | 126 | */ |
127 | typedef struct IFile { | | 127 | typedef struct IFile { |
128 | char *fname; /* name of file (relative? absolute?) */ | | 128 | char *fname; /* name of file (relative? absolute?) */ |
129 | Boolean fromForLoop; /* simulated .include by the .for loop */ | | 129 | Boolean fromForLoop; /* simulated .include by the .for loop */ |
130 | int lineno; /* current line number in file */ | | 130 | int lineno; /* current line number in file */ |
131 | int first_lineno; /* line number of start of text */ | | 131 | int first_lineno; /* line number of start of text */ |
132 | unsigned int cond_depth; /* 'if' nesting when file opened */ | | 132 | unsigned int cond_depth; /* 'if' nesting when file opened */ |
133 | Boolean depending; /* state of doing_depend on EOF */ | | 133 | Boolean depending; /* state of doing_depend on EOF */ |
| @@ -1952,47 +1952,47 @@ VarAssign_EvalSubst(const char *name, co | | | @@ -1952,47 +1952,47 @@ VarAssign_EvalSubst(const char *name, co |
1952 | (void)Var_Subst(uvalue, ctxt, VARE_WANTRES | VARE_KEEP_DOLLAR, &evalue); | | 1952 | (void)Var_Subst(uvalue, ctxt, VARE_WANTRES | VARE_KEEP_DOLLAR, &evalue); |
1953 | /* TODO: handle errors */ | | 1953 | /* TODO: handle errors */ |
1954 | preserveUndefined = savedPreserveUndefined; | | 1954 | preserveUndefined = savedPreserveUndefined; |
1955 | avalue = evalue; | | 1955 | avalue = evalue; |
1956 | Var_Set(name, avalue, ctxt); | | 1956 | Var_Set(name, avalue, ctxt); |
1957 | | | 1957 | |
1958 | *out_avalue = (FStr){ avalue, evalue }; | | 1958 | *out_avalue = (FStr){ avalue, evalue }; |
1959 | } | | 1959 | } |
1960 | | | 1960 | |
1961 | static void | | 1961 | static void |
1962 | VarAssign_EvalShell(const char *name, const char *uvalue, GNode *ctxt, | | 1962 | VarAssign_EvalShell(const char *name, const char *uvalue, GNode *ctxt, |
1963 | FStr *out_avalue) | | 1963 | FStr *out_avalue) |
1964 | { | | 1964 | { |
1965 | const char *cmd, *errfmt; | | 1965 | FStr cmd; |
| | | 1966 | const char *errfmt; |
1966 | char *cmdOut; | | 1967 | char *cmdOut; |
1967 | void *cmd_freeIt = NULL; | | | |
1968 | | | 1968 | |
1969 | cmd = uvalue; | | 1969 | cmd = FStr_InitRefer(uvalue); |
1970 | if (strchr(cmd, '$') != NULL) { | | 1970 | if (strchr(cmd.str, '$') != NULL) { |
1971 | char *ecmd; | | 1971 | char *expanded; |
1972 | (void)Var_Subst(cmd, VAR_CMDLINE, VARE_WANTRES | VARE_UNDEFERR, | | 1972 | (void)Var_Subst(cmd.str, VAR_CMDLINE, |
1973 | &ecmd); | | 1973 | VARE_WANTRES | VARE_UNDEFERR, &expanded); |
1974 | /* TODO: handle errors */ | | 1974 | /* TODO: handle errors */ |
1975 | cmd = cmd_freeIt = ecmd; | | 1975 | cmd = FStr_InitOwn(expanded); |
1976 | } | | 1976 | } |
1977 | | | 1977 | |
1978 | cmdOut = Cmd_Exec(cmd, &errfmt); | | 1978 | cmdOut = Cmd_Exec(cmd.str, &errfmt); |
1979 | Var_Set(name, cmdOut, ctxt); | | 1979 | Var_Set(name, cmdOut, ctxt); |
1980 | *out_avalue = FStr_InitOwn(cmdOut); | | 1980 | *out_avalue = FStr_InitOwn(cmdOut); |
1981 | | | 1981 | |
1982 | if (errfmt != NULL) | | 1982 | if (errfmt != NULL) |
1983 | Parse_Error(PARSE_WARNING, errfmt, cmd); | | 1983 | Parse_Error(PARSE_WARNING, errfmt, cmd); |
1984 | | | 1984 | |
1985 | free(cmd_freeIt); | | 1985 | FStr_Done(&cmd); |
1986 | } | | 1986 | } |
1987 | | | 1987 | |
1988 | /* Perform a variable assignment. | | 1988 | /* Perform a variable assignment. |
1989 | * | | 1989 | * |
1990 | * The actual value of the variable is returned in *out_avalue and | | 1990 | * The actual value of the variable is returned in *out_avalue and |
1991 | * *out_avalue_freeIt. Especially for VAR_SUBST and VAR_SHELL this can differ | | 1991 | * *out_avalue_freeIt. Especially for VAR_SUBST and VAR_SHELL this can differ |
1992 | * from the literal value. | | 1992 | * from the literal value. |
1993 | * | | 1993 | * |
1994 | * Return whether the assignment was actually done. The assignment is only | | 1994 | * Return whether the assignment was actually done. The assignment is only |
1995 | * skipped if the operator is '?=' and the variable already exists. */ | | 1995 | * skipped if the operator is '?=' and the variable already exists. */ |
1996 | static Boolean | | 1996 | static Boolean |
1997 | VarAssign_Eval(const char *name, VarAssignOp op, const char *uvalue, | | 1997 | VarAssign_Eval(const char *name, VarAssignOp op, const char *uvalue, |
1998 | GNode *ctxt, FStr *out_TRUE_avalue) | | 1998 | GNode *ctxt, FStr *out_TRUE_avalue) |