void freeParms(ParmList p) { int n; int i; int type; char *s; ParmList p2; if (p){ n = countParm(p); if ((type=typeofParm(p)) == PL_PARM) { for (i=0; i<n; i++){ getParmParm(p, &p2, i); freeParms(p2); } }else if (type == PL_STRING){ for (i=0; i<n; i++){ getStrParm(p, &s, i); if (s){ free(s); } } } free(p); } }
/************************************************************************ * * * Parse the RHS of math expression "cmd". * Returns number of source images * (STATIC) * * */ int Win_math::parse_rhs(char *cmd, ParmList *ddls, ParmList *ddlvecs, ParmList *strings, ParmList *constants) { int i; int j; int m; int n; char *pc; char *tbuf; ParmList frames; ParmList pl; void *pv; Imginfo *img; pc = strchr(cmd, '='); if (!pc){ return 0; } tbuf = strdup(++pc); // tbuf contains the RHS if (!tbuf) return 0; *ddlvecs = get_imagevector_list("src_ddlvecs", tbuf); // frame nbrs stripped *ddls = allocParm("src_ddls", PL_PTR, 0); n = countParm(*ddlvecs); for (i=0; i<n; i++){ getParmParm(*ddlvecs, &pl, i); m = countParm(pl); for (j=0; j<m; j++){ getPtrParm(pl, &pv, j); *ddls = appendPtrParm(*ddls, pv); } } /*fprintf(stderr,"cmd w/o frames = \"%s\"\n", tbuf);/*CMP*/ *strings = get_stringlist("src_strings", tbuf); // strings stripped off /*fprintf(stderr,"cmd w/o strings = \"%s\"\n", tbuf);/*CMP*/ *constants = get_constlist("src_constants", tbuf); // tbuf unchanged /*fprintf(stderr,"cmd w/ constants = \"%s\"\n", tbuf);/*CMP*/ n = countParm(*ddls); if (!n){ msgerr_print("Math: no input image(s) specified"); freeParms(*ddls); *ddls = NULL; return 0; } free(tbuf); return n; }
int getParmParms(ParmList p, ParmList *array, int nelems) { int rtn = 0; int ok = 1; int i; for (i=0; ok && i<nelems; i++){ if ( (ok=getParmParm(p, &array[i], i)) ) { rtn++; } } return rtn; }
void printParm(ParmList p) { int i; int n; int type; int pi; float pf; void *pp; char *ps; ParmList parm; if (p){ fprintf(stderr,"%s = [", p[PL_NAMEOFFSET].sval); n = countParm(p); type = typeofParm(p); for (i=0; i<n; i++){ switch (type){ case PL_INT: getIntParm(p, &pi, i); fprintf(stderr,"%d ", pi); break; case PL_FLOAT: getFloatParm(p, &pf, i); fprintf(stderr,"%g ", pf); break; case PL_STRING: getStrParm(p, &ps, i); if (ps){ fprintf(stderr,"\"%s\" ", ps); }else{ fprintf(stderr,"NULL "); } break; case PL_PTR: getPtrParm(p, &pp, i); fprintf(stderr,"%p ", pp); break; case PL_PARM: getParmParm(p, &parm, i); fprintf(stderr,"%p ", parm); break; } } fprintf(stderr,"]\n"); } }