1: #ifndef lint
   2: static char *sccsid = "@(#)refer7.c	4.3 (Berkeley) 4/23/86";
   3: #endif
   4: 
   5: #include "refer..c"
   6: 
   7: int newr[250];
   8: 
   9: chkdup(tag)
  10: char *tag;
  11: {
  12:     int i;
  13: 
  14:     for(i = 1; i <= refnum; i++) {
  15:         if (strcmp(reftable[i], tag)==0)
  16:             return(i);
  17:     }
  18:     reftable[refnum+1] = rtp;
  19:     if (refnum >= NRFTBL)
  20:         err("too many references (%d) for table", refnum);
  21:     strcpy(rtp, tag);
  22:     while (*rtp++);
  23:     if (rtp > reftext + NRFTXT)
  24:         err("reference pointers too long (%d)", rtp-reftext);
  25:     return(0);
  26: }
  27: 
  28: dumpold()
  29: {
  30:     FILE *fi;
  31:     int c, g1 = 0, nr = 1;
  32: 
  33:     if (!endpush)
  34:         return;
  35:     fclose(fo);
  36:     fo = NULL;
  37:     if (sort) {
  38:         char comm[100];
  39:         sprintf(comm, "sort -f %s -o %s", tfile, tfile);
  40:         system(comm);
  41:     }
  42:     fi = fopen(tfile, "r");
  43:     if (fi == NULL)
  44:         return;
  45:     flout();
  46:     fprintf(ftemp, ".]<\n");
  47:     while ((c = getc(fi)) > 0) {
  48:         if (c == '\n') {
  49:             nr++;
  50:             g1 = 0;
  51:         }
  52:         if (c == sep)
  53:             c = '\n';
  54:         if (c == FLAG) {
  55:             /* make old-new ref number table */
  56:             char tb[20];
  57:             char *s = tb;
  58:             while ((c = getc(fi)) != FLAG)
  59:                 *s++ = c;
  60:             *s = 0;
  61:             if (g1++ == 0)
  62:                 newr[atoi(tb)] = nr;
  63: #if EBUG
  64:             fprintf(stderr,
  65:                 "nr %d assigned to atoi(tb) %d\n",nr,atoi(tb));
  66: # endif
  67:             fprintf(ftemp,"%d", nr);
  68:             continue;
  69:         }
  70:         putc(c, ftemp);
  71:     }
  72:     fclose(fi);
  73: #ifndef TF
  74:     unlink(tfile);
  75: #endif
  76:     fprintf(ftemp, ".]>\n");
  77: }
  78: 
  79: recopy (fnam)
  80: char *fnam;
  81: {
  82:     int c;
  83:     int *wref = NULL;
  84:     int wcnt = 0;
  85:     int wsize = 50;
  86:     int finalrn;
  87:     char sig[MXSIG];
  88:     extern int *realloc();
  89: 
  90:     wref = (int *)calloc((unsigned)wsize, (unsigned)sizeof(int));
  91:     fclose(ftemp);
  92:     ftemp = fopen(fnam, "r");
  93:     if (ftemp == NULL) {
  94:         fprintf(stderr, "Can't reopen %s\n", fnam);
  95:         exit(1);
  96:     }
  97:     while ((c = getc(ftemp)) != EOF) {
  98:         if (c == FLAG) {
  99:             char tb[10];
 100:             char *s = tb;
 101:             while ((c = getc(ftemp)) != FLAG)
 102:                 *s++ = c;
 103:             *s = 0;
 104:             /*
 105: 			 * If sort was done, permute the reference number
 106: 			 * to obtain the final reference number, finalrn.
 107: 			 */
 108:             if (sort)
 109:                 finalrn = newr[atoi(tb)];
 110:             else
 111:                 finalrn = atoi(tb);
 112:             if ((++wcnt > wsize) &&
 113:              ((wref=realloc(wref,(wsize+=50)*sizeof(int)))==NULL)){
 114:                 fprintf(stderr, "Ref condense out of memory.");
 115:                 exit(1);
 116:             }
 117:             wref[wcnt-1] = finalrn;
 118:             if ((c = getc(ftemp)) == AFLAG)
 119:                 continue;
 120:             wref[wcnt] = 0;
 121:             condense(wref,wcnt,sig);
 122:             wcnt = 0;
 123:             printf("%s", sig);
 124:         }
 125:         putchar(c);
 126:     }
 127:     fclose(ftemp);
 128:     unlink(fnam);
 129: }
 130: 
 131: /*
 132:  * sort and condense referance signals when they are placed in
 133:  * the text. Viz, the signal 1,2,3,4 is condensed to 1-4 and signals
 134:  * of the form 5,2,9 are converted to 2,5,9
 135:  */
 136: condense(wref, wcnt, sig)
 137: int *wref;
 138: int wcnt;
 139: char    *sig;
 140: {
 141:     register int i = 0;
 142:     char wt[4];
 143:     extern int wswap();
 144: 
 145:     qsort(wref, wcnt, sizeof(int), wswap);
 146:     sig[0] = 0;
 147:     while (i < wcnt) {
 148:         sprintf(wt,"%d",wref[i]);
 149:         strcat(sig,wt);
 150:         if ((i+2 < wcnt) && (wref[i] == (wref[i+2] - 2))) {
 151:             while (wref[i] == (wref[i+1] - 1))
 152:                 i++;
 153:             strcat(sig, "-");
 154:         } else if (++i < wcnt)
 155:             strcat(sig,",\\|");
 156:     }
 157: }
 158: 
 159: wswap(iw1, iw2)
 160: register int *iw1,*iw2;
 161: {
 162:     return(*iw1 - *iw2);
 163: }

Defined functions

chkdup defined in line 9; used 1 times
condense defined in line 136; used 1 times
dumpold defined in line 28; used 2 times
recopy defined in line 79; used 2 times
wswap defined in line 159; used 2 times

Defined variables

newr defined in line 7; used 2 times
sccsid defined in line 2; never used
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 408
Valid CSS Valid XHTML 1.0 Strict