4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
27 * University Copyright- Copyright (c) 1982, 1986, 1988
28 * The Regents of the University of California
31 * University Acknowledgment- Portions of this document are derived from
32 * software developed by the University of California, Berkeley, and its
36 #pragma ident "%Z%%M% %I% %E% SMI"
39 #define ungetchar(c) ungetc(c, stdin)
44 * mkstr - create a string error message file by massaging C source
46 * Modified March 1978 to hash old messages to be able to recompile
47 * without adding messages to the message file (usually)
49 * Program to create a string error message file
50 * from a group of C programs. Arguments are the name
51 * of the file where the strings are to be placed, the
52 * prefix of the new files where the processed source text
53 * is to be placed, and the files to be processed.
55 * The program looks for 'error("' in the source stream.
56 * Whenever it finds this, the following characters from the '"'
57 * to a '"' are replaced by 'seekpt' where seekpt is a
58 * pointer into the error message file.
59 * If the '(' is not immediately followed by a '"' no change occurs.
61 * The optional '-' causes strings to be added at the end of the
62 * existing error message file for recompilation of single routines.
66 FILE *mesgread
, *mesgwrite
;
68 char usagestr
[] = "usage: %s [ - ] mesgfile prefix file ...\n";
77 argc
--, progname
= *argv
++;
78 if (argc
> 1 && argv
[0][0] == '-')
79 addon
++, argc
--, argv
++;
81 fprintf(stderr
, usagestr
, progname
), exit(1);
82 mesgwrite
= fopen(argv
[0], addon
? "a" : "w");
83 if (mesgwrite
== NULL
)
84 perror(argv
[0]), exit(1);
85 mesgread
= fopen(argv
[0], "r");
87 perror(argv
[0]), exit(1);
90 strcpy(name
, argv
[0]);
91 np
= name
+ strlen(name
);
95 if (freopen(name
, "w", stdout
) == NULL
)
96 perror(name
), exit(1);
97 if (freopen(argv
[0], "r", stdin
) == NULL
)
98 perror(argv
[0]), exit(1);
117 if (match("error(")) {
134 for (cp
= ocp
+ 1; *cp
; cp
++) {
150 register char *cp
= buf
;
194 c
<<= 7, c
+= ch
- '0';
198 c
<<= 3, c
+= ch
- '0', ch
= -1;
206 printf("%d", hashit(buf
, 1, NULL
));
213 return (c
>= '0' && c
<= '7');
222 while (fgetNUL(buf
, sizeof buf
, mesgread
) != NULL
) {
223 hashit(buf
, 0, mesgpt
);
224 mesgpt
+= strlen(buf
) + 2;
236 hashit(str
, really
, fakept
)
242 register struct hash
*hp
;
250 hashval
= (hashval
<< 1) + *cp
++;
251 i
= hashval
% NBUCKETS
;
255 for (hp
= bucket
[i
]; hp
!= 0; hp
= hp
->hnext
)
256 if (hp
->hval
== hashval
) {
257 fseek(mesgread
, (long) hp
->hpt
, 0);
258 fgetNUL(buf
, sizeof buf
, mesgread
);
260 fprintf(stderr, "Got (from %d) %s\n", hp->hpt, buf);
262 if (strcmp(buf
, str
) == 0)
265 if (!really
|| hp
== 0) {
266 hp
= (struct hash
*) calloc(1, sizeof *hp
);
267 hp
->hnext
= bucket
[i
];
269 hp
->hpt
= really
? ftell(mesgwrite
) : fakept
;
271 fwrite(str
, sizeof (char), strlen(str
) + 1, mesgwrite
);
272 fwrite("\n", sizeof (char), 1, mesgwrite
);
277 fprintf(stderr, "%s hashed to %ld at %d\n", str, hp->hval, hp->hpt);
282 #include <sys/types.h>
283 #include <sys/stat.h>
285 fgetNUL(obuf
, rmdr
, file
)
291 register char *buf
= obuf
;
293 while (--rmdr
> 0 && (c
= getc(file
)) != 0 && c
!= EOF
)
297 return ((feof(file
) || ferror(file
)) ? NULL
: 1);