Annotation of sbbs/src/sbbs3/prntfile.cpp, revision 1.1.1.1

1.1       root        1: /* prntfile.cpp */
                      2: 
                      3: /* Synchronet file print/display routines */
                      4: 
                      5: /* $Id: prntfile.cpp,v 1.17 2006/08/23 01:45:05 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 2006 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* 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: 
                     81:        if((stream=fnopen(&file,str,O_RDONLY))==NULL) {
                     82:                lprintf(LOG_NOTICE,"Node %d !File not found: %s",cfg.node_num,str);
                     83:                bputs(text[FileNotFound]);
                     84:                if(SYSOP) bputs(str);
                     85:                CRLF;
                     86:                return; 
                     87:        }
                     88: 
                     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);
                    104:        else {
                    105:                buf[l]=0;
                    106:                putmsg(buf,mode);
                    107:        }
                    108:        free(buf); 
                    109: 
                    110:        if((mode&P_NOABORT || wip || rip || html) && online==ON_REMOTE) {
                    111:                SYNC;
                    112:                rioctl(IOSM|ABORT); 
                    113:        }
                    114:        if(rip)
                    115:                ansi_getlines();
                    116:        console=savcon;
                    117: }
                    118: 
                    119: void sbbs_t::printtail(char *str, int lines, long mode)
                    120: {
                    121:        char*   buf;
                    122:        char*   p;
                    123:        int             file,cur=0;
                    124:        long    length,l;
                    125: 
                    126:        if(mode&P_NOABORT) {
                    127:                if(online==ON_REMOTE) {
                    128:                        rioctl(IOCM|ABORT);
                    129:                        rioctl(IOCS|ABORT); 
                    130:                }
                    131:                sys_status&=~SS_ABORT; 
                    132:        }
                    133:        if(!tos) {
                    134:                CRLF; 
                    135:        }
                    136:        if((file=nopen(str,O_RDONLY))==-1) {
                    137:                lprintf(LOG_NOTICE,"Node %d !File not found: %s",cfg.node_num,str);
                    138:                bputs(text[FileNotFound]);
                    139:                if(SYSOP) bputs(str);
                    140:                CRLF;
                    141:                return; 
                    142:        }
                    143:        length=filelength(file);
                    144:        if(length<0) {
                    145:                close(file);
                    146:                errormsg(WHERE,ERR_CHK,str,length);
                    147:                return;
                    148:        }
                    149:        if((buf=(char*)malloc(length+1L))==NULL) {
                    150:                close(file);
                    151:                errormsg(WHERE,ERR_ALLOC,str,length+1L);
                    152:                return; 
                    153:        }
                    154:        l=lread(file,buf,length);
                    155:        close(file);
                    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:        }
                    173:        if(mode&P_NOABORT && online==ON_REMOTE) {
                    174:                SYNC;
                    175:                rioctl(IOSM|ABORT); 
                    176:        }
                    177:        free(buf);
                    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: /****************************************************************************/
                    186: void sbbs_t::menu(const char *code)
                    187: {
                    188:     char str[MAX_PATH+1],path[MAX_PATH+1];
                    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);
                    197:                        strcat(str,"/"); 
                    198:                }
                    199:                strcat(str,code);
                    200:                strcat(str,".");
                    201:                sprintf(path,"%s%s",str,term_supports(WIP) ? "wip": term_supports(RIP) ? "rip" : "html");
                    202:                if(!(term_supports()&(RIP|WIP|HTML)) || !fexistcase(path)) {
                    203:                        sprintf(path,"%smon",str);
                    204:                        if((term_supports()&(COLOR|ANSI))!=ANSI || !fexistcase(path)) {
                    205:                                sprintf(path,"%sans",str);
                    206:                                if(!term_supports(ANSI) || !fexistcase(path))
                    207:                                        sprintf(path,"%sasc",str); 
                    208:                        } 
                    209:                } 
                    210:        }
                    211: 
                    212:        printfile(path,P_OPENCLOSE);
                    213: }
                    214: 
                    215: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.