Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F147909073
D50290.1784758344.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D50290.1784758344.diff
View Options
diff --git a/usr.bin/column/column.1 b/usr.bin/column/column.1
--- a/usr.bin/column/column.1
+++ b/usr.bin/column/column.1
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd July 29, 2004
+.Dd February 18, 2025
.Dt COLUMN 1
.Os
.Sh NAME
@@ -35,6 +35,7 @@
.Nm
.Op Fl tx
.Op Fl c Ar columns
+.Op Fl l Ar tblcols
.Op Fl s Ar sep
.Op Ar
.Sh DESCRIPTION
@@ -53,6 +54,14 @@
Output is formatted for a display
.Ar columns
wide.
+.It Fl l
+When used with
+.Fl t ,
+limit the table to
+.Ar tblcols
+columns in width.
+The last column will contain the rest of the line,
+including any delimiters.
.It Fl s
Specify a set of characters to be used to delimit columns for the
.Fl t
diff --git a/usr.bin/column/column.c b/usr.bin/column/column.c
--- a/usr.bin/column/column.c
+++ b/usr.bin/column/column.c
@@ -54,6 +54,7 @@
static int width(const wchar_t *);
static int termwidth = 80; /* default terminal width */
+static int tblcols; /* number of table columns for -t */
static int entries; /* number of records */
static int eval; /* exit value */
@@ -81,11 +82,14 @@
termwidth = win.ws_col;
tflag = xflag = 0;
- while ((ch = getopt(argc, argv, "c:s:tx")) != -1)
+ while ((ch = getopt(argc, argv, "c:l:s:tx")) != -1)
switch(ch) {
case 'c':
termwidth = atoi(optarg);
break;
+ case 'l':
+ tblcols = atoi(optarg);
+ break;
case 's':
src = optarg;
seplen = mbsrtowcs(NULL, &src, 0, NULL);
@@ -110,6 +114,9 @@
argc -= optind;
argv += optind;
+ if (tblcols && !tflag)
+ errx(1, "the -l flag cannot be used without the -t flag");
+
if (!*argv)
input(stdin);
else for (; *argv; ++argv)
@@ -217,7 +224,7 @@
int *lens, maxcols;
TBL *tbl;
wchar_t **cols;
- wchar_t *last;
+ wchar_t *s;
if ((t = tbl = calloc(entries, sizeof(TBL))) == NULL)
err(1, NULL);
@@ -226,9 +233,11 @@
if ((lens = calloc(maxcols, sizeof(int))) == NULL)
err(1, NULL);
for (cnt = 0, lp = list; cnt < entries; ++cnt, ++lp, ++t) {
- for (coloff = 0, p = *lp;
- (cols[coloff] = wcstok(p, separator, &last));
- p = NULL)
+ for (p = *lp; wcschr(separator, *p); ++p)
+ ;
+ for (coloff = 0; *p;) {
+ cols[coloff] = p;
+
if (++coloff == maxcols) {
if (!(cols = realloc(cols, ((u_int)maxcols +
DEFCOLS) * sizeof(wchar_t *))) ||
@@ -239,6 +248,16 @@
0, DEFCOLS * sizeof(int));
maxcols += DEFCOLS;
}
+
+ if ((!tblcols || coloff < tblcols)
+ && (s = wcspbrk(p, separator))) {
+ *s++ = L'\0';
+ while (*s && wcschr(separator, *s))
+ ++s;
+ p = s;
+ } else
+ break;
+ }
if ((t->list = calloc(coloff, sizeof(*t->list))) == NULL)
err(1, NULL);
if ((t->len = calloc(coloff, sizeof(int))) == NULL)
@@ -321,6 +340,7 @@
{
(void)fprintf(stderr,
- "usage: column [-tx] [-c columns] [-s sep] [file ...]\n");
+ "usage: column [-tx] [-c columns] [-l tblcols]"
+ " [-s sep] [file ...]\n");
exit(1);
}
diff --git a/usr.bin/column/tests/column.sh b/usr.bin/column/tests/column.sh
--- a/usr.bin/column/tests/column.sh
+++ b/usr.bin/column/tests/column.sh
@@ -144,6 +144,7 @@
::zwei
drei..
vier:
+:
END
@@ -161,10 +162,39 @@
atf_check diff expected output
}
+atf_test_case "ncols"
+ncols_head()
+{
+ atf_set descr "column(1) with -t (table) and -s and -l options"
+}
+
+ncols_body()
+{
+ cat >input <<END
+now we have five columns
+here there are four
+now only three
+just two
+one
+END
+
+ cat >expected <<END
+now we have five columns
+here there are four
+now only three
+just two
+one
+END
+
+ atf_check -o save:output column -tc120 -l3 input
+ atf_check diff expected output
+}
+
atf_init_test_cases()
{
atf_add_test_case basic
atf_add_test_case rows
atf_add_test_case basic_table
atf_add_test_case colonic_table
+ atf_add_test_case ncols
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jul 22, 10:12 PM (15 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29231877
Default Alt Text
D50290.1784758344.diff (3 KB)
Attached To
Mode
D50290: column(1): add -l flag
Attached
Detach File
Event Timeline
Log In to Comment