/* ** _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); }
void hestGlossary(FILE *f, hestOpt *opt, hestParm *_parm) { int i, j, len, maxlen, numOpts; char buff[2*AIR_STRLEN_HUGE], tmpS[AIR_STRLEN_HUGE]; hestParm *parm; parm = !_parm ? hestParmNew() : _parm; if (_hestPanic(opt, NULL, parm)) { /* we can't continue; the opt array is botched */ parm = !_parm ? hestParmFree(parm) : NULL; return; } numOpts = _hestNumOpts(opt); maxlen = 0; if (numOpts) { fprintf(f, "\n"); } for (i=0; i<numOpts; i++) { strcpy(buff, ""); _hestSetBuff(buff, opt + i, parm, AIR_TRUE, AIR_FALSE); maxlen = AIR_MAX((int)strlen(buff), maxlen); } if (parm && parm->respFileEnable) { sprintf(buff, "%cfile ...", parm->respFileFlag); len = strlen(buff); for (j=len; j<maxlen; j++) { fprintf(f, " "); } fprintf(f, "%s = ", buff); strcpy(buff, "response file(s) containing command-line arguments"); _hestPrintStr(f, maxlen + 3, maxlen + 3, parm->columns, buff, AIR_FALSE); } for (i=0; i<numOpts; i++) { strcpy(buff, ""); _hestSetBuff(buff, opt + i, parm, AIR_TRUE, AIR_FALSE); airOneLinify(buff); len = strlen(buff); for (j=len; j<maxlen; j++) { fprintf(f, " "); } fprintf(f, "%s", buff); strcpy(buff, ""); #if 1 if (opt[i].flag && strchr(opt[i].flag, parm->multiFlagSep)) { /* there is a long-form flag as well as short */ _hestSetBuff(buff, opt + i, parm, AIR_FALSE, AIR_TRUE); strcat(buff, " = "); fprintf(f, " , "); } else { /* there is only a short-form flag */ fprintf(f, " = "); } #else fprintf(f, " = "); #endif if (opt[i].info) { strcat(buff, opt[i].info); } if ((opt[i].min || _hestMax(opt[i].max)) && (!( 2 == opt[i].kind && airTypeEnum == opt[i].type && parm->elideSingleEnumType )) && (!( 2 == opt[i].kind && airTypeOther == opt[i].type && parm->elideSingleOtherType )) ) { /* if there are newlines in the info, then we want to clarify the type by printing it on its own line */ if (opt[i].info && strchr(opt[i].info, '\n')) { strcat(buff, "\n "); } else { strcat(buff, " "); } strcat(buff, "("); if (opt[i].min == 0 && _hestMax(opt[i].max) == 1) { strcat(buff, "optional\t"); } else { if ((int)opt[i].min == _hestMax(opt[i].max) && _hestMax(opt[i].max) > 1) { /* HEY scrutinize casts */ sprintf(tmpS, "%d\t", _hestMax(opt[i].max)); strcat(buff, tmpS); } else if ((int)opt[i].min < _hestMax(opt[i].max)) { /* HEY scrutinize casts */ if (-1 == opt[i].max) { sprintf(tmpS, "%d\tor\tmore\t", opt[i].min); } else { sprintf(tmpS, "%d..%d\t", opt[i].min, _hestMax(opt[i].max)); } strcat(buff, tmpS); } } sprintf(tmpS, "%s%s", (airTypeEnum == opt[i].type ? opt[i].enm->name : (airTypeOther == opt[i].type ? opt[i].CB->type : airTypeStr[opt[i].type])), (_hestMax(opt[i].max) > 1 ? (airTypeOther == opt[i].type && 'y' == opt[i].CB->type[airStrlen(opt[i].CB->type)-1] && parm->cleverPluralizeOtherY ? "\bies" : "s") : "")); strcat(buff, tmpS); strcat(buff, ")"); } /* fprintf(stderr, "!%s: parm->elideSingleOtherDefault = %d\n", "hestGlossary", parm->elideSingleOtherDefault); */ if (opt[i].dflt && (opt[i].min || _hestMax(opt[i].max)) && (!( 2 == opt[i].kind && (airTypeFloat == opt[i].type || airTypeDouble == opt[i].type) && !AIR_EXISTS(airAtod(opt[i].dflt)) && parm->elideSingleNonExistFloatDefault )) && (!( (3 == opt[i].kind || 5 == opt[i].kind) && (airTypeFloat == opt[i].type || airTypeDouble == opt[i].type) && !AIR_EXISTS(airAtod(opt[i].dflt)) && parm->elideMultipleNonExistFloatDefault )) && (!( 2 == opt[i].kind && airTypeOther == opt[i].type && parm->elideSingleOtherDefault )) && (!( 2 == opt[i].kind && airTypeString == opt[i].type && parm->elideSingleEmptyStringDefault && 0 == airStrlen(opt[i].dflt) )) && (!( (3 == opt[i].kind || 5 == opt[i].kind) && airTypeString == opt[i].type && parm->elideMultipleEmptyStringDefault && 0 == airStrlen(opt[i].dflt) )) ) { /* if there are newlines in the info, then we want to clarify the default by printing it on its own line */ if (opt[i].info && strchr(opt[i].info, '\n')) { strcat(buff, "\n "); } else { strcat(buff, "; "); } strcat(buff, "default:\t"); strcpy(tmpS, opt[i].dflt); airStrtrans(tmpS, ' ', '\t'); strcat(buff, "\""); strcat(buff, tmpS); strcat(buff, "\""); } _hestPrintStr(f, maxlen + 3, maxlen + 3, parm->columns, buff, AIR_FALSE); } parm = !_parm ? hestParmFree(parm) : NULL; return; }
int _limnReadCamanim(int imgSize[2], limnCamera **keycamP, double **timeP, unsigned int *numKeysP, FILE *fin) { char me[]="_limnReadCamanim", err[AIR_STRLEN_MED]; char line[AIR_STRLEN_HUGE]; unsigned int ki; double *tmp, *dwell, di, dn, df, fr[3], at[3], up[3], va; airArray *mop, *camA, *dwellA; if (!( 0 < airOneLine(fin, line, AIR_STRLEN_HUGE) && !strcmp(_LIMNMAGIC, line) )) { sprintf(err, "%s: couldn't read first line or it wasn't \"%s\"", me, _LIMNMAGIC); biffAdd(LIMN, err); return 1; } if (!( 0 < airOneLine(fin, line, AIR_STRLEN_HUGE) && 2 == (airStrtrans(airStrtrans(line, '{', ' '), '}', ' '), sscanf(line, "imgSize %d %d", imgSize+0, imgSize+1)) )) { sprintf(err, "%s: couldn't read second line or it wasn't " "\"imgSize <sizeX> <sizeY>\"", me); biffAdd(LIMN, err); return 1; } mop = airMopNew(); camA = airArrayNew((void **)keycamP, numKeysP, sizeof(limnCamera), 1); dwellA = airArrayNew((void **)&dwell, NULL, sizeof(double), 1); airMopAdd(mop, camA, (airMopper)airArrayNix, airMopAlways); airMopAdd(mop, dwellA, (airMopper)airArrayNuke, airMopAlways); while ( 0 < airOneLine(fin, line, AIR_STRLEN_HUGE) ) { airStrtrans(airStrtrans(line, '{', ' '), '}', ' '); ki = airArrayLenIncr(camA, 1); airArrayLenIncr(dwellA, 1); if (14 != sscanf(line, "cam.di %lg cam.at %lg %lg %lg " "cam.up %lg %lg %lg cam.dn %lg cam.df %lg cam.va %lg " "relDwell %lg cam.fr %lg %lg %lg", &di, at+0, at+1, at+2, up+0, up+1, up+2, &dn, &df, &va, dwell+ki, fr+0, fr+1, fr+2)) { sprintf(err, "%s: trouble parsing line %d: \"%s\"", me, ki, line); biffAdd(LIMN, err); airMopError(mop); return 1; } (*keycamP)[ki].neer = dn; (*keycamP)[ki].faar = df; (*keycamP)[ki].dist = di; ELL_3V_COPY((*keycamP)[ki].from, fr); ELL_3V_COPY((*keycamP)[ki].at, at); ELL_3V_COPY((*keycamP)[ki].up, up); (*keycamP)[ki].fov = va; (*keycamP)[ki].aspect = (double)imgSize[0]/imgSize[1]; (*keycamP)[ki].atRelative = AIR_FALSE; (*keycamP)[ki].orthographic = AIR_FALSE; (*keycamP)[ki].rightHanded = AIR_TRUE; } tmp = (double*)calloc(*numKeysP, sizeof(double)); airMopAdd(mop, tmp, airFree, airMopAlways); *timeP = (double*)calloc(*numKeysP, sizeof(double)); for (ki=0; ki<*numKeysP; ki++) { dwell[ki] = AIR_CLAMP(0, dwell[ki], 2); tmp[ki] = tan(AIR_AFFINE(-0.01, dwell[ki], 2.01, 0.0, AIR_PI/2)); } (*timeP)[0] = 0; for (ki=1; ki<*numKeysP; ki++) { (*timeP)[ki] = (*timeP)[ki-1] + (tmp[ki-1] + tmp[ki])/2; } for (ki=0; ki<*numKeysP; ki++) { (*timeP)[ki] /= (*timeP)[*numKeysP-1]; } airMopOkay(mop); return 0; }