"Fossies" - the Fresh Open Source Software Archive 
Member "schily-2021-09-18/sunpro/Make/bin/make/common/macro.cc" (15 Aug 2021, 5443 Bytes) of package /linux/privat/schily-2021-09-18.tar.bz2:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /*
2 * CDDL HEADER START
3 *
4 * This file and its contents are supplied under the terms of the
5 * Common Development and Distribution License ("CDDL"), version 1.0.
6 * You may use this file only in accordance with the terms of version
7 * 1.0 of the CDDL.
8 *
9 * A full copy of the text of the CDDL should have accompanied this
10 * source. A copy of the CDDL is also available via the Internet at
11 * http://www.opensource.org/licenses/cddl1.txt
12 * See the License for the specific language governing permissions
13 * and limitations under the License.
14 *
15 * When distributing Covered Code, include this CDDL HEADER in each
16 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 * If applicable, add the following below this CDDL HEADER, with the
18 * fields enclosed by brackets "[]" replaced with your own identifying
19 * information: Portions Copyright [yyyy] [name of copyright owner]
20 *
21 * CDDL HEADER END
22 */
23 /*
24 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 */
27 /*
28 * @(#)macro.cc 1.28 06/12/12
29 */
30
31 #pragma ident "@(#)macro.cc 1.28 06/12/12"
32
33 /*
34 * Copyright 2017-2018 J. Schilling
35 *
36 * @(#)macro.cc 1.4 21/08/15 2017-2018 J. Schilling
37 */
38 #include <schily/mconfig.h>
39 #ifndef lint
40 static UConst char sccsid[] =
41 "@(#)macro.cc 1.4 21/08/15 2017-2018 J. Schilling";
42 #endif
43
44 /*
45 * macro.cc
46 *
47 * Handle expansion of make macros
48 */
49
50 /*
51 * Included files
52 */
53 #ifdef DISTRIBUTED
54 #include <avo/strings.h> /* AVO_STRDUP() */
55 #include <dm/Avo_DoJobMsg.h>
56 #endif
57 #include <mk/defs.h>
58 #include <mksh/macro.h> /* getvar(), expand_value() */
59 #include <mksh/misc.h> /* getmem() */
60
61 /*
62 * Defined macros
63 */
64
65 /*
66 * typedefs & structs
67 */
68
69 /*
70 * Static variables
71 */
72
73 /*
74 * File table of contents
75 */
76
77 void
78 setvar_append(register Name name, register Name value)
79 {
80 register Property macro_apx = get_prop(name->prop, macro_append_prop);
81 register Property macro = get_prop(name->prop, macro_prop);
82 int length;
83 String_rec destination;
84 wchar_t buffer[STRING_BUFFER_LENGTH];
85 register Chain chain;
86 Name val = NULL;
87
88 if(macro_apx == NULL) {
89 macro_apx = append_prop(name, macro_append_prop);
90 if(macro != NULL) {
91 macro_apx->body.macro_appendix.value = macro->body.macro.value;
92 }
93 }
94
95 val = macro_apx->body.macro_appendix.value_to_append;
96
97 INIT_STRING_FROM_STACK(destination, buffer);
98 buffer[0] = 0;
99 if (val != NULL) {
100 APPEND_NAME(val,
101 &destination,
102 (int) val->hash.length);
103 if (value != NULL) {
104 MBTOWC(wcs_buffer, " ");
105 append_char(wcs_buffer[0], &destination);
106 }
107 }
108 if (value != NULL) {
109 APPEND_NAME(value,
110 &destination,
111 (int) value->hash.length);
112 }
113 value = GETNAME(destination.buffer.start, FIND_LENGTH);
114 if (destination.free_after_use) {
115 retmem(destination.buffer.start);
116 }
117 macro_apx->body.macro_appendix.value_to_append = value;
118
119 SETVAR(name, empty_name, true);
120 }
121
122 /*
123 * setvar_envvar()
124 *
125 * This function scans the list of environment variables that have
126 * dynamic values and sets them.
127 *
128 * Parameters:
129 *
130 * Global variables used:
131 * envvar A list of environment vars with $ in value
132 */
133 void
134 #ifdef DISTRIBUTED
135 setvar_envvar(Avo_DoJobMsg *dmake_job_msg)
136 #else
137 setvar_envvar(void)
138 #endif
139 {
140 wchar_t buffer[STRING_BUFFER_LENGTH];
141 int length;
142 #ifdef DISTRIBUTED
143 Property macro;
144 #endif
145 register char *mbs, *tmp_mbs_buffer = NULL;
146 register char *env, *tmp_mbs_buffer2 = NULL;
147 Envvar p;
148 String_rec value;
149
150 for (p = envvar; p != NULL; p = p->next) {
151 if (p->already_put
152 #ifdef DISTRIBUTED
153 && !dmake_job_msg
154 #endif
155 ) {
156 continue;
157 }
158 INIT_STRING_FROM_STACK(value, buffer);
159 expand_value(p->value, &value, false);
160 if ((length = wcslen(value.buffer.start)) >= MAXPATHLEN) {
161 mbs = tmp_mbs_buffer = getmem((length + 1) * MB_LEN_MAX);
162 (void) wcstombs(mbs,
163 value.buffer.start,
164 (length + 1) * MB_LEN_MAX);
165 } else {
166 mbs = mbs_buffer;
167 WCSTOMBS(mbs, value.buffer.start);
168 }
169 length = 2 + strlen(p->name->string_mb) + strlen(mbs);
170 if (!p->already_put || length > (MAXPATHLEN * MB_LEN_MAX)) {
171 env = tmp_mbs_buffer2 = getmem(length);
172 } else {
173 env = mbs_buffer2;
174 }
175 (void) sprintf(env,
176 "%s=%s",
177 p->name->string_mb,
178 mbs);
179 if (!p->already_put) {
180 (void) putenv(env);
181 p->already_put = true;
182 if (p->env_string) {
183 retmem_mb(p->env_string);
184 }
185 p->env_string = env;
186 tmp_mbs_buffer2 = NULL; // We should not return this memory now
187 }
188 #ifdef DISTRIBUTED
189 if (dmake_job_msg) {
190 dmake_job_msg->appendVar(env);
191 }
192 #endif
193 if (tmp_mbs_buffer2) {
194 retmem_mb(tmp_mbs_buffer2);
195 tmp_mbs_buffer2 = NULL;
196 }
197 if (tmp_mbs_buffer) {
198 retmem_mb(tmp_mbs_buffer);
199 tmp_mbs_buffer = NULL;
200 }
201 }
202 #ifdef DISTRIBUTED
203 /* Append SUNPRO_DEPENDENCIES to the dmake_job_msg. */
204 if (keep_state && dmake_job_msg) {
205 macro = get_prop(sunpro_dependencies->prop, macro_prop);
206 length = 2 +
207 strlen(sunpro_dependencies->string_mb) +
208 strlen(macro->body.macro.value->string_mb);
209 if (length > (MAXPATHLEN * MB_LEN_MAX)) {
210 env = tmp_mbs_buffer2 = getmem(length);
211 } else {
212 env = mbs_buffer2;
213 }
214 (void) sprintf(env,
215 "%s=%s",
216 sunpro_dependencies->string_mb,
217 macro->body.macro.value->string_mb);
218 dmake_job_msg->appendVar(env);
219 if (tmp_mbs_buffer2) {
220 retmem_mb(tmp_mbs_buffer2);
221 tmp_mbs_buffer2 = NULL;
222 }
223 }
224 #endif
225 }
226
227