summaryrefslogtreecommitdiff
path: root/articles.c
blob: b5c5ea366e3b4c2a5d5886acba221269c36e1518 (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
#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
	{
		max_x = 80;
		max_y = 24;
	}

	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,(Q)uit:");
				ret_len = getline( &in_buf, &in_size, stdin );
				if ( ret_len > 0 )
				{
					char ch = in_buf[0];
					switch( ch )
					{
						case 'q':
							quit_loop = 1;
							break;
						case 'n':
							i = 0;
							break;
						default:
							printf("Try more\n");
					}
				}
			}

			if ( (fret == -1) )
				break;

		}
		
		fclose( f );
		ret = 0;
	}

	return ret;
}