Page MenuHomeFreeBSD

sh: also auto-complete built-ins
ClosedPublic

Authored by pstef on Apr 26 2023, 8:11 PM.
Tags
None
Referenced Files
F109846045: D39839.id121179.diff
Mon, Feb 10, 7:03 AM
F109845947: D39839.id123435.diff
Mon, Feb 10, 7:02 AM
F109845286: D39839.id121110.diff
Mon, Feb 10, 6:53 AM
Unknown Object (File)
Sun, Feb 9, 4:17 AM
Unknown Object (File)
Thu, Feb 6, 4:04 PM
Unknown Object (File)
Sun, Jan 19, 4:24 PM
Unknown Object (File)
Dec 21 2024, 1:11 PM
Unknown Object (File)
Dec 19 2024, 11:51 AM
Subscribers

Details

Summary

Inspired by a question asked in PR 261728.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

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
671

verify if the allocation fails?

bin/sh/histedit.c
671

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
669

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

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

That's a good point, thank you.

671

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.