Age | Commit message (Collapse) | Author |
|
Thanks Michael Forney for reporting this! We cannot use identifiers
beginning with an underscore, says the C99-standard, section 7.1.3:
"All identifiers that begin with an underscore are always reserved for
use as identifiers with file scope in both the ordinary and tag name
spaces."
We go around this by putting the underscore at the end.
|
|
|
|
|
|
The (c)-symbol has become more of a remnant after the Berne convention
has been signed. Given the ISC exploits some simplifications introduced
with the Berne convention, it just makes sense to drop this relict as
well and just state our Copyright without much ado about nothing.
https://opensource.org/licenses/ISC
|
|
You never know...
|
|
|
|
The C99 standard explicitly allows to modify argc, argv, but leaves it
open what happens if you modify the content of argv. Under OpenBSD, this
actually has an effect on how the program is listed (e.g. in ps). To
prevent this, we just add a counter variable and use that for iteration.
While at it, this commit also includes a few style changes.
Thanks Hiltjo for reporting this!
|
|
We do not really parse anything, we just use/devour something.
|
|
Previously, we would return argc as -1, which could cause some problems.
This was not an issue introduced in the rewrite and is a bug present in
the "old" arg.h as well.
Thanks Isabella Parakiss for reporting this!
|
|
We decrement argc first before incrementing argv, so we never have a
state where we potentially point to uncharted territory.
|
|
This was something I wanted to do for quite a while now.
The problem with the old arg.h is that it does not allow you to call ARGF() and
EARGF() multiple times without messing the argument up. This is an
unnecessary limitation and can lead to unexpected results for people not
aware of this problem.
ARGBEGIN {
case 'a':
printf("1st call: %s\n", ARGF());
printf("2nd call: %s\n", ARGF());
break;
default:
break;
}
$ prog -a ARG
1st call: ARG
2nd call: RG
This is fixed now to properly print
$ prog -a ARG
1st call: ARG
2nd call: ARG
The old version also used more local variables than necessary, as the
problem can be reduced to one single local variable within the second
loop, which expresses if the argument has been consumed or not.
The use of abort() within EARGF() was a bit drastic. exit(1) should
suffice here and align with what you expect from an e*-type function.
Additionally, the formatting I used should make readability easier and
the code deduplication in the *ARGF()-macros helps with maintainability.
The license used is ISC, which is compatible with MIT/X, GPL and so forth in
case you want to use it in your project. I explicitly added the license header
to the file making it easy to just drop it in.
There are no plans to support the obsolete ARGNUM, ARGNUMF, LNGARG syntaxes.
|
|
|
|
No need for this when the tools don't accept arguments.
|
|
|