|
|
1.1 root 1: /* prntfile.cpp */
2:
3: /* Synchronet file print/display routines */
4:
1.1.1.2 ! root 5: /* $Id: prntfile.cpp,v 1.20 2010/03/06 00:13:04 rswindell Exp $ */
1.1 root 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: * *
1.1.1.2 ! root 11: * Copyright 2010 Rob Swindell - http://www.synchro.net/copyright.html *
1.1 root 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* buf;
48: char* p;
49: int file;
50: BOOL wip=FALSE,rip=FALSE,html=FALSE;
51: long l,length,savcon=console;
52: FILE *stream;
53:
54: p=strrchr(str,'.');
55: if(p!=NULL) {
56: if(stricmp(p,".wip")==0) {
57: wip=TRUE;
58: mode|=P_NOPAUSE;
59: }
60: else if(stricmp(p,".rip")==0) {
61: rip=TRUE;
62: mode|=P_NOPAUSE;
63: }
64: else if(stricmp(p,".html")==0) {
65: html=TRUE;
66: mode|=(P_HTML|P_NOPAUSE);
67: }
68: }
69:
70: if(mode&P_NOABORT || wip || rip || html) {
71: if(online==ON_REMOTE && console&CON_R_ECHO) {
72: rioctl(IOCM|ABORT);
73: rioctl(IOCS|ABORT);
74: }
75: sys_status&=~SS_ABORT;
76: }
77:
78: if(!(mode&P_NOCRLF) && !tos && !wip && !rip && !html)
79: CRLF;
80:
1.1.1.2 ! root 81: if((stream=fnopen(&file,str,O_RDONLY|O_DENYNONE))==NULL) {
! 82: lprintf(LOG_NOTICE,"Node %d !Error %d (%s) opening: %s"
! 83: ,cfg.node_num,errno,strerror(errno),str);
1.1 root 84: bputs(text[FileNotFound]);
85: if(SYSOP) bputs(str);
86: CRLF;
87: return;
88: }
89:
1.1.1.2 ! root 90: length=(long)filelength(file);
1.1 root 91: if(length<0) {
92: close(file);
93: errormsg(WHERE,ERR_CHK,str,length);
94: return;
95: }
96: if((buf=(char*)malloc(length+1L))==NULL) {
97: close(file);
98: errormsg(WHERE,ERR_ALLOC,str,length+1L);
99: return;
100: }
101: l=lread(file,buf,length);
102: fclose(stream);
103: if(l!=length)
104: errormsg(WHERE,ERR_READ,str,length);
105: else {
106: buf[l]=0;
107: putmsg(buf,mode);
108: }
109: free(buf);
110:
111: if((mode&P_NOABORT || wip || rip || html) && online==ON_REMOTE) {
112: SYNC;
113: rioctl(IOSM|ABORT);
114: }
115: if(rip)
116: ansi_getlines();
117: console=savcon;
118: }
119:
120: void sbbs_t::printtail(char *str, int lines, long mode)
121: {
122: char* buf;
123: char* p;
124: int file,cur=0;
125: long length,l;
126:
127: if(mode&P_NOABORT) {
128: if(online==ON_REMOTE) {
129: rioctl(IOCM|ABORT);
130: rioctl(IOCS|ABORT);
131: }
132: sys_status&=~SS_ABORT;
133: }
134: if(!tos) {
135: CRLF;
136: }
1.1.1.2 ! root 137: if((file=nopen(str,O_RDONLY|O_DENYNONE))==-1) {
! 138: lprintf(LOG_NOTICE,"Node %d !Error %d (%s) opening: %s"
! 139: ,cfg.node_num,errno,strerror(errno),str);
1.1 root 140: bputs(text[FileNotFound]);
141: if(SYSOP) bputs(str);
142: CRLF;
143: return;
144: }
1.1.1.2 ! root 145: length=(long)filelength(file);
1.1 root 146: if(length<0) {
147: close(file);
148: errormsg(WHERE,ERR_CHK,str,length);
149: return;
150: }
151: if((buf=(char*)malloc(length+1L))==NULL) {
152: close(file);
153: errormsg(WHERE,ERR_ALLOC,str,length+1L);
154: return;
155: }
156: l=lread(file,buf,length);
157: close(file);
158: if(l!=length)
159: errormsg(WHERE,ERR_READ,str,length);
160: else {
161: buf[l]=0;
162: p=(buf+l)-1;
163: if(*p==LF) p--;
164: while(*p && p>buf) {
165: if(*p==LF)
166: cur++;
167: if(cur>=lines) {
168: p++;
169: break;
170: }
171: p--;
172: }
173: putmsg(p,mode);
174: }
175: if(mode&P_NOABORT && online==ON_REMOTE) {
176: SYNC;
177: rioctl(IOSM|ABORT);
178: }
179: free(buf);
180: }
181:
182: /****************************************************************************/
183: /* Prints the menu number 'menunum' from the text directory. Checks for ^A */
184: /* ,ANSI sequences, pauses and aborts. Usually accessed by user inputing '?'*/
185: /* Called from every function that has an available menu. */
186: /* The code definitions are as follows: */
187: /****************************************************************************/
188: void sbbs_t::menu(const char *code)
189: {
190: char str[MAX_PATH+1],path[MAX_PATH+1];
191:
192: sys_status&=~SS_ABORT;
193: if(menu_file[0])
194: strcpy(path,menu_file);
195: else {
196: sprintf(str,"%smenu/",cfg.text_dir);
197: if(menu_dir[0]) {
198: strcat(str,menu_dir);
199: strcat(str,"/");
200: }
201: strcat(str,code);
202: strcat(str,".");
203: sprintf(path,"%s%s",str,term_supports(WIP) ? "wip": term_supports(RIP) ? "rip" : "html");
204: if(!(term_supports()&(RIP|WIP|HTML)) || !fexistcase(path)) {
205: sprintf(path,"%smon",str);
206: if((term_supports()&(COLOR|ANSI))!=ANSI || !fexistcase(path)) {
207: sprintf(path,"%sans",str);
208: if(!term_supports(ANSI) || !fexistcase(path))
209: sprintf(path,"%sasc",str);
210: }
211: }
212: }
213:
214: printfile(path,P_OPENCLOSE);
215: }
216:
217:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.