Commit Graph

650 Commits

Author SHA1 Message Date
Sami Kerola 508b2d79df
more: avoid defining special characters locally
The sys/ttydefaults.h can be used for CTRL() and rubout that is CERASE.  For
alarm it's best to keep things simple and call printf() alarm modifier.
QUIT was not in use, so it is just deleted.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:07 +01:00
Sami Kerola ba105bb5eb
more: use off_t and cc_t to clarify what variables attempt to represent
As a minor robustness improvement use ftello() to find out file position
rather than add and substract from old value.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:07 +01:00
Sami Kerola 437cec386f
more: do not reset parent process terminal in execute()
Only the terminal of the child process, that is the command being executed,
needs the reset.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:07 +01:00
Sami Kerola 73ff5a9561
more: use single exit path to ensure resource freeing is unified
And be a little more complete all the allocations that can be released are,
but there is a small catch.  As mentioned in ncurses FAQ some leaks are
intentional, and that's the way they are.

Reference: https://invisible-island.net/ncurses/ncurses.faq.html#config_leaks
Reference: http://man7.org/linux/man-pages/man3/_nc_free_tinfo.3x.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:13:51 +01:00
Sami Kerola 5cd4550251
more: refactor and clarify code
Use the backspace provided dy terminfo, and if that is not possible use
fallback.

Simplify entering and exiting standard mode.  Now when these std_enter and
std_exit variables are initialized correctly they do not need to be checked
quite as complex way as earlier.

Do not call prepare_line_buffer() unnecessarily.  The line buffer needs only
to be prepared only at times of more(1) initialization and when terminal
size changes.

Add a function to print various separators, that is better than static
strings.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:59 +00:00
Sami Kerola 63f96f682f
more: add display_file() to show files and stdin
Earlier main() inline code implemented input files and stdin displaying
separately.  With small restructuring this code can be shared.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:59 +00:00
Sami Kerola 22ff9a38cb
more: simplify initterm()
Return rather than use long 'else' statement.  Also unwind some overly
compact variable set and test code, that can be best observed how
underlining settings are now handled.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:59 +00:00
Sami Kerola 82129a6fca
more: move currently open file to control structure
Currently open file is needed a bit here and there.  Move it to control
structure to avoid passing it around.  This also makes fixing memory leak at
more_exit() very easy.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:59 +00:00
Sami Kerola 1f5d21ec33
more: move code blocks from more_key_command() to functions
The more_key_command() was overly long.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:58 +00:00
Sami Kerola b6818219fb
more: move runtime usage output to a function
This change also removes a ghost prompt that was left in place when printing
help.  When looking old commits the output fluke has been around at least
since util-linux v2.2.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:58 +00:00
Sami Kerola f53edc0ee6
more: restructure print_buf() if-else with continue
Replacing long 'else' with 'continue' allows dropping one level of
indentation.  Main aim is to improve code readability by reducing
complexity one needs to keep track while looking the code.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:58 +00:00
Sami Kerola f8492042f5
more: tell in run time help what the 'v' will execute as editor
In same go use well known paths from system include file.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:58 +00:00
Sami Kerola 8fb5fe304a
more: drop setuid permissions before executing anything
Pagers are not expected to have setuid or setgid bits, but assuming such
mistake has taken place try to avoid privilege escalation.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-28 07:55:58 +00:00
Sami Kerola 474c61c0a8
more: do not allocate shell command buffer from stack
This change has three possitive effects:  Avoid expansion code when it is
not needed.  Stop wasting memory from stack for something rarely needed.
When command buffer is needed stop limiting it's size artificially.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-27 21:06:08 +00:00
Sami Kerola 823ef319b6
more: replace siglongjmp() and signal() calls with signalfd()
From man siglongjmp(3) 'longjmp() and siglongjmp() make programs hard to
understand and maintain.  If possible, an alternative should be used.'  That
manual page remark summarizes quite well why more(1) needs to move away from
jumping around.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-03-27 21:06:01 +00:00
Karel Zak 5b9b6d2a74 rev: (man) add note about limitations
Addresses: https://github.com/karelzak/util-linux/issues/972
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-09 11:03:30 +01:00
Karel Zak c2e82a4aaa hexdump: fix typo, dcl instead of dc1
Addresses: https://github.com/karelzak/util-linux/issues/976
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-09 10:54:28 +01:00
Karel Zak e0e2975998 rev: report line on error
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-03-04 13:20:56 +01:00
Karel Zak f1970cc557 docs: improve size arguments description in --help output
Let's add "Arguments:" section to the --help output and describe
{K,M,G...}iB suffixes there.

Addresses: https://github.com/karelzak/util-linux/pull/917
Co-Author: ed <ed@s5h.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-02-05 11:01:36 +01:00
Bjarni Ingi Gislason 1c4c602427 man pages: Change a HYPHEN-MINUS (-) to a minus (\-) for options and numbers
Change a HYPHEN-MINUS (code 0x55, 2D) to a minus (\-), if in front of

1) a name of an option

2) a negative number to be printed.

  See man-pages(7) [Debian package "manpages"].

  The output from "nroff" is unchanged.

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
2019-12-17 12:32:43 +01:00
Bjarni Ingi Gislason eb02489380 man pages: Add a comma after "e.g." and "i.e."
Add a comma (,) after "e.g." and "i.e.", or use English words
(man-pages(7) [package "manpages"]).

  Abbreviation points should be protected (usually with the
non-printing, zero width character '\&') from being interpreted as an
end of sentence, if they are not, and that independent of their current
place on the line.

  This is important when typing, as one does not usually know in
advance when the editor jumps to a new line.

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
2019-12-17 12:32:43 +01:00
Bjarni Ingi Gislason 47da68f1c9 man pages: Make the number of .RS/.RE equal
Add or remove one of the pairs .RS/.RE to make their number equal.

  The output from "nroff" and "groff" is unchanged.

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
2019-12-17 12:32:43 +01:00
Karel Zak dc626a7586 hexdump: add header file guards [lgtm scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-20 16:13:52 +02:00
Sami Kerola 218b1dd6f9
misc: fix typos [codespell]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-09-12 19:41:46 +01:00
Karel Zak d356507207 colcrt: make seek to \n more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-09-02 11:53:10 +02:00
Sami Kerola dbeb1d733e
docs: try to find broken man references and fix them
Unfortunately methods I used to find and fix were based on quite manual
process that cannot be easily repeated so I do not see how this fix could be
turned into a tools/checkmans.sh addition.  Well, lets hope doing this
manually twice every decade is good enough.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-08-26 19:43:40 +01:00
Sami Kerola 073abd4ca8 column: pass control struct to local_wcstok()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-08-21 15:00:16 +02:00
Yousong Zhou 325bfd53e8 column: fix outputing empty column at the end of line
The following commands manifests the problem.  In old versions before
commit 4762ae9d60 ("column: use libsmartcols for --table"), both of them
should output with 2 "|"

	echo '||'  | column -o '|' -s '|' -t
	echo '|| ' | column -o '|' -s '|' -t

Fixes: 4762ae9d60 ("column: use libsmartcols for --table")
Signed-off-by: Yousong Zhou <zhouyousong@yunionyun.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
2019-07-29 10:33:58 +02:00
Karel Zak 25b7045e5d misc: replaces atexit(close_stdout) with new close_stdout_atexit()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-17 15:46:10 +02:00
Karel Zak 303ff21ea7 rev: be careful with close()
Addresses: https://github.com/karelzak/util-linux/issues/807
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-13 12:59:39 +02:00
Karel Zak b8b7f4745c ul: make sure buffers are zeroized [coverity scan] 2019-05-28 13:33:03 +02:00
Karel Zak dd45b90eef column: make code more robust [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-28 13:25:15 +02:00
Austin English 4b4a780539 column: fix "maybe be" duplication
Signed-off-by: Austin English <austinenglish@gmail.com>
2019-05-15 13:49:20 +02:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
dana 1ec4c065a2 column: Address fill-order confusion in documentation
Historical versions of column have described the default fill order as
rows-then-columns and the -x order as columns-then-rows. This was
misleading at best, and the util-linux implementation was updated to
clarify the actual behaviour in 3e094e5fe2 (March 2017).

However, the other implementations (used by *BSD, macOS, Debian, &al.)
continue to use the previous wording, and a user comparing them could
easily get the false impression that util-linux column has exactly the
opposite fill behaviour from BSD column.

To address this, a note is added to the man page explaining the change
and clarifying that, despite what the BSD documentation says, the two
implementations behave identically in this regard.

Signed-off-by: dana <dana@dana.is>
2019-02-22 14:42:58 -06:00
Karel Zak cc06250f11 col: improve error message, update regression test
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-05 18:07:26 +01:00
Karel Zak 004356f050 col: make flush_line() a little bit robust
The code is horrible. The core of the problem are signed integers
and no check for the limits.

This patch fixes c->c_column = cur_col; where c_column is "short"
and "cur_col" is int. Let's use "int" for all the variables. It's
really not perfect as for bigger lines it can segfault again...

The patch also removes some unnecessary static variables.

Addresses: https://github.com/karelzak/util-linux/issues/749
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-05 12:06:00 +01:00
Sami Kerola 577bb86f5b
hexdump: fix potential null pointer dereference warnings
First three fixes on lines 133, 151, and 280 are cosmetic.  Because there
was unobvious null check compiler thought variable might be null, and warned
when after pointer adjustment it was followed without null check.  Perhaps
this will not happen sometime in future when compiler is made more smart,
meanwhile lets give better hints to avoid false positive.

The last change addresses issue that is possible, at least in theory.

text-utils/hexdump-parse.c:465:12: warning: potential null pointer
dereference [-Wnull-dereference]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-12-10 21:48:00 +00:00
Sami Kerola 275d47c9b7
more: rename functions
This clarifies what various function calls are doing.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-09-02 18:30:12 +01:00
Sami Kerola d910f31110
more: rename variable names
Try to make variable names to tell what they do.  Earlier names have been in
more(1) since the command was first wrote, and it looks like coding
practices has changed since late 70's.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-09-02 18:28:09 +01:00
Sami Kerola 1e2cd595eb
more: remove unnecessary ifdef preprosessor directives
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-09-02 18:28:09 +01:00
Sami Kerola d2b540022b
more: do not call fileno() for std{in,out,err} streams
These file descriptor numbers are well known, use them from unistd.h

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-09-02 18:28:08 +01:00
Sami Kerola 0b735ea49e
more: remove 'register' keywords
One can only assume someone tried to make more(1) to run quicker.  More up
to date assumption is that compilers are fully capable optimizing binaries
without these sort of hints.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-09-02 18:28:08 +01:00
Sami Kerola 70824899b0
more: remove pointless functions
The curs_terminfo(3X) defines putp() as tputs(str, 1, putchar), so all of
these five functions can be replaced with putp().

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-09-02 18:28:08 +01:00
Sami Kerola f728d8baae
more: return is statement not a function
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-09-02 18:28:08 +01:00
Sami Kerola c8b1fa6046
more: remove dead code and useless comments
Removal of STOP requires explanation.  Looking unix-history-repo getline()
function in first BSD-3 version could return STOP.  By next tag BSD-4 the
return STOP had disappeared.  If I read this correctly that was a partial
removal, and second part has waited to be completed since 1980-11-16 when
BSD-4 was released.

Reference: https://github.com/dspinellis/unix-history-repo/blob/BSD-3-Snapshot-Development/usr/src/cmd/more.c#L501
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-09-02 18:28:08 +01:00
Karel Zak 2698f9ba88 column: add --table-empty-lines
The option allows to add empty line to the table. The default behavior
is to ignore empty lines at all.

echo -e "A\nAA\nAAA\n\nAAAA" | ./column --table
A
AA
AAA
AAAA

$ echo -e "A\nAA\nAAA\n\nAAAA" | ./column --table --table-empty-lines
A
AA
AAA

AAAA

Addresses: https://github.com/karelzak/util-linux/issues/593
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-23 13:34:43 +02:00
Jakub Wilk b9c3b903fe Fix man page typos
Signed-off-by: Jakub Wilk <jwilk@jwilk.net>
2018-08-16 11:09:15 +02:00
Bjarni Ingi Gislason 934a6fa80b man pages: Remove "left" (or change to "l") in the column formats of tables
A developmental version of "groff" issued a warning, for example with
"test-groff -b -e -mandoc -T utf8 -rF0 -t -w w -z":

troff: <logger.1>:299: warning: can't find font 't'

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
2018-08-06 08:58:57 +02:00
Sami Kerola bd6a253f69
more: remove function like preprocessor defines
Inlining code using preprocessor function like macros is bad for
readability, and prone to errors.  Besides this is a pager, who cares if
code is few milliseconds slower.

Requestee-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-06-18 20:19:33 +01:00
Sami Kerola 7cc31c18d7
more: remove global variables, add struct more_control
This is rather big change, but that is the only way to do this sort job.  To
keep this change relatively understandable only moves global variables to a
state structure.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-06-18 20:19:33 +01:00
Sami Kerola 82cfa6f20f
more: move couple functions
Earlier commit moved lots of functions to work without declarations, but to
be able to get rid of global variables few more moves is needed.

Reference: a8f98304e6
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-06-18 20:19:33 +01:00
Sami Kerola 25ed963d02 rev: move a global variable to local scope
Mark also file names read-only.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-28 13:36:38 +02:00
Bjarni Ingi Gislason 0bb7e904d7 man: Use the correct macro for a font change of one argument
Use the correct macro (I, B) for the font change of one argument, not
those that are used for alternating two fonts, like "BR", "IR", "RB",
or "RI".

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
2018-05-23 10:43:27 +02:00
Sami Kerola a8f98304e6 more: reorder global declarations
Group include, defines and such together, and move items inbetween functions
on top of the source file so that everything can be seen easily.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-23 10:41:46 +02:00
Sami Kerola f16ca88d9c more: remove function prototypes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-05-23 10:41:46 +02:00
Karel Zak 651c5d428c column: fix leading space characters bug
The bug has been introduced during column(1) rewrite. The function
read_input() need to skip leading space only temporary to detect empty
lines, but the rest of the code has to use the original buffer (line).
I've tried to fix one of the symptoms by 5c7b67fbbf
(alter), but this solution is unnecessary and too complex.

Changes:

* don't ignore leading space
* remove unnecessary stuff introduced by 5c7b67fbbf
* fix regression test with incorrect separator

Addresses: https://github.com/karelzak/util-linux/issues/575
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1560283
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-27 10:55:27 +02:00
ahmogit 8bd926d9fc column: update column.1
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-19 11:45:53 +01:00
Karel Zak d658091710 column: fix memory leak [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-20 14:48:26 +01:00
Karel Zak 5c7b67fbbf column: don't ignore space-char separators at begin of the line
Non-space separator:

	$ echo -e ",col1,col2\nrow,1,2" | column -t -s ","  --table-columns A,B,C
	A    B     C
	     col1  col2
	row  1     2

Space-char (\t) separator:

	$ echo -e "\tcol1\tcol2\nrow\t1\t2" | column -t -s "$(echo -e '\t')"  --table-columns A,B,C
	A     B     C
	col1  col2
	row   1     2

Fixed version:

	$ echo -e "\tcol1\tcol2\nrow\t1\t2" | column -t -s "$(echo -e '\t')"  --table-columns A,B,C
	A    B     C
	     col1  col2
	row  1     2

Addresses: https://github.com/karelzak/util-linux/issues/575
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-12 14:06:02 +01:00
Karel Zak 62fa0883be text-utils: use errexec()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-01 15:40:43 +01:00
Sami Kerola fcf841f8d3 misc: fix typos
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-11-28 14:39:13 +01:00
Karel Zak dda229c7b2 column: use \x<hex> for invalid multibyte seq.
Addresses: https://github.com/karelzak/util-linux/issues/542
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-22 14:43:36 +01:00
Karel Zak b5de9e6942 column: allow to hide unnamed columns
Addresses: https://github.com/karelzak/util-linux/pull/327
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-13 14:17:23 +01:00
Karel Zak 785e543645 column: add --table-noheadings
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-11-13 12:56:21 +01:00
Karel Zak 00e8e677e6 column: (-t) disable encoding for non-printable chars
$ echo -e '\033[34mBLUE{1\n\033[31mRED{2\n' | ./column -s '{' -t
BLUE  1
RED   2

Addresses: https://github.com/karelzak/util-linux/issues/490
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-07-31 11:48:38 +02:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
changed in include/c.h and applied via sed:

  sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
  sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 16:54:33 +02:00
Carlos Santos ccedd0d7b1 column: fix compilation when libc lacks wide-character support
Commit 4762ae9d removed mtsafe_strtok() but left behind calls to wcstok
and wcspbrk. This leads to build failures when libc does not have the
wide-character functions, like some uClibc builds.

Solve the problem by using strtok_r and strpbrk when HAVE_WIDECHAR is
not defined.

Fixes:
  http://autobuild.buildroot.net/results/fd8a1a8e0cef3aeed9588540e8e663664f6b43aa
  http://autobuild.buildroot.net/results/5ad73ea8b471321988c50d80a5e50d4504151dd6
  http://autobuild.buildroot.net/results/04411b7280dc51ecd51236967981a42352bbeb3e

Signed-off-by: Carlos Santos <casantos@datacom.ind.br>
2017-06-29 13:03:43 +02:00
Ruediger Meier b305445495 misc: consolidate all --help option descriptions
Now we are always using the same text also for commands
which had still hardcoded descriptions or where we can't
use the standard print_usage_help_options macro.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:28:36 +02:00
Ruediger Meier b1a294c448 misc: introduce print_usage_help_options()
Consolidate --help and --version descriptions. We are
now able to align them to the other options.

We changed include/c.h. The rest of this patch was
generated by sed, plus manually setting the right
alignment numbers. We do not change anything but
white spaces in the --help output.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:26:19 +02:00
Ruediger Meier 86be6a32d3 misc: cosmetics, remove argument from usage(FILE*)
This patch is trivial and changes nothing, because
we were always using usage(stdout)

Now all our usage() functions look very similar. If wanted we
could auto-generate another big cosmetical patch to remove all
the useless "FILE *out" constants and use printf and puts
rather than their f* friends. Such patch could be automatically
synchronized with the translation project (newlines!) to not
make the translators sick.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Ruediger Meier fa2cd89aca misc: cosmetics, remove argument from usage(int)
This patch is trivial and changes nothing, because
we were always using usage(0).

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Ruediger Meier 6e1eda6f22 misc: never use usage(stderr)
Here we fix all cases where we have usage(FILE*)
functions.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Ruediger Meier 9325dbfd20 misc: cleanup and fix --unknownopt issues
Fixed checkusage.sh warnings:

  rtcwake: --unknownopt, non-empty stdout

  rtcwake: --unknownopt, stderr too long: 21
  blockdev: --unknownopt, stderr too long: 28
  lsipc: --unknownopt, stderr too long: 77
  pg: --unknownopt, stderr too long: 23
  renice: --unknownopt, stderr too long: 18
  sulogin: --unknownopt, stderr too long: 17
  write: --unknownopt, stderr too long: 12

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Ruediger Meier c1da6d1eec more: add --help and --version
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 21:35:01 +02:00
Ruediger Meier 0caad87fdb misc: remove superfluous null pointer checks for optarg
This is only needed for optional arguments.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-22 02:56:57 +02:00
Ruediger Meier d0c5e5c241 more: remove unused variable
slow_tty is at least unused since util-linux 2.2.

FYI here is another derived more.c where slow_tty is still used:
https://github.com/sergev/LiteBSD/blob/master/old/more/more.c

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-15 08:55:40 +02:00
Sami Kerola f4d3783867 misc: remove stray semicolons
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 12:21:29 +02:00
Sami Kerola b1557fe981 misc: fix ggc-7 fallthrough warnings
(Original patch and commit message edited by Rudi.)

gcc-7 adds -Wimplicit-fallthrough=3 to our default flag -Wextra.
This warning can be silenced by using comment /* fallthrough */
which is also recognized by other tools like coverity. There are
also other valid comments (see man gcc-7) but we consolidate this
style now.

We could have also used __attribute__((fallthrough)) but the comment
looks nice and does not need to be ifdef'ed for compatibility.

Reference: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=7652
Reference: https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/
Reviewed-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Suggested-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-06-14 11:48:22 +02:00
Karel Zak d9eddf72a3 column: add --table-header-repeat
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-06-13 11:14:46 +02:00
Alexander Kuleshov 8bc5195be9 column: add missed semicolons in case of !HAVE_WIDECHAR
In other case we will get:

  error: expected ‘;’ before ‘}’ token

error.

Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
2017-06-01 10:56:08 +02:00
Karel Zak 3947ca4ca9 build-sys: ncurses headers cleanup
* assume ncursesw headers in ncursesw/ directory only
* prefer long paths, <term.h> and <ncurses.h> should be last
  possibility
* fix typos

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-31 11:01:46 +02:00
Karel Zak 2ac1bc84d7 text-utils: use proper paths to term.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-30 17:15:37 +02:00
Sami Kerola 2571d74382 docs: make column.1 example to use ascii output
In same go ease reading by having data and arguments in same order.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-10 10:53:28 +02:00
Sami Kerola b6b5272b03 col: avoid extra newline if no input
BSD fix missed for 22 years, and all util-linux releases so far.

Backported-from: 2a15260a2a
Addresses: https://github.com/karelzak/util-linux/issues/422
Reported-by: Pavel Raiskup <praiskup@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-10 10:53:28 +02:00
Karel Zak da06d42197 column: be robust on empty table
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-05 13:56:40 +02:00
Karel Zak cb3fdf2ae9 column: require column names for JSON
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-05 12:49:51 +02:00
Karel Zak c467fdaf80 column: use libsmartcols to avoid circular dependences
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-05 12:13:15 +02:00
Karel Zak 60102db546 column: add note that circular dependencies are ignored
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-05 11:52:04 +02:00
Karel Zak 435846ef99 column: add --tree to the man page
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-05 11:47:46 +02:00
Karel Zak b0f00a9471 column: fix --tree id-parent loop crash
The loop is silently ignored.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-05 11:31:47 +02:00
Karel Zak 960ee8e3f1 build-sys: remove column-old.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-03 10:40:46 +02:00
Karel Zak 74cc7c2515 column: parent and child has to be independent
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak bd6b5a6498 column: force to follow specified width
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 838ca70ce7 columns: add note about width
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak c728e00012 column: use NOEXTREMES for the last column
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 90852c3e12 column: add support for trees
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 236092172a column: clean up man page
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 7e947f48e7 column: clean up usage() and options order
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 166271a90b column: add --table-order
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 2483c4c9da column: fix typo
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 9624f6157c column: add --table-hide
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 68916af3b9 column: add --table-wrap
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 1ae24ec239 column: add --table-noextreme
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 3ba01db0ab column: add --table-truncate
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
Karel Zak 01e335c9e4 column: rename options
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:18:00 +02:00
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 38d691921c column: split old and new code
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-05-02 12:17:59 +02:00
Sami Kerola 70ca1a7772
tailf: remove deprecated utility
March 2017 is gone, it is time to remove this utility as scheduled in
earlier commit, and promised in manual page.

Reference: 3f8478a71c
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-04-02 16:51:00 +01:00
Sami Kerola c308e2050f misc: stop mixing declarations and code
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-03-13 14:48:04 +01: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
Grady Martin 26c91027b2
col: backspacing widechars
Until now, backspace characters have not accounted for characters of widths
other than one.  This single line amends that.

Requsted-by: Grady Martin <admin@nosuck.org>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-01-04 22:01:40 +00: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
Sébastien Helleu d673b74e9d docs: replace FTP by HTTPS in kernel.org URLs
The links to ftp://ftp.kernel.org/ are replaced by
https://www.kernel.org/.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 11:22:26 +01:00
Karel Zak 0ed2a95471 more: avoid double free() on exit
On 'q' command more(1) calls end_it() function with _exit(). The
_exit() may suspend program execution due to pending I/O on very
loaded server. In this time SIGINT may be delivered due to impatient
user who will press ^C.

And then end_it() cleanup function may be executed by signal handler
too. The result is double free()...

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1403971
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-15 14:40:26 +01:00
Michael Kerrisk (man-pages) 42632a90c1 Correctly format page cross references
Most pages in util-linux follow the standard convention
of formatting page cross references in bold. Fix the
few exceptions that use italic.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-11-29 10:44:19 +01:00
Michael Kerrisk (man-pages) f053ff1e3a Place SEE ALSO entries in order
This patch does only the following:

* Order SEE ALSO entries first by section name, then alphabetically
  within section
* Adds one or two missing commas in SEE ALSO lists
* Removes one or two periods that were (inconsistently) used
  at the end of SEE ALSO lists.

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-11-29 10:44:19 +01:00
Ruediger Meier 332123f2b6 misc: fix some compiler warnings
libsmartcols/samples/fromfile.c:59:2: warning: passing argument 3 of 'string_to_bitmask' from incompatible pointer type
  text-utils/pg.c:79:0: warning: "TABSIZE" redefined
  libblkid/src/read.c:455:13: warning: 'debug_dump_dev' defined but not used [-Wunused-function]
  libblkid/src/probe.c:769:13: warning: unused function 'cdrom_size_correction' [-Wunused-function]
  /usr/include/sys/termios.h:3:2: warning: "this file includes <sys/termios.h> which is deprecated, use <termios.h> instead" [-W#warnings]

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-10-27 11:03:24 +02:00
Tobias Stoeckmann b56b13684e rev: Avoid out of boundary read
Check if the length of the parsed string is at least 1,
otherwise an out of boundary read would occur.
2016-10-06 14:56:39 +02:00
Tobias Stoeckmann 2571cf0f9b rev: Avoid calling free in a signal handler
free() is not a safe function for a signal handler. The next
line calls _exit() anyway, so there is no need for resource
management.
2016-10-06 14:56:39 +02:00
Tobias Stoeckmann f20b214edc ul: Fix buffer overflow
The text-utility ul can run into a buffer overflow on very long lines.
See this proof of concept how to reproduce the issue:

$ dd if=/dev/zero bs=1M count=10 | tr '\000' '\041' > poc.txt
$ echo -ne '\xe\x5f\x8\x5f\x61\x2\xf\x5f\x8\x5f' | dd of=poc.txt conv=notrunc
$ ul -i poc.txt > /dev/null # output would take ages
Segmentation fault
$ _

The problem manifests by using alloca with "maxcol", which can be as
large as INT_MAX, based on the input line.

A very long line (> 8 MB) with modes must be supplied to ul, as seen in
my proof of concept byte sequence above.

It is rather easy to fix this issue: allocate space on the heap instead.
maxcol could overflow here, but in that case no system will have enough
space to handle the request, properly ending ul through an err() call.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2016-09-29 11:49:08 +02:00
Sami Kerola 74ce680a3e
misc: simplify if clauses [oclint]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-07-21 21:14:33 +01:00
Tobias Stoeckmann 3f0e7f371a tailf: Fix previously adjusted segfault patch
Casting the value to be checked to size_t renders the check useless.
If st_size is SIZE_MAX+1, it will be truncated to 0 and the check
succeeds. In fact, this check can never be false because every value
stored in a size_t is smaller or equal to SIZE_MAX.

I think this adjustment was meant to fix a compiler warning for 64 bit
systems for which sizeof(off_t) is sizeof(size_t), but the signedness
differs.

Going unconditionally to the greatest possible unsigned int type if
st_size is positive (off_t is signed) will fix this issue.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2016-07-19 11:01:18 +02:00
Tobias Stoeckmann e368476050 tailf: Fix segmentation fault in tailf on 32 bit
tailf crashes with a segmentation fault when used with a file that is
exactly 4GB in size due to an integer overflow between off_t and size_t:

$ dd if=/dev/zero of=tailf.crash bs=1 count=1 seek=4294967295
$ tailf tailf.crash
Segmentation fault
$ _

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-07-14 12:09:51 +02:00
Karel Zak 324e52a5cf more: don't include ncurses.h, fix for non-widechar
It seems our crazy widechar.h is in conflict with ncurses, but it
seems that nothing in more.c requires anything from ncurses. All we
need is probably <term.h>.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-06-03 14:51:01 +02:00
Sebastian Rasmussen 9e93004171 misc: Fix various typos
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.

Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Sebastian Rasmussen d35df4db5b docs: Fix various typos
Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
2016-05-31 23:40:21 +02:00
Sami Kerola 962a7dc3b0 colcrt: avoid the command getting hung [afl]
Some inputs make getwc(3) not to progress file descriptor and neither to
report EILSEQ.  Detect such situation and skip the bad input.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-04-13 12:29:16 +02:00
Benno Schulenberg 49b7f95e43 docs: miscellaneous tiny tweaks of man pages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2016-03-17 12:18:54 +01:00
Ruediger Meier fea1cbf748 misc: never cast void* from malloc(3) and friends
Such cast could hide serious compiler warnings in case we are
missing includes (e.g. <stdlib.h> or "xalloc.h").

See
http://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 23:29:27 +01:00
Karel Zak 8f18a9142c Merge branch 'master' of https://github.com/Rufflewind/util-linux 2016-03-07 16:04:27 +01:00
Phil Ruffwind 925ced8353 hexdump: certain long options should not accept arguments
As documented in the manual and the usage info, the long options
--one-byte-char, --canonical, and --two-bytes-octal should not accept
any arguments.

Signed-off-by: Phil Ruffwind <rf@rufflewind.com>
2016-03-06 13:47:32 -05:00