|
|
1.1 root 1: /* prntfile.cpp */
2:
3: /* Synchronet file print/display routines */
4:
5: /* $Id: prntfile.cpp,v 1.3 2000/11/07 04:17:38 rswindell Exp $ */
6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
11: * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html *
12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include "sbbs.h"
39:
40: /****************************************************************************/
41: /* Prints a file remotely and locally, interpreting ^A sequences, checks */
42: /* for pauses, aborts and ANSI. 'str' is the path of the file to print */
43: /* Called from functions menu and text_sec */
44: /****************************************************************************/
45: void sbbs_t::printfile(char *str, long mode)
46: {
47: char HUGE16 *buf;
48: int file,wip=0,rip=0;
49: long length,savcon=console;
50: FILE *stream;
51:
52: if(strstr(str,".WIP"))
53: wip=1;
54: if(strstr(str,".RIP"))
55: rip=1;
56:
57: if(mode&P_NOABORT || wip || rip) {
58: if(online==ON_REMOTE && console&CON_R_ECHO) {
59: rioctl(IOCM|ABORT);
60: rioctl(IOCS|ABORT); }
61: sys_status&=~SS_ABORT; }
62:
63: if(!tos && !wip && !rip)
64: CRLF;
65:
66: if((stream=fnopen(&file,str,O_RDONLY))==NULL) {
67: lprintf("File not found: %s",str);
68: bputs(text[FileNotFound]);
69: if(SYSOP) bputs(str);
70: CRLF;
71: return; }
72:
73: if(mode&P_OPENCLOSE) {
74: length=filelength(file);
75: if((buf=(char*)MALLOC(length+1L))==NULL) {
76: close(file);
77: console=savcon;
78: errormsg(WHERE,ERR_ALLOC,str,length+1L);
79: return; }
80: buf[lread(file,buf,length)]=0;
81: fclose(stream);
82: putmsg(buf,mode);
83: FREE((char *)buf); }
84: else {
85: putmsg_fp(stream,filelength(file),mode);
86: fclose(stream); }
87: if((mode&P_NOABORT || wip || rip) && online==ON_REMOTE) {
88: SYNC;
89: rioctl(IOSM|ABORT); }
90: if(rip)
91: ansi_getlines();
92: console=savcon;
93: }
94:
95: void sbbs_t::printtail(char *str, int lines, long mode)
96: {
97: char HUGE16 *buf,HUGE16 *p;
98: int file,cur=0;
99: ulong length,l;
100:
101: if(mode&P_NOABORT) {
102: if(online==ON_REMOTE) {
103: rioctl(IOCM|ABORT);
104: rioctl(IOCS|ABORT); }
105: sys_status&=~SS_ABORT; }
106: if(!tos) {
107: CRLF; }
108: if((file=nopen(str,O_RDONLY))==-1) {
109: lprintf("File not found: %s",str);
110: bputs(text[FileNotFound]);
111: if(SYSOP) bputs(str);
112: CRLF;
113: return; }
114: length=filelength(file);
115: if((buf=(char*)MALLOC(length+1L))==NULL) {
116: close(file);
117: errormsg(WHERE,ERR_ALLOC,str,length+1L);
118: return; }
119: l=lread(file,buf,length);
120: buf[l]=0;
121: close(file);
122: p=(buf+l)-1;
123: if(*p==LF) p--;
124: while(*p && p>buf) {
125: if(*p==LF)
126: cur++;
127: if(cur>=lines) {
128: p++;
129: break; }
130: p--; }
131: putmsg(p,mode);
132: if(mode&P_NOABORT && online==ON_REMOTE) {
133: SYNC;
134: rioctl(IOSM|ABORT); }
135: FREE((char *)buf);
136: }
137:
138: /****************************************************************************/
139: /* Prints the menu number 'menunum' from the text directory. Checks for ^A */
140: /* ,ANSI sequences, pauses and aborts. Usually accessed by user inputing '?'*/
141: /* Called from every function that has an available menu. */
142: /* The code definitions are as follows: */
143: /****************************************************************************/
144: void sbbs_t::menu(char *code)
145: {
146: char str[256],path[256];
147:
148: sys_status&=~SS_ABORT;
149: if(menu_file[0])
150: strcpy(path,menu_file);
151: else {
152: sprintf(str,"%smenu/",cfg.text_dir);
153: if(menu_dir[0]) {
154: strcat(str,menu_dir);
155: strcat(str,"/"); }
156: strcat(str,code);
157: strcat(str,".");
158: sprintf(path,"%s%s",str,useron.misc&WIP ? "wip":"rip");
159: if(!(useron.misc&(RIP|WIP)) || !fexist(path)) {
160: sprintf(path,"%smon",str);
161: if((useron.misc&(COLOR|ANSI))!=ANSI || !fexist(path)) {
162: sprintf(path,"%sans",str);
163: if(!(useron.misc&ANSI) || !fexist(path))
164: sprintf(path,"%sasc",str); } } }
165:
166: printfile(path,P_OPENCLOSE);
167: }
168:
169:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.