From: Thomas Cort Date: Mon, 14 Oct 2013 23:23:02 +0000 (-0400) Subject: Importing usr.bin/cut X-Git-Tag: v3.3.0~746 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/index.css?a=commitdiff_plain;h=refs%2Fchanges%2F42%2F1042%2F2;p=minix.git Importing usr.bin/cut Replaces commands/cut. No Minix-specific changes needed. Change-Id: I4e8e203eb8aad18232364f05cbdc961a57afae51 --- diff --git a/commands/Makefile b/commands/Makefile index 1fbe640bc..9ba275a4a 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -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 \ diff --git a/releasetools/nbsd_ports b/releasetools/nbsd_ports index d87d62073..db02ba68e 100644 --- a/releasetools/nbsd_ports +++ b/releasetools/nbsd_ports @@ -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 diff --git a/usr.bin/Makefile b/usr.bin/Makefile index 01a36ae73..45ac4ece2 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -7,7 +7,7 @@ SUBDIR= \ banner basename bdes \ bzip2 bzip2recover \ cal chpass cksum \ - col ctags \ + col ctags cut \ dirname du \ expand \ finger from \ diff --git a/commands/cut/Makefile b/usr.bin/cut/Makefile similarity index 63% rename from commands/cut/Makefile rename to usr.bin/cut/Makefile index 1aed929ef..dea610c99 100644 --- a/commands/cut/Makefile +++ b/usr.bin/cut/Makefile @@ -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 diff --git a/commands/cut/cut.1 b/usr.bin/cut/cut.1 similarity index 87% rename from commands/cut/cut.1 rename to usr.bin/cut/cut.1 index e5827c913..a3dbf555f 100644 --- a/commands/cut/cut.1 +++ b/usr.bin/cut/cut.1 @@ -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 diff --git a/commands/cut/cut.c b/usr.bin/cut/cut.c similarity index 89% rename from commands/cut/cut.c rename to usr.bin/cut/cut.c index 15a76ff07..919d63583 100644 --- a/commands/cut/cut.c +++ b/usr.bin/cut/cut.c @@ -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 +#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 #include @@ -47,8 +58,6 @@ #include #include -#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 diff --git a/commands/cut/x_cut.c b/usr.bin/cut/x_cut.c similarity index 99% rename from commands/cut/x_cut.c rename to usr.bin/cut/x_cut.c index 3023510cf..006b5afd6 100644 --- a/commands/cut/x_cut.c +++ b/usr.bin/cut/x_cut.c @@ -58,7 +58,7 @@ /* ARGSUSED */ -static void +void CUT_FN(FILE *fp, const char *fname __unused) { CUT_CH_T ch;