summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-03-31 20:47:53 +0200
committerGitHub <[email protected]>2020-03-31 20:47:53 +0200
commit671ef006b84432744f53558435ef1c273d970403 (patch)
tree9b753a7e8c07588d175fbf2d35aae5191e7cfe17
parent86fdabc60e2791c6b93a8a893ddf7820e6f0a06f (diff)
downloadSTC-modified-671ef006b84432744f53558435ef1c273d970403.tar.gz
STC-modified-671ef006b84432744f53558435ef1c273d970403.zip
Update copt.h
-rw-r--r--ccl/copt.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/ccl/copt.h b/ccl/copt.h
index 2e3aa73c..a2351b65 100644
--- a/ccl/copt.h
+++ b/ccl/copt.h
@@ -22,10 +22,10 @@
// Inspired by https://attractivechaos.wordpress.com/2018/08/31/a-survey-of-argument-parsing-libraries-in-c-c
// Fixed major bugs with option arguments (both long and short), and shows a useful demo of the features.
-// Has a more consistent API, written in C99.
+// Has a more consistent API, added arg->err output field, written in C99.
-#ifndef CGETOPT__H__
-#define CGETOPT__H__
+#ifndef COPT__H__
+#define COPT__H__
#include <string.h>
#include <stdbool.h>
@@ -40,7 +40,7 @@ typedef struct {
int opt; // equivalent to optopt
char *arg; // equivalent to optarg
char *err; // points to the faulty option
- int longidx; // index of a long option; or -1 if short
+ int longindex; // idx of long option; or -1 if short
int _i, _pos, _nargs;
char _err[4];
} copt_t;
@@ -84,7 +84,7 @@ static int copt_getopt(copt_t *opt, int argc, char *argv[],
while (opt->_i < argc && (argv[opt->_i][0] != '-' || argv[opt->_i][1] == '\0'))
++opt->_i, ++opt->_nargs;
}
- opt->arg = 0, opt->longidx = -1, i0 = opt->_i;
+ opt->arg = 0, opt->longindex = -1, i0 = opt->_i;
if (opt->_i >= argc || argv[opt->_i][0] != '-' || argv[opt->_i][1] == '\0') {
opt->ind = opt->_i - opt->_nargs;
return -1;
@@ -109,7 +109,7 @@ static int copt_getopt(copt_t *opt, int argc, char *argv[],
if (n_exact > 1 || (n_exact == 0 && n_partial > 1)) return '?';
o = n_exact == 1? o_exact : n_partial == 1? o_partial : 0;
if (o) {
- opt->opt = optc = o->val, opt->longidx = o - longopts;
+ opt->opt = optc = o->val, opt->longindex = o - longopts;
if (o->has_arg != copt_no_argument) {
if (argv[opt->_i][j] == '=')
opt->arg = &argv[opt->_i][j + 1];