2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static char copyright[] =
36 "@(#) Copyright (c) 1980, 1993\n\
37 The Regents of the University of California. All rights reserved.\n";
41 static char sccsid[] = "@(#)mkstr.c 8.1 (Berkeley) 6/6/93";
46 #define ungetchar(c) ungetc(c, stdin)
51 * mkstr - create a string error message file by massaging C source
53 * Bill Joy UCB August 1977
55 * Modified March 1978 to hash old messages to be able to recompile
56 * without addding messages to the message file (usually)
58 * Based on an earlier program conceived by Bill Joy and Chuck Haley
60 * Program to create a string error message file
61 * from a group of C programs. Arguments are the name
62 * of the file where the strings are to be placed, the
63 * prefix of the new files where the processed source text
64 * is to be placed, and the files to be processed.
66 * The program looks for 'error("' in the source stream.
67 * Whenever it finds this, the following characters from the '"'
68 * to a '"' are replaced by 'seekpt' where seekpt is a
69 * pointer into the error message file.
70 * If the '(' is not immediately followed by a '"' no change occurs.
72 * The optional '-' causes strings to be added at the end of the
73 * existing error message file for recompilation of single routines.
77 FILE *mesgread, *mesgwrite;
79 char usagestr[] = "usage: %s [ - ] mesgfile prefix file ...\n";
88 argc--, progname = *argv++;
89 if (argc > 1 && argv[0][0] == '-')
90 addon++, argc--, argv++;
92 fprintf(stderr, usagestr, progname), exit(1);
93 mesgwrite = fopen(argv[0], addon ? "a" : "w");
94 if (mesgwrite == NULL)
95 perror(argv[0]), exit(1);
96 mesgread = fopen(argv[0], "r");
98 perror(argv[0]), exit(1);
101 strcpy(name, argv[0]);
102 np = name + strlen(name);
106 if (freopen(name, "w", stdout) == NULL)
107 perror(name), exit(1);
108 if (freopen(argv[0], "r", stdin) == NULL)
109 perror(argv[0]), exit(1);
129 if (match("error(")) {
146 for (cp = ocp + 1; *cp; cp++) {
162 register char *cp = buf;
206 c <<= 7, c += ch - '0';
210 c <<= 3, c+= ch - '0', ch = -1;
218 printf("%d", hashit(buf, 1, NULL));
225 return (c >= '0' && c <= '7');
234 while (fgetNUL(buf, sizeof buf, mesgread) != NULL) {
235 hashit(buf, 0, mesgpt);
236 mesgpt += strlen(buf) + 2;
248 hashit(str, really, fakept)
254 register struct hash *hp;
262 hashval = (hashval << 1) + *cp++;
263 i = hashval % NBUCKETS;
267 for (hp = bucket[i]; hp != 0; hp = hp->hnext)
268 if (hp->hval == hashval) {
269 fseek(mesgread, (long) hp->hpt, 0);
270 fgetNUL(buf, sizeof buf, mesgread);
272 fprintf(stderr, "Got (from %d) %s\n", hp->hpt, buf);
274 if (strcmp(buf, str) == 0)
277 if (!really || hp == 0) {
278 hp = (struct hash *) calloc(1, sizeof *hp);
279 hp->hnext = bucket[i];
281 hp->hpt = really ? ftell(mesgwrite) : fakept;
283 fwrite(str, sizeof (char), strlen(str) + 1, mesgwrite);
284 fwrite("\n", sizeof (char), 1, mesgwrite);
289 fprintf(stderr, "%s hashed to %ld at %d\n", str, hp->hval, hp->hpt);
294 #include <sys/types.h>
295 #include <sys/stat.h>
297 fgetNUL(obuf, rmdr, file)
303 register char *buf = obuf;
305 while (--rmdr > 0 && (c = getc(file)) != 0 && c != EOF)
309 return ((feof(file) || ferror(file)) ? NULL : 1);