void destroy_itemset( struct itemset * this_itemset ) { int i; char * key; struct list * key_list = new_list(); list_keys_in_hash( this_itemset->items, key_list, "" ); for ( i = 0; i < key_list->next_index; i++ ) { key = listlookup( key_list, i ); struct item * data = hashlookup( this_itemset->items, key )->data; free( data ); } destroy_key_list( key_list ); destroy_hash( this_itemset->items ); key_list = new_list(); list_keys_in_hash( this_itemset->ready_for, key_list, "" ); for ( i = 0; i < key_list->next_index; i++ ) { key = listlookup( key_list, i ); struct list * ready_items = hashlookup( this_itemset->ready_for, key )->data; destroy_list( ready_items ); } destroy_key_list( key_list ); destroy_hash( this_itemset->ready_for ); destroy_list( this_itemset->complete ); free( this_itemset ); return; }
int main() { slist_t *head = NULL, *tail = NULL; size_t list_size = 0; int i, ret; time_t t; time (&t); srand (t); for (i = 13; i > 0; i--) { ret = insert_at_head (&head, &tail, &list_size, (rand() % 10)); if (ret < 0) { destroy_list (&head, &tail); return -1; } } print_list (&head); delete_duplicates (&head, &list_size); print_list (&head); destroy_list (&head, &tail); print_list (&head); return 0; }
int main() { hash_table_t* people = hash_table_init(100); entry_t oliv = { "Pinon", "Olivier", "01 02 03 04", "Paris" }; entry_t pa = { "Durand", "Pierre-Alexandre", "33 04 10", "Lyon" }; printf("Does string equality work ? %d\n", eq_str(pa.name, "Durand")); hash_table_insert( people, &oliv ); hash_table_insert( people, &pa ); hash_table_print( people ); list_t test = hash_table_find_by_name(people, "Durand"); printf("%s\n ", "Is M.Durand here ?"); print_list(test); destroy_list(test); test = hash_table_find_by_surname(people, "Pierre-Alexandre"); printf("%s\n ", "Is Pierre-Alexandre here ?"); print_list(test); destroy_list(test); printf("hash map test done\n"); hash_table_print(people); hash_table_destroy( people ); return 0; };
/*************************************************************************** * Function: void disconnect(conn_data *conn) * * Description: * Remove the indicated connection from the list of connections, * close the file descriptor associated with it, and free all of the * memory it's using (including dereferencing of any strings still in * its input and output lists). **************************************************************************/ void disconnect(conn_data *conn) { find_data(conn_list, conn, ptrcmp, TRUE); close(conn->fd); destroy_list(conn->input, deref_string); destroy_list(conn->output, deref_string); free(conn); }
void release_parser(parser_t* p) { destroy_list(p->ast->function_list); destroy_list(p->ast->statement_list); free(p->ast); release_tokenizer(p->t); free(p->t); }
list_t* find_and_report(const char* datafile, const char mode, int pkgc, list_t* argv) { // set quiet to avoid print results of search_record() unsigned short int hold_quiet=quiet; quiet = 1; int i=0; int found = 0; unsigned short int fcount = 0; unsigned short int mcount = 0; list_t* founded = new_list(0); list_t* missing = new_list(0); for (i=0; i<pkgc; i++) { char* pkg = get_list(argv,i); char buf[1024]; strcpy(buf, pkg); char* tk = strtok(buf, "|"); while(tk != NULL) { found = 0; if(search_record(datafile, tk)) { found = 1; break; } tk = strtok(NULL, " ,"); } if(found == 1) { fcount = fcount+1; resize_list(founded,fcount); add_list(founded,fcount-1,tk); } else { mcount = mcount+1; resize_list(missing,mcount); add_list(missing,mcount-1,pkg); } } quiet = hold_quiet; switch(mode) { case 'f' : return(founded); case 'm' : return(missing); } destroy_list(founded); destroy_list(missing); return(NULL); }
void destroy_list(pointer P) { if(is_type(P, DT_Pair)) { if(pair_car(P) != NIL) destroy_list(pair_car(P)); if(pair_cdr(P) != NIL) destroy_list(pair_cdr(P)); } ploy_free(P); }
static void destroy(void) { if (init_avps) destroy_list(init_avps); if (start_avps) destroy_list(start_avps); if (stop_avps) destroy_list(stop_avps); }
static void destroy(void) { if (cc_init_avps) destroy_list(cc_init_avps); if (cc_start_avps) destroy_list(cc_start_avps); if (cc_stop_avps) destroy_list(cc_stop_avps); }
void destroy_function(function_p f) { if(f != NULL) { if(f->desc != NULL) { destroy_list(f->desc); } if(f->params != NULL) { destroy_list(f->params); } free(f); } }
/*called from dispatcher.c: free all*/ int ds_destroy_list(void) { if (ds_lists) { destroy_list(0); destroy_list(1); shm_free(ds_lists); } if (crt_idx) shm_free(crt_idx); return 0; }
void destroy_list (Node *n) { if (isNil(n)) ; else if (isAtom(n)){ free(atomVal(n)); /* free the atom here */ free_node(n); } else { destroy_list(car(n)); destroy_list(cdr(n)); free_node(n); } }
static void destroy_value(struct lp_value *v) { int d; switch(v->t) { case S: free(v->v.s); break; case LIST: destroy_list(v->v.l); break; case I: case D: break; case TOPOSPEC: for(d = 0; d < v->v.t.len; d++) destroy_topospec(&v->v.t.l[d]); free(v->v.t.l); break; default: destroy_block(v->v.b); } free(v); }
float get_cpu_load_atomic(void) { char buf[MAXLINE]; char c; char **list; int i, statfd; unsigned long total_time, idle_time; float idle_pct; while ((statfd = open("/proc/stat", O_RDONLY)),statfd == -1 && errno == EINTR) ; if (statfd == -1) { perror("Failed to read /proc/stat"); return -1; } i = 0; while ((read(statfd, &c, 1) != -1) && c != '\n') buf[i++] = c; buf[i] = 0; list = string_to_list(buf, " "); total_time = 0; idle_time = atol(list[4]); for (i = 1; list[i] != 0; i++) total_time += atol(list[i]); idle_pct = ((float)idle_time/(float)total_time) * 100; destroy_list((void **)list); return idle_pct; }
int main(int argc, char *argv[]) { list l = new_list(sizeof(int), NULL, NULL); int x = 10; int y = 11; int z = 12; app_to_list(l, &x); prep_to_list(l, &y); printf("\n"); map_list(l, print); printf("\n"); map_list(l, addTwo); map_list(l, print); printf("\n"); map_compare_del(l, compareInts, &z); map_list(l, print); printf("\n"); app_to_list(l, &x); prep_to_list(l, &y); map_list(l, print); printf("\n"); destroy_list(l); return 0; }
ListType* list_pipe(ListType* l, int type, int pipe_op, int rm_l) { ListType* newl = (ListType*)malloc(sizeof(ListType)); newl->list = NULL; newl->type = type; int len = g_list_length(l->list); int i; for(i=0; i<len; i++) { switch(type) { case EDGE_T: if(pipe_op==OP_OUTE) newl = list_append_gl(newl, ((VertexType*)g_list_nth_data(l->list, i))->outEdges, EDGE_T); else if(pipe_op==OP_INE) newl = list_append_gl(newl, ((VertexType*)g_list_nth_data(l->list, i))->inEdges, EDGE_T); else die(-1,"illegal pipe op for vlist\n"); break; case VERTEX_T: if(pipe_op==OP_SV) newl = list_append(newl, VERTEX_T, ((EdgeType*)g_list_nth_data(l->list, i))->start); else if(pipe_op==OP_EV) newl = list_append(newl, VERTEX_T, ((EdgeType*)g_list_nth_data(l->list, i))->end); else die(-1,"illegel pipe op for elist\n"); break; default: die(-1,"illegal pipe type \n"); } } if(rm_l == FLAG_DESTROY_ATTR)destroy_list(l); return newl; }
static void event_record_start_trap(WORD addr, void *data) { switch (event_start_mode) { case EVENT_START_MODE_FILE_SAVE: if (machine_write_snapshot(event_snapshot_path(event_start_snapshot), 1, 1, 0) < 0) { #ifdef HAS_TRANSLATION ui_error(translate_text(IDGS_CANT_CREATE_START_SNAP_S), #else ui_error(_("Could not create start snapshot file %s."), #endif event_snapshot_path(event_start_snapshot)); ui_display_recording(0); return; } destroy_list(); create_list(); record_active = 1; event_initial_write(); next_timestamp_clk = maincpu_clk; current_timestamp = 0; break; case EVENT_START_MODE_FILE_LOAD: if (machine_read_snapshot( event_snapshot_path(event_end_snapshot), 1) < 0) { #ifdef HAS_TRANSLATION ui_error(translate_text(IDGS_ERROR_READING_END_SNAP_S), #else ui_error(_("Error reading end snapshot file %s."), #endif event_snapshot_path(event_end_snapshot)); return; }
void run_grammar(tx_grammar_literal *lit) { size_t i; int row, col; pixel px; tx_grammar_literal *chosen = NULL; tx_grammar_expansion_site *ges = NULL; // Create a list of expansion sites: list *expansion_sites = create_list(); // Start by loading our source file into our result texture and calling our // pre-processing filter if we have one: if (lit->filename == NULL) { if (lit->anchor_x == 0 || lit->anchor_y == 0) { fprintf( stderr, "Error: grammar with NULL filename must have nonzero anchor values.\n" ); fprintf(stderr, "(found: %zu, %zu)\n", lit->anchor_x, lit->anchor_y); exit(EXIT_FAILURE); } lit->result = create_texture(lit->anchor_x, lit->anchor_y); } else { lit->result = load_texture_from_png(lit->filename); } if (lit->preprocess != NULL) { (*(lit->preprocess))(lit->result, lit->preargs); } // Now expand each child reference at random. Note that due to the low // resolution of the pseudo-random process, any item with a weight of less // than 1/65536th of the total weight of all items in a disjunction will // never be picked. for (col = 0; col < lit->result->width; ++col) { for (row = 0; row < lit->result->height; ++row) { px = tx_get_px(lit->result, col, row); for (i = 0; i < N_GRAMMAR_KEYS; ++i) { if (px == GRAMMAR_KEYS[i] && lit->children[i] != NULL) { chosen = choose_child( lit->children[i], hash_3d(hash_2d(hash_1d((ptrdiff_t) lit), i), col, row) ); if (chosen->result == NULL) { run_grammar(chosen); } ges = create_expansion_site(); ges->col = col; ges->row = row; ges->literal = chosen; l_append_element(expansion_sites, ges); ges = NULL; // destroy_list later on takes care of the memory used. } } } } l_witheach(expansion_sites, (void *) lit, expand_literal_into); // Clean up our list of expansion sites: destroy_list(expansion_sites); // Before wrapping up call our post-processing function if it exists: if (lit->postprocess != NULL) { (*(lit->postprocess))(lit->result, lit->postargs); } }
int main() { init(); show_main_window(); app_event_loop(); destroy_list(AccelLogging); }
int main(void) { list *lista; lista = init_list(); if(lista == NULL) { fprintf(stderr,"Can't create de list"); return -1; } push(lista,1); push(lista,2); push(lista,3); push(lista,4); insert_after(lista,3,10); printf("POP: %i\n",pop(lista)); printf("POP: %i\n",pop(lista)); print_list(lista); destroy_list(lista); return 0; }
static void terminate_list_arr(linked_list_t **arr) { for (int i = 0; i < NUM_TOTAL_CHARS; i++) { destroy_list(arr[i]); } free(arr); }
void release_rfsd_instance(struct rfsd_instance *instance) { destroy_list(&(instance->config.listen_addresses)); free(instance->config.pid_file); free(instance->config.exports_file); free(instance->config.passwd_file); }
int close_alc_channel(alc_channel_t *ch, alc_session_t *s) { int ret_val; int ch_id = ch->ch_id; ret_val = close_alc_socket(ch); /* trying again if ret_val == -1 */ if(ret_val == -1) { ret_val = close_alc_socket(ch); } assert(s->ch_list[ch_id] == ch); freeaddrinfo(ch->addrinfo); if(s->mode == RECEIVER) { join_rx_socket_thread(ch); destroy_list(ch->receiving_list); ch->receiving_list = NULL; } assert(ch->receiving_list == NULL); free(ch); s->ch_list[ch_id] = NULL; s->nb_channel--; return ret_val; }
void main() { int len, pos, *del; plist pl = NULL; del = (int*)malloc(sizeof(int)); pl = init_list(); isEmpty_list(pl); insert_item(pl, 1, 1); insert_item(pl, 2, 3); insert_item(pl, 3, 5); insert_item(pl, 4, 7); insert_item(pl, 5, 9); insert_item(pl, 6, 11); display(pl); len = len_list(pl); printf("link list len: %d\n", len); pos = locate_item(pl, 7); printf("num 7 pos: %d\n", pos); delete_item(pl, 3, del); printf("delete pos 3 num: %d\n", *del); display(pl); printf("link list traverse...\n"); pl = traverse_list(pl); display(pl); destroy_list(pl); getch(); }
ListType* list_match(ListType* l, bool (*func) (void*, int), int rm_l) { if(l==NULL) die(-1,"NULL parameter error \n"); ListType* newl = (ListType*)malloc(sizeof(ListType)); newl->type = l->type; int length = g_list_length(l->list); int i, b; void* obj; for(i=0; i<length; i++) { obj = g_list_nth_data(l->list, i); switch(l->type) { case VERTEX_T: b = func(obj, VERTEX_T); break; case EDGE_T: b = func(obj, EDGE_T); break; default: die(-1,"Illegal type error \n"); } if(b) { newl->list = g_list_append(newl->list, obj); } } if(rm_l == FLAG_DESTROY_ATTR)destroy_list(l); return newl; }
static int evaluate_index_and_insert_into_db(void *context, const char *expression, transformation *tr) { struct evaluate_index_context *ctx; string_list *values = NULL; string_list_item *item = NULL; int status = U1DB_OK; ctx = (struct evaluate_index_context *)context; if (ctx->obj == NULL || !json_object_is_type(ctx->obj, json_type_object)) { return U1DB_INVALID_JSON; } if (status != U1DB_OK) goto finish; if (status != U1DB_OK) goto finish; if ((status = init_list(&values)) != U1DB_OK) goto finish; status = apply_transformation(tr, ctx->obj, values); for (item = values->head; item != NULL; item = item->next) { if ((status = add_to_document_fields(ctx->db, ctx->doc_id, expression, item->data)) != U1DB_OK) goto finish; } finish: destroy_list(values); return status; }
bool find_rundeps(const char* datafile, int pkgc, list_t* argv) { int i=0; char* pkg = NULL; list_t* missing = find_and_report(datafile,'m',pkgc,argv); int size = size_list(missing); if ( size > 0 ) { if (quiet == 0) { for (i=0; i<size; i++) { pkg = get_list(missing,i); printf("%s ",pkg); } } if ( quiet == 0 ) printf("\n"); destroy_list(missing); return(false); } return(true); }
int main(int argc, char **argv) { FILE *rf; /* read file */ tnode trie; /* Check if file exists */ if (access(argv[1], F_OK) == -1) { printf("Input file does not exist\n"); return 1; } rf = fopen(argv[1], "r"); if (!fileIsValid(rf)) { return 1; } trie = createTree(); loadFileToTree(trie, rf); /* Start menu loop */ menu(); doSearchLoop(trie); fclose(rf); destroyTree(trie); destroy_list(FILES); return 0; }
int main( int argc, char** argv) { int ch = 0; char buf[STR_SIZE] = {}; char* hisBuf = NULL; char str[STR_SIZE] = {}; char historyArr[HISTORY_SIZE][STR_SIZE] = {}; int inHistory = 0; int cmd = -1; List_t* list = new_list( ); while( true) { getcwd( str, STR_SIZE); printf( "%s> ", str); fgets( buf, STR_SIZE, stdin); if( feof( stdin)) { printf( "logout\n"); break; } if( buf[0] == '\n') continue; parse_program( list, buf); if( (cmd = commands( list->head->next->program)) >= 0) { switch( cmd) { case logout: goto finish; break; case cd: if( chdir( list->head->next->program->arguments[0]) < 0) warn( "Error while changing dir"); break; case history: if( list->head->next->program->arguments[0][0]) { hisBuf = get_history( historyArr, atoi( list->head->next->program->arguments[0]), inHistory); if( hisBuf) { strcpy( buf, hisBuf); clear_list( list); parse_program( list, buf); printf( "%s\n", buf); execute( list); } } else dump_history( historyArr, inHistory); break; } } else execute( list); if( cmd != history) inHistory = add_in_history( historyArr, buf, inHistory); clear_list( list); } finish: destroy_list( list); return 0; }
static void listRelease(UtilList * ul) { Generic_list l = *(Generic_list *) & ul->hdl; destroy_list(&l); if (ul->ft->memUnlink) ul->ft->memUnlink(ul->mem_state); free(ul); }