From 43d3e330b0064c8ab962a7e77b4f26ac2c63f8ec Mon Sep 17 00:00:00 2001 From: FreeArtMan Date: Mon, 22 Jun 2015 12:35:37 +0300 Subject: Replaced print to term_printf. Fixed warning --- articles.c | 20 +++++++++---------- bbsconfig.h | 1 + captcha.c | 4 +++- door.c | 17 ++++++++-------- door.h | 1 + file_use.c | 1 + libterm/term.c | 2 ++ libterm/term_io.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++------- libterm/term_io.h | 13 ++++++++---- microbbs.c | 31 +++++++++++++++-------------- motd.c | 7 +++---- sysinfo.c | 22 ++++++++++----------- todo.c | 30 +++++++++++++++++----------- twit.c | 12 +++++------ user.c | 2 ++ 15 files changed, 143 insertions(+), 79 deletions(-) diff --git a/articles.c b/articles.c index a5c196b..08f115a 100644 --- a/articles.c +++ b/articles.c @@ -24,7 +24,7 @@ int bbs_article( term_screen *ts, const char *fname ) f = fopen( fname, "r" ); if ( f == NULL ) { - printf("Cannot open article file\n"); + term_printf( ts, "Cannot open article file\n"); return -1; } @@ -47,7 +47,7 @@ int bbs_article( term_screen *ts, const char *fname ) { term_cur_set_c( ts, 0 ); term_cur_set_r( ts, max_row ); - printf("(N)ext,(D)ump,(Q)uit:"); fflush( stdout ); + term_printf( ts, "(N)ext,(D)ump,(Q)uit:"); menu_input = term_getc( ts ); //if something whent wrong dont know why, need to get some test case @@ -76,7 +76,7 @@ int bbs_article( term_screen *ts, const char *fname ) while( (tmp_size = getline(&dump_line, &dump_line_size, f)) != -1 ) { term_cur_set_c( ts, 0 ); - printf("%s", dump_line); + term_printf( ts, "%s", dump_line); } FREE( dump_line ); term_getc( ts ); @@ -84,7 +84,7 @@ int bbs_article( term_screen *ts, const char *fname ) i = 0; break; default: - printf("Try more\n"); + term_printf( ts, "Try more\n"); } } @@ -160,7 +160,7 @@ int bbs_article_list( term_screen *ts, const char *dir_name ) free( eps ); } else { - printf("Err\n"); + term_printf( ts, "Err\n"); ERROR("Cannot open article directory\n"); } ret = 0; @@ -172,12 +172,12 @@ int bbs_article_list( term_screen *ts, const char *dir_name ) { term_clr_scr( ts ); term_cur_set_c( ts, 0 ); - printf("(L)ist articles,(R)read article,(Q)uit"); + term_printf( ts, "(L)ist articles,(R)read article,(Q)uit"); fflush( stdout ); term_cur_set_c( ts, 0 ); term_cur_set_r( ts, term_get_maxrow( ts ) ); - printf(":"); fflush( stdout ); + term_printf( ts, ":"); menu_input = term_getc( ts ); //if something whent wrong dont know why, need to get some test case @@ -206,7 +206,7 @@ int bbs_article_list( term_screen *ts, const char *dir_name ) //get stat structure and get filesize stat( iter->val, &art_stat );//no err check - printf( "[%02d] %s ( %ld bytes)\n", cnt, (char *)iter->val, art_stat.st_size ); + term_printf( ts, "[%02d] %s ( %ld bytes)\n", cnt, (char *)iter->val, art_stat.st_size ); cnt += 1; iter = iter->next; } @@ -219,7 +219,7 @@ int bbs_article_list( term_screen *ts, const char *dir_name ) //while there is no more 10 articles use only 1 number //TODO fix that term_cur_set_c( ts, 0 ); - printf("Input article number 1-9:"); fflush( stdout ); + term_printf( ts, "Input article number 1-9:"); int article_input = term_getc( ts ); //if something whent wrong dont know why, need to get some test case char article_number = (char)article_input-'0'; @@ -242,7 +242,7 @@ int bbs_article_list( term_screen *ts, const char *dir_name ) } break; default: - printf("Try more\n"); + term_printf( ts, "Try more\n"); } } //needed special care to free sds strings diff --git a/bbsconfig.h b/bbsconfig.h index 459aeae..e676b74 100644 --- a/bbsconfig.h +++ b/bbsconfig.h @@ -8,6 +8,7 @@ #include #include #include +#include #define ASSERT assert diff --git a/captcha.c b/captcha.c index ea38d85..93cadde 100644 --- a/captcha.c +++ b/captcha.c @@ -9,6 +9,8 @@ int captcha_test1( term_screen *ts) { int ret = 0; + const int s_size = 2; + char s[s_size]; int column=0, row=0; int c=0; @@ -20,7 +22,7 @@ int captcha_test1( term_screen *ts) term_cur_set_r( ts, row/2 ); //just ask question - printf("Are you bot?(y/n):\n"); + term_printf( ts, "Are you bot?(y/n):\n"); c = term_getc( ts ); if ( (c == 'n') || ( c == 'N') ) ret = 1; diff --git a/door.c b/door.c index 5e34e21..82a7538 100644 --- a/door.c +++ b/door.c @@ -17,8 +17,8 @@ int bbs_door_start( term_screen *ts, const char *cmd ) int restore_mode=1; - struct termios orig_i; - struct termios orig_o; + //struct termios orig_i; + //struct termios orig_o; term_clr_scr( ts ); @@ -31,7 +31,7 @@ int bbs_door_start( term_screen *ts, const char *cmd ) //term_clr_scr( ts ); if ( system( cmd ) == -1 ) { - bbs_log( NULL, "couldnt execute %s", cmd ); + bbs_log( "DOOR", "couldnt execute doorgame"); } if ( restore_mode ) @@ -51,7 +51,6 @@ int bbs_door( term_screen *ts, const char *dir_name ) int quit_loop=0; int menu_input = 0; char menu_cmd = 0; - int row = 0; const char *door_game_dir=NULL; if ( ts == NULL ) @@ -112,7 +111,7 @@ int bbs_door( term_screen *ts, const char *dir_name ) free( eps ); } else { - printf("Err\n"); + term_printf( ts, "Err\n"); ERROR("Cannot open article directory\n"); } ret = 0; @@ -122,12 +121,12 @@ int bbs_door( term_screen *ts, const char *dir_name ) { term_clr_scr( ts ); term_cur_set_c( ts, 0 ); - printf("(L)ist games, (P)lay game, (Q)uit"); fflush( stdout ); + term_printf( ts, "(L)ist games, (P)lay game, (Q)uit"); term_cur_set_c( ts, 0 ); term_cur_set_r( ts, term_get_maxrow( ts ) ); - printf(":"); fflush( stdout ); + term_printf( ts, ":"); menu_input = term_getc( ts ); //if something whent wrong dont know why, need to get some test case @@ -171,7 +170,7 @@ int bbs_door( term_screen *ts, const char *dir_name ) case 'P': { term_cur_set_c( ts, 0 ); - printf("Input game number 1-9:"); fflush( stdout ); + term_printf( ts, "Input game number 1-9:"); 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'; @@ -194,7 +193,7 @@ int bbs_door( term_screen *ts, const char *dir_name ) } break; default: - printf("Try more\n"); + term_printf( ts, "Try more\n"); } } diff --git a/door.h b/door.h index fee893c..5645db1 100644 --- a/door.h +++ b/door.h @@ -15,6 +15,7 @@ #include "kconfig.h" #include "list.h" #include "sds.h" +#include "logs.h" #include "libterm/term.h" #include "libterm/term_io.h" diff --git a/file_use.c b/file_use.c index b21ebdd..ac5fca3 100644 --- a/file_use.c +++ b/file_use.c @@ -149,6 +149,7 @@ int f_file_size( f_file *f_f ) //--------------------------------------------------------------------- size_t f_file_write( f_file *f_f, size_t size, void *ptr ) { + size_t ret = -1; //PRINT("\n"); if ( f_f ) { diff --git a/libterm/term.c b/libterm/term.c index 532dc92..2a726b4 100644 --- a/libterm/term.c +++ b/libterm/term.c @@ -27,6 +27,8 @@ int term_init( term_screen *term ) //if you whant raw mode then you should set it man if ( tcgetattr( term->ifd, &term->orig_i ) == -1 ) goto exit_error; term->raw_i = term->orig_i; + if ( tcgetattr( term->ofd, &term->orig_o ) == -1 ) goto exit_error; + term->raw_o = term->orig_o; term->mode = SCREEN_MODE_80x25; diff --git a/libterm/term_io.c b/libterm/term_io.c index cd1b3c1..d305f51 100644 --- a/libterm/term_io.c +++ b/libterm/term_io.c @@ -140,23 +140,51 @@ int term_readline( term_screen *ts, char *str, size_t str_size, int flag ) menu_cmd = 0; buf_curent = 0; + //finsih when escape button is setted while ( menu_cmd != TK_ESC ) { menu_input = term_getc( ts ); if ( menu_input != -1 ) { menu_cmd = (char)menu_input; - //add to buffer any pritable char - //if ( (isgraph( menu_cmd ) && flag == READLINE_TEXT ) || - // (isalpha( menu_cmd ) && flag == READLINE_ALPHA ) ) - if ( isalpha( menu_cmd ) ) + //add to buffer any printable alpahnumeric char + if ( isalpha( menu_cmd ) && + (flag == READLINE_TEXT || flag == READLINE_ALPHA + || flag == READLINE_HIDDEN) ) { if ( buf_curent < buf_size ) { buf[ buf_curent ] = menu_cmd; buf_curent += 1; } - //deleteone char from buffer + //add to buffer number 0-9 + } else if ( isdigit( menu_cmd ) && + ( flag == READLINE_TEXT || flag == READLINE_NUMBER + || flag == READLINE_HIDDEN )) + { + if ( buf_curent < buf_size ) + { + buf[ buf_curent ] = menu_cmd; + buf_curent += 1; + } + //if space allowed + } else if ( (menu_cmd == ' ') && (flag == READLINE_TEXT) ) + { + if ( buf_curent < buf_size ) + { + buf[ buf_curent ] = menu_cmd; + buf_curent += 1; + } + //remaining printable chars for READLINE_TEXT + } else if ( ispunct( menu_cmd ) && + (flag == READLINE_TEXT )) + { + if ( buf_curent < buf_size ) + { + buf[ buf_curent ] = menu_cmd; + buf_curent += 1; + } + //deleteone char from buffer with backspace } else if ( menu_cmd == TK_BACKSPACE ) { if ( buf_curent > 0) @@ -164,13 +192,14 @@ int term_readline( term_screen *ts, char *str, size_t str_size, int flag ) buf[ buf_curent ] = 0x0; buf_curent -= 1; } - //input ready + //input ready lets finish input } else if ( menu_cmd == TK_ENTER ) { ret = buf_curent; memcpy( str, buf, buf_size ); str[ str_size-1 ] = 0x0; break; + //finsih input without saving result } else if ( menu_cmd == TK_ESC ) { ret = -1; @@ -184,7 +213,8 @@ int term_readline( term_screen *ts, char *str, size_t str_size, int flag ) { if ( i < buf_curent ) { - if ( (flag == READLINE_TEXT) || (flag == READLINE_ALPHA) ) + if ( (flag == READLINE_TEXT) || (flag == READLINE_ALPHA) + || (flag == READLINE_NUMBER) ) { term_putc( ts, buf[i] ); } else if ( flag == READLINE_HIDDEN ) @@ -210,3 +240,18 @@ int term_readline( term_screen *ts, char *str, size_t str_size, int flag ) return ret; } + +//this is to replace printf,flush code +int term_printf( term_screen *ts, const char *format, ...) +{ + int ret=0; + + va_list args; + va_start(args, format); + + vdprintf(ts->ofd, format, args); + + va_end(args); + + return ret; +} diff --git a/libterm/term_io.h b/libterm/term_io.h index 3c84972..b05af39 100644 --- a/libterm/term_io.h +++ b/libterm/term_io.h @@ -3,14 +3,18 @@ #include #include +#include #include "screen_modes.h" #include "term.h" -#define READLINE_NONE 0 -#define READLINE_ALPHA 1 -#define READLINE_TEXT 2 -#define READLINE_HIDDEN 3 +#define READLINE_NONE 0 //none +#define READLINE_ALPHA 1 //isalpsha +#define READLINE_TEXT 2 //[a-zA-Z0-9] + ispunct +#define READLINE_HIDDEN 3 //[a-zA-Z] +#define READLINE_NUMBER 4 //[0-9] +#define READLINE_SYMBOL 5 //not yet +#define READLINE_ALPHANUM 6 //not yet int term_fprint( screen_mode_e mode, FILE *f ); @@ -21,5 +25,6 @@ int term_draw_hline( term_screen *ts, int pc, int pr, int sz, char ch ); int term_getc( term_screen *ts ); int term_putc( term_screen *ts, char c ); int term_readline( term_screen *ts, char *str, size_t str_size, int flag ); +int term_printf( term_screen *ts, const char *format, ...); #endif diff --git a/microbbs.c b/microbbs.c index 70dc388..5024b8b 100644 --- a/microbbs.c +++ b/microbbs.c @@ -13,6 +13,7 @@ #include "bbsconfig.h" #include "twit.h" #include "todo.h" +#include "door.h" #include "libterm/term.h" #include "libterm/term_io.h" @@ -67,47 +68,47 @@ int main( int argc, char **argv ) #ifdef CONFIG_LOGIN if ( bbs_user_get_status( &g_user ) == BBS_USER_LOGEDIN ) - printf("[LOGEDIN] "); + term_printf( &ts, "[LOGEDIN] "); #endif #ifdef CONFIG_MOTD - printf("(M)otd "); + term_printf( &ts, "(M)otd "); #endif #ifdef CONFIG_ARTICLES - printf("(A)rticles "); + term_printf( &ts, "(A)rticles "); #endif #ifdef CONFIG_DOORGAMES - printf("(D)oor games "); + term_printf( &ts, "(D)oor games "); #endif #ifdef CONFIG_TWIT - printf("(T)wit "); + term_printf( &ts, "(T)wit "); #endif #ifdef CONFIG_BOARD - printf("(B)oard "); + term_printf( &ts, "(B)oard "); #endif #ifdef CONFIG_LOGIN if ( bbs_user_get_status( &g_user ) != BBS_USER_LOGEDIN ) - printf("(L)ogin "); + term_printf( &ts, "(L)ogin "); #endif #ifdef CONFIG_TODO - printf("T(o)do "); + term_printf( &ts, "T(o)do "); #endif #ifdef CONFIG_MESSAGING - printf("Mesa(G)es "); + term_printf( &ts, "Mesa(G)es "); #endif - printf("(Q)uit (S)ysinfo"); fflush( stdout ); + term_printf( &ts, "(Q)uit (S)ysinfo"); term_cur_set_c( &ts, 0 ); term_cur_set_r( &ts, term_get_maxrow( &ts ) ); - printf(":"); fflush( stdout ); + term_printf( &ts, ":"); //ret_len = getline( &str, &str_size, stdin ); main_menu_input = term_getc( &ts ); //if something whent wrong dont know why, need to get some test case @@ -172,7 +173,7 @@ int main( int argc, char **argv ) case 'g': case 'G': { - printf("Messages\n"); + term_printf( &ts, "Messages\n"); } break; #endif @@ -182,7 +183,7 @@ int main( int argc, char **argv ) case 'b': case 'B': { - printf("Board\n"); + term_printf( &ts, "Board\n"); } break; #endif @@ -203,7 +204,7 @@ int main( int argc, char **argv ) case 'o': case 'O': { - printf("Todo list\n"); + term_printf( &ts, "Todo list\n"); bbs_todo( &ts, NULL ); } break; @@ -216,7 +217,7 @@ int main( int argc, char **argv ) bbs_log_quit( NULL ); break; default: - printf("Unknow command\n"); + term_printf( &ts, "Unknow command\n"); } } #ifdef CONFIG_MOTD diff --git a/motd.c b/motd.c index df26f11..19eff13 100644 --- a/motd.c +++ b/motd.c @@ -6,18 +6,17 @@ //TODO complcations with libterm int bbs_motd_draw( term_screen *ts, const char *fname ) { - int posc=0, posr=0; + int posr=0; int ret=0; const int buf_size=80*26+1; char buf[buf_size]; - int x=0,y=0; int row=0,column=0; FILE *f = fopen( fname, "r" ); if ( f == NULL ) { - printf("Cannot open file %s\n", fname); + term_printf( ts, "Cannot open file %s\n", fname); return -1; } @@ -37,7 +36,7 @@ int bbs_motd_draw( term_screen *ts, const char *fname ) { if ( buf[i] != '\n' ) { - printf("%c",buf[i] ); + term_printf( ts, "%c",buf[i] ); } else if ( buf[i] == '\n') { diff --git a/sysinfo.c b/sysinfo.c index b43d4e5..1509925 100644 --- a/sysinfo.c +++ b/sysinfo.c @@ -7,39 +7,39 @@ int bbs_sysinfo( term_screen *ts ) //setup screen to show stuff term_clr_scr( ts ); - printf("Press ANYKEY \n\n\n"); + term_printf( ts, "Press ANYKEY \n\n\n"); term_cur_set_c( ts, 0 ); - printf("BBS:MicroBBS %s (%s)\n", BUILD_VERSION, BUILD_DATE); + term_printf( ts, "BBS:MicroBBS %s (%s)\n", BUILD_VERSION, BUILD_DATE); term_cur_set_c( ts, 0 ); - printf("Author: FreeArtMan\n"); + term_printf( ts, "Author: FreeArtMan\n"); term_cur_set_c( ts, 0 ); - printf("Contributor: epoch\n"); + term_printf( ts, "Contributor: epoch\n"); term_cur_set_c( ts, 0 ); - printf("Main chan: irc://irc.freenode.net#mainlv\n"); + term_printf( ts, "Main chan: irc://irc.freenode.net#mainlv\n"); term_cur_set_c( ts, 0 ); - printf("Ideological support: irc://hacking.allowed.org#default\n"); + term_printf( ts, "Ideological support: irc://hacking.allowed.org#default\n"); term_cur_set_c( ts, 0 ); - printf("Root dir: %s\n",g_config.root_dir ); + term_printf( ts, "Root dir: %s\n",g_config.root_dir ); term_cur_set_c( ts, 0 ); - printf("Users dir: %s\n", g_config.user_dir ); + term_printf( ts, "Users dir: %s\n", g_config.user_dir ); term_cur_set_c( ts, 0 ); - printf("Article dir: %s\n", g_config.article_dir ); + term_printf( ts, "Article dir: %s\n", g_config.article_dir ); term_cur_set_c( ts, 0 ); - printf("Syslog : %d\n", g_config.syslog ); + term_printf( ts, "Syslog : %d\n", g_config.syslog ); //main loop wait while press something term_cur_set_r( ts, term_get_maxrow( ts ) ); term_cur_set_c( ts, 0 ); - printf(":"); fflush( stdout ); + term_printf( ts, ":"); term_getc( ts ); return ret; diff --git a/todo.c b/todo.c index e68ef29..8e293d9 100644 --- a/todo.c +++ b/todo.c @@ -6,14 +6,11 @@ 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; + const char *todo_fname = NULL; if ( ts == NULL ) return ret; @@ -59,7 +56,7 @@ int bbs_todo( term_screen *ts, const char *fname) { term_clr_scr( ts ); term_cur_set_c( ts, 0 ); - printf("(A)dd,(Q)uit"); fflush( stdout ); + term_printf( ts, "(A)dd,(R)emove,(Q)uit"); //dispaly todo list row = term_get_maxrow( ts ); @@ -71,7 +68,7 @@ int bbs_todo( term_screen *ts, const char *fname) { term_cur_set_c( ts, 0 ); term_cur_set_r( ts, 1+cnt ); - printf( "[%02d] -> %s\n", cnt, (char *)iter->val); + term_printf( ts, "[%02d] -> %s\n", cnt, (char *)iter->val); cnt += 1; iter = iter->next; } @@ -80,7 +77,7 @@ int bbs_todo( term_screen *ts, const char *fname) term_cur_set_c( ts, 0 ); term_cur_set_r( ts, term_get_maxrow( ts ) ); - printf(":"); fflush( stdout ); + term_printf( ts, ":"); menu_input = term_getc( ts ); //if something whent wrong dont know why, need to get some test case @@ -107,15 +104,22 @@ int bbs_todo( term_screen *ts, const char *fname) int cnt = 1; while (iter != NULL) { - printf( "[%02d] -> %s\n", cnt, (char *)iter->val); + term_printf( ts, "[%02d] -> %s\n", cnt, (char *)iter->val); cnt += 1; iter = iter->next; } } break; + case 'r': + case 'R': + { + bbs_todo_remove( ts, todo_list, todo_fname ); + } + break; + default: - printf("Try more\n"); + term_printf( ts, "Try more\n"); } } @@ -140,11 +144,11 @@ int bbs_todo_add( term_screen *ts, List *todo, const char *fname) term_clr_scr( ts ); term_cur_set_c( ts, 0 ); term_cur_set_r( ts, 0 ); - printf("Add new todo task:\n"); fflush( stdout ); + term_printf( ts, "Add new todo task:\n"); memset( buf, 0, buf_size ); term_cur_set_c( ts, 0 ); - fret = term_readline( ts, buf, buf_size, READLINE_ALPHA ); + fret = term_readline( ts, buf, buf_size, READLINE_TEXT ); if ( fret > 0 ) { char *l = malloc( fret+1 ); @@ -177,7 +181,9 @@ int bbs_todo_remove( term_screen *ts, List *todo, const char *fname ) term_clr_scr( ts ); term_cur_set_c( ts, 0 ); term_cur_set_r( ts, 0 ); - printf("Remove entry from todo:\n"); fflush( stdout ); + term_printf( ts, "Remove entry from todo:\n"); + + return ret; diff --git a/twit.c b/twit.c index 74b61e1..4c7c008 100644 --- a/twit.c +++ b/twit.c @@ -42,7 +42,7 @@ int bbs_twit( term_screen *ts, char *fn ) { term_clr_scr( ts ); term_cur_set_c( ts, 0 ); - printf("(A)dd,(Q)uit"); fflush( stdout ); + term_printf( ts, "(A)dd,(Q)uit"); //dispaly todo list row = term_get_maxrow( ts ); @@ -54,7 +54,7 @@ int bbs_twit( term_screen *ts, char *fn ) { term_cur_set_c( ts, 0 ); term_cur_set_r( ts, 1+cnt ); - printf( "[%02d] -> %s\n", cnt, (char *)iter->val); + term_printf( ts, "[%02d] -> %s\n", cnt, (char *)iter->val); cnt += 1; iter = iter->next; } @@ -63,7 +63,7 @@ int bbs_twit( term_screen *ts, char *fn ) term_cur_set_c( ts, 0 ); term_cur_set_r( ts, term_get_maxrow( ts ) ); - printf(":"); fflush( stdout ); + term_printf( ts, ":"); menu_input = term_getc( ts ); //if something whent wrong dont know why, need to get some test case @@ -84,7 +84,7 @@ int bbs_twit( term_screen *ts, char *fn ) break; default: - printf("Try more\n"); + term_printf( ts, "Try more\n"); } } @@ -109,11 +109,11 @@ int bbs_twit_add( term_screen *ts, List *twit, const char *fname) term_clr_scr( ts ); term_cur_set_c( ts, 0 ); term_cur_set_r( ts, 0 ); - printf("Put new twit:\n"); fflush( stdout ); + term_printf( ts, "Put new twit:\n"); memset( buf, 0, buf_size ); term_cur_set_c( ts, 0 ); - fret = term_readline( ts, buf, buf_size, READLINE_ALPHA ); + fret = term_readline( ts, buf, buf_size, READLINE_TEXT ); if ( fret > 0 ) { char *l = malloc( fret+1 ); diff --git a/user.c b/user.c index 5e2ef19..1f89f4a 100644 --- a/user.c +++ b/user.c @@ -78,6 +78,8 @@ int bbs_login( term_screen *ts ) fret = bbs_login_auth( userdata_dir, username_buf, password_buf ); if ( fret == -1 ) { + term_cur_set_r( ts, 0 ); + term_cur_set_c( ts, 0 ); ERROR("No such user\n"); sleep(3); } else if ( fret == 0 ) { -- cgit v1.2.3