|
|
1.1 ! root 1: #include "parms.h" ! 2: #include "structs.h" ! 3: ! 4: #ifdef RCSIDENT ! 5: static char rcsid[] = "$Header: pagemove.c,v 1.7.0.2 85/05/20 09:55:01 notes Rel $"; ! 6: #endif RCSIDENT ! 7: ! 8: /* ! 9: * pagemove(io,where,io2,where2,lockflag) ! 10: * ! 11: * Take the text pointed to by the (io,where) pair and stuff ! 12: * it into the (io2) notesfile. Return the address in ! 13: * (where2). ! 14: * ! 15: * Lock the io2 notesfile for the transfer if the lockflag ! 16: * parameter is non-zero. ! 17: * ! 18: * Ray Essick, March 1985 ! 19: */ ! 20: ! 21: pagemove (io, where, io2, where2, lockflag) ! 22: struct io_f *io; ! 23: struct daddr_f *where; ! 24: struct io_f *io2; ! 25: struct daddr_f *where2; ! 26: int lockflag; ! 27: { ! 28: char buf[BUFSIZ]; /* for moving chunks */ ! 29: register int bufchars; /* in buffer */ ! 30: register long moved; /* actually moved */ ! 31: register long total; ! 32: register long need; ! 33: struct daddr_f nwhere; ! 34: ! 35: if (where -> addr == 0 || where -> textlen == 0) ! 36: { /* no text or empty */ ! 37: where2 -> addr = 0; ! 38: where2 -> textlen = 0; ! 39: return; /* cheap move */ ! 40: } ! 41: ! 42: if (lockflag) /* lock if wanted */ ! 43: locknf (io2, TXTLOCK); ! 44: ! 45: /* ! 46: * position the input and output files. ! 47: * we have to grab the free pointer for the output file. ! 48: */ ! 49: x (lseek (io -> fidtxt, where -> addr, 0) != where -> addr, "pagemove: old seek"); ! 50: x (lseek (io2 -> fidtxt, 0L, 0) != 0, "pagemove: io2 seek 0"); ! 51: x (read (io2 -> fidtxt, where2, sizeof *where) != sizeof *where, "pagemove: read free"); ! 52: x (lseek (io2 -> fidtxt, where2 -> addr, 0) != where2 -> addr, "pagemove: new seek"); ! 53: moved = 0; ! 54: total = where -> textlen; /* total to move */ ! 55: bufchars = 0; ! 56: where2 -> textlen = 0; /* start empty */ ! 57: ! 58: while (moved != total) /* more text */ ! 59: { ! 60: need = total - moved; /* how much wanted? */ ! 61: if (need >= BUFSIZ) ! 62: need = BUFSIZ; /* only so many at once */ ! 63: bufchars = read (io -> fidtxt, buf, ((int) need));/* read them */ ! 64: x (bufchars != need, "pagemove: bad read from old");/* check */ ! 65: x (write (io2 -> fidtxt, buf, bufchars) != bufchars, "pagemove: bad write to new"); ! 66: moved += bufchars; /* bump counts */ ! 67: where2 -> textlen += bufchars; ! 68: } ! 69: x (where -> textlen != where2 -> textlen, "pagemove: moved wrong count"); ! 70: /* ! 71: * we now have shoved the text into the second notesfile. ! 72: * We need to go back and update the free pointer. ! 73: * and then we can return... ! 74: */ ! 75: nwhere.textlen = 0; ! 76: nwhere.addr = where2 -> addr + where2 -> textlen; ! 77: if (nwhere.addr & 1) /* odd? */ ! 78: nwhere.addr++; /* round up */ ! 79: x (lseek (io2 -> fidtxt, 0L, 0) != 0, "pagemove: bad reseek"); ! 80: x (write (io2 -> fidtxt, &nwhere, sizeof nwhere) != sizeof nwhere, "pagemove: bad write free pointer"); ! 81: ! 82: if (lockflag) /* cleanup */ ! 83: unlocknf (io2, TXTLOCK); ! 84: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.