summaryrefslogtreecommitdiffstats
path: root/usr.bin/mkstr
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-07-24 07:05:02 +0000
committercharnier <charnier@FreeBSD.org>1997-07-24 07:05:02 +0000
commit572da9743b5ea2de133fc8ab9add49dc68a59b1e (patch)
tree1ba9dc147ed28b400430f598e12bc7e87dc2e96a /usr.bin/mkstr
parent87d786e31432eab6391e66d291d03bf132d779ab (diff)
downloadFreeBSD-src-572da9743b5ea2de133fc8ab9add49dc68a59b1e.zip
FreeBSD-src-572da9743b5ea2de133fc8ab9add49dc68a59b1e.tar.gz
Use err(3), add usage(), silent -Wall.
Diffstat (limited to 'usr.bin/mkstr')
-rw-r--r--usr.bin/mkstr/mkstr.112
-rw-r--r--usr.bin/mkstr/mkstr.c54
2 files changed, 45 insertions, 21 deletions
diff --git a/usr.bin/mkstr/mkstr.1 b/usr.bin/mkstr/mkstr.1
index 7a53af9..69cfc6d 100644
--- a/usr.bin/mkstr/mkstr.1
+++ b/usr.bin/mkstr/mkstr.1
@@ -38,7 +38,7 @@
.Nm mkstr
.Nd create an error message file by massaging C source
.Sh SYNOPSIS
-.Nm mkstr
+.Nm
.Op Fl
.Ar messagefile
.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
file.
The intent of
-.Nm mkstr
+.Nm
was to reduce the size of large programs and
reduce swapping (see
.Sx BUGS
@@ -62,7 +62,7 @@ consists of the specified
.Ar prefix
and the original name.
A typical usage of
-.Nm mkstr
+.Nm
is
.Bd -literal -offset indent
mkstr pistrings xx *.c
@@ -80,12 +80,12 @@ Options:
.It Fl
Error messages are placed at the end of the specified
message file for recompiling part of a large
-.Nm mkstr
+.Nm
ed
program.
.El
.Pp
-.Nm mkstr
+.Nm
finds error messages in the source by
searching for the string
.Li \&`error("'
@@ -126,7 +126,7 @@ oops:
appeared in
.Bx 3.0 .
.Sh BUGS
-.Nm mkstr
+.Nm
was intended for the limited architecture of the PDP 11 family.
Very few programs actually use it. The Pascal interpreter,
.Xr \&pi 1
diff --git a/usr.bin/mkstr/mkstr.c b/usr.bin/mkstr/mkstr.c
index c08857a..7f2efe2 100644
--- a/usr.bin/mkstr/mkstr.c
+++ b/usr.bin/mkstr/mkstr.c
@@ -32,21 +32,25 @@
*/
#ifndef lint
-static char copyright[] =
+static const char copyright[] =
"@(#) Copyright (c) 1980, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
+#if 0
static char sccsid[] = "@(#)mkstr.c 8.1 (Berkeley) 6/6/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
+#include <err.h>
#include <stdio.h>
+#include <stdlib.h>
#define ungetchar(c) ungetc(c, stdin)
-long ftell();
-char *calloc();
/*
* 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.
*/
-
FILE *mesgread, *mesgwrite;
-char *progname;
-char usagestr[] = "usage: %s [ - ] mesgfile prefix file ...\n";
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)
int argc;
char *argv[];
{
char addon = 0;
- argc--, progname = *argv++;
+ argc--, argv++;
if (argc > 1 && argv[0][0] == '-')
addon++, argc--, argv++;
if (argc < 3)
- fprintf(stderr, usagestr, progname), exit(1);
+ usage();
mesgwrite = fopen(argv[0], addon ? "a" : "w");
if (mesgwrite == NULL)
- perror(argv[0]), exit(1);
+ err(1, "%s", argv[0]);
mesgread = fopen(argv[0], "r");
if (mesgread == NULL)
- perror(argv[0]), exit(1);
+ err(1, "%s", argv[0]);
inithash();
argc--, argv++;
strcpy(name, argv[0]);
@@ -104,18 +115,25 @@ main(argc, argv)
do {
strcpy(np, argv[0]);
if (freopen(name, "w", stdout) == NULL)
- perror(name), exit(1);
+ err(1, "%s", name);
if (freopen(argv[0], "r", stdin) == NULL)
- perror(argv[0]), exit(1);
+ err(1, "%s", argv[0]);
process();
argc--, argv++;
} while (argc > 0);
exit(0);
}
+static void
+usage()
+{
+ fprintf(stderr, "usage: mkstr [ - ] mesgfile prefix file ...\n");
+ exit(1);
+}
+
+void
process()
{
- register char *cp;
register c;
for (;;) {
@@ -137,6 +155,7 @@ process()
}
}
+int
match(ocp)
char *ocp;
{
@@ -155,6 +174,7 @@ match(ocp)
return (1);
}
+void
copystr()
{
register c, ch;
@@ -218,6 +238,7 @@ out:
printf("%d", hashit(buf, 1, NULL));
}
+int
octdigit(c)
char c;
{
@@ -225,13 +246,14 @@ octdigit(c)
return (c >= '0' && c <= '7');
}
+void
inithash()
{
char buf[512];
int mesgpt = 0;
rewind(mesgread);
- while (fgetNUL(buf, sizeof buf, mesgread) != NULL) {
+ while (fgetNUL(buf, sizeof buf, mesgread) != 0) {
hashit(buf, 0, mesgpt);
mesgpt += strlen(buf) + 2;
}
@@ -245,6 +267,7 @@ struct hash {
struct hash *hnext;
} *bucket[NBUCKETS];
+unsigned
hashit(str, really, fakept)
char *str;
char really;
@@ -294,6 +317,7 @@ hashit(str, really, fakept)
#include <sys/types.h>
#include <sys/stat.h>
+int
fgetNUL(obuf, rmdr, file)
char *obuf;
register int rmdr;
@@ -306,5 +330,5 @@ fgetNUL(obuf, rmdr, file)
*buf++ = c;
*buf++ = 0;
getc(file);
- return ((feof(file) || ferror(file)) ? NULL : 1);
+ return ((feof(file) || ferror(file)) ? 0 : 1);
}
OpenPOWER on IntegriCloud