|
|
1.1 ! root 1: # include "runup.h" ! 2: copysource() ! 3: { ! 4: struct bibfile *bibp; ! 5: FILE *indco; ! 6: FILE *indcn; ! 7: FILE *fso; ! 8: FILE *fnew; ! 9: char indln[100], nowopen[100], newver[100], outline[100]; ! 10: int nbyte, off=0; ! 11: long nowpos, copyn(); ! 12: int ind_lg; char ind_nm[100]; long ind_st; ! 13: long indpos =0L, copl=0L, cnpl=0L; ! 14: bibp=bibs; ! 15: if (bibp->bibfno<0) /* no bib files */ ! 16: { ! 17: link("Ind.ic", "XInd.ic"); ! 18: return; ! 19: } ! 20: nowopen[0]=0; ! 21: indco = fopen("Ind.ic", "r"); ! 22: assert(indco!=NULL); ! 23: indcn = fopen("XInd.ic", "w"); ! 24: assert(indcn!=NULL); ! 25: while (fgets(indln, 100, indco)) ! 26: { ! 27: register char *s1, *s2; ! 28: extern long atol(); ! 29: copl += strlen(indln); ! 30: /* sscanf(indln, "%[^:]:%ld,%d", ind_nm, &ind_st, &ind_lg); */ ! 31: /* the previous line has been replaced for efficiency's sake */ ! 32: s1 = ind_nm; s2 = indln; ! 33: while (*s2!=':') *s1++ = *s2++; ! 34: *s1=0; ! 35: ind_st = atol(++s2); ! 36: while (*s2++!=','); ! 37: ind_lg = atoi(s2); ! 38: if (bibp->bibfno>=0) ! 39: switch (bcmp( bibp-> bibfref, bibp-> bibfstrt, ind_nm, ind_st)) ! 40: { ! 41: case '>': break; ! 42: case '=': ! 43: # if D1 ! 44: printf("match %s %ld %d\n",ind_nm,ind_st,ind_lg); ! 45: # endif ! 46: if (chatty) printf("bib%03d\n",bibp->bibfno); ! 47: if (strcmp(bibp->bibfref, nowopen)!=SAME) ! 48: { ! 49: if (nowopen[0]) ! 50: wrapo(fso,fnew, nowopen); ! 51: strcpy (nowopen, bibp->bibfref); ! 52: fso=fopen(nowopen, "r"); ! 53: assert(fso!=NULL); ! 54: sprintf(newver, "%s.x", nowopen); ! 55: fnew = fopen(newver, "w"); ! 56: assert(fnew!=NULL); ! 57: nowpos=0; ! 58: off=0; ! 59: if (verbose) printf("Copying %s got %.1f of %d sec.\n",nowopen,tuse(),tlapse()); ! 60: } ! 61: # if D1 ! 62: printf("copying from %ld to %ld\n", nowpos, bibp->bibfstrt); ! 63: # endif ! 64: nowpos += copyn(fso, fnew, bibp->bibfstrt-nowpos); ! 65: # if D2 ! 66: printf("nowpos now %ld\n",nowpos); ! 67: # endif ! 68: nowpos += skipn(fso, bibp->bibfleng); ! 69: # if D2 ! 70: printf("now pos now %ld\n",nowpos); ! 71: # endif ! 72: nbyte= copyb(fnew, bibp); ! 73: # if D1 ! 74: printf("nbyte %d fleng %d off %d\n",nbyte,bibp->bibfleng, off); ! 75: # endif ! 76: if (nbyte>0) ! 77: sprintf(outline, "%s:%ld,%d\n", ind_nm, ind_st+off, nbyte); ! 78: fputs(outline, indcn); ! 79: cnpl += strlen(outline); ! 80: off += (int)(nbyte-bibp->bibfleng); ! 81: bibp->bibival = indpos; ! 82: ckpos(copl, cnpl); ! 83: # if D1 ! 84: printf("item copied; bibst %ld,%d off now %d\n",bibp->bibfstrt,bibp->bibfleng,off); ! 85: # endif ! 86: bibp++; ! 87: continue; ! 88: case '<': ! 89: fprintf(stderr, "Missing bib%03d ref %s:%ld,%d\n", ! 90: bibp->bibfno, bibp->bibfref, bibp->bibfstrt,bibp->bibfleng); ! 91: bibp++; ! 92: } ! 93: if (off!=0 &&strcmp(lastsl(nowopen), ind_nm)!=SAME) ! 94: { ! 95: # if D1 ! 96: printf("Reset offset since %s not %s\n",nowopen, ind_nm); ! 97: # endif ! 98: off=0; ! 99: } ! 100: sprintf(outline, "%s:%ld,%d\n", ind_nm, ind_st+off, ind_lg); ! 101: fputs(outline, indcn); ! 102: cnpl += strlen(outline); ! 103: ckpos(indpos=copl, cnpl); ! 104: } ! 105: if (nowopen[0]) ! 106: wrapo(fso,fnew, nowopen); ! 107: fclose(indco); fclose(indcn); ! 108: } ! 109: long ! 110: copyn(fo, fn, l) ! 111: FILE *fo, *fn; ! 112: long l; ! 113: { ! 114: int k; long j; ! 115: # if D1 ! 116: printf("copyn %ld bytes\n",l); ! 117: # endif ! 118: j=0; ! 119: while (l--) ! 120: { ! 121: k = getc(fo); ! 122: if (k<0) break; ! 123: j++; ! 124: putc(k,fn); ! 125: } ! 126: # if D2 ! 127: printf("returns %ld bytes\n", j); ! 128: # endif ! 129: return(j); ! 130: } ! 131: skipn(fo, l) ! 132: FILE *fo; ! 133: { ! 134: int lu; ! 135: lu =l; ! 136: # if D1 ! 137: printf("skip %d bytes\n",l); ! 138: # endif ! 139: while (l && getc(fo)>=0) l--; ! 140: # if D2 ! 141: printf("returns %d\n",lu-l); ! 142: # endif ! 143: return(lu-l); ! 144: } ! 145: copyb(fn, bibp) ! 146: FILE *fn; ! 147: struct bibfile *bibp; ! 148: { ! 149: FILE *fb; ! 150: char ln[100]; ! 151: int k, j; ! 152: sprintf(ln, "%s/bib%03d", rundir, bibp->bibfno); ! 153: fb = fopen(ln, "r"); ! 154: fgets (ln, 100, fb); ! 155: j=0; ! 156: while ((k=getc(fb)) >=0) ! 157: { ! 158: j++; ! 159: putc(k, fn); ! 160: } ! 161: fclose(fb); ! 162: return(j); ! 163: } ! 164: wrapo(fso, fnew, nowopen) ! 165: FILE *fso, *fnew; ! 166: char *nowopen; ! 167: { ! 168: copyn(fso, fnew, 9999999L); ! 169: fclose(fso); ! 170: fclose(fnew); ! 171: svmove(nowopen); ! 172: } ! 173: bcmp( bpnm, bpst, nm, st) ! 174: long bpst, st; ! 175: char *bpnm, *nm; ! 176: { ! 177: int i; long l; ! 178: char bn1[100], bn2[100]; ! 179: flcopy(bn1, bpnm); ! 180: flcopy(bn2, nm); ! 181: i = strcmp(bn1, bn2); ! 182: if (i<0) return('<'); ! 183: if (i>0) return('>'); ! 184: l = bpst - st; ! 185: if (l<0) return('<'); ! 186: if (l>0) return('>'); ! 187: return('='); ! 188: } ! 189: ! 190: flcopy(s, t) ! 191: char *s, *t; ! 192: { ! 193: if (t[0]=='/' ) ! 194: strcpy(s,t); ! 195: else ! 196: sprintf(s,"%s/%s", Master,t); ! 197: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.