|
From: <kin...@us...> - 2025-09-18 20:39:54
|
Revision: 7456
http://sourceforge.net/p/teem/code/7456
Author: kindlmann
Date: 2025-09-18 20:39:52 +0000 (Thu, 18 Sep 2025)
Log Message:
-----------
(work is ongoing on a hestParse re-write, but also this:)
API CHANGE:
rename hestParm->respFileEnable --> responseFileEnable
rename hestDefaultRespFileEnable --> hestDefaultResponseFileEnable
because it was inconsistent to have that "response" abbreviated,
when the pattern in hest has long bin to write out long things with whole words.
ALSO API CHANGE:
removing fields from hestParm in hest.h:
char respFileFlag, /* the character at the beginning of an argument
indicating that this is a response file name */
respFileComment, /* comment character for the response files */
varParamStopFlag, /* prefixed by '-' to form the flag (usually "--") that signals the
end of a *flagged* variable parameter option (single or
multiple). This is important to use if there is a flagged
variable parameter option preceeding an unflagged variable
parameter option, because otherwise how will you know where the
first stops and the second begins */
multiFlagSep; /* character in flag which signifies that there is a long and short
version, and which separates the two. Or, can be set to '\0' to
disable this behavior entirely. */
and removing the corresponding defaults:
HEST_EXPORT char hestDefaultRespFileFlag;
HEST_EXPORT char hestDefaultRespFileComment;
HEST_EXPORT char hestDefaultVarParamStopFlag;
HEST_EXPORT char hestDefaultMultiFlagSep;
Why the change: there is more confusion than utility created by allowing these
special characters change. The actual value in giving these things names was in
code legibility by removing magic constants. That's now the role of some new
#defines in privateHest.h.
Modified Paths:
--------------
teem/trunk/src/bin/ilk.c
teem/trunk/src/bin/miter.c
teem/trunk/src/bin/mrender.c
teem/trunk/src/bin/puller.c
teem/trunk/src/hest/argvHest.c
teem/trunk/src/hest/defaultsHest.c
teem/trunk/src/hest/hest.h
teem/trunk/src/hest/methodsHest.c
teem/trunk/src/hest/parseHest.c
teem/trunk/src/hest/parsest.c
teem/trunk/src/hest/privateHest.h
teem/trunk/src/hest/test/tparse.c
teem/trunk/src/hest/usage.c
teem/trunk/src/ten/tendBfit.c
teem/trunk/src/ten/tendGlyph.c
teem/trunk/src/unrrdu/join.c
teem/trunk/src/unrrdu/make.c
teem/trunk/src/unrrdu/shuffle.c
Modified: teem/trunk/src/bin/ilk.c
===================================================================
--- teem/trunk/src/bin/ilk.c 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/bin/ilk.c 2025-09-18 20:39:52 UTC (rev 7456)
@@ -57,7 +57,7 @@
hparm->elideSingleOtherType = AIR_TRUE;
hparm->elideSingleOtherDefault = AIR_FALSE;
hparm->elideMultipleNonExistFloatDefault = AIR_TRUE;
- hparm->respFileEnable = AIR_TRUE;
+ hparm->responseFileEnable = AIR_TRUE;
hestParmColumnsIoctl(hparm, hestDefaultColumns);
hestOptAdd_1_Other(&hopt, "i", "image", &nin, "-", "input image", nrrdHestNrrd);
Modified: teem/trunk/src/bin/miter.c
===================================================================
--- teem/trunk/src/bin/miter.c 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/bin/miter.c 2025-09-18 20:39:52 UTC (rev 7456)
@@ -50,7 +50,7 @@
airMopAdd(mop, muu, (airMopper)miteUserNix, airMopAlways);
hparm->respectDashDashHelp = AIR_TRUE;
- hparm->respFileEnable = AIR_TRUE;
+ hparm->responseFileEnable = AIR_TRUE;
hparm->elideMultipleNonExistFloatDefault = AIR_TRUE;
hestOptAdd_1_Other(&hopt, "i", "nsin", &(muu->nsin), "",
"input scalar volume to render", nrrdHestNrrd);
Modified: teem/trunk/src/bin/mrender.c
===================================================================
--- teem/trunk/src/bin/mrender.c 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/bin/mrender.c 2025-09-18 20:39:52 UTC (rev 7456)
@@ -453,7 +453,7 @@
mop = airMopNew();
hparm = hestParmNew();
airMopAdd(mop, hparm, (airMopper)hestParmFree, airMopAlways);
- hparm->respFileEnable = AIR_TRUE;
+ hparm->responseFileEnable = AIR_TRUE;
hparm->respectDashDashHelp = AIR_TRUE;
uu = mrendUserNew();
airMopAdd(mop, uu, (airMopper)mrendUserNix, airMopAlways);
Modified: teem/trunk/src/bin/puller.c
===================================================================
--- teem/trunk/src/bin/puller.c 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/bin/puller.c 2025-09-18 20:39:52 UTC (rev 7456)
@@ -74,7 +74,7 @@
nPosOut = nrrdNew();
airMopAdd(mop, nPosOut, (airMopper)nrrdNuke, airMopAlways);
- hparm->respFileEnable = AIR_TRUE;
+ hparm->responseFileEnable = AIR_TRUE;
hparm->respectDashDashHelp = AIR_TRUE;
me = argv[0];
Modified: teem/trunk/src/hest/argvHest.c
===================================================================
--- teem/trunk/src/hest/argvHest.c 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/hest/argvHest.c 2025-09-18 20:39:52 UTC (rev 7456)
@@ -21,6 +21,7 @@
#include "privateHest.h"
#include <assert.h>
+#include <sys/errno.h>
#define INCR 32
@@ -32,7 +33,7 @@
void **v;
} hestPtrPtrUnion;
-/* ---------------------- hestArg = harg = hestArg = harg ------------------ */
+/* -------------------------- hestArg = harg = hestArg = harg ---------------------- */
/* dereferences as char *, sets to '\0' */
static void
@@ -110,7 +111,7 @@
return;
}
-/* ------------------ hestArgVec = havec = hestArgVec = havec -------------- */
+/* ---------------------- hestArgVec = havec = hestArgVec = havec ------------------ */
hestArgVec *
hestArgVecNew() {
@@ -150,7 +151,7 @@
printf("\n");
}
-/* --------------------- hestInput = hin = hestInput = hin ----------------- */
+/* ------------------------- hestInput = hin = hestInput = hin --------------------- */
static void
hinInit(void *_hin) {
@@ -160,8 +161,8 @@
hin->argc = 0;
hin->argv = NULL;
hin->argIdx = 0;
- hin->fname = NULL;
- hin->file = NULL;
+ hin->rfname = NULL;
+ hin->rfile = NULL;
hin->dashBraceComment = 0;
return;
}
@@ -190,6 +191,8 @@
return NULL;
}
+/* ------------------- hestInputStack = hist = hestInputStack = hist --------------- */
+
hestInputStack *
hestInputStackNew(void) {
hestInputStack *hist = AIR_CALLOC(1, hestInputStack);
@@ -200,6 +203,7 @@
hppu.hin = &(hist->hin);
hist->hinArr = airArrayNew(hppu.v, &(hist->len), sizeof(hestInput), INCR);
airArrayStructCB(hist->hinArr, hinInit, hinDone);
+ hist->stdinRead = AIR_FALSE;
return hist;
}
@@ -211,11 +215,17 @@
return NULL;
}
+#define ME ((hparm && hparm->verbosity) ? me : "")
+
int
hestInputStackPushCommandLine(hestInputStack *hist, int argc, const char **argv,
char *err, const hestParm *hparm) {
- assert(hist);
- AIR_UNUSED(err);
+ static const char me[] = "hestInputStackPushCommandLine: ";
+ if (!(hist && argv && hparm)) { // (as if all this can go wrong but err is non-NULL)
+ sprintf(err, "%s: got NULL pointer (hist %p, argv %p, hparm %p)", __func__,
+ AIR_VOIDP(hist), AIR_VOIDP(argv), AIR_VOIDP(hparm));
+ return 1;
+ }
if (hparm->verbosity) {
printf("%s: changing stack height: %u --> %u with argc=%d,argv=%p; "
"setting argIdx to 0\n",
@@ -223,7 +233,7 @@
}
uint idx = airArrayLenIncr(hist->hinArr, 1);
if (hparm->verbosity > 1) {
- printf("%s: new hinTop = %p\n", __func__, AIR_VOIDP(hist->hin + idx));
+ printf("%snew hinTop = %p\n", ME, AIR_VOIDP(hist->hin + idx));
}
hist->hin[idx].source = hestSourceCommandLine;
hist->hin[idx].argc = argc;
@@ -233,6 +243,58 @@
}
int
+hestInputStackPushResponseFile(hestInputStack *hist, const char *rfname, char *err,
+ const hestParm *hparm) {
+ static const char me[] = "hestInputStackPushResponseFile: ";
+ if (!(hist && rfname && hparm)) {
+ sprintf(err, "%s: got NULL pointer (hist %p, rfname %p, hparm %p)", __func__,
+ AIR_VOIDP(hist), AIR_VOIDP(rfname), AIR_VOIDP(hparm));
+ return 1;
+ }
+ if (!strlen(rfname)) {
+ sprintf(err,
+ "%ssaw arg start with response file flag \"%c\" "
+ "but no filename followed",
+ ME, RESPONSE_FILE_FLAG);
+ return 1;
+ }
+ // "- 1" safe because hestParse always starts with argc/argv, not a response file
+ uint topHinIdx = hist->len - 1;
+ // have we seen rfname before?
+ for (uint hidx = 0; hidx < topHinIdx; hidx++) {
+ hestInput *oldHin = hist->hin + hidx;
+ if (hestSourceResponseFile == oldHin->source //
+ && !strcmp(oldHin->rfname, rfname)) {
+ // HEY test this error
+ sprintf(err, "%salready currently reading \"%s\" as response file", ME, rfname);
+ return 1;
+ }
+ }
+ // are we trying to read stdin twice?
+ if (!strcmp("-", rfname) && hist->stdinRead) {
+ // HEY test this error
+ sprintf(err, "%sresponse filename \"%s\" but previously read stdin", ME, rfname);
+ return 1;
+ }
+ // try to open response file
+ FILE *rfile = airFopen(rfname, stdin, "r");
+ if (!(rfile)) {
+ // HEY test this error
+ sprintf(err, "%scouldn't fopen(\"%s\",\"r\"): %s", ME, rfname, strerror(errno));
+ return 1;
+ }
+ // okay, we actually opened the response file; put it on the stack
+ uint idx = airArrayLenIncr(hist->hinArr, 1);
+ if (hparm->verbosity > 1) {
+ printf("%snew hinTop = %p\n", ME, AIR_VOIDP(hist->hin + idx));
+ }
+ hist->hin[idx].source = hestSourceResponseFile;
+ hist->hin[idx].rfname = rfname;
+ hist->hin[idx].rfile = rfile;
+ return 0;
+}
+
+int
hestInputStackPop(hestInputStack *hist, char *err, const hestParm *hparm) {
assert(hist);
uint len = hist->hinArr->len;
Modified: teem/trunk/src/hest/defaultsHest.c
===================================================================
--- teem/trunk/src/hest/defaultsHest.c 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/hest/defaultsHest.c 2025-09-18 20:39:52 UTC (rev 7456)
@@ -21,7 +21,7 @@
#include "privateHest.h"
int hestDefaultVerbosity = 0;
-int hestDefaultRespFileEnable = AIR_FALSE;
+int hestDefaultResponseFileEnable = AIR_FALSE;
unsigned int hestDefaultColumns = 79;
int hestDefaultElideSingleEnumType = AIR_FALSE;
int hestDefaultElideSingleOtherType = AIR_FALSE;
@@ -33,7 +33,3 @@
int hestDefaultNoArgsIsNoProblem = AIR_FALSE;
int hestDefaultGreedySingleString = AIR_TRUE;
int hestDefaultCleverPluralizeOtherY = AIR_FALSE;
-char hestDefaultRespFileFlag = '@';
-char hestDefaultRespFileComment = '#';
-char hestDefaultVarParamStopFlag = '-';
-char hestDefaultMultiFlagSep = ',';
Modified: teem/trunk/src/hest/hest.h
===================================================================
--- teem/trunk/src/hest/hest.h 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/hest/hest.h 2025-09-18 20:39:52 UTC (rev 7456)
@@ -174,7 +174,7 @@
*/
typedef struct {
int verbosity, /* verbose diagnostic messages to stdout */
- respFileEnable, /* whether or not to use response files */
+ responseFileEnable, /* whether or not to use response files */
elideSingleEnumType, /* if type is airTypeEnum, and if it's a single fixed parameter
option, then don't bother printing the type information as
part of hestGlossary() */
@@ -212,18 +212,6 @@
might: only print info and glossary when they "ask for it" */
noBlankLineBeforeUsage; /* like it says */
unsigned int columns; /* number of printable columns in output */
- char respFileFlag, /* the character at the beginning of an argument
- indicating that this is a response file name */
- respFileComment, /* comment character for the response files */
- varParamStopFlag, /* prefixed by '-' to form the flag (usually "--") that signals the
- end of a *flagged* variable parameter option (single or
- multiple). This is important to use if there is a flagged
- variable parameter option preceeding an unflagged variable
- parameter option, because otherwise how will you know where the
- first stops and the second begins */
- multiFlagSep; /* character in flag which signifies that there is a long and short
- version, and which separates the two. Or, can be set to '\0' to
- disable this behavior entirely. */
} hestParm;
/*
@@ -267,8 +255,8 @@
const char **argv; // we do NOT own
unsigned int argIdx;
// ------ if source == hestSourceResponseFile ------
- char *fname; // we do NOT own
- FILE *file; // someone opened this for us
+ const char *rfname; // we do NOT own: points into an argv or a hestArg
+ FILE *rfile; // user opens and closes this
// ------ general for all inputs ------
unsigned int dashBraceComment; /* not a boolean: how many -{ }- comment levels
deep are we currently; tracked this way to
@@ -279,11 +267,12 @@
hestInput *hin; // array of hestInputs
unsigned int len;
airArray *hinArr;
+ int stdinRead; // while processing this stack we have read in "-" aka stdin
} hestInputStack;
// defaultsHest.c
HEST_EXPORT int hestDefaultVerbosity;
-HEST_EXPORT int hestDefaultRespFileEnable;
+HEST_EXPORT int hestDefaultResponseFileEnable;
HEST_EXPORT int hestDefaultElideSingleEnumType;
HEST_EXPORT int hestDefaultElideSingleOtherType;
HEST_EXPORT int hestDefaultElideSingleOtherDefault;
@@ -295,10 +284,6 @@
HEST_EXPORT int hestDefaultGreedySingleString;
HEST_EXPORT int hestDefaultCleverPluralizeOtherY;
HEST_EXPORT unsigned int hestDefaultColumns;
-HEST_EXPORT char hestDefaultRespFileFlag;
-HEST_EXPORT char hestDefaultRespFileComment;
-HEST_EXPORT char hestDefaultVarParamStopFlag;
-HEST_EXPORT char hestDefaultMultiFlagSep;
// argvHest.c
HEST_EXPORT hestArg *hestArgNew(void);
@@ -316,6 +301,8 @@
HEST_EXPORT int hestInputStackPushCommandLine(hestInputStack *hist, int argc,
const char **argv, char *err,
const hestParm *hparm);
+HEST_EXPORT int hestInputStackPushResponseFile(hestInputStack *hist, const char *rfname,
+ char *err, const hestParm *hparm);
HEST_EXPORT int hestInputStackPop(hestInputStack *hist, char *err,
const hestParm *hparm);
Modified: teem/trunk/src/hest/methodsHest.c
===================================================================
--- teem/trunk/src/hest/methodsHest.c 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/hest/methodsHest.c 2025-09-18 20:39:52 UTC (rev 7456)
@@ -70,7 +70,7 @@
hparm = AIR_CALLOC(1, hestParm);
assert(hparm);
hparm->verbosity = hestDefaultVerbosity;
- hparm->respFileEnable = hestDefaultRespFileEnable;
+ hparm->responseFileEnable = hestDefaultResponseFileEnable;
hparm->elideSingleEnumType = hestDefaultElideSingleEnumType;
hparm->elideSingleOtherType = hestDefaultElideSingleOtherType;
hparm->elideSingleOtherDefault = hestDefaultElideSingleOtherDefault;
@@ -106,10 +106,11 @@
hparm->dieLessVerbose = AIR_FALSE;
hparm->noBlankLineBeforeUsage = AIR_FALSE;
hparm->columns = hestDefaultColumns;
- hparm->respFileFlag = hestDefaultRespFileFlag;
- hparm->respFileComment = hestDefaultRespFileComment;
- hparm->varParamStopFlag = hestDefaultVarParamStopFlag;
- hparm->multiFlagSep = hestDefaultMultiFlagSep;
+ // see note in privateHest.h about the removal of these
+ // hparm->responseFileFlag = hestDefaultRespFileFlag;
+ // hparm->responseFileComment = hestDefaultRespFileComment;
+ // hparm->varParamStopFlag = hestDefaultVarParamStopFlag;
+ // hparm->multiFlagSep = hestDefaultMultiFlagSep;
return hparm;
}
@@ -534,7 +535,7 @@
}
if (opt[opi].flag) {
strcpy(tbuff, opt[opi].flag);
- if ((sep = strchr(tbuff, hparm->multiFlagSep))) {
+ if ((sep = strchr(tbuff, MULTI_FLAG_SEP))) {
*sep = '\0';
if (!(strlen(tbuff) && strlen(sep + 1))) {
if (err)
Modified: teem/trunk/src/hest/parseHest.c
===================================================================
--- teem/trunk/src/hest/parseHest.c 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/hest/parseHest.c 2025-09-18 20:39:52 UTC (rev 7456)
@@ -55,7 +55,7 @@
*argsNumP = 0;
*respFileNumP = 0;
- if (!hparm->respFileEnable) {
+ if (!hparm->responseFileEnable) {
/* don't do response files; we're done */
return 0;
}
@@ -62,7 +62,7 @@
argIdx = 0;
while (argv /* can be NULL for testing */ && argv[argIdx]) {
- if (hparm->respFileFlag == argv[argIdx][0]) {
+ if (RESPONSE_FILE_FLAG == argv[argIdx][0]) {
/* argv[argIdx] looks like its naming a response file */
/* NOTE: despite the repeated temptation: "-" aka stdin cannot be a response file,
because it is going to be read in twice: once by argsInResponseFiles, and then
@@ -79,7 +79,7 @@
len = airOneLine(file, line, AIR_STRLEN_HUGE + 1);
while (len > 0) {
/* first # (or #-alike char) is turned into line end */
- if ((pound = strchr(line, hparm->respFileComment))) {
+ if ((pound = strchr(line, RESPONSE_FILE_COMMENT))) {
*pound = '\0';
}
/* count words in line */
@@ -123,10 +123,9 @@
'#' character is considered to mark the beginning of a comment, EVEN IF THAT '#' is
inside a string. Sorry. (This is why hest parsing is being re-written ...)
-For a brief moment in 2023, this also stopped if it saw "--" (or whatever
-parm->varParamStopFlag implies), but that meant "--" is a brick wall that hestParse could
-never see past. But that misunderstands the relationship between how hestParse works and
-how the world uses "--". According to POSIX guidelines:
+For a brief moment in 2023, this also stopped if it saw "--", but that meant "--" is a
+brick wall that hestParse could never see past. But that misunderstands the relationship
+between how hestParse works and how the world uses "--". According to POSIX guidelines:
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_01
the elements of argv can be first "options" and then "operands", where "options" are
indicated by something starting with '-', and may have 0 or more "option-arguments".
@@ -182,7 +181,7 @@
oldArgv[argIdx]);
printArgv(newArgc, newArgv, " ");
}
- if (!hparm->respFileEnable || hparm->respFileFlag != oldArgv[argIdx][0]) {
+ if (!hparm->responseFileEnable || RESPONSE_FILE_FLAG != oldArgv[argIdx][0]) {
/* either ignoring response files, or its not a response file:
we copy the arg, remember to free it, and increment the new arg idx */
newArgv[newArgc] = airStrdup(oldArgv[argIdx]);
@@ -198,7 +197,7 @@
unsigned rgi;
if (hparm->verbosity) printf("%s: line: |%s|\n", me, line);
/* HEY HEY too bad for you if you put # inside a string */
- if ((pound = strchr(line, hparm->respFileComment))) *pound = '\0';
+ if ((pound = strchr(line, RESPONSE_FILE_COMMENT))) *pound = '\0';
if (hparm->verbosity) printf("%s: -0-> line: |%s|\n", me, line);
airOneLinify(line);
incr = airStrntok(line, AIR_WHITESPACE);
@@ -261,13 +260,13 @@
static char *
identStr(char *ident, const hestOpt *opt, const hestParm *hparm, int brief) {
char copy[AIR_STRLEN_HUGE + 1], *sep;
-
- if (opt->flag && (sep = strchr(opt->flag, hparm->multiFlagSep))) {
+ AIR_UNUSED(hparm);
+ if (opt->flag && (sep = strchr(opt->flag, MULTI_FLAG_SEP))) {
strcpy(copy, opt->flag);
- sep = strchr(copy, hparm->multiFlagSep);
+ sep = strchr(copy, MULTI_FLAG_SEP);
*sep = '\0';
if (brief)
- sprintf(ident, "-%s%c--%s option", copy, hparm->multiFlagSep, sep + 1);
+ sprintf(ident, "-%s%c--%s option", copy, MULTI_FLAG_SEP, sep + 1);
else
sprintf(ident, "-%s option", copy);
} else {
@@ -282,8 +281,8 @@
given a string in "flag" (with the hypen prefix) finds which of the options in the given
array of options has the matching flag. Returns the index of the matching option, or -1
-if there is no match, but returns -2 if the flag is the end-of-parameters marker "--" (or
-whatever parm->varParamStopFlag implies)
+if there is no match, but returns -2 if the flag is the end-of-parameters marker "--"
+(and only "--", due to VAR_PARM_STOP_FLAG)
*/
static int
whichOptFlag(const hestOpt *opt, const char *flag, const hestParm *hparm) {
@@ -300,9 +299,9 @@
printf("%s: optIdx %d |%s| ?\n", me, optIdx,
opt[optIdx].flag ? opt[optIdx].flag : "(nullflag)");
if (!opt[optIdx].flag) continue;
- if (strchr(opt[optIdx].flag, hparm->multiFlagSep)) {
+ if (strchr(opt[optIdx].flag, MULTI_FLAG_SEP)) {
strcpy(copy, opt[optIdx].flag);
- sep = strchr(copy, hparm->multiFlagSep);
+ sep = strchr(copy, MULTI_FLAG_SEP);
*sep = '\0';
/* first try the short version */
sprintf(buff, "-%s", copy);
@@ -317,10 +316,10 @@
}
}
if (hparm->verbosity) printf("%s: (b) optNum = %d\n", me, optNum);
- if (hparm->varParamStopFlag) {
- sprintf(buff, "-%c", hparm->varParamStopFlag);
+ if (VAR_PARM_STOP_FLAG) {
+ sprintf(buff, "-%c", VAR_PARM_STOP_FLAG);
if (hparm->verbosity)
- printf("%s: does maybe-is-flag |%s| == -parm->varParamStopFlag |%s| ?\n", me, flag,
+ printf("%s: does maybe-is-flag |%s| == -VAR_PARM_STOP_FLAG |%s| ?\n", me, flag,
buff);
if (!strcmp(flag, buff)) {
if (hparm->verbosity) printf("%s: yes, it does! returning -2\n", me);
@@ -352,7 +351,7 @@
if (hparm) {
stops[0] = '-';
- stops[1] = hparm->varParamStopFlag;
+ stops[1] = VAR_PARM_STOP_FLAG;
stops[2] = '\0';
} /* else stops stays as empty string */
@@ -417,9 +416,9 @@
The sawP information is not set here, since it is better set at value parsing time, which
happens after defaults are enstated.
-This is where, thanks to the action of whichOptFlag(), "--" (or whatever
-parm->varParamStopFlag implies) is used as a marker for the end of a *flagged* variable
-parameter option. AND, the "--" marker is removed from the argv.
+This is where, thanks to the action of whichOptFlag(), "--" (and only "--" due to
+VAR_PARM_STOP_FLAG) is used as a marker for the end of a *flagged* variable parameter
+option. AND, the "--" marker is removed from the argv.
*/
static int
extractFlagged(char **optParms, unsigned int *optParmNum, int *optAprd, int *argcP,
@@ -488,8 +487,7 @@
sprintf(err,
"%ssaw \"-%c\" (option-parameter-stop flag) before getting %d "
"parameter%s for %s (got %d)",
- ME, hparm->varParamStopFlag, opt[optIdx].min,
- opt[optIdx].min > 1 ? "s" : "",
+ ME, VAR_PARM_STOP_FLAG, opt[optIdx].min, opt[optIdx].min > 1 ? "s" : "",
identStr(ident2, opt + optIdx, hparm, AIR_FALSE), parmNum);
}
return 1;
@@ -1407,10 +1405,10 @@
/* currently, any left-over arguments indicate error */
if (argc_used) {
- /* char stops[3] = {'-', HPARM->varParamStopFlag, '\0'}; triggers warning:
+ /* char stops[3] = {'-', VAR_PARM_STOP_FLAG, '\0'}; triggers warning:
initializer element is not computable at load time */
char stops[3] = "-X";
- stops[1] = HPARM->varParamStopFlag;
+ stops[1] = VAR_PARM_STOP_FLAG;
if (strcmp(stops, argv[0])) {
sprintf(err, "%sunexpected arg%s: \"%s\"", ME,
('-' == argv[0][0] ? " (or unrecognized flag)" : ""), argv[0]);
Modified: teem/trunk/src/hest/parsest.c
===================================================================
--- teem/trunk/src/hest/parsest.c 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/hest/parsest.c 2025-09-18 20:39:52 UTC (rev 7456)
@@ -20,8 +20,10 @@
#include "hest.h"
#include "privateHest.h"
-/* parse, parser, parsest: this aims to be the final implmentation of hestParse */
+/* parse, parser, parsest: may this be the final implmentation of hestParse */
+#include <assert.h>
+
/* A little trickery for error reporting. For many of the functions here, if they hit an
error and hparm->verbosity is set, then we should reveal the current function name (set
by convention in `me`). But without verbosity, we hide that function name, so it appears
@@ -39,64 +41,77 @@
histProc(hestArgVec *havec, int *helpWantedP, hestInputStack *hist, char *err,
const hestParm *hparm) {
static const char me[] = "histProc: ";
- int ret = 0;
int popAtEnd = AIR_FALSE;
*helpWantedP = AIR_FALSE; // may over-write later
- hestInput *hinTop = hist->hin + (hist->len - 1);
- switch (hinTop->source) {
+ hestInput *theHin = hist->hin + hist->len - 1;
+ switch (theHin->source) {
case hestSourceDefault: // ---------------------------------
- sprintf(err, "%ssorry hestSourceDefault not implemented\n", ME);
- ret = 1;
+ sprintf(err, "%ssorry hestSourceDefault not implemented", ME);
+ return 1;
break;
case hestSourceCommandLine: // ---------------------------------
- /* argv[] 0 1 2 3 (argc=4) */
- /* cmd arg1 arg2 arg3 */
+ // argv[] 0 1 2 3 (argc=4)
+ // cmd arg1 arg2 arg3
if (hparm->verbosity > 1) {
- printf("%shist->len=%u -> hinTop=%p\n", me, hist->len, AIR_VOIDP(hinTop));
+ printf("%shist->len=%u -> theHin=%p\n", me, hist->len, AIR_VOIDP(theHin));
}
- if (hinTop->argIdx < hinTop->argc) {
- /* there are args left to parse */
- const char *thisArgv = hinTop->argv[hinTop->argIdx];
+ if (theHin->argIdx < theHin->argc) {
+ // there are args left to parse
+ uint thisArgIdx = theHin->argIdx;
+ const char *theArg = theHin->argv[thisArgIdx];
if (hparm->verbosity > 1) {
- printf("%slooking at argv[%u] |%s|\n", me, hinTop->argIdx, thisArgv);
+ printf("%slooking at argv[%u] |%s|\n", me, theHin->argIdx, theArg);
}
- hinTop->argIdx++;
- if (hparm->respectDashBraceComments && !strcmp("-{", thisArgv)) {
+ theHin->argIdx++;
+ // process theArg we just acquired
+ if (hparm->respectDashBraceComments && !strcmp("-{", theArg)) {
// start of -{ }- commenting (or increase in nesting level)
- hinTop->dashBraceComment += 1;
+ theHin->dashBraceComment += 1;
}
- if (!hinTop->dashBraceComment) {
- hestArgVecAppendString(havec, thisArgv);
+ if (theHin->dashBraceComment) {
+ if (hparm->verbosity > 1) {
+ printf("%sskipping commented-out |%s|\n", me, theArg);
+ }
+ } else {
+ // not commenting out thisArg
+ if (!hparm->responseFileEnable || theArg[0] != RESPONSE_FILE_FLAG) {
+ // not a response file, just an arg
+ hestArgVecAppendString(havec, theArg);
+ } else {
+ /* theArg is asking to be a response file; try pushing it. With or without an
+ error, we return early because there's nothing more for us to do */
+ return hestInputStackPushResponseFile(hist, theArg + 1, err, hparm);
+ }
}
- if (hparm->respectDashBraceComments && !strcmp("}-", thisArgv)) {
- if (hinTop->dashBraceComment) {
- hinTop->dashBraceComment -= 1;
+ if (hparm->respectDashBraceComments && !strcmp("}-", theArg)) {
+ if (theHin->dashBraceComment) {
+ theHin->dashBraceComment -= 1;
} else {
sprintf(err, "%send comment arg \"}-\" not balanced by prior \"-{\"", ME);
- ret = 1;
+ return 1;
}
}
- }
- if (hinTop->argIdx == hinTop->argc) {
+ } // NOT else
+ if (theHin->argIdx == theHin->argc) {
// we have gotten to the end of the given argv array */
- if (hinTop->dashBraceComment) {
+ if (theHin->dashBraceComment) {
sprintf(err, "%sstart comment arg \"-{\" not balanced by later \"}-\"", ME);
- ret = 1;
+ return 1;
} else {
popAtEnd = AIR_TRUE;
- // but don't pop now because we need to check for --help
+ // but don't pop now because we still need to check for --help
}
}
break;
case hestSourceResponseFile: // ---------------------------------
- sprintf(err, "%ssorry hestSourceResponseFile not implemented\n", ME);
- ret = 1;
+ sprintf(err, "%ssorry hestSourceResponseFile not implemented", ME);
+ return 1;
break;
}
/* when processing command-line or response file, check for --help
(it makes no sense for --help to appear in a default string) */
- if (hestSourceResponseFile == hinTop->source
- || hestSourceCommandLine == hinTop->source) {
+ if (hestSourceResponseFile == theHin->source
+ || hestSourceCommandLine == theHin->source) {
const hestArg *hlast;
if (hparm->respectDashDashHelp // watching for "--help"
&& havec->len // have at least one arg
@@ -107,10 +122,10 @@
}
if (popAtEnd) {
if (hestInputStackPop(hist, err, hparm)) {
- ret = 1;
+ return 1;
}
}
- return ret;
+ return 0;
}
int
Modified: teem/trunk/src/hest/privateHest.h
===================================================================
--- teem/trunk/src/hest/privateHest.h 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/hest/privateHest.h 2025-09-18 20:39:52 UTC (rev 7456)
@@ -21,7 +21,31 @@
extern "C" {
#endif
-#include <assert.h>
+// pre-TeemV2, these used to be change-able defaults in defaultsHest.c:
+// char hestDefaultRespFileFlag = '@';
+// char hestDefaultRespFileComment = '#';
+// char hestDefaultVarParamStopFlag = '-';
+// char hestDefaultMultiFlagSep = ',';
+// with corresponding fields in the hestParm defined in hest.h
+// char respFileFlag, /* the character at the beginning of an argument
+// indicating that this is a response file name */
+// respFileComment, /* comment character for the response files */
+// varParamStopFlag, /* prefixed by '-' to form the flag (usually "--") that signals
+// the end of a *flagged* variable parameter option (single or
+// multiple). This is important to use if there is a flagged
+// variable parameter option preceeding an unflagged variable
+// parameter option, because otherwise how will you know where
+// the first stops and the second begins */
+// multiFlagSep; /* character in flag which signifies that there is a long and
+// short version, and which separates the two. Or, can be set
+// to '\0' to disable this behavior entirely. */
+// However, there is more confusion than utility created by allowing these
+// change. The actual value in giving these things names was in code legibility by
+// removing magic constants, so that's the role of these #define's now.
+#define RESPONSE_FILE_FLAG '@'
+#define RESPONSE_FILE_COMMENT '#'
+#define VAR_PARM_STOP_FLAG '-'
+#define MULTI_FLAG_SEP ','
typedef unsigned int uint;
Modified: teem/trunk/src/hest/test/tparse.c
===================================================================
--- teem/trunk/src/hest/test/tparse.c 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/hest/test/tparse.c 2025-09-18 20:39:52 UTC (rev 7456)
@@ -33,6 +33,7 @@
hestOpt *opt = NULL;
hestParm *hparm = hestParmNew();
hparm->respectDashDashHelp = AIR_TRUE;
+ hparm->respFileEnable = AIR_TRUE;
int res[2];
hestOptAdd_2_Int(&opt, "res", "sx sy", res, NULL, "image resolution");
int flag;
Modified: teem/trunk/src/hest/usage.c
===================================================================
--- teem/trunk/src/hest/usage.c 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/hest/usage.c 2025-09-18 20:39:52 UTC (rev 7456)
@@ -26,13 +26,12 @@
static void
_hestSetBuff(char *B, const hestOpt *O, const hestParm *P, int showshort, int showlong) {
char copy[AIR_STRLEN_HUGE + 1], *sep;
- int max;
unsigned int len;
-
- max = _hestMax(O->max);
+ AIR_UNUSED(P); // formerly for P->multiFlagSep
+ int max = _hestMax(O->max);
if (O->flag) {
strcpy(copy, O->flag);
- if ((sep = strchr(copy, P->multiFlagSep))) {
+ if ((sep = strchr(copy, MULTI_FLAG_SEP))) {
*sep = 0;
if (showshort) {
strcat(B, "-");
@@ -41,7 +40,7 @@
if (showlong) {
if (showshort) {
len = AIR_UINT(strlen(B));
- B[len] = P->multiFlagSep;
+ B[len] = MULTI_FLAG_SEP;
B[len + 1] = '\0';
}
strcat(B, "--");
@@ -247,8 +246,8 @@
}
strcpy(buff, "Usage: ");
strcat(buff, argv0 ? argv0 : "");
- if (HPARM->respFileEnable) {
- sprintf(tmpS, " [%cfile\t...]", HPARM->respFileFlag);
+ if (HPARM->responseFileEnable) {
+ sprintf(tmpS, " [%cfile\t...]", RESPONSE_FILE_FLAG);
strcat(buff, tmpS);
}
for (i = 0; i < numOpts; i++) {
@@ -294,8 +293,8 @@
_hestSetBuff(buff, opt + i, HPARM, AIR_TRUE, AIR_FALSE);
maxlen = AIR_MAX((int)strlen(buff), maxlen);
}
- if (HPARM->respFileEnable) {
- sprintf(buff, "%cfile ...", HPARM->respFileFlag);
+ if (HPARM->responseFileEnable) {
+ sprintf(buff, "%cfile ...", RESPONSE_FILE_FLAG);
len = AIR_UINT(strlen(buff));
for (j = len; j < maxlen; j++) {
fprintf(f, " ");
@@ -315,7 +314,7 @@
fprintf(f, "%s", buff);
strcpy(buff, "");
#if 1
- if (opt[i].flag && strchr(opt[i].flag, HPARM->multiFlagSep)) {
+ if (opt[i].flag && strchr(opt[i].flag, MULTI_FLAG_SEP)) {
/* there is a long-form flag as well as short */
_hestSetBuff(buff, opt + i, HPARM, AIR_FALSE, AIR_TRUE);
strcat(buff, " = ");
Modified: teem/trunk/src/ten/tendBfit.c
===================================================================
--- teem/trunk/src/ten/tendBfit.c 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/ten/tendBfit.c 2025-09-18 20:39:52 UTC (rev 7456)
@@ -39,7 +39,7 @@
int iterMax;
char *outS;
- hparm->respFileEnable = AIR_TRUE;
+ hparm->responseFileEnable = AIR_TRUE;
hestOptAdd_1_Other(&hopt, "i", "nin", &nin, "-",
"Input nrrd. List of DWIs from different b-values must "
Modified: teem/trunk/src/ten/tendGlyph.c
===================================================================
--- teem/trunk/src/ten/tendGlyph.c 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/ten/tendGlyph.c 2025-09-18 20:39:52 UTC (rev 7456)
@@ -123,7 +123,7 @@
double v2w[9], ldir[3], edir[3], fdir[3], corn[3], len;
/* so that command-line options can be read from file */
- hparm->respFileEnable = AIR_TRUE;
+ hparm->responseFileEnable = AIR_TRUE;
hparm->elideSingleEmptyStringDefault = AIR_TRUE;
mop = airMopNew();
Modified: teem/trunk/src/unrrdu/join.c
===================================================================
--- teem/trunk/src/unrrdu/join.c 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/unrrdu/join.c 2025-09-18 20:39:52 UTC (rev 7456)
@@ -45,7 +45,7 @@
double mm[2], spc;
airArray *mop;
- hparm->respFileEnable = AIR_TRUE;
+ hparm->responseFileEnable = AIR_TRUE;
hestOptAdd_Nv_Other(&opt, "i,input", "nin0", 1, -1, &nin, NULL,
"everything to be joined together", &ninLen, nrrdHestNrrdNoTTY);
Modified: teem/trunk/src/unrrdu/make.c
===================================================================
--- teem/trunk/src/unrrdu/make.c 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/unrrdu/make.c 2025-09-18 20:39:52 UTC (rev 7456)
@@ -82,7 +82,7 @@
const NrrdEncoding *encoding;
/* so that long lists of filenames can be read from file */
- hparm->respFileEnable = AIR_TRUE;
+ hparm->responseFileEnable = AIR_TRUE;
hparm->greedySingleString = AIR_TRUE;
mop = airMopNew();
Modified: teem/trunk/src/unrrdu/shuffle.c
===================================================================
--- teem/trunk/src/unrrdu/shuffle.c 2025-09-18 15:34:17 UTC (rev 7455)
+++ teem/trunk/src/unrrdu/shuffle.c 2025-09-18 20:39:52 UTC (rev 7456)
@@ -44,7 +44,7 @@
airArray *mop;
/* so that long permutations can be read from file */
- hparm->respFileEnable = AIR_TRUE;
+ hparm->responseFileEnable = AIR_TRUE;
hestOptAdd_Nv_UInt(&opt, "p,permute", "slc0 slc1", 1, -1, &perm, NULL,
"new slice ordering", &permLen);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|