#include "door.h" #ifdef CONFIG_DOORGAMES //just for full fill libc example static int dir_door_game_selector (const struct dirent *unused) { return 1; } int bbs_door_start( term_screen *ts, const char *cmd ) { int ret=0; int restore_mode=1; struct termios orig_i; struct termios orig_o; term_clr_scr( ts ); //if ( tcgetattr( ts->ifd, &orig_i ) == -1 ) restore_mode = 0; //if ( tcgetattr( ts->ofd, &orig_o ) == -1 ) restore_mode = 0; tcsetattr( ts->ifd, TCSAFLUSH, &ts->orig_i ); //tcsetattr( ts->ofd, TCSAFLUSH, &ts->orig_o ); //term_clr_scr( ts ); if ( system( cmd ) == -1 ) { bbs_log( NULL, "couldnt execute %s", cmd ); } if ( restore_mode ) { tcsetattr( ts->ifd, TCSAFLUSH, &ts->raw_i ); //tcsetattr( ts->ofd, TCSAFLUSH, &orig_o ); } return ret; } int bbs_door( term_screen *ts, const char *dir_name ) { int ret=0; int quit_loop=0; int menu_input = 0; char menu_cmd = 0; int row = 0; const char *door_game_dir=NULL; if ( ts == NULL ) return ret; if ( dir_name == NULL ) { door_game_dir = CONFIG_DOOR_DEFAULT_DIR; } else { door_game_dir = dir_name; } //list dir struct stat path_node; struct dirent **eps; int n; //get all articles names in list and use list every time needed List *dir_list = llist_new(); bbs_log_article_list( NULL ); if ( door_game_dir != NULL ) { //should have some bugs be carefull n = scandir( door_game_dir, &eps, dir_door_game_selector, alphasort ); if ( n >= 0) { int cnt; for ( cnt=0; cntd_name ); sds pathname = sds_new( door_game_dir ); sds_cat( pathname, d_name ); //check if its file term_cur_set_c( ts, 0 ); if ( stat( pathname, &path_node ) == 0 ) { if ( (path_node.st_mode & S_IFREG) && (path_node.st_mode & 0111) ) { llist_push( dir_list, pathname ); } else { sds_free( pathname ); sds_free( d_name ); } } else { sds_free( pathname ); sds_free( d_name ); } free( eps[cnt] ); } free( eps ); } else { printf("Err\n"); ERROR("Cannot open article directory\n"); } ret = 0; } while( (quit_loop == 0) ) { term_clr_scr( ts ); term_cur_set_c( ts, 0 ); printf("(L)ist games, (P)lay game, (Q)uit"); fflush( stdout ); term_cur_set_c( ts, 0 ); term_cur_set_r( ts, term_get_maxrow( ts ) ); printf(":"); fflush( stdout ); menu_input = term_getc( ts ); //if something whent wrong dont know why, need to get some test case if ( menu_input == -1 ) { term_cur_set_c( ts, 0 ); ERROR("Cannot read char"); sleep(1); continue; } menu_cmd = (char)menu_input; switch( menu_cmd ) { case 'q': case 'Q': quit_loop = 1; break; case 'l': case 'L': { term_cur_set_c( ts, 0 ); term_cur_set_r( ts, 2 ); //print list of executables struct ListNode *iter=dir_list->first; int cnt = 1; while (iter != NULL) { term_cur_set_c( ts, 0 ); printf( "[%02d] %s\n", cnt, (char *)iter->val); cnt += 1; iter = iter->next; } term_cur_set_c( ts, 0 ); term_print( ts, "Press ANYKEY\n", 13); term_getc( ts ); } break; case 'p': case 'P': { term_cur_set_c( ts, 0 ); printf("Input game number 1-9:"); fflush( stdout ); int game_input = term_getc( ts ); //if something whent wrong dont know why, need to get some test case char game_number = (char)game_input-'0'; if ( game_number > 0 && game_number < 10) { struct ListNode *iter = dir_list->first; int cnt = 1; while ( iter != NULL ) { if ( cnt == game_number ) { bbs_door_start( ts, iter->val ); break; } cnt += 1; iter = iter->next; } } } break; default: printf("Try more\n"); } } //needed special care to free sds strings //llist_free( dir_list ); return ret; } #endif