|
From: <kin...@us...> - 2025-09-25 08:56:51
|
Revision: 7486
http://sourceforge.net/p/teem/code/7486
Author: kindlmann
Date: 2025-09-25 08:56:49 +0000 (Thu, 25 Sep 2025)
Log Message:
-----------
still debugging stack, dammit
Modified Paths:
--------------
teem/trunk/src/hest/parsest.c
teem/trunk/src/hest/test/tparse.c
Modified: teem/trunk/src/hest/parsest.c
===================================================================
--- teem/trunk/src/hest/parsest.c 2025-09-25 07:47:57 UTC (rev 7485)
+++ teem/trunk/src/hest/parsest.c 2025-09-25 08:56:49 UTC (rev 7486)
@@ -310,8 +310,7 @@
}
*nastP = nastTryAgain;
}
- } else {
- // hin->source is hestSourceResponseFile or hestSourceDefault
+ } else if (hestSourceResponseFile == hin->source || hestSourceDefault == hin->source) {
int icc; // the next character we read as int
int state = argstStart;
do {
@@ -354,6 +353,9 @@
}
}
} while (nastUnknown == *nastP);
+ } else {
+ biffAddf(HEST, "%s%sconfused about hin->source %d", _ME_, hin->source);
+ return 1;
}
return 0;
}
@@ -514,10 +516,13 @@
static int
histProcess(hestArgVec *havec, int *helpWantedP, hestArg *tharg, hestInputStack *hist,
const hestParm *hparm) {
+ if (!hist->len) {
+ biffAddf(HEST, "%s%scannot process zero-height stack", _ME_);
+ return 1;
+ }
if (helpWantedP) *helpWantedP = AIR_FALSE;
int nast = nastUnknown;
uint iters = 0;
- hestInput *topHin;
// printf("!%s: hello hist->len %u\n", __func__, hist->len);
// initialize destination havec
airArrayLenSet(havec->hargArr, 0);
@@ -526,12 +531,10 @@
Otherwise, we loop again. */
while (1) {
iters += 1;
- /* if this loop just pushed a response file, the top hestInput is different
- from what it was when this function started, so re-learn it. */
- topHin = hist->hin + hist->len - 1;
- /* printf("!%s: (iters %u) topHin(%p)->rfname = |%s|\n", __func__, iters,
- AIR_VOIDP(topHin), topHin->rfname); */
- const char *srcstr = airEnumStr(hestSource, topHin->source);
+ // learn ways to describe current input source
+ hestInput *topHin = hist->hin + hist->len - 1;
+ int srcval = topHin->source;
+ const char *srcstr = airEnumStr(hestSource, srcval);
// read next arg into tharg
if (histProcNextArg(&nast, tharg, hist, hparm)) {
biffAddf(HEST, "%s%s(iter %u, on %s) unable to get next arg", _ME_, iters, srcstr);
@@ -544,8 +547,18 @@
}
break;
}
+ // annoyingly, we may get here with an empty stack (HEY fix this?)
+ topHin = (hist->len //
+ ? hist->hin + hist->len - 1
+ : NULL);
+ printf("!%s: nast = %s, |stack| = %u, topHin = %p\n", __func__, airEnumStr(nast_ae, nast),
+ hist->len, AIR_VOIDP(topHin));
// we have a token, is it turning off commenting?
if (hparm->respectDashBraceComments && !strcmp("}-", tharg->str)) {
+ if (!topHin) {
+ biffAddf(HEST, "%s%s(iter %u, on %s) unexpected empty stack (0)", _ME_, iters, srcstr);
+ return 1;
+ }
if (topHin->dashBraceComment) {
topHin->dashBraceComment -= 1;
if (hparm->verbosity) {
@@ -563,6 +576,10 @@
}
// not ending comment, are we starting (or deepening) one?
if (hparm->respectDashBraceComments && !strcmp("-{", tharg->str)) {
+ if (!topHin) {
+ biffAddf(HEST, "%s%s(iter %u, on %s) unexpected empty stack (1)", _ME_, iters, srcstr);
+ return 1;
+ }
topHin->dashBraceComment += 1;
if (hparm->verbosity) {
printf("%s: topHin->dashBraceComment now %u\n", __func__,
@@ -571,7 +588,7 @@
continue;
}
// if in comment, move along
- if (topHin->dashBraceComment) {
+ if (topHin && topHin->dashBraceComment) {
if (hparm->verbosity > 1) {
printf("%s: (iter %u, on %s) skipping commented-out |%s|\n", __func__, iters,
srcstr, tharg->str);
@@ -580,6 +597,10 @@
}
// else this arg is not in a comment and is not related to commenting
if (hparm->respectDashDashHelp && !strcmp("--help", tharg->str)) {
+ if (!topHin) {
+ biffAddf(HEST, "%s%s(iter %u, on %s) unexpected empty stack (2)", _ME_, iters, srcstr);
+ return 1;
+ }
if (hestSourceCommandLine == topHin->source) {
/* user asking for help halts further parsing work: user is not looking
for parsing results nor error messages about that process */
@@ -601,6 +622,10 @@
srcstr, tharg->str);
}
if (hparm->responseFileEnable && tharg->str[0] == RESPONSE_FILE_FLAG) {
+ if (!topHin) {
+ biffAddf(HEST, "%s%s(iter %u, on %s) unexpected empty stack (3)", _ME_, iters, srcstr);
+ return 1;
+ }
if (hestSourceDefault == topHin->source) {
biffAddf(HEST,
"%s%s(iter %u, on %s) %s response files not handled in this source",
@@ -624,7 +649,11 @@
srcstr, tharg->str, havec->len);
}
// set source in the hestArg we just appended
- havec->harg[havec->len - 1]->source = topHin->source;
+ havec->harg[havec->len - 1]->source = srcval;
+ // bail if stack is empty
+ if (!topHin) {
+ break;
+ }
}
if (hist->len && nast == nastEmpty) {
biffAddf(HEST, "%s%snon-empty stack (depth %u) can't generate args???", _ME_,
@@ -1010,7 +1039,7 @@
uint np = opt[opi].min;
biffAddf(HEST,
"%s%sremaining %u args not enough for the %u parameter%s "
- "needed for %s or later options",
+ "needed for unflagged %s or later options",
_ME_, havec->len, np, np > 1 ? "s" : "", identStr(ident, opt + opi));
return 1;
}
@@ -1097,7 +1126,7 @@
uint optNum = opt->arrLen;
for (uint opi = 0; opi < optNum; opi++) {
if (hparm->verbosity) {
- printf("%s: INCOMING", __func__);
+ printf(" -> %s incoming", __func__);
optPrint(opt + opi, opi);
}
if (opt[opi].source) {
@@ -1111,7 +1140,7 @@
opt[opi].dflt is enforced to be NULL) so there is no default string to tokenize,
but we above set source to default for sake of completeness, and to signal that
the flag was not given by user */
- continue;
+ goto nextopt;
}
char ident[AIR_STRLEN_HUGE + 1];
identStr(ident, opt + opi);
@@ -1149,8 +1178,9 @@
_ME_, opi, ident, opt[opi].havec->len, opt[opi].min);
return 1;
}
+ nextopt:
if (hparm->verbosity) {
- printf("%s: OUTGOING", __func__);
+ printf("<- %s: outgoing", __func__);
optPrint(opt + opi, opi);
}
}
Modified: teem/trunk/src/hest/test/tparse.c
===================================================================
--- teem/trunk/src/hest/test/tparse.c 2025-09-25 07:47:57 UTC (rev 7485)
+++ teem/trunk/src/hest/test/tparse.c 2025-09-25 08:56:49 UTC (rev 7486)
@@ -54,7 +54,7 @@
int glaf;
hestOptAdd_Flag(&opt, "c,cingo", &glaf, "a flag");
int unpC[2];
- hestOptAdd_2_Int(&opt, NULL, "C C", unpC, NULL, "unflagged C");
+ hestOptAdd_2_Int(&opt, NULL, "C C", unpC, "dfltC0", "unflagged C");
/*
int *unpC;
unsigned int sawC;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|