Annotation of sbbs/sbbs2/text_sec.c, revision 1.1

1.1     ! root        1: #line 1 "TEXT_SEC.C"
        !             2: 
        !             3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
        !             4: 
        !             5: #include "sbbs.h"
        !             6: 
        !             7: #define MAX_TXTSECS    500 /* Maximum number of text file sections     */
        !             8: #define MAX_TXTFILES    500 /* Maximum number of text files per section */
        !             9: 
        !            10: /****************************************************************************/
        !            11: /* General Text File Section.                                               */
        !            12: /* Called from function main_sec                                            */
        !            13: /* Returns 1 if no text sections available, 0 otherwise.                    */
        !            14: /****************************************************************************/
        !            15: char text_sec()
        !            16: {
        !            17:        char    str[256],usrsec[MAX_TXTSECS],usrsecs,cursec,usemenu
        !            18:                        ,*file[MAX_TXTFILES],addpath[83],addstr[83],*buf,ch;
        !            19:        long    i,j;
        !            20:     long    l,length;
        !            21:     FILE    *stream;
        !            22: 
        !            23: // ch=getage(useron.birth); Removed 05/19/96
        !            24: for(i=j=0;i<total_txtsecs;i++) {
        !            25:     if(!chk_ar(txtsec[i]->ar,useron))
        !            26:         continue;
        !            27:     usrsec[j++]=i; }
        !            28: usrsecs=j;
        !            29: if(!usrsecs) {
        !            30:     bputs(text[NoTextSections]);
        !            31:     return(1); }
        !            32: action=NODE_RTXT;
        !            33: while(online) {
        !            34:        sprintf(str,"%sMENU\\TEXT_SEC.*",text_dir);
        !            35:     if(fexist(str))
        !            36:         menu("TEXT_SEC");
        !            37:     else {
        !            38:         bputs(text[TextSectionLstHdr]);
        !            39:         for(i=0;i<usrsecs && !msgabort();i++) {
        !            40:             sprintf(str,text[TextSectionLstFmt],i+1,txtsec[usrsec[i]]->name);
        !            41:             if(i<9) outchar(SP);
        !            42:             bputs(str); } }
        !            43:     ASYNC;
        !            44:     mnemonics(text[WhichTextSection]);
        !            45:     if((cursec=getnum(usrsecs))<1)
        !            46:         break;
        !            47:     cursec--;
        !            48:     while(online) {
        !            49:                sprintf(str,"%sMENU\\TEXT%u.*",text_dir,cursec+1);
        !            50:         if(fexist(str)) {
        !            51:             sprintf(str,"TEXT%u",cursec+1);
        !            52:             menu(str);
        !            53:             usemenu=1; }
        !            54:         else {
        !            55:             bprintf(text[TextFilesLstHdr],txtsec[usrsec[cursec]]->name);
        !            56:             usemenu=0; }
        !            57:         sprintf(str,"%sTEXT\\%s.IXT",data_dir,txtsec[usrsec[cursec]]->code);
        !            58:         j=0;
        !            59:         if(fexist(str)) {
        !            60:                        if((stream=fnopen((int *)&i,str,O_RDONLY))==NULL) {
        !            61:                 errormsg(WHERE,ERR_OPEN,str,O_RDONLY);
        !            62:                 return(0); }
        !            63:             while(!ferror(stream) && !msgabort()) {  /* file open too long */
        !            64:                 if(!fgets(str,81,stream))
        !            65:                     break;
        !            66:                 str[strlen(str)-2]=0;   /* chop off CRLF */
        !            67:                 if((file[j]=MALLOC(strlen(str)+1))==NULL) {
        !            68:                     errormsg(WHERE,ERR_ALLOC,nulstr,strlen(str)+1);
        !            69:                     continue; }
        !            70:                 strcpy(file[j],str);
        !            71:                 fgets(str,81,stream);
        !            72:                 if(!usemenu) bprintf(text[TextFilesLstFmt],j+1,str);
        !            73:                 j++; }
        !            74:             fclose(stream); }
        !            75:         ASYNC;
        !            76:         if(SYSOP) {
        !            77:             strcpy(str,"QARE?");
        !            78:             mnemonics(text[WhichTextFileSysop]); }
        !            79:         else {
        !            80:             strcpy(str,"Q?");
        !            81:             mnemonics(text[WhichTextFile]); }
        !            82:         i=getkeys(str,j);
        !            83:                if(!(i&0x80000000L)) {            /* no file number */
        !            84:             for(l=0;l<j;l++)
        !            85:                 FREE(file[l]);
        !            86:             if((i=='E' || i=='R') && !j)
        !            87:                 continue; }
        !            88:         if(i=='Q' || !i)
        !            89:             break;
        !            90:         if(i==-1) {  /* ctrl-c */
        !            91:             for(i=0;i<j;i++)
        !            92:                 FREE(file[i]);
        !            93:             return(0); }
        !            94:         if(i=='?')  /* ? means re-list */
        !            95:             continue;
        !            96:         if(i=='A') {    /* Add text file */
        !            97:             if(j) {
        !            98:                 bputs(text[AddTextFileBeforeWhich]);
        !            99:                 i=getnum(j+1);
        !           100:                 if(i<1)
        !           101:                     continue;
        !           102:                 i--;    /* number of file entries to skip */ }
        !           103:             else
        !           104:                 i=0;
        !           105:             bprintf(text[AddTextFilePath]
        !           106:                 ,data_dir,txtsec[usrsec[cursec]]->code);
        !           107:             if(!getstr(addpath,80,K_UPPER))
        !           108:                 continue;
        !           109:             strcat(addpath,crlf);
        !           110:             bputs(text[AddTextFileDesc]);
        !           111:             if(!getstr(addstr,74,0))
        !           112:                 continue;
        !           113:             strcat(addstr,crlf);
        !           114:             sprintf(str,"%sTEXT\\%s.IXT"
        !           115:                 ,data_dir,txtsec[usrsec[cursec]]->code);
        !           116:             if(i==j) {  /* just add to end */
        !           117:                 if((i=nopen(str,O_WRONLY|O_APPEND|O_CREAT))==-1) {
        !           118:                     errormsg(WHERE,ERR_OPEN,str,O_WRONLY|O_APPEND|O_CREAT);
        !           119:                     return(0); }
        !           120:                 write(i,addpath,strlen(addpath));
        !           121:                 write(i,addstr,strlen(addstr));
        !           122:                 close(i);
        !           123:                 continue; }
        !           124:             j=i; /* inserting in middle of file */
        !           125:                        if((stream=fnopen((int *)&i,str,O_RDWR))==NULL) {
        !           126:                 errormsg(WHERE,ERR_OPEN,str,O_RDWR);
        !           127:                 return(0); }
        !           128:             length=filelength(i);
        !           129:             for(i=0;i<j;i++) {  /* skip two lines for each entry */
        !           130:                 fgets(tmp,81,stream);
        !           131:                 fgets(tmp,81,stream); }
        !           132:             l=ftell(stream);
        !           133:             if((buf=(char *)MALLOC(length-l))==NULL) {
        !           134:                 fclose(stream);
        !           135:                 errormsg(WHERE,ERR_ALLOC,str,length-l);
        !           136:                 return(0); }
        !           137:             fread(buf,1,length-l,stream);
        !           138:             fseek(stream,l,SEEK_SET); /* go back to where we need to insert */
        !           139:             fputs(addpath,stream);
        !           140:             fputs(addstr,stream);
        !           141:             fwrite(buf,1,length-l,stream);
        !           142:             fclose(stream);
        !           143:             FREE(buf);
        !           144:             continue; }
        !           145:         if(i=='R' || i=='E') {   /* Remove or Edit text file */
        !           146:             ch=i;
        !           147:             if(ch=='R')
        !           148:                 bputs(text[RemoveWhichTextFile]);
        !           149:             else
        !           150:                 bputs(text[EditWhichTextFile]);
        !           151:             i=getnum(j);
        !           152:             if(i<1)
        !           153:                 continue;
        !           154:             sprintf(str,"%sTEXT\\%s.IXT"
        !           155:                 ,data_dir,txtsec[usrsec[cursec]]->code);
        !           156:             j=i-1;
        !           157:                        if((stream=fnopen((int *)&i,str,O_RDONLY))==NULL) {
        !           158:                 errormsg(WHERE,ERR_OPEN,str,O_RDONLY);
        !           159:                 return(0); }
        !           160:                        // length=filelength(i); Removed 05/19/96
        !           161:             for(i=0;i<j;i++) {  /* skip two lines for each entry */
        !           162:                 fgets(tmp,81,stream);
        !           163:                 fgets(tmp,81,stream); }
        !           164:             fgets(addpath,81,stream);
        !           165:             truncsp(addpath);
        !           166:             fclose(stream);
        !           167:             if(!strchr(addpath,'\\'))
        !           168:                 sprintf(tmp,"%sTEXT\\%s\\%s"
        !           169:                     ,data_dir,txtsec[usrsec[cursec]]->code,addpath);
        !           170:             else
        !           171:                 strcpy(tmp,addpath);
        !           172:             if(ch=='R') {               /* Remove */
        !           173:                 if(fexist(tmp)) {
        !           174:                     sprintf(str,text[DeleteTextFileQ],tmp);
        !           175:                     if(!noyes(str))
        !           176:                         if(remove(tmp)) errormsg(WHERE,ERR_REMOVE,tmp,0); }
        !           177:                 sprintf(str,"%sTEXT\\%s.IXT"
        !           178:                     ,data_dir,txtsec[usrsec[cursec]]->code);
        !           179:                                removeline(str,addpath,2,0); }
        !           180:             else {                      /* Edit */
        !           181:                 strcpy(str,tmp);
        !           182:                 editfile(str); }
        !           183:             continue; }
        !           184:                i=(i&~0x80000000L)-1;
        !           185:         if(!strchr(file[i],'\\'))
        !           186:             sprintf(str,"%sTEXT\\%s\\%s"
        !           187:                 ,data_dir,txtsec[usrsec[cursec]]->code,file[i]);
        !           188:         else
        !           189:             strcpy(str,file[i]);
        !           190:         attr(LIGHTGRAY);
        !           191:         printfile(str,0);
        !           192:         sprintf(str,"Read Text File: %s",file[i]);
        !           193:         logline("T-",str);
        !           194:         pause();
        !           195:         sys_status&=~SS_ABORT;
        !           196:         for(i=0;i<j;i++)
        !           197:             FREE(file[i]); } }
        !           198: return(0);
        !           199: }
        !           200: 

unix.superglobalmegacorp.com

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