Use err(3), add usage(), silent -Wall.
This commit is contained in:
parent
3974610c18
commit
2487a449d3
@ -38,7 +38,7 @@
|
|||||||
.Nm mkstr
|
.Nm mkstr
|
||||||
.Nd create an error message file by massaging C source
|
.Nd create an error message file by massaging C source
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm mkstr
|
.Nm
|
||||||
.Op Fl
|
.Op Fl
|
||||||
.Ar messagefile
|
.Ar messagefile
|
||||||
.Ar prefix file ...
|
.Ar prefix file ...
|
||||||
@ -48,7 +48,7 @@ creates files containing error messages extracted from C source,
|
|||||||
and restructures the same C source, to utilize the created error message
|
and restructures the same C source, to utilize the created error message
|
||||||
file.
|
file.
|
||||||
The intent of
|
The intent of
|
||||||
.Nm mkstr
|
.Nm
|
||||||
was to reduce the size of large programs and
|
was to reduce the size of large programs and
|
||||||
reduce swapping (see
|
reduce swapping (see
|
||||||
.Sx BUGS
|
.Sx BUGS
|
||||||
@ -62,7 +62,7 @@ consists of the specified
|
|||||||
.Ar prefix
|
.Ar prefix
|
||||||
and the original name.
|
and the original name.
|
||||||
A typical usage of
|
A typical usage of
|
||||||
.Nm mkstr
|
.Nm
|
||||||
is
|
is
|
||||||
.Bd -literal -offset indent
|
.Bd -literal -offset indent
|
||||||
mkstr pistrings xx *.c
|
mkstr pistrings xx *.c
|
||||||
@ -80,12 +80,12 @@ Options:
|
|||||||
.It Fl
|
.It Fl
|
||||||
Error messages are placed at the end of the specified
|
Error messages are placed at the end of the specified
|
||||||
message file for recompiling part of a large
|
message file for recompiling part of a large
|
||||||
.Nm mkstr
|
.Nm
|
||||||
ed
|
ed
|
||||||
program.
|
program.
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
.Nm mkstr
|
.Nm
|
||||||
finds error messages in the source by
|
finds error messages in the source by
|
||||||
searching for the string
|
searching for the string
|
||||||
.Li \&`error("'
|
.Li \&`error("'
|
||||||
@ -126,7 +126,7 @@ oops:
|
|||||||
appeared in
|
appeared in
|
||||||
.Bx 3.0 .
|
.Bx 3.0 .
|
||||||
.Sh BUGS
|
.Sh BUGS
|
||||||
.Nm mkstr
|
.Nm
|
||||||
was intended for the limited architecture of the PDP 11 family.
|
was intended for the limited architecture of the PDP 11 family.
|
||||||
Very few programs actually use it. The Pascal interpreter,
|
Very few programs actually use it. The Pascal interpreter,
|
||||||
.Xr \&pi 1
|
.Xr \&pi 1
|
||||||
|
@ -32,21 +32,25 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char copyright[] =
|
static const char copyright[] =
|
||||||
"@(#) Copyright (c) 1980, 1993\n\
|
"@(#) Copyright (c) 1980, 1993\n\
|
||||||
The Regents of the University of California. All rights reserved.\n";
|
The Regents of the University of California. All rights reserved.\n";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
|
#if 0
|
||||||
static char sccsid[] = "@(#)mkstr.c 8.1 (Berkeley) 6/6/93";
|
static char sccsid[] = "@(#)mkstr.c 8.1 (Berkeley) 6/6/93";
|
||||||
|
#endif
|
||||||
|
static const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
|
#include <err.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#define ungetchar(c) ungetc(c, stdin)
|
#define ungetchar(c) ungetc(c, stdin)
|
||||||
|
|
||||||
long ftell();
|
|
||||||
char *calloc();
|
|
||||||
/*
|
/*
|
||||||
* mkstr - create a string error message file by massaging C source
|
* mkstr - create a string error message file by massaging C source
|
||||||
*
|
*
|
||||||
@ -73,29 +77,36 @@ char *calloc();
|
|||||||
* existing error message file for recompilation of single routines.
|
* existing error message file for recompilation of single routines.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
FILE *mesgread, *mesgwrite;
|
FILE *mesgread, *mesgwrite;
|
||||||
char *progname;
|
|
||||||
char usagestr[] = "usage: %s [ - ] mesgfile prefix file ...\n";
|
|
||||||
char name[100], *np;
|
char name[100], *np;
|
||||||
|
|
||||||
|
void copystr __P((void));
|
||||||
|
int fgetNUL __P((char *, int, FILE *));
|
||||||
|
unsigned hashit __P((char *, char, unsigned));
|
||||||
|
void inithash __P((void));
|
||||||
|
int match __P((char *));
|
||||||
|
int octdigit __P((char));
|
||||||
|
void process __P((void));
|
||||||
|
static void usage __P((void));
|
||||||
|
|
||||||
|
int
|
||||||
main(argc, argv)
|
main(argc, argv)
|
||||||
int argc;
|
int argc;
|
||||||
char *argv[];
|
char *argv[];
|
||||||
{
|
{
|
||||||
char addon = 0;
|
char addon = 0;
|
||||||
|
|
||||||
argc--, progname = *argv++;
|
argc--, argv++;
|
||||||
if (argc > 1 && argv[0][0] == '-')
|
if (argc > 1 && argv[0][0] == '-')
|
||||||
addon++, argc--, argv++;
|
addon++, argc--, argv++;
|
||||||
if (argc < 3)
|
if (argc < 3)
|
||||||
fprintf(stderr, usagestr, progname), exit(1);
|
usage();
|
||||||
mesgwrite = fopen(argv[0], addon ? "a" : "w");
|
mesgwrite = fopen(argv[0], addon ? "a" : "w");
|
||||||
if (mesgwrite == NULL)
|
if (mesgwrite == NULL)
|
||||||
perror(argv[0]), exit(1);
|
err(1, "%s", argv[0]);
|
||||||
mesgread = fopen(argv[0], "r");
|
mesgread = fopen(argv[0], "r");
|
||||||
if (mesgread == NULL)
|
if (mesgread == NULL)
|
||||||
perror(argv[0]), exit(1);
|
err(1, "%s", argv[0]);
|
||||||
inithash();
|
inithash();
|
||||||
argc--, argv++;
|
argc--, argv++;
|
||||||
strcpy(name, argv[0]);
|
strcpy(name, argv[0]);
|
||||||
@ -104,18 +115,25 @@ main(argc, argv)
|
|||||||
do {
|
do {
|
||||||
strcpy(np, argv[0]);
|
strcpy(np, argv[0]);
|
||||||
if (freopen(name, "w", stdout) == NULL)
|
if (freopen(name, "w", stdout) == NULL)
|
||||||
perror(name), exit(1);
|
err(1, "%s", name);
|
||||||
if (freopen(argv[0], "r", stdin) == NULL)
|
if (freopen(argv[0], "r", stdin) == NULL)
|
||||||
perror(argv[0]), exit(1);
|
err(1, "%s", argv[0]);
|
||||||
process();
|
process();
|
||||||
argc--, argv++;
|
argc--, argv++;
|
||||||
} while (argc > 0);
|
} while (argc > 0);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
usage()
|
||||||
|
{
|
||||||
|
fprintf(stderr, "usage: mkstr [ - ] mesgfile prefix file ...\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
process()
|
process()
|
||||||
{
|
{
|
||||||
register char *cp;
|
|
||||||
register c;
|
register c;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -137,6 +155,7 @@ process()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
match(ocp)
|
match(ocp)
|
||||||
char *ocp;
|
char *ocp;
|
||||||
{
|
{
|
||||||
@ -155,6 +174,7 @@ match(ocp)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
copystr()
|
copystr()
|
||||||
{
|
{
|
||||||
register c, ch;
|
register c, ch;
|
||||||
@ -218,6 +238,7 @@ out:
|
|||||||
printf("%d", hashit(buf, 1, NULL));
|
printf("%d", hashit(buf, 1, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
octdigit(c)
|
octdigit(c)
|
||||||
char c;
|
char c;
|
||||||
{
|
{
|
||||||
@ -225,13 +246,14 @@ octdigit(c)
|
|||||||
return (c >= '0' && c <= '7');
|
return (c >= '0' && c <= '7');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
inithash()
|
inithash()
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
int mesgpt = 0;
|
int mesgpt = 0;
|
||||||
|
|
||||||
rewind(mesgread);
|
rewind(mesgread);
|
||||||
while (fgetNUL(buf, sizeof buf, mesgread) != NULL) {
|
while (fgetNUL(buf, sizeof buf, mesgread) != 0) {
|
||||||
hashit(buf, 0, mesgpt);
|
hashit(buf, 0, mesgpt);
|
||||||
mesgpt += strlen(buf) + 2;
|
mesgpt += strlen(buf) + 2;
|
||||||
}
|
}
|
||||||
@ -245,6 +267,7 @@ struct hash {
|
|||||||
struct hash *hnext;
|
struct hash *hnext;
|
||||||
} *bucket[NBUCKETS];
|
} *bucket[NBUCKETS];
|
||||||
|
|
||||||
|
unsigned
|
||||||
hashit(str, really, fakept)
|
hashit(str, really, fakept)
|
||||||
char *str;
|
char *str;
|
||||||
char really;
|
char really;
|
||||||
@ -294,6 +317,7 @@ hashit(str, really, fakept)
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
int
|
||||||
fgetNUL(obuf, rmdr, file)
|
fgetNUL(obuf, rmdr, file)
|
||||||
char *obuf;
|
char *obuf;
|
||||||
register int rmdr;
|
register int rmdr;
|
||||||
@ -306,5 +330,5 @@ fgetNUL(obuf, rmdr, file)
|
|||||||
*buf++ = c;
|
*buf++ = c;
|
||||||
*buf++ = 0;
|
*buf++ = 0;
|
||||||
getc(file);
|
getc(file);
|
||||||
return ((feof(file) || ferror(file)) ? NULL : 1);
|
return ((feof(file) || ferror(file)) ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user