gint testMove2(autounit_test_t *t) { Stack stkFrom,stkTo; QueryNode tmp; stk_init(&stkFrom); stk_init(&stkTo); tmp.operator = QPP_OP_OR; stk_push(&stkFrom,&tmp); tmp.operator = QPP_OP_AND; stk_push(&stkFrom,&tmp); tmp.operator = QPP_OP_NEAR; stk_push(&stkFrom,&tmp); stk_moveTillParen(&stkFrom,&stkTo); au_assert(t,"",stkTo.queryNodes[0].operator == QPP_OP_NEAR); au_assert(t,"",stkTo.queryNodes[1].operator == QPP_OP_AND); au_assert(t,"",stkTo.queryNodes[2].operator == QPP_OP_OR); au_assert(t,"",stkTo.index == 3); return TRUE; }
gint testMorePushPop(autounit_test_t *t) { QueryNode queryNode[10]; QueryNode tmp; queryNode[0].operator = QPP_OP_AND; queryNode[1].operator = QPP_OP_OR; queryNode[1].num_of_operands = 2; queryNode[2].operator = QPP_OP_STAR; queryNode[2].num_of_operands = 1; queryNode[2].opParam = STAR_BEGIN; queryNode[3].operator = QPP_OP_BEG_PHRASE; queryNode[4].operator = -1; queryNode[4].wordid = 4; queryNode[5].operator = QPP_OP_END_PHRASE; queryNode[6].operator = -1; queryNode[6].wordid = 6; stk_init(&stack); for (i = 0; i<7; i++) stk_push(&stack,&(queryNode[i]) ); stk_pop(&stack,&tmp); au_assert(t,"",tmp.operator == -1); au_assert(t,"",tmp.wordid == 6); stk_pop(&stack,&tmp); au_assert(t,"",tmp.operator == QPP_OP_END_PHRASE); stk_pop(&stack,&tmp); au_assert(t,"",tmp.operator == -1); au_assert(t,"",tmp.wordid == 4); stk_pop(&stack,&tmp); au_assert(t,"",tmp.operator == QPP_OP_BEG_PHRASE); stk_pop(&stack,&tmp); au_assert(t,"",tmp.operator == QPP_OP_STAR); au_assert(t,"",tmp.num_of_operands == 1); au_assert(t,"",tmp.opParam == STAR_BEGIN); stk_pop(&stack,&tmp); au_assert(t,"",tmp.operator == QPP_OP_OR); au_assert(t,"",tmp.num_of_operands == 2); stk_pop(&stack,&tmp); au_assert(t,"",tmp.operator == QPP_OP_AND); nRet = stk_pop(&stack,&tmp); au_assert(t,"",nRet == STACK_UNDERFLOW); return TRUE; }
gint testErrors(autounit_test_t *t) { QueryNode tmp; stk_init(&stack); nRet = stk_pop(&stack,&tmp); au_assert(t,"",nRet == STACK_UNDERFLOW); return TRUE; }
void localinit(void) { falloc_init(); /* probe_init(true);*/ sound_init(); #ifdef CMTSTUFF seqext_init(); #endif sine_init(); stk_init(); }
gint testPushPop(autounit_test_t *t) { QueryNode queryNode; stk_init(&stack); queryNode.operator = QPP_OP_STAR; stk_push(&stack,&queryNode); stk_pop(&stack,&queryNode); au_assert(t,"",queryNode.operator == QPP_OP_STAR); return TRUE; }
void parse(void) { int rv; stk_init(&sp); err = 0; rv = mpl_init(&token.num.value); if (rv != MPL_OK) { printf("memory error\n"); return ; } get_next_token(); list_expr(); }
int main() { struct stack sp; stk_init(&sp); mpl_int a, b, c, d, e, f; char as[] = "12"; char bs[] = "128"; char cs[] = "5"; char str[10]; int i; mpl_init(&a); mpl_init(&b); mpl_init(&c); mpl_set_str(&a, as, 10); mpl_set_str(&b, bs, 10); mpl_set_str(&c, cs, 10); push_item(&sp, &a); push_item(&sp, &b); push_item(&sp, &c); print_stk(&sp); pop_item(&sp, &d); pop_item(&sp, &e); pop_item(&sp, &f); mpl_add(&d, &f, &e); mpl_to_str(&d, str, 10, 10); for (i = 0; str[i] != '\0'; i++) printf("%c", str[i]); printf("\n"); return 0; }
static int QPP_parse(void* word_db, char infix[], int max_infix_size, QueryNode postfix[], int maxNode) { QueryNode quNode; char tmpQueryStr[STRING_SIZE]; int nRet = 0; TokenObj tkObj; StateObj stObj; DEBUG("infix query: [%s]",infix); strncpy(tmpQueryStr,infix,STRING_SIZE-1); tmpQueryStr[STRING_SIZE-1] = '\0'; DEBUG("before tokenizer set string"); tk_setString(&tkObj,tmpQueryStr); stk_init(&(stObj.postfixStack)); stk_init(&(stObj.operatorStack)); stObj.searchField = -1; // search all field stObj.nextTurn = TURN_OPERAND; stObj.posWithinPhrase = FALSE; stObj.numPhraseOperand = 0; stObj.truncated = 0; stObj.virtualfield = 0; stObj.virtualfield_morpid = 20; stObj.natural_search = 0; quNode.original_word[0] = '\0'; // 초기화 DEBUG("before entering while loop"); while (1) { nRet = tk_getNextToken(&tkObj,&quNode,MAX_ORIGINAL_WORD_LEN); DEBUG("got next token nRet [%d], token_string[%s]",nRet, quNode.original_word); // error if (nRet == END_OF_STRING) break; else if (nRet == TOKEN_OVERFLOW) continue; // FIXME warn and push the token to stack.. else if (nRet == 0) continue; // right token switch (nRet) { case TOKEN_STAR: nRet = pushStarredWord(word_db, &stObj,&quNode); break; case TOKEN_NUMERIC: nRet = pushNumeric(&stObj,&quNode); break; case TOKEN_OPERATOR: nRet = pushOperator(&stObj,&quNode); break; default: // case nRet < 0 nRet = pushExtendedOperand(word_db, &stObj,&quNode); break; } if (nRet < 0) break; } DEBUG("stack postfix index is [%d]",stObj.postfixStack.index); // parse된 데이터가 있고, // operator로 끝나서 다음이 operand차례이면 // fake operand를 집어넣는다. if (stObj.postfixStack.index > 0 && stObj.nextTurn ==TURN_OPERAND) { DEBUG("pushing fake operand because stack ended with operator"); pushFakeOperand(&stObj); } nRet = stk_moveTillBottom(&(stObj.operatorStack),&(stObj.postfixStack)); DEBUG("stk_moveTillBottom nRet is (%d)",nRet); nRet = stk_copyQueryNodes(&(stObj.postfixStack),maxNode,postfix); DEBUG("stk_copyQueryNodes nRet is (%d)",nRet); if (nRet == QPP_QUERY_NODE_OVERFLOW) { error("query node overflow. maxNode:%d", maxNode); return QPP_QUERY_NODE_OVERFLOW; } /* if (nRet == QPP_QUERY_NODE_OVERFLOW) { DEBUG("OVERFLOW handling"); return handle_query_overflow(maxNode, postfix); }*/ return stObj.postfixStack.index; }
int main(int argc, char *argv[]) { int result = ACTION_NONE; int leave = 0; char *editor_file = 0; char path[512]; SDL_Surface *loading; #ifdef __unix__ gid_t realgid; hi_dir_chart_file = fopen(HI_DIR "/" CHART_FILE_NAME, "r+"); /* This is where we drop our setuid/setgid privileges. */ realgid = getgid(); if (setresgid(-1, realgid, realgid) != 0) { perror("Could not drop setgid privileges. Aborting."); exit(1); } #endif /* i18n */ #ifdef ENABLE_NLS setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); #endif #ifdef _WIN32 /* Get Windows to open files in binary mode instead of default text mode */ _fmode = _O_BINARY; #endif /* lbreakout info */ printf( "LBreakout2 %s\nCopyright 2001-2010 Michael Speck\nPublished under GNU GPL\n---\n", VERSION ); printf( "Looking up data in: %s\n", SRC_DIR ); printf( "Looking up highscores in: %s\n", HI_DIR ); printf( "Looking up custom levels in: %s/%s/lbreakout2-levels\n", (getenv( "HOME" )?getenv( "HOME" ):"."), CONFIG_DIR_NAME ); #ifndef AUDIO_ENABLED printf( "Compiled without sound and music\n" ); #endif set_random_seed(); /* set random seed */ config_load(); stk_init( SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK ); if ( config.fullscreen ) stk_display_open( SDL_SWSURFACE | SDL_FULLSCREEN, 640, 480, 16 ); else stk_display_open( SDL_SWSURFACE, 640, 480, 16 ); stk_audio_open( 0,0,0,config.audio_buffer_size ); SDL_WM_SetCaption( "LBreakout2", 0 ); SDL_SetEventFilter( event_filter ); stk_audio_enable_sound( config.sound ); stk_audio_set_sound_volume( config.volume * 16 ); /* load a little loading pic */ stk_surface_set_path( SRC_DIR "/gfx" ); loading = stk_surface_load( SDL_SWSURFACE, "loading.png" ); stk_surface_blit( loading, 0,0,-1,-1, stk_display, (stk_display->w-loading->w)/2, (stk_display->h-loading->h)/2 ); stk_display_update( STK_UPDATE_ALL ); /* load the GUI graphics from SRC_DIR/gui_theme */ stk_surface_set_path( SRC_DIR ); stk_audio_set_path( SRC_DIR ); gui_init( "gui_theme" ); stk_surface_set_path( SRC_DIR "/gfx" ); stk_audio_set_path( SRC_DIR "/sounds" ); /* load resources */ /* for simplicity all functions are kept but anything * that is now themeable is loaded in * theme_load instead of the original function * (deleting resources works analouge) */ theme_get_list(); if ( config.theme_count != theme_count ) { if ( config.theme_id >= theme_count ) config.theme_id = 0; config.theme_count = theme_count; } theme_load( theme_names[config.theme_id] ); /* old functions still with initialzations of * lists or variables */ client_game_create(); hint_load_res(); chart_load(); manager_create(); client_create(); exp_load(); editor_create(); help_create(); /* run game */ manager_fade( STK_FADE_IN ); while( !leave && !stk_quit_request ) { result = manager_run(); switch( result ) { case ACTION_QUIT: leave = 1; break; case ACTION_RESUME_0: manager_fade( STK_FADE_OUT ); if ( client_game_resume_local( 0 ) ) client_game_run(); client_game_finalize(); manager_fade( STK_FADE_IN ); break; case ACTION_PLAY_LBR: manager_fade( STK_FADE_OUT ); gameSeed = rand(); /* set random seed for next FREAKOUT/BonusLevels */ if ( client_game_init_local( "LBreakout2" ) ) client_game_run(); client_game_finalize(); manager_fade( STK_FADE_IN ); break; case ACTION_PLAY_CUSTOM: manager_fade( STK_FADE_OUT ); gameSeed = rand(); /* set random seed for next FREAKOUT/BonusLevels */ if (gameSeed==0) gameSeed=1; /* not allowed because.... A HACK!!! 0 means to have no bonus levels to save a parameter */ if ( client_game_init_local( levelset_names_local[config.levelset_id_local] ) ) client_game_run(); client_game_finalize(); manager_fade( STK_FADE_IN ); break; case ACTION_EDIT: /* new set? */ if ( strequal( NEW_SET, edit_set ) ) { editor_file = calloc( 16, sizeof( char ) ); snprintf( path, sizeof(path)-1, "%s/%s/lbreakout2-levels", getenv( "HOME" )? getenv("HOME"):".", CONFIG_DIR_NAME ); if ( !enter_string( font, _("Set Name:"), editor_file, 12 ) || !file_check( path, editor_file, "w" ) ) { free( editor_file ); break; } else manager_update_set_list(); } else editor_file = strdup( edit_set ); if ( editor_init( editor_file ) ) { manager_fade( STK_FADE_OUT ); editor_run(); editor_clear(); manager_fade( STK_FADE_IN ); } free( editor_file ); editor_file = 0; break; case ACTION_QUICK_HELP: help_run(); break; case ACTION_CLIENT: manager_fade( STK_FADE_OUT ); client_run(); manager_fade( STK_FADE_IN ); break; default: break; } } manager_fade( STK_FADE_OUT ); /* delete stuff */ help_delete(); manager_delete(); chart_save(); chart_delete(); editor_delete(); exp_delete(); client_game_delete(); hint_delete_res(); theme_delete(); theme_delete_list(); stk_surface_free( &loading ); config_save(); if (hi_dir_chart_file) fclose(hi_dir_chart_file); return EXIT_SUCCESS; }
int main (int argc, char* argv[]) { int fd, kernel_fd = -1; /* scanning whether there's -h or --help in the options */ char c, *unit; while ((c = getopt_long(argc, argv, ":skmdx:", longopts, 0)) != -1) { switch (c) { case 'h': printf (" -d <path>, --disk=<path> specify normal disk\n" " -k <path>, --kernel=<path> specify kernel file\n" " -m NUM , --memsize=NUM specify memory size\n" " -s <path>, --swap=<path> specify swap disk\n" " -h, --help print this message and exit\n"); return 0; break; case 'k': if ((kernel_fd = open (optarg, O_RDONLY)) < 0) return 1; break; case 'm': memsize = strtol (optarg, &unit, 10); if (*unit == 'K' || *unit == 'k') memsize <<= 10; else if (*unit == 'M' || *unit == 'm') memsize <<= 20; break; default: /* ignore other options now */ break; } } if (kernel_fd < 0) { printf ("No kernel file specified.\n"); return 1; } struct stat buf; fstat (kernel_fd, &buf); fd = create_mem_file (memsize); /* map the temp file & copy boot and kernel code to the memory */ int brk_end = (int)sbrk (0); mmap ((void*)brk_end, memsize, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED, fd, 0); read_kernel (kernel_fd, brk_end - KERNBASE); /* map the reserved part to where it really should be */ mmap ((void*)KERNBASE, RESERVED_SIZE, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_SHARED, fd, 0); /* Now we have access to ginfo normally. */ ginfo->mem_fd = fd; e820_init (kernel_fd); parse_opts (argc, argv); /* unmap useless page table entries */ memcpy ((void*)(BOOT_CODE), (void*)&__boot_start, PGSIZE); stk_init (brk_end, fd); void (*boot_start) (void); boot_start = __pa (__boot_entry); boot_start (); return 0; }
gint testInit(autounit_test_t *t) { nRet = stk_init(&stack); au_assert(t,"",nRet == SUCCESS); return TRUE; }