-
- if(ibuf[i] == '\n') { /* end of line */
- /*sprintf(sizebuf,"%4.4d",i+4); /* make length string */
- /*strncpy(obuf,sizebuf,4); /* put in length field */
- obuf[0] = ((i+4)/1000) + '0';
- obuf[1] = (((i+4)/100)%10) + '0';
- obuf[2] = (((i+4)/10)%10) + '0';
- obuf[3] = (((i+4)/1)%10) + '0';
- obuf += (4+i); /* size + strlen */
- ibuf += (1+i); /* newline + strlen */
- i=0;
+ } else {
+ fflush(stdout);
+ while(1) {
+ /* writing an 'F' format tape */
+ got = read(file,ibuf,recsize+1);
+ if(got == 0) {
+ /* end of input */
+ if(obuf<=obufstart) {
+ break; /* done */
+ } else {
+ /* no more data, so force the record out */
+ recsize = blocksize+1;
+ }
+ } else if(got != recsize+1) {
+ printf("short read: filled\n");
+ } else if( *(ibuf+recsize) != '\n') {
+ printf("corrupted record - write aborted\b");
+ rewind(tape);
+ exit(1);
+ }
+ if(obuf+recsize >endobuf) {
+ /*would overflow output buffer, so fill up old buffer */
+ for(j=obuf;j<endobuf;j++) {
+ *j = '^';
+ }
+ /* and write it */
+ success = write(tape,obufstart,blocksize);
+ if(success != blocksize) {
+ perror("tape");
+ fprintf(stderr," hard write error: write aborted\n");
+ rewind(tape);
+ exit(1);
+ }
+ obuf=obufstart;
+ numblock++;
+ }
+ bcopy(ibuf,obuf,recsize);
+ obuf+=got-1;