From 2292a0fbefedec1f30c7492f750fe741b83985eb Mon Sep 17 00:00:00 2001 From: tjr Date: Fri, 24 May 2002 09:56:18 +0000 Subject: When a file name of "-" is given, read from standard input (SUSv3) --- usr.bin/cut/cut.1 | 9 +++++++-- usr.bin/cut/cut.c | 16 ++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'usr.bin/cut') diff --git a/usr.bin/cut/cut.1 b/usr.bin/cut/cut.1 index 65beeee..55fd456 100644 --- a/usr.bin/cut/cut.1 +++ b/usr.bin/cut/cut.1 @@ -61,8 +61,13 @@ utility selects portions of each line (as specified by .Ar list ) from each .Ar file -(or the standard input by default), and writes them to the -standard output. +and writes them to the standard output. +If no +.Ar file +arguments are specified, or a file argument is a single dash +.Pq Ql \&- , +.Nm +reads from from the standard input. The items specified by .Ar list can be in terms of column position or in terms of fields delimited diff --git a/usr.bin/cut/cut.c b/usr.bin/cut/cut.c index 12d0e83..1f67f2a 100644 --- a/usr.bin/cut/cut.c +++ b/usr.bin/cut/cut.c @@ -119,13 +119,17 @@ main(argc, argv) rval = 0; if (*argv) for (; *argv; ++argv) { - if (!(fp = fopen(*argv, "r"))) { - warn("%s", *argv); - rval = 1; - continue; + if (strcmp(*argv, "-") == 0) + fcn(stdin, "stdin"); + else { + if (!(fp = fopen(*argv, "r"))) { + warn("%s", *argv); + rval = 1; + continue; + } + fcn(fp, *argv); + (void)fclose(fp); } - fcn(fp, *argv); - (void)fclose(fp); } else fcn(stdin, "stdin"); -- cgit v1.1