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

  1. /* t4write.c 
  2.  
  3.    (c)Copyright Sequiter Software Inc., 1987-1990. All rights reserved.
  4.  
  5.    Tests Code Base 'd4seek' and 'd4write' routines.
  6. */
  7.  
  8. #include "p4misc.h"
  9. #include "d4all.h"
  10. #include "w4.h"
  11. #include "u4error.h"
  12.  
  13. #include <string.h>
  14. #include <stdio.h>
  15.  
  16.  
  17. static FIELD  fields[]=
  18. {
  19.    { "TEST", 'N', 15, 0, 0 },
  20. } ;
  21.  
  22.  
  23. main( int argc, char **argv )
  24. {
  25.    int   i_ref, c ;
  26.    long  num_recs, i_rec, f_ref ;
  27.    double d, neg ;
  28.  
  29.    #ifdef NO_HUGE
  30.       #ifdef IS_386
  31.          d4init() ;
  32.       #else
  33.          d4initialize( 4, 4, 20, 1000, 20000L ) ;
  34.       #endif
  35.    #else
  36.       d4init() ;
  37.    #endif
  38.    w4clear(-1) ;
  39.  
  40.    if ( argc >= 2 )
  41.       num_recs =  c4atol( argv[1], strlen(argv[1]) ) ;
  42.    else
  43.       num_recs =  1000L ;
  44.    w4( w4row(),0, "t4write - Number of Records:" ) ;
  45.    w4long( w4row(),w4col(), num_recs, 6 ) ;
  46.  
  47.    d4create( "t4write2", 1, fields, 0 ) ;
  48.    i_ref =  i4index( "t4write2", "TEST", 0, 0 ) ;
  49.  
  50.    f_ref = f4ref( "TEST") ;
  51.  
  52.    d   =  60000000.0 ;
  53.    neg = -5.0 ;
  54.  
  55.    f4replace( f_ref, &d ) ;
  56.  
  57.    w4( w4row()+1,0, "Writing Rec:" ) ;
  58.    c =  w4col() ;
  59.  
  60.    for ( i_rec = 1L; i_rec <= num_recs; i_rec++ )  
  61.    {
  62.       w4long( w4row(),c, i_rec, 6 ) ;
  63.       d4write(0L) ;
  64.    }
  65.  
  66.    if ( i4check(i_ref) != 0L )
  67.    {
  68.       u4error( 0, "t4write:  after writes, i4check()", (char *) 0 ) ;
  69.       w4exit(1) ;
  70.    }
  71.  
  72.    d -=  100000.0 ;
  73.  
  74.    w4( w4row()+1,0, "Replacing Record: " ) ;
  75.    c =  w4col() ;
  76.  
  77.    for ( i_rec = 1; i_rec <= num_recs; i_rec++ )
  78.    {
  79.       w4long( w4row(),c, i_rec, 6 ) ;
  80.  
  81.       if ( d4seek( &d ) != 2 )
  82.       {
  83.          u4error( 0, "t4write:  d4seek()", (char *) 0 ) ;
  84.          w4exit(1) ;
  85.       }
  86.  
  87.       if ( d4recno() != i_rec )
  88.       {
  89.          u4error( 0, "t4write:  d4seek()", (char *) 0 ) ;
  90.          w4exit(1) ;
  91.       }
  92.  
  93.       f4replace( f_ref, &neg ) ;
  94.  
  95.       if ( d4write ( d4recno() )  != 0 )
  96.       {
  97.      u4error( 0, "t4write:  d4write", (char *) 0 ) ;
  98.          w4exit(1) ;
  99.       }
  100.    }
  101.  
  102.    if ( i4check(i_ref) != 0L )
  103.    {
  104.       u4error( 0, "t4write:  after replaces, i4check()", (char *) 0 ) ;
  105.       w4exit(1) ;
  106.    }
  107.  
  108.    d4close_all();
  109.  
  110.  
  111.    #ifdef H4TEST
  112.    {
  113.       int  rc ;
  114.       d4init_undo() ;
  115.       rc = h4free_check(32000) ;
  116.       d4init() ;
  117.       if ( rc != 0 )
  118.       {
  119.          u4error( 0, "t4write:  Memory items not freed", (char *) 0 );
  120.          w4exit(1) ;
  121.       }
  122.    }
  123.    #endif
  124.  
  125.    w4handle(1) ;
  126.    w4( w4row()+1,0, "t4write:  SUCCESS" ) ;
  127.    w4exit(0) ;
  128. }
  129.