int setParmParms(ParmList p, ParmList *array, int n) { int rtn = 0; int ok = 1; int i; for (i=0; ok && i<n; i++){ if ( (ok=setParmParm(p, array[i], i)) ) { rtn++; } } return rtn; }
ParmList appendParmParm(ParmList p, ParmList value) { ParmList rtn = NULL; int n; if (p[PL_TYPEOFFSET].ival == PL_PARM){ n = countParm(p); rtn = (ParmList)realloc(p, (n+1+PL_DATAOFFSET)*sizeof(ParmItem)); if (rtn){ rtn[PL_SIZEOFFSET].ival = n+1; setParmParm(rtn, value, n); } } return rtn; }
/************************************************************************ * * * Process the Image Math string "cmd". * (STATIC) * * */ void Win_math::exec_string(char *cmd) { int i; int n; int err = FALSE; char *pc; // The following get pointed to mallocated memory ParmList dst_frames = NULL; ParmList dst_ddls = NULL; ParmList src_ddls = NULL; ParmList src_ddl_vecs = NULL; ParmList src_strings = NULL; ParmList src_constants = NULL; ParmList parmtree = NULL; char *exec_path = NULL; win_print_msg("Math: Parsing..."); /* Change New-Lines to Spaces */ while (pc=strchr(cmd, '\n')){ *pc = ' '; } /* Parse the left hand side */ int nout = parse_lhs(cmd, &dst_frames); if (!nout){ err = TRUE; } /*printParm(dst_frames);/*CMP*/ /* Parse images on right hand side */ int nin = parse_rhs(cmd, &src_ddls, &src_ddl_vecs, &src_strings, &src_constants); if (!nin){ err = TRUE; } /*printParm(src_ddls);/*CMP*/ /*printParm(src_strings);/*CMP*/ /* Get the executable, compiling if necessary */ if (!err){ win_print_msg("Math: Compiling program..."); if (!(exec_path = get_program(cmd))){ err = TRUE; } } /*fprintf(stderr,"exec_path=%s\n", exec_path);/*CMP*/ /* Execute the program */ parmtree = allocParm("parmtree", PL_PARM, 5); setParmParm(parmtree, src_ddls, 0); setParmParm(parmtree, dst_frames, 1); setParmParm(parmtree, src_strings, 2); setParmParm(parmtree, src_constants, 3); setParmParm(parmtree, src_ddl_vecs, 4); /*printParm(parmtree);/*CMP*/ if (!err){ win_print_msg("Math: Executing program..."); if (!exec_program(exec_path, parmtree, &dst_ddls)){ err = TRUE; } } /* Display the results */ /*printParm(dst_ddls);/*CMP*/ void *vst; int frame; Gframe *gf; n = countParm(dst_ddls); for (i=0; i<n; i++){ getPtrParm(dst_ddls, &vst, i); DDLSymbolTable *st = (DDLSymbolTable *)vst; getIntParm(dst_frames, &frame, i); /*fprintf(stderr,"st=0x%x, frame=%d\n", st, frame);/*CMP*/ if (st && frame){ char *fname; st->GetValue("filename", fname); char *newname = (char *)malloc(strlen(fname) + 20); sprintf(newname,"%s-mathout#%d", fname, i+1); st->SetValue("filename", newname); free(newname); gf = Gframe::get_frame_by_number(frame); int display_data = TRUE; int math_result = TRUE; Frame_data::load_ddl_data(gf, NULL, NULL, &display_data, TRUE, (DDLSymbolTable *)st, math_result); } } /* Free memory */ free(parmtree); // Also frees params under it free(dst_ddls); win_print_msg("Math: Done."); }