Annotation of researchv10no/cmd/refer/refer7.c, revision 1.1.1.1

1.1       root        1: # include "refer..c"
                      2: # define NRS 500
                      3: int newr[NRS];
                      4: chkdup ( tag )
                      5:        char *tag;
                      6: {
                      7: int i;
                      8: for(i=1; i<=refnum; i++)
                      9:        {
                     10:        if (strcmp(reftable[i], tag)==0)
                     11:                return(i);
                     12:        }
                     13: reftable[refnum+1] = rtp;
                     14: if (refnum>=NRFTBL)
                     15:        err("too many references (%d) for table", refnum);
                     16: strcpy (rtp, tag);
                     17: while (*rtp++);
                     18: if (rtp > reftext + NRFTXT)
                     19:        err("reftext too big (%d)", rtp-reftext);
                     20: return(0);
                     21: }
                     22: dumpold()
                     23: {
                     24: FILE *fi;
                     25: int c, oc, g1 = 0, nr = 1;
                     26: if (!endpush) return;
                     27: fclose(fo);
                     28: # ifdef D1
                     29: fprintf(stderr, "closing %o\n",fo);
                     30: # endif
                     31: fo=NULL;
                     32: # if D1
                     33: fprintf(stderr, "dumpold for %s ftemp is %o stdout %o\n", tfile, ftemp, stdout);
                     34: # endif
                     35: if (sort)
                     36:        {
                     37:        char comm[100];
                     38:        lim512(tfile);
                     39:        sprintf(comm, "sort -fd %s -o %s", tfile, tfile);
                     40:        system(comm);
                     41:        }
                     42: fi = fopen(tfile, "r");
                     43: # if D1
                     44: fprintf(stderr, "reopened %s as %o\n",tfile,fi);
                     45: # endif
                     46: if (fi==NULL) return;
                     47: flout();
                     48: fprintf(ftemp,".]<\n");
                     49: while ( (c = getc(fi)) >=0)
                     50:        {
                     51:        if (c=='\n')
                     52:                {
                     53:                if (oc==sep) continue;
                     54:                nr++;
                     55:                g1 = 0;
                     56:                }
                     57:        oc=c;
                     58:        if (c==sep)
                     59:                c = '\n';
                     60:        if (c== FLAG)
                     61:                {
                     62:                /* make old-new ref number table */
                     63:                char tb[20];
                     64:                int irr;
                     65:                char *s = tb;
                     66:                while ( (c=getc(fi)) != FLAG)
                     67:                        *s++ = c;
                     68:                *s=0;
                     69:                if (g1++ == 0)
                     70:                        {
                     71:                        irr = atoi(tb);
                     72:                        if (irr>=NRS)
                     73:                                err("too many references to renumber",0);
                     74:                        newr[irr]=nr;
                     75:                        }
                     76: # if D1
                     77:                fprintf(stderr, "nr %d assigned to atoi(tb) %d\n",nr,irr);
                     78: # endif
                     79:                if (!labels)
                     80:                        fprintf(ftemp,"%d", nr);
                     81:                else
                     82:                        expkey (irr, nr, ftemp);
                     83:                continue;
                     84:                }
                     85:        putc(c, ftemp);
                     86:        }
                     87: fclose(fi);
                     88: # ifndef D1
                     89: unlink(tfile);
                     90: # endif
                     91: widelab();
                     92: fprintf(ftemp, ".]>\n");
                     93: }
                     94: 
                     95: recopy (fnam)
                     96:        char *fnam;
                     97: {
                     98: int c;
                     99: fclose(ftemp);
                    100: # if D1
                    101: fprintf(stderr, "recopy, fnam %s\n",fnam);
                    102: # endif
                    103: 
                    104: ftemp = fopen(fnam, "r");
                    105: if (ftemp==NULL)
                    106:        {
                    107:        fprintf(stderr, "Can't reopen %s\n", fnam);
                    108:        exit(1);
                    109:        }
                    110: # if D1
                    111: fprintf(stderr, "open ok ftemp %o\n",ftemp);
                    112: # endif
                    113: while ( 1)
                    114:        {
                    115:        c = fgetc(ftemp);
                    116: # if D1
                    117: fprintf(stderr, "read char %o /%c/\n",c,c);
                    118: # endif
                    119:        if (c == FLAG)
                    120:                {
                    121:                char tb[10];
                    122:                char *s = tb;
                    123:                int tbx;
                    124:                while ( (c = getc(ftemp)) != FLAG && c != EOF)
                    125:                        *s++ = c;
                    126:                *s=0;
                    127:                tbx = atoi(tb);
                    128: # if D1
                    129:                fprintf(stderr, "prelim number is %d\n",tbx);
                    130: # endif
                    131:                if (!labels)
                    132:                        printf("%d", newr[tbx]);
                    133:                else
                    134:                        expkey (tbx, newr[tbx], stdout);
                    135:                continue;
                    136:                }
                    137:        if (c==EOF) break;
                    138:        putchar(c);
                    139:        }
                    140: # if D1
                    141: fprintf(stderr, "finished reading file \n");
                    142: # endif
                    143: fclose(ftemp);
                    144: unlink(fnam);
                    145: # if D1
                    146: fprintf(stderr, "leaving recopy\n");
                    147: # endif
                    148: }
                    149: lim512(tfile)
                    150:        char *tfile;
                    151: {
                    152: /* this stupid program merely breaks up very long citations
                    153: into lines of 512 bytes */
                    154: FILE *f1, *f2;
                    155: char *zline, *p, *q;
                    156: extern char one[];
                    157: int ln, no;
                    158: zline=one;
                    159: f1 = fopen(tfile, "r");
                    160: f2 = fopen(tdfile, "w");
                    161: # ifdef D1
                    162: fprintf(stderr,"in lim512 %s is %o, %s is %o\n", tfile, f1, tdfile, f2);
                    163: # endif
                    164: while (fgets(zline, ANSLEN, f1))
                    165:        {
                    166:        if (strlen(zline)<512)
                    167:                {
                    168:                fputs(zline, f2);
                    169:                continue;
                    170:                }
                    171:        no='a';
                    172:        for(p=zline; *p!=sep; p++)
                    173:                ;
                    174:        *p++ = 0;
                    175:        ln = 500 - strlen(zline);
                    176:        while (strlen(p)>ln)
                    177:                {
                    178:                for(q=p+ln; q>p && *q!=sep; q--)
                    179:                        ;
                    180:                *q++ = 0;
                    181:                fprintf(f2, "%s%c%c%s%c\n",zline,no++,sep,p,sep);
                    182:                p=q;
                    183:                }
                    184:        fprintf(f2, "%s%c%c%s", zline, no, sep, p);
                    185:        }
                    186: fclose(f1); fclose(f2);
                    187: # ifdef D1
                    188: fprintf(stderr, "unlinking in lim512\n");
                    189: # endif
                    190: unlink(tfile); link(tdfile, tfile); unlink(tdfile);
                    191: }

unix.superglobalmegacorp.com

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