getopt returns -1 not EOF, use <err.h>, use ANSI string.h functions

This commit is contained in:
lukem 1997-10-20 01:07:48 +00:00
parent a5e1830c1e
commit bfd39f4ab1
7 changed files with 35 additions and 59 deletions

View File

@ -1,7 +1,6 @@
# $NetBSD: Makefile,v 1.4 1997/10/14 02:07:55 lukem Exp $
# $NetBSD: Makefile,v 1.5 1997/10/20 01:07:48 lukem Exp $
# @(#)Makefile 8.1 (Berkeley) 6/9/93
WARNS?= 1
PROG= tset
SRCS= map.c misc.c set.c term.c tset.c wrterm.c

View File

@ -1,4 +1,4 @@
/* $NetBSD: extern.h,v 1.4 1997/10/14 02:07:56 lukem Exp $ */
/* $NetBSD: extern.h,v 1.5 1997/10/20 01:07:50 lukem Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -45,7 +45,6 @@ extern int erasechar, intrchar, killchar;
void add_mapping __P((char *, char *));
void cat __P((char *));
void err __P((const char *, ...));
char *get_termcap_entry __P((char *, char **));
char *mapped __P((char *));
void outc __P((int));

View File

@ -1,4 +1,4 @@
/* $NetBSD: map.c,v 1.7 1997/10/14 02:07:57 lukem Exp $ */
/* $NetBSD: map.c,v 1.8 1997/10/20 01:07:51 lukem Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -38,10 +38,11 @@
#if 0
static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/9/93";
#endif
__RCSID("$NetBSD: map.c,v 1.7 1997/10/14 02:07:57 lukem Exp $");
__RCSID("$NetBSD: map.c,v 1.8 1997/10/20 01:07:51 lukem Exp $");
#endif /* not lint */
#include <sys/types.h>
#include <err.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
@ -83,7 +84,7 @@ add_mapping(port, arg)
copy = strdup(arg);
mapp = malloc((u_int)sizeof(MAP));
if (copy == NULL || mapp == NULL)
err("%s", strerror(errno));
err(1, "malloc");
mapp->next = NULL;
if (maplist == NULL)
cur = maplist = mapp;
@ -159,7 +160,7 @@ next: if (*arg == ':') {
/* If user specified a port with an option flag, set it. */
done: if (port) {
if (mapp->porttype)
badmopt: err("illegal -m option format: %s", copy);
badmopt: errx(1, "illegal -m option format: %s", copy);
mapp->porttype = port;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: misc.c,v 1.4 1997/10/14 02:07:58 lukem Exp $ */
/* $NetBSD: misc.c,v 1.5 1997/10/20 01:07:52 lukem Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -38,9 +38,10 @@
#if 0
static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/9/93";
#endif
__RCSID("$NetBSD: misc.c,v 1.4 1997/10/14 02:07:58 lukem Exp $");
__RCSID("$NetBSD: misc.c,v 1.5 1997/10/20 01:07:52 lukem Exp $");
#endif /* not lint */
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@ -57,13 +58,13 @@ cat(file)
char buf[1024];
if ((fd = open(file, O_RDONLY, 0)) < 0)
err("%s: %s", file, strerror(errno));
err(1, "%s", file);
while ((nr = read(fd, buf, sizeof(buf))) > 0)
if ((nw = write(STDERR_FILENO, buf, nr)) == -1)
err("write to stderr: %s", strerror(errno));
err(1, "write to stderr");
if (nr != 0)
err("%s: %s", file, strerror(errno));
err(1, "%s", file);
(void)close(fd);
}
@ -73,32 +74,3 @@ outc(c)
{
(void)putc(c, stderr);
}
#if __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
void
#if __STDC__
err(const char *fmt, ...)
#else
err(fmt, va_alist)
char *fmt;
va_dcl
#endif
{
va_list ap;
#if __STDC__
va_start(ap, fmt);
#else
va_start(ap);
#endif
(void)fprintf(stderr, "tset: ");
(void)vfprintf(stderr, fmt, ap);
va_end(ap);
(void)fprintf(stderr, "\n");
exit(1);
/* NOTREACHED */
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: term.c,v 1.8 1997/10/14 02:08:01 lukem Exp $ */
/* $NetBSD: term.c,v 1.9 1997/10/20 01:07:53 lukem Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -38,10 +38,11 @@
#if 0
static char sccsid[] = "@(#)term.c 8.1 (Berkeley) 6/9/93";
#endif
__RCSID("$NetBSD: term.c,v 1.8 1997/10/14 02:08:01 lukem Exp $");
__RCSID("$NetBSD: term.c,v 1.9 1997/10/20 01:07:53 lukem Exp $");
#endif /* not lint */
#include <sys/types.h>
#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@ -114,12 +115,14 @@ found: if ((p = getenv("TERMCAP")) != NULL && *p != '/')
/* Find the termcap entry. If it doesn't exist, ask the user. */
while ((rval = tgetent(tbuf, ttype)) == 0) {
(void)fprintf(stderr,
"tset: terminal type %s is unknown\n", ttype);
warnx("terminal type %s is unknown", ttype);
ttype = askuser(NULL);
}
if (rval == -1)
err("termcap: %s", strerror(errno ? errno : ENOENT));
if (rval == -1) {
if (!errno)
errno = ENOENT;
err(1, "%s", "");
}
*tcapbufp = tbuf;
return (ttype);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: tset.c,v 1.5 1997/10/14 02:08:03 lukem Exp $ */
/* $NetBSD: tset.c,v 1.6 1997/10/20 01:07:54 lukem Exp $ */
/*-
* Copyright (c) 1980, 1991, 1993
@ -43,12 +43,13 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1991, 1993\n\
#if 0
static char sccsid[] = "@(#)tset.c 8.1 (Berkeley) 6/9/93";
#endif
__RCSID("$NetBSD: tset.c,v 1.5 1997/10/14 02:08:03 lukem Exp $");
__RCSID("$NetBSD: tset.c,v 1.6 1997/10/20 01:07:54 lukem Exp $");
#endif /* not lint */
#include <sys/types.h>
#include <sys/ioctl.h>
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@ -83,7 +84,7 @@ main(argc, argv)
char savech, *p, *t, *tcapbuf, *ttype;
if (tcgetattr(STDERR_FILENO, &mode) < 0)
err("standard error: %s", strerror(errno));
err(1, "standard error");
oldmode = mode;
ospeed = cfgetospeed(&mode);
@ -100,7 +101,7 @@ main(argc, argv)
obsolete(argv);
noinit = noset = quiet = Sflag = sflag = showterm = 0;
while ((ch = getopt(argc, argv, "-a:d:e:Ii:k:m:np:QSrs")) != EOF) {
while ((ch = getopt(argc, argv, "-a:d:e:Ii:k:m:np:QSrs")) != -1) {
switch (ch) {
case '-': /* display term only */
noset = 1;
@ -195,7 +196,7 @@ main(argc, argv)
savech = *p;
*p = '\0';
if ((ttype = strdup(t)) == NULL)
err("%s", strerror(errno));
err(1, "strdup");
*p = savech;
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: wrterm.c,v 1.5 1997/10/14 02:08:05 lukem Exp $ */
/* $NetBSD: wrterm.c,v 1.6 1997/10/20 01:07:55 lukem Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -38,11 +38,12 @@
#if 0
static char sccsid[] = "@(#)wrterm.c 8.1 (Berkeley) 6/9/93";
#endif
__RCSID("$NetBSD: wrterm.c,v 1.5 1997/10/14 02:08:05 lukem Exp $");
__RCSID("$NetBSD: wrterm.c,v 1.6 1997/10/20 01:07:55 lukem Exp $");
#endif /* not lint */
#include <sys/types.h>
#include <ctype.h>
#include <err.h>
#include <stdio.h>
#include <string.h>
#include "extern.h"
@ -55,13 +56,13 @@ void
wrtermcap(bp)
char *bp;
{
register int ch;
register char *p;
int ch;
char *p;
char *t, *sep;
/* Find the end of the terminal names. */
if ((t = index(bp, ':')) == NULL)
err("termcap names not colon terminated");
if ((t = strchr(bp, ':')) == NULL)
errx(1, "termcap names not colon terminated");
*t++ = '\0';
/* Output terminal names that don't have whitespace or quotes. */