Print this page
make: translate using gettext, rather than the unmaintainable catgets
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/make/bin/state.cc
+++ new/usr/src/cmd/make/bin/state.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 /*
27 27 * state.c
28 28 *
29 29 * This file contains the routines that write the .make.state file
30 30 */
31 31
32 32 /*
33 33 * Included files
34 34 */
35 35 #include <mk/defs.h>
36 36 #include <mksh/misc.h> /* errmsg() */
37 37 #include <setjmp.h> /* setjmp() */
38 38 #include <unistd.h> /* getpid() */
39 39 #include <errno.h> /* errno */
40 40 #include <locale.h> /* MB_CUR_MAX */
41 41
42 42 /*
43 43 * Defined macros
44 44 */
45 45 #define LONGJUMP_VALUE 17
46 46 #define XFWRITE(string, length, fd) {if (fwrite(string, 1, length, fd) == 0) \
47 47 longjmp(long_jump, LONGJUMP_VALUE);}
48 48 #define XPUTC(ch, fd) { \
49 49 if (putc((int) ch, fd) == EOF) \
50 50 longjmp(long_jump, LONGJUMP_VALUE); \
51 51 }
52 52 #define XFPUTS(string, fd) fputs(string, fd)
53 53
54 54 /*
55 55 * typedefs & structs
56 56 */
57 57
58 58 /*
59 59 * Static variables
60 60 */
61 61
62 62 /*
63 63 * File table of contents
64 64 */
65 65 static char * escape_target_name(Name np)
66 66 {
67 67 if(np->dollar) {
68 68 int len = strlen(np->string_mb);
69 69 char * buff = (char*)malloc(2 * len);
70 70 int pos = 0;
71 71 wchar_t wc;
72 72 int pp = 0;
73 73 while(pos < len) {
74 74 int n = mbtowc(&wc, np->string_mb + pos, MB_CUR_MAX);
75 75 if(n < 0) { // error - this shouldn't happen
76 76 (void)free(buff);
77 77 return strdup(np->string_mb);
78 78 }
79 79 if(wc == dollar_char) {
80 80 buff[pp] = '\\'; pp++;
81 81 buff[pp] = '$'; pp++;
82 82 } else {
83 83 for(int j=0;j<n;j++) {
84 84 buff[pp] = np->string_mb[pos+j]; pp++;
85 85 }
86 86 }
87 87 pos += n;
88 88 }
89 89 buff[pp] = '\0';
90 90 return buff;
91 91 } else {
92 92 return strdup(np->string_mb);
93 93 }
94 94 }
95 95
96 96 static void print_auto_depes(register Dependency dependency, register FILE *fd, register Boolean built_this_run, register int *line_length, register char *target_name, jmp_buf long_jump);
97 97
98 98 /*
99 99 * write_state_file(report_recursive, exiting)
100 100 *
101 101 * Write a new version of .make.state
102 102 *
103 103 * Parameters:
104 104 * report_recursive Should only be done at end of run
105 105 * exiting true if called from the exit handler
106 106 *
107 107 * Global variables used:
108 108 * built_last_make_run The Name ".BUILT_LAST_MAKE_RUN", written
109 109 * command_changed If no command changed we do not need to write
110 110 * current_make_version The Name "<current version>", written
111 111 * do_not_exec_rule If -n is on we do not write statefile
112 112 * hashtab The hashtable that contains all names
113 113 * keep_state If .KEEP_STATE is no on we do not write file
114 114 * make_state The Name ".make.state", used for opening file
115 115 * make_version The Name ".MAKE_VERSION", written
116 116 * recursive_name The Name ".RECURSIVE", written
117 117 * rewrite_statefile Indicates that something changed
118 118 */
119 119
120 120 void
121 121 write_state_file(int, Boolean exiting)
122 122 {
123 123 register FILE *fd;
124 124 int lock_err;
125 125 char buffer[MAXPATHLEN];
126 126 char make_state_tempfile[MAXPATHLEN];
127 127 jmp_buf long_jump;
128 128 register int attempts = 0;
129 129 Name_set::iterator np, e;
130 130 register Property lines;
131 131 register int m;
132 132 Dependency dependency;
133 133 register Boolean name_printed;
134 134 Boolean built_this_run = false;
135 135 char *target_name;
136 136 int line_length;
137 137 register Cmd_line cp;
↓ open down ↓ |
137 lines elided |
↑ open up ↑ |
138 138
139 139
140 140 if (!rewrite_statefile ||
141 141 !command_changed ||
142 142 !keep_state ||
143 143 do_not_exec_rule ||
144 144 (report_dependencies_level > 0)) {
145 145 return;
146 146 }
147 147 /* Lock the file for writing. */
148 - make_state_lockfile = getmem(strlen(make_state->string_mb) + strlen(NOCATGETS(".lock")) + 1);
148 + make_state_lockfile = getmem(strlen(make_state->string_mb) + strlen(".lock") + 1);
149 149 (void) sprintf(make_state_lockfile,
150 - NOCATGETS("%s.lock"),
150 + "%s.lock",
151 151 make_state->string_mb);
152 152 if (lock_err = file_lock(make_state->string_mb,
153 153 make_state_lockfile,
154 154 (int *) &make_state_locked, 0)) {
155 155 retmem_mb(make_state_lockfile);
156 156 make_state_lockfile = NULL;
157 157
158 158 /*
159 159 * We need to make sure that we are not being
160 160 * called by the exit handler so we don't call
161 161 * it again.
162 162 */
163 163
164 164 if (exiting) {
165 - (void) sprintf(buffer, NOCATGETS("%s/.make.state.%d.XXXXXX"), tmpdir, getpid());
165 + (void) sprintf(buffer, "%s/.make.state.%d.XXXXXX", tmpdir, getpid());
166 166 report_pwd = true;
167 - warning(catgets(catd, 1, 60, "Writing to %s"), buffer);
167 + warning(gettext("Writing to %s"), buffer);
168 168 int fdes = mkstemp(buffer);
169 169 if ((fdes < 0) || (fd = fdopen(fdes, "w")) == NULL) {
170 170 fprintf(stderr,
171 - catgets(catd, 1, 61, "Could not open statefile `%s': %s"),
171 + gettext("Could not open statefile `%s': %s"),
172 172 buffer,
173 173 errmsg(errno));
174 174 return;
175 175 }
176 176 } else {
177 177 report_pwd = true;
178 - fatal(catgets(catd, 1, 62, "Can't lock .make.state"));
178 + fatal(gettext("Can't lock .make.state"));
179 179 }
180 180 }
181 181
182 182 (void) sprintf(make_state_tempfile,
183 - NOCATGETS("%s.tmp"),
183 + "%s.tmp",
184 184 make_state->string_mb);
185 185 /* Delete old temporary statefile (in case it exists) */
186 186 (void) unlink(make_state_tempfile);
187 187 if ((fd = fopen(make_state_tempfile, "w")) == NULL) {
188 188 lock_err = errno; /* Save it! unlink() can change errno */
189 189 (void) unlink(make_state_lockfile);
190 190 retmem_mb(make_state_lockfile);
191 191 make_state_lockfile = NULL;
192 192 make_state_locked = false;
193 - fatal(catgets(catd, 1, 59, "Could not open temporary statefile `%s': %s"),
193 + fatal(gettext("Could not open temporary statefile `%s': %s"),
194 194 make_state_tempfile,
195 195 errmsg(lock_err));
196 196 }
197 197 /*
198 198 * Set a trap for failed writes. If a write fails, the routine
199 199 * will try saving the .make.state file under another name in /tmp.
200 200 */
201 201 if (setjmp(long_jump)) {
202 202 (void) fclose(fd);
203 203 if (attempts++ > 5) {
204 204 if ((make_state_lockfile != NULL) &&
205 205 make_state_locked) {
206 206 (void) unlink(make_state_lockfile);
207 207 retmem_mb(make_state_lockfile);
208 208 make_state_lockfile = NULL;
209 209 make_state_locked = false;
210 210 }
211 - fatal(catgets(catd, 1, 63, "Giving up on writing statefile"));
211 + fatal(gettext("Giving up on writing statefile"));
212 212 }
213 213 sleep(10);
214 - (void) sprintf(buffer, NOCATGETS("%s/.make.state.%d.XXXXXX"), tmpdir, getpid());
214 + (void) sprintf(buffer, "%s/.make.state.%d.XXXXXX", tmpdir, getpid());
215 215 int fdes = mkstemp(buffer);
216 216 if ((fdes < 0) || (fd = fdopen(fdes, "w")) == NULL) {
217 - fatal(catgets(catd, 1, 64, "Could not open statefile `%s': %s"),
217 + fatal(gettext("Could not open statefile `%s': %s"),
218 218 buffer,
219 219 errmsg(errno));
220 220 }
221 - warning(catgets(catd, 1, 65, "Initial write of statefile failed. Trying again on %s"),
221 + warning(gettext("Initial write of statefile failed. Trying again on %s"),
222 222 buffer);
223 223 }
224 224
225 225 /* Write the version stamp. */
226 226 XFWRITE(make_version->string_mb,
227 227 strlen(make_version->string_mb),
228 228 fd);
229 229 XPUTC(colon_char, fd);
230 230 XPUTC(tab_char, fd);
231 231 XFWRITE(current_make_version->string_mb,
232 232 strlen(current_make_version->string_mb),
233 233 fd);
234 234 XPUTC(newline_char, fd);
235 235
236 236 /*
237 237 * Go through all the targets, dump their dependencies and
238 238 * command used.
239 239 */
240 240 for (np = hashtab.begin(), e = hashtab.end(); np != e; np++) {
241 241 /*
242 242 * If the target has no command used nor dependencies,
243 243 * we can go to the next one.
244 244 */
245 245 if ((lines = get_prop(np->prop, line_prop)) == NULL) {
246 246 continue;
247 247 }
248 248 /* If this target is a special target, don't print. */
249 249 if (np->special_reader != no_special) {
250 250 continue;
251 251 }
252 252 /*
253 253 * Find out if any of the targets dependencies should
254 254 * be written to .make.state.
255 255 */
256 256 for (m = 0, dependency = lines->body.line.dependencies;
257 257 dependency != NULL;
258 258 dependency = dependency->next) {
259 259 if (m = !dependency->stale
260 260 && (dependency->name != force)
261 261 #ifndef PRINT_EXPLICIT_DEPEN
262 262 && dependency->automatic
263 263 #endif
264 264 ) {
265 265 break;
266 266 }
267 267 }
268 268 /* Only print if dependencies listed. */
269 269 if (m || (lines->body.line.command_used != NULL)) {
270 270 name_printed = false;
271 271 /*
272 272 * If this target was built during this make run,
273 273 * we mark it.
274 274 */
275 275 built_this_run = false;
276 276 if (np->has_built) {
277 277 built_this_run = true;
278 278 XFWRITE(built_last_make_run->string_mb,
279 279 strlen(built_last_make_run->string_mb),
280 280 fd);
281 281 XPUTC(colon_char, fd);
282 282 XPUTC(newline_char, fd);
283 283 }
284 284 /* If the target has dependencies, we dump them. */
285 285 target_name = escape_target_name(np);
286 286 if (np->has_long_member_name) {
287 287 target_name =
288 288 get_prop(np->prop, long_member_name_prop)
289 289 ->body.long_member_name.member_name->
290 290 string_mb;
291 291 }
292 292 if (m) {
293 293 XFPUTS(target_name, fd);
294 294 XPUTC(colon_char, fd);
295 295 XFPUTS("\t", fd);
296 296 name_printed = true;
297 297 line_length = 0;
298 298 for (dependency =
299 299 lines->body.line.dependencies;
300 300 dependency != NULL;
301 301 dependency = dependency->next) {
302 302 print_auto_depes(dependency,
303 303 fd,
304 304 built_this_run,
305 305 &line_length,
306 306 target_name,
307 307 long_jump);
308 308 }
309 309 XFPUTS("\n", fd);
310 310 }
311 311 /* If there is a command used, we dump it. */
312 312 if (lines->body.line.command_used != NULL) {
313 313 /*
314 314 * Only write the target name if it
315 315 * wasn't done for the dependencies.
316 316 */
317 317 if (!name_printed) {
318 318 XFPUTS(target_name, fd);
319 319 XPUTC(colon_char, fd);
320 320 XPUTC(newline_char, fd);
321 321 }
322 322 /*
323 323 * Write the command lines.
324 324 * Prefix each textual line with a tab.
325 325 */
326 326 for (cp = lines->body.line.command_used;
327 327 cp != NULL;
328 328 cp = cp->next) {
329 329 char *csp;
330 330 int n;
331 331
332 332 XPUTC(tab_char, fd);
333 333 if (cp->command_line != NULL) {
334 334 for (csp = cp->
335 335 command_line->
336 336 string_mb,
337 337 n = strlen(cp->
338 338 command_line->
339 339 string_mb);
340 340 n > 0;
341 341 n--, csp++) {
342 342 XPUTC(*csp, fd);
343 343 if (*csp ==
344 344 (int) newline_char) {
345 345 XPUTC(tab_char,
346 346 fd);
347 347 }
348 348 }
349 349 }
350 350 XPUTC(newline_char, fd);
351 351 }
352 352 }
353 353 (void)free(target_name);
354 354 }
355 355 }
356 356 if (fclose(fd) == EOF) {
357 357 longjmp(long_jump, LONGJUMP_VALUE);
↓ open down ↓ |
126 lines elided |
↑ open up ↑ |
358 358 }
359 359 if (attempts == 0) {
360 360 if (unlink(make_state->string_mb) != 0 && errno != ENOENT) {
361 361 lock_err = errno; /* Save it! unlink() can change errno */
362 362 /* Delete temporary statefile */
363 363 (void) unlink(make_state_tempfile);
364 364 (void) unlink(make_state_lockfile);
365 365 retmem_mb(make_state_lockfile);
366 366 make_state_lockfile = NULL;
367 367 make_state_locked = false;
368 - fatal(catgets(catd, 1, 356, "Could not delete old statefile `%s': %s"),
368 + fatal(gettext("Could not delete old statefile `%s': %s"),
369 369 make_state->string_mb,
370 370 errmsg(lock_err));
371 371 }
372 372 if (rename(make_state_tempfile, make_state->string_mb) != 0) {
373 373 lock_err = errno; /* Save it! unlink() can change errno */
374 374 /* Delete temporary statefile */
375 375 (void) unlink(make_state_tempfile);
376 376 (void) unlink(make_state_lockfile);
377 377 retmem_mb(make_state_lockfile);
378 378 make_state_lockfile = NULL;
379 379 make_state_locked = false;
380 - fatal(catgets(catd, 1, 357, "Could not rename `%s' to `%s': %s"),
380 + fatal(gettext("Could not rename `%s' to `%s': %s"),
381 381 make_state_tempfile,
382 382 make_state->string_mb,
383 383 errmsg(lock_err));
384 384 }
385 385 }
386 386 if ((make_state_lockfile != NULL) && make_state_locked) {
387 387 (void) unlink(make_state_lockfile);
388 388 retmem_mb(make_state_lockfile);
389 389 make_state_lockfile = NULL;
390 390 make_state_locked = false;
391 391 }
392 392 }
393 393
394 394 /*
395 395 * print_auto_depes(dependency, fd, built_this_run,
396 396 * line_length, target_name, long_jump)
397 397 *
398 398 * Will print a dependency list for automatic entries.
399 399 *
400 400 * Parameters:
401 401 * dependency The dependency to print
402 402 * fd The file to print it to
403 403 * built_this_run If on we prefix each line with .BUILT_THIS...
404 404 * line_length Pointer to line length var that we update
405 405 * target_name We need this when we restart line
406 406 * long_jump setjmp/longjmp buffer used for IO error action
407 407 *
408 408 * Global variables used:
409 409 * built_last_make_run The Name ".BUILT_LAST_MAKE_RUN", written
410 410 * force The Name " FORCE", compared against
411 411 */
412 412 static void
413 413 print_auto_depes(register Dependency dependency, register FILE *fd, register Boolean built_this_run, register int *line_length, register char *target_name, jmp_buf long_jump)
414 414 {
415 415 if (!dependency->automatic ||
416 416 dependency->stale ||
417 417 (dependency->name == force)) {
418 418 return;
419 419 }
420 420 XFWRITE(dependency->name->string_mb,
421 421 strlen(dependency->name->string_mb),
422 422 fd);
423 423 /*
424 424 * Check if the dependency line is too long.
425 425 * If so, break it and start a new one.
426 426 */
427 427 if ((*line_length += (int) strlen(dependency->name->string_mb) + 1) > 450) {
428 428 *line_length = 0;
429 429 XPUTC(newline_char, fd);
430 430 if (built_this_run) {
431 431 XFPUTS(built_last_make_run->string_mb, fd);
432 432 XPUTC(colon_char, fd);
433 433 XPUTC(newline_char, fd);
434 434 }
435 435 XFPUTS(target_name, fd);
436 436 XPUTC(colon_char, fd);
437 437 XPUTC(tab_char, fd);
438 438 } else {
439 439 XFPUTS(" ", fd);
440 440 }
441 441 return;
442 442 }
443 443
444 444
↓ open down ↓ |
54 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX