|
|
1.1 ! root 1: /* putmsg.cpp */ ! 2: ! 3: /* Synchronet message/menu display routine */ ! 4: ! 5: /* $Id: putmsg.cpp,v 1.2 2000/11/07 04:28:59 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: /* Outputs a NULL terminated string locally and remotely (if applicable) */ ! 42: /* checking for message aborts, pauses, ANSI escape and ^A sequences. */ ! 43: /* Changes local text attributes if necessary. Max length of str is 4 gig */ ! 44: /* Returns the last char of the buffer access.. 0 if not aborted. */ ! 45: /* If P_SAVEATR bit is set in mode, the attributes set by the message */ ! 46: /* will be the current attributes after the message is displayed, otherwise */ ! 47: /* the attributes prior to diplaying the message are always restored. */ ! 48: /* Ignores Ctrl-Z's */ ! 49: /****************************************************************************/ ! 50: char sbbs_t::putmsg(char HUGE16 *str, long mode) ! 51: { ! 52: char tmpatr,tmp2[256],tmp3[128]; ! 53: uchar exatr=0; ! 54: int orgcon=console,i; ! 55: ulong l=0,sys_status_sav=sys_status; ! 56: ! 57: tmpatr=curatr; /* was lclatr(-1) */ ! 58: if(!(mode&P_SAVEATR)) ! 59: attr(LIGHTGRAY); ! 60: while(str[l] && (mode&P_NOABORT || !msgabort()) && online) { ! 61: if(str[l]==1) { /* Ctrl-Ax sequence */ ! 62: if(str[l+1]=='"' && !(sys_status&SS_NEST_PF)) { /* Quote a file */ ! 63: l+=2; ! 64: i=0; ! 65: while(i<12 && isprint(str[l]) && str[l]!='\\' && str[l]!='/') ! 66: tmp2[i++]=str[l++]; ! 67: tmp2[i]=0; ! 68: sys_status|=SS_NEST_PF; /* keep it only one message deep! */ ! 69: sprintf(tmp3,"%s%s",cfg.text_dir,tmp2); ! 70: printfile(tmp3,0); ! 71: sys_status&=~SS_NEST_PF; } ! 72: else if(toupper(str[l+1])=='Z') /* Ctrl-AZ==EOF */ ! 73: break; ! 74: else { ! 75: ctrl_a(str[l+1]); ! 76: l+=2; } } ! 77: else if((str[l]=='`' || str[l]=='�') && str[l+1]=='[') { ! 78: outchar(ESC); /* Convert `[ and �[ to ESC[ */ ! 79: l++; } ! 80: else if(cfg.sys_misc&SM_PCBOARD && str[l]=='@' && str[l+1]=='X' ! 81: && isxdigit(str[l+2]) && isxdigit(str[l+3])) { ! 82: sprintf(tmp2,"%.2s",str+l+2); ! 83: attr(ahtoul(tmp2)); ! 84: exatr=1; ! 85: l+=4; } ! 86: else if(cfg.sys_misc&SM_WILDCAT && str[l]=='@' && str[l+3]=='@' ! 87: && isxdigit(str[l+1]) && isxdigit(str[l+2])) { ! 88: sprintf(tmp2,"%.2s",str+l+1); ! 89: attr(ahtoul(tmp2)); ! 90: // exatr=1; ! 91: l+=4; } ! 92: else if(cfg.sys_misc&SM_RENEGADE && str[l]=='|' && isdigit(str[l+1]) ! 93: && !(useron.misc&(RIP|WIP))) { ! 94: sprintf(tmp2,"%.2s",str+l+1); ! 95: i=atoi(tmp2); ! 96: if(i>=16) { /* setting background */ ! 97: i-=16; ! 98: i<<=4; ! 99: i|=(curatr&0x0f); } /* leave foreground alone */ ! 100: else ! 101: i|=(curatr&0xf0); /* leave background alone */ ! 102: attr(i); ! 103: exatr=1; ! 104: l+=2; /* Skip |x */ ! 105: if(isdigit(str[l])) ! 106: l++; } /* Skip second digit if it exists */ ! 107: else if(cfg.sys_misc&SM_CELERITY && str[l]=='|' && isalpha(str[l+1]) ! 108: && !(useron.misc&(RIP|WIP))) { ! 109: switch(str[l+1]) { ! 110: case 'k': ! 111: attr((curatr&0xf0)|BLACK); ! 112: break; ! 113: case 'b': ! 114: attr((curatr&0xf0)|BLUE); ! 115: break; ! 116: case 'g': ! 117: attr((curatr&0xf0)|GREEN); ! 118: break; ! 119: case 'c': ! 120: attr((curatr&0xf0)|CYAN); ! 121: break; ! 122: case 'r': ! 123: attr((curatr&0xf0)|RED); ! 124: break; ! 125: case 'm': ! 126: attr((curatr&0xf0)|MAGENTA); ! 127: break; ! 128: case 'y': ! 129: attr((curatr&0xf0)|YELLOW); ! 130: break; ! 131: case 'w': ! 132: attr((curatr&0xf0)|LIGHTGRAY); ! 133: break; ! 134: case 'd': ! 135: attr((curatr&0xf0)|BLACK|HIGH); ! 136: break; ! 137: case 'B': ! 138: attr((curatr&0xf0)|BLUE|HIGH); ! 139: break; ! 140: case 'G': ! 141: attr((curatr&0xf0)|GREEN|HIGH); ! 142: break; ! 143: case 'C': ! 144: attr((curatr&0xf0)|CYAN|HIGH); ! 145: break; ! 146: case 'R': ! 147: attr((curatr&0xf0)|RED|HIGH); ! 148: break; ! 149: case 'M': ! 150: attr((curatr&0xf0)|MAGENTA|HIGH); ! 151: break; ! 152: case 'Y': /* Yellow */ ! 153: attr((curatr&0xf0)|YELLOW|HIGH); ! 154: break; ! 155: case 'W': ! 156: attr((curatr&0xf0)|LIGHTGRAY|HIGH); ! 157: break; ! 158: case 'S': /* swap foreground and background */ ! 159: attr((curatr&0x07)<<4); ! 160: break; } ! 161: exatr=1; ! 162: l+=2; /* Skip |x */ ! 163: } /* Skip second digit if it exists */ ! 164: else if(cfg.sys_misc&SM_WWIV && str[l]==3 && isdigit(str[l+1])) { ! 165: exatr=1; ! 166: switch(str[l+1]) { ! 167: default: ! 168: attr(LIGHTGRAY); ! 169: break; ! 170: case '1': ! 171: attr(CYAN|HIGH); ! 172: break; ! 173: case '2': ! 174: attr(BROWN|HIGH); ! 175: break; ! 176: case '3': ! 177: attr(MAGENTA); ! 178: break; ! 179: case '4': ! 180: attr(LIGHTGRAY|HIGH|(BLUE<<4)); ! 181: break; ! 182: case '5': ! 183: attr(GREEN); ! 184: break; ! 185: case '6': ! 186: attr(RED|HIGH|BLINK); ! 187: break; ! 188: case '7': ! 189: attr(BLUE|HIGH); ! 190: break; ! 191: case '8': ! 192: attr(BLUE); ! 193: break; ! 194: case '9': ! 195: attr(CYAN); ! 196: break; } ! 197: l+=2; } ! 198: else { ! 199: if(str[l]==LF) { ! 200: if(exatr) /* clear at newline for extra attr codes */ ! 201: attr(LIGHTGRAY); ! 202: if(l && str[l-1]!=CR) /* convert sole LF to CR/LF */ ! 203: outchar(CR); ! 204: } ! 205: ! 206: /* ansi escape sequence */ ! 207: if(outchar_esc) { ! 208: if(str[l]=='A' || str[l]=='B' || str[l]=='H' || str[l]=='J' ! 209: || str[l]=='f' || str[l]=='u') /* ANSI anim */ ! 210: lncntr=0; /* so defeat pause */ ! 211: if(str[l]=='"') { ! 212: l++; /* don't pass on keyboard reassignment */ ! 213: continue; } } ! 214: if(str[l]=='!' && str[l+1]=='|' && useron.misc&(RIP|WIP)) /* RIP */ ! 215: lncntr=0; /* so defeat pause */ ! 216: if(str[l]==ESC && str[l+1]=='$') /* WIP command */ ! 217: lncntr=0; ! 218: if(str[l]=='@' && !(mode&P_NOATCODES)) { ! 219: i=atcodes((char *)str+l); /* returns 0 if not valid @ code */ ! 220: l+=i; /* i is length of code string */ ! 221: if(i) /* if valid string, go to top */ ! 222: continue; } ! 223: if(str[l]!=26) ! 224: outchar(str[l]); ! 225: l++; } } ! 226: //curatr=lclatr(-1); 01/29/96 ! 227: if(!(mode&P_SAVEATR)) { ! 228: console=orgcon; ! 229: attr(tmpatr); } ! 230: ! 231: /* Restore original settings of Forced Pause On/Off */ ! 232: sys_status&=~(SS_PAUSEOFF|SS_PAUSEON); ! 233: sys_status|=(sys_status_sav&(SS_PAUSEOFF|SS_PAUSEON)); ! 234: return(str[l]); ! 235: } ! 236: ! 237: /****************************************************************************/ ! 238: /* Displays a text file to the screen, reading/display a block at time */ ! 239: /****************************************************************************/ ! 240: void sbbs_t::putmsg_fp(FILE *fp, long length, long mode) ! 241: { ! 242: char *buf,tmpatr; ! 243: int i,j,b=8192,orgcon=console; ! 244: long l; ! 245: ! 246: tmpatr=curatr; /* was lclatr(-1) */ ! 247: if((buf=(char *)MALLOC(b+1))==NULL) { ! 248: errormsg(WHERE,ERR_ALLOC,nulstr,b+1L); ! 249: return; } ! 250: for(l=0;l<length;l+=b) { ! 251: if(l+b>length) ! 252: b=length-l; ! 253: i=j=fread(buf,1,b,fp); ! 254: if(!j) break; /* No bytes read */ ! 255: if(l+i<length) /* Not last block */ ! 256: while(i && buf[i-1]!=LF) i--; /* Search for last LF */ ! 257: if(!i) i=j; /* None found */ ! 258: buf[i]=0; ! 259: if(i<j) ! 260: fseek(fp,(long)-(j-i),SEEK_CUR); ! 261: b=i; ! 262: if(putmsg(buf,mode|P_SAVEATR)) ! 263: break; } ! 264: if(!(mode&P_SAVEATR)) { ! 265: console=orgcon; ! 266: attr(tmpatr); } ! 267: FREE(buf); ! 268: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.