Commit Graph

620 Commits

Author SHA1 Message Date
Sami Kerola 186946b239
man: add missing backslash to caret printing macro
Fixes: 3ea54b843c
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-28 09:53:13 +00:00
Sami Kerola 14a36f96ee
col: make input to tolerate invalid wide characters
The getwchar(3) will choke and exit if invalid character is encountered.
This change will make col(1) to print broken multibyte characters as
\x{hex} string.

Reported-by: Vitaly Lipatov <lav@etersoft.ru>
Addresses: https://github.com/karelzak/util-linux/issues/1198
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-02 22:12:32 +00:00
Sami Kerola 32a4efc567
more: improve error messaging when input file is directory
Before this change the error message about directory was not informative,
and a little bit out of place.

    $ touch empty ; ./more ./empty /
    ::::::::::::::
    ./empty
    ::::::::::::::
    magic failed: cannot read fd 4 (Is a directory)
    ::::::::::::::
    /
    ::::::::::::::

After the change messaging is reverted back to what it used to be.

    $ ./more ./empty /
    ::::::::::::::
    ./empty
    ::::::::::::::

    *** /: directory ***

And while on it lets remove repeated fstat() call.

Fixes: 09070e1a65
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-14 16:07:05 +00:00
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
Sami Kerola c7ad82209a
colrm: fix argument parsing
Short options had all sortss of characters listed, that were clearly copied
from col(1) command getopt_long() invocation.  Luckily both -V and -h were
part of the short options, but lets get rid of the unnecessary ones.

Fixes: 1647d032a7
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-14 16:06:56 +00:00
Sami Kerola 3ea54b843c
man: make tilde and caret characters to render correctly
As mentioned in 'Generating optimal glyphs' title in the manual page
mentioned in reference:

    Where a proper caret (^) that renders well in both a terminal and PDF is
    required, use "\(ha".

    Using a naked "~" character results in a poor rendering in PDF.  Instead
    use "\(ti".

Reference: https://man7.org/linux/man-pages/man7/man-pages.7.html#STYLE_GUIDE
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-14 15:22:34 +00:00
Samanta Navarro cb77628876 misc: fix typos [codespell]
Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-04 11:42:25 +00:00
Egor Chelak 1b10fa0ef7 cast NULL to char * when using execl
When calling variadic functions, NULL must be explicitly cast to a
desired type.
This is noted in the exec(3) manpage.

The call in newgrp.c was changed for consistency.

Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-10-29 19:49:07 +02: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
Sami Kerola afbf8fe223 col: fix --help short option in usage() output
The col(1) is using unusual -H as --help short option.  The -h is used for
--tabs (horizontal tab?) in this implementation.

Fixes: 62dee0176a
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-16 11:13:04 +02:00
Karel Zak 598ea3fd30 col: enable deallocation on exit also for __SANITIZE_ADDRESS__
The macro FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION does not have to
enabled in all cases (e.g. default travis-ci, local tests, ...). It
seems more robust also check for __SANITIZE_ADDRESS__ too.

Addresses: https://github.com/karelzak/util-linux/pull/1115
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-30 13:48:54 +02:00
Karel Zak 62dee0176a col: cleanup usage() and struct col_*
- remove extra line about stdout in usage() output

- use our macros to print int about --help and --version

- remove uint8_t bit-field from struct col_ctl (it seems fragile for
  future code changes).

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-29 14:20:57 +02:00
Karel Zak 18b96d7102 Merge branch 'col-refactor' of https://github.com/kerolasa/util-linux
* 'col-refactor' of https://github.com/kerolasa/util-linux:
  col: replace LINE and CHAR typedefs with structs
  col: free memory before exit [LeakSanitizer]
  col: tidy up sources a little bit
  col: add defaults to switch case clauses
  col: flip all comparisions to numerical order
  col: use size_t when dealing with numbers that buffer sizes
  col: add structure to hold line variables
  col: add update_cur_line() function
  col: add handle_not_graphic() function
  col: initialize variables when they are declared
  col: move option handling to separate function
  col: move global variables to a control structure
  col: use inline function rather than function like define
  col: use typedef and enum to clarify struct
  col: remove function prototypes
  col: add more tests
2020-09-29 13:41:00 +02:00
Lennard Hofmann f01e54d7a1 column: Deprecate --table-empty-lines in favor of --keep-empty-lines
`--table-empty-lines` gives the false impression that the option
only applies to table mode.

Signed-off-by: Lennard Hofmann <lennard.hofmann@web.de>
2020-09-29 12:38:18 +02:00
Lennard Hofmann aae0bf77bb column: Optionally keep empty lines in cols/rows mode
Signed-off-by: Lennard Hofmann <lennard.hofmann@web.de>
2020-09-29 12:38:16 +02:00
Sami Kerola 81c9867d18
col: replace LINE and CHAR typedefs with structs
Karel Zak said; typedef is evil, see reference.  I don't know are they evil,
but it is fair comment structs without hiding what is the data type is
easier and quicker understand when reading the code.

Reference: https://github.com/karelzak/util-linux/pull/1115#discussion_r481971317
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-12 23:20:18 +01:00
Sami Kerola 86c6d3ff68
col: free memory before exit [LeakSanitizer]
Clean up before exit to satisfy LeakSanitizer tests run by travis.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-12 23:19:16 +01:00
Sami Kerola 3375fd9ccf
col: tidy up sources a little bit
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-12 18:32:55 +01:00
Sami Kerola 12234f462a
col: add defaults to switch case clauses
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-12 18:32:55 +01:00
Sami Kerola e15ed08756
col: flip all comparisions to numerical order
Left side is always smaller or equal to right side.  This makes reading code
quicker when not having to constantly swap where is the greater value.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-12 18:32:54 +01:00
Sami Kerola 8f36d39294
col: use size_t when dealing with numbers that buffer sizes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-12 18:31:05 +01:00
Sami Kerola 0148d75bcd
col: add structure to hold line variables
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-12 18:27:13 +01:00
Sami Kerola 812e849eac
col: add update_cur_line() function
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-12 18:27:13 +01:00
Sami Kerola 6591d3bd6b
col: add handle_not_graphic() function
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-12 18:27:13 +01:00
Sami Kerola d38392a1e8
col: initialize variables when they are declared
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-11 20:55:02 +01:00
Sami Kerola 9f60a69217
col: move option handling to separate function
Mark --tabs and --spaces mutually exclusive in same go.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-11 20:55:02 +01:00
Sami Kerola 31a61cbedc
col: move global variables to a control structure
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-11 20:55:02 +01:00
Sami Kerola fd8270b4f2
col: use inline function rather than function like define
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-11 20:55:02 +01:00
Sami Kerola 6c5a421e09
col: use typedef and enum to clarify struct
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-11 20:55:02 +01:00
Sami Kerola f5ab4ee375
col: remove function prototypes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-11 20:55:02 +01:00
Karel Zak 42fa381b9d pg: fix wcstombs() use
The size (3rd) argument should be ignored if the 1st *dest is NULL, but it seems gcc & glibc headers
are more pedantic now:

ext-utils/pg.c:456:13: error: argument 1 is null but the corresponding size argument 3 value is 2048 [-Werror=nonnull]

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-01 11:54:07 +02:00
Karel Zak ea160a2bef column: add --table-columns-limit
$ echo -e 'AAA:BBB:CCC:DDD\n' | ./column -t -s ':'
AAA  BBB  CCC  DDD

$ echo -e 'AAA:BBB:CCC:DDD\n' | ./column -t -s ':' -l 2
AAA  BBB:CCC:DDD

$ echo -e 'AAA:BBB:CCC:DDD\n' | ./column -t -s ':' -l 3
AAA  BBB  CCC:DDD

Addresses: https://github.com/karelzak/util-linux/issues/1124
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-25 14:15:36 +02:00
Chris Hofstaedtler d0aa83147a hexdump: automatically use -C when called as hd
When invoking hexdump as hd enable the "Canonical" format to by
default, implying the -C option.

This is historic behaviour on Debian and apparently also on FreeBSD.
Some Debian users have asked for this to be restored, after Debian
switched to util-linux' hexdump and hd.

Signed-off-by: Chris Hofstaedtler <zeha@debian.org>
2020-07-23 12:23:56 +02:00
Michael Kerrisk (man-pages) 4f68c8b179 Manual pages: various: reword "allow(s) to"
The wording "allow(s) to" is not grammatical English. Reword various
pages to use a more correct form such "can be use to" or "allows
the [noun] of".

Aklong the way, fix a few nearby wording errors in some pages.

Signed-off-by: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>
2020-07-14 14:08:54 +02:00
Sami Kerola d8bfcb4cc5
col: fix output when first line does not have newline character
Commit I made while back and has been part of util-linux v2.30 to v2.35 made
col(1) not to output anything when first line did not have newline character.

    printf "gone from output" | col

This commit fixes the issue.  Admittedly the col source code is unnecessarily
hard to work with.  It could be a good idea to refactor the col(1) as low
priority task, Assuming refactoring is done the first commit to get that done
should add tests that exhaust all possible input handling including all command
line option directives.

Addresses: https://github.com/karelzak/util-linux/issues/422
Fixes: b6b5272b03
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-06-20 22:17:30 +01:00
Bjarni Ingi Gislason 960a8d1b63 doc: text-utils/*: fix some warnings from "mandoc -T lint"
mandoc: ./text-utils/column.1:58:2: WARNING: skipping paragraph macro: PP empty
mandoc: ./text-utils/column.1:63:2: WARNING: skipping paragraph macro: PP empty
mandoc: ./text-utils/column.1:119:2: WARNING: skipping paragraph macro: PP empty
mandoc: ./text-utils/column.1:171:1: WARNING: skipping paragraph macro: sp after PP
mandoc: ./text-utils/column.1:170:2: WARNING: skipping paragraph macro: PP empty

mandoc: ./text-utils/hexdump.1:206:2: WARNING: skipping paragraph macro: PP empty
mandoc: ./text-utils/hexdump.1:356:2: STYLE: fill mode already disabled, skipping: nf
mandoc: ./text-utils/hexdump.1:359:2: STYLE: fill mode already disabled, skipping: nf
mandoc: ./text-utils/hexdump.1:362:2: STYLE: fill mode already disabled, skipping: nf
mandoc: ./text-utils/hexdump.1:366:2: STYLE: fill mode already disabled, skipping: nf
mandoc: ./text-utils/hexdump.1:369:2: STYLE: fill mode already disabled, skipping: nf

####

  There are no changes in the output from "nroff" and "groff", except
for a reformat of a paragraph caused by "fill-mode".

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
2020-06-15 11:28:01 +02:00
Michael Kerrisk (man-pages) 1538f6f636 Manual pages: wording fix: "another" ==> "other"
In several pages, there is a consistent wording problem: "another"
where "other" should be used. This wording problem can be
surprisingly confusing for native speakers, especially those
unaware that in some other languages, "another" and "other" can be
expressed with the same word.

Signed-off-by: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>
2020-05-29 14:31:47 +02:00
Michael Kerrisk (man-pages) 3bc92f313a Manual pages: rename EXAMPLE section to EXAMPLES
Earlier, I patched various pages to consistently use EXAMPLE as a
section heading, rather than EXAMPLES.  (At that time, both headings
occurred in util-linux, with roughly equal frequency.)

Since then, I've observed that EXAMPLES is the more common usage
across a large corpus of manual pages. So, in Linux the man-pages
project, I switched to using EXAMPLES also. This patch makes the same
change for util-linux.

Signed-off-by: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>
2020-05-28 14:51:54 +02:00
Sami Kerola 2eb527722a more: avoid libmagic telling an empty file is binary
My earlier change that took libmagic in use to identify mime-type of an input
file caused empty files to be marked binary.  Before the change empty files
were simply displayed as empty.  This change will restore that behavior.

Addresses: 09070e1a65
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-05-25 14:16:45 +02:00