add -s option
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 2 Nov 1989 11:55:03 +0000 (03:55 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Thu, 2 Nov 1989 11:55:03 +0000 (03:55 -0800)
SCCS-vsn: usr.bin/column/column.1 5.3
SCCS-vsn: usr.bin/column/column.c 5.4

usr/src/usr.bin/column/column.1
usr/src/usr.bin/column/column.c

index aa507d5..925e37c 100644 (file)
@@ -13,7 +13,7 @@
 .\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 .\"
 .\" IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 .\"
-.\"    @(#)column.1    5.2 (Berkeley) %G%
+.\"    @(#)column.1    5.3 (Berkeley) %G%
 .\"
 .UC 7
 .TH COLUMN 1 ""
 .\"
 .UC 7
 .TH COLUMN 1 ""
@@ -21,7 +21,7 @@
 .SH NAME
 column \- columnate lists
 .SH SYNOPSIS
 .SH NAME
 column \- columnate lists
 .SH SYNOPSIS
-\fBcolumn [ \fI-tx\fB ] [\fI-c columns\fB ] [ \fIfile ...\fB ]
+\fBcolumn [ \fI\-tx\fB ] [ \fI\-s sep\fB ] [\fI\-c columns\fB ] [ \fIfile ...\fB ]
 .ft R
 .SH DESCRIPTION
 The
 .ft R
 .SH DESCRIPTION
 The
@@ -40,9 +40,17 @@ Output is formatted for a display
 .I columns
 wide.
 .TP
 .I columns
 wide.
 .TP
+.I \-s
+Specify a set of characters to be used to delimit columns for the
 .I \-t
 .I \-t
-Use the whitespace in each line to determine the number of columns
-it contains and create a table.
+option.
+.TP
+.I \-t
+Determine the number of columns the input contains and create a table.
+Columns are delimited by whitespace, by default, or by the characters
+supplied using the
+.I \-s
+option.
 Useful for pretty-printing displays, for example:
 .sp
 (printf "PERM LINKS OWNER SIZE MONTH DAY HH:MM/YEAR NAME\en";
 Useful for pretty-printing displays, for example:
 .sp
 (printf "PERM LINKS OWNER SIZE MONTH DAY HH:MM/YEAR NAME\en";
index 7888ec0..1d1170a 100644 (file)
@@ -22,7 +22,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)column.c   5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)column.c   5.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/types.h>
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -33,10 +33,11 @@ static char sccsid[] = "@(#)column.c        5.3 (Berkeley) %G%";
 
 int termwidth = 80;            /* default terminal width */
 
 
 int termwidth = 80;            /* default terminal width */
 
-char **list;                   /* array of pointers to records */
 int entries;                   /* number of records */
 int eval;                      /* exit value */
 int maxlength;                 /* longest record */
 int entries;                   /* number of records */
 int eval;                      /* exit value */
 int maxlength;                 /* longest record */
+char **list;                   /* array of pointers to records */
+char *separator = "\t ";       /* field separator for table option */
 
 main(argc, argv)
        int argc;
 
 main(argc, argv)
        int argc;
@@ -56,11 +57,14 @@ main(argc, argv)
                termwidth = win.ws_col;
 
        xflag = 0;
                termwidth = win.ws_col;
 
        xflag = 0;
-       while ((ch = getopt(argc, argv, "c:tx")) != EOF)
+       while ((ch = getopt(argc, argv, "c:s:tx")) != EOF)
                switch(ch) {
                case 'c':
                        termwidth = atoi(optarg);
                        break;
                switch(ch) {
                case 'c':
                        termwidth = atoi(optarg);
                        break;
+               case 's':
+                       separator = optarg;
+                       break;
                case 't':
                        tflag = 1;
                        break;
                case 't':
                        tflag = 1;
                        break;
@@ -187,7 +191,7 @@ maketbl()
        cols = (char **)emalloc((maxcols = DEFCOLS) * sizeof(char *));
        lens = (int *)emalloc(maxcols * sizeof(int));
        for (cnt = 0, lp = list; cnt < entries; ++cnt, ++lp, ++t) {
        cols = (char **)emalloc((maxcols = DEFCOLS) * sizeof(char *));
        lens = (int *)emalloc(maxcols * sizeof(int));
        for (cnt = 0, lp = list; cnt < entries; ++cnt, ++lp, ++t) {
-               for (coloff = 0, p = *lp; cols[coloff] = strtok(p, "\t ");
+               for (coloff = 0, p = *lp; cols[coloff] = strtok(p, separator);
                    p = NULL)
                        if (++coloff == maxcols) {
                                if (!(cols = (char **)realloc((char *)cols,
                    p = NULL)
                        if (++coloff == maxcols) {
                                if (!(cols = (char **)realloc((char *)cols,