Print this page
make: unifdef for NSE (undefined)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/make/lib/mksh/macro.cc
+++ new/usr/src/cmd/make/lib/mksh/macro.cc
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26
27 27 /*
28 28 * macro.cc
29 29 *
30 30 * Handle expansion of make macros
31 31 */
32 32
33 33 /*
34 34 * Included files
35 35 */
36 36 #include <mksh/dosys.h> /* sh_command2string() */
37 37 #include <mksh/i18n.h> /* get_char_semantics_value() */
38 38 #include <mksh/macro.h>
↓ open down ↓ |
38 lines elided |
↑ open up ↑ |
39 39 #include <mksh/misc.h> /* retmem() */
40 40 #include <mksh/read.h> /* get_next_block_fn() */
41 41 #include <mksdmsi18n/mksdmsi18n.h> /* libmksdmsi18n_init() */
42 42
43 43 #include <widec.h>
44 44
45 45 /*
46 46 * File table of contents
47 47 */
48 48 static void add_macro_to_global_list(Name macro_to_add);
49 -#ifdef NSE
50 -static void expand_value_with_daemon(Name name, register Property macro, register String destination, Boolean cmd);
51 -#else
52 49 static void expand_value_with_daemon(Name, register Property macro, register String destination, Boolean cmd);
53 -#endif
54 50
55 51 static void init_arch_macros(void);
56 52 static void init_mach_macros(void);
57 53 static Boolean init_arch_done = false;
58 54 static Boolean init_mach_done = false;
59 55
60 56
61 57 long env_alloc_num = 0;
62 58 long env_alloc_bytes = 0;
63 59
64 60 /*
65 61 * getvar(name)
66 62 *
67 63 * Return expanded value of macro.
68 64 *
69 65 * Return value:
70 66 * The expanded value of the macro
71 67 *
72 68 * Parameters:
73 69 * name The name of the macro we want the value for
74 70 *
75 71 * Global variables used:
76 72 */
77 73 Name
78 74 getvar(register Name name)
79 75 {
80 76 String_rec destination;
81 77 wchar_t buffer[STRING_BUFFER_LENGTH];
82 78 register Name result;
83 79
84 80 if ((name == host_arch) || (name == target_arch)) {
85 81 if (!init_arch_done) {
86 82 init_arch_done = true;
87 83 init_arch_macros();
88 84 }
89 85 }
90 86 if ((name == host_mach) || (name == target_mach)) {
91 87 if (!init_mach_done) {
92 88 init_mach_done = true;
93 89 init_mach_macros();
94 90 }
95 91 }
96 92
97 93 INIT_STRING_FROM_STACK(destination, buffer);
98 94 expand_value(maybe_append_prop(name, macro_prop)->body.macro.value,
99 95 &destination,
100 96 false);
101 97 result = GETNAME(destination.buffer.start, FIND_LENGTH);
102 98 if (destination.free_after_use) {
103 99 retmem(destination.buffer.start);
104 100 }
105 101 return result;
106 102 }
107 103
108 104 /*
109 105 * expand_value(value, destination, cmd)
110 106 *
111 107 * Recursively expands all macros in the string value.
112 108 * destination is where the expanded value should be appended.
113 109 *
114 110 * Parameters:
115 111 * value The value we are expanding
116 112 * destination Where to deposit the expansion
117 113 * cmd If we are evaluating a command line we
118 114 * turn \ quoting off
119 115 *
120 116 * Global variables used:
121 117 */
122 118 void
123 119 expand_value(Name value, register String destination, Boolean cmd)
124 120 {
125 121 Source_rec sourceb;
126 122 register Source source = &sourceb;
127 123 register wchar_t *source_p = NULL;
128 124 register wchar_t *source_end = NULL;
129 125 wchar_t *block_start = NULL;
130 126 int quote_seen = 0;
131 127
132 128 if (value == NULL) {
133 129 /*
134 130 * Make sure to get a string allocated even if it
135 131 * will be empty.
136 132 */
137 133 MBSTOWCS(wcs_buffer, "");
138 134 append_string(wcs_buffer, destination, FIND_LENGTH);
139 135 destination->text.end = destination->text.p;
140 136 return;
141 137 }
142 138 if (!value->dollar) {
143 139 /*
144 140 * If the value we are expanding does not contain
145 141 * any $, we don't have to parse it.
146 142 */
147 143 APPEND_NAME(value,
148 144 destination,
149 145 (int) value->hash.length
150 146 );
151 147 destination->text.end = destination->text.p;
152 148 return;
153 149 }
154 150
155 151 if (value->being_expanded) {
156 152 fatal_reader_mksh(catgets(libmksdmsi18n_catd, 1, 113, "Loop detected when expanding macro value `%s'"),
157 153 value->string_mb);
158 154 }
159 155 value->being_expanded = true;
160 156 /* Setup the structure we read from */
161 157 Wstring vals(value);
162 158 sourceb.string.text.p = sourceb.string.buffer.start = wsdup(vals.get_string());
163 159 sourceb.string.free_after_use = true;
164 160 sourceb.string.text.end =
165 161 sourceb.string.buffer.end =
166 162 sourceb.string.text.p + value->hash.length;
167 163 sourceb.previous = NULL;
168 164 sourceb.fd = -1;
169 165 sourceb.inp_buf =
170 166 sourceb.inp_buf_ptr =
171 167 sourceb.inp_buf_end = NULL;
172 168 sourceb.error_converting = false;
173 169 /* Lift some pointers from the struct to local register variables */
174 170 CACHE_SOURCE(0);
175 171 /* We parse the string in segments */
176 172 /* We read chars until we find a $, then we append what we have read so far */
177 173 /* (since last $ processing) to the destination. When we find a $ we call */
178 174 /* expand_macro() and let it expand that particular $ reference into dest */
179 175 block_start = source_p;
180 176 quote_seen = 0;
181 177 for (; 1; source_p++) {
182 178 switch (GET_CHAR()) {
183 179 case backslash_char:
184 180 /* Quote $ in macro value */
185 181 if (!cmd) {
186 182 quote_seen = ~quote_seen;
187 183 }
188 184 continue;
189 185 case dollar_char:
190 186 /* Save the plain string we found since */
191 187 /* start of string or previous $ */
192 188 if (quote_seen) {
193 189 append_string(block_start,
194 190 destination,
195 191 source_p - block_start - 1);
196 192 block_start = source_p;
197 193 break;
198 194 }
199 195 append_string(block_start,
200 196 destination,
201 197 source_p - block_start);
202 198 source->string.text.p = ++source_p;
203 199 UNCACHE_SOURCE();
204 200 /* Go expand the macro reference */
205 201 expand_macro(source, destination, sourceb.string.buffer.start, cmd);
206 202 CACHE_SOURCE(1);
207 203 block_start = source_p + 1;
208 204 break;
209 205 case nul_char:
210 206 /* The string ran out. Get some more */
211 207 append_string(block_start,
212 208 destination,
213 209 source_p - block_start);
214 210 GET_NEXT_BLOCK_NOCHK(source);
215 211 if (source == NULL) {
216 212 destination->text.end = destination->text.p;
217 213 value->being_expanded = false;
218 214 return;
219 215 }
220 216 if (source->error_converting) {
221 217 fatal_reader_mksh(NOCATGETS("Internal error: Invalid byte sequence in expand_value()"));
222 218 }
223 219 block_start = source_p;
224 220 source_p--;
225 221 continue;
226 222 }
227 223 quote_seen = 0;
228 224 }
229 225 retmem(sourceb.string.buffer.start);
230 226 }
231 227
232 228 /*
233 229 * expand_macro(source, destination, current_string, cmd)
234 230 *
235 231 * Should be called with source->string.text.p pointing to
236 232 * the first char after the $ that starts a macro reference.
237 233 * source->string.text.p is returned pointing to the first char after
238 234 * the macro name.
239 235 * It will read the macro name, expanding any macros in it,
240 236 * and get the value. The value is then expanded.
241 237 * destination is a String that is filled in with the expanded macro.
242 238 * It may be passed in referencing a buffer to expand the macro into.
243 239 * Note that most expansions are done on demand, e.g. right
244 240 * before the command is executed and not while the file is
245 241 * being parsed.
246 242 *
247 243 * Parameters:
248 244 * source The source block that references the string
249 245 * to expand
250 246 * destination Where to put the result
251 247 * current_string The string we are expanding, for error msg
252 248 * cmd If we are evaluating a command line we
253 249 * turn \ quoting off
254 250 *
255 251 * Global variables used:
256 252 * funny Vector of semantic tags for characters
257 253 * is_conditional Set if a conditional macro is refd
258 254 * make_word_mentioned Set if the word "MAKE" is mentioned
259 255 * makefile_type We deliver extra msg when reading makefiles
260 256 * query The Name "?", compared against
261 257 * query_mentioned Set if the word "?" is mentioned
262 258 */
263 259 void
264 260 expand_macro(register Source source, register String destination, wchar_t *current_string, Boolean cmd)
265 261 {
266 262 static Name make = (Name)NULL;
267 263 static wchar_t colon_sh[4];
268 264 static wchar_t colon_shell[7];
269 265 String_rec string;
270 266 wchar_t buffer[STRING_BUFFER_LENGTH];
271 267 register wchar_t *source_p = source->string.text.p;
272 268 register wchar_t *source_end = source->string.text.end;
273 269 register int closer = 0;
274 270 wchar_t *block_start = (wchar_t *)NULL;
275 271 int quote_seen = 0;
276 272 register int closer_level = 1;
277 273 Name name = (Name)NULL;
278 274 wchar_t *colon = (wchar_t *)NULL;
279 275 wchar_t *percent = (wchar_t *)NULL;
280 276 wchar_t *eq = (wchar_t *) NULL;
281 277 Property macro = NULL;
282 278 wchar_t *p = (wchar_t*)NULL;
283 279 String_rec extracted;
284 280 wchar_t extracted_string[MAXPATHLEN];
285 281 wchar_t *left_head = NULL;
286 282 wchar_t *left_tail = NULL;
287 283 wchar_t *right_tail = NULL;
288 284 int left_head_len = 0;
289 285 int left_tail_len = 0;
290 286 int tmp_len = 0;
291 287 wchar_t *right_hand[128];
292 288 int i = 0;
293 289 enum {
294 290 no_extract,
295 291 dir_extract,
296 292 file_extract
297 293 } extraction = no_extract;
298 294 enum {
299 295 no_replace,
300 296 suffix_replace,
301 297 pattern_replace,
302 298 sh_replace
303 299 } replacement = no_replace;
304 300
305 301 if (make == NULL) {
306 302 MBSTOWCS(wcs_buffer, NOCATGETS("MAKE"));
307 303 make = GETNAME(wcs_buffer, FIND_LENGTH);
308 304
309 305 MBSTOWCS(colon_sh, NOCATGETS(":sh"));
310 306 MBSTOWCS(colon_shell, NOCATGETS(":shell"));
311 307 }
312 308
313 309 right_hand[0] = NULL;
314 310
315 311 /* First copy the (macro-expanded) macro name into string. */
316 312 INIT_STRING_FROM_STACK(string, buffer);
317 313 recheck_first_char:
318 314 /* Check the first char of the macro name to figure out what to do. */
319 315 switch (GET_CHAR()) {
320 316 case nul_char:
321 317 GET_NEXT_BLOCK_NOCHK(source);
322 318 if (source == NULL) {
323 319 WCSTOMBS(mbs_buffer, current_string);
324 320 fatal_reader_mksh(catgets(libmksdmsi18n_catd, 1, 114, "'$' at end of string `%s'"),
325 321 mbs_buffer);
326 322 }
327 323 if (source->error_converting) {
328 324 fatal_reader_mksh(NOCATGETS("Internal error: Invalid byte sequence in expand_macro()"));
329 325 }
330 326 goto recheck_first_char;
331 327 case parenleft_char:
332 328 /* Multi char name. */
333 329 closer = (int) parenright_char;
334 330 break;
335 331 case braceleft_char:
336 332 /* Multi char name. */
337 333 closer = (int) braceright_char;
338 334 break;
339 335 case newline_char:
340 336 fatal_reader_mksh(catgets(libmksdmsi18n_catd, 1, 115, "'$' at end of line"));
341 337 default:
342 338 /* Single char macro name. Just suck it up */
343 339 append_char(*source_p, &string);
344 340 source->string.text.p = source_p + 1;
345 341 goto get_macro_value;
346 342 }
347 343
348 344 /* Handle multi-char macro names */
349 345 block_start = ++source_p;
350 346 quote_seen = 0;
351 347 for (; 1; source_p++) {
352 348 switch (GET_CHAR()) {
353 349 case nul_char:
354 350 append_string(block_start,
355 351 &string,
356 352 source_p - block_start);
357 353 GET_NEXT_BLOCK_NOCHK(source);
358 354 if (source == NULL) {
359 355 if (current_string != NULL) {
360 356 WCSTOMBS(mbs_buffer, current_string);
361 357 fatal_reader_mksh(catgets(libmksdmsi18n_catd, 1, 116, "Unmatched `%c' in string `%s'"),
362 358 closer ==
363 359 (int) braceright_char ?
364 360 (int) braceleft_char :
365 361 (int) parenleft_char,
366 362 mbs_buffer);
367 363 } else {
368 364 fatal_reader_mksh(catgets(libmksdmsi18n_catd, 1, 117, "Premature EOF"));
369 365 }
370 366 }
371 367 if (source->error_converting) {
372 368 fatal_reader_mksh(NOCATGETS("Internal error: Invalid byte sequence in expand_macro()"));
373 369 }
374 370 block_start = source_p;
375 371 source_p--;
376 372 continue;
377 373 case newline_char:
378 374 fatal_reader_mksh(catgets(libmksdmsi18n_catd, 1, 118, "Unmatched `%c' on line"),
379 375 closer == (int) braceright_char ?
380 376 (int) braceleft_char :
381 377 (int) parenleft_char);
382 378 case backslash_char:
383 379 /* Quote dollar in macro value. */
384 380 if (!cmd) {
385 381 quote_seen = ~quote_seen;
386 382 }
387 383 continue;
388 384 case dollar_char:
389 385 /*
390 386 * Macro names may reference macros.
391 387 * This expands the value of such macros into the
392 388 * macro name string.
393 389 */
394 390 if (quote_seen) {
395 391 append_string(block_start,
396 392 &string,
397 393 source_p - block_start - 1);
398 394 block_start = source_p;
399 395 break;
400 396 }
401 397 append_string(block_start,
402 398 &string,
403 399 source_p - block_start);
404 400 source->string.text.p = ++source_p;
405 401 UNCACHE_SOURCE();
406 402 expand_macro(source, &string, current_string, cmd);
407 403 CACHE_SOURCE(0);
408 404 block_start = source_p;
409 405 source_p--;
410 406 break;
411 407 case parenleft_char:
412 408 /* Allow nested pairs of () in the macro name. */
413 409 if (closer == (int) parenright_char) {
414 410 closer_level++;
415 411 }
416 412 break;
417 413 case braceleft_char:
418 414 /* Allow nested pairs of {} in the macro name. */
419 415 if (closer == (int) braceright_char) {
420 416 closer_level++;
421 417 }
422 418 break;
423 419 case parenright_char:
424 420 case braceright_char:
425 421 /*
426 422 * End of the name. Save the string in the macro
427 423 * name string.
428 424 */
429 425 if ((*source_p == closer) && (--closer_level <= 0)) {
430 426 source->string.text.p = source_p + 1;
431 427 append_string(block_start,
432 428 &string,
433 429 source_p - block_start);
434 430 goto get_macro_value;
435 431 }
436 432 break;
437 433 }
438 434 quote_seen = 0;
439 435 }
440 436 /*
441 437 * We got the macro name. We now inspect it to see if it
442 438 * specifies any translations of the value.
443 439 */
444 440 get_macro_value:
445 441 name = NULL;
446 442 /* First check if we have a $(@D) type translation. */
447 443 if ((get_char_semantics_value(string.buffer.start[0]) &
448 444 (int) special_macro_sem) &&
449 445 (string.text.p - string.buffer.start >= 2) &&
450 446 ((string.buffer.start[1] == 'D') ||
451 447 (string.buffer.start[1] == 'F'))) {
452 448 switch (string.buffer.start[1]) {
453 449 case 'D':
454 450 extraction = dir_extract;
455 451 break;
456 452 case 'F':
457 453 extraction = file_extract;
458 454 break;
459 455 default:
460 456 WCSTOMBS(mbs_buffer, string.buffer.start);
461 457 fatal_reader_mksh(catgets(libmksdmsi18n_catd, 1, 119, "Illegal macro reference `%s'"),
462 458 mbs_buffer);
463 459 }
464 460 /* Internalize the macro name using the first char only. */
465 461 name = GETNAME(string.buffer.start, 1);
466 462 (void) wscpy(string.buffer.start, string.buffer.start + 2);
467 463 }
468 464 /* Check for other kinds of translations. */
469 465 if ((colon = (wchar_t *) wschr(string.buffer.start,
470 466 (int) colon_char)) != NULL) {
471 467 /*
472 468 * We have a $(FOO:.c=.o) type translation.
473 469 * Get the name of the macro proper.
474 470 */
475 471 if (name == NULL) {
476 472 name = GETNAME(string.buffer.start,
477 473 colon - string.buffer.start);
478 474 }
479 475 /* Pickup all the translations. */
480 476 if (IS_WEQUAL(colon, colon_sh) || IS_WEQUAL(colon, colon_shell)) {
481 477 replacement = sh_replace;
482 478 } else if ((svr4) ||
483 479 ((percent = (wchar_t *) wschr(colon + 1,
484 480 (int) percent_char)) == NULL)) {
485 481 while (colon != NULL) {
486 482 if ((eq = (wchar_t *) wschr(colon + 1,
487 483 (int) equal_char)) == NULL) {
488 484 fatal_reader_mksh(catgets(libmksdmsi18n_catd, 1, 120, "= missing from replacement macro reference"));
489 485 }
490 486 left_tail_len = eq - colon - 1;
491 487 if(left_tail) {
492 488 retmem(left_tail);
493 489 }
494 490 left_tail = ALLOC_WC(left_tail_len + 1);
495 491 (void) wsncpy(left_tail,
496 492 colon + 1,
497 493 eq - colon - 1);
498 494 left_tail[eq - colon - 1] = (int) nul_char;
499 495 replacement = suffix_replace;
500 496 if ((colon = (wchar_t *) wschr(eq + 1,
501 497 (int) colon_char)) != NULL) {
502 498 tmp_len = colon - eq;
503 499 if(right_tail) {
504 500 retmem(right_tail);
505 501 }
506 502 right_tail = ALLOC_WC(tmp_len);
507 503 (void) wsncpy(right_tail,
508 504 eq + 1,
509 505 colon - eq - 1);
510 506 right_tail[colon - eq - 1] =
511 507 (int) nul_char;
512 508 } else {
513 509 if(right_tail) {
514 510 retmem(right_tail);
515 511 }
516 512 right_tail = ALLOC_WC(wslen(eq) + 1);
517 513 (void) wscpy(right_tail, eq + 1);
518 514 }
519 515 }
520 516 } else {
521 517 if ((eq = (wchar_t *) wschr(colon + 1,
522 518 (int) equal_char)) == NULL) {
523 519 fatal_reader_mksh(catgets(libmksdmsi18n_catd, 1, 121, "= missing from replacement macro reference"));
524 520 }
525 521 if ((percent = (wchar_t *) wschr(colon + 1,
526 522 (int) percent_char)) == NULL) {
527 523 fatal_reader_mksh(catgets(libmksdmsi18n_catd, 1, 122, "%% missing from replacement macro reference"));
528 524 }
529 525 if (eq < percent) {
530 526 fatal_reader_mksh(catgets(libmksdmsi18n_catd, 1, 123, "%% missing from replacement macro reference"));
531 527 }
532 528
533 529 if (percent > (colon + 1)) {
534 530 tmp_len = percent - colon;
535 531 if(left_head) {
536 532 retmem(left_head);
537 533 }
538 534 left_head = ALLOC_WC(tmp_len);
539 535 (void) wsncpy(left_head,
540 536 colon + 1,
541 537 percent - colon - 1);
542 538 left_head[percent-colon-1] = (int) nul_char;
543 539 left_head_len = percent-colon-1;
544 540 } else {
545 541 left_head = NULL;
546 542 left_head_len = 0;
547 543 }
548 544
549 545 if (eq > percent+1) {
550 546 tmp_len = eq - percent;
551 547 if(left_tail) {
552 548 retmem(left_tail);
553 549 }
554 550 left_tail = ALLOC_WC(tmp_len);
555 551 (void) wsncpy(left_tail,
556 552 percent + 1,
557 553 eq - percent - 1);
558 554 left_tail[eq-percent-1] = (int) nul_char;
559 555 left_tail_len = eq-percent-1;
560 556 } else {
561 557 left_tail = NULL;
562 558 left_tail_len = 0;
563 559 }
564 560
565 561 if ((percent = (wchar_t *) wschr(++eq,
566 562 (int) percent_char)) == NULL) {
567 563
568 564 right_hand[0] = ALLOC_WC(wslen(eq) + 1);
569 565 right_hand[1] = NULL;
570 566 (void) wscpy(right_hand[0], eq);
571 567 } else {
572 568 i = 0;
573 569 do {
574 570 right_hand[i] = ALLOC_WC(percent-eq+1);
575 571 (void) wsncpy(right_hand[i],
576 572 eq,
577 573 percent - eq);
578 574 right_hand[i][percent-eq] =
579 575 (int) nul_char;
580 576 if (i++ >= VSIZEOF(right_hand)) {
581 577 fatal_mksh(catgets(libmksdmsi18n_catd, 1, 124, "Too many %% in pattern"));
582 578 }
583 579 eq = percent + 1;
584 580 if (eq[0] == (int) nul_char) {
585 581 MBSTOWCS(wcs_buffer, "");
586 582 right_hand[i] = (wchar_t *) wsdup(wcs_buffer);
587 583 i++;
588 584 break;
589 585 }
590 586 } while ((percent = (wchar_t *) wschr(eq, (int) percent_char)) != NULL);
591 587 if (eq[0] != (int) nul_char) {
592 588 right_hand[i] = ALLOC_WC(wslen(eq) + 1);
593 589 (void) wscpy(right_hand[i], eq);
594 590 i++;
595 591 }
596 592 right_hand[i] = NULL;
597 593 }
598 594 replacement = pattern_replace;
599 595 }
600 596 }
601 597 if (name == NULL) {
602 598 /*
603 599 * No translations found.
604 600 * Use the whole string as the macro name.
605 601 */
606 602 name = GETNAME(string.buffer.start,
607 603 string.text.p - string.buffer.start);
608 604 }
609 605 if (string.free_after_use) {
610 606 retmem(string.buffer.start);
611 607 }
612 608 if (name == make) {
613 609 make_word_mentioned = true;
614 610 }
615 611 if (name == query) {
616 612 query_mentioned = true;
617 613 }
618 614 if ((name == host_arch) || (name == target_arch)) {
619 615 if (!init_arch_done) {
620 616 init_arch_done = true;
621 617 init_arch_macros();
↓ open down ↓ |
558 lines elided |
↑ open up ↑ |
622 618 }
623 619 }
624 620 if ((name == host_mach) || (name == target_mach)) {
625 621 if (!init_mach_done) {
626 622 init_mach_done = true;
627 623 init_mach_macros();
628 624 }
629 625 }
630 626 /* Get the macro value. */
631 627 macro = get_prop(name->prop, macro_prop);
632 -#ifdef NSE
633 - if (nse_watch_vars && nse && macro != NULL) {
634 - if (macro->body.macro.imported) {
635 - nse_shell_var_used= name;
636 - }
637 - if (macro->body.macro.value != NULL){
638 - if (nse_backquotes(macro->body.macro.value->string)) {
639 - nse_backquote_seen= name;
640 - }
641 - }
642 - }
643 -#endif
644 628 if ((macro != NULL) && macro->body.macro.is_conditional) {
645 629 conditional_macro_used = true;
646 630 /*
647 631 * Add this conditional macro to the beginning of the
648 632 * global list.
649 633 */
650 634 add_macro_to_global_list(name);
651 635 if (makefile_type == reading_makefile) {
652 636 warning_mksh(catgets(libmksdmsi18n_catd, 1, 164, "Conditional macro `%s' referenced in file `%ws', line %d"),
653 637 name->string_mb, file_being_read, line_number);
654 638 }
655 639 }
656 640 /* Macro name read and parsed. Expand the value. */
657 641 if ((macro == NULL) || (macro->body.macro.value == NULL)) {
658 642 /* If the value is empty, we just get out of here. */
659 643 goto exit;
660 644 }
661 645 if (replacement == sh_replace) {
662 646 /* If we should do a :sh transform, we expand the command
663 647 * and process it.
664 648 */
665 649 INIT_STRING_FROM_STACK(string, buffer);
666 650 /* Expand the value into a local string buffer and run cmd. */
667 651 expand_value_with_daemon(name, macro, &string, cmd);
668 652 sh_command2string(&string, destination);
669 653 } else if ((replacement != no_replace) || (extraction != no_extract)) {
670 654 /*
671 655 * If there were any transforms specified in the macro
672 656 * name, we deal with them here.
673 657 */
674 658 INIT_STRING_FROM_STACK(string, buffer);
675 659 /* Expand the value into a local string buffer. */
676 660 expand_value_with_daemon(name, macro, &string, cmd);
677 661 /* Scan the expanded string. */
678 662 p = string.buffer.start;
679 663 while (*p != (int) nul_char) {
680 664 wchar_t chr;
681 665
682 666 /*
683 667 * First skip over any white space and append
684 668 * that to the destination string.
685 669 */
686 670 block_start = p;
687 671 while ((*p != (int) nul_char) && iswspace(*p)) {
688 672 p++;
689 673 }
690 674 append_string(block_start,
691 675 destination,
692 676 p - block_start);
693 677 /* Then find the end of the next word. */
694 678 block_start = p;
695 679 while ((*p != (int) nul_char) && !iswspace(*p)) {
696 680 p++;
697 681 }
698 682 /* If we cant find another word we are done */
699 683 if (block_start == p) {
700 684 break;
701 685 }
702 686 /* Then apply the transforms to the word */
703 687 INIT_STRING_FROM_STACK(extracted, extracted_string);
704 688 switch (extraction) {
705 689 case dir_extract:
706 690 /*
707 691 * $(@D) type transform. Extract the
708 692 * path from the word. Deliver "." if
709 693 * none is found.
710 694 */
711 695 if (p != NULL) {
712 696 chr = *p;
713 697 *p = (int) nul_char;
714 698 }
715 699 eq = (wchar_t *) wsrchr(block_start, (int) slash_char);
716 700 if (p != NULL) {
717 701 *p = chr;
718 702 }
719 703 if ((eq == NULL) || (eq > p)) {
720 704 MBSTOWCS(wcs_buffer, ".");
721 705 append_string(wcs_buffer, &extracted, 1);
722 706 } else {
723 707 append_string(block_start,
724 708 &extracted,
725 709 eq - block_start);
726 710 }
727 711 break;
728 712 case file_extract:
729 713 /*
730 714 * $(@F) type transform. Remove the path
731 715 * from the word if any.
732 716 */
733 717 if (p != NULL) {
734 718 chr = *p;
735 719 *p = (int) nul_char;
736 720 }
737 721 eq = (wchar_t *) wsrchr(block_start, (int) slash_char);
738 722 if (p != NULL) {
739 723 *p = chr;
740 724 }
741 725 if ((eq == NULL) || (eq > p)) {
742 726 append_string(block_start,
743 727 &extracted,
744 728 p - block_start);
745 729 } else {
746 730 append_string(eq + 1,
747 731 &extracted,
748 732 p - eq - 1);
749 733 }
750 734 break;
751 735 case no_extract:
752 736 append_string(block_start,
753 737 &extracted,
754 738 p - block_start);
755 739 break;
756 740 }
757 741 switch (replacement) {
758 742 case suffix_replace:
759 743 /*
760 744 * $(FOO:.o=.c) type transform.
761 745 * Maybe replace the tail of the word.
762 746 */
763 747 if (((extracted.text.p -
764 748 extracted.buffer.start) >=
765 749 left_tail_len) &&
766 750 IS_WEQUALN(extracted.text.p - left_tail_len,
767 751 left_tail,
768 752 left_tail_len)) {
769 753 append_string(extracted.buffer.start,
770 754 destination,
771 755 (extracted.text.p -
772 756 extracted.buffer.start)
773 757 - left_tail_len);
774 758 append_string(right_tail,
775 759 destination,
776 760 FIND_LENGTH);
777 761 } else {
778 762 append_string(extracted.buffer.start,
779 763 destination,
780 764 FIND_LENGTH);
781 765 }
782 766 break;
783 767 case pattern_replace:
784 768 /* $(X:a%b=c%d) type transform. */
785 769 if (((extracted.text.p -
786 770 extracted.buffer.start) >=
787 771 left_head_len+left_tail_len) &&
788 772 IS_WEQUALN(left_head,
789 773 extracted.buffer.start,
790 774 left_head_len) &&
791 775 IS_WEQUALN(left_tail,
792 776 extracted.text.p - left_tail_len,
793 777 left_tail_len)) {
794 778 i = 0;
795 779 while (right_hand[i] != NULL) {
796 780 append_string(right_hand[i],
797 781 destination,
798 782 FIND_LENGTH);
799 783 i++;
800 784 if (right_hand[i] != NULL) {
801 785 append_string(extracted.buffer.
802 786 start +
803 787 left_head_len,
804 788 destination,
805 789 (extracted.text.p - extracted.buffer.start)-left_head_len-left_tail_len);
806 790 }
807 791 }
808 792 } else {
809 793 append_string(extracted.buffer.start,
810 794 destination,
811 795 FIND_LENGTH);
812 796 }
813 797 break;
814 798 case no_replace:
815 799 append_string(extracted.buffer.start,
816 800 destination,
817 801 FIND_LENGTH);
818 802 break;
819 803 case sh_replace:
820 804 break;
821 805 }
822 806 }
823 807 if (string.free_after_use) {
824 808 retmem(string.buffer.start);
825 809 }
826 810 } else {
827 811 /*
828 812 * This is for the case when the macro name did not
829 813 * specify transforms.
830 814 */
831 815 if (!strncmp(name->string_mb, NOCATGETS("GET"), 3)) {
832 816 dollarget_seen = true;
833 817 }
834 818 dollarless_flag = false;
835 819 if (!strncmp(name->string_mb, "<", 1) &&
836 820 dollarget_seen) {
837 821 dollarless_flag = true;
838 822 dollarget_seen = false;
839 823 }
840 824 expand_value_with_daemon(name, macro, destination, cmd);
841 825 }
842 826 exit:
843 827 if(left_tail) {
844 828 retmem(left_tail);
845 829 }
846 830 if(right_tail) {
847 831 retmem(right_tail);
848 832 }
849 833 if(left_head) {
850 834 retmem(left_head);
851 835 }
852 836 i = 0;
853 837 while (right_hand[i] != NULL) {
854 838 retmem(right_hand[i]);
855 839 i++;
856 840 }
857 841 *destination->text.p = (int) nul_char;
858 842 destination->text.end = destination->text.p;
859 843 }
860 844
861 845 static void
862 846 add_macro_to_global_list(Name macro_to_add)
863 847 {
864 848 Macro_list new_macro;
865 849 Macro_list macro_on_list;
866 850 char *name_on_list = (char*)NULL;
867 851 char *name_to_add = macro_to_add->string_mb;
868 852 char *value_on_list = (char*)NULL;
869 853 const char *value_to_add = (char*)NULL;
870 854
871 855 if (macro_to_add->prop->body.macro.value != NULL) {
872 856 value_to_add = macro_to_add->prop->body.macro.value->string_mb;
873 857 } else {
874 858 value_to_add = "";
875 859 }
876 860
877 861 /*
878 862 * Check if this macro is already on list, if so, do nothing
879 863 */
880 864 for (macro_on_list = cond_macro_list;
881 865 macro_on_list != NULL;
882 866 macro_on_list = macro_on_list->next) {
883 867
884 868 name_on_list = macro_on_list->macro_name;
885 869 value_on_list = macro_on_list->value;
886 870
887 871 if (IS_EQUAL(name_on_list, name_to_add)) {
888 872 if (IS_EQUAL(value_on_list, value_to_add)) {
889 873 return;
890 874 }
891 875 }
892 876 }
893 877 new_macro = (Macro_list) malloc(sizeof(Macro_list_rec));
894 878 new_macro->macro_name = strdup(name_to_add);
895 879 new_macro->value = strdup(value_to_add);
896 880 new_macro->next = cond_macro_list;
897 881 cond_macro_list = new_macro;
898 882 }
899 883
900 884 /*
901 885 * init_arch_macros(void)
902 886 *
903 887 * Set the magic macros TARGET_ARCH, HOST_ARCH,
904 888 *
905 889 * Parameters:
906 890 *
907 891 * Global variables used:
908 892 * host_arch Property for magic macro HOST_ARCH
909 893 * target_arch Property for magic macro TARGET_ARCH
910 894 *
911 895 * Return value:
912 896 * The function does not return a value, but can
913 897 * call fatal() in case of error.
↓ open down ↓ |
260 lines elided |
↑ open up ↑ |
914 898 */
915 899 static void
916 900 init_arch_macros(void)
917 901 {
918 902 String_rec result_string;
919 903 wchar_t wc_buf[STRING_BUFFER_LENGTH];
920 904 char mb_buf[STRING_BUFFER_LENGTH];
921 905 FILE *pipe;
922 906 Name value;
923 907 int set_host, set_target;
924 -#ifdef NSE
925 - Property macro;
926 -#endif
927 908 const char *mach_command = NOCATGETS("/bin/mach");
928 909
929 910 set_host = (get_prop(host_arch->prop, macro_prop) == NULL);
930 911 set_target = (get_prop(target_arch->prop, macro_prop) == NULL);
931 912
932 913 if (set_host || set_target) {
933 914 INIT_STRING_FROM_STACK(result_string, wc_buf);
934 915 append_char((int) hyphen_char, &result_string);
935 916
936 917 if ((pipe = popen(mach_command, "r")) == NULL) {
937 918 fatal_mksh(catgets(libmksdmsi18n_catd, 1, 185, "Execute of %s failed"), mach_command);
938 919 }
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
939 920 while (fgets(mb_buf, sizeof(mb_buf), pipe) != NULL) {
940 921 MBSTOWCS(wcs_buffer, mb_buf);
941 922 append_string(wcs_buffer, &result_string, wslen(wcs_buffer));
942 923 }
943 924 if (pclose(pipe) != 0) {
944 925 fatal_mksh(catgets(libmksdmsi18n_catd, 1, 186, "Execute of %s failed"), mach_command);
945 926 }
946 927
947 928 value = GETNAME(result_string.buffer.start, wslen(result_string.buffer.start));
948 929
949 -#ifdef NSE
950 - macro = setvar_daemon(host_arch, value, false, no_daemon, true, 0);
951 - macro->body.macro.imported= true;
952 - macro = setvar_daemon(target_arch, value, false, no_daemon, true, 0);
953 - macro->body.macro.imported= true;
954 -#else
955 930 if (set_host) {
956 931 (void) setvar_daemon(host_arch, value, false, no_daemon, true, 0);
957 932 }
958 933 if (set_target) {
959 934 (void) setvar_daemon(target_arch, value, false, no_daemon, true, 0);
960 935 }
961 -#endif
962 936 }
963 937 }
964 938
965 939 /*
966 940 * init_mach_macros(void)
967 941 *
968 942 * Set the magic macros TARGET_MACH, HOST_MACH,
969 943 *
970 944 * Parameters:
971 945 *
972 946 * Global variables used:
973 947 * host_mach Property for magic macro HOST_MACH
974 948 * target_mach Property for magic macro TARGET_MACH
975 949 *
976 950 * Return value:
977 951 * The function does not return a value, but can
978 952 * call fatal() in case of error.
979 953 */
980 954 static void
981 955 init_mach_macros(void)
982 956 {
983 957 String_rec result_string;
984 958 wchar_t wc_buf[STRING_BUFFER_LENGTH];
985 959 char mb_buf[STRING_BUFFER_LENGTH];
986 960 FILE *pipe;
987 961 Name value;
988 962 int set_host, set_target;
989 963 const char *arch_command = NOCATGETS("/bin/arch");
990 964
991 965 set_host = (get_prop(host_mach->prop, macro_prop) == NULL);
992 966 set_target = (get_prop(target_mach->prop, macro_prop) == NULL);
993 967
994 968 if (set_host || set_target) {
995 969 INIT_STRING_FROM_STACK(result_string, wc_buf);
996 970 append_char((int) hyphen_char, &result_string);
997 971
998 972 if ((pipe = popen(arch_command, "r")) == NULL) {
999 973 fatal_mksh(catgets(libmksdmsi18n_catd, 1, 183, "Execute of %s failed"), arch_command);
1000 974 }
1001 975 while (fgets(mb_buf, sizeof(mb_buf), pipe) != NULL) {
1002 976 MBSTOWCS(wcs_buffer, mb_buf);
1003 977 append_string(wcs_buffer, &result_string, wslen(wcs_buffer));
1004 978 }
1005 979 if (pclose(pipe) != 0) {
1006 980 fatal_mksh(catgets(libmksdmsi18n_catd, 1, 184, "Execute of %s failed"), arch_command);
1007 981 }
1008 982
1009 983 value = GETNAME(result_string.buffer.start, wslen(result_string.buffer.start));
1010 984
1011 985 if (set_host) {
1012 986 (void) setvar_daemon(host_mach, value, false, no_daemon, true, 0);
1013 987 }
1014 988 if (set_target) {
1015 989 (void) setvar_daemon(target_mach, value, false, no_daemon, true, 0);
1016 990 }
1017 991 }
1018 992 }
1019 993
1020 994 /*
1021 995 * expand_value_with_daemon(name, macro, destination, cmd)
1022 996 *
1023 997 * Checks for daemons and then maybe calls expand_value().
1024 998 *
↓ open down ↓ |
53 lines elided |
↑ open up ↑ |
1025 999 * Parameters:
1026 1000 * name Name of the macro (Added by the NSE)
1027 1001 * macro The property block with the value to expand
1028 1002 * destination Where the result should be deposited
1029 1003 * cmd If we are evaluating a command line we
1030 1004 * turn \ quoting off
1031 1005 *
1032 1006 * Global variables used:
1033 1007 */
1034 1008 static void
1035 -#ifdef NSE
1036 -expand_value_with_daemon(Name name, register Property macro, register String destination, Boolean cmd)
1037 -#else
1038 1009 expand_value_with_daemon(Name, register Property macro, register String destination, Boolean cmd)
1039 -#endif
1040 1010 {
1041 1011 register Chain chain;
1042 1012
1043 -#ifdef NSE
1044 - if (reading_dependencies) {
1045 - /*
1046 - * Processing the dependencies themselves
1047 - */
1048 - depvar_dep_macro_used(name);
1049 - } else {
1050 - /*
1051 - * Processing the rules for the targets
1052 - * the nse_watch_vars flags chokes off most
1053 - * checks. it is true only when processing
1054 - * the output from a recursive make run
1055 - * which is all we are interested in here.
1056 - */
1057 - if (nse_watch_vars) {
1058 - depvar_rule_macro_used(name);
1059 - }
1060 - }
1061 -#endif
1062 1013
1063 1014 switch (macro->body.macro.daemon) {
1064 1015 case no_daemon:
1065 1016 if (!svr4 && !posix) {
1066 1017 expand_value(macro->body.macro.value, destination, cmd);
1067 1018 } else {
1068 1019 if (dollarless_flag && tilde_rule) {
1069 1020 expand_value(dollarless_value, destination, cmd);
1070 1021 dollarless_flag = false;
1071 1022 tilde_rule = false;
1072 1023 } else {
1073 1024 expand_value(macro->body.macro.value, destination, cmd);
1074 1025 }
1075 1026 }
1076 1027 return;
1077 1028 case chain_daemon:
1078 1029 /* If this is a $? value we call the daemon to translate the */
1079 1030 /* list of names to a string */
1080 1031 for (chain = (Chain) macro->body.macro.value;
1081 1032 chain != NULL;
1082 1033 chain = chain->next) {
1083 1034 APPEND_NAME(chain->name,
1084 1035 destination,
1085 1036 (int) chain->name->hash.length);
1086 1037 if (chain->next != NULL) {
1087 1038 append_char((int) space_char, destination);
1088 1039 }
1089 1040 }
1090 1041 return;
1091 1042 }
1092 1043 }
1093 1044
1094 1045 /*
1095 1046 * We use a permanent buffer to reset SUNPRO_DEPENDENCIES value.
1096 1047 */
1097 1048 char *sunpro_dependencies_buf = NULL;
1098 1049 char *sunpro_dependencies_oldbuf = NULL;
1099 1050 int sunpro_dependencies_buf_size = 0;
1100 1051
1101 1052 /*
1102 1053 * setvar_daemon(name, value, append, daemon, strip_trailing_spaces)
1103 1054 *
1104 1055 * Set a macro value, possibly supplying a daemon to be used
1105 1056 * when referencing the value.
1106 1057 *
1107 1058 * Return value:
1108 1059 * The property block with the new value
1109 1060 *
1110 1061 * Parameters:
1111 1062 * name Name of the macro to set
1112 1063 * value The value to set
1113 1064 * append Should we reset or append to the current value?
1114 1065 * daemon Special treatment when reading the value
1115 1066 * strip_trailing_spaces from the end of value->string
1116 1067 * debug_level Indicates how much tracing we should do
1117 1068 *
1118 1069 * Global variables used:
1119 1070 * makefile_type Used to check if we should enforce read only
1120 1071 * path_name The Name "PATH", compared against
1121 1072 * virtual_root The Name "VIRTUAL_ROOT", compared against
1122 1073 * vpath_defined Set if the macro VPATH is set
1123 1074 * vpath_name The Name "VPATH", compared against
1124 1075 * envvar A list of environment vars with $ in value
1125 1076 */
1126 1077 Property
1127 1078 setvar_daemon(register Name name, register Name value, Boolean append, Daemon daemon, Boolean strip_trailing_spaces, short debug_level)
1128 1079 {
↓ open down ↓ |
57 lines elided |
↑ open up ↑ |
1129 1080 register Property macro = maybe_append_prop(name, macro_prop);
1130 1081 register Property macro_apx = get_prop(name->prop, macro_append_prop);
1131 1082 int length = 0;
1132 1083 String_rec destination;
1133 1084 wchar_t buffer[STRING_BUFFER_LENGTH];
1134 1085 register Chain chain;
1135 1086 Name val;
1136 1087 wchar_t *val_string = (wchar_t*)NULL;
1137 1088 Wstring wcb;
1138 1089
1139 -#ifdef NSE
1140 - macro->body.macro.imported = false;
1141 -#endif
1142 1090
1143 1091 if ((makefile_type != reading_nothing) &&
1144 1092 macro->body.macro.read_only) {
1145 1093 return macro;
1146 1094 }
1147 1095 /* Strip spaces from the end of the value */
1148 1096 if (daemon == no_daemon) {
1149 1097 if(value != NULL) {
1150 1098 wcb.init(value);
1151 1099 length = wcb.length();
1152 1100 val_string = wcb.get_string();
1153 1101 }
1154 1102 if ((length > 0) && iswspace(val_string[length-1])) {
1155 1103 INIT_STRING_FROM_STACK(destination, buffer);
1156 1104 buffer[0] = 0;
1157 1105 append_string(val_string, &destination, length);
1158 1106 if (strip_trailing_spaces) {
1159 1107 while ((length > 0) &&
1160 1108 iswspace(destination.buffer.start[length-1])) {
1161 1109 destination.buffer.start[--length] = 0;
1162 1110 }
1163 1111 }
1164 1112 value = GETNAME(destination.buffer.start, FIND_LENGTH);
1165 1113 }
1166 1114 }
1167 1115
1168 1116 if(macro_apx != NULL) {
1169 1117 val = macro_apx->body.macro_appendix.value;
1170 1118 } else {
1171 1119 val = macro->body.macro.value;
1172 1120 }
1173 1121
1174 1122 if (append) {
1175 1123 /*
1176 1124 * If we are appending, we just tack the new value after
1177 1125 * the old one with a space in between.
1178 1126 */
1179 1127 INIT_STRING_FROM_STACK(destination, buffer);
1180 1128 buffer[0] = 0;
1181 1129 if ((macro != NULL) && (val != NULL)) {
1182 1130 APPEND_NAME(val,
1183 1131 &destination,
1184 1132 (int) val->hash.length);
1185 1133 if (value != NULL) {
1186 1134 wcb.init(value);
1187 1135 if(wcb.length() > 0) {
1188 1136 MBTOWC(wcs_buffer, " ");
1189 1137 append_char(wcs_buffer[0], &destination);
1190 1138 }
1191 1139 }
1192 1140 }
1193 1141 if (value != NULL) {
1194 1142 APPEND_NAME(value,
1195 1143 &destination,
1196 1144 (int) value->hash.length);
1197 1145 }
1198 1146 value = GETNAME(destination.buffer.start, FIND_LENGTH);
1199 1147 wcb.init(value);
1200 1148 if (destination.free_after_use) {
1201 1149 retmem(destination.buffer.start);
1202 1150 }
1203 1151 }
1204 1152
1205 1153 /* Debugging trace */
1206 1154 if (debug_level > 1) {
1207 1155 if (value != NULL) {
1208 1156 switch (daemon) {
1209 1157 case chain_daemon:
1210 1158 (void) printf("%s =", name->string_mb);
1211 1159 for (chain = (Chain) value;
1212 1160 chain != NULL;
1213 1161 chain = chain->next) {
1214 1162 (void) printf(" %s", chain->name->string_mb);
1215 1163 }
1216 1164 (void) printf("\n");
1217 1165 break;
1218 1166 case no_daemon:
1219 1167 (void) printf("%s= %s\n",
1220 1168 name->string_mb,
1221 1169 value->string_mb);
1222 1170 break;
1223 1171 }
1224 1172 } else {
1225 1173 (void) printf("%s =\n", name->string_mb);
1226 1174 }
1227 1175 }
1228 1176 /* Set the new values in the macro property block */
1229 1177 /**/
1230 1178 if(macro_apx != NULL) {
1231 1179 macro_apx->body.macro_appendix.value = value;
1232 1180 INIT_STRING_FROM_STACK(destination, buffer);
1233 1181 buffer[0] = 0;
1234 1182 if (value != NULL) {
1235 1183 APPEND_NAME(value,
1236 1184 &destination,
1237 1185 (int) value->hash.length);
1238 1186 if (macro_apx->body.macro_appendix.value_to_append != NULL) {
1239 1187 MBTOWC(wcs_buffer, " ");
1240 1188 append_char(wcs_buffer[0], &destination);
1241 1189 }
1242 1190 }
1243 1191 if (macro_apx->body.macro_appendix.value_to_append != NULL) {
1244 1192 APPEND_NAME(macro_apx->body.macro_appendix.value_to_append,
1245 1193 &destination,
1246 1194 (int) macro_apx->body.macro_appendix.value_to_append->hash.length);
1247 1195 }
1248 1196 value = GETNAME(destination.buffer.start, FIND_LENGTH);
1249 1197 if (destination.free_after_use) {
1250 1198 retmem(destination.buffer.start);
1251 1199 }
1252 1200 }
1253 1201 /**/
1254 1202 macro->body.macro.value = value;
1255 1203 macro->body.macro.daemon = daemon;
1256 1204 /*
1257 1205 * If the user changes the VIRTUAL_ROOT, we need to flush
1258 1206 * the vroot package cache.
1259 1207 */
1260 1208 if (name == path_name) {
1261 1209 flush_path_cache();
1262 1210 }
1263 1211 if (name == virtual_root) {
1264 1212 flush_vroot_cache();
1265 1213 }
1266 1214 /* If this sets the VPATH we remember that */
1267 1215 if ((name == vpath_name) &&
1268 1216 (value != NULL) &&
1269 1217 (value->hash.length > 0)) {
1270 1218 vpath_defined = true;
1271 1219 }
1272 1220 /*
1273 1221 * For environment variables we also set the
1274 1222 * environment value each time.
1275 1223 */
1276 1224 if (macro->body.macro.exported) {
1277 1225 static char *env;
1278 1226
1279 1227 #ifdef DISTRIBUTED
1280 1228 if (!reading_environment && (value != NULL)) {
1281 1229 #else
1282 1230 if (!reading_environment && (value != NULL) && value->dollar) {
1283 1231 #endif
1284 1232 Envvar p;
1285 1233
1286 1234 for (p = envvar; p != NULL; p = p->next) {
1287 1235 if (p->name == name) {
1288 1236 p->value = value;
1289 1237 p->already_put = false;
1290 1238 goto found_it;
1291 1239 }
1292 1240 }
1293 1241 p = ALLOC(Envvar);
1294 1242 p->name = name;
1295 1243 p->value = value;
1296 1244 p->next = envvar;
1297 1245 p->env_string = NULL;
1298 1246 p->already_put = false;
1299 1247 envvar = p;
1300 1248 found_it:;
1301 1249 #ifdef DISTRIBUTED
1302 1250 }
1303 1251 if (reading_environment || (value == NULL) || !value->dollar) {
1304 1252 #else
1305 1253 } else {
1306 1254 #endif
1307 1255 length = 2 + strlen(name->string_mb);
1308 1256 if (value != NULL) {
1309 1257 length += strlen(value->string_mb);
1310 1258 }
1311 1259 Property env_prop = maybe_append_prop(name, env_mem_prop);
1312 1260 /*
1313 1261 * We use a permanent buffer to reset SUNPRO_DEPENDENCIES value.
1314 1262 */
1315 1263 if (!strncmp(name->string_mb, NOCATGETS("SUNPRO_DEPENDENCIES"), 19)) {
1316 1264 if (length >= sunpro_dependencies_buf_size) {
1317 1265 sunpro_dependencies_buf_size=length*2;
1318 1266 if (sunpro_dependencies_buf_size < 4096)
1319 1267 sunpro_dependencies_buf_size = 4096; // Default minimum size
1320 1268 if (sunpro_dependencies_buf)
1321 1269 sunpro_dependencies_oldbuf = sunpro_dependencies_buf;
1322 1270 sunpro_dependencies_buf=getmem(sunpro_dependencies_buf_size);
1323 1271 }
1324 1272 env = sunpro_dependencies_buf;
1325 1273 } else {
1326 1274 env = getmem(length);
1327 1275 }
1328 1276 env_alloc_num++;
1329 1277 env_alloc_bytes += length;
1330 1278 (void) sprintf(env,
1331 1279 "%s=%s",
1332 1280 name->string_mb,
1333 1281 value == NULL ?
1334 1282 "" : value->string_mb);
1335 1283 (void) putenv(env);
1336 1284 env_prop->body.env_mem.value = env;
1337 1285 if (sunpro_dependencies_oldbuf) {
1338 1286 /* Return old buffer */
1339 1287 retmem_mb(sunpro_dependencies_oldbuf);
1340 1288 sunpro_dependencies_oldbuf = NULL;
1341 1289 }
1342 1290 }
1343 1291 }
1344 1292 if (name == target_arch) {
1345 1293 Name ha = getvar(host_arch);
1346 1294 Name ta = getvar(target_arch);
1347 1295 Name vr = getvar(virtual_root);
1348 1296 int length;
1349 1297 wchar_t *new_value;
1350 1298 wchar_t *old_vr;
1351 1299 Boolean new_value_allocated = false;
1352 1300
1353 1301 Wstring ha_str(ha);
1354 1302 Wstring ta_str(ta);
1355 1303 Wstring vr_str(vr);
1356 1304
1357 1305 wchar_t * wcb_ha = ha_str.get_string();
1358 1306 wchar_t * wcb_ta = ta_str.get_string();
1359 1307 wchar_t * wcb_vr = vr_str.get_string();
1360 1308
1361 1309 length = 32 +
1362 1310 wslen(wcb_ha) +
1363 1311 wslen(wcb_ta) +
1364 1312 wslen(wcb_vr);
1365 1313 old_vr = wcb_vr;
1366 1314 MBSTOWCS(wcs_buffer, NOCATGETS("/usr/arch/"));
1367 1315 if (IS_WEQUALN(old_vr,
1368 1316 wcs_buffer,
1369 1317 wslen(wcs_buffer))) {
1370 1318 old_vr = (wchar_t *) wschr(old_vr, (int) colon_char) + 1;
1371 1319 }
1372 1320 if ( (ha == ta) || (wslen(wcb_ta) == 0) ) {
1373 1321 new_value = old_vr;
1374 1322 } else {
1375 1323 new_value = ALLOC_WC(length);
1376 1324 new_value_allocated = true;
1377 1325 WCSTOMBS(mbs_buffer, old_vr);
1378 1326 (void) wsprintf(new_value,
1379 1327 NOCATGETS("/usr/arch/%s/%s:%s"),
1380 1328 ha->string_mb + 1,
1381 1329 ta->string_mb + 1,
1382 1330 mbs_buffer);
1383 1331 }
1384 1332 if (new_value[0] != 0) {
1385 1333 (void) setvar_daemon(virtual_root,
1386 1334 GETNAME(new_value, FIND_LENGTH),
1387 1335 false,
1388 1336 no_daemon,
1389 1337 true,
1390 1338 debug_level);
1391 1339 }
1392 1340 if (new_value_allocated) {
1393 1341 retmem(new_value);
1394 1342 }
1395 1343 }
1396 1344 return macro;
1397 1345 }
↓ open down ↓ |
246 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX