Page MenuHomeFreeBSD

sh: also auto-complete built-ins
ClosedPublic

Authored by pstef on Apr 26 2023, 8:11 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, May 13, 11:26 AM
Unknown Object (File)
Apr 26 2024, 11:19 AM
Unknown Object (File)
Apr 26 2024, 6:14 AM
Unknown Object (File)
Apr 26 2024, 4:27 AM
Unknown Object (File)
Apr 26 2024, 2:10 AM
Unknown Object (File)
Apr 26 2024, 2:07 AM
Unknown Object (File)
Apr 26 2024, 2:07 AM
Unknown Object (File)
Apr 26 2024, 2:07 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.