int testbench() { List *testList = (List*)malloc(sizeof(List)); list_init(testList); int x = 8; list_insert(testList, NULL, x); list_insert(testList, NULL, 3); printf("size %d\n", list_size(testList)); print_list_int(testList); printf("remove 3\n"); list_remove(testList, 3); print_list_int(testList); printf("remove 8\n"); list_remove(testList, 8); print_list_int(testList); printf("remove 2\n"); list_remove(testList, 2); print_list_int(testList); printf("%d\n", list_search(testList, 4)); printf("%d\n", list_search(testList, 3)); printf("%d\n", list_search(testList, 2)); return 0; };
static void test_search(void) { int *num, val, i; val = 5; i = list_search(list_d, compare_int, &val); assert(!(i != 5)); num = list_getel(list_d, i); assert(!(num != list_d->v[5])); assert(!(*num != 5)); /* Now I delete it and search again */ list_del(list_d, 5); assert(!(list_d->v[5] != NULL)); i = list_search(list_d, compare_int, &val); assert(!(i != -1)); num = list_getel(list_d, i); assert(!(num != NULL)); /* Now I try to get an element with negative or too big index */ num = list_getel(list_d, -1); assert(!(num != NULL)); free(num); num = list_getel(list_d, -2); assert(!(num != NULL)); free(num); num = list_getel(list_d, 12345); assert(!(num != NULL)); free(num); }
int ini_append(INI *pini,const char *key,const char *value) { ini_item *item, *sear, *temp; char buffer[LINE_LEN]; char *k, *v, *s, *p; strcpy(buffer,key); if (NULL == (p=strchr(buffer,'.'))) { if (pini->header) strcpy(buffer,pini->header->section); else strcpy(buffer,DEF_SECT_ROOT); strcat(buffer,"."); strcat(buffer,key); } else if (p == buffer) { strcpy(buffer,pini->header->section); strcat(buffer,key); } else if ((unsigned int)(p+1-buffer) == strlen(buffer)) return 0; p = strchr(buffer,'.'); sear = list_search(pini,buffer); if (sear && 0==strcmp(sear->key,p+1)) return 0; item = (ini_item *)malloc(sizeof(ini_item)); k = (char *)malloc(strlen(key)+1); strcpy(k,p+1); item->key = k; v = (char *)malloc(strlen(value)+1); strcpy(v,value); item->value = v; *(p+1) = 0; sear = list_search(pini,buffer); if (sear) { s = (char *)malloc(strlen(sear->section)+1); strcpy(s,sear->section); temp = sear->next; sear->next = item; item->next = temp; } else { *p = 0; s = (char *)malloc(strlen(buffer)+1); strcpy(s,buffer); item->next = NULL; if (pini->header) { pini->tailer->next = item; pini->tailer = item; } else pini->header = pini->tailer = item; } item->section = s; pini->length += 1; return 1; }
bag::size_type bag::count(const value_type& target) const { size_type answer; const node *cursor; answer = 0; cursor = list_search(head_ptr, target); while (cursor != NULL) { ++answer; cursor = cursor->link( ); cursor = list_search(cursor, target); } return answer; }
//출금 void ma_cancel() { int num,i; char ch; char num1[20]; Member* cur; printf("[1] 전화번호 [2] 예약 번호\n"); while(1) { scanf("%d",&num); if(num==1) { printf("전화번호 입력: "); fflush(stdin); gets(num1); cur=list_search(&g_list,num1); break; } else if(num==2) { printf("예약번호 입력: "); fflush(stdin); gets(num1); cur=list_search(&g_list,num1); break; } else { printf("다시 입력하세요..\n"); continue; } } if(cur != NULL) list_print(cur); else { printf("예약정보를 찾을수 없음..\n"); return; } printf("\n위 예약을 취소할까요? : (y, n)"); scanf("%c",&ch); if(ch=='y' || ch=='Y') { free(cur); for(i=0; i < cur->count ;i++); g_arr.data[cur->seat[i]-1]=NULL; } else return; }
bag::size_type bag::erase(const value_type& target) { size_type answer = 0; node *target_ptr; target_ptr = list_search(head_ptr, target); while (target_ptr != NULL) { target_ptr->set_data( head_ptr->data( ) ); target_ptr = target_ptr->link( ); target_ptr = list_search(target_ptr, target); list_head_remove(head_ptr); --many_nodes; ++answer; } return answer; }
static int root_client_find( IN nfs41_root *root, IN const nfs41_exchange_id_res *exchangeid, IN bool_t is_data, OUT nfs41_client **client_out) { struct cl_exid_info info; struct list_entry *entry; int status; dprintf(NSLVL, "--> root_client_find()\n"); info.exchangeid = exchangeid; info.roles = nfs41_exchange_id_flags(is_data) & EXCHGID4_FLAG_MASK_PNFS; entry = list_search(&root->clients, &info, cl_exid_compare); if (entry) { *client_out = client_entry(entry); status = NO_ERROR; dprintf(NSLVL, "<-- root_client_find() returning 0x%p\n", *client_out); } else { status = ERROR_FILE_NOT_FOUND; dprintf(NSLVL, "<-- root_client_find() failed with %d\n", status); } return status; }
void cmd_luntag(int argc, char **argv) { int i; OPT_HELP_NEW(_("Remove files from the local tag list."), "luntag [options] <filemask>...", NULL); minargs(1); if(list_numitem(gvLocalTagList) == 0) { printf(_("nothing tagged -- use 'ltag' to tag files\n")); return; } for(i=1;i<argc;i++) { bool del_done = false; listitem *li; while((li = list_search(gvLocalTagList, (listsearchfunc)ltagcmp, argv[i])) != 0) { printf("%s\n", (const char *)li->data); list_delitem(gvLocalTagList, li); del_done = true; } if(!del_done) printf(_("%s: no matches found\n"), argv[i]); } }
int ini_remove(INI *pini,const char *key) { ini_item *item, *temp, *p; item = list_search(pini,key); if (!item) return 0; p = pini->header; if (p && !p->next) { if (p != item) return 0; free(p->section); free(p->key); free(p->value); free(item); pini->header = pini->tailer = NULL; pini->length -= 1; return 1; } while (p && p->next) { if (p->next == item) break; p = p->next; } if (!p || !p->next) return 0; temp = p->next; p->next = temp->next; free(temp->section); free(temp->key); free(temp->value); free(temp); pini->length -= 1; return 1; }
cList *list_setremove(cList * list, cData * d) { Int pos = list_search(list, d); if (pos == -1) return list; return list_delete(list, pos); }
void *list_delete(List *L, const void *value) { ListNode *del_node = list_search(L, value); if (!IS_NULL(del_node)) return _do_delete(L, del_node); return NULL; }
struct listitem *gen_svc_tree(char *svc) { struct listitem *li; struct dep *deps; /* only do something if the service is not already known */ if((li = list_search(svc))) return li; /* create a template, so other instances won't try to recreate us */ if(!(li = svc_create(svc))) return NULL; /* add dependencies */ if(!check_add_deps(li, DEP_NEEDS)) return NULL; if(!check_add_deps(li, DEP_WANTS)) return NULL; /* If it has no dependencies, then the service is a start service. */ if(!li->wants && !li->needs) { deps = dep_create(li); if(!deps) return NULL; dep_entry_add(&deps_pending, deps); /* * Mark it as being in the startup list, so it does not get added again * in a dep_needs_wants_add call */ li->status |= CINIT_ST_IN_LIST; } return li; }
int list_insert(List *list, ListElmt *elmt, const int data) { ListElmt *newElmt; if ((newElmt = (ListElmt *)malloc(sizeof(ListElmt))) == 0) return 0; if (list_search(list, data) != NULL) return 0; newElmt->data = data; if (elmt == NULL) { if (list->size == 0) list->tail = newElmt; newElmt->next = list->head; list->head = newElmt; } else { if (elmt->next == NULL) list->tail = newElmt; newElmt->next = elmt->next; elmt->next = newElmt; } list->size = list->size + 1; return 1; };
/* alias and password should be set already in url */ static void create_the_bookmark(url_t *url) { listitem *li; /* we don't want to be asked again */ url_setalias(ftp->url, url->alias); if(strcmp(ftp->curdir, ftp->homedir) != 0) url_setdirectory(url, ftp->curdir); else url_setdirectory(url, 0); list_clear(gvBookmarks); { char *tmp = NULL; if (asprintf(&tmp, "%s/bookmarks", gvWorkingDirectory) == -1) { fprintf(stderr, _("Failed to allocate memory.\n")); return; } parse_rc(tmp, false); free(tmp); } li = list_search(gvBookmarks, (listsearchfunc)urlcmp, url); if(li) list_delitem(gvBookmarks, li); list_additem(gvBookmarks, url); bookmark_save(0); }
int main(void) { static char * strings[] = { "Hello, world!", "Bye, world!", NULL }; static char * keys[] = { "Hel", "Bye", NULL }; smr_init(LIBCONTAIN_MIN_HPTRS); hptr_init(); smr_thread_init(); list_t * list = list_new(compare_func); int i; for (i = 0; strings[i]; i++) if (list_insert(list, strings[i])) abort(); for (i = 0; strings[i]; i++) if (strcmp(strings[i], list_search(list, keys[i]))) abort(); smr_thread_fini(); hptr_fini(); smr_fini(); return 0; }
//画list //listbox:listbox指针 void listbox_draw_list(_listbox_obj *listbox) { u16 i; u16 endx=0; u16 tempcolor; _listbox_list * listx; endx=listbox->left+listbox->width-1; //条目显示结束x坐标 if(listbox->scbv->totalitems>listbox->scbv->itemsperpage)endx-=LBOX_SCB_WIDTH;//需要滚动条了. gui_fill_rectangle(listbox->left,listbox->top,endx-listbox->left+1,listbox->height,listbox->lbkcolor);//清空为底色. listx=list_search(listbox->list,listbox->scbv->topitem);//得到顶部list信息(curitem在listbox中用于记录顶部index) for(i=0;i<listbox->scbv->itemsperpage;i++)//显示条目 { if((listbox->scbv->topitem+i)==listbox->selindex)//此项为选中项目 { gui_fill_rectangle(listbox->left,listbox->top+i*gui_phy.listheight,endx-listbox->left+1,gui_phy.listheight,listbox->lnselbkcolor);//填充底色 listbox->fname=listx->name;//获得当前选中的条目的名字 listbox->namelen=strlen((const char*)listbox->fname)*listbox->font/2;//名字的总长度 listbox->curnamepos=0; tempcolor=listbox->lnselcolor; }else tempcolor=listbox->lncolor; gui_show_ptstr(listbox->left,listbox->top+i*gui_phy.listheight+(gui_phy.listheight-listbox->font)/2,endx,gui_phy.lcdheight,0,tempcolor,listbox->font,listx->name,1); if(listx->nextlist==0)break; listx=listx->nextlist; } }
static int cache_insert( struct idmap_cache *cache, const struct idmap_lookup *lookup, const struct list_entry *src) { struct list_entry *entry; int status = NO_ERROR; AcquireSRWLockExclusive(&cache->lock); /* search for an existing match */ entry = list_search(&cache->head, lookup->value, lookup->compare); if (entry) { /* overwrite the existing entry with the new results */ cache->ops->entry_copy(entry, src); goto out; } /* initialize a new entry and add it to the list */ entry = cache->ops->entry_alloc(); if (entry == NULL) { status = GetLastError(); goto out; } cache->ops->entry_copy(entry, src); list_add_head(&cache->head, entry); out: ReleaseSRWLockExclusive(&cache->lock); return status; }
static int open_unlock_delegate( IN nfs41_open_state *open, IN const nfs41_lock_state *input) { struct list_entry *entry; int status = ERROR_NOT_LOCKED; AcquireSRWLockExclusive(&open->lock); /* find lock state that matches this range */ entry = list_search(&open->locks.list, input, lock_range_cmp); if (entry) { nfs41_lock_state *lock = lock_entry(entry); if (lock->delegated) { /* if the lock was delegated, remove/free it and return success */ list_remove(entry); free(lock); status = NO_ERROR; } else status = ERROR_LOCKED; } ReleaseSRWLockExclusive(&open->lock); return status; }
/* appends char * items in list LP matching MASK * EXCLUDE_FUNC (if not 0) is called for each path found * and that path is excluded if EXCLUDE_FUNC returns true * * returns 0 if successful, -1 if failure */ int lglob_glob(list *gl, const char *mask, bool ignore_multiples, lglobfunc exclude_func) { struct dirent *de; DIR *dp; char *directory; char tmp[PATH_MAX]; bool added = false, found = false; directory = base_dir_xptr(mask); if((dp = opendir(directory ? directory : ".")) == 0) { ftp_err("Unable to read directory %s\n", directory ? directory : "."); return -1; } if (!getcwd(tmp, PATH_MAX)) { if (ERANGE == errno) { ftp_err("cwd too long\n"); } else { ftp_err("getcwd(): %s\n", strerror(errno)); } return -1; } while((de = readdir(dp)) != 0) { char *path; asprintf(&path, "%s/%s", directory ? directory : ".", de->d_name); if(fnmatch(base_name_ptr(mask), de->d_name, 0) == 0) { if(!(exclude_func && exclude_func(path))) { char *p; bool ignore_item; p = path_absolute(path, tmp, gvLocalHomeDir); ignore_item = (ignore_multiples && (list_search(gl, (listsearchfunc)strcmp, p) != 0)); if(!ignore_item) { list_additem(gl, p); added = true; } } found = true; } free(path); } closedir(dp); if(!found) { ftp_err("%s: no matches found\n", mask); return -1; } return added ? 0 : -1; }
static void create_bookmark(const char *guessed_alias) { char *default_alias = 0; char *prompt; url_t *url; listitem *li; int a; char *alias; alias = xstrdup(guessed_alias); while(true) { if(!alias) { default_alias = guess_alias(ftp->url); if(default_alias) asprintf(&prompt, "alias (%s): ", default_alias); else prompt = xstrdup("alias: "); force_completion_type = cpBookmark; alias = input_read_string(prompt); free(prompt); if(!alias || !*alias) alias = default_alias; else free(default_alias); } url = url_clone(ftp->url); url_setalias(url, alias); free(alias); alias = 0; li = list_search(gvBookmarks, (listsearchfunc)urlcmp, url); if(li) { a = ask(ASKYES|ASKNO|ASKCANCEL, ASKYES, _("a bookmark named '%s' already exists, overwrite?"), url->alias ? url->alias : url->hostname); if(a == ASKCANCEL) { url_destroy(url); return; } if(a == ASKYES) break; } else break; } /* password is automatically saved if anonymous login */ if(!url_isanon(url) && url->password) { a = ask(ASKYES|ASKNO, ASKNO, _("Save password?")); if(a == ASKNO) url_setpassword(url, 0); } create_the_bookmark(url); printf(_("created bookmark %s\n"), url->alias); }
static WTPCached_tid *tid_cached(WTPRespMachine *resp_machine) { WTPCached_tid *item = NULL; item = list_search(tid_cache, resp_machine->addr_tuple, tid_is_cached); return item; }
static int server_entry_find( IN struct server_list *servers, IN const struct server_info *info, OUT struct list_entry **entry_out) { *entry_out = list_search(&servers->head, info, server_compare); return *entry_out ? NO_ERROR : ERROR_FILE_NOT_FOUND; }
void delete_node(list_node *local_guard_node, int local_value){ list_node *local_node; local_node=list_search(local_guard_node,local_value); local_node->previous_node->next_node=local_node->next_node; local_node->next_node->previous_node=local_node->previous_node; free(local_node); //同时删除掉已经赋予的空间 }
point_t* graph_find(list_t graph, int width, int height, int x, int y) { int id = graph_id(width, height, x, y); point_t* point; list_search(graph, id, &point); // will set point to NULL if not found return point; }
ListElement * hash_search(const HashTable *table,const ListElement *to_search,CompareElementFuncType equal) { unsigned int hash=0; assert(table && to_search && equal); hash=hash_value((*table->elmtostr_fptr)(to_search),table->size); // DEBUG fprintf(stderr,"\n\n hash_search: before list_search\n\n"); return list_search(&table->hashbucket[hash].list,to_search,equal); }
def_t dict_search(dict_t dict, word_t word) { assert(dict != NULL && word != NULL && dict_exists(dict, word)); index_t palabra = NULL; palabra = index_from_string(word); data_t definition = list_search(dict->list, palabra); def_t result = data_to_string(definition); palabra = index_destroy(palabra); assert(result != NULL); return (result); }
/** * Binary search of a single function name in the list */ int list_search(char** flist, int fbase, int fcount, int fmax, const char * str) { if (fmax==0) return -1; if (fmax==1) { if (strcmp(flist[0], str)==0) return 0; else return -1; } int my_count = (fcount - fbase) / 2 + fbase; //the middle element in the range int res = strcmp(flist[my_count], str); if (res == 0) return my_count; else if (fcount - fbase <= 1) { int i = strcmp(flist[fbase], str); if (i == 0) return fbase; if (fcount==fmax) return -1; i = strcmp(flist[fcount], str); if (i == 0) return fcount; else return -1; } else if (res < 0) return list_search(flist, my_count, fcount, fmax, str); else if (res > 0) return list_search(flist, fbase, my_count, fmax, str); }
/* * 删除 * */ Bool list_delete(ListHead *head,int index) { ListNode *old_node = list_search(head,index); if (old_node) { list_unlink(old_node); return True; } return False; }
bool dict_exists(dict_t dict, word_t word) { assert(dict != NULL && word != NULL); bool result = false; index_t palabra = index_from_string(word); data_t definition = list_search(dict->list, palabra); if (definition != NULL) result = true; palabra = index_destroy(palabra); return (result); }
rfile *rdir_get_file(rdirectory *rdir, const char *filename) { listitem *li; li = list_search(rdir->files, (listsearchfunc)rfile_search_filename, filename); if(li) return (rfile *)li->data; return 0; }