summaryrefslogtreecommitdiff
path: root/motd.c
diff options
context:
space:
mode:
Diffstat (limited to 'motd.c')
-rw-r--r--motd.c110
1 files changed, 31 insertions, 79 deletions
diff --git a/motd.c b/motd.c
index 8d11b3f..359834b 100644
--- a/motd.c
+++ b/motd.c
@@ -4,103 +4,55 @@
//TODO merge 2 functions in one proper
//TODO complcations with libterm
-int bbs_login_motd( term_screen *ts, const char *fname )
+int bbs_motd_draw( 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;
+ int posc=0, posr=0;
+ int ret=0;
+ const int buf_size=80*25+1;
char buf[buf_size];
int x=0,y=0;
+ int row=0,column=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;
-}
-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 )
+ term_clr_scr( ts );
+ row = term_get_maxrow( ts );
+ column = term_get_maxcol( ts );
+ term_cur_set_r( ts, ++posr );
+ term_cur_set_c( ts, 0 );
+
+ memset( buf, 0, buf_size );
+ ret = fread( buf, 1, buf_size, f );
+ if (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;
+ int i=0;
+ while ( i < ret )
+ {
+ if ( buf[i] != '\n' )
+ {
+ printf("%c",buf[i] );
+ }
+ else if ( buf[i] == '\n')
+ {
+ posr += 1;
+ fflush( stdout );
+ term_cur_set_r( ts, posr );
+ term_cur_set_c( ts, 0 );
+ }
+ i++;
+ }
}
+
}
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;
}