Annotation of sbbs/sbbs2/echo/docs/man.c, revision 1.1.1.1

1.1       root        1: /* MAN.C */
                      2: 
                      3: /* Synchronet docs convert to paged format for printing */
                      4: 
                      5: #include <stdio.h>
                      6: #include <string.h>
                      7: #include <stdlib.h>
                      8: #include <dos.h>
                      9: #include <io.h>
                     10: #include <alloc.h>
                     11: 
                     12: /****************************************************************************/
                     13: /* Truncates white-space chars off end of 'str' and terminates at first tab */
                     14: /****************************************************************************/
                     15: void truncsp(char *str)
                     16: {
                     17:        char c;
                     18: 
                     19: str[strcspn(str,"\t")]=0;
                     20: c=strlen(str);
                     21: while(c && (unsigned char)str[c-1]<=32) c--;
                     22: str[c]=0;
                     23: }
                     24: 
                     25: int main(int argc, char **argv)
                     26: {
                     27:        char str[256],str2[256],infile[128],outfile[128],idxfile[128]
                     28:                ,*invbuf,*outvbuf,*idxvbuf,*tempvbuf,*p,*p2
                     29:                ,chap[128]="SBBSecho"
                     30:                ,pagetag[250][9]
                     31:                ,idxtag[512][9];
                     32:        int i,j,page=1,line=0,pagetags=0,idxtags=0;
                     33:        long pageidx[250],idx[512],l;
                     34:        FILE *in, *out, *index, *tempfile;
                     35: 
                     36: if(argc<3) {
                     37:        printf("usage: man infile outfile indexfile\r\n");
                     38:        exit(1); }
                     39: 
                     40: strcpy(infile,argv[1]);
                     41: strcpy(outfile,argv[2]);
                     42: strcpy(idxfile,argv[3]);
                     43: 
                     44: if((in=fopen(infile,"rb"))==NULL) {
                     45:        printf("error opening %s\r\n",infile);
                     46:        exit(1); }
                     47: 
                     48: if((out=fopen(outfile,"wb"))==NULL) {
                     49:        printf("error opening %s\r\n",outfile);
                     50:     exit(1); }
                     51: 
                     52: //if((index=fopen(idxfile,"rb"))==NULL) {
                     53: //       printf("error opening %s\r\n",idxfile);
                     54: //       exit(1); }
                     55: 
                     56: //if((tempfile=fopen("TEMPFILE","w+b"))==NULL) {
                     57: //       printf("error opening TEMPFILE\r\n");
                     58: //       exit(1); }
                     59: 
                     60: if((invbuf=(char *)malloc(8*1024))==NULL) {
                     61:        printf("error allocating input buffer\n");
                     62:        exit(1); }
                     63: 
                     64: if((outvbuf=(char *)malloc(8*1024))==NULL) {
                     65:        printf("error allocating output buffer\n");
                     66:     exit(1); }
                     67: 
                     68: //if((idxvbuf=(char *)malloc(8*1024))==NULL) {
                     69: //       printf("error allocating index buffer\n");
                     70: //       exit(1); }
                     71: 
                     72: //if((tempvbuf=(char *)malloc(8*1024))==NULL) {
                     73: //       printf("error allocating temp buffer\n");
                     74: //       exit(1); }
                     75: 
                     76: setvbuf(in,invbuf,_IOFBF,8*1024);
                     77: setvbuf(out,outvbuf,_IOFBF,8*1024);
                     78: //setvbuf(index,idxvbuf,_IOFBF,8*1024);
                     79: //setvbuf(tempfile,tempvbuf,_IOFBF,8*1024);
                     80: 
                     81: //while(!ferror(index) && !feof(index)) {
                     82: //       p=fgets(str,128,index);
                     83: //       fputs(str,tempfile);
                     84: //       while((p2=strstr(str,"@@"))!=NULL) {
                     85: //               p2[0]=32;
                     86: //               p2[1]=32;
                     87: //               sprintf(idxtag[idxtags],"%-.8s",p2+2);
                     88: //               idx[idxtags++]=ftell(index)-strlen(p2); } }
                     89: 
                     90: while(!ferror(in) && !feof(in)) {
                     91:        p=fgets(str,128,in);
                     92:        if(str[0]=='&' && str[1]=='&') {
                     93:                truncsp(str+2);
                     94:                strcpy(chap,str+2);
                     95:                continue; }
                     96:        if(str[0]=='$' && str[1]=='$') {
                     97:                truncsp(str+2);
                     98: 
                     99: //               for(i=0;i<idxtags;i++) {
                    100: //                       if(!stricmp(str+2,idxtag[i])) {
                    101: //                               fseek(tempfile,idx[i],SEEK_SET);
                    102: //                               sprintf(str2,"%-10d",page);
                    103: //                               fprintf(tempfile,"%s",str2); } }
                    104: 
                    105:                for(i=0;i<pagetags;i++)
                    106:                        if(!stricmp(str+2,pagetag[i]))
                    107:                                break;
                    108:                if(i<pagetags) {
                    109:                        l=ftell(out);
                    110:                        fseek(out,pageidx[i]-1,SEEK_SET);
                    111:                        sprintf(str,"%10d",page);
                    112:                        for(i=0;i<10;i++)
                    113:                                if(str[i]==0x20)
                    114:                                        str[i]='.';
                    115:                        fprintf(out,"%s",str);
                    116:                        fseek(out,l,SEEK_SET); }
                    117:                continue; }
                    118: 
                    119:        line++;
                    120:        if(!p)
                    121:                break;
                    122:        if(!p || str[0]==0xc || line==55) {
                    123:                while(line<55) {
                    124:                        fprintf(out,"\r\n");
                    125:                        line++; }
                    126:                line=1;
                    127:                if(page!=1)     /* no tag on page 1 */
                    128:                        fprintf(out,"\r\n___________________________________________"
                    129:                                "____________________________________\r\n"
                    130:                                "%-35s %3u %39s"
                    131:                                ,"SBBSecho",page,chap);
                    132:                fprintf(out,"\r\n\xc\r\n\r\n");
                    133:                page++; }
                    134: 
                    135:        if((p2=strstr(str,"@@"))!=NULL) {
                    136:         sprintf(pagetag[pagetags],"%-.8s",p2+2);
                    137:         pageidx[pagetags++]=ftell(out)+(p2-str)+1; }
                    138: 
                    139:        if(!p)
                    140:                break;
                    141:        if(str[0]!=0xc)
                    142:                fprintf(out,"%s",str);
                    143:        else
                    144:                line=0;
                    145:                }
                    146: 
                    147: //fseek(tempfile,0L,SEEK_SET);
                    148: //while(!ferror(tempfile) && !feof(tempfile)) {
                    149: //       j=0;
                    150: //       p=fgets(str2,128,tempfile);
                    151: //       for(i=0;i<strlen(str2);i++) {
                    152: //               str[j++]=str2[i];
                    153: //               if(str2[i]==',') {
                    154: //                       i++;
                    155: //                       str[j++]=str2[i++];
                    156: //                       while(1) {
                    157: //                               if(str2[i]>32 && isdigit(str2[i]))
                    158: //                                       str[j++]=str2[i++];
                    159: //                               else
                    160: //                                       break; }
                    161: //                       while(str2[i++]==32);
                    162: //                       i-=2; } }
                    163: //       str[j]=0;
                    164: 
                    165: //       line++;
                    166: //       if(!p || str[0]==0xc || line==55) {
                    167: //               while(line<55) {
                    168: //                       fprintf(out,"\r\n");
                    169: //                       line++; }
                    170: //               line=1;
                    171: //               if(page!=1)     /* no tag on page 1 */
                    172: //                       fprintf(out,"\r\n\t___________________________________________"
                    173: //                               "____________________________________\r\n"
                    174: //                               "\t%-35s %3u %39s"
                    175: //                               ,"Synchronet",page,"Index");
                    176: //               fprintf(out,"\r\n\xc\r\n\r\n");
                    177: //               page++; }
                    178: 
                    179: //       if(!p)
                    180: //               break;
                    181: //       if(str[0]!=0xc)
                    182: //               fprintf(out,"\t%s",str);
                    183: //     else
                    184: //               line=0;
                    185: //               }
                    186: return(0);
                    187: }
                    188: 
                    189: 

unix.superglobalmegacorp.com

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