static char *sccsid
= "@(#)mkstr.c 4.1 (Berkeley) %G%";
#define ungetchar(c) ungetc(c, stdin)
* mkstr - create a string error message file by massaging C source
* Bill Joy UCB August 1977
* Modified March 1978 to hash old messages to be able to recompile
* without addding messages to the message file (usually)
* Based on an earlier program conceived by Bill Joy and Chuck Haley
* Program to create a string error message file
* from a group of C programs. Arguments are the name
* of the file where the strings are to be placed, the
* prefix of the new files where the processed source text
* is to be placed, and the files to be processed.
* The program looks for 'error("' in the source stream.
* Whenever it finds this, the following characters from the '"'
* to a '"' are replaced by 'seekpt' where seekpt is a
* pointer into the error message file.
* If the '(' is not immediately followed by a '"' no change occurs.
* The optional '-' causes strings to be added at the end of the
* existing error message file for recompilation of single routines.
FILE *mesgread
, *mesgwrite
;
char usagestr
[] = "usage: %s [ - ] mesgfile prefix file ...\n";
argc
--, progname
= *argv
++;
if (argc
> 1 && argv
[0][0] == '-')
fprintf(stderr
, usagestr
, progname
), exit(1);
mesgwrite
= fopen(argv
[0], addon
? "a" : "w");
perror(argv
[0]), exit(1);
mesgread
= fopen(argv
[0], "r");
perror(argv
[0]), exit(1);
np
= name
+ strlen(name
);
if (freopen(name
, "w", stdout
) == NULL
)
if (freopen(argv
[0], "r", stdin
) == NULL
)
perror(argv
[0]), exit(1);
for (cp
= ocp
+ 1; *cp
; cp
++) {
c
<<= 3, c
+= ch
- '0', ch
= -1;
printf("%d", hashit(buf
, 1, NULL
));
return (c
>= '0' && c
<= '7');
while (fgetNUL(buf
, sizeof buf
, mesgread
) != NULL
) {
mesgpt
+= strlen(buf
) + 2;
hashit(str
, really
, fakept
)
register struct hash
*hp
;
hashval
= (hashval
<< 1) + *cp
++;
for (hp
= bucket
[i
]; hp
!= 0; hp
= hp
->hnext
)
if (hp
->hval
== hashval
) {
fseek(mesgread
, (long) hp
->hpt
, 0);
fgetNUL(buf
, sizeof buf
, mesgread
);
fprintf(stderr, "Got (from %d) %s\n", hp->hpt, buf);
if (strcmp(buf
, str
) == 0)
if (!really
|| hp
== 0) {
hp
= (struct hash
*) calloc(1, sizeof *hp
);
hp
->hpt
= really
? ftell(mesgwrite
) : fakept
;
fwrite(str
, sizeof (char), strlen(str
) + 1, mesgwrite
);
fwrite("\n", sizeof (char), 1, mesgwrite
);
fprintf(stderr, "%s hashed to %ld at %d\n", str, hp->hval, hp->hpt);
fgetNUL(obuf
, rmdr
, file
)
register char *buf
= obuf
;
while (--rmdr
> 0 && (c
= getc(file
)) != 0 && c
!= EOF
)
return ((feof(file
) || ferror(file
)) ? NULL
: 1);