[Toybox] Slow grep

Rob Landley rob at landley.net
Fri Sep 30 20:42:10 PDT 2022


On 9/30/22 10:38, enh wrote:
>     Also, I checked in the start of the sed/tar xform protocol stuff. It's not
>     handling flags yet, but it's passing the data so it _can_ do so. (I didn't want
>     to send you a tar/sed pair that had to be upgraded in tandem and then changed
>     AGAIN later. Hopefully this is the usable protocol version...)
> 
> i'll wait for an "all clear" before i poke further :-)

The code is easy. Writing the test cases is...

Did you know the gnu/dammit tar developers made --no-recursion positional? It
even warns!

$ tar c uno uno/{dos,tres,quatro} --no-recursion | tar tv
tar: The following options were used after any non-optional arguments in archive
create or update mode.  These options are positional and affect only arguments
that follow them.  Please, rearrange them properly.
tar: --no-recursion has no effect
tar: Exiting with failure status due to previous errors
drwxr-xr-x landley/landley   0 2022-09-30 03:14 uno/
-rw-r--r-- landley/landley   7 2022-09-30 03:14 uno/cinco
-rw-r--r-- landley/landley   0 2022-09-30 02:34 uno/quatro
lrwxrwxrwx landley/landley   0 2022-09-30 02:34 uno/dos -> tres
hrw-r--r-- landley/landley   0 2022-09-30 02:34 uno/tres link to uno/quatro
hrwxrwxrwx landley/landley   0 2022-09-30 02:34 uno/dos link to uno/dos
hrw-r--r-- landley/landley   0 2022-09-30 02:34 uno/tres link to uno/quatro
hrw-r--r-- landley/landley   0 2022-09-30 02:34 uno/quatro link to uno/quatro

(Which, since it completed successfully and the pipeline ate the return code and
my initial test redirected stderr to null I didn't notice until just now. But
apparently they designed an API that people get wrong often enough to add a
warning about. Sigh of a good user interface design, that.)

The toybox one is not positional. I could MAKE it positional. I've got
toys.argv[] and can perform rubber hose cryptography after the fact if I really
NEED more info. It's only moderately horrific:

void comfy_chair(struct double_list *soft_cushions[2])
{
  int i, j, type;

  for (i = j = type = 0; toys.argv[i]; i++) {
    if (!strcmp(toys.argv[i], "--")) type |= 2;
    else if (type<2 && !strcmp(toys.argv[i], "--no-recursion")) type = 1;
    else if (type<2 && !strcmp(toys.argv[i], "--recursion")) type = 0;
    else if (!strcmp(toys.optargs[j], toys.argv[i]))
      dlist_add(soft_cushions+(type&1), toys.optargs[j++]);
  }
}

I just really don't _want_ to, because ew. (The above quick and dirty off the
top of my head code doesn't handle the longopt abbreviation matching, which I
could do with strstart relying on the initial parsing pass to have errored out
about ambiguous matches, but I am not compile testing this email.)

Again, wait for somebody to complain...

Rob


More information about the Toybox mailing list