summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-07-08 11:05:59 +0000
committercharnier <charnier@FreeBSD.org>1997-07-08 11:05:59 +0000
commita905367e5903383d1a99e8d3d16f065600dc9208 (patch)
tree8c58e75367492e46659eb096db1fbcb264ecf248 /usr.bin
parent0b74b1044e108ab2d7b26b257d5ae8bea1acad6e (diff)
downloadFreeBSD-src-a905367e5903383d1a99e8d3d16f065600dc9208.zip
FreeBSD-src-a905367e5903383d1a99e8d3d16f065600dc9208.tar.gz
Use err(3), remove unused variables.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/gencat/gencat.c95
-rw-r--r--usr.bin/gencat/genlib.c13
2 files changed, 40 insertions, 68 deletions
diff --git a/usr.bin/gencat/gencat.c b/usr.bin/gencat/gencat.c
index 37c7990..8085642 100644
--- a/usr.bin/gencat/gencat.c
+++ b/usr.bin/gencat/gencat.c
@@ -40,6 +40,7 @@ up-to-date. Many thanks.
08/13/90 1 schulert move from ua to omu
*/
+#include <err.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
@@ -76,9 +77,12 @@ static void writeIfChanged P_((char *fname, int lang, int orConsts));
#undef P_
-void usage() {
- fprintf(stderr, "Use: gencat [-new] [-or] [-lang C|C++|ANSIC]\n");
- fprintf(stderr, " catfile msgfile [-h <header-file>]...\n");
+static void
+usage()
+{
+ fprintf(stderr, "usage: gencat [-new] [-or] [-lang C|C++|ANSIC]\n");
+ fprintf(stderr, " catfile msgfile [-h <header-file>]...\n");
+ exit(1);
}
void main(
@@ -91,7 +95,6 @@ char *argv[];
#endif
{
int ofd, ifd, i;
- FILE *fptr;
char *catfile = NULL;
char *input = NULL;
int lang = MCLangC;
@@ -106,55 +109,41 @@ char *argv[];
else if (strcmp(argv[i], "C++") == 0) lang = MCLangCPlusPlus;
else if (strcmp(argv[i], "ANSIC") == 0) lang = MCLangANSIC;
else {
- fprintf(stderr, "gencat: Unrecognized language: %s\n", argv[i]);
- exit(1);
+ errx(1, "unrecognized language: %s", argv[i]);
}
} else if (strcmp(argv[i], "-h") == 0) {
- if (!input) {
- fprintf(stderr, "gencat: Can't write to a header before reading something.\n");
- exit(1);
- }
+ if (!input)
+ errx(1, "can't write to a header before reading something");
++i;
writeIfChanged(argv[i], lang, orConsts);
} else if (strcmp(argv[i], "-new") == 0) {
- if (catfile) {
- fprintf(stderr, "gencat: You must specify -new before the catalog file name\n");
- exit(1);
- }
+ if (catfile)
+ errx(1, "you must specify -new before the catalog file name");
new = True;
} else if (strcmp(argv[i], "-or") == 0) {
orConsts = ~orConsts;
} else {
usage();
- exit(1);
}
} else {
if (!catfile) {
catfile = argv[i];
if (new) {
- if ((ofd = open(catfile, O_WRONLY|O_TRUNC|O_CREAT, 0666)) < 0) {
- fprintf(stderr, "gencat: Unable to create a new %s.\n", catfile);
- exit(1);
- }
+ if ((ofd = open(catfile, O_WRONLY|O_TRUNC|O_CREAT, 0666)) < 0)
+ errx(1, "unable to create a new %s", catfile);
} else if ((ofd = open(catfile, O_RDONLY)) < 0) {
- if ((ofd = open(catfile, O_WRONLY|O_CREAT, 0666)) < 0) {
- fprintf(stderr, "gencat: Unable to create %s.\n", catfile);
- exit(1);
- }
+ if ((ofd = open(catfile, O_WRONLY|O_CREAT, 0666)) < 0)
+ errx(1, "unable to create %s", catfile);
} else {
MCReadCat(ofd);
close(ofd);
- if ((ofd = open(catfile, O_WRONLY|O_TRUNC)) < 0) {
- fprintf(stderr, "gencat: Unable to truncate %s.\n", catfile);
- exit(1);
- }
+ if ((ofd = open(catfile, O_WRONLY|O_TRUNC)) < 0)
+ errx(1, "unable to truncate %s", catfile);
}
} else {
input = argv[i];
- if ((ifd = open(input, O_RDONLY)) < 0) {
- fprintf(stderr, "gencat: Unable to read %s\n", input);
- exit(1);
- }
+ if ((ifd = open(input, O_RDONLY)) < 0)
+ errx(1, "unable to read %s", input);
MCParse(ifd);
close(ifd);
}
@@ -165,7 +154,6 @@ char *argv[];
exit(0);
} else {
usage();
- exit(1);
}
}
@@ -183,15 +171,13 @@ int orConsts;
char buf[BUFSIZ], tbuf[BUFSIZ], *cptr, *tptr;
int fd, tfd;
int diff = False;
- int c, len, tlen;
+ int len, tlen;
struct stat sbuf;
/* If it doesn't exist, just create it */
if (stat(fname, &sbuf)) {
- if ((fd = open(fname, O_WRONLY|O_CREAT, 0666)) < 0) {
- fprintf(stderr, "gencat: Unable to create header file %s.\n", fname);
- exit(1);
- }
+ if ((fd = open(fname, O_WRONLY|O_CREAT, 0666)) < 0)
+ errx(1, "unable to create header file %s", fname);
MCWriteConst(fd, lang, orConsts);
close(fd);
return;
@@ -199,26 +185,20 @@ int orConsts;
/* If it does exist, create a temp file for now */
sprintf(tmpname, "/tmp/gencat.%d", (int) getpid());
- if ((tfd = open(tmpname, O_RDWR|O_CREAT, 0666)) < 0) {
- fprintf(stderr, "gencat: Unable to open temporary file: %s\n", tmpname);
- exit(1);
- }
+ if ((tfd = open(tmpname, O_RDWR|O_CREAT, 0666)) < 0)
+ errx(1, "unable to open temporary file: %s", tmpname);
unlink(tmpname);
/* Write to the temp file and rewind */
MCWriteConst(tfd, lang, orConsts);
/* Open the real header file */
- if ((fd = open(fname, O_RDONLY)) < 0) {
- fprintf(stderr, "gencat: Unable to read header file: %s\n", fname);
- exit(1);
- }
+ if ((fd = open(fname, O_RDONLY)) < 0)
+ errx(1, "unable to read header file: %s", fname);
/* Backup to the start of the temp file */
- if (lseek(tfd, 0L, L_SET) < 0) {
- fprintf(stderr, "gencat: Unable to seek in tempfile: %s\n", tmpname);
- exit(1);
- }
+ if (lseek(tfd, 0L, L_SET) < 0)
+ errx(1, "unable to seek in tempfile: %s", tmpname);
/* Now compare them */
while ((tlen = read(tfd, tbuf, BUFSIZ)) > 0) {
@@ -235,19 +215,14 @@ int orConsts;
}
done:
if (diff) {
- if (lseek(tfd, 0L, L_SET) < 0) {
- fprintf(stderr, "gencat: Unable to seek in tempfile: %s\n", tmpname);
- exit(1);
- }
+ if (lseek(tfd, 0L, L_SET) < 0)
+ errx(1, "unable to seek in tempfile: %s", tmpname);
close(fd);
- if ((fd = open(fname, O_WRONLY|O_TRUNC)) < 0) {
- fprintf(stderr, "gencat: Unable to truncate header file: %s\n", fname);
- exit(1);
- }
+ if ((fd = open(fname, O_WRONLY|O_TRUNC)) < 0)
+ errx(1, "unable to truncate header file: %s", fname);
while ((len = read(tfd, buf, BUFSIZ)) > 0) {
- if (write(fd, buf, len) != len) {
- fprintf(stderr, "gencat: Error writing to header file: %s\n", fname);
- }
+ if (write(fd, buf, len) != len)
+ warnx("error writing to header file: %s", fname);
}
}
close(fd);
diff --git a/usr.bin/gencat/genlib.c b/usr.bin/gencat/genlib.c
index 3b42987..b1179af 100644
--- a/usr.bin/gencat/genlib.c
+++ b/usr.bin/gencat/genlib.c
@@ -63,6 +63,7 @@ int length;
#endif
#include <sys/file.h>
#include <ctype.h>
+#include <err.h>
#include "msgcat.h"
#include "gencat.h"
@@ -73,8 +74,7 @@ static void warning(cptr, msg)
char *cptr;
char *msg;
{
- fprintf(stderr, "gencat: %s on line %d\n", msg, lineno);
- fprintf(stderr, "%s\n", curline);
+ warnx("%s on line %d\n%s", msg, lineno, curline);
if (cptr) {
char *tptr;
for (tptr = curline; tptr < cptr; ++tptr) putc(' ', stderr);
@@ -100,7 +100,7 @@ static void nomem() {
static char *getline(fd)
int fd;
{
- static long len = 0, curlen = BUFSIZ;
+ static long curlen = BUFSIZ;
static char buf[BUFSIZ], *bptr = buf, *bend = buf;
char *cptr, *cend;
long buflen;
@@ -342,7 +342,6 @@ int fd;
int setid, msgid = 0;
char hconst[MAXTOKEN+1];
char quote = 0;
- int i;
if (!cat) {
cat = (catT *) malloc(sizeof(catT));
@@ -874,10 +873,8 @@ FILE *fp;
msgT *msg;
setT *set;
- if (!cat) {
- fprintf(stderr, "No catalog open\n");
- exit (1);
- }
+ if (!cat)
+ errx(1, "no catalog open");
for (set = cat->first; set; set = set->next) {
fprintf(fp, "$set %d", set->setId);
OpenPOWER on IntegriCloud