/* ** _hestPrintStr() ** ** not a useful function. Do not use. */ void _hestPrintStr(FILE *f, int indent, int already, int width, const char *_str, int bslash) { char *str, *ws, *last; int nwrd, wrd, pos, s, newed=AIR_FALSE; str = airStrdup(_str); nwrd = airStrntok(str, " "); pos = already; for (wrd=0; wrd<nwrd; wrd++) { /* we used airStrtok() to delimit words on spaces ... */ ws = airStrtok(!wrd ? str : NULL, " ", &last); /* ... but then convert tabs to spaces */ airStrtrans(ws, '\t', ' '); if ((int)(pos + 1 + strlen(ws)) <= width - !!bslash) { /* if this word would still fit on the current line */ if (wrd && !newed) fprintf(f, " "); fprintf(f, "%s", ws); pos += 1 + strlen(ws); newed = AIR_FALSE; } else { /* else we start a new line and print the indent */ if (bslash) { fprintf(f, " \\"); } fprintf(f, "\n"); for (s=0; s<indent; s++) { fprintf(f, " "); } fprintf(f, "%s", ws); pos = indent + strlen(ws); } /* if the last character of the word was a newline, then indent */ if ('\n' == ws[strlen(ws)-1]) { for (s=0; s<indent; s++) { fprintf(f, " "); } pos = indent; newed = AIR_TRUE; } else { newed = AIR_FALSE; } } fprintf(f, "\n"); free(str); }
int _nrrdSpaceVectorParse(double val[NRRD_SPACE_DIM_MAX], char **hhP, unsigned int spaceDim, int useBiff) { char me[]="_nrrdSpaceVectorParse", err[BIFF_STRLEN], *hh, *buff, sep[]=",)"; airArray *mop; unsigned int ret, dd, length; mop = airMopNew(); hh = *hhP; /* skip past space */ length = strspn(hh, _nrrdFieldSep); hh += length; /* make sure we have something */ if (!*hh) { sprintf(err, "%s: hit end of string before seeing (", me); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } /* first, see if we're getting the non-vector */ if ( (strstr(hh, _nrrdNoSpaceVector) == hh) ) { if (!hh[strlen(_nrrdNoSpaceVector)] || strchr(_nrrdFieldSep, hh[strlen(_nrrdNoSpaceVector)])) { /* yes, we got the non-vector */ for (dd=0; dd<spaceDim; dd++) { val[dd] = AIR_NAN; } length += strlen(_nrrdNoSpaceVector); } else { /* we got something that started out looking like the non-vector */ sprintf(err, "%s: couldn't parse non-vector \"%s\"", me, hh); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } } else { /* this isn't a non-vector */ /* make sure we have an open paren */ if ('(' != *hh) { sprintf(err, "%s: first vector in \"%s\" didn't start with '('", me, hh); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } /* copy string (including open paren) for local fiddling */ if (!(buff = airStrdup(hh))) { sprintf(err, "%s: couldn't allocate local buffer", me); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } airMopAdd(mop, buff, airFree, airMopAlways); /* scan for close paren */ hh = buff+1; while (*hh) { if (')' == *hh) { break; } else { hh++; } } if (')' != *hh) { sprintf(err, "%s: didn't see ')' at end of first vector in \"%s\"", me, hh); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } /* terminate at end paren */ *(hh+1) = 0; length += strlen(buff); /* see if we have too many fields */ ret = airStrntok(buff+1, sep); if (ret > spaceDim) { sprintf(err, "%s: space dimension is %d, but seem to have %d " "coefficients", me, spaceDim, ret); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } /* try to parse the values */ ret = airParseStrD(val, buff+1, ",", spaceDim); if (spaceDim != ret) { sprintf(err, "%s: parsed %d values, but space dimension is %d", me, ret, spaceDim); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } } /* probably not useful */ for (dd=spaceDim; dd<NRRD_SPACE_DIM_MAX; dd++) { val[dd] = AIR_NAN; } /* make sure all coefficients exist or not together */ for (dd=1; dd<spaceDim; dd++) { if (!!AIR_EXISTS(val[0]) ^ !!AIR_EXISTS(val[dd])) { sprintf(err, "%s: existance of all space vector coefficients must " "be consistent (val[0] not like val[%d])", me, dd); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } } for (dd=0; dd<spaceDim; dd++) { if (airIsInf_d(val[dd])) { sprintf(err, "%s: vector coefficient %d can't be infinite", me, dd); biffMaybeAdd(NRRD, err, useBiff); airMopError(mop); return 1; } } *hhP += length; airMopOkay(mop); return 0; }
/* ******** meetPullVolParse ** ** parses a string to extract all the information necessary to create ** the pullVolume (this function originated in Deft/src/main-pull.c) */ int meetPullVolParse(meetPullVol *mpv, const char *_str) { static const char me[]="meetPullVolParse"; #define VFMT_SHRT "<fileName>:<kind>:<volName>" #define SFMT "<minScl>-<#smp>-<maxScl>[-no|u]" #define VFMT_LONG "<fileName>:<kind>:" SFMT ":<volName>" char *str, *ctok, *clast=NULL, *dtok, *dlast=NULL; airArray *mop; int wantSS; if (!(mpv && _str)) { biffAddf(MEET, "%s: got NULL pointer", me); return 1; } if (!( str = airStrdup(_str) )) { biffAddf(MEET, "%s: couldn't strdup input", me); return 1; } mop = airMopNew(); airMopAdd(mop, str, airFree, airMopAlways); if (!( 3 == airStrntok(str, ":") || 4 == airStrntok(str, ":") )) { biffAddf(MEET, "%s: didn't get 3 or 4 \":\"-separated tokens in \"%s\"; " "not of form " VFMT_SHRT " or " VFMT_LONG , me, _str); airMopError(mop); return 1; } /* mpv->nin is set elsewhere */ wantSS = (4 == airStrntok(str, ":")); ctok = airStrtok(str, ":", &clast); if (!(mpv->fileName = airStrdup(ctok))) { biffAddf(MEET, "%s: couldn't strdup fileName", me); airMopError(mop); return 1; } airMopAdd(mop, &(mpv->fileName), (airMopper)airSetNull, airMopOnError); airMopAdd(mop, mpv->fileName, airFree, airMopOnError); ctok = airStrtok(NULL, ":", &clast); if (!(mpv->kind = meetConstGageKindParse(ctok))) { biffAddf(MEET, "%s: couldn't parse \"%s\" as kind", me, ctok); airMopError(mop); return 1; } if (wantSS) { int haveFlags; ctok = airStrtok(NULL, ":", &clast); if (!( 3 == airStrntok(ctok, "-") || 4 == airStrntok(ctok, "-") )) { biffAddf(MEET, "%s: didn't get 3 or 4 \"-\"-separated tokens in \"%s\"; " "not of form SFMT" , me, ctok); airMopError(mop); return 1; } haveFlags = (4 == airStrntok(ctok, "-")); dtok = airStrtok(ctok, "-", &dlast); if (1 != sscanf(dtok, "%lg", &(mpv->rangeSS[0]))) { biffAddf(MEET, "%s: couldn't parse \"%s\" as min scale", me, dtok); airMopError(mop); return 1; } dtok = airStrtok(NULL, "-", &dlast); if (1 != sscanf(dtok, "%u", &(mpv->numSS))) { biffAddf(MEET, "%s: couldn't parse \"%s\" as # scale samples", me, dtok); airMopError(mop); return 1; } if (!( mpv->numSS >= 2 )) { biffAddf(MEET, "%s: need # scale samples >= 2 (not %u)", me, mpv->numSS); airMopError(mop); return 1; } dtok = airStrtok(NULL, "-", &dlast); if (1 != sscanf(dtok, "%lg", &(mpv->rangeSS[1]))) { biffAddf(MEET, "%s: couldn't parse \"%s\" as max scale", me, dtok); airMopError(mop); return 1; } /* initialize things as if there were no flags */ mpv->derivNormSS = AIR_FALSE; mpv->uniformSS = AIR_FALSE; mpv->optimSS = AIR_FALSE; mpv->derivNormBiasSS = 0.0; if (haveFlags) { char *flags, *bias; /* look for various things in flags */ flags = airToLower(airStrdup(airStrtok(NULL, "-", &dlast))); airMopAdd(mop, flags, airFree, airMopAlways); if (strchr(flags, 'n')) { mpv->derivNormSS = AIR_TRUE; } if (strchr(flags, 'u')) { mpv->uniformSS = AIR_TRUE; } if (strchr(flags, 'o')) { mpv->optimSS = AIR_TRUE; } if (mpv->optimSS && mpv->uniformSS) { biffAddf(MEET, "%s: can't have both optimal ('o') and uniform ('u') " "flags set in \"%s\"", me, flags); airMopError(mop); return 1; } if ((bias = strchr(flags, '+'))) { /* indicating a bias, unfortunately only a positive one is possible here, because of the way that other fields are tokenized by '-' */ bias++; if (1 != sscanf(bias, "%lf", &(mpv->derivNormBiasSS))) { biffAddf(MEET, "%s: couldn't parse bias \"%s\"", me, bias); airMopError(mop); return 1; } } } /* mpv->ninSS and mpv->posSS are allocated and filled elsewhere */ mpv->ninSS = NULL; mpv->posSS = NULL; /* we don't actually create nrrds nor load the volumes here, because we don't know cachePath, and because we might want different pullVolumes to share the same underlying Nrrds */ } else { /* no scale-space stuff wanted */ mpv->numSS = 0; mpv->rangeSS[0] = mpv->rangeSS[1] = AIR_NAN; mpv->ninSS = NULL; mpv->posSS = NULL; } ctok = airStrtok(NULL, ":", &clast); if (!(mpv->volName = airStrdup(ctok))) { biffAddf(MEET, "%s: couldn't strdup volName", me); airMopError(mop); return 1; } airMopAdd(mop, &(mpv->volName), (airMopper)airSetNull, airMopOnError); airMopAdd(mop, mpv->volName, airFree, airMopOnError); if (strchr(ctok, '-')) { biffAddf(MEET, "%s: you probably don't want \"-\" in volume name \"%s\"; " "forgot last \":\" in scale sampling specification?", me, ctok); airMopError(mop); return 1; } airMopOkay(mop); return 0; }