|
|
1.1 ! root 1: /* text_sec.cpp */ ! 2: ! 3: /* Synchronet general text file (g-file) section */ ! 4: ! 5: /* $Id: text_sec.cpp,v 1.9 2005/09/20 03:39:52 deuce 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: #define MAX_TXTSECS 500 /* Maximum number of text file sections */ ! 41: #define MAX_TXTFILES 500 /* Maximum number of text files per section */ ! 42: ! 43: /****************************************************************************/ ! 44: /* General Text File Section. */ ! 45: /* Called from function main_sec */ ! 46: /* Returns 1 if no text sections available, 0 otherwise. */ ! 47: /****************************************************************************/ ! 48: int sbbs_t::text_sec() ! 49: { ! 50: char str[256],usemenu ! 51: ,*file[MAX_TXTFILES],addpath[83],addstr[83],*buf,ch; ! 52: char tmp[512]; ! 53: long i,j,usrsec[MAX_TXTSECS],usrsecs,cursec; ! 54: long l,length; ! 55: FILE *stream; ! 56: ! 57: for(i=j=0;i<cfg.total_txtsecs;i++) { ! 58: if(!chk_ar(cfg.txtsec[i]->ar,&useron)) ! 59: continue; ! 60: usrsec[j++]=i; } ! 61: usrsecs=j; ! 62: if(!usrsecs) { ! 63: bputs(text[NoTextSections]); ! 64: return(1); } ! 65: action=NODE_RTXT; ! 66: while(online) { ! 67: sprintf(str,"%smenu/text_sec.*",cfg.text_dir); ! 68: if(fexist(str)) ! 69: menu("text_sec"); ! 70: else { ! 71: bputs(text[TextSectionLstHdr]); ! 72: for(i=0;i<usrsecs && !msgabort();i++) { ! 73: sprintf(str,text[TextSectionLstFmt],i+1,cfg.txtsec[usrsec[i]]->name); ! 74: if(i<9) outchar(' '); ! 75: bputs(str); } } ! 76: ASYNC; ! 77: mnemonics(text[WhichTextSection]); ! 78: if((cursec=getnum(usrsecs))<1) ! 79: break; ! 80: cursec--; ! 81: while(online) { ! 82: sprintf(str,"%smenu/text%lu.*",cfg.text_dir,cursec+1); ! 83: if(fexist(str)) { ! 84: sprintf(str,"text%lu",cursec+1); ! 85: menu(str); ! 86: usemenu=1; } ! 87: else { ! 88: bprintf(text[TextFilesLstHdr],cfg.txtsec[usrsec[cursec]]->name); ! 89: usemenu=0; } ! 90: sprintf(str,"%stext/%s.ixt",cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code); ! 91: j=0; ! 92: if(fexist(str)) { ! 93: if((stream=fnopen((int *)&i,str,O_RDONLY))==NULL) { ! 94: errormsg(WHERE,ERR_OPEN,str,O_RDONLY); ! 95: return(0); } ! 96: while(!ferror(stream) && !msgabort()) { /* file open too long */ ! 97: if(!fgets(str,81,stream)) ! 98: break; ! 99: str[strlen(str)-2]=0; /* chop off CRLF */ ! 100: if((file[j]=(char *)malloc(strlen(str)+1))==NULL) { ! 101: errormsg(WHERE,ERR_ALLOC,nulstr,strlen(str)+1); ! 102: continue; } ! 103: strcpy(file[j],str); ! 104: fgets(str,81,stream); ! 105: if(!usemenu) bprintf(text[TextFilesLstFmt],j+1,str); ! 106: j++; } ! 107: fclose(stream); } ! 108: ASYNC; ! 109: if(SYSOP) { ! 110: strcpy(str,"QARE?"); ! 111: mnemonics(text[WhichTextFileSysop]); } ! 112: else { ! 113: strcpy(str,"Q?"); ! 114: mnemonics(text[WhichTextFile]); } ! 115: i=getkeys(str,j); ! 116: if(!(i&0x80000000L)) { /* no file number */ ! 117: for(l=0;l<j;l++) ! 118: free(file[l]); ! 119: if((i=='E' || i=='R') && !j) ! 120: continue; } ! 121: if(i=='Q' || !i) ! 122: break; ! 123: if(i==-1) { /* ctrl-c */ ! 124: for(i=0;i<j;i++) ! 125: free(file[i]); ! 126: return(0); } ! 127: if(i=='?') /* ? means re-list */ ! 128: continue; ! 129: if(i=='A') { /* Add text file */ ! 130: if(j) { ! 131: bputs(text[AddTextFileBeforeWhich]); ! 132: i=getnum(j+1); ! 133: if(i<1) ! 134: continue; ! 135: i--; /* number of file entries to skip */ } ! 136: else ! 137: i=0; ! 138: bprintf(text[AddTextFilePath] ! 139: ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code); ! 140: if(!getstr(addpath,80,0)) ! 141: continue; ! 142: strcat(addpath,crlf); ! 143: bputs(text[AddTextFileDesc]); ! 144: if(!getstr(addstr,74,0)) ! 145: continue; ! 146: strcat(addstr,crlf); ! 147: sprintf(str,"%stext/%s.ixt" ! 148: ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code); ! 149: if(i==j) { /* just add to end */ ! 150: if((i=nopen(str,O_WRONLY|O_APPEND|O_CREAT))==-1) { ! 151: errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_APPEND|O_CREAT); ! 152: return(0); } ! 153: write(i,addpath,strlen(addpath)); ! 154: write(i,addstr,strlen(addstr)); ! 155: close(i); ! 156: continue; } ! 157: j=i; /* inserting in middle of file */ ! 158: if((stream=fnopen((int *)&i,str,O_RDWR))==NULL) { ! 159: errormsg(WHERE,ERR_OPEN,str,O_RDWR); ! 160: return(0); } ! 161: length=filelength(i); ! 162: for(i=0;i<j;i++) { /* skip two lines for each entry */ ! 163: fgets(tmp,81,stream); ! 164: fgets(tmp,81,stream); } ! 165: l=ftell(stream); ! 166: if((buf=(char *)malloc(length-l))==NULL) { ! 167: fclose(stream); ! 168: errormsg(WHERE,ERR_ALLOC,str,length-l); ! 169: return(0); } ! 170: fread(buf,1,length-l,stream); ! 171: fseek(stream,l,SEEK_SET); /* go back to where we need to insert */ ! 172: fputs(addpath,stream); ! 173: fputs(addstr,stream); ! 174: fwrite(buf,1,length-l,stream); ! 175: fclose(stream); ! 176: free(buf); ! 177: continue; } ! 178: if(i=='R' || i=='E') { /* Remove or Edit text file */ ! 179: ch=(char)i; ! 180: if(ch=='R') ! 181: bputs(text[RemoveWhichTextFile]); ! 182: else ! 183: bputs(text[EditWhichTextFile]); ! 184: i=getnum(j); ! 185: if(i<1) ! 186: continue; ! 187: sprintf(str,"%stext/%s.ixt" ! 188: ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code); ! 189: j=i-1; ! 190: if((stream=fnopen(NULL,str,O_RDONLY))==NULL) { ! 191: errormsg(WHERE,ERR_OPEN,str,O_RDONLY); ! 192: return(0); } ! 193: for(i=0;i<j;i++) { /* skip two lines for each entry */ ! 194: fgets(tmp,81,stream); ! 195: fgets(tmp,81,stream); } ! 196: fgets(addpath,81,stream); ! 197: truncsp(addpath); ! 198: fclose(stream); ! 199: if(!strchr(addpath,'\\') && !strchr(addpath,'/')) ! 200: sprintf(tmp,"%stext/%s/%s" ! 201: ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code,addpath); ! 202: else ! 203: strcpy(tmp,addpath); ! 204: if(ch=='R') { /* Remove */ ! 205: if(fexist(tmp)) { ! 206: sprintf(str,text[DeleteTextFileQ],tmp); ! 207: if(!noyes(str)) ! 208: if(remove(tmp)) errormsg(WHERE,ERR_REMOVE,tmp,0); } ! 209: sprintf(str,"%stext/%s.ixt" ! 210: ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code); ! 211: removeline(str,addpath,2,0); } ! 212: else { /* Edit */ ! 213: strcpy(str,tmp); ! 214: editfile(str); } ! 215: continue; } ! 216: i=(i&~0x80000000L)-1; ! 217: if(!strchr(file[i],'\\') && !strchr(file[i],'/')) ! 218: sprintf(str,"%stext/%s/%s" ! 219: ,cfg.data_dir,cfg.txtsec[usrsec[cursec]]->code,file[i]); ! 220: else ! 221: strcpy(str,file[i]); ! 222: attr(LIGHTGRAY); ! 223: printfile(str,0); ! 224: sprintf(str,"%s read text file: %s" ! 225: ,useron.alias,file[i]); ! 226: logline("T-",str); ! 227: pause(); ! 228: sys_status&=~SS_ABORT; ! 229: for(i=0;i<j;i++) ! 230: free(file[i]); } } ! 231: return(0); ! 232: } ! 233:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.