summaryrefslogtreecommitdiff
path: root/motd.c
blob: 8d11b3f5c76600136a022247805a9b0d00726118 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "motd.h"

#ifdef CONFIG_MOTD

//TODO merge 2 functions in one proper
//TODO complcations with libterm
int bbs_login_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 )
	{
		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 )
	{
		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;
}

#endif