/* Tue Nov 9 09:30:45 EST 1993 /plas5/h1/ksg/src/test bat.c */ /* Wed Apr 24 13:46:39 EDT 1991 /leverrier/h1/ksg/src/test bat.c */ /* Fri Mar 9 13:31:46 EST 1990 /plasma/h1/vgr/src/pls bat */ /* Tuesday Feb. 25, 1992 gsg jr. fixed short ead from disk */ /* indpip & streams mad global so tbatn.c can use them 4 Feb 1994 gsg jr 4 Feb 1994*/ #include #include #include #include #include #include #include #include #define BUFSIZE 32768 #define VBUFSIZE 67000 /* #define RSTBUFSIZE 524288 */ #define RSTBUFSIZE 32768 #define MAXUNITS 99 /* corrected to make stdin keep reading assuming a piped input */ /* Aur 31, 1989 gsg jr. */ /* Thu Oct 20 13:21:53 EDT 1988 8mm tape added */ /* Thur Dec 20, 1990 gsg jr increased number of logical units */ /* Wed Jan 9, 1991, gsg jr uped maxunits to 99, and added tclosebat*/ /* these routines simulate part of bat7 for reading only */ /* they assume that the tape has been copied form tape ot disk using ttof.c */ /* there are no file marks on disk and skipping may take longer than reading */ /* */ /* it is the users responsibility to do any conversion */ /* */ /* treadn twaitn tskipn tnextn have been adden to allow bacwards skipping */ static int nblocks=0; /* nomber of blocks moved */ static int nrecords=0; /* number of records moved */ static int nrecarr[MAXUNITS]={MAXUNITS*0}; static int nblkarr[MAXUNITS]={MAXUNITS*0}; static char tbuf[BUFSIZE]; /* temp buffer to allow skipping */ static int nb1,nb2; /* number of bytes as set at begining and end of record */ static int ncount[MAXUNITS]; /* number of bytes read */ static int lcount[MAXUNITS]; /* number of bytes in vbs record */ static int lres[12][MAXUNITS]; /* logical flags to mark errors etc. */ /* lres meaning a la lns 1 tape mark 2 end of tape 3 perminate error 4 data conversion check (7-track) 5 data check ( validity check error ) 6 equipment check 7 error in opening (e.g. no dd card ) 8... only 1,2,3 implimented here */ static int iunit=32; /* old fortran unit number for bat */ static int junit; /* int file descriptor */ static int junita[MAXUNITS]; /* int file descriptor array*/ static char *unitpt; /* pointer to unit name */ static int rstbufsize=RSTBUFSIZE; static int irw[MAXUNITS]; /* is file read = 1, or write = -1, not opened =0*/ static char *pbufmm[MAXUNITS]; /* pointer to buffer for 8mm drive */ static char *pbufmmd[MAXUNITS]; /* pointer to buffer data for 8mm drive */ static char *pbufmme[MAXUNITS]; /* pointer to buffer end for 8mm drive */ static int pbuf_full[MAXUNITS]; /* number of bytes in 8mm buffer */ static int ieof[MAXUNITS]={MAXUNITS*0}; /* number of reads of physicial eof */ static int lvbs[MAXUNITS]={MAXUNITS*0}; /* 0= do not check for vbs rec, 1= check & unpack vbs rec */ //ccc gsgjr 13_08_14 changing NULL to 0 to satisfy compiler //static char *lbuf[MAXUNITS]={MAXUNITS*NULL}; /* pointer to curren location in vbs buf */ //static char *vbuf[MAXUNITS]={MAXUNITS*NULL}; /* pointer to buffers for vbs unpacking */ //static char *evbuf[MAXUNITS]={MAXUNITS*NULL}; /* pointer to end of buffers for vbs unpacking */ static char *lbuf[MAXUNITS]={MAXUNITS*0}; /* pointer to curren location in vbs buf */ static char *vbuf[MAXUNITS]={MAXUNITS*0}; /* pointer to buffers for vbs unpacking */ static char *evbuf[MAXUNITS]={MAXUNITS*0}; /* pointer to end of buffers for vbs unpacking */ static int zero=0,one=1,two=2,fill=0xffffffff; /* litteral '0' & '1' & '2' */ static char filenam[MAXUNITS][64]; /* stored filename */ /* #static int indpip[MAXUNITS]; /* index on filenam for '|' */ /* #static FILE *stream[MAXUNITS]; /* pointer to stream */ int indpip[MAXUNITS]; /* index on filenam for '|' */ FILE *stream[MAXUNITS]; /* pointer to stream */ static int *ip; static char *st; static char readtype[]="r"; static char writetype[]="w"; /* one used for normal, two used for concatinate files */ static int iaerr; /* counter for error flags */ static int ir; /* number of files in dataset */ static int ltape; /* type of data file, 0 disk, 1 1/2" tape, 2 8mm tape, 3 8mm tape literal */ /* * * warning 8mm scsi buffer overflow not hanleled correctly * */ static int vbufs=VBUFSIZE; /* vbs buffer size */ /* if ltape > 0 file is referencing a tape */ static struct bdw { short int bkn; short int dum; } bkds,*pbkds; static struct sdw { short int sgn; short int i_dum :6; short int i_pre :1; short int i_flo :1; short int i_res :8; } sgds,*psgds; /* the following tables are for the buffered read and maybe later for buffered writes */ /* files for select */ /* #static struct timeval timeout={1,0}; #static int select_width=1; #static int readfld=1; #static int writefld=0; #static int execfld=0; #static int readfld0=1; #static int writefld0=0; #static int execfld0=0; #static struct timeval timeout={1,0}; */ static int select_width=1; /* #Need to be initialized before use */ static fd_set readfld; static fd_set writefld; static fd_set execfld; static int readfld0=1; static int writefld0=0; static int execfld0=0; static struct timeval timeout={1,0}; /*should come from header files */ //extern int select( ); batvbs_( unit, ivbs, il) /* allow or disallow vbs unpacking */ char *unit; /* unit name */ int *ivbs; /* flag 0 for no unpacking, 1 to unpack */ int il; /* length of unit */ { unitpt = unit; printf(" 1 call to getunit "); (void) getunit_( unit, &iunit, &junit, &iaerr, &ir, &one, stream, indpip, <ape, 4); /* get unit numbers */ (void) batvbsi_( &iaerr, ivbs); batclear_( unit); /* clear unit if we change to or from vbs */ } batvbsi_( iaerri, ivbs) int *iaerri, *ivbs; { lvbs[*iaerri] = *ivbs; sgds.i_flo = 1; } batclear_( unit ) /* force next read to be a block if vbs */ char *unit; /* unit name */ { unitpt = unit; printf(" 2 call to getunit "); (void) getunit_( unit, &iunit, &junit, &iaerr, &ir, &one, stream, indpip, <ape, 4); /* get unit numbers */ evbuf[iaerr] = vbuf[iaerr]; /* simulate end of block */ } treadbat_( unit, buffer, rcount, il) /* no backwards motion allowed */ /* just a line filler */ char *unit; /* name of tape*/ char *buffer; /* buffer into which data is to be read */ int *rcount; /* number of bytes to be read, have been read */ int il; /* length count for unit */ { int i; /* dummy variable */ //char *malloc(); nrecords += 1; /*fprintf(stderr," JWB I am in treadbat unit follows %d \n",unit); */ unitpt = unit; /*printf(" 3 call to getunit ");*/ (void) getunit_( unit, &iunit, &junit, &iaerr, &ir, &one, stream, indpip, <ape, 4); /* get unit numbers */ irw[iaerr] = 1; nrecarr[iaerr] += 1; if ( lvbs[iaerr] == 0 ) { treadbat( buffer, rcount); /* no backwars motion allowed */ return; } else if ( lvbs[iaerr] == 1 ) { psgds = ( struct sdw * ) &fill; lcount[iaerr] = 0; /* no data yet */ while ( psgds->i_flo != 0 ) { if (evbuf[iaerr] <= lbuf[iaerr]) { /* no data left over */ if ( vbuf[iaerr] == NULL ) /* no buffer allocated */ { evbuf[iaerr] = vbuf[iaerr] = lbuf[iaerr] = malloc( vbufs); if ( vbuf[iaerr] == NULL) { fprintf(stderr," unable to allocate buffer space in bat"); //ccc gsgjr added argument to exit exit( 0); } } treadbat( vbuf[iaerr], &vbufs); /* get next block */ if ( ieof[iaerr] > 0) { /* error leave this record */ lcount[iaerr] = ncount[iaerr] = 0; if ( ieof[iaerr] == 1 && lres[2][iaerr] == 1 ) { /* on error try next record just once */ treadbat( vbuf[iaerr], &vbufs); /* get next block */ if ( ieof[iaerr] > 0) return; } } pbkds = (struct bdw *) vbuf[iaerr]; if ( pbkds->dum == 0 && pbkds->bkn == ncount[iaerr] && ncount[iaerr] > 0 ) { /* we have a vbs record */ lbuf[iaerr] = vbuf[iaerr] + 4; evbuf[iaerr] = vbuf[iaerr] + ncount[iaerr]; } else { /* no vbs just copy and return */ lbuf[iaerr] = vbuf[iaerr]; /* reset pointer for logical buffer */ for ( i=0; i < ncount[iaerr] ; i++) *buffer++ = *lbuf[iaerr]++ ; return; } } /* now to unpack next segment */ psgds = ( struct sdw * ) lbuf[iaerr]; lbuf[iaerr] += 4; lcount[iaerr] += psgds->sgn - 4 ; for ( i=4; i < psgds->sgn ; i++) *buffer++ = *lbuf[iaerr]++; if ( psgds->i_flo == 0 ) { ncount[iaerr] = lcount[iaerr]; lcount[iaerr] = 0; return; } } } else if ( lvbs[iaerr] == 2 ) { i = batread( junit, buffer, *rcount); if ( i == EOF || i == 0 ) { lres[0][iaerr] = 1; ieof[iaerr] += 1; ncount[iaerr] = 0; } else { lres[0][iaerr] = 0; ieof[iaerr] = 0; ncount[iaerr] = i; } return; } else { fprintf( stderr,"lvbs of %d not supported on iaerr %d\n", lvbs[iaerr], iaerr); (void) exit( 9); } } treadbat( buffer, rcount) /* no backwards motion allowed */ char *buffer[]; /* buffer into which data is to be read */ int *rcount; /* number of bytes to be read, have been read */ { int i,j,k; /* temp int */ char *ttbuf; nblocks += 1; /* incrment block counter */ nblkarr[iaerr] += 1; for ( i=0; i < 12; i++) lres[i][iaerr]=0; /* clear error flags */ if ((ltape == 0) || (ltape == 2)) { /* disk file */ /* 8mm tape */ nb1 = 0; i = batread( junit, &nb1, 4); /* read in byte count */ if ( i == EOF || i == 0 ) goto eof; j = ( nb1 < *rcount) ? nb1 : *rcount; /* get smaller */ i = 0; if (j > 0) { i = batread( junit, buffer, j); /* read in record */ if ( i == EOF || i == 0 ) goto eof; nb2 = 0; if ( i != j ) goto err; } else { for ( k=0 ; k<8; k++ ) *buffer++ = 0; /* put zero into buffer */ if ( nb1 <= 0) { i = nb1; lres[0][iaerr] = 1; } } ncount[iaerr] = i; /* record number of bytes read */ if ( j < nb1) i = skips( nb1-j); /* skip rest of record */ i = batread( junit, &nb2, 4); /* read in trailing byte count */ if ( i == EOF || i == 0 ) goto eof; if ( nb1 != nb2) goto err; if (ncount[iaerr] <= 0) lres[0][iaerr] = 1; } else if (ltape == 1 || ltape == 3 ) { /* 1/2"" tape file */ /* 8mm tape literal */ i = EOF; j = *rcount; i = read( junit, buffer, j); ncount[iaerr] = i; /* record nomber of bytes read */ if (i == EOF || i == 0) goto eof; } if ( ncount[iaerr] == 0) lres[0][iaerr] = 1; ieof[iaerr] = 0; return; eof:; lres[0][iaerr] = 1; /* set EOF flag */ ieof[iaerr] = ieof[iaerr]+1; ncount[iaerr] = 0; vbuf[iaerr] = evbuf[iaerr]; if (ieof[iaerr] < 4) return; fprintf(stderr," eof of data over read %d times\n",ieof[iaerr]); lres[0][iaerr] = 1; /* set EOF flag */ lres[1][iaerr] = 1; lres[2][iaerr] = 1; ieof[iaerr] = ieof[iaerr]+1; //ccc gsgjr added argument to exit if (ieof[iaerr] >= 9) exit( 1); return; err:; fprintf(stderr," error on reading file %s, nb1 = %d, nb2 = %d, i = %d \n",unitpt, nb1,nb2,i); lres[0][iaerr] = 1; /* set EOF flag */ lres[1][iaerr] = 1; lres[2][iaerr] = 1; ieof[iaerr] = ieof[iaerr]+1; if (ieof[iaerr] >= 3) goto eof ; evbuf[iaerr] = vbuf[iaerr]; /* read next physical record */ return; } skips( rc) /* skip section of record */ int rc; /* number of bytes to be skipped */ { int i,j; for ( i = rc; i > 0; i -= BUFSIZE) { j = (i > BUFSIZE) ? BUFSIZE : i; j = batread( junit, tbuf, j); /* skip next section */ if ( j == EOF) return(j); /* on EOF return EOF */ } return(j); } twait_( unit, rb, il) char *unit; int *rb[]; /* return count & error flags */ int il; { unitpt = unit; /*printf(" 4 call to getunit ");*/ (void) getunit_( unit, &iunit, &junit, &iaerr, &ir, &one, stream, indpip, <ape, 4); (void) twait( rb); } twait( rb) int *rb; /* return count & error flags */ { int *iint; int i; int *lrb; iint = rb; *iint = ncount[iaerr]; lrb = rb + 1; for ( i=0 ; i < 12 ; i++, lrb++) *lrb = lres[i][iaerr]; } tskip_( unit, rewind, marks, blocks) /* rewinds, or skips forward */ char unit[]; int *rewind; /* rewind file if != 0 */ int *marks; /* error != 0 number of tape marks to skip */ int *blocks; /* number of blocks to skip */ { unitpt = unit; printf(" 5 call to getunit "); (void) getunit_( unit, &iunit, &junit, &iaerr, &ir, &one, stream, indpip, <ape, 4); (void) tskip( unit, rewind, marks, blocks); /* rewinds, or skips forward */ } tskip( unit, rewind, marks, blocks) /* rewinds, or skips forward */ char unit[]; int *rewind; /* rewind file if != 0 */ int *marks; /* error != 0 number of tape marks to skip */ int *blocks; /* number of blocks to skip */ { int i,k; if ( *marks < 0 || *blocks < 0) { fprintf ( stderr,"\n no backward skipping \n"); exit(2); } for ( k=0 ; k < *marks ; k++) { /* skip over marks */ for ( i=1 ; i > 0; ) { if ((ltape == 0) || (ltape == 2)) { /* disk file */ /* 8mm tape */ nb1 = 0; i = batread( junit, &nb1, 4); if ( i == EOF) nb1 = 0 ; i = skips( nb1); if ( i == EOF) nb1 = 0 ; i = batread( junit, &nb2, 4); if ( nb1 != nb2) nb1 = -1; i = nb1; } else if (ltape == 1 || ltape == 3 ) { /* 1/2" tape file */ /* 8mm tape literal */ i = read ( junit, tbuf, 1); } } } i = BUFSIZE; for ( k=0 ; k < *blocks ; k++) { /* read over blocks */ treadbat_( unit, tbuf, &i, 8); } return; } tnext_( unit, lnext, il) char *unit; long int *lnext; /* logical flag true=1 if this is last */ int il; { unitpt = unit; printf(" 6 call to getunit "); (void) getunit_( unit, &iunit, &junit, &iaerr, &ir, &two, stream, indpip, <ape, 4); (void) tnext( unit, lnext); } tnext( unit, lnext) char *unit; long int *lnext; { int mone = 1001; if ( junit > 0) *lnext=0; else *lnext = 1; ieof[iaerr] = 0; return; } twritebat_( unit, buffer, rcount, il) char *unit; /* name of tape, just a dummy here */ char *buffer[]; /* buffer into which data is to be read */ int *rcount; /* number of bytes to be read, have been read */ int il; /* length count for unit */ { int i; unitpt = unit; nrecords += 1; printf(" 7 call to getunit "); (void) getunit_( unit, &iunit, &junit, &iaerr, &ir, &one, stream, indpip, <ape, 4); /* get unit numbers */ irw[iaerr] = -1; nrecarr[iaerr] += 1; if ( lvbs[iaerr] == 0 ) { twrite( buffer, rcount); } else if ( lvbs[iaerr] == 2 ) { i = batwrite( junit, buffer, *rcount); if ( i == EOF || i == 0 ) { lres[0][iaerr] = 1; ieof[iaerr] += 1; ncount[iaerr] = 0; } else { lres[0][iaerr] = 0; ieof[iaerr] = 0; ncount[iaerr] = i; } return; } else { fprintf( stderr,"lvbs of %d not supported on iaerr %d\n", lvbs[iaerr], iaerr); exit( 9); } } twrite( buffer, rcount) /* no backwars motion allowed */ char *buffer[]; /* buffer into which data is to be read */ int *rcount; /* number of bytes to be read, have been read */ { int i,j; /* temp int */ nblocks += 1; /* incrment block counter */ nblkarr[iaerr] += 1; for ( i=0; i < 12; i++) lres[i][iaerr]=0; /* clear error flags */ if ((ltape == 0) || (ltape == 2)) { /* disk file */ /* 8mm tape */ ncount[iaerr] = 0; j=4; i= batwrite( junit, rcount, j); /* write out number of bytes */ if ( i != j ) { lres[1][iaerr] = 1; } else { i = 0; if ( *rcount > 0) i = batwrite(junit, buffer, *rcount); /* write out buffer */ ncount[iaerr] = i; /* record nomber of bytes read */ if ( i != *rcount ) { lres[1][iaerr] = 1; } else { i = batwrite( junit, rcount, j); /* write out number of bytes */ if ( i != j ) lres[1][iaerr] = 1; } j=0; } } else if (ltape == 1 || ltape == 3 ) { /* tape file */ /* 8mm tape literal */ i = write (junit, buffer, *rcount) ; ncount[iaerr] = i; /* record nomber of bytes written */ if ( i < 0 ) lres[1][iaerr] = 1; j = 0; } return; } tmark_( unit,il) char *unit; /* name of tape, just a dummy here */ int il; /* length count for unit */ { struct mtop op; int i ; int zero = 0; unitpt = unit; printf(" 8 call to getunit "); (void) getunit_( unit, &iunit, &junit, &iaerr, &ir, &one, stream, indpip, <ape, 4); /* get unit numbers */ if ((ltape == 0) || (ltape == 2)) { /* disk file */ /* 8mm tape */ twrite( unit, &zero); } else if (ltape == 1 || ltape == 3 ) { /* 1/2" tape file */ /* 8mm tape literal */ op.mt_op = MTWEOF; op.mt_count = 1; i = ioctl( junit, MTIOCTOP, &op); } } teom_( unit,il) char *unit; /* name of tape, just a dummy here */ int il; /* length count for unit */ { struct mtop op; int i ; int zero = 0; int mone = -1; unitpt = unit; printf(" 9 call to getunit "); (void) getunit_( unit, &iunit, &junit, &iaerr, &ir, &one, stream, indpip, <ape, 4); /* get unit numbers */ if ((ltape == 0) || (ltape == 2)) { /* disk file */ /* 8mm tape */ twrite( unit, &zero); twrite( unit, &zero); twrite( unit, &mone); } else if (ltape == 1 || ltape == 3 ) { /* 1/2" tape file */ /* 8mm tape literal */ op.mt_op = MTWEOF; op.mt_count = 2; i = ioctl( junit, MTIOCTOP, &op); } } popenr_( pipe, iaerr, il) char *pipe; int *iaerr; /* index to file */ int il; /* length of pipe name */ { *(pipe+il-1) = '\0'; stream[*iaerr] = popen( pipe, readtype); } popenw_( pipe, iaerr, il) char *pipe; int *iaerr; int il; /* length of pipe name */ { *(pipe+il-1) = '\0'; stream[*iaerr] = popen( pipe, writetype); } popenrs_( pipe, iaerr, il) char *pipe; int *iaerr; /* index to file */ int il; /* length of pipe name */ { stream[*iaerr] = stdin ; } popenws_( pipe, iaerr, il) char *pipe; int *iaerr; int il; /* length of pipe name */ { stream[*iaerr] = stdout ; } tclosebat_( unit) /* close bat unit, does remove it from getunits tables */ char *unit; /* unit name */ { iunit = -1; unitpt = unit; printf(" 10 call to getunit "); (void) getunit_( unit, &iunit, &junit, &iaerr, &ir, &one, stream, indpip, <ape, 4); /* get unit numbers */ if ( indpip[ iaerr] == 0 ) { if ( ltape == 1 ) { /* not only close tape, offline it */ tbatoff_( &junit); } (void) initiocl_(&one, &iunit, &junit); } else if ( indpip[ iaerr] > 0 ) { /* close pipe */ if ( stream[ iaerr ] != (FILE *) NULL) { /* do not close pipe twice */ (void) pclose( stream[ iaerr ]); stream[ iaerr ] = NULL; } else { /* warn of error */ (void) fprintf( stderr," tried to close pipe twice, uint = %s\n", unit); } } else { /* close stream */ if ( stream[ iaerr ] != (FILE *) NULL) { /* do not close stream twice */ (void) fclose( stream[ iaerr ]); stream[ iaerr ] = NULL; } else { /* warn of error */ (void) fprintf( stderr," tried to close stream twice, uint = %s\n", unit); } } } batread( junit, buf, icount) int junit; char *buf; int icount; { int i,ii; int iii,iiii,ill; char *buf0; int loop,rep; buf0 = buf; ill = 0; loop = 0; if ( indpip[iaerr] == 0) { /* not piped */ if (ltape == 0) { /* disk file */ i = read ( junit, buf, icount); buf += i; ill = i; icount -= i; loop = 1; rep = 0; while ( ( icount > 0 ) && ( junit == 0)) //ccc gsgjr 13_08_14 to handel new tructure { /* keep reading on stdin */ //readfld = readfld0; //#writefld = writefld0; //#execfld = execfld0; //#from select man page example FD_ZERO(&readfld); FD_SET(readfld0,&readfld); FD_ZERO(&writefld); FD_SET(writefld0,&writefld); FD_ZERO(&execfld); FD_SET(execfld0,&execfld); ii = select( select_width, &readfld, &writefld, &execfld, &timeout); if ( ii > 0 ) { i = 1; while ( icount > 0 && i > 0 ) { i = read ( junit, buf, icount); buf += i; ill += i; icount -= i; } } else { loop++; rep++; sleep( one); } } i = ill; } else if (ltape == 2) { /* 8mm tape */ if (pbufmm[iaerr] == NULL) { /* no buffer so get one */ if ((pbufmm[iaerr] = malloc((unsigned) rstbufsize)) == NULL) {(void) perror("allocation error");(void)exit(4);} pbufmme[iaerr] = pbufmm[iaerr] + rstbufsize - 1; pbufmmd[iaerr] = pbufmme[iaerr] + 1; junita[iaerr] = junit; } i = 0; while ( i < icount) { if (pbufmmd[iaerr] >= pbufmme[iaerr]) { /* buffer full so write it out */ ii = read( junit, pbufmm[iaerr], rstbufsize); if ( ii != rstbufsize) fprintf( stderr,"read error on unit %d\n",junit); pbufmmd[iaerr] = pbufmm[iaerr]; } for (;(i < icount) && ( pbufmmd[iaerr] <= pbufmme[iaerr]); i++,pbufmmd[iaerr]++) *buf++ = *pbufmmd[iaerr]; } } } else { /* a pipe stream */ i = fread( buf, sizeof( char), icount, stream[iaerr]); iii = *buf; buf += i; iiii = *buf; /* for ( i=0; i < icount ; i++, buf++) { *buf = getc ( stream[iaerr]); iii = *buf; iiii = iii; } if ( iii == EOF) i = EOF; */ } return(i); } batwrite( junit, buf, icount) int junit; char *buf; int icount; { int i,ii; if ( indpip[iaerr] == 0) { /* not piped */ if (ltape == 0) { /* disk file */ i = write ( junit, buf, icount); } else if (ltape == 2) { /* 8mm tape */ if (pbufmm[iaerr] == NULL) { /* no buffer so get one */ if ((pbufmm[iaerr] = malloc((unsigned) rstbufsize)) == NULL) {(void) perror("allocation error");(void)exit(4);} pbufmmd[iaerr] = pbufmm[iaerr]; pbufmme[iaerr] = pbufmm[iaerr] + rstbufsize - 1; junita[iaerr] = junit; } i = 0; while ( i < icount) { for (;(i < icount) && ( pbufmmd[iaerr] <= pbufmme[iaerr]); i++,pbufmmd[iaerr]++) *pbufmmd[iaerr] = *buf++; if (pbufmmd[iaerr] >= pbufmme[iaerr]) { /* buffer full so write it out */ ii = write( junit, pbufmm[iaerr], rstbufsize); if ( ii != rstbufsize) fprintf( stderr,"write error on unit %d\n",junit); pbufmmd[iaerr] = pbufmm[iaerr]; } } } } else { /* piped */ i = fwrite( buf, sizeof( char), icount, stream[iaerr]); } return (i); } batend_() { /* clean up, i.e.write out left over write buffers */ int i,ii; for ( i=0; i < 10 ; i++) if ((pbufmm[i] != NULL) && (irw[i] == -1)) { /* flush out buffer wth nulls and then write */ for (;pbufmmd[i] <= pbufmme[i]; pbufmmd[i]++) *pbufmmd[i] = 0; ii = write( junita[i], pbufmm[i], rstbufsize); irw[i] = 0; (void) free( pbufmm[i]); pbufmm[i] = NULL; } } tbatoff_( ju) int *ju; /* unix file number */ { struct mtop op; int i; junit = *ju; /* tape file */ op.mt_op = MTOFFL; op.mt_count = 1; i = ioctl( junit, MTIOCTOP, &op); return(i); } tbatstat_( ju) int *ju; /* unix file number */ { struct mtop op; int i; junit = *ju; /* tape file */ op.mt_op = MTNOP; op.mt_count = 1; i = ioctl( junit, MTIOCTOP, &op); return(i); }