home *** CD-ROM | disk | FTP | other *** search
-
- /* t4seek.c
-
- (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
-
- Tests Code Base 'd4seek' routine.
- */
-
- #include "p4misc.h"
- #include "d4all.h"
- #include "w4.h"
- #include "u4error.h"
-
- #include <stdlib.h>
- #include <math.h>
- #include <string.h>
-
- FIELD fields[] =
- {
- { "FIELD", 'C', 25, 0, 0 },
- } ;
-
- static long power( long, long ) ;
-
- static long power( long val, long p )
- {
- long r ;
-
- r = 1L ;
-
- while ( --p >= 0 )
- r *= val ;
-
- return r ;
- }
-
- main( int argc, char **argv )
- {
- int rc ;
- long num_digits, on_digits, i, limit, extra, f_ref ;
- long num_recs, left, on_rec ;
- char buf[100], *ptr ;
-
- #ifdef NO_HUGE
- #ifdef IS_386
- d4init() ;
- #else
- d4initialize( 4, 4, 20, 1000, 20000L ) ;
- #endif
- #else
- d4init() ;
- #endif
- w4clear(-1) ;
-
- if ( argc < 2 )
- {
- w4(0,0, "t4seek Num_Records") ;
- w4(1,0, "t4seek Test 'd4seek' routine") ;
- w4cursor(2,0) ;
- w4exit(1) ;
- }
-
- d4create( "T4SEEK", 1, fields, 0 ) ;
-
- left = atol( argv[1] ) ;
-
- for ( num_digits = 0; left> 0; num_digits++ )
- left /= 10 ;
-
- if ( num_digits <= 0 ) num_digits = 1 ;
- for ( num_recs = 10, i=1; i< num_digits; i++ )
- num_recs *= 10 ;
-
- num_recs-- ;
-
- w4( 0,50, "Records Using: ") ;
- w4long( 0, w4col(), num_recs, 8) ;
-
- if ( num_digits > fields[0].width )
- {
- u4error( 0, "t4seek: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
-
- ptr = (char *) f4record() ;
- ptr += 1 ;
- f_ref = f4j_ref( 1 ) ;
-
- w4( 0,0, "Writing: " ) ;
- for ( on_rec = 1; on_rec <= num_recs; on_rec++ )
- {
- c4ltoa( on_rec, ptr, - ((int) num_digits) ) ;
- w4field( 0,9, f_ref ) ;
- d4write( 0L ) ;
- }
-
- i4index( "T4SEEK", "FIELD", 0, 0 ) ;
-
- memset( buf, 0, sizeof(buf) ) ;
- w4position(4,0) ;
- w4( 4,0, "Seeking: ") ;
- w4( 4,20, "Record: ") ;
-
- for ( on_digits = 1; on_digits <= num_digits; on_digits++ )
- {
- w4clear(0) ;
- limit = power( 10L, on_digits ) ;
- extra = power( 10L, num_digits-on_digits ) ;
-
- for ( i=0; i< limit; i++ )
- {
- c4ltoa(i, buf, -((int)on_digits) ) ;
- w4( 4,9, buf ) ;
-
- rc = d4seek( buf ) ;
- w4long( 4,28, d4recno(), 6) ;
- if ( rc != 0 && rc != 1 )
- {
- if ( rc != 2 || d4recno() != 1 )
- {
- u4error( 0, "t4seek: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- }
- if ( d4recno() != i*extra && d4recno() != 1 )
- {
- u4error( 0, "t4seek: Error", (char *) 0 ) ;
- w4exit(1) ;
- }
- }
- }
-
- d4close_all() ;
-
-
- #ifdef H4TEST
- {
- int rc ;
- d4init_undo() ;
- rc = h4free_check(32000) ;
- d4init() ;
- if ( rc != 0 )
- {
- u4error( 0, "t4seek: Memory items not freed", (char *) 0 );
- w4exit(1) ;
- }
- }
- #endif
-
- w4handle(1) ;
- w4( w4row()+1,0, "t4seek: SUCCESS" ) ;
- w4exit(0) ;
- }
-
-