int EiC_analyseCode(code_t *C) { /* returns the index to the last visited instruction */ block_t *block = NULL; int nb = 0; int i,j,rtn; int *visit; visit = calloc(sizeof(*visit),nextinst(C)+1); block = realloc(block,(nb+1)*sizeof(*block)); block[nb++] = initblock(C,0,visit); for(i=0;i<nb;++i) { for(j=0;j<block[i].nb;++j) { if(!visit[block[i].branch[j]]) { block = realloc(block,(nb+1)*sizeof(*block)); block[nb++] = initblock(C,block[i].branch[j],visit); } else visit[block[i].branch[j]]++; } } rtn = 0; for(i=0;i<=nextinst(C);) if(visit[i]) rtn = i++; else if(i < nextinst(C) && instline(C,i)) { EiC_warningerror("Unreachable code at line %d",instline(C,i)); for(;i<nextinst(C) && !visit[i];i++) ; } else i++; EiC_peephole(C,visit); /******* for(i=0;i<nextinst(C);++i) if(!visit[i]) setopcode(C,i,empty); *******/ freeblock(block,nb); free(visit); return rtn; }
/*starts SIGCHLD handling when signal method, * handles background processes termination */ void initSignalHandlers(){ /* check that we are using signal method for detecting terminated children */ if (SIGNALDETECTION != 0){ initblock(); setChildSigHandler(); } }
/** * Decrypts a string. For any message, key, and seed, we have that * <code>decrypt(crypt(msg, key, seed), key) == msg</code>. * @param cyphertext: message to be decrypted (this must be the result of a previous call to <code>crypt</code>. * @param key: arbitrary binary string to be used as a key. * @return The plaintext. */ static int decrypt (lua_State *L) { size_t lcyphertext; const char *cyphertext = luaL_checklstring(L, 1, &lcyphertext); size_t lseed = cyphertext[0]; const char *seed = cyphertext+1; int lblock; char block[BLOCKSIZE+MAXKEY]; luaL_argcheck(L, lcyphertext >= lseed+1 && lseed <= BLOCKSIZE, 1, "invalid cyphered string"); cyphertext += lseed+1; lcyphertext -= lseed+1; lblock = initblock(L, seed, lseed, block); decodestream(L, cyphertext, lcyphertext, block, lblock); return 1; }
/** * Encrypts a string. Uses the hash function md5 in CFB (Cipher-feedback * mode). * @param message: arbitrary binary string to be encrypted. * @param key: arbitrary binary string to be used as a key. * @param [seed]: optional arbitrary binary string to be used as a seed. * if no seed is provided, the function uses the result of * <code>time()</code> as a seed. * @return The cyphertext (as a binary string). */ static int crypt (lua_State *L) { size_t lmsg; const char *msg = luaL_checklstring(L, 1, &lmsg); size_t lseed; const char *seed; int lblock; char block[BLOCKSIZE+MAXKEY]; checkseed(L); seed = luaL_checklstring(L, 3, &lseed); if (lseed > BLOCKSIZE) luaL_error(L, "seed too long (> %d)", BLOCKSIZE); /* put seed and seed length at the beginning of result */ block[0] = (char)lseed; memcpy(block+1, seed, lseed); lua_pushlstring(L, block, lseed+1); /* to concat with result */ lblock = initblock(L, seed, lseed, block); codestream(L, msg, lmsg, block, lblock); lua_concat(L, 2); return 1; }
void nextblock(){ copy(b1,b2); initblock(b2); }
void start(){ initscr(); srand(time(0)); init_background(0,0); refresh(); keypad(stdscr,TRUE); pthread_t keyboard; //键盘监听线程 int err = init_network(); //初始化网络模块 if(err!=0){ mvprintw(5,60,"Network model init failed!"); } start: initpanel(); //把两个panel清空 initblock(b1);initblock(b2); printpanel(PANELSTARTX,PANELSTARTY); err = pthread_create(&keyboard,NULL,keylistener,NULL); if(err !=0){ printf("can't create thread keyboard listener!"); exit(1); } //main thread make the block moving down until the gameover while(!over){ movemid(); if(caninput(b1)){ //可以放下当前块说明游戏未结束 while( canmovedown() ){ //直到不能下落位置 //继续下落 goahead(); //显示一次 printpanel(PANELSTARTX,PANELSTARTY); usleep(sleeptime); } //save temp panel to preview panel and create new block savetoprev(); printpanel(PANELSTARTX,PANELSTARTY); //停止下落后要消除 eliminate(); //把下一个块替换上来 nextblock(); } else over=true; } attrset(COLOR_PAIR(7)); mvprintw(21,37,"YOU DEAD!Try again?(y/n):"); int input; int quit = 1; while(quit){ input=getch(); //判断用户还要不要玩下去 switch(input){ case 'y': over = 0; attrset(COLOR_PAIR(0)); mvprintw(21,37," "); goto start; //重新开始 break; case 'n': endwin();quit = 0;break; default: mvprintw(21,37,"YOU DEAD!Try again?(y/n):"); } } }