prntfile.cpp 5.2 KB
Newer Older
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
/* 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)		*
 *																			*
 * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html		*
 *																			*
 * 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;
49
50
51
52
	int file,wip=0,rip=0;
	long length,savcon=console;
	FILE *stream;

53
54
55
56
57
58
59
	p=strrchr(str,'.');
	if(p!=NULL) {
		if(stricmp(p,".wip")==0)
			wip=1;
		else if(stricmp(p,".rip")==0)
			rip=1;
	}
60
61
62
63
64
65
66
67
68
69
70

	if(mode&P_NOABORT || wip || rip) {
		if(online==ON_REMOTE && console&CON_R_ECHO) {
			rioctl(IOCM|ABORT);
			rioctl(IOCS|ABORT); }
		sys_status&=~SS_ABORT; }

	if(!tos && !wip && !rip)
		CRLF;

	if((stream=fnopen(&file,str,O_RDONLY))==NULL) {
71
		lprintf("File not found: %s",str);
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
108
109
110
111
112
		bputs(text[FileNotFound]);
		if(SYSOP) bputs(str);
		CRLF;
		return; }

	if(mode&P_OPENCLOSE) {
		length=filelength(file);
		if((buf=(char*)MALLOC(length+1L))==NULL) {
			close(file);
			console=savcon;
			errormsg(WHERE,ERR_ALLOC,str,length+1L);
			return; }
		buf[lread(file,buf,length)]=0;
		fclose(stream);
		putmsg(buf,mode);
		FREE((char *)buf); }
	else {
		putmsg_fp(stream,filelength(file),mode);
		fclose(stream); }
	if((mode&P_NOABORT || wip || rip) && online==ON_REMOTE) {
		SYNC;
		rioctl(IOSM|ABORT); }
	if(rip)
		ansi_getlines();
	console=savcon;
	}

void sbbs_t::printtail(char *str, int lines, long mode)
{
	char HUGE16 *buf,HUGE16 *p;
	int file,cur=0;
	ulong length,l;

	if(mode&P_NOABORT) {
		if(online==ON_REMOTE) {
			rioctl(IOCM|ABORT);
			rioctl(IOCS|ABORT); }
		sys_status&=~SS_ABORT; }
	if(!tos) {
		CRLF; }
	if((file=nopen(str,O_RDONLY))==-1) {
113
		lprintf("File not found: %s",str);
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
		bputs(text[FileNotFound]);
		if(SYSOP) bputs(str);
		CRLF;
		return; }
	length=filelength(file);
	if((buf=(char*)MALLOC(length+1L))==NULL) {
		close(file);
		errormsg(WHERE,ERR_ALLOC,str,length+1L);
		return; }
	l=lread(file,buf,length);
	buf[l]=0;
	close(file);
	p=(buf+l)-1;
	if(*p==LF) p--;
	while(*p && p>buf) {
		if(*p==LF)
			cur++;
		if(cur>=lines) {
			p++;
			break; }
		p--; }
	putmsg(p,mode);
	if(mode&P_NOABORT && online==ON_REMOTE) {
		SYNC;
		rioctl(IOSM|ABORT); }
	FREE((char *)buf);
}

/****************************************************************************/
/* 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:                                     */
/****************************************************************************/
void sbbs_t::menu(char *code)
{
150
    char str[MAX_PATH+1],path[MAX_PATH+1];
151
152
153
154
155

	sys_status&=~SS_ABORT;
	if(menu_file[0])
		strcpy(path,menu_file);
	else {
156
		sprintf(str,"%smenu/",cfg.text_dir);
157
158
159
160
161
		if(menu_dir[0]) {
			strcat(str,menu_dir);
			strcat(str,"/"); }
		strcat(str,code);
		strcat(str,".");
162
		sprintf(path,"%s%s",str,useron.misc&WIP ? "wip":"rip");
163
		if(!(useron.misc&(RIP|WIP)) || !fexistcase(path)) {
164
			sprintf(path,"%smon",str);
165
			if((useron.misc&(COLOR|ANSI))!=ANSI || !fexistcase(path)) {
166
				sprintf(path,"%sans",str);
167
168
169
170
171
				if(!(useron.misc&ANSI) || !fexistcase(path))
					sprintf(path,"%sasc",str); 
			} 
		} 
	}
172
173
174
175
176

	printfile(path,P_OPENCLOSE);
}