Importing usr.bin/cut

Replaces commands/cut. No Minix-specific changes needed.

Change-Id: I4e8e203eb8aad18232364f05cbdc961a57afae51
This commit is contained in:
Thomas Cort 2013-10-14 19:23:02 -04:00
parent 40b23ce476
commit d091a404e8
7 changed files with 38 additions and 39 deletions

View File

@ -5,7 +5,7 @@
SUBDIR= add_route arp ash at backup btrace \
cawf cd cdprobe cpp \
chmod chown ci cleantmp cmp co \
comm compress cp crc cron crontab cut \
comm compress cp crc cron crontab \
dd decomp16 DESCRIBE devmand devsize df dhcpd \
dhrystone diff diskctl dumpcore \
eject env factor fbdctl \

View File

@ -152,6 +152,7 @@
2012/10/17 12:00:00,usr.bin/cksum
2012/10/17 12:00:00,usr.bin/col
2012/10/17 12:00:00,usr.bin/ctags
2013/10/14 12:00:00,usr.bin/cut
2012/10/17 12:00:00,usr.bin/dirname
2011/09/01 13:37:33,usr.bin/du
2012/10/17 12:00:00,usr.bin/expand

View File

@ -7,7 +7,7 @@ SUBDIR= \
banner basename bdes \
bzip2 bzip2recover \
cal chpass cksum \
col ctags \
col ctags cut \
dirname du \
expand \
finger from \

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.5 2007/07/02 18:41:03 christos Exp $
# $NetBSD: Makefile,v 1.6 2009/04/14 22:15:19 lukem Exp $
# @(#)Makefile 8.1 (Berkeley) 6/6/93
PROG= cut

View File

@ -1,4 +1,4 @@
.\" $NetBSD: cut.1,v 1.14.26.1 2008/12/23 03:47:20 snj Exp $
.\" $NetBSD: cut.1,v 1.18 2012/06/20 17:53:19 wiz Exp $
.\"
.\" Copyright (c) 1989, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@ -32,7 +32,7 @@
.\"
.\" @(#)cut.1 8.1 (Berkeley) 6/6/93
.\"
.Dd December 21, 2008
.Dd June 12, 2012
.Dt CUT 1
.Os
.Sh NAME
@ -48,14 +48,14 @@
.Op Ar
.Nm
.Fl f Ar list
.Op Fl d Ar delim
.Op Fl d Ar string
.Op Fl s
.Op Ar
.Sh DESCRIPTION
The
.Nm
utility selects portions of each line (as specified by
.Ar list )
.Ar list )
from each
.Ar file
and writes them to the
@ -71,32 +71,30 @@ The items specified by
.Ar list
can be in terms of column position or in terms of fields delimited
by a special character.
Column numbering starts from 1.
Column and field numbering start from 1.
.Pp
.Ar List
.Ar list
is a comma or whitespace separated set of increasing numbers and/or
number ranges.
Number ranges consist of a number, a dash
.Pq Li \- ,
and a second number
and select the fields or columns from the first number to the second,
and select the columns or fields from the first number to the second,
inclusive.
Numbers or number ranges may be preceded by a dash, which selects all
fields or columns from 1 to the first number.
columns or fields from 1 to the first number.
Numbers or number ranges may be followed by a dash, which selects all
fields or columns from the last number to the end of the line.
columns or fields from the last number to the end of the line.
Numbers and number ranges may be repeated, overlapping, and in any order.
It is not an error to select fields or columns not present in the
It is not an error to select columns or fields not present in the
input line.
.Pp
The options are as follows:
.Bl -tag -width Fl
.It Fl b Ar list
The
.Ar list
specifies byte positions.
.It Fl c Ar list
The
.Ar list
specifies character positions.
.It Fl d Ar string
@ -107,7 +105,6 @@ The default is the
.Aq TAB
character.
.It Fl f Ar list
The
.Ar list
specifies fields, separated by the field delimiter character.
The selected fields are output,
@ -115,12 +112,11 @@ separated by the field delimiter character.
.It Fl n
Do not split multi-byte characters.
.It Fl s
Suppresses lines with no field delimiter characters.
Suppress lines with no field delimiter characters.
Unless specified, lines with no delimiters are passed through unmodified.
.El
.Sh EXIT STATUS
.Nm
exits 0 on success, 1 if an error occurred.
.Ex -std
.Sh SEE ALSO
.Xr paste 1
.Sh STANDARDS

View File

@ -1,4 +1,4 @@
/* $NetBSD: cut.c,v 1.25 2008/07/21 14:19:22 lukem Exp $ */
/* $NetBSD: cut.c,v 1.28 2012/06/20 17:53:39 wiz Exp $ */
/*
* Copyright (c) 1989, 1993
@ -33,6 +33,17 @@
*/
#include <sys/cdefs.h>
#ifndef lint
__COPYRIGHT("@(#) Copyright (c) 1989, 1993\
The Regents of the University of California. All rights reserved.");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)cut.c 8.3 (Berkeley) 5/4/95";
#endif
__RCSID("$NetBSD: cut.c,v 1.28 2012/06/20 17:53:39 wiz Exp $");
#endif /* not lint */
#include <ctype.h>
#include <err.h>
@ -47,8 +58,6 @@
#include <wchar.h>
#include <sys/param.h>
#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
static int bflag;
static int cflag;
static char dchar;
@ -57,9 +66,7 @@ static int fflag;
static int sflag;
static void b_cut(FILE *, const char *);
#if 0
static void c_cut(FILE *, const char *);
#endif
static void f_cut(FILE *, const char *);
static void get_list(char *);
static void usage(void) __dead;
@ -76,23 +83,20 @@ main(int argc, char *argv[])
dchar = '\t'; /* default delimiter is \t */
/* Since we don't support multi-byte characters, the -c and -b
/* Since we don't support multi-byte characters, the -c and -b
options are equivalent, and the -n option is meaningless. */
while ((ch = getopt(argc, argv, "b:c:d:f:sn")) != -1)
switch(ch) {
case 'b':
case 'c':
fcn = b_cut;
get_list(optarg);
bflag = 1;
break;
#if 0
case 'c':
fcn = c_cut;
get_list(optarg);
cflag = 1;
break;
#endif
case 'd':
dchar = *optarg;
dflag = 1;
@ -142,7 +146,7 @@ static size_t autostart, autostop, maxval;
static char *positions = NULL;
static size_t numpositions = 0;
#define ALLOC_CHUNK 4096 /* malloc granularity */
#define ALLOC_CHUNK _POSIX2_LINE_MAX /* malloc granularity */
static void
get_list(char *list)
@ -162,7 +166,7 @@ get_list(char *list)
* This parser is less restrictive than the Draft 9 POSIX spec.
* POSIX doesn't allow lists that aren't in increasing order or
* overlapping lists. We also handle "-3-5" although there's no
* real reason too.
* real reason to.
*/
for (; (p = strtok(list, ", \t")) != NULL; list = NULL) {
setautostart = start = stop = 0;
@ -185,9 +189,9 @@ get_list(char *list)
}
}
if (*p)
errx(1, "[-cf] list: illegal list value");
errx(1, "[-bcf] list: illegal list value");
if (!stop || !start)
errx(1, "[-cf] list: values may not include zero");
errx(1, "[-bcf] list: values may not include zero");
if (stop + 1 > numpositions) {
size_t newsize;
newsize = roundup(stop + 1, ALLOC_CHUNK);
@ -281,20 +285,18 @@ f_cut(FILE *fp, const char *fname __unused)
static void
usage(void)
{
(void)fprintf(stderr, "Usage:\tcut -b list [-n] [file ...]\n"
"\tcut -c list [file1 ...]\n"
"\tcut -f list [-d delim] [-s] [file ...]\n");
(void)fprintf(stderr, "usage:\tcut -b list [-n] [file ...]\n"
"\tcut -c list [file ...]\n"
"\tcut -f list [-d string] [-s] [file ...]\n");
exit(1);
}
/* make b_put(): */
#define CUT_BYTE 1
#define CUT_BYTE 1
#include "x_cut.c"
#undef CUT_BYTE
#if 0
/* make c_put(): */
#define CUT_BYTE 0
#include "x_cut.c"
#undef CUT_BYTE
#endif

View File

@ -58,7 +58,7 @@
/* ARGSUSED */
static void
void
CUT_FN(FILE *fp, const char *fname __unused)
{
CUT_CH_T ch;