diff options
Diffstat (limited to 'usr.bin/paste/paste.c')
-rw-r--r-- | usr.bin/paste/paste.c | 70 |
1 files changed, 34 insertions, 36 deletions
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 <sys/types.h> +#include <err.h> #include <errno.h> #include <limits.h> #include <stdio.h> #include <string.h> +#include <unistd.h> 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); } |