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)
Sat, Nov 23, 10:16 AM
Unknown Object (File)
Tue, Nov 19, 9:33 AM
Unknown Object (File)
Tue, Nov 19, 9:31 AM
Unknown Object (File)
Tue, Nov 19, 9:30 AM
Unknown Object (File)
Tue, Nov 19, 9:28 AM
Unknown Object (File)
Tue, Nov 19, 7:12 AM
Unknown Object (File)
Wed, Nov 13, 1:59 AM
Unknown Object (File)
Wed, Nov 13, 12:50 AM
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
662

verify if the allocation fails?

bin/sh/histedit.c
662

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
660

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

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

That's a good point, thank you.

662

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.