#include "todo.h" #ifdef CONFIG_TODO int bbs_todo( term_screen *ts, const char *fname) { int ret=0; int ret_len; size_t in_size=0; char *in_buf=NULL; int quit_loop=0; int menu_input = 0; char menu_cmd = 0; int row = 0; char *todo_fname = NULL; if ( ts == NULL ) return ret; if ( fname == NULL ) { todo_fname = CONFIG_TODO_DEFAULT_FILE; } else { todo_fname = fname; } //LOAD DATA FROM FILE TO LINKED LIST List *todo_list = llist_new(); f_file *file = f_file_open( todo_fname, F_FILE_READ ); if ( file != NULL ) { const int l_s = 128; int r_v; { cycle0:; char *l = malloc( l_s ); r_v = f_file_readl( file, l_s, l ); if ( r_v < 0 ) goto exit_cycle0; l[r_v] = '\0'; llist_push( todo_list, l ); goto cycle0; exit_cycle0:; if ( l != NULL ) free( l ); } } f_file_close( file ); //LOAD DATA FROM FILE TO LINKED LIST //END //log that someone use todo bbs_log( NULL, "visited TODO" ); while( (quit_loop == 0) ) { term_clr_scr( ts ); term_cur_set_c( ts, 0 ); printf("(Q)uit"); fflush( stdout ); //dispaly todo list row = term_get_maxrow( ts ); term_cur_set_c( ts, 0 ); { struct ListNode *iter=todo_list->first; int cnt = 1; while ( (iter != NULL) || ( cnt > row - 2)) { term_cur_set_c( ts, 0 ); term_cur_set_r( ts, 1+cnt ); printf( "[%02d] -> %s\n", cnt, (char *)iter->val); cnt += 1; iter = iter->next; } } 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 ) continue; menu_cmd = (char)menu_input; switch( menu_cmd ) { case 'q': case 'Q': quit_loop = 1; break; case 's': case 'S': { struct ListNode *iter=todo_list->first; int cnt = 1; while (iter != NULL) { printf( "[%02d] -> %s\n", cnt, (char *)iter->val); cnt += 1; iter = iter->next; } } break; default: printf("Try more\n"); } } llist_free( todo_list ); return ret; } #endif