summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--art/quit.txt26
-rw-r--r--articles.c114
-rw-r--r--articles.h11
-rw-r--r--microbbs.c7
-rw-r--r--mmm.c4
-rw-r--r--motd.c53
-rw-r--r--motd.h3
7 files changed, 210 insertions, 8 deletions
diff --git a/art/quit.txt b/art/quit.txt
new file mode 100644
index 0000000..9dfe9f4
--- /dev/null
+++ b/art/quit.txt
@@ -0,0 +1,26 @@
+ A_______
+ |______<
+ ||
+ ______||_______
+ \##############\
+ \##############\
+ | |
+ | |
+ |###############|
+ |###############|
+ | |
+ VK | |
+ |###############|
+ /###############/ @@
+ /\ /_______________/ ( C
+ (@\ ( ") /\\ /\\||/\\ /\\ /\\ / /'
+ \\_ (\_) ( "))( ")|( "))( "))( ")) / /
+ \```--/----/(o)-/(o)-/(o)-/(o)-/(o)--' /
+~~~~~~~~~/ ~~~/~~~~/~~~~/~~~~/~~~~/~~~~~~~~~~~~~~~~~
+ - - ' ( ' )( ' )( ' )( ' )( ' )
+ ___ ___ ___ _ _ __ _
+/ __|/ _ \/ _ \ | | | |/ _` |
+\__ \ __/ __/ | |_| | (_| |
+|___/\___|\___| \__, |\__,_|
+ __/ |
+ |___/ \ No newline at end of file
diff --git a/articles.c b/articles.c
index c071bf1..cf5f40d 100644
--- a/articles.c
+++ b/articles.c
@@ -1,6 +1,7 @@
#include "articles.h"
-
+//TODO add checkout on size of art it will fix,
+// warn about cutted images
int bbs_article( term_screen *ts, const char *fname )
{
int ret=-1;
@@ -99,10 +100,32 @@ int bbs_article( term_screen *ts, const char *fname )
return ret;
}
+
+//just for full fill libc example
+static int dir_article_selector (const struct dirent *unused)
+{
+ return 1;
+}
+
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;
+
+ //list dir
+ struct stat path_node;
+ struct dirent **eps;
+ int n;
+
+ //get all articles names in list and use list every time needed
+ List *dir_list = llist_new();
if ( ts->mode == SCREEN_MODE_80x24 )
{
@@ -120,9 +143,96 @@ int bbs_article_list( term_screen *ts, const char *dir_name )
if ( dir_name != NULL )
{
//should have some bugs be carefull
-
+ n = scandir( dir_name, &eps, dir_article_selector, alphasort );
+ if ( n >= 0)
+ {
+ int cnt;
+ for ( cnt=0; cnt<n; cnt++)
+ {
+ size_t tmp_size = strlen( eps[cnt]->d_name );
+ char *cnct_path = malloc( tmp_size + strlen(dir_name)+1);
+ memcpy( cnct_path, dir_name, strlen(dir_name));
+ memcpy( cnct_path+sizeof(dir_name)+2, eps[cnt]->d_name,
+ tmp_size+1 );
+
+ //check if its file
+ if ( stat( cnct_path, &path_node ) == 0 )
+ {
+ if ( path_node.st_mode & S_IFREG )
+ {
+ llist_push( dir_list, cnct_path );
+ printf("-->%s\n", cnct_path);
+ }
+ }
+ }
+ } else
+ {
+ printf("Err\n");
+ ERROR("Cannot open article directory\n");
+ }
ret = 0;
}
+
+ i = 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 )
+ {
+ char ch = in_buf[0];
+ switch( ch )
+ {
+ case 'q':
+ case 'Q':
+ quit_loop = 1;
+ break;
+ case 'l':
+ case 'L':
+ {
+ //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;
+ }
+ }
+ break;
+ case 'r':
+ case 'R':
+ {
+ //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 )
+ {
+ if ( cnt == article_number )
+ {
+ bbs_article( ts, iter->val );
+ break;
+ }
+ cnt += 1;
+ iter = iter->next;
+ }
+ }
+ }
+ break;
+ default:
+ printf("Try more\n");
+ }
+ }
+ }
+
+ llist_free( dir_list );
+
+
return ret;
}
diff --git a/articles.h b/articles.h
index 0282386..5f773a3 100644
--- a/articles.h
+++ b/articles.h
@@ -3,10 +3,21 @@
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
+#include <dirent.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+//part of libterm
#include "libterm/term.h"
#include "logs.h"
+
+//part of libadt
+#include "list.h"
+
#define WORKING_DIR "article"
int bbs_article( term_screen*, const char* );
diff --git a/microbbs.c b/microbbs.c
index 77ac92b..6a6c098 100644
--- a/microbbs.c
+++ b/microbbs.c
@@ -18,7 +18,7 @@ int main( int argc, char **argv )
//write to log that some user have accesed bbs
//bbs_log( NULL ); //write to default place
- bbs_motd( &ts, "art/motd.txt" );
+ bbs_login_motd( &ts, "art/motd.txt" );
print_build_info();
while ( strncmp( str, "q", 1 ) && strncmp( str, "Q", 1 ) )
{
@@ -31,7 +31,7 @@ int main( int argc, char **argv )
case 'm':
case 'M':
{
- bbs_motd( &ts, "art/motd.txt" );
+ bbs_login_motd( &ts, "art/motd.txt" );
}
break;
case 's':
@@ -43,7 +43,7 @@ int main( int argc, char **argv )
case 'a':
case 'A':
{
- bbs_article( &ts, "article/post1.txt" );
+ bbs_article_list( &ts, "./article/" );
}
break;
case 'q':
@@ -55,5 +55,6 @@ int main( int argc, char **argv )
}
}
}
+ bbs_quit_motd( &ts, "art/quit.txt" );
return 0;
}
diff --git a/mmm.c b/mmm.c
index 4dc9a04..6b271e8 100644
--- a/mmm.c
+++ b/mmm.c
@@ -3,9 +3,11 @@
#ifdef MMM_PLAIN
#endif
-#ifdef MMM_RECORD
+/*Special choice option*/
+#ifdef MMM_RECORD
+
void* mmm_malloc(size_t size, const char *fname, int line )
{
void *ret=NULL;
diff --git a/motd.c b/motd.c
index 21d6246..ce68f77 100644
--- a/motd.c
+++ b/motd.c
@@ -1,6 +1,8 @@
#include "motd.h"
-int bbs_motd( term_screen *ts, const char *fname )
+//TODO merge 2 functions in one proper
+//TODO complcations with libterm
+int bbs_login_motd( term_screen *ts, const char *fname )
{
int posx=0, posy=0;
int i;
@@ -50,3 +52,52 @@ int bbs_motd( term_screen *ts, const char *fname )
return 0;
}
+int bbs_quit_motd( term_screen *ts, const char *fname )
+{
+ int posx=0, posy=0;
+ int i;
+ FILE *f = fopen( fname, "r" );
+ if ( f == NULL )
+ {
+ printf("Cannot open file %s\n", fname);
+ return -1;
+ }
+
+ int ret;
+ const int buf_size=160;
+ char buf[buf_size];
+ int x=0,y=0;
+
+ if ( ts->term_row > 24 )
+ {
+ posy = (ts->term_row-24)/2;
+ }
+ for (i=0;i<posy;i++)
+ printf("\n");
+ ret = 1;
+ while ( ret > 0 )
+ {
+ memset( buf, 0, buf_size );
+ ret = fread( buf, 1, buf_size, f );
+ if (ret > 0)
+ {
+ //printf("%d %d",x,y);
+ x = term_print( ts, buf, ret, x, y );
+ y = (x&0xffff0000)>>16;
+ x = x&0x0000ffff;
+ }
+ }
+ fclose( f );
+
+ //printf("->posy=%d y=%d x=%d\n",posy,y,x);
+ //printf("-->%d\n",ts->term_row-posy-(24-y));
+ for (i=0;i<(ts->term_row-posy-y);i++)
+ printf("\n");
+ //for (i=0;i < ts->term_row-(ts->term_row-posy-24+y);i++)
+ // printf("\n");
+ //printf("%d\n",i);
+
+ //printf("%d %d %d\n",y,posy,ts->term_row);
+
+ return 0;
+} \ No newline at end of file
diff --git a/motd.h b/motd.h
index f4344a6..e64d06c 100644
--- a/motd.h
+++ b/motd.h
@@ -12,7 +12,8 @@
//get file name
//calculate current termsize and then print motd in da middle
-int bbs_motd( term_screen*, const char* );
+int bbs_login_motd( term_screen*, const char* );
+int bbs_quit_motd( term_screen*, const char* );
#endif