int qemu_config_parse(FILE *fp, QemuOptsList **lists, const char *fname) { char line[1024], group[64], id[64], arg[64], value[1024]; Location loc; QemuOptsList *list = NULL; QemuOpts *opts = NULL; int res = -1, lno = 0; loc_push_none(&loc); while (fgets(line, sizeof(line), fp) != NULL) { loc_set_file(fname, ++lno); if (line[0] == '\n') { /* skip empty lines */ continue; } if (line[0] == '#') { /* comment */ continue; } if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) { /* group with id */ list = find_list(lists, group); if (list == NULL) goto out; opts = qemu_opts_create(list, id, 1); continue; } if (sscanf(line, "[%63[^]]]", group) == 1) { /* group without id */ list = find_list(lists, group); if (list == NULL) goto out; opts = qemu_opts_create(list, NULL, 0); continue; } if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2) { /* arg = value */ if (opts == NULL) { error_report("no group defined"); goto out; } if (qemu_opt_set(opts, arg, value) != 0) { goto out; } continue; } error_report("parse error"); goto out; } if (ferror(fp)) { error_report("error reading file"); goto out; } res = 0; out: loc_pop(&loc); return res; }
int qemu_config_parse(FILE *fp) { char line[1024], group[64], id[64], arg[64], value[1024]; QemuOptsList *list = NULL; QemuOpts *opts = NULL; while (fgets(line, sizeof(line), fp) != NULL) { if (line[0] == '\n') { /* skip empty lines */ continue; } if (line[0] == '#') { /* comment */ continue; } if (sscanf(line, "[%63s \"%63[^\"]\"]", group, id) == 2) { /* group with id */ list = find_list(group); if (list == NULL) return -1; opts = qemu_opts_create(list, id, 1); continue; } if (sscanf(line, "[%63[^]]]", group) == 1) { /* group without id */ list = find_list(group); if (list == NULL) return -1; opts = qemu_opts_create(list, NULL, 0); continue; } if (sscanf(line, " %63s = \"%1023[^\"]\"", arg, value) == 2) { /* arg = value */ if (opts == NULL) { fprintf(stderr, "no group defined\n"); return -1; } if (qemu_opt_set(opts, arg, value) != 0) { fprintf(stderr, "failed to set \"%s\" for %s\n", arg, group); return -1; } continue; } fprintf(stderr, "parse error: %s\n", line); return -1; } return 0; }
int qemu_set_option(const char *str) { char group[64], id[64], arg[64]; QemuOptsList *list; QemuOpts *opts; int rc, offset; rc = sscanf(str, "%63[^.].%63[^.].%63[^=]%n", group, id, arg, &offset); if (rc < 3 || str[offset] != '=') { qemu_error("can't parse: \"%s\"\n", str); return -1; } list = find_list(group); if (list == NULL) { return -1; } opts = qemu_opts_find(list, id); if (!opts) { qemu_error("there is no %s \"%s\" defined\n", list->name, id); return -1; } if (qemu_opt_set(opts, arg, str+offset+1) == -1) { return -1; } return 0; }
int main(int argc, const char *argv[]) { NODE_T *head = NULL; NODE_T *mp = NULL; int key = 4; while(1) { mp = getNode(); head = insert_list(head, mp); trav_list(head); mp = find_list(head, key); if(mp) { print_node(mp); head = delete_list(head, mp); } else { printf("no age %d\n", key); } } return 0; //sdf }
void free_call_d(int line, const char *file_name, const char *function, void *addr) { struct mlist_t *list = find_list(file_name); if (!rm_malloc(list, addr)) { list = files_list; while (list != NULL) { if (rm_malloc(list, addr)) { free(addr); return; } list = list->next; } } else { logi("free addr 0x%08lX (%d:%s '%s')\n", addr, line, function, file_name); free(addr); return; } LOGW("cannot free element!!! 0x%08lX (%d:%s '%s')\n", addr, line, function, file_name); }
void all(void) { system("cls"); int m=0; FILE *fout; team *fp,*head; head=fp=find_list(); if((fout=fopen("F:\\lol_info_table.dat","ab+"))==NULL) { printf("Open the file failed!\n"); exit(-1); } while(!feof(fout))//注意指向 { fread(fp,sizeof(team)-4,1,fout); m++; fp=fp->next; } fclose(fout); printf(" Num Name Age Location \n"); for(fp=head;m>1;m--) { printf("\t\t%d\t\t%s\t\t%d\t\t%s\n",fp->num,fp->name,fp->age,fp->add); fp=fp->next; } free(head); system("pause"); }
void Query::build_index(People *p, int key, enum parameter_t pm) { //得到某个二级属性节点 List *list = find_list(key, pm); //将查到的people指针插入到二级属性节点后面 insert_list(list, p, pm); }
int glIsList(unsigned int list) { GLContext *c=gl_get_context(); GLList *l; l=find_list(c,list); return (l != NULL); }
void bluez_detect(void) { inquiry_info *ii = NULL; int max_rsp, num_rsp; int dev_id, sock, len, flags; int i; char addr[19] = { 0 }; char name[248] = { 0 }; dev_id = hci_get_route(NULL); sock = hci_open_dev(dev_id); if (dev_id < 0 || sock < 0) { perror("opening socket"); exit(1); } len = 8; max_rsp = 255; flags = IREQ_CACHE_FLUSH; ii = (inquiry_info *) malloc(max_rsp * sizeof(inquiry_info)); num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags); if (num_rsp < 0) perror("hci_inquiry"); for (i = 0; i < num_rsp; i++) { ba2str(&(ii + i)->bdaddr, addr); memset(name, 0, sizeof(name)); if (hci_read_remote_name(sock, &(ii + i)->bdaddr, sizeof(name), name, 0) < 0) strcpy(name, "[unknown]"); if (debug) printf("; %s %s\n", addr, name); if (find_list(addr, at_prefixes)) { print_config(addr, name, "blueat"); } if (find_list(addr, nokia_prefixes)) { print_config(addr, name, "bluephonet"); } } free(ii); close(sock); }
void *malloc_call_d(int line, const char *file_name, const char *func_name, size_t size) { logi("malloc>\n"); void *addr = malloc(size); logi("malloc> 0x%0lX (%d:%s '%s')\n", addr, line, func_name, file_name); struct mlist_t *file_el = find_list(file_name); add_malloc(&(file_el->addr), addr, line, file_name, func_name, size); return addr; }
QemuOptsList *qemu_find_opts(const char *group) { QemuOptsList *ret; Error *local_err = NULL; ret = find_list(vm_config_groups, group, &local_err); if (local_err) { error_report_err(local_err); } return ret; }
QemuOptsList *qemu_find_opts(const char *group) { QemuOptsList *ret; Error *local_err = NULL; ret = find_list(vm_config_groups, group, &local_err); if (error_is_set(&local_err)) { error_report("%s\n", error_get_pretty(local_err)); error_free(local_err); } return ret; }
/* place - * Places the requested block at the beginning of the freeblock, and splitting * only if the size of the remainder block would equal or exceed the minimum * block size */ static void place(void *bp, size_t asize) { size_t csize = GET_SIZE(HDRP(bp)); size_t remainder = csize - asize; if (remainder >= (MINSIZE * WSIZE)) { remove_from_list(find_list(GET_SIZE(HDRP(bp))), bp); SET_SIZE(HDRP(bp), asize); SET_ALLOC(HDRP(bp)); bp = NEXT_BLKP(bp); SET_SIZE(HDRP(bp), remainder); SET_SIZE(FTRP(bp), remainder); UNSET_ALLOC(HDRP(bp)); UNSET_ALLOC(FTRP(bp)); SET_TAG(HDRP(bp)); SET_TAG(FTRP(bp)); add_to_list(find_list(GET_SIZE(HDRP(bp))), bp); }else { remove_from_list(find_list(GET_SIZE(HDRP(bp))), bp); SET_ALLOC(HDRP(bp)); SET_TAG(HDRP(NEXT_BLKP(bp))); } }
bool delete_list(struct node **L, data_t data) { struct node *p = find_list(L, data); if (p == NULL) return false; p->prev->next = p->next; p->next->prev = p->prev; free(p); return true; }
void del_dir(void) { system("cls"); int num,m=0,*v;//用一个m来数到底有多少个数据 char choice; FILE *fout,*fin; team *fp,*head; v=&m; fp=head=find_list(); if((fout=fopen("F:\\lol_info_table.dat","ab+"))==NULL) { printf("open the file error"); exit(-1); } while(!feof(fout)) { if(fread(fp,sizeof(team),1,fout)==1) m++; fp=fp->next; } fclose(fout);//fp没用了 while(TRUE) { printf("Input the number you want to delete:\n"); scanf("%d",&num); getchar(); head=del_list(head,num,m,v); printf("If you want to continue delete?(y/n)\n"); scanf("%c",&choice); getchar(); if(choice=='y'||choice=='Y') ; else break; } if((fin=fopen("F:\\lol_info_table.dat","wb"))==NULL) { printf("Open the file failed!\n"); exit(-1); } for(fp=head;m>0;m--) { if(fwrite(fp,sizeof(team)-4,1,fin)!=1) { printf("can not save"); exit(-1); } fp=fp->next; } fclose(fin); }
void insert_dir(void) { system("cls"); int num,m=0,*v; FILE *fin,*fout; team *head,*fp; char choice; v=&m; head=fp=find_list(); if((fout=fopen("F:\\lol_info_table.dat","ab+"))==NULL) { printf("Open the file failed!\n"); exit(-1); } while(!feof(fout)) { fread(fp,sizeof(team),1,fout); m++; fp=fp->next; } fclose(fout); while(TRUE) { printf("你想要把数据插在哪一位序号队员后面?\n"); scanf("%d",&num); head=insert_list(head,num,m,v); printf("If you want to continue delete?(y/n)\n"); scanf("%c",&choice); getchar(); if(choice=='y'||choice=='Y') ; else break; } if((fin=fopen("F:\\lol_info_table.dat","wb"))==NULL) { printf("Open the file failed"); exit(-1); } for(fp=head;m>0;m--) { if(fwrite(fp,sizeof(team)-4,1,fin)!=1) { printf("Can not save"); exit(-1); } fp=fp->next; } fclose(fin); }
void print_malloc_list(char *file_name, int only_count) { struct mlist_t *file = NULL; LOGI("BEGIN--------------------------------------------------------\n"); if (file_name == NULL) { file = files_list; while (file != NULL) { print_file_malloc_list(file, only_count); file = file->next; } } else { struct mlist_t *file = find_list(file_name); print_file_malloc_list(file, only_count); } LOGI("END----------------------------------------------------------\n"); }
void Query::query_data(Stat &stat, QString item, QString nativeplace, QString district, QString armtype, QString education, QString militaryrank) { int pm; QList<int> parameters; stat.reset(); if (item == "") return; parameters << get_value_by_key(nativeplace_map, nativeplace); parameters << get_value_by_key(district_map, district); parameters << get_value_by_key(armtype_map, armtype); parameters << get_value_by_key(education_map, education); parameters << get_value_by_key(militaryrank_map, militaryrank); pm = 0; while (pm < PARAMETER_SIZE && parameters[pm] == -1) { pm++; } if (pm == PARAMETER_SIZE) { for (int i = 0; i < this->npeople; i++) { People *p = &people[i]; float item_data = get_data_by_item(p, item); if (item_data > 0) { stat.add_element(item_data); } } } else { List *l = find_list(parameters[pm], pm); People *p = l->first; while (p) { bool all_parameter_match = true; for (int ii = pm + 1; ii < PARAMETER_SIZE; ii++) { if (parameters[ii] != -1 && !match_parameter(p, ii, parameters[ii])) { all_parameter_match = false; break; } } float item_data = get_data_by_item(p, item); if (all_parameter_match && item_data > 0) { stat.add_element(item_data); } p = p->next[pm]; } } }
Article* Diction::auto_create(char*word, char* description) { Article art = { word, description }; Article* fin = find(word); if (fin) { return fin; } else { Diction_list* list = (Diction_list*)find_list(word); list->add(&art); return find(word); } }
Article* Diction::auto_create(char*word) { Article art = { word, "" }; Article* fin = find(word); if (fin != nullptr) return fin; else { Diction_list* list = (Diction_list*)find_list(word); if (!list) { list = (Diction_list*)heap_my.get_mem(sizeof(Diction_list)); } list->add(&art); } return find(word); }
static void delete_list(GLContext *c, int list) { GLParamBuffer *pb, *pb1; GLList *l; l = find_list(c, list); assert(l); // free param buffer pb = l->first_op_buffer; while (pb) { pb1 = pb->next; gl_free(pb); pb = pb1; } gl_free(l); c->shared_state.lists[list] = NULL; }
void glNewList(unsigned int list,int mode) { GLList *l; GLContext *c=gl_get_context(); assert(mode == GL_COMPILE || mode == GL_COMPILE_AND_EXECUTE); assert(c->compile_flag == 0); l=find_list(c,list); if (l!=NULL) delete_list(c,list); l=alloc_list(c,list); c->current_op_buffer=l->first_op_buffer; c->current_op_buffer_index=0; c->compile_flag=1; c->exec_flag=(mode == GL_COMPILE_AND_EXECUTE); }
/* * Returns the next suitable free block from the free list using the 'first * fit' algorithm, else a NULL is returned */ static void *find_fit(size_t asize){ /* First fit search */ void *bp; int current = find_list(asize); /* Go through all the higher sized lists, if there are no available free blocks */ while (current < NUMBER_OF_LISTS) { bp = *(FRONT(current)); while (bp && GET_SIZE(HDRP(bp)) > 0) { if (asize <= GET_SIZE(HDRP(bp))) return bp; bp = SUCC_BP(bp); } ++current; } /* BOOM! found nothing */ return NULL; }
void num(void) { system("cls"); int m=0; FILE *fout; team *fp; fp=find_list(); if((fout=fopen("F:\\lol_info_table.dat","ab+"))==NULL) { printf("Open the file failed!\n"); exit(-1); } while(!feof(fout))//注意指向 { fread(fp,sizeof(team)-4,1,fout); m++; fp=fp->next; } printf("The total number is:%d\n",m-1); fclose(fout); system("pause"); }
void glopCallList(GLContext *c,GLParam *p) { GLList *l; int list,op; list=p[1].ui; l=find_list(c,list); if(l == NULL) { gl_fatal_error("list %d not defined", list); return; } p=l->first_op_buffer->ops; while (1) { op=p[0].op; if (op == OP_EndList) break; if (op == OP_NextBuffer) { p=(GLParam *)p[1].p; } else { op_table_func[op](c,p); p+=op_table_size[op]; } } }
void find_dir(void) { system("cls"); int l=MAX_LIST,num,m=0; char choose='y'; team *head,*fp,*p; FILE *fout; fp=head=find_list(); if((fout=fopen("F:\\lol_info_table.dat","rb"))==NULL) { printf("Open the file error!!!\n"); exit(-1); } while(!feof(fout)) { if(fread(fp,sizeof(team)-4,1,fout)==1) m++; fp=fp->next; } fclose(fout); while(choose=='y'||choose=='Y') { printf("Input the number you want to find:\n"); scanf("%d",&num); getchar(); p=search_list(head,num,m); if(p!=NULL) { printf("\nThe loler's information:\n"); printf("Num:%d\tName:%s\tAge:%d\tLocation:%s\n",p->num,p->name,p->age,p->add); } else printf("Not find!\n"); printf("Do you want again?\n(y\\n)\n"); scanf("%c",&choose); } }
/* * coalesce - Implements boundary-tag coalescing to merge the input block * with any adjacent free blocks in constant time. */ static void *coalesce(void *bp) { size_t prev_alloc = GET_PREV_ALLOC(HDRP(bp)); size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp))); size_t size = GET_SIZE(HDRP(bp)); if (prev_alloc && next_alloc) { /* Case 1 */ UNSET_TAG(HDRP(NEXT_BLKP(bp))); add_to_list(find_list(GET_SIZE(HDRP(bp))), bp); return bp; } else if (prev_alloc && !next_alloc) { /* Case 2 */ remove_from_list(find_list(GET_SIZE(HDRP(NEXT_BLKP(bp)))), NEXT_BLKP(bp)); size += GET_SIZE(HDRP(NEXT_BLKP(bp))); PUT(HDRP(bp), PACK(size, 0)); PUT(FTRP(bp), PACK(size,0)); SET_TAG(HDRP(bp)); SET_TAG(FTRP(bp)); } else if (!prev_alloc && next_alloc) { /* Case 3 */ remove_from_list(find_list(GET_SIZE(HDRP(PREV_BLKP(bp)))), PREV_BLKP(bp)); size += GET_SIZE(HDRP(PREV_BLKP(bp))); SET_SIZE(FTRP(bp), size); SET_SIZE(HDRP(PREV_BLKP(bp)), size); bp = PREV_BLKP(bp); } else { /* Case 4 */ remove_from_list(find_list(GET_SIZE(HDRP(PREV_BLKP(bp)))), PREV_BLKP(bp)); remove_from_list(find_list(GET_SIZE(HDRP(NEXT_BLKP(bp)))), NEXT_BLKP(bp)); size += GET_SIZE(HDRP(PREV_BLKP(bp))) + GET_SIZE(FTRP(NEXT_BLKP(bp))); SET_SIZE(HDRP(PREV_BLKP(bp)), size); SET_SIZE(FTRP(NEXT_BLKP(bp)), size); bp = PREV_BLKP(bp); } UNSET_TAG(HDRP(NEXT_BLKP(bp))); add_to_list(find_list(GET_SIZE(HDRP(bp))), bp); return bp; }
QemuOptsList *qemu_find_opts(const char *group) { return find_list(vm_config_groups, group); }
Article* Diction::find(char* word) { Diction_list* list = (Diction_list*)find_list(word); return list->find(word); }
QemuOptsList *qemu_find_opts_err(const char *group, Error **errp) { return find_list(vm_config_groups, group, errp); }