Page MenuHomeFreeBSD

sh: also auto-complete built-ins
ClosedPublic

Authored by pstef on Apr 26 2023, 8:11 PM.
Tags
None
Referenced Files
F102965605: D39839.diff
Tue, Nov 19, 7:12 AM
Unknown Object (File)
Wed, Nov 13, 1:59 AM
Unknown Object (File)
Wed, Nov 13, 12:50 AM
Unknown Object (File)
Mon, Nov 11, 4:43 PM
Unknown Object (File)
Tue, Nov 5, 12:37 AM
Unknown Object (File)
Mon, Oct 21, 5:03 AM
Unknown Object (File)
Oct 7 2024, 5:47 AM
Unknown Object (File)
Sep 28 2024, 4:58 PM
Subscribers

Details

Summary

Inspired by a question asked in PR 261728.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

pstef requested review of this revision.Apr 26 2023, 8:11 PM

This doesn't follow the Don't Repeat Yourself principle, but currently I don't have a better idea how to express this code.

builtincmd doesn't hold C strings, use memcmp().

bin/sh/histedit.c
664

verify if the allocation fails?

bin/sh/histedit.c
664

This part is a copy-paste from the while loop above. In each case, if strdup/strndup fails, it returns a null pointer which is assigned to matches[++i]. The next consumer of that is libedit which handles this as nice as I can imagine.

We could perhaps break the loop on allocation failure, but it's a potential microoptimization in a corner case, I think.

This doesn't follow the Don't Repeat Yourself principle, but currently I don't have a better idea how to express this code.

The code doesn't really repeat itself since there was nothing before that returned a list of builtins.

bin/sh/histedit.c
662

The MIN seems incorrect. Instead, if curpos > bp[0], it's not a match.

pstef added inline comments.
bin/sh/histedit.c
662

That's a good point, thank you.

664

I added the check both here and in the original part.

This revision is now accepted and ready to land.Apr 28 2023, 9:15 PM

Reduce code duplication.
I was worried about some repetitive code here when adding the second source of commands (built-ins, after files from $PATH), but it became visibly worse when I started working on adding a third source (aliases). So the sooner I factor this out, the cleaner the future commits will be.

This revision now requires review to proceed.Apr 29 2023, 8:48 PM
This revision is now accepted and ready to land.Jun 1 2023, 12:24 PM
This revision was automatically updated to reflect the committed changes.