[Toybox] [PATCH] more.c: More stuff, down cursor key scrolls down. Also stuff about less

Rob Landley rob at landley.net
Thu Mar 21 14:01:52 PDT 2024


On 3/20/24 11:47, enh wrote:
> On Wed, Mar 20, 2024 at 9:38 AM Rob Landley <rob at landley.net
> <mailto:rob at landley.net>> wrote:
> 
>     On 3/20/24 00:02, Oliver Webb via Toybox wrote:
>     > I spotted the more implementation in pending. Looking at it, it's missing
>     quite a lot of stuff,
>     > Such as the ability to go back in a file.
> 
>     More never had the ability to go backwards, less did. Different command.
> 
> 
> (...but there's a lot of confusion because many modern systems have more just a
> symlink to less.)

Ooh, there's a fun edge case.

A failure mode of busybox is what if you symlink an unknown name to an existing
command, busybox says the unknown name is an unknown command. But in toybox, if
it doesn't recognize the name toybox_main loops resolving symlinks until it runs
out of them or hits a recognized name:

  // fast path: try to exec immediately.
  // (Leave toys.which null to disable suid return logic.)
  // Try dereferencing symlinks until we hit a recognized name
  while (s) {
    char *ss = basename(s);
    struct toy_list *tl = toy_find(ss);

    if (tl==toy_list && s!=toys.argv[1]) unknown(ss);
    toy_exec_which(tl, toys.argv+1);
    s = (0<readlink(s, libbuf, sizeof(libbuf))) ? libbuf : 0;
  }

So you can "ln -s sed gsed' and it should work in toybox, but not in busybox.

BUT: it stops at the first recognized name. so more -> less -> toybox would act
like more, not like less. (Unless you configured more out but left less in, then
it should behave like less.)

I note that "more" is from the days of daisy wheel teletypes, and was thus
designed to work ok without a tty or interaction through cursor keys (you can
export $COLUMNS and $LINES or just let it guess 80x25), and "less" requires a
tty and cursor keys. This might make "more" a better fit for on-screen keyboards
that don't provide cursor keys. (Or not...)

I would _like_ to have one implementation sharing code. Implementing "less -R"
cuts the behavior delta between the two, and having an option to let ctrl-c exit
less (instead of just killing the rest of the pipeline) probably gets us close
enough we to handwave the rest?

I need to genericize my watch.c code to share the cursor tracking with less.
Possibly keep a scrollback buffer. Except there's still some extension because
watch.c doesn't let you cursor left and right...

Rob


More information about the Toybox mailing list