Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIH: rewrite getopt #2445

Merged
merged 6 commits into from
May 30, 2020
Merged

NIH: rewrite getopt #2445

merged 6 commits into from
May 30, 2020

Conversation

bugaevc
Copy link
Member

@bugaevc bugaevc commented May 29, 2020

Fixes #91

cc @alimpfard 😉

@alimpfard
Copy link
Member

I swear, if I see the silly globals that the old getopt had, I will...do nothing...and just nag about it

#define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */
int opterr = 1;
int optopt = 0;
int optind = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OH FFS

@alimpfard
Copy link
Member

I like the idea, but can we have OptionParser not depend on the optind and co globals?
You could synchronise them at the end of getopt and getopt_long, and perhaps just keep a g_option_parser or something that tracks the global stupidity of getopt?

@bugaevc
Copy link
Member Author

bugaevc commented May 29, 2020

We could do that, but I thought that would be more boilerplate for little gain

@alimpfard
Copy link
Member

can we at least document the behaviour then?
"to reset getopt{_long,}, please set optind to 0"
or maybe call serenity_getopt_reset?

@bugaevc
Copy link
Member Author

bugaevc commented May 30, 2020

can we at least document the behaviour then?

Yes we can, and that reminds me, I forgot to write the man page, shame on me!

This causes the kernel to return EOF, which in turn confuses everything. This is
a regression from the LibVT port of VirtualConsole.
It's a bit weird to get a newline after plain text but not after, say, a URL
list.
@bugaevc
Copy link
Member Author

bugaevc commented May 30, 2020

Now with optreset and optind = 0 support, extensive man pages, colorful error messages, and misc stuff.

@bugaevc
Copy link
Member Author

bugaevc commented May 30, 2020

image

@alimpfard
Copy link
Member

alimpfard commented May 30, 2020 via email

@awesomekling awesomekling merged commit c742306 into SerenityOS:master May 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LibC: Rewrite getopt()
3 participants