Merged with 4.4Lite

This commit is contained in:
glass 1995-03-26 20:51:24 +00:00
parent f76f1f89ad
commit 843a1dd6bf
3 changed files with 57 additions and 56 deletions

View File

@ -1,5 +1,5 @@
# from: @(#)Makefile 5.2 (Berkeley) 5/11/90 # $NetBSD: Makefile,v 1.3 1995/03/26 20:51:24 glass Exp $
# $Id: Makefile,v 1.2 1993/07/31 15:24:03 mycroft Exp $ # @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= cut PROG= cut

View File

@ -1,5 +1,7 @@
.\" Copyright (c) 1989, 1990 The Regents of the University of California. .\" $NetBSD: cut.1,v 1.5 1995/03/26 20:51:25 glass Exp $
.\" All rights reserved. .\"
.\" Copyright (c) 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\" .\"
.\" This code is derived from software contributed to Berkeley by .\" This code is derived from software contributed to Berkeley by
.\" the Institute of Electrical and Electronics Engineers, Inc. .\" the Institute of Electrical and Electronics Engineers, Inc.
@ -32,10 +34,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" from: @(#)cut.1 5.5 (Berkeley) 6/27/91 .\" @(#)cut.1 8.1 (Berkeley) 6/6/93
.\" $Id: cut.1,v 1.4 1993/08/19 17:16:46 jtc Exp $
.\" .\"
.Dd June 27, 1991 .Dd June 6, 1993
.Dt CUT 1 .Dt CUT 1
.Os .Os
.Sh NAME .Sh NAME
@ -94,9 +95,9 @@ specifies byte positions.
The The
.Ar list .Ar list
specifies character positions. specifies character positions.
.It Fl d Ar delim .It Fl d Ar string
Use Use the first character of
.Ar delim .Ar string
as the field delimiter character instead of the tab character. as the field delimiter character instead of the tab character.
.It Fl f Ar list .It Fl f Ar list
The The

View File

@ -1,6 +1,8 @@
/* $NetBSD: cut.c,v 1.8 1995/03/26 20:51:27 glass Exp $ */
/* /*
* Copyright (c) 1989 The Regents of the University of California. * Copyright (c) 1989, 1993
* All rights reserved. * The Regents of the University of California. All rights reserved.
* *
* This code is derived from software contributed to Berkeley by * This code is derived from software contributed to Berkeley by
* Adam S. Moskowitz of Menlo Consulting and Marciano Pitargue. * Adam S. Moskowitz of Menlo Consulting and Marciano Pitargue.
@ -35,23 +37,27 @@
*/ */
#ifndef lint #ifndef lint
char copyright[] = static char copyright[] =
"@(#) Copyright (c) 1989 The Regents of the University of California.\n\ "@(#) Copyright (c) 1989, 1993\n\
All rights reserved.\n"; The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */ #endif /* not lint */
#ifndef lint #ifndef lint
/*static char sccsid[] = "from: @(#)cut.c 5.4 (Berkeley) 10/30/90";*/ #if 0
static char rcsid[] = "$Id: cut.c,v 1.7 1995/03/20 23:50:43 mycroft Exp $"; static char sccsid[] = "@(#)cut.c 8.1 (Berkeley) 6/6/93";
#else
static char rcsid[] = "$NetBSD: cut.c,v 1.8 1995/03/26 20:51:27 glass Exp $";
#endif
#endif /* not lint */ #endif /* not lint */
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <limits.h>
#include <locale.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <limits.h>
#include <locale.h>
#include <ctype.h>
#include <err.h>
int cflag; int cflag;
char dchar; char dchar;
@ -59,15 +65,19 @@ int dflag;
int fflag; int fflag;
int sflag; int sflag;
void c_cut __P((FILE *, char *));
void f_cut __P((FILE *, char *));
void get_list __P((char *));
void usage __P((void));
int int
main(argc, argv) main(argc, argv)
int argc; int argc;
char **argv; char *argv[];
{ {
extern char *optarg;
extern int errno, optind;
FILE *fp; FILE *fp;
int ch, (*fcn)(), c_cut(), f_cut(); void (*fcn) __P((FILE *, char *));
int ch;
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
@ -112,11 +122,10 @@ main(argc, argv)
if (*argv) if (*argv)
for (; *argv; ++argv) { for (; *argv; ++argv) {
if (!(fp = fopen(*argv, "r"))) { if (!(fp = fopen(*argv, "r")))
err(1, "%s", *argv); err(1, "%s", *argv);
/* NOTREACHED */
}
fcn(fp, *argv); fcn(fp, *argv);
(void)fclose(fp);
} }
else else
fcn(stdin, "stdin"); fcn(stdin, "stdin");
@ -127,11 +136,12 @@ int autostart, autostop, maxval;
char positions[_POSIX2_LINE_MAX + 1]; char positions[_POSIX2_LINE_MAX + 1];
void
get_list(list) get_list(list)
char *list; char *list;
{ {
register char *pos;
register int setautostart, start, stop; register int setautostart, start, stop;
register char *pos;
char *p; char *p;
/* /*
@ -163,15 +173,12 @@ get_list(list)
} }
} }
if (*p) if (*p)
badlist("illegal list value"); errx(1, "[-cf] list: illegal list value\n");
if (!stop || !start) if (!stop || !start)
badlist("values may not include zero"); errx(1, "[-cf] list: values may not include zero\n");
if (stop > _POSIX2_LINE_MAX) { if (stop > _POSIX2_LINE_MAX)
/* positions used rather than allocate a new buffer */ errx(1, "[-cf] list: %d too large (max %d)\n",
(void)sprintf(positions, "%d too large (max %d)",
stop, _POSIX2_LINE_MAX); stop, _POSIX2_LINE_MAX);
badlist(positions);
}
if (maxval < stop) if (maxval < stop)
maxval = stop; maxval = stop;
for (pos = positions + start; start++ <= stop; *pos++ = 1); for (pos = positions + start; start++ <= stop; *pos++ = 1);
@ -187,6 +194,7 @@ get_list(list)
} }
/* ARGSUSED */ /* ARGSUSED */
void
c_cut(fp, fname) c_cut(fp, fname)
FILE *fp; FILE *fp;
char *fname; char *fname;
@ -202,18 +210,19 @@ c_cut(fp, fname)
if (ch == '\n') if (ch == '\n')
break; break;
if (*pos++) if (*pos++)
putchar(ch); (void)putchar(ch);
} }
if (ch != '\n') if (ch != '\n')
if (autostop) if (autostop)
while ((ch = getc(fp)) != EOF && ch != '\n') while ((ch = getc(fp)) != EOF && ch != '\n')
putchar(ch); (void)putchar(ch);
else else
while ((ch = getc(fp)) != EOF && ch != '\n'); while ((ch = getc(fp)) != EOF && ch != '\n');
putchar('\n'); (void)putchar('\n');
} }
} }
void
f_cut(fp, fname) f_cut(fp, fname)
FILE *fp; FILE *fp;
char *fname; char *fname;
@ -226,11 +235,8 @@ f_cut(fp, fname)
for (sep = dchar; fgets(lbuf, sizeof(lbuf), fp);) { for (sep = dchar; fgets(lbuf, sizeof(lbuf), fp);) {
output = 0; output = 0;
for (isdelim = 0, p = lbuf;; ++p) { for (isdelim = 0, p = lbuf;; ++p) {
if (!(ch = *p)) { if (!(ch = *p))
(void)fprintf(stderr, errx(1, "%s: line too long.\n", fname);
"cut: %s: line too long.\n", fname);
exit(1);
}
/* this should work if newline is delimiter */ /* this should work if newline is delimiter */
if (ch == sep) if (ch == sep)
isdelim = 1; isdelim = 1;
@ -247,9 +253,9 @@ f_cut(fp, fname)
for (field = maxval, p = lbuf; field; --field, ++pos) { for (field = maxval, p = lbuf; field; --field, ++pos) {
if (*pos) { if (*pos) {
if (output++) if (output++)
putchar(sep); (void)putchar(sep);
while ((ch = *p++) != '\n' && ch != sep) while ((ch = *p++) != '\n' && ch != sep)
putchar(ch); (void)putchar(ch);
} else } else
while ((ch = *p++) != '\n' && ch != sep); while ((ch = *p++) != '\n' && ch != sep);
if (ch == '\n') if (ch == '\n')
@ -258,22 +264,16 @@ f_cut(fp, fname)
if (ch != '\n') if (ch != '\n')
if (autostop) { if (autostop) {
if (output) if (output)
putchar(sep); (void)putchar(sep);
for (; (ch = *p) != '\n'; ++p) for (; (ch = *p) != '\n'; ++p)
putchar(ch); (void)putchar(ch);
} else } else
for (; (ch = *p) != '\n'; ++p); for (; (ch = *p) != '\n'; ++p);
putchar('\n'); (void)putchar('\n');
} }
} }
badlist(msg) void
char *msg;
{
(void)fprintf(stderr, "cut: [-cf] list: %s.\n", msg);
exit(1);
}
usage() usage()
{ {
(void)fprintf(stderr, (void)fprintf(stderr,