Importing usr.bin/cut
Replaces commands/cut. No Minix-specific changes needed. Change-Id: I4e8e203eb8aad18232364f05cbdc961a57afae51
This commit is contained in:
parent
40b23ce476
commit
d091a404e8
7 changed files with 38 additions and 39 deletions
|
@ -5,7 +5,7 @@
|
||||||
SUBDIR= add_route arp ash at backup btrace \
|
SUBDIR= add_route arp ash at backup btrace \
|
||||||
cawf cd cdprobe cpp \
|
cawf cd cdprobe cpp \
|
||||||
chmod chown ci cleantmp cmp co \
|
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 \
|
dd decomp16 DESCRIBE devmand devsize df dhcpd \
|
||||||
dhrystone diff diskctl dumpcore \
|
dhrystone diff diskctl dumpcore \
|
||||||
eject env factor fbdctl \
|
eject env factor fbdctl \
|
||||||
|
|
|
@ -152,6 +152,7 @@
|
||||||
2012/10/17 12:00:00,usr.bin/cksum
|
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/col
|
||||||
2012/10/17 12:00:00,usr.bin/ctags
|
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
|
2012/10/17 12:00:00,usr.bin/dirname
|
||||||
2011/09/01 13:37:33,usr.bin/du
|
2011/09/01 13:37:33,usr.bin/du
|
||||||
2012/10/17 12:00:00,usr.bin/expand
|
2012/10/17 12:00:00,usr.bin/expand
|
||||||
|
|
|
@ -7,7 +7,7 @@ SUBDIR= \
|
||||||
banner basename bdes \
|
banner basename bdes \
|
||||||
bzip2 bzip2recover \
|
bzip2 bzip2recover \
|
||||||
cal chpass cksum \
|
cal chpass cksum \
|
||||||
col ctags \
|
col ctags cut \
|
||||||
dirname du \
|
dirname du \
|
||||||
expand \
|
expand \
|
||||||
finger from \
|
finger from \
|
||||||
|
|
|
@ -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
|
# @(#)Makefile 8.1 (Berkeley) 6/6/93
|
||||||
|
|
||||||
PROG= cut
|
PROG= cut
|
|
@ -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
|
.\" Copyright (c) 1989, 1990, 1993
|
||||||
.\" The Regents of the University of California. All rights reserved.
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
.\"
|
.\"
|
||||||
.\" @(#)cut.1 8.1 (Berkeley) 6/6/93
|
.\" @(#)cut.1 8.1 (Berkeley) 6/6/93
|
||||||
.\"
|
.\"
|
||||||
.Dd December 21, 2008
|
.Dd June 12, 2012
|
||||||
.Dt CUT 1
|
.Dt CUT 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
@ -48,7 +48,7 @@
|
||||||
.Op Ar
|
.Op Ar
|
||||||
.Nm
|
.Nm
|
||||||
.Fl f Ar list
|
.Fl f Ar list
|
||||||
.Op Fl d Ar delim
|
.Op Fl d Ar string
|
||||||
.Op Fl s
|
.Op Fl s
|
||||||
.Op Ar
|
.Op Ar
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
|
@ -71,32 +71,30 @@ The items specified by
|
||||||
.Ar list
|
.Ar list
|
||||||
can be in terms of column position or in terms of fields delimited
|
can be in terms of column position or in terms of fields delimited
|
||||||
by a special character.
|
by a special character.
|
||||||
Column numbering starts from 1.
|
Column and field numbering start from 1.
|
||||||
.Pp
|
.Pp
|
||||||
.Ar List
|
.Ar list
|
||||||
is a comma or whitespace separated set of increasing numbers and/or
|
is a comma or whitespace separated set of increasing numbers and/or
|
||||||
number ranges.
|
number ranges.
|
||||||
Number ranges consist of a number, a dash
|
Number ranges consist of a number, a dash
|
||||||
.Pq Li \- ,
|
.Pq Li \- ,
|
||||||
and a second number
|
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.
|
inclusive.
|
||||||
Numbers or number ranges may be preceded by a dash, which selects all
|
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
|
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.
|
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.
|
input line.
|
||||||
.Pp
|
.Pp
|
||||||
The options are as follows:
|
The options are as follows:
|
||||||
.Bl -tag -width Fl
|
.Bl -tag -width Fl
|
||||||
.It Fl b Ar list
|
.It Fl b Ar list
|
||||||
The
|
|
||||||
.Ar list
|
.Ar list
|
||||||
specifies byte positions.
|
specifies byte positions.
|
||||||
.It Fl c Ar list
|
.It Fl c Ar list
|
||||||
The
|
|
||||||
.Ar list
|
.Ar list
|
||||||
specifies character positions.
|
specifies character positions.
|
||||||
.It Fl d Ar string
|
.It Fl d Ar string
|
||||||
|
@ -107,7 +105,6 @@ The default is the
|
||||||
.Aq TAB
|
.Aq TAB
|
||||||
character.
|
character.
|
||||||
.It Fl f Ar list
|
.It Fl f Ar list
|
||||||
The
|
|
||||||
.Ar list
|
.Ar list
|
||||||
specifies fields, separated by the field delimiter character.
|
specifies fields, separated by the field delimiter character.
|
||||||
The selected fields are output,
|
The selected fields are output,
|
||||||
|
@ -115,12 +112,11 @@ separated by the field delimiter character.
|
||||||
.It Fl n
|
.It Fl n
|
||||||
Do not split multi-byte characters.
|
Do not split multi-byte characters.
|
||||||
.It Fl s
|
.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.
|
Unless specified, lines with no delimiters are passed through unmodified.
|
||||||
.El
|
.El
|
||||||
.Sh EXIT STATUS
|
.Sh EXIT STATUS
|
||||||
.Nm
|
.Ex -std
|
||||||
exits 0 on success, 1 if an error occurred.
|
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr paste 1
|
.Xr paste 1
|
||||||
.Sh STANDARDS
|
.Sh STANDARDS
|
|
@ -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
|
* Copyright (c) 1989, 1993
|
||||||
|
@ -33,6 +33,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#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 <ctype.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
@ -47,8 +58,6 @@
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
|
|
||||||
|
|
||||||
static int bflag;
|
static int bflag;
|
||||||
static int cflag;
|
static int cflag;
|
||||||
static char dchar;
|
static char dchar;
|
||||||
|
@ -57,9 +66,7 @@ static int fflag;
|
||||||
static int sflag;
|
static int sflag;
|
||||||
|
|
||||||
static void b_cut(FILE *, const char *);
|
static void b_cut(FILE *, const char *);
|
||||||
#if 0
|
|
||||||
static void c_cut(FILE *, const char *);
|
static void c_cut(FILE *, const char *);
|
||||||
#endif
|
|
||||||
static void f_cut(FILE *, const char *);
|
static void f_cut(FILE *, const char *);
|
||||||
static void get_list(char *);
|
static void get_list(char *);
|
||||||
static void usage(void) __dead;
|
static void usage(void) __dead;
|
||||||
|
@ -81,18 +88,15 @@ main(int argc, char *argv[])
|
||||||
while ((ch = getopt(argc, argv, "b:c:d:f:sn")) != -1)
|
while ((ch = getopt(argc, argv, "b:c:d:f:sn")) != -1)
|
||||||
switch(ch) {
|
switch(ch) {
|
||||||
case 'b':
|
case 'b':
|
||||||
case 'c':
|
|
||||||
fcn = b_cut;
|
fcn = b_cut;
|
||||||
get_list(optarg);
|
get_list(optarg);
|
||||||
bflag = 1;
|
bflag = 1;
|
||||||
break;
|
break;
|
||||||
#if 0
|
|
||||||
case 'c':
|
case 'c':
|
||||||
fcn = c_cut;
|
fcn = c_cut;
|
||||||
get_list(optarg);
|
get_list(optarg);
|
||||||
cflag = 1;
|
cflag = 1;
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
case 'd':
|
case 'd':
|
||||||
dchar = *optarg;
|
dchar = *optarg;
|
||||||
dflag = 1;
|
dflag = 1;
|
||||||
|
@ -142,7 +146,7 @@ static size_t autostart, autostop, maxval;
|
||||||
|
|
||||||
static char *positions = NULL;
|
static char *positions = NULL;
|
||||||
static size_t numpositions = 0;
|
static size_t numpositions = 0;
|
||||||
#define ALLOC_CHUNK 4096 /* malloc granularity */
|
#define ALLOC_CHUNK _POSIX2_LINE_MAX /* malloc granularity */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_list(char *list)
|
get_list(char *list)
|
||||||
|
@ -162,7 +166,7 @@ get_list(char *list)
|
||||||
* This parser is less restrictive than the Draft 9 POSIX spec.
|
* This parser is less restrictive than the Draft 9 POSIX spec.
|
||||||
* POSIX doesn't allow lists that aren't in increasing order or
|
* POSIX doesn't allow lists that aren't in increasing order or
|
||||||
* overlapping lists. We also handle "-3-5" although there's no
|
* 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) {
|
for (; (p = strtok(list, ", \t")) != NULL; list = NULL) {
|
||||||
setautostart = start = stop = 0;
|
setautostart = start = stop = 0;
|
||||||
|
@ -185,9 +189,9 @@ get_list(char *list)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*p)
|
if (*p)
|
||||||
errx(1, "[-cf] list: illegal list value");
|
errx(1, "[-bcf] list: illegal list value");
|
||||||
if (!stop || !start)
|
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) {
|
if (stop + 1 > numpositions) {
|
||||||
size_t newsize;
|
size_t newsize;
|
||||||
newsize = roundup(stop + 1, ALLOC_CHUNK);
|
newsize = roundup(stop + 1, ALLOC_CHUNK);
|
||||||
|
@ -281,9 +285,9 @@ f_cut(FILE *fp, const char *fname __unused)
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
(void)fprintf(stderr, "Usage:\tcut -b list [-n] [file ...]\n"
|
(void)fprintf(stderr, "usage:\tcut -b list [-n] [file ...]\n"
|
||||||
"\tcut -c list [file1 ...]\n"
|
"\tcut -c list [file ...]\n"
|
||||||
"\tcut -f list [-d delim] [-s] [file ...]\n");
|
"\tcut -f list [-d string] [-s] [file ...]\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,9 +296,7 @@ usage(void)
|
||||||
#include "x_cut.c"
|
#include "x_cut.c"
|
||||||
#undef CUT_BYTE
|
#undef CUT_BYTE
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* make c_put(): */
|
/* make c_put(): */
|
||||||
#define CUT_BYTE 0
|
#define CUT_BYTE 0
|
||||||
#include "x_cut.c"
|
#include "x_cut.c"
|
||||||
#undef CUT_BYTE
|
#undef CUT_BYTE
|
||||||
#endif
|
|
|
@ -58,7 +58,7 @@
|
||||||
|
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
static void
|
void
|
||||||
CUT_FN(FILE *fp, const char *fname __unused)
|
CUT_FN(FILE *fp, const char *fname __unused)
|
||||||
{
|
{
|
||||||
CUT_CH_T ch;
|
CUT_CH_T ch;
|
Loading…
Reference in a new issue