home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c160 / 1.ddi / TEST / T4SEEK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-22  |  3.0 KB  |  155 lines

  1.  
  2. /* t4seek.c
  3.  
  4.    (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
  5.  
  6.    Tests Code Base 'd4seek' routine.
  7. */
  8.  
  9. #include "p4misc.h"
  10. #include "d4all.h"
  11. #include "w4.h"
  12. #include "u4error.h"
  13.  
  14. #include <stdlib.h>
  15. #include <math.h>
  16. #include <string.h>
  17.  
  18. FIELD  fields[] = 
  19. {
  20.    { "FIELD", 'C', 25, 0, 0 },
  21. } ;
  22.  
  23. static long power( long, long ) ;
  24.  
  25. static long power( long val, long p )
  26. {
  27.    long r ;
  28.  
  29.    r = 1L ;
  30.  
  31.    while ( --p >= 0 )
  32.       r *= val ;
  33.  
  34.    return r ;
  35. }
  36.  
  37. main( int argc, char **argv )
  38. {
  39.    int   rc ;
  40.    long  num_digits, on_digits, i, limit, extra, f_ref ;
  41.    long  num_recs, left, on_rec ;
  42.    char  buf[100], *ptr ;
  43.  
  44.    #ifdef NO_HUGE
  45.       #ifdef IS_386
  46.          d4init() ;
  47.       #else
  48.          d4initialize( 4, 4, 20, 1000, 20000L ) ;
  49.       #endif
  50.    #else
  51.       d4init() ;
  52.    #endif
  53.    w4clear(-1) ;
  54.  
  55.    if ( argc < 2 )
  56.    {
  57.       w4(0,0, "t4seek  Num_Records") ;
  58.       w4(1,0, "t4seek  Test 'd4seek' routine") ;
  59.       w4cursor(2,0) ;
  60.       w4exit(1) ;
  61.    }
  62.  
  63.    d4create( "T4SEEK", 1, fields, 0 ) ;
  64.  
  65.    left =  atol( argv[1] ) ;
  66.  
  67.    for ( num_digits = 0; left> 0; num_digits++ ) 
  68.       left /= 10 ;
  69.  
  70.    if ( num_digits <= 0 )  num_digits =  1 ;
  71.    for ( num_recs = 10, i=1; i< num_digits; i++ )
  72.       num_recs  *=  10 ;
  73.  
  74.    num_recs-- ;
  75.  
  76.    w4( 0,50, "Records Using: ") ;
  77.    w4long( 0, w4col(), num_recs, 8) ;
  78.  
  79.    if ( num_digits > fields[0].width )
  80.    {
  81.       u4error( 0, "t4seek:  Error", (char *) 0 ) ;
  82.       w4exit(1) ;
  83.    }
  84.  
  85.    ptr =  (char *) f4record() ;
  86.    ptr += 1 ;
  87.    f_ref =  f4j_ref( 1 ) ;
  88.  
  89.    w4( 0,0, "Writing: " ) ;
  90.    for ( on_rec = 1;  on_rec <= num_recs; on_rec++ ) 
  91.    {
  92.       c4ltoa( on_rec, ptr, - ((int) num_digits) ) ;
  93.       w4field( 0,9, f_ref ) ;
  94.       d4write( 0L ) ;
  95.    }
  96.  
  97.    i4index(  "T4SEEK", "FIELD", 0, 0 ) ;
  98.  
  99.    memset( buf, 0, sizeof(buf) ) ;
  100.    w4position(4,0) ;
  101.    w4( 4,0, "Seeking: ") ;
  102.    w4( 4,20, "Record: ") ;
  103.  
  104.    for ( on_digits = 1; on_digits <= num_digits; on_digits++ ) 
  105.    {
  106.       w4clear(0) ;
  107.       limit  =  power( 10L, on_digits ) ;
  108.       extra  =  power( 10L, num_digits-on_digits ) ;
  109.  
  110.       for ( i=0; i< limit; i++ ) 
  111.       {
  112.      c4ltoa(i, buf, -((int)on_digits) ) ;
  113.      w4( 4,9, buf ) ;
  114.  
  115.      rc =  d4seek( buf ) ;
  116.      w4long( 4,28, d4recno(), 6) ;
  117.          if ( rc != 0  &&  rc != 1 ) 
  118.      {
  119.         if ( rc != 2 || d4recno() != 1 )
  120.             {
  121.                u4error( 0, "t4seek:  Error", (char *) 0 ) ;
  122.                w4exit(1) ;
  123.             }
  124.          }
  125.          if ( d4recno() != i*extra && d4recno() != 1 )
  126.          {
  127.             u4error( 0, "t4seek:  Error", (char *) 0 ) ;
  128.             w4exit(1) ;
  129.          }
  130.       }
  131.    }
  132.  
  133.    d4close_all() ;
  134.  
  135.  
  136.    #ifdef H4TEST
  137.    {
  138.       int  rc ;
  139.       d4init_undo() ;
  140.       rc = h4free_check(32000) ;
  141.       d4init() ;
  142.       if ( rc != 0 )
  143.       {
  144.          u4error( 0, "t4seek:  Memory items not freed", (char *) 0 );
  145.          w4exit(1) ;
  146.       }
  147.    }
  148.    #endif
  149.  
  150.    w4handle(1) ;
  151.    w4( w4row()+1,0, "t4seek:  SUCCESS" ) ;
  152.    w4exit(0) ;
  153. }
  154.  
  155.