Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2020wk13 more more(1) changes #1003

Merged
merged 13 commits into from
Apr 14, 2020
Merged

2020wk13 more more(1) changes #1003

merged 13 commits into from
Apr 14, 2020

Conversation

kerolasa
Copy link
Member

@kerolasa kerolasa commented Apr 1, 2020

Continuation to series of more(1) changes. Notable changes in this change set are use of libmagic to identify non-textual files, removal of underlining handling that is not needed on a modern linux terminals that will handle underlining just fine, and addition of long options.

@kerolasa
Copy link
Member Author

kerolasa commented Apr 3, 2020

An additional commit more: make page and arrow up/down to update view is ready, so I added it to this pull request. Relates to discussion in #986

@kerolasa
Copy link
Member Author

kerolasa commented Apr 4, 2020

I noticed an issue in more: use single exit path [...] that caused last line be erased when it did not end to newline, and the output was directed to a pipe. That is now fixed in amended commit that I pushed moment ago.

for (opt = 0; opt < as_argc; opt++) {
int move = 0;

if (as_argv[opt][0] == '-' && isdigit(as_argv[opt][1])) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use isdigit_string() instead of isdigit()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed to use isdigit_string() in ffb1f57.

if (move) {
as_argc--;
memmove(as_argv + opt, as_argv + opt + 1, sizeof(char *) * (as_argc - opt));
opt--;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it would be better to add to include/env.h inline function remove_arg(char **arg) and use it in sanitize_env() as well as in more(1).

ssize_t i, ilen;
struct number_command cmd = { .key = more_kc_unknown_command };

if ((ilen = read(STDERR_FILENO, &input, sizeof(input))) <= 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why stderr? why not stdin?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be dealt in upcoming follow up pull request that will add up / down key commands.

return cmd;
} else if (!memcmp(input, "\x1b\x5b\x36\x7e\x00", 5)) { /* page down */
cmd.key = more_kc_skip_forward;
return cmd;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but would it be better to use getch() from ncurses and KEY_NPAGE and KEY_PPAGE (etc)? It seems strange to hardcode it to the code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing I will address in upcoming follow up. That said I will look into using getch().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, but to get getch() working more(1) would require initscr() and that will lead to terminal window. That is not how I imagine more(1). The differentiating factor of more vs less is if terminal window is used or not.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

@karelzak
Copy link
Collaborator

karelzak commented Apr 6, 2020

What about to split it to two PR, one for real clean ups and another PR for new features like the libmagic and page-up/down? :-)

kerolasa added a commit to kerolasa/util-linux that referenced this pull request Apr 12, 2020
A function to remove an command-line option argument, or environment
variable.

Requested-by: Karel Zak <kzak@redhat.com>
Reference: util-linux#1003 (comment)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
@kerolasa
Copy link
Member Author

Both libmagic and page up/down changes are removed from this pull request. They will be part of follow up sometime later.

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>
Only the terminal of the child process, that is the command being executed,
needs the reset.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
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>
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>
These functions did similar things, so there is no need for both of them.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
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>
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>
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>
Linux terminal handles underlining just fine without more executable needing
to do anything extra.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
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>
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>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
A function to remove an command-line option argument, or environment
variable.

Requested-by: Karel Zak <kzak@redhat.com>
Reference: util-linux#1003 (comment)
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
@karelzak karelzak merged commit d3c08f4 into util-linux:master Apr 14, 2020
@karelzak
Copy link
Collaborator

Thanks!

@kerolasa kerolasa deleted the 2020wk13 branch April 14, 2020 18:16
kerolasa added a commit to kerolasa/util-linux that referenced this pull request May 6, 2020
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: util-linux#1003
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
kerolasa added a commit to kerolasa/util-linux that referenced this pull request May 6, 2020
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: util-linux#1003
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
karelzak pushed a commit that referenced this pull request May 12, 2020
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: #1003
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants