Merge from NetBSD cut.1 rev 1.6 and cut.c rev 1.9, respectively. This

makes us conform to IEEE Std1003.2-1992 (``POSIX.2'').

Obtained from:	NetBSD (but with slight modifications).
This commit is contained in:
Eivind Eklund 1999-02-02 14:26:39 +00:00
parent bb25f0dd23
commit d51c662504
2 changed files with 26 additions and 7 deletions

View File

@ -42,13 +42,17 @@
.Nd select portions of each line of a file .Nd select portions of each line of a file
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm cut .Nm cut
.Fl b Ar list
.Op Fl n
.Op Ar
.Nm cut
.Fl c Ar list .Fl c Ar list
.Ar .Op Ar
.Nm cut .Nm cut
.Fl f Ar list .Fl f Ar list
.Op Fl d Ar delim .Op Fl d Ar delim
.Op Fl s .Op Fl s
.Ar .Op Ar
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Nm cut .Nm cut
@ -81,6 +85,10 @@ 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
The
.Ar list
specifies byte positions.
.It Fl c Ar list .It Fl c Ar list
The The
.Ar list .Ar list
@ -94,6 +102,8 @@ The
.Ar list .Ar list
specifies fields, delimited in the input by a single tab character. specifies fields, delimited in the input by a single tab character.
Output fields are separated by a single tab character. Output fields are separated by a single tab character.
.It Fl n
Do not split multi-byte characters.
.It Fl s .It Fl s
Suppresses lines with no field delimiter characters. Suppresses 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.
@ -106,5 +116,5 @@ exits 0 on success, 1 if an error occurred.
.Sh STANDARDS .Sh STANDARDS
The The
.Nm cut .Nm cut
utility is expected to conform to utility conforms to
.St -p1003.2 . .St -p1003.2-92 .

View File

@ -48,6 +48,7 @@ static const char sccsid[] = "@(#)cut.c 8.3 (Berkeley) 5/4/95";
#include <err.h> #include <err.h>
#include <errno.h> #include <errno.h>
#include <limits.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>
@ -73,10 +74,15 @@ main(argc, argv)
void (*fcn) __P((FILE *, char *)) = NULL; void (*fcn) __P((FILE *, char *)) = NULL;
int ch; int ch;
setlocale (LC_ALL, "");
dchar = '\t'; /* default delimiter is \t */ dchar = '\t'; /* default delimiter is \t */
while ((ch = getopt(argc, argv, "c:d:f:s")) != -1) /* 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")) != EOF)
switch(ch) { switch(ch) {
case 'b':
case 'c': case 'c':
fcn = c_cut; fcn = c_cut;
get_list(optarg); get_list(optarg);
@ -94,6 +100,8 @@ main(argc, argv)
case 's': case 's':
sflag = 1; sflag = 1;
break; break;
case 'n':
break;
case '?': case '?':
default: default:
usage(); usage();
@ -263,8 +271,9 @@ f_cut(fp, fname)
static void static void
usage() usage()
{ {
(void)fprintf(stderr, "%s\n%s\n", (void)fprintf(stderr, "%s\n%s\n%s\n",
"usage: cut -c list [file1 ...]", "usage: cut -b list [-n] [file ...]",
" cut -c list [file ...]",
" cut -f list [-s] [-d delim] [file ...]"); " cut -f list [-s] [-d delim] [file ...]");
exit(1); exit(1);
} }