diff options
| author | FreeArtMan <dos21h@gmail.com> | 2015-06-09 17:51:57 +0300 | 
|---|---|---|
| committer | FreeArtMan <dos21h@gmail.com> | 2015-06-09 17:51:57 +0300 | 
| commit | 712439932ce9ac04fa6354cd4603046232121974 (patch) | |
| tree | 26b9db563fd09d353add5ea4abdddd0d3b1edacb | |
| parent | 5e5e5b1cbcb98eda7e0c52a367c66b944b480eda (diff) | |
| download | microbbs-712439932ce9ac04fa6354cd4603046232121974.tar.gz microbbs-712439932ce9ac04fa6354cd4603046232121974.zip | |
Added twitting messages
| -rw-r--r-- | Kconfig | 5 | ||||
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | buildinfo.h | 2 | ||||
| -rw-r--r-- | file_use.c | 4 | ||||
| -rw-r--r-- | kconfig.h | 9 | ||||
| -rw-r--r-- | list.c | 18 | ||||
| -rw-r--r-- | list.h | 1 | ||||
| -rw-r--r-- | microbbs.c | 5 | ||||
| -rw-r--r-- | todo.c | 37 | ||||
| -rw-r--r-- | todo.h | 1 | ||||
| -rw-r--r-- | twit.c | 168 | ||||
| -rw-r--r-- | twit.h | 20 | 
12 files changed, 262 insertions, 12 deletions
| @@ -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 @@ -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(); @@ -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;  } @@ -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 @@ -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 )  { @@ -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* ); @@ -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 @@ -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 ); @@ -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 @@ -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 @@ -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 | 
