Commit Graph

70 Commits

Author SHA1 Message Date
Sami Kerola 792ff9fcee
ul: make set_column() zero check more obvious
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-14 16:07:05 +00:00
Karel Zak 9210db64a6 ul: fix use of unsigned number
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-21 12:45:02 +02:00
Karel Zak 5064635395 ul: small coding changes
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-21 11:16:34 +02:00
Sami Kerola 1a3f71b292
ul: flip comparisons to lesser to greater order
1 < 2 < x < 4 is the order is the natural of values.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 21:13:25 +01:00
Sami Kerola 0186ff364d
ul: use size_t to measure memory allocation size
The size_t is the type libc memory allocation functions use.  The size_t
also provides allocation range that is enough not to a simple tool like this
to perform paranoia size checks.  Just let the realloc(3) fail if there is
not enough memory available to handle the requested line size.  That is a
lot more straightforward.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 21:13:24 +01:00
Sami Kerola 9a59ee6525
ul: improve function and variable names
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 21:13:24 +01:00
Sami Kerola 580c63259b
ul: rename enumerated mode symbols
First two are are ISO/IEC 2022 graphic character sets G0 (normal) and G1
(alternative), that one has to Switch In (SI) and Switch Out (SO).  The rest
are about how ul(1) is interacting with various text emphasis.

Reference: https://tldp.org/HOWTO/Keyboard-and-Console-HOWTO-6.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 21:12:49 +01:00
Sami Kerola 52e3ce0097
ul: remove function like putwp preprocessor define
The #ifdef HAVE_WIDECHAR can be removed, because the command already is
using wide character functions elsewhere without fallbacks.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:27 +01:00
Sami Kerola 1962d5cfca
ul: free most allocations ncurses did during setupterm()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:27 +01:00
Sami Kerola eaf68e3083
ul: replace global runtime variables with a control structure
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:27 +01:00
Sami Kerola 4942193926
ul: add a term capabilities tracking structure
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:27 +01:00
Sami Kerola a2811907e9
ul: remove function prototypes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:27 +01:00
Sami Kerola 5b627d8496
ul: tidy up coding style
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-20 20:29:27 +01:00
Rosen Penev 042f62dfc5
[clang-tidy] do not use else after return
Found with readability-else-after-return

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:20:59 -07:00
Karel Zak b8b7f4745c ul: make sure buffers are zeroized [coverity scan] 2019-05-28 13:33:03 +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
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
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
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 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 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
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
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
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
Ruediger Meier b0b24b11f8 lib: rename strmode() and setmode()
On BSD they are part of the standard C library.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-02-18 12:53:48 +01:00
Sami Kerola 97d8f180b6 ul: remove unexplained TERM=lpr override
The FIXME item has been in place since 2011-04-30, and the code has never
made sense, so remove it.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2015-01-07 21:57:53 +00: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 d07b223788 ul: fix filter() indentation
Content of the while() loop missed one indentation step.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-20 14:07:20 +02: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 67519cdd8f ul: use string printing function
Use of for loop and printing a string character by character is slower
than to print whole string with single function.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-07-09 14:25:55 +02:00
Sami Kerola aa971f7d58 ul: use correct types
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-07-09 14:25:36 +02:00
Sami Kerola 99361a9c0e ul: enhance command performance
Avoid reseting, time after time, the memory which was not used.  Effect
of the change is below in before and after timings.

$ time ./ul </etc/services >/dev/null
real    0m0.320s
user    0m0.307s
sys     0m0.010s

$ time ./ul </etc/services >/dev/null
real    0m0.068s
user    0m0.050s
sys     0m0.017s

[kzak@redhat.com: - add "else" and use maxcol]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-07-01 14:02:57 +02:00
Karel Zak a2343e0312 ul: cleanup usage() and man page
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-05 12:43:51 +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 7285104410 ul: fix shadow declaration
text-utils/ul.c:641:25: warning: declaration of 'col' shadows a global declaration [-Wshadow]
text-utils/ul.c:126:5: warning: shadowed declaration is here [-Wshadow]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-26 13:51:20 +02:00
Sami Kerola 289dcc9023 translation: unify file open error messages
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-07-16 18:18:22 +02:00
Bernhard Voelker 455fe9a075 Fix typos found by misspellings
The tool misspellings (https://github.com/lyda/misspell-check)
detected several typos. Command used:

  $ git ls-files | grep -v ^po/ | misspellings -f -

* isosize: Fix typo in usage string.
* configure.ac: Fix typo in help string of --enable-most-builds option.
* fdisk: Fix typo in man page.
* libblkid, blkid, mount: Likewise.
* Fix various typos in docs and in source code comments.

Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
2012-04-23 13:16:35 +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
Benno Schulenberg 262aee0b45 ul: remove superfluous return as usage() does not return
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2011-08-15 15:49:42 +02:00
Benno Schulenberg 293fbd7f04 ul: make usage() say that more than one input file is allowed
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2011-08-15 15:49:38 +02:00
Benno Schulenberg 055da7c5e4 ul: in usage() not overwriting but overriding is meant
Also always use lowercase.

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2011-08-15 15:49:36 +02:00
Sami Kerola 0200c80155 ul.c: warn user when command chooses term type
Happens usually when user specifies garbage as -t argument.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-17 15:58:05 +02:00
Sami Kerola a4949aaa54 ul.c: escape handling refactored
Separate function for escape handling to make switch statement
more readable.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-17 15:58:05 +02:00
Sami Kerola 78b0fdd3d7 ul.c: close files and free memory after usage
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-17 15:58:05 +02:00
Sami Kerola 565239b034 ul.c: code style and comment fixes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-17 15:58:05 +02:00
Sami Kerola 2afa872ffc ul.c: fix compier warnings
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-17 15:56:30 +02:00
Sami Kerola cc319747b5 ul.c: magic constant removal
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-05-17 15:56:30 +02:00