Merge from NetBSD: cut.1 rev 1.6 to 1.8
cut.c rev 1.9 to 1.13 * Man page internal cleanups * 8-bit characters cast to unsigned for is*() * Misc cleanups for egcs -Wall compatibility
This commit is contained in:
parent
5183fb5330
commit
2c39ae659c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=43533
@ -41,21 +41,21 @@
|
||||
.Nm cut
|
||||
.Nd select portions of each line of a file
|
||||
.Sh SYNOPSIS
|
||||
.Nm cut
|
||||
.Nm
|
||||
.Fl b Ar list
|
||||
.Op Fl n
|
||||
.Op Ar
|
||||
.Nm cut
|
||||
.Nm ""
|
||||
.Fl c Ar list
|
||||
.Op Ar
|
||||
.Nm cut
|
||||
.Nm ""
|
||||
.Fl f Ar list
|
||||
.Op Fl d Ar delim
|
||||
.Op Fl s
|
||||
.Op Ar
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm cut
|
||||
.Nm
|
||||
utility selects portions of each line (as specified by
|
||||
.Ar list )
|
||||
from each
|
||||
@ -110,12 +110,12 @@ Unless specified, lines with no delimiters are passed through unmodified.
|
||||
.El
|
||||
.Pp
|
||||
The
|
||||
.Nm cut
|
||||
utility exits 0 on success or 1 if an error occurred.
|
||||
.Nm
|
||||
utility exits with 0 on success or 1 if an error occurred.
|
||||
.Sh SEE ALSO
|
||||
.Xr paste 1
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm cut
|
||||
.Nm
|
||||
utility conforms to
|
||||
.St -p1003.2-92 .
|
||||
|
@ -63,7 +63,8 @@ int sflag;
|
||||
void c_cut __P((FILE *, char *));
|
||||
void f_cut __P((FILE *, char *));
|
||||
void get_list __P((char *));
|
||||
static void usage __P((void));
|
||||
int main __P((int, char **));
|
||||
static void usage __P((void));
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
@ -74,6 +75,7 @@ main(argc, argv)
|
||||
void (*fcn) __P((FILE *, char *)) = NULL;
|
||||
int ch;
|
||||
|
||||
fcn = NULL;
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
dchar = '\t'; /* default delimiter is \t */
|
||||
@ -135,8 +137,8 @@ void
|
||||
get_list(list)
|
||||
char *list;
|
||||
{
|
||||
register int setautostart, start, stop;
|
||||
register char *pos;
|
||||
int setautostart, start, stop;
|
||||
char *pos;
|
||||
char *p;
|
||||
|
||||
/*
|
||||
@ -147,19 +149,19 @@ get_list(list)
|
||||
* overlapping lists. We also handle "-3-5" although there's no
|
||||
* real reason too.
|
||||
*/
|
||||
for (; (p = strsep(&list, ", \t"));) {
|
||||
for (; (p = strsep(&list, ", \t")) != NULL;) {
|
||||
setautostart = start = stop = 0;
|
||||
if (*p == '-') {
|
||||
++p;
|
||||
setautostart = 1;
|
||||
}
|
||||
if (isdigit(*p)) {
|
||||
if (isdigit((unsigned char)*p)) {
|
||||
start = stop = strtol(p, &p, 10);
|
||||
if (setautostart && start > autostart)
|
||||
autostart = start;
|
||||
}
|
||||
if (*p == '-') {
|
||||
if (isdigit(p[1]))
|
||||
if (isdigit((unsigned char)p[1]))
|
||||
stop = strtol(p + 1, &p, 10);
|
||||
if (*p == '-') {
|
||||
++p;
|
||||
@ -194,9 +196,10 @@ c_cut(fp, fname)
|
||||
FILE *fp;
|
||||
char *fname;
|
||||
{
|
||||
register int ch = 0, col;
|
||||
register char *pos;
|
||||
int ch, col;
|
||||
char *pos;
|
||||
|
||||
ch = 0;
|
||||
for (;;) {
|
||||
pos = positions + 1;
|
||||
for (col = maxval; col; --col) {
|
||||
@ -207,12 +210,13 @@ c_cut(fp, fname)
|
||||
if (*pos++)
|
||||
(void)putchar(ch);
|
||||
}
|
||||
if (ch != '\n')
|
||||
if (ch != '\n') {
|
||||
if (autostop)
|
||||
while ((ch = getc(fp)) != EOF && ch != '\n')
|
||||
(void)putchar(ch);
|
||||
else
|
||||
while ((ch = getc(fp)) != EOF && ch != '\n');
|
||||
}
|
||||
(void)putchar('\n');
|
||||
}
|
||||
}
|
||||
@ -222,8 +226,8 @@ f_cut(fp, fname)
|
||||
FILE *fp;
|
||||
char *fname;
|
||||
{
|
||||
register int ch, field, isdelim;
|
||||
register char *pos, *p, sep;
|
||||
int ch, field, isdelim;
|
||||
char *pos, *p, sep;
|
||||
int output;
|
||||
char lbuf[_POSIX2_LINE_MAX + 1];
|
||||
|
||||
@ -251,12 +255,14 @@ f_cut(fp, fname)
|
||||
(void)putchar(sep);
|
||||
while ((ch = *p++) != '\n' && ch != sep)
|
||||
(void)putchar(ch);
|
||||
} else
|
||||
while ((ch = *p++) != '\n' && ch != sep);
|
||||
} else {
|
||||
while ((ch = *p++) != '\n' && ch != sep)
|
||||
continue;
|
||||
}
|
||||
if (ch == '\n')
|
||||
break;
|
||||
}
|
||||
if (ch != '\n')
|
||||
if (ch != '\n') {
|
||||
if (autostop) {
|
||||
if (output)
|
||||
(void)putchar(sep);
|
||||
@ -264,6 +270,7 @@ f_cut(fp, fname)
|
||||
(void)putchar(ch);
|
||||
} else
|
||||
for (; (ch = *p) != '\n'; ++p);
|
||||
}
|
||||
(void)putchar('\n');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user