/* streamio.c: tests Unix Stream I/O functions */ /* Modifications: */ /* 1/84 verbose error msgs for 68K whf */ /* 9/83 improved error msgs whf */ /* Runs by itself: just compile and exec. It will tell you which functions it is testing. */ #include #include /************************************************/ /* Possible file size parameters for each pass: */ #define NUMPASS 4 /* Number of passes for this test */ #define MAXRECMAX 128 /* Maximum record size */ #define NRCHECKS 7 /* Number of random i/o checks */ WORD pass_types[NUMPASS][2] = /* Num records, Len records for each pass */ { 100, MAXRECMAX, 16, 32, 10, 20, 10000, 20 }; /*************************/ /* O.S. dependent values */ #define BYTE_LEVEL 128 /* Size of sectors: PCDOS = 1, CP/M = 128 */ /*********************************************/ /* Possible kinds of File I/O for each case: */ /* Ascii/Binary I/O indicator */ #define AB_ASCII 1 #define AB_BINARY 0 /* Record/Char/Line indicator */ #define RCL_RECORD 1 #define RCL_CHAR 2 #define RCL_LINE 3 #define NUMCASE 6 /* Number of cases per pass */ WORD case_types[NUMCASE][2] = /* AB type, RCL type for each case */ { AB_BINARY, RCL_RECORD, AB_BINARY, RCL_LINE, AB_BINARY, RCL_CHAR, AB_ASCII, RCL_LINE, AB_ASCII, RCL_RECORD, AB_ASCII, RCL_CHAR }; /*************************************************************************/ /*************************************************************************/ GLOBAL WORD nerrors = 0; /* number of errors reported */ main(ac,av) int ac; char **av; { int ii, jj, nfiles; BYTE **files, *calloc(); BYTE *test_dir, *make_fn(); av[0] = "STREAMIO"; /* kludge: DRC doesn't handle */ test_dir = "g:"; /* where we want to do the testing */ nfiles = 0; files = calloc(NUMPASS*NUMCASE,sizeof(BYTE *)); printf("%s tests the following Stream I/O functions:\n",av[0]); printf("\tfopen, fclose, freopen, fseek, ftell, rewind\n"); printf("as well as functions listed below.\n"); printf("****************** %s test starting ****************\n",av[0]); for( ii=0; ii 1 ) { eof_slack = BYTE_LEVEL - ((recmax*reclen) % BYTE_LEVEL); if( eof_slack == BYTE_LEVEL ) eof_slack = 0; } else eof_slack = 0; tt = -reclen - eof_slack; if( FAILURE == fseek(tfsp,tt,2) ) /* addr of last record*/ eprintf("fseek(%ld,2) in rand_write",tt); if( write_it(recmax-1) ) return FAILURE; tt = 1 - recmax; tt *= reclen; tt -= eof_slack; if( FAILURE == fseek(tfsp,tt,2) ) eprintf("fseek(%ld,2) in rand_write",tt); if( write_it(1L) ) return FAILURE; } /* step 4: close file again */ if( FAILURE == fclose(tfsp) ) return eprintf("fclose in rand_write"); return SUCCESS; } /***************************************************************************/ check_it() /*** check that everything reads ok sequential ***/ { LONG rn; FILE *fopen(), *fopenb(); /* step 1: open for read */ if( AB_ASCII == ab_flag ) tfsp = fopen(filename,"r"); else tfsp = fopenb(filename,"r"); /* watch: reclen % 128 != 0 */ if( NULLPTR == tfsp ) return eprintf("fopen(%s,r) in check_it",filename); /* step2: read sequential */ for( rn=0; rn < recmax; ++rn ) { if( read_it(rn) ) return FAILURE; } /* step 3: close file */ if( FAILURE == fclose(tfsp) ) return eprintf("fclose in check_it"); return SUCCESS; } /***************************************************************************/ read_it(rnum) LONG rnum; { WORD rlen, ii; /* step 1: make a record */ rlen = reclen; if( rcl_flag == RCL_LINE ) --rlen; /* leave room for newline */ makerec(rec1,rlen,rnum,filename,ch_first,ch_last); if( rcl_flag == RCL_LINE ) rec1[reclen-1]='\n'; /* step 2: read the record */ switch( rcl_flag ) { case RCL_RECORD: if( reclen != fread(rec2,1,reclen,tfsp) ) return eprintf("fread in read_it"); break; case RCL_CHAR: for( ii=0; ii */ /* or if reclabel==NULL */ /****************************************************************/ makerec(record,rlen,recnum,reclabel,clo,chi) BYTE *record; /* place to make the record */ UWORD rlen; /* size of the record to make */ LONG recnum; /* record number to make */ BYTE *reclabel; /* label to prepend to each record */ WORD clo, chi; /* range of char values for ripple pattern */ { BYTE lbuf[10]; /* place to hold chars */ BYTE *cp; /* char ptr */ WORD cc; /* char temp */ clo &= 0xFF; chi &= 0xFF; /* defeat sign extension */ if( reclabel != NULLPTR ) { for( ; *reclabel && rlen>0; --rlen )/* copy label to record */ *record++ = *reclabel++; sprintf(lbuf,"#%5.5D#",recnum); /* cvt recnum to ascii */ for( cp=lbuf; *cp && rlen>0; --rlen)/* copy recnum into rec */ *record++ = *cp++; } cc = recnum % (1 + chi - clo); /* choose new place to start */ cc += clo; /* DRC bug... */ for( ; rlen>0; --rlen ) /* generate ripple pattern */ { if( cc > chi ) cc = clo; /* ripple range check */ *record++ = cc++; } *record++ = NULL; /* insure NULL terminated */ *record++ = NULL; /* insure NULL terminated */ } /***************************************************************************/ /***************************************************************************/ /************************************************************************ * * Calling sequence: * nchrs = eprintf(fmt,arg1,arg2,...argn); * Where: * nchrs = # chars output by printf * fmt -> a string specifying how arg1-n are to be printed. * **************************************************************************/ WORD eprintf(fmt,args) BYTE *fmt, *args; { _doprt(stdout,"\nERROR:\t"); return(_doprt(stdout,fmt,&args)); } WORD ep_init() /* initiate eprintf for new set of error messages */ { } WORD ep_fini() /* wrap up a set of error messages */ { } ap up a set of error messages */ { } ap up a set of error messages */ { }