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