Commit Graph

563 Commits

Author SHA1 Message Date
Sami Kerola 1f861935a7 more: make page and arrow up/down to update view
Aim was to introduce page and arrow up/down keys to more(1), but that
also required merging colon_command() and more_key_command() functions.

The more_key_commands enum is pointless from computers point of view.
The command identification performed in read_command() inline with
more_key_command() execution -- but that would be hard for humans, and
source code ought to serve both parties.

Reference: https://github.com/karelzak/util-linux/pull/1003
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-05-12 10:22:09 +02:00
Sami Kerola 09070e1a65 more: use libmagic to identify binary files
As the old commend said: 'This code would best be shared with the file(1)
program or, perhaps, more should not try to be so smart'.  Now at configure
time one can choose whether more(1) is sharing code with file(1), or not.

Addresses: http://bugs.debian.org/139205
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-05-12 10:22:09 +02:00
Rosen Penev ad296391f9
[clang-tidy] fix wrong *cmp usage
Found with bugprone-suspicious-string-compare

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-20 13:21:00 -07: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
Rosen Penev bd89499e07
[clang-tidy] do not return in void functions
Found with readability-redundant-control-flow

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-04-19 14:03:21 -07:00
Sami Kerola ed292a08dd
include: add remove_entry() to env.h
A function to remove an command-line option argument, or environment
variable.

Requested-by: Karel Zak <kzak@redhat.com>
Reference: https://github.com/karelzak/util-linux/pull/1003#discussion_r403988092
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:08 +01:00
Sami Kerola 837f49c6bf
more: fix moving backwards so that it can reach begining of the file
Moving backwards has worked fine until reaching start of file.  At that
point more printout had one line too much in output causing more seemingly
never to be able to reach the start.  That is now fixed, with clean ups to
skip_backwards() making it less confusing.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:08 +01:00
Sami Kerola e3cb27f535
more: use getopt_long() to parse options
This commit also includes fix to how initial skip lines and search are
instructed in the code.  Earlier version was pretty close impossible to make
work with getopt_long() and had minor flaw - if both initial skip lines and
search were defined at the same time the skipping did not happen.  That is
now corrected.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:08 +01:00
Sami Kerola 94bece3c22
more: remove underlining related code
Linux terminal handles underlining just fine without more executable needing
to do anything extra.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:08 +01:00
Sami Kerola 6dcaaa9ef5
more: fix SIGSTOP and SIGCONT handling
When suspending only the more process.  Sending signal to process group
makes signal destination unnecessarily vague.  After the suspend is over
SIGCONT is expected, and it needs to ensure output terminal settings are
what more needs.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:07 +01:00
Sami Kerola c366ebc7ef
more: make execute() more robust and timely
The wait() is now a little more robust by being more tolerate rogue SIGCHLDs
and unblocked signals.  The repeated fork() and sleep() is removed, if first
try does not success give up without delay to provide user timely feedback.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:07 +01:00
Sami Kerola f3c044eeed
more: target all standard streams when calling fflush()
If streams need to be flushed do not try to be clever, just flush all of
them.  That lead to finding unnecessary print out in run_shell() that is
removed in this commit.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:07 +01:00
Sami Kerola 21d096239c
more: remove kill_line() in favor of erase_prompt()
These functions did similar things, so there is no need for both of them.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-04-13 12:14:07 +01:00
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