From 491754a358a73af434ddea8e9cc0a33daf66748e Mon Sep 17 00:00:00 2001 From: charnier Date: Thu, 31 Jul 1997 06:59:26 +0000 Subject: Use err(3). Add prototypes. Silent -Wall. --- usr.bin/paste/paste.1 | 10 ++++---- usr.bin/paste/paste.c | 70 +++++++++++++++++++++++++-------------------------- 2 files changed, 39 insertions(+), 41 deletions(-) (limited to 'usr.bin/paste') diff --git a/usr.bin/paste/paste.1 b/usr.bin/paste/paste.1 index f62b994..c9d9a5f 100644 --- a/usr.bin/paste/paste.1 +++ b/usr.bin/paste/paste.1 @@ -42,13 +42,13 @@ .Nm paste .Nd merge corresponding or subsequent lines of files .Sh SYNOPSIS -.Nm paste +.Nm .Op Fl s .Op Fl d Ar list .Ar file ... .Sh DESCRIPTION The -.Nm paste +.Nm utility concatenates the corresponding lines of the given input files, replacing all but the last file's newline characters with a single tab character, and writes the resulting lines to standard output. @@ -71,7 +71,7 @@ is reused. This continues until a line from the last input file (in default operation) or the last line in each file (using the -s option) is displayed, at which time -.Nm paste +.Nm begins selecting characters from the beginning of .Ar list again. @@ -107,13 +107,13 @@ for each instance of .Ql Fl . .Pp The -.Nm paste +.Nm utility exits 0 on success, and >0 if an error occurs. .Sh SEE ALSO .Xr cut 1 .Sh STANDARDS The -.Nm paste +.Nm utility is expected to be .St -p1003.2 compatible. diff --git a/usr.bin/paste/paste.c b/usr.bin/paste/paste.c index 4155855..00edfa7 100644 --- a/usr.bin/paste/paste.c +++ b/usr.bin/paste/paste.c @@ -35,30 +35,40 @@ */ #ifndef lint -static char copyright[] = +static const char copyright[] = "@(#) Copyright (c) 1989, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint +#if 0 static char sccsid[] = "@(#)paste.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ #include +#include #include #include #include #include +#include char *delim; int delimcnt; +void parallel __P((char **)); +void sequential __P((char **)); +int tr __P((char *)); +static void usage __P((void)); + +int main(argc, argv) int argc; char **argv; { - extern char *optarg; - extern int optind; int ch, seq; seq = 0; @@ -96,6 +106,7 @@ typedef struct _list { char *name; } LIST; +void parallel(argv) char **argv; { @@ -106,18 +117,13 @@ parallel(argv) int opencnt, output; char buf[_POSIX2_LINE_MAX + 1], *malloc(); - for (cnt = 0, head = NULL; p = *argv; ++argv, ++cnt) { - if (!(lp = (LIST *)malloc((u_int)sizeof(LIST)))) { - (void)fprintf(stderr, "paste: %s.\n", strerror(ENOMEM)); - exit(1); - } + for (cnt = 0, head = NULL; (p = *argv); ++argv, ++cnt) { + if (!(lp = (LIST *)malloc((u_int)sizeof(LIST)))) + errx(1, "%s", strerror(ENOMEM)); if (p[0] == '-' && !p[1]) lp->fp = stdin; - else if (!(lp->fp = fopen(p, "r"))) { - (void)fprintf(stderr, "paste: %s: %s.\n", p, - strerror(errno)); - exit(1); - } + else if (!(lp->fp = fopen(p, "r"))) + err(1, "%s", p); lp->next = NULL; lp->cnt = cnt; lp->name = p; @@ -146,12 +152,8 @@ parallel(argv) putchar(ch); continue; } - if (!(p = index(buf, '\n'))) { - (void)fprintf(stderr, - "paste: %s: input line too long.\n", - lp->name); - exit(1); - } + if (!(p = index(buf, '\n'))) + errx(1, "%s: input line too long", lp->name); *p = '\0'; /* * make sure that we don't print any delimiters @@ -160,9 +162,9 @@ parallel(argv) if (!output) { output = 1; for (cnt = 0; cnt < lp->cnt; ++cnt) - if (ch = delim[cnt % delimcnt]) + if ((ch = delim[cnt % delimcnt])) putchar(ch); - } else if (ch = delim[(lp->cnt - 1) % delimcnt]) + } else if ((ch = delim[(lp->cnt - 1) % delimcnt])) putchar(ch); (void)printf("%s", buf); } @@ -171,6 +173,7 @@ parallel(argv) } } +void sequential(argv) char **argv; { @@ -179,27 +182,22 @@ sequential(argv) register char ch, *p, *dp; char buf[_POSIX2_LINE_MAX + 1]; - for (; p = *argv; ++argv) { + for (; (p = *argv); ++argv) { if (p[0] == '-' && !p[1]) fp = stdin; else if (!(fp = fopen(p, "r"))) { - (void)fprintf(stderr, "paste: %s: %s.\n", p, - strerror(errno)); + warn("%s", p); continue; } if (fgets(buf, sizeof(buf), fp)) { for (cnt = 0, dp = delim;;) { - if (!(p = index(buf, '\n'))) { - (void)fprintf(stderr, - "paste: %s: input line too long.\n", - *argv); - exit(1); - } + if (!(p = index(buf, '\n'))) + errx(1, "%s: input line too long", *argv); *p = '\0'; (void)printf("%s", buf); if (!fgets(buf, sizeof(buf), fp)) break; - if (ch = *dp++) + if ((ch = *dp++)) putchar(ch); if (++cnt == delimcnt) { dp = delim; @@ -213,6 +211,7 @@ sequential(argv) } } +int tr(arg) char *arg; { @@ -237,15 +236,14 @@ tr(arg) } else *arg = ch; - if (!cnt) { - (void)fprintf(stderr, "paste: no delimiters specified.\n"); - exit(1); - } + if (!cnt) + errx(1, "no delimiters specified"); return(cnt); } +static void usage() { - (void)fprintf(stderr, "paste: [-s] [-d delimiters] file ...\n"); + (void)fprintf(stderr, "usage: paste [-s] [-d delimiters] file ...\n"); exit(1); } -- cgit v1.1