summaryrefslogtreecommitdiff
path: root/motd.c
blob: a8f7ada082251ad5b8d0552dabf94711283ce423 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "motd.h"

#ifdef CONFIG_MOTD

//TODO merge 2 functions in one proper
//TODO complcations with libterm
int bbs_motd_draw( term_screen *ts, const char *fname )
{
	int posr=0;
	int ret=0;
	const int buf_size=80*26+1;
	char buf[buf_size];
	//int row=0,column=0;


	FILE *f = fopen( fname, "r" );
	if ( f == NULL ) 
	{
		term_printf( ts, "Cannot open file %s\n", fname);
		return -1;
	}

	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)
	{
		{
			int i=0;
			while ( i < ret )
			{
				if ( buf[i] != '\n' )
				{
					term_printf( ts, "%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++;
			}
			fflush( stdout );
		}
		
	}
	fclose( f );

	return 0;
}

#endif