void del_so(QSP_ARG_DECL Screen_Obj *sop) { del_scrnobj(sop); // delete from database... if( SOB_ACTION(sop) != NULL ) rls_str(SOB_ACTION(sop)); if( SOB_SELECTOR(sop) != NULL ) rls_str(SOB_SELECTOR(sop)); }
void close_pipe(QSP_ARG_DECL Pipe *pp) { if( pp->p_fp != NULL && pclose(pp->p_fp) == -1 ){ sprintf(ERROR_STRING,"Error closing pipe \"%s\"!?",pp->p_name); WARN(ERROR_STRING); } del_pipe(QSP_ARG pp); rls_str(pp->p_name); rls_str(pp->p_cmd); }
void _log_message(QSP_ARG_DECL const char *msg) { const char *log_time; log_time = get_date_string(SINGLE_QSP_ARG); if( HAS_PREV_LOG_MSG(THIS_QSP) ){ if( !strcmp(msg,PREV_LOG_MSG(THIS_QSP)) ){ INCREMENT_LOG_MSG_COUNT(THIS_QSP); return; } else { unsigned long c; if( (c=LOG_MSG_COUNT(THIS_QSP)) > 1 ){ sprintf(ERROR_STRING, "%s: previous message was repeated %ld time%s", log_time,c-1,c==2?"":"s"); advise(ERROR_STRING); } } rls_str(PREV_LOG_MSG(THIS_QSP)); } else { SET_QS_FLAG_BITS(THIS_QSP,QS_HAS_PREV_LOG_MSG); } sprintf(ERROR_STRING,"%s: %s", log_time,msg); advise(ERROR_STRING); SET_PREV_LOG_MSG(THIS_QSP,savestr(msg)); SET_LOG_MSG_COUNT(THIS_QSP,1); }
Disp_Obj *open_display(QSP_ARG_DECL const char *name,int desired_depth) { Disp_Obj *dop; static int siz_done=0; dop = new_disp_obj(QSP_ARG name); if( dop == NO_DISP_OBJ ){ sprintf(ERROR_STRING, "Couldn't create object for display %s", name); NWARN(ERROR_STRING); return(NO_DISP_OBJ); } if( dop_open(QSP_ARG dop) < 0 ){ return(NO_DISP_OBJ); } if( dop_setup(QSP_ARG dop,desired_depth) < 0 ){ /* Bug - XCloseDisplay?? */ /* need to destroy object here */ del_disp_obj(QSP_ARG dop); rls_str((char *)dop->do_name); return(NO_DISP_OBJ); } set_display(dop); if( ! siz_done ){ siz_done++; add_sizable(QSP_ARG disp_obj_itp,&dpy_sf, NULL ); } return(dop); }
static int dop_open( QSP_ARG_DECL Disp_Obj *dop ) { /* BUG - on Solaris, when we have DISPLAY set to :0, * but are on a remote server, this call hangs... * (e.g., run iview on vision from xterm on stiles, * w/ DISPLAY erroneously set to :0 instead of stiles:0) * We ought to put a watchdog timer here... */ if ( (dop->do_dpy=XOpenDisplay(dop->do_name)) == NULL) { sprintf(ERROR_STRING, "dop_open: Can't open display \"%s\"\n",dop->do_name); NWARN(ERROR_STRING); /* remove the object */ del_disp_obj(QSP_ARG dop); rls_str((char *)dop->do_name); return(-1); } return(0); }
static void _make_zombie(QSP_ARG_DECL Data_Obj *dp) { static int n_zombie=1; char zname[LLEN]; /* this function removes it from the hash table and * active item list, doesn't add the structure to the * item free list. This is why we release the node * and later free the object... * * I think the idea here is that there might be a dangling reference * to an image - for instance, if we display an image, then delete it, * and then later want to refresh the window... */ zombie_item(dobj_itp,(Item *)dp); sprintf(zname,"Z.%s.%d",OBJ_NAME(dp),n_zombie++); fprintf(stderr,"make_zombie, changing object %s to %s\n",OBJ_NAME(dp),zname); rls_str( (char *) OBJ_NAME(dp) ); /* unsave old name, make_zombie */ SET_OBJ_NAME(dp,savestr(zname)); SET_OBJ_FLAG_BITS(dp,DT_ZOMBIE); } // make_zombie
void _delvec(QSP_ARG_DECL Data_Obj *dp) { assert(dp!=NULL); assert(OBJ_NAME(dp)!=NULL); #ifdef ZOMBIE_SUPPORT // This should go back in eventually! if( OBJ_FLAGS(dp) & DT_STATIC && OWNS_DATA(dp) ){ sprintf(ERROR_STRING,"delvec: static object %s will be made a zombie",OBJ_NAME(dp)); advise(ERROR_STRING); make_zombie(dp); return; } if( OBJ_REFCOUNT(dp) > 0 ){ /* This zombie business was introduced at a time * when a displayed image had to be kept around * to refresh its window... with the current * X windows implementation of viewers that is * no longer the case, so this may be unecessary... * * But another case arises when we have a static * object in the expression language, that gets * deleted outside of the expression language. * This shouldn't be done, but we don't want to * be able to crash the program either... */ sprintf(ERROR_STRING,"delvec: object %s (refcount = %d) will be made a zombie",OBJ_NAME(dp),dp->dt_refcount); advise(ERROR_STRING); make_zombie(dp); return; } #endif /* ZOMBIE_SUPPORT */ // If the object has been exported, we need to delete // the associated identifier... // // BUT if it was exported, then it may be referenced!? // So it should be static... // // If we have references, and are therefore keeping the // object as a zombie, then we don't want to delete the // identifier, and we probably don't want to change the // object's name... if( IS_EXPORTED(dp) ){ Identifier *idp; idp = id_of(OBJ_NAME(dp)); assert( idp != NULL ); delete_id((Item *)idp); } if( OBJ_CHILDREN( dp ) != NULL ){ delete_subobjects(dp); } if( OBJ_PARENT(dp) != NULL ){ disown_child(dp); } if( IS_TEMP(dp) ){ if( OBJ_DECLFILE(dp) != NULL ){ sprintf(ERROR_STRING,"delvec %s: temp object has declfile %s!?\n", OBJ_NAME(dp),OBJ_DECLFILE(dp)); advise(ERROR_STRING); } release_tmp_obj(dp); /* * Most likely called when parent is deleted. * Temp objects are not hashed, and are not dynamically * allocated. * * Simply mark as free by clearing name field. */ return; } // We might clean this up by making the release // function a platform member... if( OWNS_DATA(dp) ){ if( ! UNKNOWN_SHAPE(OBJ_SHAPE(dp)) ){ release_data(dp); } } // In the first OpenCL implementation, we used subbuffers, which had // to be released here even for subimages. But now we handle subobjects // ourselves, managing offsets, so non-data-owners don't need to release. rls_shape( OBJ_SHAPE(dp) ); // We don't need to do this if we have garbage collection? /* The name might be null if we had an error creating the object... */ if( OBJ_DECLFILE(dp) != NULL ){ rls_str( OBJ_DECLFILE(dp) ); } #ifdef ZOMBIE_SUPPORT /* BUG context code assumes that this is really deleted... */ // not sure I understand the above comment? if( IS_ZOMBIE(dp) ){ // The object is a zombie that is no longer referenced... /* NOTE: we used to release the struct here with givbuf, * but in the current implementation of the item package, * objects aren't allocated with getbuf! */ // The object has already been removed from the dictionary, // so we don't need to call del_item... /* put this back on the free list... */ recycle_item(dobj_itp,dp); } else { del_item(dobj_itp, dp ); } #else /* ! ZOMBIE_SUPPORT */ DELETE_OBJ_ITEM(dp); // del_dobj - item function #endif /* ! ZOMBIE_SUPPORT */ // used to release the name here // and set to null, but that is done in del_item }
static COMMAND_FUNC( do_slct_obj ) { int x, y; const char *s; GLuint n_names, *ptr; GLint hits; GLuint this_hit=0; /* initialize to silence compiler */ GLuint the_hit; float z1,z2; float z_this,z_min; int clickWindowSize = 1; GLint viewport[4]; GLint i; GLuint j; char ret_str[32]; x=(int)HOW_MANY("x location"); y=(int)HOW_MANY("y location"); s=NAMEOF("scene render command"); s=savestr(s); //glPushMatrix(); glSelectBuffer(MAX_SELECT,selectBuf); check_gl_error("glSelectBuffer"); glRenderMode(GL_SELECT); check_gl_error("glRenderMode"); glMatrixMode(GL_PROJECTION); check_gl_error("glMatrixMode"); glPushMatrix(); check_gl_error("glPushMatrix"); glLoadIdentity(); check_gl_error("glLoadIdentity"); glGetIntegerv(GL_VIEWPORT,viewport); check_gl_error("glGetIntegerv"); gluPickMatrix(x,viewport[3]-y, clickWindowSize,clickWindowSize,viewport); check_gl_error("gluPickMatrix"); // Setup camera. //drawer.setupCamera(&manager); //glMatrixMode(GL_MODELVIEW); glInitNames(); check_gl_error("glInitNames"); glPushName(0); check_gl_error("glPushName"); //drawer.drawAirspace(&manager, &table); /* Call the user's draw routine here... */ chew_text(s, "(gl object selection)" ); rls_str(s); // Restoring the original projection matrix. glMatrixMode(GL_PROJECTION); check_gl_error("glMatrixMode GL_PROJECTION"); glPopMatrix(); check_gl_error("glPopMatrix"); glMatrixMode(GL_MODELVIEW); check_gl_error("glMatrixMode GL_MODELVIEW"); glFlush(); check_gl_error("glFlush"); // Returning to normal rendering mode. hits = glRenderMode(GL_RENDER); //printf ("hits = %d\n", hits); // Red book example. // When there are multiple objects, the hits are recorded // in drawing order, we have to check the z values to know // which is the foreground object. z_min=100000; ptr = (GLuint *) selectBuf; for (i = 0; i < hits; i++) { n_names = *ptr++; z1= ((float)*ptr++)/0x7fffffff; z2= ((float)*ptr++)/0x7fffffff; if( z1 < z2 ) z_this = z1; else z_this=z2; if( z_this < z_min ) z_min=z_this; for(j=0;j<n_names;j++){ this_hit=*ptr++; } // sprintf(ERROR_STRING,"Hit %d, %d from %g to %g, last is %d", // i,n_names,z1,z2,this_hit); // advise(ERROR_STRING); } the_hit=0; ptr = (GLuint *) selectBuf; for (i = 0; i < hits; i++) { n_names = *ptr++; z1= ((float)*ptr++)/0x7fffffff; z2= ((float)*ptr++)/0x7fffffff; if( z1 < z2 ) z_this = z1; else z_this=z2; for(j=0;j<n_names;j++){ this_hit=*ptr++; } if( z_this == z_min ) the_hit=this_hit; } //sprintf(ERROR_STRING,"front-most hit is %d",the_hit); //advise(ERROR_STRING); sprintf(ret_str,"%d",the_hit); assign_reserved_var("selection_index",ret_str); //if (hits != 0) { //manager.advanceTrial(processHits()); //} //glPopMatrix(); /* Set a variable to indicate what happened */ }
static void release_container(Container *cnt_p) { rls_str((char *)cnt_p->name); givbuf(cnt_p); }
long _recv_img_file(QSP_ARG_DECL Port *mpp, /* char **bufp */ Packet *pkp ) { long len; Image_File *old_ifp, *new_ifp; char namebuf[LLEN]; Image_File imgf, *ifp; long code; ifp=(&imgf); len=get_port_int32(mpp); if( len <= 0 ) goto error_return; #ifdef QUIP_DEBUG if( debug & debug_data ){ sprintf(ERROR_STRING, "recv_file: want %ld name bytes",len); advise(ERROR_STRING); } #endif /* QUIP_DEBUG */ if( (ifp->if_nfrms = get_port_int32(mpp)) == BAD_PORT_LONG || (ifp->if_ftp = filetype_for_code( QSP_ARG (filetype_code) get_port_int32(mpp))) == NULL || (ifp->if_flags = (short) get_port_int32(mpp)) == (short)BAD_PORT_LONG ){ warn("error getting image file data"); goto error_return; } if( len > LLEN ){ warn("more than LLEN name chars!?"); goto error_return; } if( read_port(mpp,namebuf,len) != len ){ warn("recv_file: error reading data object name"); goto error_return; } /* where does the string get null-terminated? */ if( (long)strlen( namebuf ) != len-1 ){ u_int i; sprintf(ERROR_STRING,"name length %ld, expected %ld", (long)strlen(namebuf), len-1); advise(ERROR_STRING); sprintf(ERROR_STRING,"name: \"%s\"",namebuf); advise(ERROR_STRING); for(i=0;i<strlen(namebuf);i++){ sprintf(ERROR_STRING,"name[%d] = '%c' (0%o)", i,namebuf[i],namebuf[i]); advise(ERROR_STRING); } error1("choked"); } old_ifp=img_file_of(namebuf); if( old_ifp != NULL ){ del_img_file(old_ifp); rls_str((char *)old_ifp->if_name); // BUG? release name here or not? old_ifp = NULL; } new_ifp=new_img_file(namebuf); if( new_ifp==NULL ){ sprintf(ERROR_STRING, "recv_file: couldn't create file struct \"%s\"", namebuf); warn(ERROR_STRING); goto error_return; } new_ifp->if_nfrms = imgf.if_nfrms; new_ifp->if_ftp = filetype_for_code(QSP_ARG IFT_NETWORK); new_ifp->if_flags = imgf.if_flags; new_ifp->if_dp = NULL; /* BUG should receive? */ new_ifp->if_pathname = new_ifp->if_name; code = get_port_int32(mpp); if( code == -1 ) error1("error port code received!?"); if( code != P_DATA ){ sprintf(ERROR_STRING, "recv_file: expected data object packet to complete transmission of file %s!?", new_ifp->if_name); error1(ERROR_STRING); } // the cast generates a compiler warning??? if( recv_obj(mpp, pkp ) != sizeof(Data_Obj) ){ warn("Error receiving data object!?"); goto error_return; } // The packet returns the dp in pk_extra... return sizeof(*new_ifp); // BUG - what size should we return??? error_return: return -1; }
void rls_stringref( String_Ref *srp ) { rls_str(srp->sr_string); givbuf(srp); }