void* dequeue(t_queue* queue) { void* datum=0; if (!ll_empty(queue)) { t_llist_node* node=ll_last(queue); datum=node->val; ll_delete_node(node); } return datum; }
/* Print a list of tokens to stdout, mostly for debugging purposes */ void print_tlist(linked_list *list) { if(ll_empty(list)) { return; } linked_iter iterator = ll_iter_head(list); parse_token *current = ll_iter_next(&iterator); while(ll_iter_has_next(&iterator)) { print_token(current); current = ll_iter_next(&iterator); } print_token(current); }
int main( int argc, char** argv){ int d = 0, quit = 1, commandNum, numRead; char *input, command; Line l = line_init(stdin); Ll ll = ll_init(); gen_parse_args( argc, argv, &d); while( quit){ printf("Command: "); line_read_line( l); input = get_line( l); sscanf(input, " %c%n", &command, &numRead); switch( command){ case 'q': quit = 0; break; case 'i': if( gen_exists_num( input+numRead) ){ sscanf(input+numRead, "%d", &commandNum); ll_insert( ll, commandNum , d); } else printf("Sorry, you didn't enter a number!\n"); break; case 'd': if( gen_exists_num( input+numRead) ){ sscanf( input+numRead, "%d", &commandNum); ll_delete( ll, commandNum, d); } else printf("Sorry, you didn't enter a number!\n"); break; case 'c': if( gen_exists_num( input+numRead) ){ sscanf( input+numRead, "%d", &commandNum); if( ll_contains( ll, commandNum, d) ) printf("LIST DOES CONTAIN %d\n", commandNum); else printf("LIST DOES NOT CONATAIN %d\n", commandNum); } else printf("Sorry, you didn't enter a number!\n"); break; case 'e': ll_empty( ll, d); break; case 'l': ll_print( ll, d); break; case 'r': ll_print_rev( ll, d); break; case '?': gen_print_help(); break; case 'h': gen_print_help(); break; case '\n': break; default: printf("Invalid Command\n"); } free( input); } ll_free( ll, d); line_free( l); return 0; }
//IN THIS CASE REMOVE THE LIST'S CONTENT TOO //BETTER PROVIDE BOTH POSSIBILITY TO DESTROY AND NOT DESTROY //THE CONTENT.EXAMPLE WHAT IF THE SAME OBJECT IS INSIDE TWO DIFFERENT //LISTS? CHECKING C++ LIBRARY CLEAR EMPTY LIST BUT DOESN'T REMOVE //OBJECT.IDEALLY WE COULD ALLOW FREE ON EMPTY LIST ONLY AND //DELETAGE ALL FLUSH JOB TO CALLER.THIS IS IMPRACTICAL BECAUSE LEAD //TO LOT OF DUPLICATE CODE. void free_llist(t_llist *l) { t_llist_node* node; while (!ll_empty(l)) { node=ll_first(l); if (l->data_destructor!=NULL) { (*l->data_destructor)(node->val); } else { kfree(node->val); } ll_delete_node(node); } kfree(l->sentinel_node); kfree(l); }
/************************************************************************** * *N select_feature_class_relate * *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * Purpose: *P * Set up the relationships between features and primitives or between * primitives and features (one way only) for a specified feature class. *E *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: * * History: *H * Barry Michaels DOS Turbo C *E *************************************************************************/ fcrel_type select_feature_class_relate( int fcnum, library_type *library, char *start_table, char *end_table ) { int storage, cov; vpf_table_type fcs; long int i; char path[255], covpath[255]; position_type p; vpf_relate_struct rcell; fcrel_type fcrel; fcrel.nchain = 0; fcrel.table = NULL; fcrel.relate_list = NULL; cov = library->fc[fcnum].coverage; strcpy(covpath,library->cover[cov].path); rightjust(covpath); sprintf( path, "%sfcs", covpath ); /* Feature Class Schema table */ fcs = vpf_open_table( path, disk, "rb", NULL ); fcrel.relate_list = fcs_relate_list( library->fc[fcnum].name, start_table,end_table, fcs ); if (ll_empty(fcrel.relate_list)) { ll_reset(fcrel.relate_list); displaymessage("ERROR in feature class relationship!", start_table,end_table,NULL); return fcrel; } /* Find the number of tables in the relate chain */ p = ll_first(fcrel.relate_list); fcrel.nchain = 0; while (!ll_end(p)) { fcrel.nchain++; p = ll_next(p); } /* Allow for last table2 */ fcrel.nchain++; fcrel.table = (vpf_table_type *) vpfmalloc((fcrel.nchain+1)* sizeof(vpf_table_type)); for (i=0;i<fcrel.nchain+1;i++) vpf_nullify_table( &(fcrel.table[i]) ); p = ll_first(fcrel.relate_list); for (i=0;i<fcrel.nchain-1;i++) { ll_element(p,&rcell); /** Can't open primitive table - may be several under tile **/ /** directories. Open all others **/ if (!is_primitive(rcell.table1)) { sprintf(path,"%s%s",covpath,rcell.table1); if (is_join(rcell.table1)) storage = ram; else storage = disk; fcrel.table[i] = vpf_open_table(path,(storage_type)storage,"rb",NULL); } if (!ll_end(p)) p = ll_next(p); } /* End of relate chain */ i = fcrel.nchain-1; if (!is_primitive(rcell.table2)) { sprintf(path,"%s%s",covpath,rcell.table2); storage = disk; fcrel.table[i] = vpf_open_table(path,(storage_type)storage,"rb",NULL); } vpf_close_table( &fcs ); return fcrel; }
static unsigned int _read_write_28_ata(t_io_request* io_request) { int i; struct t_process_context* process_context; struct t_process_context *current_process_context; t_device_desc* device_desc; t_io_request* pending_request; t_llist_node* node; SAVE_IF_STATUS CLI exit_count_7++; io_request->status=REQUEST_WAITING; device_desc=io_request->device_desc; if (device_desc->status==REQUEST_WAITING || test==0) { ll_append(device_desc->pending_request,io_request); test=io_request->process_context->pid; _sleep(); } else { device_desc->status=REQUEST_WAITING; } if (io_request->process_context->pid==test) { i++; } out(0xE0 | (io_request->lba >> 24),0x1F6); out((unsigned char)io_request->sector_count,0x1F2); out((unsigned char)io_request->lba,0x1F3); out((unsigned char)(io_request->lba >> 8),0x1F4); out((unsigned char)(io_request->lba >> 16),0x1F5); out(io_request->command,0x1F7); if (io_request->command==WRITE_28) { for (i=0;i<256;i++) { //out(*(char*)io_request->io_buffer++,0x1F0); outw((unsigned short)57,0x1F0); } } system.device_desc->serving_request=io_request; if (system.process_info.current_process->val!=NULL) { io_request->process_context=system.process_info.current_process->val; _sleep(); } else { while(io_request->status==REQUEST_WAITING); } if (io_request->process_context->pid==test) { i++; } if (io_request->status!=REQUEST_COMPLETED) { panic(); return -1; } if (io_request->command==READ_28) { for (i=0;i<256;i++) { //out(*(char*)io_buffer++,0x1F0); int zz=inw(0x1F0); ((char*)io_request->io_buffer)[i]=zz; } } if (!ll_empty(device_desc->pending_request)) { node=ll_first(device_desc->pending_request); pending_request=(t_io_request*) node->val; ll_delete_node(node); _awake(pending_request->process_context); } RESTORE_IF_STATUS return 0; }