Commit Graph

73 Commits

Author SHA1 Message Date
Karel Zak f05593e100 column: fix greedy initialization
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak dbed2f8c63 column: add --table-colright
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak be03f65232 column: use err_exclusive_options()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 86399c3306 column: make mbs/wcs conversions more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 9dbe8e1c02 column: add --json
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 11a1092ad6 column: add --table-colnames
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 739e58ffe0 column: rename too generic macro
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 4762ae9d60 column: use libsmartcols for --table
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 8f1be58816 column: clean up multi-byte #ifelse
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 37d84d6d26 column: reorder functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak d6b63b9f1d column: rename functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 3cc2ade826 column: don't ignore mbs_to_wcs() errors
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:17:59 +02:00
Karel Zak 0784187d14 column: make input() more generic
* remove line size limit
* use multi-byte rather than wchar when read input
* prepare for future libsmartcols use in input() for table

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:17:59 +02:00
Karel Zak 2593c13998 column: use colntrol struct on more places
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:17:59 +02:00
Karel Zak 7d07df62a2 columns: add control struct
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:17:59 +02:00
Karel Zak 3e094e5fe2 column: make more obvious what is default behavior
The man page contains mistakes. The default is to fill columns before
lines:

$ printf 'aaaaaaaaaaaaaaaaaaaaaa\nBBBBBBBBBBBBBBBBBBBBB\nXXXXXXX\nYYYYYYYYYYY\nZZZZZ' > data

$ column --columns 80 < data
aaaaaaaaaaaaaaaaaaaaaa	XXXXXXX			ZZZZZ
BBBBBBBBBBBBBBBBBBBBB	YYYYYYYYYYY

$ column  --fillrows --columns 80 < data
aaaaaaaaaaaaaaaaaaaaaa	BBBBBBBBBBBBBBBBBBBBB	XXXXXXX
YYYYYYYYYYY		ZZZZZ

The patch also rename functions in the code to make it more obvious
for code readers.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-03-01 12:25:16 +01:00
Sami Kerola 2ba641e5f3 misc: add static keyword to where needed [smatch scan]
text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be
static?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Carlos Santos 9ea8ded37b build-sys: fix compilation with ncurses and uClibc or musl libc
Compiling util-linux with musl and uClibc-ng toolchains when wide-char
support is not enabled in ncurses results in compilation failures with
the following message:

    error: two or more data types in declaration specifiers
    #define
     wchar_t char

The problem occurs because util-linux #defines its own wchar_t (as char)
when configured without widechar support. This conflicts with definition
of wchar_t contained in stddef.h.

This error can be reproduced running "<toolchain-cc -o test test.c" with
the following test program:

    #include <ctype.h>
    #define wchar_t char
    #include <stddef.h>

    int main()
    {
        return 0;
    }

The only way to avoid the problem it to reorder the inclusion of headers
in some files under the text-utils directory.

Addresses:
  http://autobuild.buildroot.net/results/3a2f228e0fa7b5cc28a13d49f48f1a6aef8d9d7a
  http://autobuild.buildroot.net/results/99e96069f652d511c6212a5bb6be29e68fb1747c
  http://autobuild.buildroot.net/results/2dc5721aef93b7b410153bafad78248fac3db941
  http://autobuild.buildroot.net/results/8a9e197ba7a292b18f8c0c36dca974685556a38a

Signed-off-by: Carlos Santos <casantos@datacom.ind.br>
2017-01-20 11:07:46 +01:00
Karel Zak d7a3bf949b column: rename --columns to --output-width
* rename to use less confusing option name
* cleanup usage()
* update man page

Addresses: https://github.com/karelzak/util-linux/pull/327
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-17 13:14:05 +01:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
The current default is to print all usage() output. This is overkill
in many case.

Addresses: https://github.com/karelzak/util-linux/issues/338
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 13:13:34 +01:00
Karel Zak 683ddbd5c4 column: ignore non-printable chars
echo -e '\033[33mb\033[mXFoo\n\033[33mbar\033[mXFoo' | column -s X -t

old version:

	b   Foo
	bar   Foo

fixed version:

	b    Foo
	bar  Foo

References: https://github.com/karelzak/util-linux/issues/252
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-13 10:08:39 +01:00
Boris Egorov 43b4f7ea5f lib/tty: Pass default width to get_terminal_width()
Almost any code calling get_terminal_width() checks returned width for
non-positive values and sets it to some default value (say, 80). So,
let's pass this default value directly to the function.

[kzak@redhat.com: - get_terminal_width() refactoring]

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-01-06 12:22:07 +01:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
This adds a concise description of a tool to its usage text.

A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-06 11:27:38 +01:00
Sami Kerola f627750083 textual: use version printing macro everywhere
Only mount, umount, and blkid remains not using the macro because they
are print also library references.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:23 +02:00
Sami Kerola acb5f9b56e column: inform user when multibyte conversion error occurs
The column(1) read input until conversion error, and used incomplete
input when outputing, that made at least me to wonder where the rest
disappeared without explanation.  IMHO it is better to fail immediately
rather than do only half of the task.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-05-07 11:28:48 +02:00
Karel Zak cd70a4606a column: fix mem leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-14 17:55:05 +01:00
Sami Kerola d2b7bc74d9 column: use variable lenght printf field width to wprint blanks
This makes program to run a little faster.  My test input show about 20%
speed improvement.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-08-05 10:47:42 +02:00
Sami Kerola c630db891a column: dereference of null pointer [clang-analyzer]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-07-09 14:26:06 +02:00
Benno Schulenberg 4ce393f4d8 textual: fix several typos and angular brackets in messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-06-07 12:11:14 +02:00
Benno Schulenberg b50945d4ac textual: spell and encode the name of Arkadiusz Miśkiewicz correctly
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-02-06 11:15:02 +01:00
Sami Kerola 3eed42f342 column: make usage() translator friendly
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-01-25 16:40:05 +01:00
Sami Kerola 47bd8ddc5b column: add --output-separator option
The --output-separator option will allow user to define table column
separator.  This will allow for example to write back same delimeter as
which was used as input separator, for example

column -t -s : -o : /etc/passwd

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-10-15 16:19:35 +02:00
Pádraig Brady a38dc987ca column: clarify the --separator option
Indicate that the string is a set,
which also clarifies that it's only
significant when parsing the input.
2012-10-02 10:24:55 +02:00
Sami Kerola 732e3dec7d column: make defined separator to be non-greedy
This patch changes interpretation of subsequent delimeter interpretation.
Earlier version merged columns that had null string as content together,
which lead to output as visualized below.

$ printf "a🅱️c\n1::3\n" | column  -t -s ':'
a  b  c
1  3

The number 3 has wrong column, which this patch takes care of, and alters
the output following way.

$ printf "a🅱️c\n1::3\n" | column  -t -s ':'
a  b  c
1     3

This patch does not alter the default case, e.g., subsequent white spaces
are understood as separator of the same field, and the beginning of line
white spaces are being ignored together.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-10-02 10:24:48 +02:00
Yuri Chornoivan bbac757b1e textual: fix typos in messages 2012-09-04 17:26:31 +02:00
B Watson 43f8915c51 column: --separator segfaults
The --separator and --columns long options in util-linux-2.21.2 and in
a git clone from 5 minutes ago, don't work:

$ echo foobar | column -s x
foobar

$ echo foobar | column -c 10
foobar

$ echo foobar | column --separator=x
column: option '--separator' doesn't allow an argument

$ echo foobar | column --separator x
Segmentation fault

$ echo foobar | column --columns 10
column: bad columns width value: '(null)': Invalid argument

$ echo foobar | column --columns=10
column: option '--columns' doesn't allow an argument

Looks like a simple case of missing has_arg flag in the "struct
option" initialization for these two options. The patch just adds the
flag. I haven't done thorough testing of the patched code, but it
seems to work OK and it no longer segfaults or tries to dereference a
null pointer.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-08-14 18:27:09 +02:00
Karel Zak 3b56eea7c9 text-utils: cleanup strtoxx_or_err()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-15 17:46:20 +02:00
Sami Kerola b87cbe8486 text-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 19:45:41 +02:00
Karel Zak 5be926fac1 column: don't check result from xmalloc()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-01-04 14:29:26 +01:00
Dave Reisner cce4d25aed column: use xalloc libs
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
2012-01-04 13:53:40 +01:00
Jim Meyering 26ae00a72b column: avoid memory overrun and/or use of uninitialized buffer
* text-utils/column.c (maketbl): Use the right starting point
and the right length when zeroing new memory after xrealloc.
2011-11-16 23:51:33 +01:00
Sami Kerola 6a41edfa5b column: fix error reported by smatch
column.c:201:2: error: 'for' loop initial declarations are only allowed in C99 mode

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-09-10 16:48:12 +02:00
Karel Zak a46e644e5c column: fix problems with uninitialized variables
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-26 10:23:50 +02:00
Sami Kerola daf093d264 column.c: global variables removed
Variables from global scope are moved to main, and passed as
function arguments where ever they are needed.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-19 21:09:24 +02:00
Sami Kerola 02b77f7b2b column.c: validate numeric user inputs
Use strtol_or_err from strutils.h to check numeric user input is
sane.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-19 21:09:24 +02:00
Sami Kerola dcbca568f7 column.c: free memory before exit
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-19 21:09:24 +02:00
Sami Kerola 4eaeb0ef25 column.c: make table function clarification
Readability enchancement, and few variable type changes to be
more proper.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-19 21:09:23 +02:00
Sami Kerola 1df29104d0 column.c: coding style fixes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-01 19:15:21 +02:00
Sami Kerola 4ef21375ec column.c: add version printing
The patch makes return value to be non-zero when command line
short option is unknown.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-01 19:09:54 +02:00