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