4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
29 * Handle expansion of make macros
36 #include <mksh/macro.h> /* getvar(), expand_value() */
37 #include <mksh/misc.h> /* getmem() */
52 * File table of contents
56 setvar_append(register Name name
, register Name value
)
58 register Property macro_apx
= get_prop(name
->prop
, macro_append_prop
);
59 register Property macro
= get_prop(name
->prop
, macro_prop
);
61 String_rec destination
;
62 wchar_t buffer
[STRING_BUFFER_LENGTH
];
66 if(macro_apx
== NULL
) {
67 macro_apx
= append_prop(name
, macro_append_prop
);
69 macro_apx
->body
.macro_appendix
.value
= macro
->body
.macro
.value
;
73 val
= macro_apx
->body
.macro_appendix
.value_to_append
;
75 INIT_STRING_FROM_STACK(destination
, buffer
);
80 (int) val
->hash
.length
);
82 MBTOWC(wcs_buffer
, " ");
83 append_char(wcs_buffer
[0], &destination
);
89 (int) value
->hash
.length
);
91 value
= GETNAME(destination
.buffer
.start
, FIND_LENGTH
);
92 if (destination
.free_after_use
) {
93 retmem(destination
.buffer
.start
);
95 macro_apx
->body
.macro_appendix
.value_to_append
= value
;
97 SETVAR(name
, empty_name
, true);
103 * This function scans the list of environment variables that have
104 * dynamic values and sets them.
108 * Global variables used:
109 * envvar A list of environment vars with $ in value
114 wchar_t buffer
[STRING_BUFFER_LENGTH
];
116 register char *mbs
, *tmp_mbs_buffer
= NULL
;
117 register char *env
, *tmp_mbs_buffer2
= NULL
;
121 for (p
= envvar
; p
!= NULL
; p
= p
->next
) {
126 INIT_STRING_FROM_STACK(value
, buffer
);
127 expand_value(p
->value
, &value
, false);
128 if ((length
= wcslen(value
.buffer
.start
)) >= MAXPATHLEN
) {
129 mbs
= tmp_mbs_buffer
= getmem((length
+ 1) * MB_LEN_MAX
);
132 (length
+ 1) * MB_LEN_MAX
);
135 WCSTOMBS(mbs
, value
.buffer
.start
);
137 length
= 2 + strlen(p
->name
->string_mb
) + strlen(mbs
);
138 if (!p
->already_put
|| length
> (MAXPATHLEN
* MB_LEN_MAX
)) {
139 env
= tmp_mbs_buffer2
= getmem(length
);
147 if (!p
->already_put
) {
149 p
->already_put
= true;
151 retmem_mb(p
->env_string
);
154 tmp_mbs_buffer2
= NULL
; // We should not return this memory now
156 if (tmp_mbs_buffer2
) {
157 retmem_mb(tmp_mbs_buffer2
);
158 tmp_mbs_buffer2
= NULL
;
160 if (tmp_mbs_buffer
) {
161 retmem_mb(tmp_mbs_buffer
);
162 tmp_mbs_buffer
= NULL
;