prntfile.cpp 5.76 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/* prntfile.cpp */

/* 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)		*
 *																			*
rswindell's avatar
rswindell committed
11
 * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html		*
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
 *																			*
 * 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)
{
47
48
	char* buf;
	char* p;
rswindell's avatar
rswindell committed
49
50
	int file;
	BOOL wip=FALSE,rip=FALSE,html=FALSE;
rswindell's avatar
rswindell committed
51
	long l,length,savcon=console;
52
53
	FILE *stream;

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

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

rswindell's avatar
rswindell committed
78
	if(!tos && !wip && !rip && !html)
79
80
81
		CRLF;

	if((stream=fnopen(&file,str,O_RDONLY))==NULL) {
82
		lprintf(LOG_NOTICE,"File not found: %s",str);
83
84
85
		bputs(text[FileNotFound]);
		if(SYSOP) bputs(str);
		CRLF;
rswindell's avatar
rswindell committed
86
87
		return; 
	}
88
89
90

	if(mode&P_OPENCLOSE) {
		length=filelength(file);
rswindell's avatar
rswindell committed
91
92
93
94
95
		if(length<0) {
			close(file);
			errormsg(WHERE,ERR_CHK,str,length);
			return;
		}
96
97
98
		if((buf=(char*)MALLOC(length+1L))==NULL) {
			close(file);
			errormsg(WHERE,ERR_ALLOC,str,length+1L);
rswindell's avatar
rswindell committed
99
100
			return; 
		}
rswindell's avatar
rswindell committed
101
		l=lread(file,buf,length);
102
		fclose(stream);
rswindell's avatar
rswindell committed
103
104
105
106
107
108
109
		if(l!=length)
			errormsg(WHERE,ERR_READ,str,length);
		else {
			buf[l]=0;
			putmsg(buf,mode);
		}
		FREE(buf); 
rswindell's avatar
rswindell committed
110
	}
111
112
	else {
		putmsg_fp(stream,filelength(file),mode);
rswindell's avatar
rswindell committed
113
114
115
		fclose(stream); 
	}
	if((mode&P_NOABORT || wip || rip || html) && online==ON_REMOTE) {
116
		SYNC;
rswindell's avatar
rswindell committed
117
118
		rioctl(IOSM|ABORT); 
	}
119
120
121
	if(rip)
		ansi_getlines();
	console=savcon;
rswindell's avatar
rswindell committed
122
}
123
124
125

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

	if(mode&P_NOABORT) {
		if(online==ON_REMOTE) {
			rioctl(IOCM|ABORT);
rswindell's avatar
rswindell committed
134
135
136
137
			rioctl(IOCS|ABORT); 
		}
		sys_status&=~SS_ABORT; 
	}
138
	if(!tos) {
rswindell's avatar
rswindell committed
139
140
		CRLF; 
	}
141
	if((file=nopen(str,O_RDONLY))==-1) {
142
		lprintf(LOG_NOTICE,"File not found: %s",str);
143
144
145
		bputs(text[FileNotFound]);
		if(SYSOP) bputs(str);
		CRLF;
rswindell's avatar
rswindell committed
146
147
		return; 
	}
148
	length=filelength(file);
rswindell's avatar
rswindell committed
149
150
151
152
153
	if(length<0) {
		close(file);
		errormsg(WHERE,ERR_CHK,str,length);
		return;
	}
154
155
156
	if((buf=(char*)MALLOC(length+1L))==NULL) {
		close(file);
		errormsg(WHERE,ERR_ALLOC,str,length+1L);
rswindell's avatar
rswindell committed
157
158
		return; 
	}
159
160
	l=lread(file,buf,length);
	close(file);
rswindell's avatar
rswindell committed
161
162
163
164
165
166
167
168
169
170
171
172
173
174
	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
175
		}
rswindell's avatar
rswindell committed
176
		putmsg(p,mode);
rswindell's avatar
rswindell committed
177
	}
178
179
	if(mode&P_NOABORT && online==ON_REMOTE) {
		SYNC;
rswindell's avatar
rswindell committed
180
181
		rioctl(IOSM|ABORT); 
	}
rswindell's avatar
rswindell committed
182
	FREE(buf);
183
184
185
186
187
188
189
190
}

/****************************************************************************/
/* 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:                                     */
/****************************************************************************/
191
void sbbs_t::menu(const char *code)
192
{
193
    char str[MAX_PATH+1],path[MAX_PATH+1];
194
195
196
197
198

	sys_status&=~SS_ABORT;
	if(menu_file[0])
		strcpy(path,menu_file);
	else {
199
		sprintf(str,"%smenu/",cfg.text_dir);
200
201
		if(menu_dir[0]) {
			strcat(str,menu_dir);
rswindell's avatar
rswindell committed
202
203
			strcat(str,"/"); 
		}
204
205
		strcat(str,code);
		strcat(str,".");
rswindell's avatar
rswindell committed
206
207
		sprintf(path,"%s%s",str,useron.misc&WIP ? "wip": useron.misc&RIP ? "rip" : "html");
		if(!(useron.misc&(RIP|WIP|HTML)) || !fexistcase(path)) {
208
			sprintf(path,"%smon",str);
209
			if((useron.misc&(COLOR|ANSI))!=ANSI || !fexistcase(path)) {
210
				sprintf(path,"%sans",str);
211
212
213
214
215
				if(!(useron.misc&ANSI) || !fexistcase(path))
					sprintf(path,"%sasc",str); 
			} 
		} 
	}
216
217
218
219
220

	printfile(path,P_OPENCLOSE);
}