#include "articles.h" int bbs_article( term_screen *ts, const char *fname ) { int ret=-1; int i=0; FILE *f; size_t str_size=0, fret=1; char *str=NULL; size_t in_size=0; char *in_buf=NULL; int max_x, max_y, ret_len; int quit_loop=0; if ( ts->mode == SCREEN_MODE_80x24 ) { max_x = 80; max_y = 24; } else { printf("Unknown mode\n"); max_x = 80; max_y = 24; } bbs_log_article( NULL ); if ( fname != NULL ) { f = fopen( fname, "r" ); if ( f == NULL ) { printf("Cannot open article file\n"); return -1; } fret = 1; i = 0; while ( (fret > 0) && (quit_loop == 0) ) { fret = getline( &str, &str_size, f ); if ( fret > 0 ) { printf("%s", str); i += 1; } //if ( ((i > 0) && (fret == -1)) || // ((fret > 0) && (i > max_x-1)) ) if ( i >= max_y-1 ) { printf("(N)ext,(D)ump,(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 'n': case 'N': i = 0; break; //dump whole file to the screen case 'd': case 'D': { char tmp_buf[81]; size_t tmp_size; fseek( f, 0, SEEK_SET ); while ( (tmp_size = fread( &tmp_buf, 1, 80, f )) > 0 ) { tmp_buf[ tmp_size ] = 0; printf( "%s", tmp_buf ); } } i = 0; break; default: printf("Try more\n"); } } } if ( (fret == -1) ) break; } fclose( f ); ret = 0; } return ret; } int bbs_article_list( term_screen *ts, const char *dir_name ) { int ret=-1; int max_x=-1, max_y=-1; if ( ts->mode == SCREEN_MODE_80x24 ) { max_x = 80; max_y = 24; } else { printf("Unknown mode\n"); max_x = 80; max_y = 24; } bbs_log_article_list( NULL ); if ( dir_name != NULL ) { //should have some bugs be carefull ret = 0; } return ret; }