Skip to content

Remove getopt dependency and getopt_compat.h #995

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

Merged
merged 1 commit into from
Mar 23, 2025

Conversation

bnoordhuis
Copy link
Contributor

Remove the use of getopt() from qjsc. Parse command line arguments the same way qjs does.

As a bonus, teach the -S (stack size) option about size suffixes, just like qjs. qjsc -S 2M -o x.c x.js now works.

Copy link
Contributor Author

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

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

Left some comments. It's mostly copy/paste from qjs but I think that's okay for unexciting code like arg parsing.

Comment on lines -444 to +441
char *opt_arg = NULL;
char *optarg = NULL;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed for consistency (if you call optind optind, then call optarg optarg, amirite?)

break;
case 'n':
script_name = optarg;
while (optind < argc && *argv[optind] == '-') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Stopping on - is maybe not useful for qjsc now, but I decided to keep it for consistency with qjs.

Potentially useful in the future to bake in arguments to the compiled script somehow?

Remove the use of getopt() from qjsc. Parse command line arguments the
same way qjs does.

As a bonus, teach the -S (stack size) option about size suffixes, just
like qjs. `qjsc -S 2M -o x.c x.js` now works.
Copy link
Contributor

@saghul saghul left a comment

Choose a reason for hiding this comment

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

Nice!

@bnoordhuis bnoordhuis merged commit 8b5d525 into quickjs-ng:master Mar 23, 2025
128 checks passed
@bnoordhuis bnoordhuis deleted the rm-getopt branch March 23, 2025 13:27
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.

2 participants