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/report.cc
+++ new/usr/src/cmd/make/lib/vroot/report.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 /*
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
22 22 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #include <stdio.h>
27 27 #include <stdlib.h>
28 28 #include <string.h>
29 29 #include <sys/param.h>
30 30 #include <sys/wait.h>
31 31 #include <unistd.h>
32 +#include <libintl.h>
32 33
33 34 #include <vroot/report.h>
34 35 #include <vroot/vroot.h>
35 -#include <mksdmsi18n/mksdmsi18n.h>
36 -#include <avo/intl.h> /* for NOCATGETS */
37 36 #include <mk/defs.h> /* for tmpdir */
38 37
39 38 static FILE *report_file;
40 39 static FILE *command_output_fp;
41 40 static char *target_being_reported_for;
42 41 static char *search_dir;
43 42 static char command_output_tmpfile[30];
44 43 static int is_path = 0;
45 44 static char sfile[MAXPATHLEN];
46 45 extern "C" {
47 46 static void (*warning_ptr) (char *, ...) = (void (*) (char *, ...)) NULL;
48 47 }
49 48
50 49 FILE *
51 50 get_report_file(void)
52 51 {
53 52 return(report_file);
54 53 }
55 54
56 55 char *
57 56 get_target_being_reported_for(void)
58 57 {
59 58 return(target_being_reported_for);
60 59 }
61 60
62 61 extern "C" {
63 62 static void
64 63 close_report_file(void)
65 64 {
66 65 (void)fputs("\n", report_file);
67 66 (void)fclose(report_file);
68 67 }
69 68 } // extern "C"
70 69
71 70 static void
72 71 clean_up(FILE *nse_depinfo_fp, FILE *merge_fp, char *nse_depinfo_file, char *merge_file, int unlinkf)
73 72 {
74 73 fclose(nse_depinfo_fp);
75 74 fclose(merge_fp);
76 75 fclose(command_output_fp);
77 76 unlink(command_output_tmpfile);
78 77 if (unlinkf)
79 78 unlink(merge_file);
80 79 else
81 80 rename(merge_file, nse_depinfo_file);
82 81 }
83 82
84 83
85 84 /*
86 85 * Update the file, if necessary. We don't want to rewrite
87 86 * the file if we don't have to because we don't want the time of the file
88 87 * to change in that case.
89 88 */
90 89
91 90 extern "C" {
92 91 static void
93 92 close_file(void)
94 93 {
95 94 char line[MAXPATHLEN+2];
96 95 char buf[MAXPATHLEN+2];
97 96 FILE *nse_depinfo_fp;
98 97 FILE *merge_fp;
99 98 char nse_depinfo_file[MAXPATHLEN];
100 99 char merge_file[MAXPATHLEN];
101 100 char lock_file[MAXPATHLEN];
102 101 int err;
↓ open down ↓ |
56 lines elided |
↑ open up ↑ |
103 102 int len;
104 103 int changed = 0;
105 104 int file_locked;
106 105
107 106 fprintf(command_output_fp, "\n");
108 107 fclose(command_output_fp);
109 108 if ((command_output_fp = fopen(command_output_tmpfile, "r")) == NULL) {
110 109 return;
111 110 }
112 111 sprintf(nse_depinfo_file, "%s/%s", search_dir, NSE_DEPINFO);
113 - sprintf(merge_file, NOCATGETS("%s/.tmp%s.%d"), search_dir, NSE_DEPINFO, getpid());
112 + sprintf(merge_file, "%s/.tmp%s.%d", search_dir, NSE_DEPINFO, getpid());
114 113 sprintf(lock_file, "%s/%s", search_dir, NSE_DEPINFO_LOCK);
115 114 err = file_lock(nse_depinfo_file, lock_file, &file_locked, 0);
116 115 if (err) {
117 116 if (warning_ptr != (void (*) (char *, ...)) NULL) {
118 - (*warning_ptr)(catgets(libmksdmsi18n_catd, 1, 147, "Couldn't write to %s"), nse_depinfo_file);
117 + (*warning_ptr)(gettext("Couldn't write to %s"), nse_depinfo_file);
119 118 }
120 119 unlink(command_output_tmpfile);
121 120 return;
122 121 }
123 122 /* If .nse_depinfo file doesn't exist */
124 123 if ((nse_depinfo_fp = fopen(nse_depinfo_file, "r+")) == NULL) {
125 124 if (is_path) {
126 125 if ((nse_depinfo_fp =
127 126 fopen(nse_depinfo_file, "w")) == NULL) {
128 - fprintf(stderr, catgets(libmksdmsi18n_catd, 1, 148, "Cannot open `%s' for writing\n"),
127 + fprintf(stderr, gettext("Cannot open `%s' for writing\n"),
129 128 nse_depinfo_file);
130 129 unlink(command_output_tmpfile);
131 130
132 131 unlink(lock_file);
133 132 return;
134 133 }
135 134 while (fgets(line, MAXPATHLEN+2, command_output_fp)
136 135 != NULL) {
137 136 fprintf(nse_depinfo_fp, "%s", line);
138 137 }
139 138 fclose(command_output_fp);
140 139 }
141 140 fclose(nse_depinfo_fp);
142 141 if (file_locked) {
143 142 unlink(lock_file);
144 143 }
145 144 unlink(command_output_tmpfile);
146 145 return;
147 146 }
148 147 if ((merge_fp = fopen(merge_file, "w")) == NULL) {
149 - fprintf(stderr, catgets(libmksdmsi18n_catd, 1, 149, "Cannot open %s for writing\n"), merge_file);
148 + fprintf(stderr, gettext("Cannot open %s for writing\n"), merge_file);
150 149 if (file_locked) {
151 150 unlink(lock_file);
152 151 }
153 152 unlink(command_output_tmpfile);
154 153 return;
155 154 }
156 155 len = strlen(sfile);
157 156 while (fgets(line, MAXPATHLEN+2, nse_depinfo_fp) != NULL) {
158 157 if (strncmp(line, sfile, len) == 0 && line[len] == ':') {
159 158 while (fgets(buf, MAXPATHLEN+2, command_output_fp)
160 159 != NULL) {
161 160 if (is_path) {
162 161 fprintf(merge_fp, "%s", buf);
163 162 if (strcmp(line, buf)) {
164 163 /* changed */
165 164 changed = 1;
166 165 }
167 166 }
168 167 if (buf[strlen(buf)-1] == '\n') {
169 168 break;
170 169 }
171 170 }
172 171 if (changed || !is_path) {
173 172 while (fgets(line, MAXPATHLEN, nse_depinfo_fp)
174 173 != NULL) {
175 174 fputs(line, merge_fp);
176 175 }
177 176 clean_up(nse_depinfo_fp, merge_fp,
178 177 nse_depinfo_file, merge_file, 0);
179 178 } else {
180 179 clean_up(nse_depinfo_fp, merge_fp,
181 180 nse_depinfo_file, merge_file, 1);
182 181 }
183 182 if (file_locked) {
184 183 unlink(lock_file);
185 184 }
186 185 unlink(command_output_tmpfile);
187 186 return;
188 187 } /* entry found */
189 188 fputs(line, merge_fp);
190 189 }
191 190 /* Entry never found. Add it if there is a search path */
192 191 if (is_path) {
193 192 while (fgets(line, MAXPATHLEN+2, command_output_fp) != NULL) {
194 193 fprintf(nse_depinfo_fp, "%s", line);
195 194 }
196 195 }
197 196 clean_up(nse_depinfo_fp, merge_fp, nse_depinfo_file, merge_file, 1);
198 197 if (file_locked) {
199 198 unlink(lock_file);
200 199 }
↓ open down ↓ |
41 lines elided |
↑ open up ↑ |
201 200 }
202 201
203 202 } // extern "C"
204 203
205 204 static void
206 205 report_dep(char *iflag, char *filename)
207 206 {
208 207
209 208 if (command_output_fp == NULL) {
210 209 sprintf(command_output_tmpfile,
211 - NOCATGETS("%s/%s.%d.XXXXXX"), tmpdir, NSE_DEPINFO, getpid());
210 + "%s/%s.%d.XXXXXX", tmpdir, NSE_DEPINFO, getpid());
212 211 int fd = mkstemp(command_output_tmpfile);
213 212 if ((fd < 0) || (command_output_fp = fdopen(fd, "w")) == NULL) {
214 213 return;
215 214 }
216 - if ((search_dir = getenv(NOCATGETS("NSE_DEP"))) == NULL) {
215 + if ((search_dir = getenv("NSE_DEP")) == NULL) {
217 216 return;
218 217 }
219 218 atexit(close_file);
220 219 strcpy(sfile, filename);
221 220 if (iflag == NULL || *iflag == '\0') {
222 221 return;
223 222 }
224 223 fprintf(command_output_fp, "%s:", sfile);
225 224 }
226 225 fprintf(command_output_fp, " ");
227 226 fprintf(command_output_fp, iflag);
228 227 if (iflag != NULL) {
229 228 is_path = 1;
230 229 }
231 230 }
232 231
233 232 void
234 233 report_libdep(char *lib, char *flag)
235 234 {
236 235 char *ptr;
237 236 char filename[MAXPATHLEN];
238 237 char *p;
239 238
240 239 if ((p= getenv(SUNPRO_DEPENDENCIES)) == NULL) {
241 240 return;
242 241 }
243 242 ptr = strchr(p, ' ');
244 243 if(ptr) {
245 244 sprintf(filename, "%s-%s", ptr+1, flag);
246 245 is_path = 1;
247 246 report_dep(lib, filename);
248 247 }
249 248 }
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
250 249
251 250 void
252 251 report_search_path(char *iflag)
253 252 {
254 253 char curdir[MAXPATHLEN];
255 254 char *sdir;
256 255 char *newiflag;
257 256 char filename[MAXPATHLEN];
258 257 char *p, *ptr;
259 258
260 - if ((sdir = getenv(NOCATGETS("NSE_DEP"))) == NULL) {
259 + if ((sdir = getenv("NSE_DEP")) == NULL) {
261 260 return;
262 261 }
263 262 if ((p= getenv(SUNPRO_DEPENDENCIES)) == NULL) {
264 263 return;
265 264 }
266 265 ptr = strchr(p, ' ');
267 266 if( ! ptr ) {
268 267 return;
269 268 }
270 - sprintf(filename, NOCATGETS("%s-CPP"), ptr+1);
269 + sprintf(filename, "%s-CPP", ptr+1);
271 270 getcwd(curdir, sizeof(curdir));
272 271 if (strcmp(curdir, sdir) != 0 && strlen(iflag) > 2 &&
273 272 iflag[2] != '/') {
274 273 /* Makefile must have had an "cd xx; cc ..." */
275 274 /* Modify the -I path to be relative to the cd */
276 275 newiflag = (char *)malloc(strlen(iflag) + strlen(curdir) + 2);
277 276 sprintf(newiflag, "-%c%s/%s", iflag[1], curdir, &iflag[2]);
278 277 report_dep(newiflag, filename);
279 278 } else {
280 279 report_dep(iflag, filename);
281 280 }
282 281 }
283 282
284 283 void
285 284 report_dependency(const char *name)
286 285 {
287 286 register char *filename;
288 287 char buffer[MAXPATHLEN+1];
289 288 register char *p;
290 289 register char *p2;
291 290 char nse_depinfo_file[MAXPATHLEN];
292 291
293 292 if (report_file == NULL) {
294 293 if ((filename= getenv(SUNPRO_DEPENDENCIES)) == NULL) {
295 294 report_file = (FILE *)-1;
296 295 return;
297 296 }
298 297 if (strlen(filename) == 0) {
299 298 report_file = (FILE *)-1;
300 299 return;
301 300 }
302 301 (void)strcpy(buffer, name);
303 302 name = buffer;
304 303 p = strchr(filename, ' ');
305 304 if(p) {
306 305 *p= 0;
307 306 } else {
308 307 report_file = (FILE *)-1;
309 308 return;
310 309 }
311 310 if ((report_file= fopen(filename, "a")) == NULL) {
312 311 if ((report_file= fopen(filename, "w")) == NULL) {
313 312 report_file= (FILE *)-1;
314 313 return;
315 314 }
316 315 }
317 316 atexit(close_report_file);
318 317 if ((p2= strchr(p+1, ' ')) != NULL)
319 318 *p2= 0;
320 319 target_being_reported_for= (char *)malloc((unsigned)(strlen(p+1)+1));
321 320 (void)strcpy(target_being_reported_for, p+1);
322 321 (void)fputs(p+1, report_file);
323 322 (void)fputs(":", report_file);
324 323 *p= ' ';
325 324 if (p2 != NULL)
326 325 *p2= ' ';
327 326 }
328 327 if (report_file == (FILE *)-1)
329 328 return;
330 329 (void)fputs(name, report_file);
331 330 (void)fputs(" ", report_file);
332 331 }
333 332
334 333
↓ open down ↓ |
54 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX