Annotation of sbbs/src/sbbs3/text_sec.cpp, revision 1.1.1.2

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

unix.superglobalmegacorp.com

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