void _mk_it_scroller(QSP_ARG_DECL Screen_Obj *sop,Item_Type *itp) { List *lp; Node *np; int i; int n=0; const char **sp; const char *string_arr[MAX_STRINGS]; Item *ip; lp=item_list(itp); if( lp == NULL ) return; np=QLIST_HEAD(lp); while(np!=NULL){ ip=(Item *)np->n_data; if( n < MAX_STRINGS ) string_arr[n]=ip->item_name; n++; np = np->n_next; } set_scroller_list(sop,string_arr,n); SET_SOB_SELECTORS(sop, (const char **)getbuf( n * sizeof(char *) )); sp = SOB_SELECTORS(sop); for(i=0;i<n;i++) sp[i]=string_arr[i]; }
static void evaluate_error_c(void) { double err; double x[MAX_OPT_PARAMS]; int i; List *lp; Node *np; #ifdef THREAD_SAFE_QUERY Query_Stack *qsp; assert(cs_qsp != NULL ); qsp = cs_qsp; #endif // THREAD_SAFE_QUERY getvals(x,n_prms); /* get the parameter estimates */ lp=opt_param_list(); np=QLIST_HEAD(lp); i=0; while(np!=NULL && i < n_prms ){ Opt_Param *opp; opp = (Opt_Param *)(np->n_data); opp->ans = (float) x[i]; i++; np=np->n_next; } err=(*stept_user_func)(SINGLE_QSP_ARG); setfobj(err); }
Node *first_panel_node(SINGLE_QSP_ARG_DECL) { List *lp; lp=item_list(panel_obj_itp); if( lp==NULL ) return NULL; else return(QLIST_HEAD(lp)); }
void _list_menu(QSP_ARG_DECL const Menu *mp) { List *lp; Node *np; lp = MENU_LIST(mp); np = QLIST_HEAD(lp); while( np != NULL ){ Command *cp; cp = (Command *) NODE_DATA(np); list_command(QSP_ARG cp); np = NODE_NEXT(np); } }
void _call_funcs_from_list(QSP_ARG_DECL List *lp ) { Node *np; void (*func)(SINGLE_QSP_ARG_DECL); np=QLIST_HEAD(lp); assert( np != NULL ); while( np != NULL ){ func = (void (*)(SINGLE_QSP_ARG_DECL)) NODE_DATA(np); (*func)(SINGLE_QSP_ARG); np = NODE_NEXT(np); } }
static void init_cstepit_params(SINGLE_QSP_ARG_DECL) { double xmin[MAX_OPT_PARAMS]; double xmax[MAX_OPT_PARAMS]; double deltx[MAX_OPT_PARAMS]; double delmn[MAX_OPT_PARAMS]; double ans[MAX_OPT_PARAMS]; List *lp; Node *np; Opt_Param *opp; int i,n; int nfmax; /* max. # function calls */ #ifdef THREAD_SAFE_QUERY cs_qsp = THIS_QSP; #endif // THREAD_SAFE_QUERY lp = opt_param_list(); if( lp == NULL ) return; n_prms=eltcount(lp); n=reset_n_params(n_prms); if( n != n_prms ) n_prms = n; np=QLIST_HEAD(lp); i=0; while( np!= NULL && i < n_prms ){ opp = (Opt_Param *)(np->n_data); xmin[i]=opp->minv; xmax[i]=opp->maxv; deltx[i]=opp->delta; delmn[i]=opp->mindel; ans[i]=opp->ans; i++; np=np->n_next; } nfmax=100000; /* copy to fortran */ setvals(QSP_ARG ans,n_prms); setminmax(QSP_ARG xmin,xmax,n_prms); setdelta(QSP_ARG deltx,delmn,n_prms); //advise("SETTING ntrace to 1 FOR MAX DEBUG!"); // settrace(1); setmaxcalls(nfmax); }
static void propagate_down(Data_Obj *dp,uint32_t flagbit) { Node *np; if( dp->dt_children != NULL ){ np=QLIST_HEAD(dp->dt_children); while(np!=NULL){ Data_Obj *child_dp; child_dp = (Data_Obj *)np->n_data; xfer_dobj_flag(child_dp,dp,flagbit); propagate_down(child_dp,flagbit); np = np->n_next; } } }
int list_camera_features(QSP_ARG_DECL PGR_Cam *pgcp ) { Node *np; assert( pgcp->pc_feat_lp != NULL ); np = QLIST_HEAD(pgcp->pc_feat_lp); while(np!=NULL){ dc1394feature_info_t * f; f= (dc1394feature_info_t *) np->n_data; list_camera_feature(QSP_ARG f); np=np->n_next; } return(0); }
static void _delete_subobjects(QSP_ARG_DECL Data_Obj *dp) /** delete all subimages */ { Node *np; /* * delvec() will remove the parent's child list * after deleting last child. * * List elements are de-allocated by delvec() */ while( OBJ_CHILDREN( dp ) != NULL ){ np=QLIST_HEAD( OBJ_CHILDREN( dp ) ); delvec( (Data_Obj *) NODE_DATA(np) ); } }
int get_camera_names( QSP_ARG_DECL Data_Obj *str_dp ) { // Could check format of object here... // Should be string table with enough entries to hold the modes // Should the strings be rows or multidim pixels? List *lp; Node *np; PGR_Cam *pgcp; int i, n; lp = pgc_list(); if( lp == NULL ){ WARN("No cameras!?"); return 0; } n=eltcount(lp); if( OBJ_COLS(str_dp) < n ){ sprintf(ERROR_STRING,"String object %s has too few columns (%ld) to hold %d camera names", OBJ_NAME(str_dp),(long)OBJ_COLS(str_dp),n); WARN(ERROR_STRING); n = OBJ_COLS(str_dp); } np=QLIST_HEAD(lp); i=0; while(np!=NULL){ char *dst; pgcp = (PGR_Cam *) NODE_DATA(np); dst = OBJ_DATA_PTR(str_dp); dst += i * OBJ_PXL_INC(str_dp); if( strlen(pgcp->pc_name)+1 > OBJ_COMPS(str_dp) ){ sprintf(ERROR_STRING,"String object %s has too few components (%ld) to hold camera name \"%s\"", OBJ_NAME(str_dp),(long)OBJ_COMPS(str_dp),pgcp->pc_name); WARN(ERROR_STRING); } else { strcpy(dst,pgcp->pc_name); } i++; if( i>=n ) np=NULL; else np = NODE_NEXT(np); } return i; }
Screen_Obj *find_object_at(Panel_Obj *po,int x,int y) { Node *np; Screen_Obj *sop; np=QLIST_HEAD(PO_CHILDREN(po)); while(np!=NULL){ sop=(Screen_Obj *)np->n_data; if( x >= SOB_X(sop) && x < (int) (SOB_X(sop)+SOB_DX(sop)) && y >= SOB_Y(sop) && y < (int) (SOB_Y(sop)+SOB_DY(sop)) ) return(sop); np=np->n_next; } return NULL; }
void show_panel_children(Panel_Obj *po) { Node *np; Screen_Obj *sop; np=QLIST_HEAD(PO_CHILDREN(po)); while(np!=NULL){ sop=(Screen_Obj *)np->n_data; if( sop != NULL ){ sprintf(ERROR_STRING,"\t%s",SOB_NAME(sop)); advise(ERROR_STRING); } else { advise("\tnull screen_obj!?"); } np=np->n_next; } }
void delete_opt_params(SINGLE_QSP_ARG_DECL) { List *lp; Node *np; lp = opt_param_list(); if( lp == NULL ) return; np=QLIST_HEAD(lp); while( np!= NULL ){ Opt_Param *opp; Node *next; opp = (Opt_Param *)(np->n_data); next=np->n_next; del_opt_param(opp); np=next; } }
static void search_list_for_fragment(List *lp, Frag_Match_Info *fmi_p, const char *frag) { int n; Node* np; // we might assert the this frag match is associated with a list container // but we get here from a list-specific function so should be safe... // famous last words? lp = _alpha_sort(DEFAULT_QSP_ARG lp); // BUG should sort in-place??? np = QLIST_HEAD(lp); n = (int) strlen(frag); SET_CURR_FRAG(fmi_p, NULL); // default SET_FIRST_FRAG(fmi_p, NULL); SET_LAST_FRAG(fmi_p, NULL); while( np != NULL ){ const Item *ip; int compVal; ip = NODE_DATA(np); compVal = strncmp( frag, ITEM_NAME(ip), n ); if( compVal == 0 ){ // We have found the first node that is a match, // but we want also determine the last... SET_CURR_FRAG(fmi_p, np); SET_FIRST_FRAG(fmi_p, np); SET_LAST_FRAG(fmi_p, np); np = NODE_NEXT(np); while( np != NULL ){ ip = NODE_DATA(np); compVal = strncmp( frag, ITEM_NAME(ip), n ); if( compVal != 0 ) return; SET_LAST_FRAG(fmi_p, np); np = NODE_NEXT(np); } return; } np = NODE_NEXT(np); } }
void call_funcs_from_list(QSP_ARG_DECL List *lp ) { Node *np; void (*func)(SINGLE_QSP_ARG_DECL); np=QLIST_HEAD(lp); //#ifdef CAUTIOUS // if( np == NO_NODE ){ // WARN("CAUTIOUS: call_funcs_from_list: list is empty!?"); // return; // } //#endif /* CAUTIOUS */ assert( np != NO_NODE ); while( np != NO_NODE ){ func = (void (*)(SINGLE_QSP_ARG_DECL)) NODE_DATA(np); (*func)(SINGLE_QSP_ARG); np = NODE_NEXT(np); } }
void set_choice(Screen_Obj *sop,int i) { Node *np; int n; Screen_Obj *bsop; n=0; if( SOB_CHILDREN(sop) == NULL ) return; // if no motif np=QLIST_HEAD(SOB_CHILDREN(sop)); while( np != NO_NODE ){ bsop = (Screen_Obj *)NODE_DATA(np); if( n == i ) set_toggle_state(bsop,1); else set_toggle_state(bsop,0); n++; np=NODE_NEXT(np); } }
int get_feature_choices( PGR_Cam *pgcp, const char ***chp ) { int n; const char * /* const */ * sptr; Node *np; n=eltcount(pgcp->pc_feat_lp); if( n <= 0 ) return(0); sptr = (const char **) getbuf( n * sizeof(char *) ); *chp = sptr; np=QLIST_HEAD(pgcp->pc_feat_lp); while(np!=NULL){ dc1394feature_info_t *f; f= (dc1394feature_info_t *) np->n_data; *sptr = /*(char *)dc1394_feature_desc[f->id - DC1394_FEATURE_MIN]*/ dc1394_feature_get_string(f->id) ; sptr++; np=np->n_next; } return n; }
static void cstepit_scr_funk(void) { char str[128]; float err; Variable *vp; int i; List *lp; Node *np; double ans[MAX_OPT_PARAMS]; #ifdef THREAD_SAFE_QUERY Query_Stack *qsp; assert(cs_qsp != NULL ); qsp = cs_qsp; #endif // THREAD_SAFE_QUERY /* ooh, icky: getvals fetches global vars from cstepit module... */ getvals(ans,n_prms); if( opt_func_string==NULL ){ warn("No optimization string defined"); return; } lp=_opt_param_list(SGL_DEFAULT_QSP_ARG); if( lp == NULL ){ warn("No optimization parameters to vary!?"); err=0.0; setfobj((double)err); return; } np=QLIST_HEAD(lp); /* stepit has passed us params in the ans array - * we want to get them into named variables... */ i=0; while(np!=NULL && i < n_prms ){ Opt_Param *opp; opp = (Opt_Param *)( np->n_data); sprintf(str,"%g",ans[i]); /* why add 1? fortan? */ _assign_var(DEFAULT_QSP_ARG opp->op_name,str); i++; np=np->n_next; } /* We used to call pushtext here, but we like digest * because it automatically pushes and pops the top menu. * * chew_text doesn't work, however, because it doesn't block * the interpreter, which returns to the terminal... * * We have a problem - calling optimization from another callback * function causes it to exit when done!? * It turns out that that was because older scripts (written * for the old version that didn't push the top menu automatically) * didn't have a quit after the call to optimize - ??? */ digest(opt_func_string, OPTIMIZER_FILENAME); vp=var__of("error"); if( vp == NULL ) { warn(ERROR_STRING); sprintf(ERROR_STRING, "variable \"error\" not set by script fragment \"%s\"!?", opt_func_string); err=0.0; } else sscanf(VAR_VALUE(vp),"%g",&err); setfobj((double)err); }
void report_feature_info(QSP_ARG_DECL PGR_Cam *pgcp, dc1394feature_t id ) { Node *np; dc1394feature_info_t *f; unsigned int i; const char *name; char nbuf[32]; np = QLIST_HEAD(pgcp->pc_feat_lp); f=NULL; while( np != NULL ){ f= (dc1394feature_info_t *) np->n_data; if( f->id == id ) np=NULL; else f=NULL; if( np != NULL ) np = np->n_next; } assert( f != NULL ); name=/*dc1394_feature_desc[f->id - DC1394_FEATURE_MIN]*/ dc1394_feature_get_string(f->id); sprintf(nbuf,"%s:",name); sprintf(msg_str,"%-16s",nbuf); prt_msg_frag(msg_str); if (f->on_off_capable) { if (f->is_on) prt_msg_frag("ON\t"); else prt_msg_frag("OFF\t"); } else { prt_msg_frag("\t"); } /* if (f->one_push){ if (f->one_push_active) prt_msg_frag(" one push: ACTIVE"); else prt_msg_frag(" one push: INACTIVE"); } prt_msg(""); */ /* BUG need to use (new?) feature_get_modes... */ /* FIXME */ /* if( f->auto_capable ){ if (f->auto_active) prt_msg_frag("AUTO\t"); else prt_msg_frag("MANUAL\t"); } else { prt_msg_frag("\t"); } */ /* prt_msg(""); */ /* if( f->id != DC1394_FEATURE_TRIGGER ){ sprintf(msg_str,"\tmin: %d max %d", f->min, f->max); prt_msg(msg_str); } if( f->absolute_capable){ sprintf(msg_str,"\tabsolute settings: value: %f min: %f max: %f", f->abs_value,f->abs_min,f->abs_max); prt_msg(msg_str); } */ switch(f->id){ case DC1394_FEATURE_TRIGGER: switch(f->trigger_modes.num){ case 0: prt_msg("no trigger modes available"); break; case 1: sprintf(msg_str,"one trigger mode (%s)", name_for_trigger_mode(f->trigger_modes.modes[0])); prt_msg(msg_str); break; default: sprintf(msg_str,"%d trigger modes (",f->trigger_modes.num); prt_msg_frag(msg_str); for(i=0;i<f->trigger_modes.num-1;i++){ sprintf(msg_str,"%s, ", name_for_trigger_mode(f->trigger_modes.modes[i])); prt_msg_frag(msg_str); } sprintf(msg_str,"%s)", name_for_trigger_mode(f->trigger_modes.modes[i])); prt_msg(msg_str); break; } break; /* printf("\n\tAvailableTriggerModes: "); if (f->trigger_modes.num==0) { printf("none"); } else { int i; for (i=0;i<f->trigger_modes.num;i++) { printf("%d ",f->trigger_modes.modes[i]); } } printf("\n\tAvailableTriggerSources: "); if (f->trigger_sources.num==0) { printf("none"); } else { int i; for (i=0;i<f->trigger_sources.num;i++) { printf("%d ",f->trigger_sources.sources[i]); } } printf("\n\tPolarity Change Capable: "); if (f->polarity_capable) printf("True"); else printf("False"); printf("\n\tCurrent Polarity: "); if (f->trigger_polarity) printf("POS"); else printf("NEG"); printf("\n\tcurrent mode: %d\n", f->trigger_mode); if (f->trigger_sources.num>0) { printf("\n\tcurrent source: %d\n", f->trigger_source); } */ case DC1394_FEATURE_WHITE_BALANCE: case DC1394_FEATURE_TEMPERATURE: case DC1394_FEATURE_WHITE_SHADING: warn("unhandled case in feature type switch"); break; default: sprintf(msg_str,"value: %-8d range: %d-%d",f->value,f->min,f->max); prt_msg(msg_str); break; } }
static void _dump_node_basic(QSP_ARG_DECL Vec_Expr_Node *enp) { Tree_Code code; int i; const char *s; if( enp==NULL ) return; /* print the node "name", and a code that tells about shape knowledge */ // Temporarily print to stderr instead of stdout for debugging... prt_node(enp,msg_str); prt_msg_frag(msg_str); if( SHOWING_LHS_REFS ){ sprintf(msg_str,"\t%d",VN_LHS_REFS(enp)); prt_msg_frag(msg_str); } if( SHOWING_COST ){ if( VN_SHAPE(enp) != NULL ){ sprintf(msg_str,"\t%d", SHP_N_MACH_ELTS(VN_SHAPE(enp))); } prt_msg_frag(msg_str); sprintf(msg_str,"\t%d\t%d", VN_FLOPS(enp),VN_N_MATH(enp)); prt_msg_frag(msg_str); } if( IS_CURDLED(enp) ){ sprintf(msg_str,"\t%s (curdled!?)", NNAME(enp)); prt_msg(msg_str); return; } sprintf(msg_str,"\t%s", NNAME(enp)); prt_msg_frag(msg_str); /* print the special op-dependent args in human-readable form */ code = VN_CODE(enp); if( code==T_DYN_OBJ || code == T_UNDEF || code == T_PROTO || code==T_POINTER || code==T_FUNCPTR || code==T_STR_PTR ){ sprintf(msg_str,"\t%s",VN_STRING(enp)); prt_msg_frag(msg_str); if( code == T_POINTER ){ Identifier *idp; /* We don't use get_set_ptr() here because we don't want an error msg... */ idp = id_of(VN_STRING(enp)); if( idp != NULL && IS_POINTER(idp) && POINTER_IS_SET(idp) ){ if( PTR_REF(ID_PTR(idp)) == NULL ){ /* how could this ever happen??? */ prt_msg_frag("->???"); } else { Data_Obj *dp; dp = REF_OBJ(PTR_REF(ID_PTR(idp))); sprintf(msg_str,"->%s",OBJ_NAME(dp)); prt_msg_frag(msg_str); } } } } else if( code == T_STATIC_OBJ ){ sprintf(msg_str,"\t%s",OBJ_NAME(VN_OBJ(enp))); prt_msg_frag(msg_str); #ifdef SCALARS_NOT_OBJECTS } else if( code == T_SCALAR_VAR ){ sprintf(msg_str,"\t%s",VN_STRING(enp)); prt_msg_frag(msg_str); #endif // SCALARS_NOT_OBJECTS } else if ( code == T_FUNCREF ){ Subrt *srp; srp=VN_SUBRT(enp); sprintf(msg_str,"\t%s",SR_NAME(srp)); prt_msg_frag(msg_str); } else if( code == T_SIZE_FN ){ sprintf(msg_str,"\t%s",FUNC_NAME(VN_FUNC_PTR(enp))); prt_msg_frag(msg_str); } #ifdef NOT_YET else if(code == T_CALL_NATIVE ){ // was kw_token??? // curr_native_func_tbl... sprintf(msg_str,"\t%s",FUNC_NAME(VN_FUNC_PTR(enp))); prt_msg_frag(msg_str); } #endif /* NOT_YET */ else if(code == T_TYPECAST ){ // BUG not how we do precision any more!!! //sprintf(msg_str," %s",NAME_FOR_PREC_CODE(VN_INTVAL(enp))); if( VN_SHAPE(enp) == NULL ) error1("CAUTIOUS: null node shape for typecast node!?"); else { sprintf(msg_str," %s",PREC_NAME(VN_PREC_PTR(enp))); prt_msg_frag(msg_str); } } else if( code == T_SUBRT_DECL || code == T_SCRIPT ){ Subrt *srp; srp=VN_SUBRT(enp); sprintf(msg_str,"\t%s",SR_NAME(srp)); prt_msg_frag(msg_str); } else if( code==T_DECL_STAT ){ //sprintf(msg_str," %s",NAME_FOR_PREC_CODE(VN_INTVAL(enp))); sprintf(msg_str," %s",PREC_NAME(VN_DECL_PREC(enp))); prt_msg_frag(msg_str); } else if( IS_DECL(code) ){ sprintf(msg_str," %s",VN_STRING(enp)); prt_msg_frag(msg_str); } else if( code==T_ADVISE ){ /* BUG need to elim yylex_qsp */ s=eval_string(VN_CHILD(enp,0)); sprintf(msg_str,"\t\"%s\"",s); prt_msg_frag(msg_str); } else if( code==T_WARN ){ /* BUG need to elim yylex_qsp */ s=eval_string(VN_CHILD(enp,0)); sprintf(msg_str,"\t\"%s\"",s); prt_msg_frag(msg_str); } else if( code==T_STRING ){ sprintf(msg_str,"\t\"%s\"",VN_STRING(enp)); prt_msg_frag(msg_str); } else if( code == T_LABEL || code ==T_GO_BACK || code == T_GO_FWD ){ sprintf(msg_str," %s",VN_STRING(enp)); prt_msg_frag(msg_str); } else if( code==T_LIT_DBL ){ sprintf(msg_str," %g",VN_DBLVAL(enp)); prt_msg_frag(msg_str); } else if( code == T_MATH0_FN ){ sprintf(msg_str," %s",FUNC_NAME(VN_FUNC_PTR(enp))); prt_msg_frag(msg_str); } else if( code == T_MATH1_FN ){ sprintf(msg_str," %s",FUNC_NAME(VN_FUNC_PTR(enp))); prt_msg_frag(msg_str); } else if( code == T_MATH2_FN ){ sprintf(msg_str," %s",FUNC_NAME(VN_FUNC_PTR(enp))); prt_msg_frag(msg_str); } else if ( code == T_MATH0_VFN || code == T_MATH1_VFN || code == T_MATH2_VFN || code == T_MATH2_VSFN || code == T_CHAR_VFN /* BUG? shouldn't there bre a VSFN2 ??? */ || code == T_VS_FUNC || code == T_VV_FUNC ){ sprintf(msg_str," %s",VF_NAME(FIND_VEC_FUNC(VN_VFUNC_CODE(enp)))); prt_msg_frag(msg_str); } else if( code==T_CALLFUNC ){ assert(VN_SUBRT(enp)!=NULL); sprintf(msg_str," %s", SR_NAME(VN_SUBRT(enp))); prt_msg_frag(msg_str); } else if( code==T_LIT_INT ){ sprintf(msg_str," %"PRId64, VN_INTVAL(enp) ); prt_msg_frag(msg_str); } else if( code==T_ASSIGN ){ prt_msg_frag("\t"); } else if( code==T_MAXVAL ){ prt_msg_frag("\t"); } else if( code==T_MINVAL ){ prt_msg_frag("\t"); } else if( code==T_RAMP ){ prt_msg_frag("\t"); } /* Now print the addresses of the child nodes */ if( VN_CHILD(enp,0)!=NULL){ sprintf(msg_str,"\t\tn%d",VN_SERIAL(VN_CHILD(enp,0))); prt_msg_frag(msg_str); } for(i=1;i<MAX_CHILDREN(enp);i++){ if( VN_CHILD(enp,i)!=NULL){ sprintf(msg_str,", n%d",VN_SERIAL(VN_CHILD(enp,i))); prt_msg_frag(msg_str); } } prt_msg(""); if( SHOWING_SHAPES && VN_SHAPE(enp) != NULL ){ prt_msg_frag("\t"); if( OWNS_SHAPE(enp) ){ sprintf(msg_str,"* 0x%lx ",(u_long)VN_SHAPE(enp)); prt_msg_frag(msg_str); } else { sprintf(msg_str,"@ 0x%lx ",(u_long)VN_SHAPE(enp)); prt_msg_frag(msg_str); } prt_msg_frag("\t"); describe_shape(VN_SHAPE(enp)); } if( SHOWING_RESOLVERS && VN_RESOLVERS(enp)!=NULL ){ Node *np; Vec_Expr_Node *enp2; prt_msg("\tResolvers:"); np=QLIST_HEAD(VN_RESOLVERS(enp)); while(np!=NULL){ enp2=(Vec_Expr_Node *)NODE_DATA(np); sprintf(msg_str,"\t\t%s",node_desc(enp2)); prt_msg(msg_str); np=NODE_NEXT(np); } } }