summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Kconfig5
-rw-r--r--Makefile4
-rw-r--r--buildinfo.h2
-rw-r--r--file_use.c4
-rw-r--r--kconfig.h9
-rw-r--r--list.c18
-rw-r--r--list.h1
-rw-r--r--microbbs.c5
-rw-r--r--todo.c37
-rw-r--r--todo.h1
-rw-r--r--twit.c168
-rw-r--r--twit.h20
12 files changed, 262 insertions, 12 deletions
diff --git a/Kconfig b/Kconfig
index 7ab7a51..157b524 100644
--- a/Kconfig
+++ b/Kconfig
@@ -15,6 +15,9 @@ menuconfig TWIT
default n
if TWIT
+ config TWIT_DEFAULT_FILE
+ string "Default file location"
+ default "twit/twit.txt"
endif
menuconfig DOORGAMES
@@ -44,7 +47,7 @@ menuconfig LOGIN
if LOGIN
config USER_DEFAULT_DIR
string "Defaul user data directory"
- default "./users/"
+ default "./users"
endif
menuconfig ARTICLES
diff --git a/Makefile b/Makefile
index 9bf3049..8c809b3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
PROJECT=microbbs
CC=gcc
-CFLAGS=-g3
-SOURCES=articles.c bbsconfig.c buildinfo.c captcha.c door.c file_use.c ini.c list.c logs.c mmm.c motd.c sds.c session.c statistics.c sysinfo.c telnetd.c textview.c todo.c user.c vote.c
+CFLAGS=
+SOURCES=articles.c bbsconfig.c buildinfo.c captcha.c door.c file_use.c ini.c list.c logs.c mmm.c motd.c sds.c session.c statistics.c sysinfo.c telnetd.c textview.c todo.c twit.c user.c vote.c
OBJECTS=$(SOURCES:.c=.o)
BUILD_DIR=build_dir
diff --git a/buildinfo.h b/buildinfo.h
index 296879e..9554d85 100644
--- a/buildinfo.h
+++ b/buildinfo.h
@@ -4,7 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
-#define BUILD_VERSION "0.2.3"
+#define BUILD_VERSION "0.2.4"
#define BUILD_DATE (__DATE__)
void print_build_info();
diff --git a/file_use.c b/file_use.c
index 8b72e25..b21ebdd 100644
--- a/file_use.c
+++ b/file_use.c
@@ -155,10 +155,10 @@ size_t f_file_write( f_file *f_f, size_t size, void *ptr )
if ((f_f->flags == F_FILE_WRITE) ||
(f_f->flags == F_FILE_RW) )
{
- ERROR("Not yet ready\n");
+ ret = fwrite( ptr, 1, size, f_f->fid );
}
}
-
+ return ret;
}
diff --git a/kconfig.h b/kconfig.h
index ec26978..edfc794 100644
--- a/kconfig.h
+++ b/kconfig.h
@@ -1,5 +1,12 @@
#ifndef __KCONFIG_H
#define __KCONFIG_H
+#define CONFIG_TODO
+#define CONFIG_TODO_DEFAULT_FILE "todo/todo.txt"
+#define CONFIG_TWIT
+#define CONFIG_TWIT_DEFAULT_FILE "twit/twit.txt"
+#define CONFIG_DOORGAMES
+#define CONFIG_DOOR_DEFAULT_DIR "door"
#define CONFIG_LOGIN
-#define CONFIG_USER_DEFAULT_DIR "./users/"
+#define CONFIG_USER_DEFAULT_DIR "./users"
+#define CONFIG_ARTICLES
#endif
diff --git a/list.c b/list.c
index 7e7f732..a6e5e83 100644
--- a/list.c
+++ b/list.c
@@ -90,6 +90,24 @@ void* llist_pop( struct List *list )
return NULL;
}
+void* llist_popf( struct List *list )
+{
+ void *ptr = NULL;
+ struct ListNode *node = list->first;
+ struct ListNode *next;
+ if ( node )
+ {
+ next = node->next;
+
+ list->count -= 1;
+ list->first = next;
+ if ( list->first == NULL )
+ list->last = NULL;
+ ptr = node->val;
+ free( node );
+ }
+ return ptr;
+}
void llist_push( struct List *list, void *ptr )
{
diff --git a/list.h b/list.h
index 94794f0..fd17b1b 100644
--- a/list.h
+++ b/list.h
@@ -93,6 +93,7 @@ void llist_appendn( struct List**, void*, struct ListNode* );
// get one element from list and erease it from list
void* llist_pop( struct List* );
+void* llist_popf( struct List* );//pop first element of list
//add at the end one element
void llist_push( struct List*, void* );
diff --git a/microbbs.c b/microbbs.c
index 92aa1ed..70dc388 100644
--- a/microbbs.c
+++ b/microbbs.c
@@ -11,6 +11,8 @@
#include "articles.h"
#include "user.h"
#include "bbsconfig.h"
+#include "twit.h"
+#include "todo.h"
#include "libterm/term.h"
#include "libterm/term_io.h"
@@ -149,7 +151,8 @@ int main( int argc, char **argv )
case 't':
case 'T':
{
- printf("Twitter like\n");
+ //printf("Twitter like\n");
+ bbs_twit( &ts, NULL );
}
break;
#endif
diff --git a/todo.c b/todo.c
index aa074b2..e68ef29 100644
--- a/todo.c
+++ b/todo.c
@@ -147,8 +147,9 @@ int bbs_todo_add( term_screen *ts, List *todo, const char *fname)
fret = term_readline( ts, buf, buf_size, READLINE_ALPHA );
if ( fret > 0 )
{
- char *l = malloc( fret );
+ char *l = malloc( fret+1 );
memcpy( l, buf, fret );
+ l[fret]='\0';
llist_push( todo, l );
bbs_todo_save( fname, todo );
ret = 0;
@@ -160,6 +161,28 @@ int bbs_todo_add( term_screen *ts, List *todo, const char *fname)
return ret;
}
+int bbs_todo_remove( term_screen *ts, List *todo, const char *fname )
+{
+ int ret=-1;
+
+ if ( ts == NULL )
+ return ret;
+
+ if ( todo == NULL )
+ return ret;
+
+ if ( fname == NULL )
+ return ret;
+
+ term_clr_scr( ts );
+ term_cur_set_c( ts, 0 );
+ term_cur_set_r( ts, 0 );
+ printf("Remove entry from todo:\n"); fflush( stdout );
+
+
+ return ret;
+}
+
int bbs_todo_save( const char *fname, List *todo )
{
int ret=-1;
@@ -168,10 +191,16 @@ int bbs_todo_save( const char *fname, List *todo )
struct ListNode *iter=todo->first;
f = f_file_open( fname, F_FILE_WRITE );
- while ( iter->next != NULL )
+ while ( iter != NULL )
{
- f_file_write( f, strlen(iter->val), iter->val );
- printf("%s\n", iter->val );
+ size_t str_size=strlen( iter->val )+2;
+ char *str = malloc( str_size );
+ memcpy( str, iter->val, str_size-2);
+ str[str_size-1] = '\0';
+ str[str_size-2] = '\n';
+ f_file_write( f, strlen(str), str );
+ printf( "%s\n", str ); fflush( stdout );
+ free( str );
iter = iter->next;
}
f_file_close( f );
diff --git a/todo.h b/todo.h
index 724a2c8..3550f08 100644
--- a/todo.h
+++ b/todo.h
@@ -12,6 +12,7 @@
int bbs_todo( term_screen *, const char *);
int bbs_todo_add( term_screen*, List*, const char*);
+int bbs_todo_remove( term_screen*, List*, const char* );
int bbs_todo_save( const char*, List* );
#endif \ No newline at end of file
diff --git a/twit.c b/twit.c
new file mode 100644
index 0000000..74b61e1
--- /dev/null
+++ b/twit.c
@@ -0,0 +1,168 @@
+#include "twit.h"
+
+#ifdef CONFIG_TWIT
+
+int bbs_twit( term_screen *ts, char *fn )
+{
+ int ret = 0;
+ char *fname = CONFIG_TWIT_DEFAULT_FILE;
+ int menu_input = 0;
+ char menu_cmd;
+ int row;
+ int quit_loop = 0;
+
+ if ( fn != NULL )
+ fname = fn;
+
+ List *twit_list = llist_new();
+ f_file *file = f_file_open( 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( twit_list, l );
+ goto cycle0;
+ exit_cycle0:;
+ if ( l != NULL ) free( l );
+ }
+
+ }
+ f_file_close( file );
+
+ //log that someone use twit
+ bbs_log( NULL, "visited TWIT" );
+
+ while( (quit_loop == 0) )
+ {
+ term_clr_scr( ts );
+ term_cur_set_c( ts, 0 );
+ printf("(A)dd,(Q)uit"); fflush( stdout );
+
+ //dispaly todo list
+ row = term_get_maxrow( ts );
+ term_cur_set_c( ts, 0 );
+ {
+ struct ListNode *iter=twit_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 'a':
+ case 'A':
+ bbs_twit_add( ts, twit_list, fname );
+ break;
+
+ default:
+ printf("Try more\n");
+ }
+ }
+
+ llist_free( twit_list );
+
+ return ret;
+}
+
+int bbs_twit_add( term_screen *ts, List *twit, 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("Put new twit:\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+1 );
+ memcpy( l, buf, fret );
+ l[fret]='\0';
+ llist_push( twit, l );
+ bbs_twit_save( fname, twit );
+ ret = 0;
+ } else
+ {
+ return -1;
+ }
+
+ if ( ret == 0 )
+ if ( llist_length(twit) > TWIT_MAX_MESSAGES )
+ {
+ char *ptr = llist_popf( twit );
+ if ( ptr != NULL )
+ free( ptr );
+ }
+
+ return ret;
+}
+
+int bbs_twit_save( const char *fname, List *twit )
+{
+ int ret=-1;
+
+ f_file *f=NULL;
+ struct ListNode *iter=twit->first;
+
+ f = f_file_open( fname, F_FILE_WRITE );
+
+ while ( iter != NULL )
+ {
+ size_t str_size=strlen( iter->val )+2;
+ char *str = malloc( str_size );
+ memcpy( str, iter->val, str_size-2);
+ str[str_size-1] = '\0';
+ str[str_size-2] = '\n';
+ f_file_write( f, strlen(str), str );
+ printf( "%s\n", str ); fflush( stdout );
+ free( str );
+ iter = iter->next;
+ }
+ f_file_close( f );
+
+ return ret;
+}
+
+
+#endif
diff --git a/twit.h b/twit.h
new file mode 100644
index 0000000..34aef0b
--- /dev/null
+++ b/twit.h
@@ -0,0 +1,20 @@
+#ifndef __MICROBBS_TWIT_H
+#define __MICROBBS_TWIT_H
+
+#include "libterm/term.h"
+#include "libterm/term_io.h"
+#include "logs.h"
+#include "file_use.h"
+#include "list.h"
+
+#include "kconfig.h"
+
+//maybe move to Kconf
+#define TWIT_MAX_MESSAGES 10
+
+int bbs_twit( term_screen *, char *);
+int bbs_twit_add( term_screen *ts, List *twit, const char *fname);
+int bbs_twit_save( const char *fname, List *twit );
+
+
+#endif \ No newline at end of file