summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--usr.bin/cut/cut.114
-rw-r--r--usr.bin/cut/cut.c35
2 files changed, 28 insertions, 21 deletions
diff --git a/usr.bin/cut/cut.1 b/usr.bin/cut/cut.1
index fd1c92d..1b03323 100644
--- a/usr.bin/cut/cut.1
+++ b/usr.bin/cut/cut.1
@@ -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 .
diff --git a/usr.bin/cut/cut.c b/usr.bin/cut/cut.c
index 11e9513..1dfd3b0 100644
--- a/usr.bin/cut/cut.c
+++ b/usr.bin/cut/cut.c
@@ -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');
}
}
OpenPOWER on IntegriCloud