summaryrefslogtreecommitdiffstats
path: root/articles.c
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2014-11-16 15:20:30 +0900
committerFreeArtMan <dos21h@gmail.com>2014-11-16 15:20:30 +0900
commitdc4bbe5366d6c733f9f77b7c9fee0cbba3e0d92b (patch)
tree59335ea751ae3e3cbedfd227e4c9c92237b1d6de /articles.c
parentc0adc26b6e1b9c07b144798fb3b5de27a2e36e0c (diff)
downloadmicrobbs-dc4bbe5366d6c733f9f77b7c9fee0cbba3e0d92b.tar.gz
microbbs-dc4bbe5366d6c733f9f77b7c9fee0cbba3e0d92b.zip
New version bumped. Article list and list read added. Quit motd added
Diffstat (limited to 'articles.c')
-rw-r--r--articles.c114
1 files changed, 112 insertions, 2 deletions
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;
}