int main (void) { Tlist list; int order_no; char to_be_searched; initialize_list(&list); insert_to_list_end(&list, 'x'); insert_to_list_end(&list, 'a'); insert_to_list_end(&list, 'b'); insert_to_list_end(&list, 'c'); insert_to_list_end(&list, 'd'); insert_to_list_end(&list, 'y'); print_list(list); printf("Enter first character to be searced\n"); fflush(stdin); scanf("%c", &to_be_searched); if (find_pos_in_list(&list,to_be_searched, &order_no)) printf("The order no is %d\n", order_no); else printf("Not found\n"); printf("Enter second character to be searced\n"); fflush(stdin); scanf("%c", &to_be_searched); if (find_pos_in_list(&list, to_be_searched, &order_no)) printf("The order no is %d\n", order_no); else printf("Not found\n"); delete_first(&list); print_list(list); delete_last(&list); print_list(list); system("PAUSE"); }
void delete_last(Tlist *list){ Tpointer tmp; Tpointer tmp2; if(*list == NULL){ //do nothing printf("Nothing to delete\n"); } else { tmp = *list; if(tmp->next == NULL){ free(tmp); initialize_list(*&list); } else{ while(tmp->next->next!=NULL){ tmp = tmp->next; } tmp2=tmp->next; tmp->next = NULL; free(tmp2); } printf("Last item is deleted\n"); } }
int main (void) { Tlist list; initialize_list(&list); insert_to_list_end(&list, 'a'); insert_to_list_end(&list, 'b'); insert_to_list_end(&list, 'c'); insert_to_list_end(&list, 'd'); print_list(&list); delete_first(&list); print_list(&list); delete_first(&list); print_list(&list); delete_first(&list); print_list(&list); delete_first(&list); print_list(&list); //tulostuu tyhjä lista insert_to_list_end(&list, 'e'); print_list(&list); #if defined(WIN32)||defined(_WIN32) system("pause"); return 0; #else return 0; #endif }
int main( int argc,char** argv ) { int arr[] = { 1,2,3,4,5 } ; node* head;// = (node*)0;//= ( node* )malloc( sizeof( node ) ) ; head = initialize_list( head,arr,5 ) ; print_nodes( head ) ; return 0 ; }
void cleanup_list(Tlist *list) { Tpointer aux1, aux2; aux1 = *list; while (aux1 != NULL) { aux2 = aux1->next; free(aux1); printf("\nDeleted"); //for testing purposes aux1=aux2; } initialize_list(list); }
void cleanup_list(Tlist *list) { extern void CleanUp(void *p); Tpointer aux1, aux2; aux1 = *list; while (aux1 != NULL) { aux2 = aux1->next; CleanUp(aux1); printf("\nList Deleted\n"); //for testing purposes aux1 = aux2; } initialize_list(list); }
// Application int main (void) { Tlist list; initialize_list(&list); insert_to_list_end(&list, 'a'); insert_to_list_end(&list, 'b'); insert_to_list_end(&list, 'c'); insert_to_list_end(&list, 'd'); print_list(list); cleanup_list(&list); fflush(stdin); getchar(); }
// Application int main (void) { Tlist list; initialize_list(&list); insert_to_list_end(&list, CreateComplex(1, 2)); // add 1+2i insert_to_list_end(&list, CreateComplex(2, 3)); // add 2+3i insert_to_list_end(&list, CreateComplex(3, 4)); // add 3+4i insert_to_list_end(&list, CreateComplex(4, 5)); // add 4+5i print_list(list); cleanup_list(&list); heapleak(); fflush(stdin); getchar(); //heapdump(); }
UtilList * newList(void* memAddFunc, void* memReleaseFunc) { UtilList ul; ul.ft = UtilListFT; initialize_list((Generic_list *) & ul.hdl); ul.ft->memUnlink = memReleaseFunc; if (memAddFunc) { /* SFCB does this */ UtilList* (*memLink)(UtilList*); memLink = memAddFunc; return (*memLink)(&ul); } else { /* SFCC does this */ return memcpy(malloc(sizeof(ul)),&ul,sizeof(ul)); } }
struct node* prepare_list_of_files() { FILE* fp; char* line, *file_id, *file_size, *num_of_parts, *filename; size_t len = 0; int read; struct file_info* new_file; struct node* files_list = initialize_list(); struct node* node; //printf"malloc++\n") line = malloc(BUFF_SIZE); fp = fopen("tmp/files", "ab+"); if (fp == NULL) ERR("fopen"); printf("CZYTAM PLIKI Z PLIKUUU\n"); while ((read = getline(&line, &len, fp)) != -1) { printf("Plik wyryty!!!\n"); new_file = malloc(sizeof(struct file_info)); file_id = strtok(line, " "); new_file -> file_id = atoi(file_id); filename = strtok(NULL, " "); new_file -> filename = malloc(strlen(filename)); strcpy(new_file -> filename, filename); printf("FILE READ FROM FILE: %s\n", new_file -> filename); file_size = strtok(NULL, " "); num_of_parts = strtok(NULL, " "); new_file -> file_size = atoi(file_size); new_file -> num_of_parts = atoi(num_of_parts); add_new_end(files_list, (void*)new_file); } node = files_list -> next; while(node -> id != -2) { printf("PRZEGLĄDAM LISTĘ PLIKÓW, FILENAME: %s\n", ((struct file_info*)(node -> data))-> filename); node = node -> next; } free(line); fclose(fp); return files_list; }
int order_by_priority() { initialize_list(); //inicializo a struct da fila para depois ordena-la if(sizeof(p) > 0) { int i,j, tamanho, menor = p[0].prioridade; struct processos aux; tamanho = sizeof(fila.p_new) / sizeof(fila.p_new[0]); for(i = 0; i < tamanho; i++) { menor = i; for(j = i; j < (sizeof(fila.p_new) / sizeof(fila.p_new[0])); j++) { if(fila.p_new[menor].prioridade < fila.p_new[j].prioridade) { menor = j; } } aux = fila.p_new[menor]; fila.p_new[menor] = fila.p_new[i]; fila.p_new[i] = aux; } } return 1; }
int order_by_arrival() { initialize_list(); //inicializo a struct da fila para depois ordena-la if(sizeof(p) > 0) { int menor = p[0].chegada; struct processos aux; int i,j; for(i = 0; i < (sizeof(fila.p_new) / sizeof(fila.p_new[0])); i++) { menor = i; for(j = i; j < (sizeof(fila.p_new) / sizeof(fila.p_new[0])); j++) { if(fila.p_new[menor].chegada > fila.p_new[j].chegada) { menor = j; } } aux = fila.p_new[menor]; fila.p_new[menor] = fila.p_new[i]; fila.p_new[i] = aux; } } return 1; }
/* The application */ int main(int argc, const char * argv[]) { TOrderedList list; Titem item; int i; initialize_list(&list); printf("\n Enter items in any order\n"); for (i = 0 ; i < 5 ; i++) { read_item(&item); if (!insert_item(&list, item)) printf("\nList is full"); } printf("\nList ouputted using for loop and retrieve_ith function:\n"); for (i=0; i<number_of_items(&list); i++) { retrieve_ith(&list, i, &item); print_item(item); } return 0; }
int main (void) { TOrderedList list; Titem item; int i , succeed, no, result; initialize_list(&list); printf("\n Enter items in any order\n"); for (i = 0 ; i < 5 ; i++) { read_item(&item); if (!insert_item(&list, item)) printf("\nList is full"); } printf("List ouputted using for loop and retrieve_ith function:\n"); for (i=0; i<number_of_items(&list); i++) { retrieve_ith(&list, i, &item); print_item(item); } system("pause"); return 0; }
const char* test_list() { gc_list list; initialize_list(&list); for(long i = 1; i < 17; ++i) append_item((os_pointer)i, &list); gc_list_iterator itr; begin_list_iteration(&list, &itr); os_pointer item = 0; long expected = 1; while((item = current_item(&itr))) { if((long)item != expected) return "append item failed"; if((long)item % 2 == 0 || (long)item < 7) remove_item(&itr); advance_item(&itr); ++expected; } for(long i = 16; i < 19; ++i) append_item((os_pointer)i, &list); long expected2[] = {7, 9, 11, 13, 15, 16, 17, 18}; int expected2_idx = 0; begin_list_iteration(&list, &itr); while((item = current_item(&itr))) { if((long)item != expected2[expected2_idx++]) return "remove item failed"; advance_item(&itr); } finalize_list(&list); return "passed"; }
int main() { /*DECLARATIONS*/ struct command *L[100]; char *cmdLine = calloc(100,sizeof(char)); //command line int *groupD; //keep track of directives char c; int numLists = 0; //number of lists created int listNum=0; //specific list to deal with int i; signal(SIGCHLD, bg_handler); //allow children to die signal(SIGALRM, alarm_handler); //check efficiency L[numLists] = (struct command *)calloc(1, sizeof(struct command)); initialize_list(L[numLists]); printf("My Shell > "); fflush(stdout); while(1) { c = getchar(); switch(c) { case'\n': if (cmdLine[0] == '\0') { printf("My Shell > "); } else { /*execute command line*/ groupD = parse_cmdline(L[numLists], cmdLine); if (groupD[0] == 0){ exec_cmdline(L[numLists]); } else { /*directives*/ for (i=0; i<numLists+1; i++){ if (L[i]->group == groupD[1]){ directive(L[i], groupD[0]); } } } printf("My Shell > "); numLists++; L[numLists] = (struct command *)calloc(1, sizeof(struct command)); initialize_list(L[numLists]); reset_cmdline(cmdLine); } break; default: strncat(cmdLine, &c, 1); break; } } for (i=0; i<numLists+1; i++) free_proclist(L[i]); free_listofproclist(L); free(cmdLine); return -1; }
void view_arg_convert(viewtab_entry *vtp, int vtp_parm, mval *parm, viewparm *parmblk, boolean_t is_dollar_view) { static int4 first_time = TRUE; char *cptr; char *strtokptr; gd_binding *gd_map; gd_region *gd_reg_start, *r_ptr, *r_top; gvnh_reg_t *gvnh_reg; gvnh_spanreg_t *gvspan; gv_namehead *tmp_gvt; ht_ent_mname *tabent; int n, reg_index; mident_fixed lcl_buff; mname_entry gvent, lvent; mstr namestr, tmpstr; unsigned char *c, *c_top, *dst, *dst_top, global_names[1024], *nextsrc, *src, *src_top, stashed, y; switch (vtp_parm) { case VTP_NULL: if (parm != 0) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_VIEWARGCNT, 2, strlen((const char *)vtp->keyword), vtp->keyword); break; case (VTP_NULL | VTP_VALUE): if (NULL == parm) { parmblk->value = (mval *)&literal_one; break; } /* caution: fall through */ case VTP_VALUE: if (NULL == parm) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_VIEWARGCNT, 2, strlen((const char *)vtp->keyword), vtp->keyword); parmblk->value = parm; break; case (VTP_NULL | VTP_DBREGION): if (!is_dollar_view && ((NULL == parm) || ((1 == parm->str.len) && ('*' == *parm->str.addr)))) { parmblk->gv_ptr = NULL; break; } /* caution: fall through */ case VTP_DBREGION: if (NULL == parm) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_VIEWARGCNT, 2, strlen((const char *)vtp->keyword), vtp->keyword); if (!gd_header) /* IF GD_HEADER ==0 THEN OPEN GBLDIR */ gvinit(); r_ptr = gd_header->regions; if (!parm->str.len && vtp->keycode == VTK_GVNEXT) /* "" => 1st region */ parmblk->gv_ptr = r_ptr; else { for (cptr = parm->str.addr, n = 0; n < parm->str.len; cptr++, n++) lcl_buff.c[n] = TOUPPER(*cptr); /* Region names are upper-case ASCII */ namestr.len = n; namestr.addr = &lcl_buff.c[0]; for (r_top = r_ptr + gd_header->n_regions; ; r_ptr++) { if (r_ptr >= r_top) { format2zwr((sm_uc_ptr_t)parm->str.addr, parm->str.len, global_names, &n); rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_NOREGION,2, n, global_names); } tmpstr.len = r_ptr->rname_len; tmpstr.addr = (char *)r_ptr->rname; MSTR_CMP(tmpstr, namestr, n); if (0 == n) break; } parmblk->gv_ptr = r_ptr; } break; case VTP_DBKEY: if (NULL == parm) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_VIEWARGCNT, 2, strlen((const char *)vtp->keyword), vtp->keyword); if (!parm->str.len) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_NOTGBL, 2, parm->str.len, NULL); if (!gd_header) /* IF GD_HEADER ==0 THEN OPEN GBLDIR */ gvinit(); c = (unsigned char *)parm->str.addr; if ('^' != *c) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_NOTGBL, 2, parm->str.len, c); c_top = c + parm->str.len; c++; /* skip initial '^' */ parmblk->str.addr = (char *)c; for ( ; (c < c_top) && ('(' != *c); c++) ; parmblk->str.len = (char *)c - parmblk->str.addr; if (MAX_MIDENT_LEN < parmblk->str.len) parmblk->str.len = MAX_MIDENT_LEN; if (!valid_mname(&parmblk->str)) { format2zwr((sm_uc_ptr_t)parm->str.addr, parm->str.len, global_names, &n); rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_VIEWGVN, 2, n, global_names); } break; case VTP_RTNAME: if (NULL == parm) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_VIEWARGCNT, 2, strlen((const char *)vtp->keyword), vtp->keyword); memset(&parmblk->ident.c[0], 0, SIZEOF(parmblk->ident)); if (parm->str.len > 0) memcpy(&parmblk->ident.c[0], parm->str.addr, (parm->str.len <= MAX_MIDENT_LEN ? parm->str.len : MAX_MIDENT_LEN)); break; case VTP_NULL | VTP_DBKEYLIST: if (NULL == parm || 0 == parm->str.len) { parmblk->ni_list.gvnh_list = NULL; parmblk->ni_list.type = NOISOLATION_NULL; break; } /* caution : explicit fall through */ case VTP_DBKEYLIST: if (NULL == parm) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_VIEWARGCNT, 2, strlen((const char *)vtp->keyword), vtp->keyword); if (!gd_header) gvinit(); if (first_time) { noisolation_buddy_list = (buddy_list *)malloc(SIZEOF(buddy_list)); initialize_list(noisolation_buddy_list, SIZEOF(noisolation_element), NOISOLATION_INIT_ALLOC); gvt_pending_buddy_list = (buddy_list *)malloc(SIZEOF(buddy_list)); initialize_list(gvt_pending_buddy_list, SIZEOF(gvt_container), NOISOLATION_INIT_ALLOC); first_time = FALSE; } assertpro(SIZEOF(global_names) > parm->str.len); tmpstr.len = parm->str.len; /* we need to change len and should not change parm->str, so take a copy */ tmpstr.addr = parm->str.addr; if (0 != tmpstr.len) { switch (*tmpstr.addr) { case '+' : parmblk->ni_list.type = NOISOLATION_PLUS; tmpstr.addr++; tmpstr.len--; break; case '-' : parmblk->ni_list.type = NOISOLATION_MINUS; tmpstr.addr++; tmpstr.len--; break; default : parmblk->ni_list.type = NOISOLATION_NULL; break; } if (!tmpstr.len) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_VIEWGVN, 2, tmpstr.len, NULL); memcpy(global_names, tmpstr.addr, tmpstr.len); global_names[tmpstr.len] = '\0'; src = (unsigned char *)STRTOK_R((char *)global_names, ",", &strtokptr); REINITIALIZE_LIST(noisolation_buddy_list); /* reinitialize the noisolation buddy_list */ parmblk->ni_list.gvnh_list = NULL; for ( ; src < &global_names[tmpstr.len + 1]; src = nextsrc) { nextsrc = (unsigned char *)STRTOK_R(NULL, ",", &strtokptr); if (NULL == nextsrc) nextsrc = &global_names[tmpstr.len + 1]; if (nextsrc - src >= 2 && '^' == *src) { namestr.addr = (char *)src + 1; /* skip initial '^' */ namestr.len = INTCAST(nextsrc - src - 2); /* don't count initial ^ and trailing 0 */ if (namestr.len > MAX_MIDENT_LEN) namestr.len = MAX_MIDENT_LEN; if (valid_mname(&namestr)) { memcpy(&lcl_buff.c[0], namestr.addr, namestr.len); gvent.var_name.len = namestr.len; } else { memcpy(&lcl_buff.c[0], src, nextsrc - src - 1); format2zwr((sm_uc_ptr_t)&lcl_buff.c, nextsrc - src - 1, global_names, &n); rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_VIEWGVN, 2, n, global_names); } } else { memcpy(&lcl_buff.c[0], src, nextsrc - src - 1); format2zwr((sm_uc_ptr_t)&lcl_buff.c, nextsrc - src - 1, global_names, &n); rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_VIEWGVN, 2, n, global_names); } tmp_gvt = NULL; gvent.var_name.addr = &lcl_buff.c[0]; COMPUTE_HASH_MNAME(&gvent); if (NULL != (tabent = lookup_hashtab_mname(gd_header->tab_ptr, &gvent))) { gvnh_reg = (gvnh_reg_t *)tabent->value; assert(NULL != gvnh_reg); tmp_gvt = gvnh_reg->gvt; } else { gd_map = gv_srch_map(gd_header, gvent.var_name.addr, gvent.var_name.len, SKIP_BASEDB_OPEN_FALSE); r_ptr = gd_map->reg.addr; tmp_gvt = (gv_namehead *)targ_alloc(r_ptr->max_key_size, &gvent, r_ptr); GVNH_REG_INIT(gd_header, gd_header->tab_ptr, gd_map, tmp_gvt, r_ptr, gvnh_reg, tabent); /* In case of a global spanning multiple regions, the gvt pointer corresponding to * the region where the unsubscripted global reference maps to is stored in TWO * locations (one in gvnh_reg->gvspan->gvt_array[index] and one in gvnh_reg->gvt. * So pass in both these pointer addresses to be stored in the pending list in * case this gvt gets reallocated (due to different keysizes between gld and db). */ if (NULL == (gvspan = gvnh_reg->gvspan)) { ADD_TO_GVT_PENDING_LIST_IF_REG_NOT_OPEN(r_ptr, &gvnh_reg->gvt, NULL); } else { gd_reg_start = &gd_header->regions[0]; GET_REG_INDEX(gd_header, gd_reg_start, r_ptr, reg_index); /* the above sets "reg_index" */ assert(reg_index >= gvspan->min_reg_index); assert(reg_index <= gvspan->max_reg_index); reg_index -= gvspan->min_reg_index; ADD_TO_GVT_PENDING_LIST_IF_REG_NOT_OPEN(r_ptr, &gvspan->gvt_array[reg_index], &gvnh_reg->gvt); } } ADD_GVT_TO_VIEW_NOISOLATION_LIST(tmp_gvt, parmblk); if (!is_dollar_view && (NULL != gvnh_reg->gvspan)) { /* Global spans multiple regions. Make sure gv_targets corresponding to ALL * spanned regions are allocated so NOISOLATION status can be set in all of * them even if the corresponding regions are not open yet. Do this only for * VIEW "NOISOLATION" commands which change the noisolation characteristic. * $VIEW("NOISOLATION") only examines the characteristics and so no need to * allocate all the gv-targets in that case. Just one is enough. */ gvnh_spanreg_subs_gvt_init(gvnh_reg, gd_header, parmblk); } } } else rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_VIEWGVN, 2, tmpstr.len, tmpstr.addr); break; case VTP_LVN: if (NULL == parm) rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_VIEWARGCNT, 2, strlen((const char *)vtp->keyword), vtp->keyword); if (0 < parm->str.len) { lvent.var_name.addr = parm->str.addr; lvent.var_name.len = parm->str.len; if (lvent.var_name.len > MAX_MIDENT_LEN) lvent.var_name.len = MAX_MIDENT_LEN; if (!valid_mname(&lvent.var_name)) { format2zwr((sm_uc_ptr_t)parm->str.addr, parm->str.len, global_names, &n); rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_VIEWLVN, 2, n, global_names); } } else rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_VIEWLVN, 2, parm->str.len, parm->str.addr); /* Now look up the name.. */ COMPUTE_HASH_MNAME(&lvent); if ((tabent = lookup_hashtab_mname(&curr_symval->h_symtab, &lvent)) && (NULL != tabent->value)) parmblk->value = (mval *)tabent->value; /* Return lv_val ptr */ else rts_error_csa(CSA_ARG(NULL) VARLSTCNT(4) ERR_VIEWLVN, 2, parm->str.len, parm->str.addr); break; default: assertpro(FALSE && vtp_parm); } }
/* Initialize the TP structures we will be using for the successive TP operations */ void gvcst_tp_init(gd_region *greg) { sgm_info *si; sgmnt_addrs *csa; csa = (sgmnt_addrs *)&FILE_INFO(greg)->s_addrs; if (NULL == csa->sgm_info_ptr) { si = csa->sgm_info_ptr = (sgm_info *)malloc(sizeof(sgm_info)); assert(32768 > sizeof(sgm_info)); memset(si, 0, sizeof(sgm_info)); si->tp_hist_size = TP_MAX_MM_TRANSIZE; si->cur_tp_hist_size = INIT_CUR_TP_HIST_SIZE; /* should be very much less than si->tp_hist_size */ assert(si->cur_tp_hist_size <= si->tp_hist_size); si->blks_in_use = (hash_table_int4 *)malloc(sizeof(hash_table_int4)); init_hashtab_int4(si->blks_in_use, BLKS_IN_USE_INIT_ELEMS); /* See comment in tp.h about cur_tp_hist_size for details */ si->first_tp_hist = si->last_tp_hist = (srch_blk_status *)malloc(sizeof(srch_blk_status) * si->cur_tp_hist_size); si->cw_set_list = (buddy_list *)malloc(sizeof(buddy_list)); initialize_list(si->cw_set_list, sizeof(cw_set_element), CW_SET_LIST_INIT_ALLOC); si->tlvl_cw_set_list = (buddy_list *)malloc(sizeof(buddy_list)); initialize_list(si->tlvl_cw_set_list, sizeof(cw_set_element), TLVL_CW_SET_LIST_INIT_ALLOC); si->tlvl_info_list = (buddy_list *)malloc(sizeof(buddy_list)); initialize_list(si->tlvl_info_list, sizeof(tlevel_info), TLVL_INFO_LIST_INIT_ALLOC); si->new_buff_list = (buddy_list *)malloc(sizeof(buddy_list)); initialize_list(si->new_buff_list, SIZEOF(que_ent) + csa->hdr->blk_size, NEW_BUFF_LIST_INIT_ALLOC); si->recompute_list = (buddy_list *)malloc(sizeof(buddy_list)); initialize_list(si->recompute_list, sizeof(key_cum_value), RECOMPUTE_LIST_INIT_ALLOC); /* The size of the si->cr_array can go up to TP_MAX_MM_TRANSIZE, but usually is quite less. * Therefore, initially allocate a small array and expand as needed later. */ if (dba_bg == greg->dyn.addr->acc_meth) { si->cr_array_size = si->cur_tp_hist_size; si->cr_array = (cache_rec_ptr_ptr_t)malloc(sizeof(cache_rec_ptr_t) * si->cr_array_size); } else { si->cr_array_size = 0; si->cr_array = NULL; } si->fresh_start = TRUE; } else si = csa->sgm_info_ptr; si->gv_cur_region = greg; si->tp_csa = csa; si->tp_csd = csa->hdr; si->start_tn = csa->ti->curr_tn; if (JNL_ALLOWED(csa)) { si->total_jnl_rec_size = csa->min_total_tpjnl_rec_size; /* Reinitialize total_jnl_rec_size */ /* Since the following jnl-mallocs are independent of any dynamically-changeable parameter of the * database, we can as well use the existing malloced jnl structures if at all they exist. */ if (NULL == si->jnl_tail) { si->jnl_tail = &si->jnl_head; si->jnl_list = (buddy_list *)malloc(sizeof(buddy_list)); initialize_list(si->jnl_list, sizeof(jnl_format_buffer), JNL_LIST_INIT_ALLOC); si->format_buff_list = (buddy_list *)malloc(sizeof(buddy_list)); /* Minimum value of elemSize is 8 due to alignment requirements of the returned memory location. * Therefore, we request an elemSize of 8 bytes for the format-buffer and will convert as much * bytes as we need into as many 8-byte multiple segments (see code in jnl_format). */ initialize_list(si->format_buff_list, JFB_ELE_SIZE, DIVIDE_ROUND_UP(JNL_FORMAT_BUFF_INIT_ALLOC, JFB_ELE_SIZE)); } } else if (NULL != si->jnl_tail) { /* journaling is currently disallowed although it was allowed (non-zero si->jnl_tail) * during the prior use of this region. Free up unnecessary region-specific structures now. */ FREEUP_BUDDY_LIST(si->jnl_list); FREEUP_BUDDY_LIST(si->format_buff_list); si->jnl_tail = NULL; } }
int main(void) { list* l = initialize_list(); list_node* c_node = create_list_node("c"); list_node* a_node = create_list_node("a"); list_node* z_node = create_list_node("z"); list_node* x_node = create_list_node("x"); push_list_node(l, a_node); remove_internal_list_node(l, a_node); push_list_node(l, a_node); push_list(l, "b"); push_list_node(l, c_node); unshift_list_node(l, z_node); unshift_list(l, "y"); unshift_list_node(l, x_node); remove_internal_list_node(l, z_node); remove_internal_list_node(l, a_node); remove_internal_list_node(l, x_node); free_list_node(z_node); free_list_node(a_node); free_list_node(x_node); while(l->length > 0) { printf("%s\n", (char*)pop_list(l)); } unsigned long dl; destroy_list(l, DESTROY_MODE_IGNORE_VALUES, &dl); printf("-------queue test-------------\n"); unsigned long priority; char* id; priority_queue* pq = initialize_priority_queue(); push_priority_queue(pq, 30, "id_1", "value_1"); push_priority_queue(pq, 10, "id_2", "value_2"); push_priority_queue(pq, 10, "id_3", "value_3"); push_priority_queue(pq, 40, "id_4", "value_4"); push_priority_queue(pq, 5, "id_5", "value_5"); push_priority_queue(pq, 30, "id_6", "value_6"); push_priority_queue(pq, 30, "id_7", "value_7"); printf("queue length = %ld\n", pq->length); unsigned long num_destroyed; char* tmp = peek_priority_queue(pq, &priority, &id, 0); printf("first is \"%s\"\n", tmp); set_priority_for_id_in_priority_queue(pq, "id_5", 35); tmp = peek_priority_queue(pq, &priority, &id, 0); printf("first is \"%s\"\n", tmp); set_priority_for_id_in_priority_queue(pq, "id_2", 36); tmp = peek_priority_queue(pq, &priority, &id, 0); printf("first is \"%s\"\n", tmp); /* char** values = (char**)destroy_priority_queue(pq, DESTROY_MODE_RETURN_VALUES, &num_destroyed); int index = 0; for(index = 0; values[index] != NULL; index++) { printf("%s\n", values[index]); } */ while(pq->length > 0) { char* value = (char*)shift_priority_queue(pq, &priority, &id); printf("%s\n", value); free(id); } destroy_priority_queue(pq, DESTROY_MODE_FREE_VALUES, &dl); return 0; }
void initialize_face_list(face_list *AFL, int size) { initialize_list(AFL,sizeof(face *),equal_face); hash_list(AFL, size, hash_face); }
void initialize_char_list(TcharList* charL){ initialize_list(charL); }
int main(int argc, char **argv) { char *table = argv[1]; char *delete_chain = argv[2]; if(argc != 3) { printf("USAGE: %s [TABLE] [CHAIN TO DELETE]\n\n", argv[0]); return 0; } char *command = dynamic_strcat(3, "iptables -t ", table, " -L -n --line-numbers 2>/dev/null"); unsigned long num_lines = 0; char** table_dump = get_shell_command_output_lines(command, &num_lines); free(command); unsigned long line_index; char* current_chain = NULL; list* delete_commands = initialize_list(); for(line_index=0; line_index < num_lines; line_index++) { char* line = table_dump[line_index]; unsigned long num_pieces = 0; char whitespace[] = { '\t', ' ', '\r', '\n' }; char** line_pieces = split_on_separators(line, whitespace, 4, -1, 0, &num_pieces); if(strcmp(line_pieces[0], "Chain") == 0) { if(current_chain != NULL) { free(current_chain); } current_chain = strdup(line_pieces[1]); } else { unsigned long line_num; int read = sscanf(line_pieces[0], "%ld", &line_num); if(read > 0 && current_chain != NULL && num_pieces >1) { if(strcmp(line_pieces[1], delete_chain) == 0) { char* delete_command = dynamic_strcat(7, "iptables -t ", table, " -D ", current_chain, " ", line_pieces[0], " 2>/dev/null"); push_list(delete_commands, delete_command); } } } //free line_pieces free_null_terminated_string_array(line_pieces); } free_null_terminated_string_array(table_dump); /* final two commands to flush chain being deleted and whack it */ unshift_list(delete_commands, dynamic_strcat(5, "iptables -t ", table, " -F ", delete_chain, " 2>/dev/null")); unshift_list(delete_commands, dynamic_strcat(5, "iptables -t ", table, " -X ", delete_chain, " 2>/dev/null")); /* run delete commands */ while(delete_commands->length > 0) { char *next_command = (char*)pop_list(delete_commands); char **out = get_shell_command_output_lines(next_command, &num_lines); free_null_terminated_string_array(out); } return 0; }
void serve_file(int fd, int file_id, struct node* slaves){ struct node* files_list; struct file_info* file; struct node* tids_list; int i = 0; pthread_t* tid; struct part_info* part_info; struct get_file_part_arg* file_part_arg; struct node* node; tids_list = initialize_list(); void* data = 0; char* file_data; char* response; char* response_body; file_data = malloc(1024); response = malloc(1024); response_body = malloc(1024); files_list = prepare_list_of_files(); files_list = files_list -> next; while(files_list -> id != -2){ file = (struct file_info*)(files_list -> data); if( file -> file_id == file_id) { printf("ZNALEZIONO PLIK! ID: %d NUM OF PARTS: %d\n", file -> file_id, file -> num_of_parts); break; } files_list = files_list -> next; } if(files_list -> id == -2) return; for(i = 0; i < file -> num_of_parts; i++) { tid = malloc(sizeof(pthread_t)); part_info = malloc(sizeof(struct part_info)); part_info -> file_id = file_id; part_info -> part_id = i; file_part_arg = malloc(sizeof(struct get_file_part_arg)); file_part_arg -> part = part_info; file_part_arg -> slaves = slaves; sleep(1); pthread_create(tid, NULL, get_file_part, (void*)file_part_arg); add_new_end(tids_list, (void*)(tid)); } node = tids_list -> next; while(node -> id != -2) { pthread_join(*((pthread_t*)(node -> data)), &data); if(data == NULL) { response_body = "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"><html><head><title>Błąd!</title></head><body><h1>Bad Request</h1><p>Liczba wyłączonych slave\'ów przekroczyła poziom niezawodności tego pliku.<p></body></html>"; sprintf(response, "HTTP/1.1 400 Bad Request\r\n" "Content-Length: %d\r\n" "Content-Type: text/html; charset=utf-8\r\n" "Connection: Closed\r\n" "\r\n" "%s", strlen(response_body), response_body); bulk_write(fd, response, strlen(response)); add_file_downloaded_error_status(); return; } part_info = (struct part_info*)data; strcat(file_data, part_info -> data); node = node -> next; } printf("OTRZYMANY PLIK: %s\n", file_data); sprintf(response, "HTTP/1.1 200 OK\r\n" "Content-Disposition: attachment; filename=\"%s\"\r\n" "Content-Type: text/plain\r\n" "Connection: close\r\n" "Content-Length: %d\r\n" "\r\n" "%s" ,file -> filename, strlen(file_data), file_data); bulk_write(fd, response, strlen(response)); add_file_downloaded_status(); }
/****************************************************************************** * * This receives the reads, converts them, and writes them to the FIFO(s) * * void *a: a pointer to a struct with the following components: * * int thread_id: the thread_id * char *fastq1: FIFO from which bowtie2 can get read1 * char *fastq2: FIFO from which bowtie2 can get read2 (if it exists) * *******************************************************************************/ void * slurp_fastq(void *a) { pthread_t threads[2]; void *p = NULL, *p2 = NULL, *p3 = NULL; int size = 0, current_p_size = 0; MPI_Status status; fastq *read = malloc(sizeof(fastq)); assert(read); first_writer = initialize_list(first_writer); first_writer_sentinel = first_writer->next; pthread_create(&(threads[0]), NULL, &first_writer_func, a); if(config.paired) { //If we have pairs, then writing simultaneuosly to two fifos (that will be read sequentially by bowtie2) won't work, since bowtie2 will read from a single fifo multiple times!!! second_writer = initialize_list(second_writer); second_writer_sentinel = second_writer->next; pthread_create(&(threads[1]), NULL, &second_writer_func, a); } //Initialize the fastq struct read->max_name1 = 10; read->max_name2 = 10; read->max_seq1 = 10; read->max_seq2 = 10; read->max_qual1 = 10; read->max_qual2 = 10; read->name1 = malloc(sizeof(char) * 10); read->seq1 = malloc(sizeof(char) * 10); read->qual1 = malloc(sizeof(char) * 10); read->name2 = malloc(sizeof(char) * 10); read->seq2 = malloc(sizeof(char) * 10); read->qual2 = malloc(sizeof(char) * 10); assert(read->name1); assert(read->seq1); assert(read->qual1); assert(read->name2); assert(read->seq2); assert(read->qual2); //Receive and process the raw reads while(1) { MPI_Probe(0, 3, MPI_COMM_WORLD, &status); MPI_Get_count(&status, MPI_BYTE, &size); if(size > current_p_size) { p = realloc(p, (size_t) size); assert(p); } MPI_Recv(p, size, MPI_BYTE, 0, 3, MPI_COMM_WORLD, &status); //Are we finished receiving? if(size <= 1) break; //Copy if needed if(config.paired) { p2 = malloc(size); assert(p2); memcpy(p2,p,size); add_element(second_writer_sentinel, p2); } p3 = malloc(size); assert(p3); memcpy(p3,p,size); add_element(first_writer_sentinel, p3); } add_finished(first_writer_sentinel); if(config.paired) add_finished(second_writer_sentinel); //Wait for the other thread pthread_join(threads[0], NULL); if(config.paired) { pthread_join(threads[1], NULL); } //Free things up free(p); free(read->name1); free(read->seq1); free(read->qual1); free(read->name2); free(read->seq2); free(read->qual2); free(read); return NULL; }
void initialize_string_list(TstringList* strL){ initialize_list(strL); }
void initialize_simplex_list(simplex_list *sl, int size) { initialize_list(sl,sizeof(simplex_index *),equal_simplex); hash_list(sl, size, hash_simplex); }
void set_initial_sat_status(){ char *buffer; int clauses, current_literal, clause_length; int *clause_buffer; int empty_clause; FILE * file; size_t nbytes; file = fopen (sat_gs.input_file,"r"); if ( file == NULL ){ report_io_error(1); } buffer = (char*) malloc( (BUFFERSIZE + 1)*sizeof(char) ); if ( buffer == NULL ){ report_io_error(3); } nbytes = BUFFERSIZE; // Skip comments. while ( getline (&buffer, &nbytes, file) && buffer[0] == 'c'); // We read the number of variables and clauses. sscanf( buffer, "p cnf %d%d", &sat_st.num_vars, &sat_st.num_clauses); sat_st.num_original_clauses = sat_st.num_clauses; clause_buffer = (int*) malloc( 2*sat_st.num_vars*sizeof(int) ); // We allocate memory for each of sat_st's internal structures. allocate_sat_status(); clauses = 0; empty_clause = 0; while ( clauses < sat_st.num_clauses && !empty_clause){ char* l_aux; int r_getline; r_getline = getline (&buffer, &nbytes, file); if ( r_getline <= 0){ report_io_error(4); } if (*buffer == 'c') continue; l_aux = buffer; clause_length = 0; while ( sscanf(l_aux, "%d", ¤t_literal) && current_literal != 0 ) { clause_buffer[clause_length] = current_literal; // We search for the next literal in the buffer. // A literal corresponds to a number in the buffer. while ( isdigit(*l_aux) || *l_aux == '-') l_aux++; while ( !( isdigit(*l_aux) || *l_aux == '-') ) l_aux++; clause_length++; } if ( clause_length == 0 ){ empty_clause = 1; } else { // We copy the array of literals just read (clause_buffer) in the // current line to one of sat_st's clauses. set_clause(&sat_st.formula[clauses], clause_length, clause_buffer); } clauses++; } initialize_list(&sat_st.backtracking_status); //initialize_list_bt(&sat_st.backtracking_status); initialize_list(&sat_st.unit_learned_clauses); int i ; for (i = 0; i<=sat_st.num_vars; i++){ sat_st.impl_graph[i].decision_level = -1; sat_st.impl_graph[i].conflictive_clause = 0; sat_st.ac[i] = 0.0; sat_st.lit_ac[i] = 0; } free( buffer ); free( clause_buffer ); fclose(file); sat_st.clause_upper_bound = 2*sat_st.num_clauses; sat_st.clause_available_space = sat_st.num_clauses; sat_st.num_original_clauses = sat_st.num_clauses; sat_gs.restart_max_unit_clauses = 0; sat_gs.num_expanded_nodes = 0; sat_gs.num_non_chronological_jumps = 0; sat_gs.unit_learned_clauses = 0; sat_gs.num_conflicts = 0; }
void validate_map(partition_map_header *map) { range_list *list; char *name; unsigned int i; u32 limit; int printed; //printf("Validation not implemented yet.\n"); if (map == NULL) { the_map = 0; if (get_string_argument("Name of device: ", &name, 1) == 0) { bad_input("Bad name"); return; } the_media = open_pathname_as_media(name, O_RDONLY); if (the_media == 0) { error(errno, "can't open file '%s'", name); free(name); return; } g = media_granularity(the_media); if (g < PBLOCK_SIZE) { g = PBLOCK_SIZE; } the_media = open_deblock_media(PBLOCK_SIZE, the_media); buffer = malloc(PBLOCK_SIZE); if (buffer == NULL) { error(errno, "can't allocate memory for disk buffer"); goto done; } } else { name = 0; the_map = map; g = map->logical_block; } initialize_list(&list); // get block 0 if (get_block_zero() == 0) { printf("unable to read block 0\n"); goto check_map; } // XXX signature valid // XXX size & count match DeviceCapacity // XXX number of descriptors matches array size // XXX each descriptor wholly contained in a partition // XXX the range below here is in physical blocks but the map is in logical blocks!!! add_range(&list, 1, b0->sbBlkCount-1, 0); /* subtract one since args are base & len */ check_map: // compute size of map if (map != NULL) { limit = the_map->blocks_in_map; } else { if (get_block_n(1) == 0) { printf("unable to get first block\n"); goto done; } else { if (mb->dpme_signature != DPME_SIGNATURE) { limit = -1; } else { limit = mb->dpme_map_entries; } } } // for each entry for (i = 1; ; i++) { #if 0 if (limit < 0) { /* XXX what to use for end of list? */ if (i > 5) { break; } } else #endif if (i > limit) { break; } printf("block %d:\n", i); // get entry if (get_block_n(i) == 0) { printf("\tunable to get\n"); goto post_processing; } printed = 0; // signature matches if (mb->dpme_signature != DPME_SIGNATURE) { printed = 1; printf("\tsignature is 0x%x, should be 0x%x\n", mb->dpme_signature, DPME_SIGNATURE); } // reserved1 == 0 if (mb->dpme_reserved_1 != 0) { printed = 1; printf("\treserved word is 0x%x, should be 0\n", mb->dpme_reserved_1); } // entry count matches #if 0 if (limit < 0) { printed = 1; printf("\tentry count is 0x%lx, real value unknown\n", mb->dpme_map_entries); } else #endif if (mb->dpme_map_entries != limit) { printed = 1; printf("\tentry count is 0x%lx, should be %ld\n", mb->dpme_map_entries, limit); } // lblocks contained within physical if (mb->dpme_lblock_start >= mb->dpme_pblocks || mb->dpme_lblocks > mb->dpme_pblocks - mb->dpme_lblock_start) { printed = 1; printf("\tlogical blocks (%ld for %ld) not within physical size (%ld)\n", mb->dpme_lblock_start, mb->dpme_lblocks, mb->dpme_pblocks); } // remember stuff for post processing add_range(&list, mb->dpme_pblock_start, mb->dpme_pblocks, 1); // XXX type is known type? // XXX no unknown flags? // XXX boot blocks either within or outside of logical // XXX checksum matches contents // XXX other fields zero if boot_bytes is zero // XXX processor id is known value? // XXX no data in reserved3 if (printed == 0) { printf("\tokay\n"); } } post_processing: // properties of whole map // every block on disk in one & only one partition coalesce_list(list); print_range_list(list); // there is a partition for the map // map fits within partition that contains it // try to detect 512/2048 mixed partition map? done: if (map == NULL) { close_media(the_media); free(buffer); free(name); } }
static void initialize_sorted_list(Generic_list * list, int (*lt) (void *a, void *b)) { initialize_list(list); list->info->lt = lt; }