int thRemoveFromList(int handle, char *pattern) { thNameList *list; thNameNode *this,**thisp; char **vlist; /* List of characters matching pattern */ int count; /* Number of variables being removed */ int nremove; int i; #ifdef BIT64 list = (thNameList *) handle_list[handle-1]; #else list = (thNameList *) handle; #endif daVarList(pattern,&vlist,&count); nremove = 0; for(i=0; i<count; i++) { this = list->namehead; /* Start of list */ thisp = &list->namehead; /* Pointer to next field of previous name */ while(this) { if(strcasecmp(this->name,vlist[i])==0) { /* Remove matching string */ *thisp = this->next; free(this->name); free(this); this = *thisp; nremove++; } else { thisp = &(this->next); this = this->next; } } } list->nnames -= nremove; /* Perhaps I should just count when needed ? */ return(list->nnames); }
int thAddToList(int handle, char *pattern) /* Add registered variables to a list of variables to get from a server Return the number of variables added Should we check for duplicates? Not now. No harm in duplicates. thRemoveFromList will remove all duplicates though. */ { thNameList *list; thNameNode *next,*this; char **vlist; /* List of characters matching pattern */ int count; /* Number of variables being added */ int i; #ifdef BIT64 list = (thNameList *) handle_list[handle-1]; #else list = (thNameList *) handle; #endif daVarList(pattern,&vlist,&count); for(i=0; i<count; i++) { next = list->namehead; /* The current list */ this = list->namehead = (thNameNode *) malloc(sizeof(thNameNode)); /* New name */ this->name = (char *) malloc(strlen(vlist[i])+1); strcpy(this->name,vlist[i]); this->next = next; /* Attach rest of list */ } list->nnames += count; /* Perhaps I should just count when needed ? */ list->rpc_made = 0; /* RPC format list now out of date. */ return(list->nnames); }
thStatus thOBook() /* Book all the parameter, tests, and histograms and anything else that is in the booking order list. This is the pre-group booking routine. Within each class it booked blocks in alphabetical order. */ { thBookList *booklist; /* Need to find a way to make sure these are called by anything else that might do booking. Perhaps need a thInit routine. */ /* printf("In thBook\n");*/ if (!thBookListP) { /* Booking order not defined */ if(thSetBlockClasses() != S_SUCCESS){ fprintf(STDERR,"Failed to set the th Block Class handlers\n"); return(S_FAILURE); } } booklist = thBookListP; while(booklist){ char *prefix; char **blist0; char **blist; int count; daVarStruct var, *bvar; if(daVarLookup(booklist->classname,&var) != S_SUCCESS){ fprintf(STDERR,"Failed to find class variable %s\n",booklist->classname); return(S_FAILURE); } prefix = (char *) malloc(strlen(booklist->classname) + 2); strcpy(prefix,booklist->classname); strcat(prefix,"."); daVarList(prefix,&blist0,&count); blist = blist0; while(count-- > 0){ thStatus stat; /* printf("Booking %s\n",*blist); */ if(daVarLookupP(*blist,&bvar) != S_SUCCESS){ fprintf(STDERR,"Failed to find %s\n",*blist); return(S_FAILURE); } if(!bvar->varptr) { /* Only book those not already booked */ bvar->varptr = (DAINT *) malloc(sizeof(DAINT)); *((DAINT *) bvar->varptr) = 0; /* Initializec execution counter */ stat = ((thStatus (*)()) var.opaque)(bvar); } blist++; } daVarFreeList(blist0); booklist = booklist->next; } return(S_SUCCESS); }
NAMELIST * davar_getlist_1(char **argp, CLIENT *clnt) { static NAMELIST result= {0,0}; char **list; int i, count; if(result.NAMELIST_val) { /* printf("Freeing previous list\n");*/ daVarFreeList(result.NAMELIST_val); } daVarList(*argp,&list,&count); /* Check error code */ result.NAMELIST_len = count; result.NAMELIST_val = list; return(&result); }