diff options
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | articles.c | 227 | ||||
-rw-r--r-- | articles.h | 9 | ||||
-rw-r--r-- | captcha.c | 4 | ||||
-rw-r--r-- | logs.h | 1 | ||||
-rw-r--r-- | microbbs.c | 7 | ||||
-rw-r--r-- | sysinfo.h | 1 | ||||
-rw-r--r-- | todo.c | 1 |
8 files changed, 141 insertions, 115 deletions
@@ -1,6 +1,6 @@ PROJECT=microbbs CC=gcc -CFLAGS= +CFLAGS= SOURCES=articles.c bbsconfig.c buildinfo.c captcha.c file_use.c ini.c list.c login.c logs.c mmm.c motd.c sds.c session.c statistics.c sysinfo.c telnetd.c textview.c todo.c vote.c OBJECTS=$(SOURCES:.c=.o) BUILD_DIR=build_dir @@ -25,6 +25,10 @@ $(PROJECT): $(SOURCES) %.o: %.c $(CC) $(CFLAGS) -c $< -o $(BUILD_DIR)/$@ +leak: + valgrind --leak-check=full --track-origins=yes --log-file=log.txt ./$(PROJECT) + + clean: rm -rf *.o microbbs cd ./$(BUILD_DIR); rm -rf *.o @@ -12,21 +12,10 @@ int bbs_article( term_screen *ts, const char *fname ) FILE *f; size_t str_size=0, fret=1; char *str=NULL; - size_t in_size=0; - char *in_buf=NULL; - int max_x, max_y, ret_len; int quit_loop=0; - - if ( ts->mode == SCREEN_MODE_80x24 ) - { - max_x = 80; - max_y = 24; - } else - { - printf("Unknown mode\n"); - max_x = 80; - max_y = 24; - } + int max_row=0; + int menu_input=0; + char menu_cmd=0; bbs_log_article( NULL ); @@ -39,6 +28,9 @@ int bbs_article( term_screen *ts, const char *fname ) return -1; } + term_clr_scr( ts ); + max_row = term_get_maxrow( ts ); + fret = 1; i = 0; while ( (fret > 0) && (quit_loop == 0) ) @@ -46,55 +38,63 @@ int bbs_article( term_screen *ts, const char *fname ) fret = getline( &str, &str_size, f ); if ( fret > 0 ) { + term_cur_set_c( ts, 0 ); printf("%s", str); i += 1; } - //if ( ((i > 0) && (fret == -1)) || - // ((fret > 0) && (i > max_x-1)) ) - if ( i >= max_y-1 ) + if ( i >= max_row ) { - printf("(N)ext,(D)ump,(Q)uit:"); - ret_len = getline( &in_buf, &in_size, stdin ); - if ( ret_len > 0 ) + term_cur_set_c( ts, 0 ); + term_cur_set_r( ts, max_row ); + printf("(N)ext,(D)ump,(Q)uit:"); 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 ) { - char ch = in_buf[0]; - switch( ch ) - { - case 'q': - case 'Q': - quit_loop = 1; - break; - case 'n': - case 'N': - i = 0; - break; - //dump whole file to the screen - case 'd': - case 'D': + case 'q': + case 'Q': + quit_loop = 1; + break; + case 'n': + case 'N': + i = 0; + break; + //dump whole file to the screen + case 'd': + case 'D': + { + char *dump_line=NULL; + size_t dump_line_size=0; + size_t tmp_size=-1; + fseek( f, 0, SEEK_SET ); + while( (tmp_size = getline(&dump_line, &dump_line_size, f)) != -1 ) { - char tmp_buf[81]; - size_t tmp_size; - fseek( f, 0, SEEK_SET ); - while ( (tmp_size = fread( &tmp_buf, 1, 80, f )) > 0 ) - { - tmp_buf[ tmp_size ] = 0; - printf( "%s", tmp_buf ); - } + term_cur_set_c( ts, 0 ); + printf("%s", dump_line); } - i = 0; - break; - default: - printf("Try more\n"); - } + FREE( dump_line ); + term_getc( ts ); + } + i = 0; + break; + default: + printf("Try more\n"); } } if ( (fret == -1) ) + term_getc( ts ); + if ( (fret == -1) ) break; } - + FREE( str ); fclose( f ); ret = 0; } @@ -112,14 +112,9 @@ static int dir_article_selector (const struct dirent *unused) int bbs_article_list( term_screen *ts, const char *dir_name ) { int ret=-1; - int max_x=-1, max_y=-1; - size_t str_size=0,fret=-1; - int ret_len; - char *str=NULL; - size_t in_size=0; - char *in_buf=NULL; int quit_loop=0; - int i; + int menu_input = 0; + char menu_cmd = 0; //list dir struct stat path_node; @@ -129,17 +124,6 @@ int bbs_article_list( term_screen *ts, const char *dir_name ) //get all articles names in list and use list every time needed List *dir_list = llist_new(); - if ( ts->mode == SCREEN_MODE_80x24 ) - { - max_x = 80; - max_y = 24; - } else - { - printf("Unknown mode\n"); - max_x = 80; - max_y = 24; - } - bbs_log_article_list( NULL ); if ( dir_name != NULL ) @@ -163,9 +147,17 @@ int bbs_article_list( term_screen *ts, const char *dir_name ) if ( path_node.st_mode & S_IFREG ) { llist_push( dir_list, cnct_path ); + } else + { + free( cnct_path ); } + } else + { + free( cnct_path ); } + free( eps[cnt] ); } + free( eps ); } else { printf("Err\n"); @@ -175,60 +167,77 @@ int bbs_article_list( term_screen *ts, const char *dir_name ) } - i = 0; + quit_loop = 0; while ( (quit_loop == 0) ) { - printf("(L)ist articles,(R)read article,(Q)uit:"); - ret_len = getline( &in_buf, &in_size, stdin ); - if ( ret_len > 0 ) + term_clr_scr( ts ); + term_cur_set_c( ts, 0 ); + printf("(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 ); + + 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 ) { - char ch = in_buf[0]; - switch( ch ) - { - case 'q': - case 'Q': - quit_loop = 1; - break; - case 'l': - case 'L': + case 'q': + case 'Q': + quit_loop = 1; + break; + case 'l': + case 'L': + { + term_cur_set_r( ts, 2 ); + //print list of articles + struct ListNode *iter=dir_list->first; + int cnt = 1; + while (iter != NULL) { - //print list of articles - struct ListNode *iter=dir_list->first; - int cnt = 1; - while (iter != NULL) - { - printf( "%d%s\n", cnt, (char *)iter->val); - cnt += 1; - iter = iter->next; - } + term_cur_set_c( ts, 0 ); + printf( "[%02d] %s\n", cnt, (char *)iter->val); + cnt += 1; + iter = iter->next; } - break; - case 'r': - case 'R': + term_getc( ts ); + } + break; + case 'r': + case 'R': + { + //while there is no more 10 articles use only 1 number + //TODO fix that + term_cur_set_c( ts, 0 ); + printf("Input article number 0-9:"); fflush( stdout ); + 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'; + + if ( article_number > 0 && article_number < 10) { - //while there is no more 10 articles use only 1 number - //TODO fix that - int article_number = in_buf[1]-'0'; - if ( article_number > 0 && article_number < 10) + struct ListNode *iter = dir_list->first; + int cnt = 1; + while ( iter != NULL ) { - struct ListNode *iter = dir_list->first; - int cnt = 1; - while ( iter != NULL ) + if ( cnt == article_number ) { - if ( cnt == article_number ) - { - bbs_article( ts, iter->val ); - break; - } - cnt += 1; - iter = iter->next; + bbs_article( ts, iter->val ); + break; } + cnt += 1; + iter = iter->next; } } - break; - default: - printf("Try more\n"); - } + } + break; + default: + printf("Try more\n"); } } @@ -1,6 +1,14 @@ #ifndef __MICROBBS_ARTICLES_H #define __MICROBBS_ARTICLES_H +#define _XOPEN_SOURCE 500 + +#ifndef _BSD_SOURCE + #define _BSD_SOURCE +#endif + +#define _POSIX_C_SOURCE 200809L + #include <stdio.h> #include <stdlib.h> #include <stdint.h> @@ -14,6 +22,7 @@ //part of libterm #include "libterm/term.h" +#include "libterm/term_io.h" #include "logs.h" @@ -11,8 +11,8 @@ int captcha_test1( term_screen *ts) int ret = 0; const int s_size = 2; char s[s_size]; - int column, row; - int c; + int column=0, row=0; + int c=0; //setup terminal output position term_clr_scr( ts ); @@ -4,6 +4,7 @@ #include <stdlib.h> #include <stdio.h> #include <syslog.h> +#include <unistd.h> #define BBS_DEFAULT_SYSLOG "microbbs" @@ -4,6 +4,8 @@ #include "kconfig.h" #include "logs.h" #include "motd.h" +#include "sysinfo.h" +#include "articles.h" #include "libterm/term.h" #include "libterm/term_io.h" @@ -11,14 +13,12 @@ int main( int argc, char **argv ) { - int ret_len; int quit_main_menu = 0; - int column, row; int main_menu_input=0; char main_menu_cmd; - term_screen ts; + term_screen ts; memset( (void *)&ts, 0, sizeof(ts) ); term_init( &ts ); term_set_raw_mode( &ts ); term_clr_scr( &ts ); @@ -206,4 +206,5 @@ exit_restore_terminal: term_clr_scr( &ts ); term_set_orig_mode( &ts ); return 0; +goto exit_restore_terminal; // if some flags used points that label not used } @@ -4,6 +4,7 @@ #include "buildinfo.h" #include "libterm/term.h" +#include "libterm/term_io.h" int bbs_sysinfo( term_screen* ); @@ -37,6 +37,7 @@ int bbs_todo( term_screen *ts, const char *fname) llist_push( todo_list, l ); goto cycle0; exit_cycle0:; + if ( l != NULL ) free( l ); } } |