summaryrefslogtreecommitdiff
path: root/motd.c
blob: 359834b239a9362d73e11c1f9544eb332dc210dd (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 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;


	FILE *f = fopen( fname, "r" );
	if ( f == NULL ) 
	{
		printf("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' )
				{
					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 );

	return 0;
}

#endif