Print this page
make: translate using gettext, rather than the unmaintainable catgets
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/make/lib/vroot/vroot.cc
+++ new/usr/src/cmd/make/lib/vroot/vroot.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 2004 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26
↓ open down ↓ |
26 lines elided |
↑ open up ↑ |
27 27 #include <stdlib.h>
28 28 #include <string.h>
29 29
30 30 #include <vroot/vroot.h>
31 31 #include <vroot/args.h>
32 32
33 33 #include <string.h>
34 34 #include <sys/param.h>
35 35 #include <sys/file.h>
36 36
37 -#include <avo/intl.h> /* for NOCATGETS */
38 -
39 37 typedef struct {
40 38 short init;
41 39 pathpt vector;
42 40 const char *env_var;
43 41 } vroot_patht;
44 42
45 43 typedef struct {
46 44 vroot_patht vroot;
47 45 vroot_patht path;
48 46 char full_path[MAXPATHLEN+1];
49 47 char *vroot_start;
50 48 char *path_start;
51 49 char *filename_start;
52 50 int scan_vroot_first;
53 51 int cpp_style_path;
54 52 } vroot_datat, *vroot_datapt;
55 53
56 54 static vroot_datat vroot_data= {
57 - { 0, NULL, NOCATGETS("VIRTUAL_ROOT")},
58 - { 0, NULL, NOCATGETS("PATH")},
55 + { 0, NULL, "VIRTUAL_ROOT"},
56 + { 0, NULL, "PATH"},
59 57 "", NULL, NULL, NULL, 0, 1};
60 58
61 59 void
62 60 add_dir_to_path(const char *path, register pathpt *pointer, register int position)
63 61 {
64 62 register int size= 0;
65 63 register int length;
66 64 register char *name;
67 65 register pathcellpt p;
68 66 pathpt new_path;
69 67
70 68 if (*pointer != NULL) {
71 69 for (p= &((*pointer)[0]); p->path != NULL; p++, size++);
72 70 if (position < 0)
73 71 position= size;}
74 72 else
75 73 if (position < 0)
76 74 position= 0;
77 75 if (position >= size) {
78 76 new_path= (pathpt)calloc((unsigned)(position+2), sizeof(pathcellt));
79 77 if (*pointer != NULL) {
80 78 memcpy((char *)new_path,(char *)(*pointer), size*sizeof(pathcellt));
81 79 free((char *)(*pointer));};
82 80 *pointer= new_path;};
83 81 length= strlen(path);
84 82 name= (char *)malloc((unsigned)(length+1));
85 83 (void)strcpy(name, path);
86 84 if ((*pointer)[position].path != NULL)
87 85 free((*pointer)[position].path);
88 86 (*pointer)[position].path= name;
89 87 (*pointer)[position].length= length;
90 88 }
91 89
92 90 pathpt
93 91 parse_path_string(register char *string, register int remove_slash)
94 92 {
95 93 register char *p;
96 94 pathpt result= NULL;
97 95
98 96 if (string != NULL)
99 97 for (; 1; string= p+1) {
100 98 if (p= strchr(string, ':')) *p= 0;
101 99 if ((remove_slash == 1) && !strcmp(string, "/"))
102 100 add_dir_to_path("", &result, -1);
103 101 else
104 102 add_dir_to_path(string, &result, -1);
105 103 if (p) *p= ':';
106 104 else return(result);};
107 105 return((pathpt)NULL);
108 106 }
109 107
110 108 const char *
111 109 get_vroot_name(void)
112 110 {
113 111 return(vroot_data.vroot.env_var);
114 112 }
115 113
116 114 const char *
117 115 get_path_name(void)
118 116 {
119 117 return(vroot_data.path.env_var);
120 118 }
121 119
122 120 void
123 121 flush_path_cache(void)
124 122 {
125 123 vroot_data.path.init= 0;
126 124 }
127 125
128 126 void
129 127 flush_vroot_cache(void)
130 128 {
131 129 vroot_data.vroot.init= 0;
132 130 }
133 131
134 132 void
135 133 scan_path_first(void)
136 134 {
137 135 vroot_data.scan_vroot_first= 0;
138 136 }
139 137
140 138 void
141 139 scan_vroot_first(void)
142 140 {
143 141 vroot_data.scan_vroot_first= 1;
144 142 }
145 143
146 144 void
147 145 set_path_style(int style)
148 146 {
149 147 vroot_data.cpp_style_path= style;
150 148 }
151 149
152 150 char *
153 151 get_vroot_path(register char **vroot, register char **path, register char **filename)
154 152 {
155 153 if (vroot != NULL) {
156 154 if ((*vroot= vroot_data.vroot_start) == NULL)
157 155 if ((*vroot= vroot_data.path_start) == NULL)
158 156 *vroot= vroot_data.filename_start;};
159 157 if (path != NULL) {
160 158 if ((*path= vroot_data.path_start) == NULL)
161 159 *path= vroot_data.filename_start;};
162 160 if (filename != NULL)
163 161 *filename= vroot_data.filename_start;
164 162 return(vroot_data.full_path);
165 163 }
166 164
167 165 void
168 166 translate_with_thunk(register char *filename, int (*thunk) (char *), pathpt path_vector, pathpt vroot_vector, rwt rw)
169 167 {
170 168 register pathcellt *vp;
171 169 pathcellt *pp;
172 170 register pathcellt *pp1;
173 171 register char *p;
174 172 int flags[256];
175 173
176 174 /* Setup path to use */
177 175 if (rw == rw_write)
178 176 pp1= NULL; /* Do not use path when writing */
179 177 else {
180 178 if (path_vector == VROOT_DEFAULT) {
181 179 if (!vroot_data.path.init) {
182 180 vroot_data.path.init= 1;
183 181 vroot_data.path.vector= parse_path_string(getenv(vroot_data.path.env_var), 0);};
184 182 path_vector= vroot_data.path.vector;};
185 183 pp1= path_vector == NULL ? NULL : &(path_vector)[0];};
186 184
187 185 /* Setup vroot to use */
188 186 if (vroot_vector == VROOT_DEFAULT) {
189 187 if (!vroot_data.vroot.init) {
190 188 vroot_data.vroot.init= 1;
191 189 vroot_data.vroot.vector= parse_path_string(getenv(vroot_data.vroot.env_var), 1);};
192 190 vroot_vector= vroot_data.vroot.vector;};
193 191 vp= vroot_vector == NULL ? NULL : &(vroot_vector)[0];
194 192
195 193 /* Setup to remember pieces */
196 194 vroot_data.vroot_start= NULL;
197 195 vroot_data.path_start= NULL;
198 196 vroot_data.filename_start= NULL;
199 197
200 198 int flen = strlen(filename);
201 199 if(flen >= MAXPATHLEN) {
202 200 errno = ENAMETOOLONG;
203 201 return;
204 202 }
205 203
206 204 switch ((vp ?1:0) + (pp1 ? 2:0)) {
207 205 case 0: /* No path. No vroot. */
208 206 use_name:
209 207 (void)strcpy(vroot_data.full_path, filename);
210 208 vroot_data.filename_start= vroot_data.full_path;
211 209 (void)(*thunk)(vroot_data.full_path);
212 210 return;
213 211 case 1: /* No path. Vroot */
214 212 if (filename[0] != '/') goto use_name;
215 213 for (; vp->path != NULL; vp++) {
216 214 if((1 + flen + vp->length) >= MAXPATHLEN) {
217 215 errno = ENAMETOOLONG;
218 216 continue;
219 217 }
220 218 p= vroot_data.full_path;
221 219 (void)strcpy(vroot_data.vroot_start= p, vp->path);
222 220 p+= vp->length;
223 221 (void)strcpy(vroot_data.filename_start= p, filename);
224 222 if ((*thunk)(vroot_data.full_path)) return;};
225 223 (void)strcpy(vroot_data.full_path, filename);
226 224 return;
227 225 case 2: /* Path. No vroot. */
228 226 if (vroot_data.cpp_style_path) {
229 227 if (filename[0] == '/') goto use_name;
230 228 } else {
231 229 if (strchr(filename, '/') != NULL) goto use_name;
232 230 };
233 231 for (; pp1->path != NULL; pp1++) {
234 232 p= vroot_data.full_path;
235 233 if((1 + flen + pp1->length) >= MAXPATHLEN) {
236 234 errno = ENAMETOOLONG;
237 235 continue;
238 236 }
239 237 if (vroot_data.cpp_style_path) {
240 238 (void)strcpy(vroot_data.path_start= p, pp1->path);
241 239 p+= pp1->length;
242 240 *p++= '/';
243 241 } else {
244 242 if (pp1->length != 0) {
245 243 (void)strcpy(vroot_data.path_start= p,
246 244 pp1->path);
247 245 p+= pp1->length;
248 246 *p++= '/';
249 247 };
250 248 };
251 249 (void)strcpy(vroot_data.filename_start= p, filename);
252 250 if ((*thunk)(vroot_data.full_path)) return;};
253 251 (void)strcpy(vroot_data.full_path, filename);
254 252 return;
255 253 case 3: { /* Path. Vroot. */
256 254 int *rel_path, path_len= 1;
257 255 if (vroot_data.scan_vroot_first == 0) {
258 256 for (pp= pp1; pp->path != NULL; pp++) path_len++;
259 257 rel_path= flags;
260 258 for (path_len-= 2; path_len >= 0; path_len--) rel_path[path_len]= 0;
261 259 for (; vp->path != NULL; vp++)
262 260 for (pp= pp1, path_len= 0; pp->path != NULL; pp++, path_len++) {
263 261 int len = 0;
264 262 if (rel_path[path_len] == 1) continue;
265 263 if (pp->path[0] != '/') rel_path[path_len]= 1;
266 264 p= vroot_data.full_path;
267 265 if ((filename[0] == '/') || (pp->path[0] == '/')) {
268 266 if(vp->length >= MAXPATHLEN) {
269 267 errno = ENAMETOOLONG;
270 268 continue;
271 269 }
272 270 (void)strcpy(vroot_data.vroot_start= p, vp->path); p+= vp->length;
273 271 len += vp->length;
274 272 };
275 273 if (vroot_data.cpp_style_path) {
276 274 if (filename[0] != '/') {
277 275 if(1 + len + pp->length >= MAXPATHLEN) {
278 276 errno = ENAMETOOLONG;
279 277 continue;
280 278 }
281 279 (void)strcpy(vroot_data.path_start= p, pp->path); p+= pp->length;
282 280 *p++= '/';
283 281 len += 1 + pp->length;
284 282 };
285 283 } else {
286 284 if (strchr(filename, '/') == NULL) {
287 285 if (pp->length != 0) {
288 286 if(1 + len + pp->length >= MAXPATHLEN) {
289 287 errno = ENAMETOOLONG;
290 288 continue;
291 289 }
292 290 (void)strcpy(vroot_data.path_start= p,
293 291 pp->path);
294 292 p+= pp->length;
295 293 *p++= '/';
296 294 len += 1 + pp->length;
297 295 }
298 296 }
299 297 };
300 298 (void)strcpy(vroot_data.filename_start= p, filename);
301 299 if ((*thunk)(vroot_data.full_path)) return;};}
302 300 else { pathcellt *vp1= vp;
303 301 for (pp= pp1, path_len= 0; pp->path != NULL; pp++, path_len++)
304 302 for (vp= vp1; vp->path != NULL; vp++) {
305 303 int len = 0;
306 304 p= vroot_data.full_path;
307 305 if ((filename[0] == '/') || (pp->path[0] == '/')) {
308 306 if(vp->length >= MAXPATHLEN) {
309 307 errno = ENAMETOOLONG;
310 308 continue;
311 309 }
312 310 (void)strcpy(vroot_data.vroot_start= p, vp->path); p+= vp->length;
313 311 len += vp->length;
314 312 }
315 313 if (vroot_data.cpp_style_path) {
316 314 if (filename[0] != '/') {
317 315 if(1 + len + pp->length >= MAXPATHLEN) {
318 316 errno = ENAMETOOLONG;
319 317 continue;
320 318 }
321 319 (void)strcpy(vroot_data.path_start= p, pp->path); p+= pp->length;
322 320 *p++= '/';
323 321 len += 1 + pp->length;
324 322 }
325 323 } else {
326 324 if (strchr(filename, '/') == NULL) {
327 325 if(1 + len + pp->length >= MAXPATHLEN) {
328 326 errno = ENAMETOOLONG;
329 327 continue;
330 328 }
331 329 (void)strcpy(vroot_data.path_start= p, pp->path); p+= pp->length;
332 330 *p++= '/';
333 331 len += 1 + pp->length;
334 332 }
335 333 }
336 334 (void)strcpy(vroot_data.filename_start= p, filename);
337 335 if ((*thunk)(vroot_data.full_path)) return;};};
338 336 (void)strcpy(vroot_data.full_path, filename);
339 337 return;};};
340 338 }
↓ open down ↓ |
272 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX