diff options
-rw-r--r-- | articles.h | 4 | ||||
-rw-r--r-- | bbsconfig.h | 3 | ||||
-rw-r--r-- | file_use.c | 6 | ||||
-rw-r--r-- | libterm/term.c | 11 | ||||
-rw-r--r-- | libterm/term.h | 3 | ||||
-rw-r--r-- | microbbs.c | 10 | ||||
-rw-r--r-- | todo.c | 62 | ||||
-rw-r--r-- | todo.h | 3 | ||||
-rw-r--r-- | user.c | 3 |
9 files changed, 76 insertions, 29 deletions
@@ -3,8 +3,8 @@ #define _XOPEN_SOURCE 500 -#ifndef _DEFAULT_SOURCE - #define _DEFAULT_SOURCE +#ifndef _BSD_SOURCE + #define _BSD_SOURCE #endif #define _POSIX_C_SOURCE 200809L diff --git a/bbsconfig.h b/bbsconfig.h index bcd2100..459aeae 100644 --- a/bbsconfig.h +++ b/bbsconfig.h @@ -37,6 +37,9 @@ typedef struct bbs_config //directory with all user inis char *user_dir; + //show motd messages? + int motd; + //write syslogs? int syslog; @@ -170,8 +170,8 @@ f_file* f_file_open( const char *fname, int flags ) { f_file *ret = NULL; - char *f_flags_write="r"; - char *f_flags_read="w"; + char *f_flags_write="w"; + char *f_flags_read="r"; char *f_flags_rw="r+"; char *f_flags_tmp=NULL; @@ -207,7 +207,7 @@ f_file* f_file_open( const char *fname, int flags ) ERROR("Unknown flag for opening \n"); goto exit_close_f; } - ret->fid = fopen( fname, "r" ); + ret->fid = fopen( fname, f_flags_tmp ); if ( ret->fid == NULL ) { ERROR("Cannot open file\n"); diff --git a/libterm/term.c b/libterm/term.c index 241b650..532dc92 100644 --- a/libterm/term.c +++ b/libterm/term.c @@ -250,26 +250,17 @@ exit_error: } -#include <assert.h> //clean terminal with escape command int term_clr_scr( term_screen *ts ) { int ret = 0; - char s[] = T_ESC "[H" T_ESC "[2J"; - - - ASSERT( strlen(s)>0 ); - ASSERT( ts != NULL ); - ASSERT( ts->ofd > 0 ); - - if ( write( ts->ofd, s, strlen(s) ) <= 0 ){}; + if ( write( ts->ofd, T_ESC "[H" T_ESC "[2J", 7 ) <= 0 ){}; return ret; } - //set terminal default input/output behavior int term_set_raw_mode( term_screen *ts ) { diff --git a/libterm/term.h b/libterm/term.h index 878cda4..51af31d 100644 --- a/libterm/term.h +++ b/libterm/term.h @@ -12,13 +12,10 @@ #include <sys/types.h> #include <sys/ioctl.h> #include <unistd.h> -#include <assert.h> #include "screen_modes.h" #include "debug.h" -#define ASSERT assert - enum TERM_KEY_ACTION { KEY_NULL = 0, /* NULL */ CTRL_A = 1, /* Ctrl+a */ @@ -25,14 +25,6 @@ int main( int argc, char **argv ) int main_menu_input=0; char main_menu_cmd; -#ifdef NDEBUG - printf("Assertions on\n"); -#endif - - //initialise default config options - config_default(); - config_from_argv( argc, argv ); - term_screen ts; memset( (void *)&ts, 0, sizeof(ts) ); term_init( &ts ); term_set_raw_mode( &ts ); @@ -46,7 +38,7 @@ int main( int argc, char **argv ) //lunch captcha and try to detect if its random bot #ifdef CONFIG_CAPTCHA - if ( captcha_test1( &ts ) != 1) + if ( captcha_test1( ts ) != 1) { goto exit_restore_terminal; } @@ -59,7 +59,7 @@ int bbs_todo( term_screen *ts, const char *fname) { term_clr_scr( ts ); term_cur_set_c( ts, 0 ); - printf("(Q)uit"); fflush( stdout ); + printf("(A)dd,(Q)uit"); fflush( stdout ); //dispaly todo list row = term_get_maxrow( ts ); @@ -95,6 +95,11 @@ int bbs_todo( term_screen *ts, const char *fname) quit_loop = 1; break; + case 'a': + case 'A': + bbs_todo_add( ts, todo_list, todo_fname ); + break; + case 's': case 'S': { @@ -119,4 +124,59 @@ int bbs_todo( term_screen *ts, const char *fname) return ret; } +int bbs_todo_add( term_screen *ts, List *todo, const char *fname) +{ + int ret = -1; + int fret = -1; + const int buf_size = 64; + char buf[buf_size]; + + if ( ts == NULL ) + return -1; + + if ( fname == NULL ) + return -1; + + term_clr_scr( ts ); + term_cur_set_c( ts, 0 ); + term_cur_set_r( ts, 0 ); + printf("Add new todo task:\n"); fflush( stdout ); + + memset( buf, 0, buf_size ); + term_cur_set_c( ts, 0 ); + fret = term_readline( ts, buf, buf_size, READLINE_ALPHA ); + if ( fret > 0 ) + { + char *l = malloc( fret ); + memcpy( l, buf, fret ); + llist_push( todo, l ); + bbs_todo_save( fname, todo ); + ret = 0; + } else + { + return -1; + } + + return ret; +} + +int bbs_todo_save( const char *fname, List *todo ) +{ + int ret=-1; + + f_file *f=NULL; + struct ListNode *iter=todo->first; + + f = f_file_open( fname, F_FILE_WRITE ); + while ( iter->next != NULL ) + { + f_file_write( f, strlen(iter->val), iter->val ); + printf("%s\n", iter->val ); + iter = iter->next; + } + f_file_close( f ); + + return ret; +} + #endif
\ No newline at end of file @@ -3,6 +3,7 @@ //part of libterm #include "libterm/term.h" +#include "libterm/term_io.h" #include "logs.h" #include "file_use.h" #include "list.h" @@ -10,5 +11,7 @@ #include "kconfig.h" int bbs_todo( term_screen *, const char *); +int bbs_todo_add( term_screen*, List*, const char*); +int bbs_todo_save( const char*, List* ); #endif
\ No newline at end of file @@ -109,7 +109,8 @@ static int user_cfg_handler( void *user, const char *section, const char *name, const char *value ) { user_config_file *cfg = (user_config_file *)user; -#define MATCH(s,n) strcmp(section,s) == 0 && strcmp(name,n)==0 + + #define MATCH(s,n) strcmp(section,s) == 0 && strcmp(name,n)==0 if ( MATCH("user","password") ) { |