prntfile.cpp 6.17 KB
Newer Older
1
/* prntfile.cpp */
2
// vi: tabstop=4
3
4
5
6
7
8
9
10
11

/* Synchronet file print/display routines */

/* $Id$ */

/****************************************************************************
 * @format.tab-size 4		(Plain Text/Source Code File Header)			*
 * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
 *																			*
12
 * Copyright Rob Swindell - http://www.synchro.net/copyright.html			*
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
 *																			*
 * This program is free software; you can redistribute it and/or			*
 * modify it under the terms of the GNU General Public License				*
 * as published by the Free Software Foundation; either version 2			*
 * of the License, or (at your option) any later version.					*
 * See the GNU General Public License for more details: gpl.txt or			*
 * http://www.fsf.org/copyleft/gpl.html										*
 *																			*
 * Anonymous FTP access to the most recent released source is available at	*
 * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
 *																			*
 * Anonymous CVS access to the development source and modification history	*
 * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
 *     (just hit return, no password is necessary)							*
 * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
 *																			*
 * For Synchronet coding style and modification guidelines, see				*
 * http://www.synchro.net/source.html										*
 *																			*
 * You are encouraged to submit any modifications (preferably in Unix diff	*
 * format) via e-mail to mods@synchro.net									*
 *																			*
 * Note: If this box doesn't appear square, then you need to fix your tabs.	*
 ****************************************************************************/

#include "sbbs.h"

/****************************************************************************/
/* Prints a file remotely and locally, interpreting ^A sequences, checks    */
/* for pauses, aborts and ANSI. 'str' is the path of the file to print      */
/* Called from functions menu and text_sec                                  */
/****************************************************************************/
void sbbs_t::printfile(char *str, long mode)
{
48
49
	char* buf;
	char* p;
rswindell's avatar
rswindell committed
50
51
	int file;
	BOOL wip=FALSE,rip=FALSE,html=FALSE;
rswindell's avatar
rswindell committed
52
	long l,length,savcon=console;
53
54
	FILE *stream;

55
56
	p=strrchr(str,'.');
	if(p!=NULL) {
rswindell's avatar
rswindell committed
57
		if(stricmp(p,".wip")==0) {
rswindell's avatar
rswindell committed
58
			wip=TRUE;
rswindell's avatar
rswindell committed
59
60
61
			mode|=P_NOPAUSE;
		}
		else if(stricmp(p,".rip")==0) {
rswindell's avatar
rswindell committed
62
			rip=TRUE;
rswindell's avatar
rswindell committed
63
64
65
			mode|=P_NOPAUSE;
		}
		else if(stricmp(p,".html")==0)  {
rswindell's avatar
rswindell committed
66
			html=TRUE;
rswindell's avatar
rswindell committed
67
68
			mode|=(P_HTML|P_NOPAUSE);
		}
69
	}
70

rswindell's avatar
rswindell committed
71
	if(mode&P_NOABORT || wip || rip || html) {
72
73
		if(online==ON_REMOTE && console&CON_R_ECHO) {
			rioctl(IOCM|ABORT);
rswindell's avatar
rswindell committed
74
75
76
77
			rioctl(IOCS|ABORT); 
		}
		sys_status&=~SS_ABORT; 
	}
78

79
	if(!(mode&P_NOCRLF) && !tos && !wip && !rip && !html) {
80
		CRLF;
81
	}
82

83
	fexistcase(str);
84
	if((stream=fnopen(&file,str,O_RDONLY|O_DENYNONE))==NULL) {
85
86
		lprintf(LOG_NOTICE,"Node %d !Error %d (%s) opening: %s"
			,cfg.node_num,errno,strerror(errno),str);
87
88
89
		bputs(text[FileNotFound]);
		if(SYSOP) bputs(str);
		CRLF;
rswindell's avatar
rswindell committed
90
91
		return; 
	}
92

93
	length=(long)filelength(file);
94
	if(length<0) {
rswindell's avatar
rswindell committed
95
		fclose(stream);
96
97
		errormsg(WHERE,ERR_CHK,str,length);
		return;
rswindell's avatar
rswindell committed
98
	}
deuce's avatar
deuce committed
99
	if((buf=(char*)malloc(length+1L))==NULL) {
rswindell's avatar
rswindell committed
100
		fclose(stream);
101
102
103
104
105
106
107
		errormsg(WHERE,ERR_ALLOC,str,length+1L);
		return; 
	}
	l=lread(file,buf,length);
	fclose(stream);
	if(l!=length)
		errormsg(WHERE,ERR_READ,str,length);
108
	else {
109
110
		buf[l]=0;
		putmsg(buf,mode);
rswindell's avatar
rswindell committed
111
	}
deuce's avatar
deuce committed
112
	free(buf); 
113

rswindell's avatar
rswindell committed
114
	if((mode&P_NOABORT || wip || rip || html) && online==ON_REMOTE) {
115
		SYNC;
rswindell's avatar
rswindell committed
116
117
		rioctl(IOSM|ABORT); 
	}
118
119
120
	if(rip)
		ansi_getlines();
	console=savcon;
rswindell's avatar
rswindell committed
121
}
122
123
124

void sbbs_t::printtail(char *str, int lines, long mode)
{
rswindell's avatar
rswindell committed
125
126
127
128
	char*	buf;
	char*	p;
	int		file,cur=0;
	long	length,l;
129
130
131
132

	if(mode&P_NOABORT) {
		if(online==ON_REMOTE) {
			rioctl(IOCM|ABORT);
rswindell's avatar
rswindell committed
133
134
135
136
			rioctl(IOCS|ABORT); 
		}
		sys_status&=~SS_ABORT; 
	}
137
	if(!tos) {
rswindell's avatar
rswindell committed
138
139
		CRLF; 
	}
140
	fexistcase(str);
141
	if((file=nopen(str,O_RDONLY|O_DENYNONE))==-1) {
142
143
		lprintf(LOG_NOTICE,"Node %d !Error %d (%s) opening: %s"
			,cfg.node_num,errno,strerror(errno),str);
144
145
146
		bputs(text[FileNotFound]);
		if(SYSOP) bputs(str);
		CRLF;
rswindell's avatar
rswindell committed
147
148
		return; 
	}
149
	length=(long)filelength(file);
rswindell's avatar
rswindell committed
150
151
152
153
154
	if(length<0) {
		close(file);
		errormsg(WHERE,ERR_CHK,str,length);
		return;
	}
deuce's avatar
deuce committed
155
	if((buf=(char*)malloc(length+1L))==NULL) {
156
157
		close(file);
		errormsg(WHERE,ERR_ALLOC,str,length+1L);
rswindell's avatar
rswindell committed
158
159
		return; 
	}
160
161
	l=lread(file,buf,length);
	close(file);
rswindell's avatar
rswindell committed
162
163
164
165
166
167
168
169
170
171
172
173
174
175
	if(l!=length)
		errormsg(WHERE,ERR_READ,str,length);
	else {
		buf[l]=0;
		p=(buf+l)-1;
		if(*p==LF) p--;
		while(*p && p>buf) {
			if(*p==LF)
				cur++;
			if(cur>=lines) {
				p++;
				break; 
			}
			p--; 
rswindell's avatar
rswindell committed
176
		}
rswindell's avatar
rswindell committed
177
		putmsg(p,mode);
rswindell's avatar
rswindell committed
178
	}
179
180
	if(mode&P_NOABORT && online==ON_REMOTE) {
		SYNC;
rswindell's avatar
rswindell committed
181
182
		rioctl(IOSM|ABORT); 
	}
deuce's avatar
deuce committed
183
	free(buf);
184
185
186
187
188
189
190
191
}

/****************************************************************************/
/* Prints the menu number 'menunum' from the text directory. Checks for ^A  */
/* ,ANSI sequences, pauses and aborts. Usually accessed by user inputing '?'*/
/* Called from every function that has an available menu.                   */
/* The code definitions are as follows:                                     */
/****************************************************************************/
192
void sbbs_t::menu(const char *code)
193
{
194
    char str[MAX_PATH-5],path[MAX_PATH+1];
195
196
197

	sys_status&=~SS_ABORT;
	if(menu_file[0])
198
		SAFECOPY(path,menu_file);
199
	else {
200
201
202
		if(isfullpath(code))
			SAFECOPY(str, code);
		else {
203
204
			backslash(menu_dir);
			SAFEPRINTF3(str, "%smenu/%s%s", cfg.text_dir, menu_dir, code);
rswindell's avatar
rswindell committed
205
		}
206
		sprintf(path,"%s.%s",str,term_supports(WIP) ? "wip": term_supports(RIP) ? "rip" : "html");
207
		if(!(term_supports()&(RIP|WIP|HTML)) || !fexistcase(path)) {
208
			SAFEPRINTF(path, "%s.mon", str);
209
			if((term_supports()&(COLOR|ANSI))!=ANSI || !fexistcase(path)) {
210
				SAFEPRINTF(path, "%s.ans", str);
211
				if(!term_supports(ANSI) || !fexistcase(path))
212
					SAFEPRINTF(path, "%s.asc", str); 
213
214
215
			} 
		} 
	}
216

217
218
219
220
	long mode = P_OPENCLOSE;
	if(column == 0)
		mode |= P_NOCRLF;
	printfile(path, mode);
221
222
}

223
224
225
226
227
228
bool sbbs_t::menu_exists(const char *code)
{
	char path[MAX_PATH+1];

	if(menu_file[0])
		return fexistcase(menu_file) ? true : false;
229

230
	backslash(menu_dir);
deuce's avatar
deuce committed
231
	SAFEPRINTF3(path, "%smenu/%s%s.asc", cfg.text_dir, menu_di