Bring in use of strsep() to handle bad input better, and clean up

some text.

Obtained from:	Merge from OpenBSD
(cut.1 up to OpenBSD rev 1.3, cut.c up to OpenBSD rev 1.6)
This commit is contained in:
Eivind Eklund 1999-02-02 14:56:55 +00:00
parent d51c662504
commit 5183fb5330
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=43532
2 changed files with 8 additions and 7 deletions

View File

@ -67,11 +67,11 @@ The items specified by
can be in terms of column position or in terms of fields delimited
by a special character. Column numbering starts 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 \- ,
.Pq Sq \- ,
and a second number
and select the fields or columns from the first number to the second,
inclusive.
@ -109,8 +109,9 @@ Suppresses lines with no field delimiter characters.
Unless specified, lines with no delimiters are passed through unmodified.
.El
.Pp
.Nm Cut
exits 0 on success, 1 if an error occurred.
The
.Nm cut
utility exits 0 on success or 1 if an error occurred.
.Sh SEE ALSO
.Xr paste 1
.Sh STANDARDS

View File

@ -80,7 +80,7 @@ main(argc, argv)
/* 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)
while ((ch = getopt(argc, argv, "b:c:d:f:sn")) != -1)
switch(ch) {
case 'b':
case 'c':
@ -147,7 +147,7 @@ get_list(list)
* overlapping lists. We also handle "-3-5" although there's no
* real reason too.
*/
for (; (p = strtok(list, ", \t")); list = NULL) {
for (; (p = strsep(&list, ", \t"));) {
setautostart = start = stop = 0;
if (*p == '-') {
++p;
@ -231,7 +231,7 @@ f_cut(fp, fname)
output = 0;
for (isdelim = 0, p = lbuf;; ++p) {
if (!(ch = *p))
errx(1, "%s: line too long", fname);
errx(1, "%s: line too long.", fname);
/* this should work if newline is delimiter */
if (ch == sep)
isdelim = 1;