|
From: <kin...@us...> - 2025-09-18 07:32:07
|
Revision: 7451
http://sourceforge.net/p/teem/code/7451
Author: kindlmann
Date: 2025-09-18 07:32:03 +0000 (Thu, 18 Sep 2025)
Log Message:
-----------
tweaks and moving _hestOptCheck from parseHest to methodsHest.c
Modified Paths:
--------------
teem/trunk/src/hest/methodsHest.c
teem/trunk/src/hest/parseHest.c
teem/trunk/src/hest/parsest.c
teem/trunk/src/hest/privateHest.h
Modified: teem/trunk/src/hest/methodsHest.c
===================================================================
--- teem/trunk/src/hest/methodsHest.c 2025-09-18 07:22:10 UTC (rev 7450)
+++ teem/trunk/src/hest/methodsHest.c 2025-09-18 07:32:03 UTC (rev 7451)
@@ -416,6 +416,234 @@
return NULL;
}
+/*
+_hestOptCheck() (formerly _hestPanic, in parseHest.c)
+
+This performs the validation of the given hestOpt array itself (not the command line to
+be parsed), with descriptive error messages sprintf'ed into err, if given. hestOptCheck()
+is the expected way for users to access this.
+
+Prior to 2023 code revisit; this used to set the "kind" in all the opts but now that is
+more appropriately done at the time the option is added (by hestOptAdd, hestOptAdd_nva,
+hestOptSingleSet, or hestOptAdd_*_*)
+*/
+int
+_hestOptCheck(const hestOpt *opt, char *err, const hestParm *hparm) {
+ /* see note on ME (at top) for why me[] ends with ": " */
+ static const char me[] = "_hestOptCheck: ";
+ char tbuff[AIR_STRLEN_HUGE + 1], *sep;
+ int numvar, opi, optNum;
+
+ optNum = hestOptNum(opt);
+ numvar = 0;
+ for (opi = 0; opi < optNum; opi++) {
+ if (!(AIR_IN_OP(airTypeUnknown, opt[opi].type, airTypeLast))) {
+ if (err)
+ sprintf(err, "%sopt[%d].type (%d) not in valid range [%d,%d]", ME, opi,
+ opt[opi].type, airTypeUnknown + 1, airTypeLast - 1);
+ else
+ fprintf(stderr, "%s: panic 0\n", me);
+ return 1;
+ }
+ if (!(opt[opi].valueP)) {
+ if (err)
+ sprintf(err, "%sopt[%d]'s valueP is NULL!", ME, opi);
+ else
+ fprintf(stderr, "%s: panic 0.5\n", me);
+ return 1;
+ }
+ if (-1 == opt[opi].kind) {
+ if (err)
+ sprintf(err, "%sopt[%d]'s min (%d) and max (%d) incompatible", ME, opi,
+ opt[opi].min, opt[opi].max);
+ else
+ fprintf(stderr, "%s: panic 1\n", me);
+ return 1;
+ }
+ if (5 == opt[opi].kind && !(opt[opi].sawP)) {
+ if (err)
+ sprintf(err,
+ "%shave multiple variable parameters, "
+ "but sawP is NULL",
+ ME);
+ else
+ fprintf(stderr, "%s: panic 2\n", me);
+ return 1;
+ }
+ if (airTypeEnum == opt[opi].type) {
+ if (!(opt[opi].enm)) {
+ if (err) {
+ sprintf(err,
+ "%sopt[%d] (%s) is type \"enum\", but no "
+ "airEnum pointer given",
+ ME, opi, opt[opi].flag ? opt[opi].flag : "?");
+ } else {
+ fprintf(stderr, "%s: panic 3\n", me);
+ }
+ return 1;
+ }
+ }
+ if (airTypeOther == opt[opi].type) {
+ if (!(opt[opi].CB)) {
+ if (err) {
+ sprintf(err,
+ "%sopt[%d] (%s) is type \"other\", but no "
+ "callbacks given",
+ ME, opi, opt[opi].flag ? opt[opi].flag : "?");
+ } else {
+ fprintf(stderr, "%s: panic 4\n", me);
+ }
+ return 1;
+ }
+ if (!(opt[opi].CB->size > 0)) {
+ if (err)
+ sprintf(err, "%sopt[%d]'s \"size\" (%d) invalid", ME, opi,
+ (int)(opt[opi].CB->size));
+ else
+ fprintf(stderr, "%s: panic 5\n", me);
+ return 1;
+ }
+ if (!(opt[opi].CB->type)) {
+ if (err)
+ sprintf(err, "%sopt[%d]'s \"type\" is NULL", ME, opi);
+ else
+ fprintf(stderr, "%s: panic 6\n", me);
+ return 1;
+ }
+ if (!(opt[opi].CB->parse)) {
+ if (err)
+ sprintf(err, "%sopt[%d]'s \"parse\" callback NULL", ME, opi);
+ else
+ fprintf(stderr, "%s: panic 7\n", me);
+ return 1;
+ }
+ if (opt[opi].CB->destroy && (sizeof(void *) != opt[opi].CB->size)) {
+ if (err)
+ sprintf(err,
+ "%sopt[%d] has a \"destroy\", but size %lu isn't "
+ "sizeof(void*)",
+ ME, opi, (unsigned long)(opt[opi].CB->size));
+ else
+ fprintf(stderr, "%s: panic 8\n", me);
+ return 1;
+ }
+ }
+ if (opt[opi].flag) {
+ strcpy(tbuff, opt[opi].flag);
+ if ((sep = strchr(tbuff, hparm->multiFlagSep))) {
+ *sep = '\0';
+ if (!(strlen(tbuff) && strlen(sep + 1))) {
+ if (err)
+ sprintf(err,
+ "%seither short (\"%s\") or long (\"%s\") flag"
+ " of opt[%d] is zero length",
+ ME, tbuff, sep + 1, opi);
+ else
+ fprintf(stderr, "%s: panic 9\n", me);
+ return 1;
+ }
+ if (hparm->respectDashDashHelp && !strcmp("help", sep + 1)) {
+ if (err)
+ sprintf(err,
+ "%slong \"--%s\" flag of opt[%d] is same as \"--help\" "
+ "that requested hparm->respectDashDashHelp handles separately",
+ ME, sep + 1, opi);
+ else
+ fprintf(stderr, "%s: panic 9.5\n", me);
+ return 1;
+ }
+ } else {
+ if (!strlen(opt[opi].flag)) {
+ if (err)
+ sprintf(err, "%sopt[%d].flag is zero length", ME, opi);
+ else
+ fprintf(stderr, "%s: panic 10\n", me);
+ return 1;
+ }
+ }
+ if (hparm->respectDashBraceComments
+ && (strchr(opt[opi].flag, '{') || strchr(opt[opi].flag, '}'))) {
+ if (err)
+ sprintf(err,
+ "%srequested hparm->respectDashBraceComments but opt[%d]'s flag "
+ "\"%s\" confusingly contains '{' or '}'",
+ ME, opi, opt[opi].flag);
+ else
+ fprintf(stderr, "%s: panic 10.5\n", me);
+ return 1;
+ }
+ if (4 == opt[opi].kind) {
+ if (!opt[opi].dflt) {
+ if (err)
+ sprintf(err,
+ "%sflagged single variable parameter must "
+ "specify a default",
+ ME);
+ else
+ fprintf(stderr, "%s: panic 11\n", me);
+ return 1;
+ }
+ if (!strlen(opt[opi].dflt)) {
+ if (err)
+ sprintf(err,
+ "%sflagged single variable parameter default "
+ "must be non-zero length",
+ ME);
+ else
+ fprintf(stderr, "%s: panic 12\n", me);
+ return 1;
+ }
+ }
+ /*
+ sprintf(tbuff, "-%s", opt[op].flag);
+ if (1 == sscanf(tbuff, "%f", &tmpF)) {
+ if (err)
+ sprintf(err, "%sopt[%d].flag (\"%s\") is numeric, bad news",
+ ME, op, opt[op].flag);
+ return 1;
+ }
+ */
+ }
+ if (1 == opt[opi].kind) {
+ if (!opt[opi].flag) {
+ if (err)
+ sprintf(err, "%sflags must have flags", ME);
+ else
+ fprintf(stderr, "%s: panic 13\n", me);
+ return 1;
+ }
+ } else {
+ if (!opt[opi].name) {
+ if (err)
+ sprintf(err, "%sopt[%d] isn't a flag: must have \"name\"", ME, opi);
+ else
+ fprintf(stderr, "%s: panic 14\n", me);
+ return 1;
+ }
+ }
+ if (4 == opt[opi].kind && !opt[opi].dflt) {
+ if (err)
+ sprintf(err,
+ "%sopt[%d] is single variable parameter, but "
+ "no default set",
+ ME, opi);
+ else
+ fprintf(stderr, "%s: panic 15\n", me);
+ return 1;
+ }
+ numvar += ((int)opt[opi].min < _hestMax(opt[opi].max)
+ && (NULL == opt[opi].flag)); /* HEY scrutinize casts */
+ }
+ if (numvar > 1) {
+ if (err)
+ sprintf(err, "%scan't have %d unflagged min<max opts, only one", ME, numvar);
+ else
+ fprintf(stderr, "%s: panic 16\n", me);
+ return 1;
+ }
+ return 0;
+}
+
/* experiments in adding a nixer/free-er that exactly matches the airMopper type,
as part of trying to avoid all "undefined behavior" */
void *
Modified: teem/trunk/src/hest/parseHest.c
===================================================================
--- teem/trunk/src/hest/parseHest.c 2025-09-18 07:22:10 UTC (rev 7450)
+++ teem/trunk/src/hest/parseHest.c 2025-09-18 07:32:03 UTC (rev 7451)
@@ -225,234 +225,6 @@
return newArgc;
}
-/*
-_hestOptCheck() (formerly _hestPanic)
-
-This performs the validation of the given hestOpt array itself (not the command line to
-be parsed), with descriptive error messages sprintf'ed into err, if given. hestOptCheck()
-is the expected way for users to access this.
-
-Prior to 2023 code revisit; this used to set the "kind" in all the opts but now that is
-more appropriately done at the time the option is added (by hestOptAdd, hestOptAdd_nva,
-hestOptSingleSet, or hestOptAdd_*_*)
-*/
-int
-_hestOptCheck(const hestOpt *opt, char *err, const hestParm *hparm) {
- /* see note on ME (at top) for why me[] ends with ": " */
- static const char me[] = "_hestOptCheck: ";
- char tbuff[AIR_STRLEN_HUGE + 1], *sep;
- int numvar, opi, optNum;
-
- optNum = hestOptNum(opt);
- numvar = 0;
- for (opi = 0; opi < optNum; opi++) {
- if (!(AIR_IN_OP(airTypeUnknown, opt[opi].type, airTypeLast))) {
- if (err)
- sprintf(err, "%sopt[%d].type (%d) not in valid range [%d,%d]", ME, opi,
- opt[opi].type, airTypeUnknown + 1, airTypeLast - 1);
- else
- fprintf(stderr, "%s: panic 0\n", me);
- return 1;
- }
- if (!(opt[opi].valueP)) {
- if (err)
- sprintf(err, "%sopt[%d]'s valueP is NULL!", ME, opi);
- else
- fprintf(stderr, "%s: panic 0.5\n", me);
- return 1;
- }
- if (-1 == opt[opi].kind) {
- if (err)
- sprintf(err, "%sopt[%d]'s min (%d) and max (%d) incompatible", ME, opi,
- opt[opi].min, opt[opi].max);
- else
- fprintf(stderr, "%s: panic 1\n", me);
- return 1;
- }
- if (5 == opt[opi].kind && !(opt[opi].sawP)) {
- if (err)
- sprintf(err,
- "%shave multiple variable parameters, "
- "but sawP is NULL",
- ME);
- else
- fprintf(stderr, "%s: panic 2\n", me);
- return 1;
- }
- if (airTypeEnum == opt[opi].type) {
- if (!(opt[opi].enm)) {
- if (err) {
- sprintf(err,
- "%sopt[%d] (%s) is type \"enum\", but no "
- "airEnum pointer given",
- ME, opi, opt[opi].flag ? opt[opi].flag : "?");
- } else {
- fprintf(stderr, "%s: panic 3\n", me);
- }
- return 1;
- }
- }
- if (airTypeOther == opt[opi].type) {
- if (!(opt[opi].CB)) {
- if (err) {
- sprintf(err,
- "%sopt[%d] (%s) is type \"other\", but no "
- "callbacks given",
- ME, opi, opt[opi].flag ? opt[opi].flag : "?");
- } else {
- fprintf(stderr, "%s: panic 4\n", me);
- }
- return 1;
- }
- if (!(opt[opi].CB->size > 0)) {
- if (err)
- sprintf(err, "%sopt[%d]'s \"size\" (%d) invalid", ME, opi,
- (int)(opt[opi].CB->size));
- else
- fprintf(stderr, "%s: panic 5\n", me);
- return 1;
- }
- if (!(opt[opi].CB->type)) {
- if (err)
- sprintf(err, "%sopt[%d]'s \"type\" is NULL", ME, opi);
- else
- fprintf(stderr, "%s: panic 6\n", me);
- return 1;
- }
- if (!(opt[opi].CB->parse)) {
- if (err)
- sprintf(err, "%sopt[%d]'s \"parse\" callback NULL", ME, opi);
- else
- fprintf(stderr, "%s: panic 7\n", me);
- return 1;
- }
- if (opt[opi].CB->destroy && (sizeof(void *) != opt[opi].CB->size)) {
- if (err)
- sprintf(err,
- "%sopt[%d] has a \"destroy\", but size %lu isn't "
- "sizeof(void*)",
- ME, opi, (unsigned long)(opt[opi].CB->size));
- else
- fprintf(stderr, "%s: panic 8\n", me);
- return 1;
- }
- }
- if (opt[opi].flag) {
- strcpy(tbuff, opt[opi].flag);
- if ((sep = strchr(tbuff, hparm->multiFlagSep))) {
- *sep = '\0';
- if (!(strlen(tbuff) && strlen(sep + 1))) {
- if (err)
- sprintf(err,
- "%seither short (\"%s\") or long (\"%s\") flag"
- " of opt[%d] is zero length",
- ME, tbuff, sep + 1, opi);
- else
- fprintf(stderr, "%s: panic 9\n", me);
- return 1;
- }
- if (hparm->respectDashDashHelp && !strcmp("help", sep + 1)) {
- if (err)
- sprintf(err,
- "%slong \"--%s\" flag of opt[%d] is same as \"--help\" "
- "that requested hparm->respectDashDashHelp handles separately",
- ME, sep + 1, opi);
- else
- fprintf(stderr, "%s: panic 9.5\n", me);
- return 1;
- }
- } else {
- if (!strlen(opt[opi].flag)) {
- if (err)
- sprintf(err, "%sopt[%d].flag is zero length", ME, opi);
- else
- fprintf(stderr, "%s: panic 10\n", me);
- return 1;
- }
- }
- if (hparm->respectDashBraceComments
- && (strchr(opt[opi].flag, '{') || strchr(opt[opi].flag, '}'))) {
- if (err)
- sprintf(err,
- "%srequested hparm->respectDashBraceComments but opt[%d]'s flag "
- "\"%s\" confusingly contains '{' or '}'",
- ME, opi, opt[opi].flag);
- else
- fprintf(stderr, "%s: panic 10.5\n", me);
- return 1;
- }
- if (4 == opt[opi].kind) {
- if (!opt[opi].dflt) {
- if (err)
- sprintf(err,
- "%sflagged single variable parameter must "
- "specify a default",
- ME);
- else
- fprintf(stderr, "%s: panic 11\n", me);
- return 1;
- }
- if (!strlen(opt[opi].dflt)) {
- if (err)
- sprintf(err,
- "%sflagged single variable parameter default "
- "must be non-zero length",
- ME);
- else
- fprintf(stderr, "%s: panic 12\n", me);
- return 1;
- }
- }
- /*
- sprintf(tbuff, "-%s", opt[op].flag);
- if (1 == sscanf(tbuff, "%f", &tmpF)) {
- if (err)
- sprintf(err, "%sopt[%d].flag (\"%s\") is numeric, bad news",
- ME, op, opt[op].flag);
- return 1;
- }
- */
- }
- if (1 == opt[opi].kind) {
- if (!opt[opi].flag) {
- if (err)
- sprintf(err, "%sflags must have flags", ME);
- else
- fprintf(stderr, "%s: panic 13\n", me);
- return 1;
- }
- } else {
- if (!opt[opi].name) {
- if (err)
- sprintf(err, "%sopt[%d] isn't a flag: must have \"name\"", ME, opi);
- else
- fprintf(stderr, "%s: panic 14\n", me);
- return 1;
- }
- }
- if (4 == opt[opi].kind && !opt[opi].dflt) {
- if (err)
- sprintf(err,
- "%sopt[%d] is single variable parameter, but "
- "no default set",
- ME, opi);
- else
- fprintf(stderr, "%s: panic 15\n", me);
- return 1;
- }
- numvar += ((int)opt[opi].min < _hestMax(opt[opi].max)
- && (NULL == opt[opi].flag)); /* HEY scrutinize casts */
- }
- if (numvar > 1) {
- if (err)
- sprintf(err, "%scan't have %d unflagged min<max opts, only one", ME, numvar);
- else
- fprintf(stderr, "%s: panic 16\n", me);
- return 1;
- }
- return 0;
-}
-
uint
_hestErrStrlen(const hestOpt *opt, int argc, const char **argv) {
uint ret = 0;
Modified: teem/trunk/src/hest/parsest.c
===================================================================
--- teem/trunk/src/hest/parsest.c 2025-09-18 07:22:10 UTC (rev 7450)
+++ teem/trunk/src/hest/parsest.c 2025-09-18 07:32:03 UTC (rev 7451)
@@ -184,8 +184,7 @@
airMopError(mop);
return 1;
}
- /* keep going while there's something on stack and no calls for help have been seen
- */
+ // keep going while there's something on stack and no calls for help have been seen
} while (hist->len && !(opt->helpWanted));
hestArgVecPrint(__func__, havec);
Modified: teem/trunk/src/hest/privateHest.h
===================================================================
--- teem/trunk/src/hest/privateHest.h 2025-09-18 07:22:10 UTC (rev 7450)
+++ teem/trunk/src/hest/privateHest.h 2025-09-18 07:32:03 UTC (rev 7451)
@@ -28,9 +28,9 @@
/* methodsHest.c */
extern int _hestKind(const hestOpt *opt);
extern int _hestMax(int max);
+extern int _hestOptCheck(const hestOpt *opt, char *err, const hestParm *parm);
/* parseHest.c */
-extern int _hestOptCheck(const hestOpt *opt, char *err, const hestParm *parm);
extern uint _hestErrStrlen(const hestOpt *opt, int argc, const char **argv);
#ifdef __cplusplus
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|