home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / CODE4-4.ZIP / HDR_EXMP.ZIP / EXAMPLES.ZIP / D4SMALL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-04-13  |  1.9 KB  |  86 lines

  1.  
  2. /* (c)Copyright Sequiter Software Inc., 1989. All rights reserved.
  3.  
  4.    This program counts the number of non-blank data bytes in
  5.    a database.
  6.  
  7.    It illustrates how small an EXE file for a Code Base application can be.
  8.  
  9.    This application was compiled with the NOIO and SMALL switches set.
  10.  
  11.    After compiling and linking with the Turbo C 2.0 Tiny memory model,
  12.    the EXE size was 22.5K.  Refer to file 'd4small.prj'.
  13.  
  14.    After compiling and linking with the Microsoft C 5.1 compiler, with 
  15.    size optimization, the EXE size was 13.5K.  Refer to file 'd4sm.bat'.
  16.    
  17. */
  18.  
  19. #include "d4base.h"
  20.  
  21. #ifndef UNIX
  22.    #include <io.h>
  23. #endif
  24. #include <stdlib.h>
  25. #include <string.h>
  26.  
  27. extern  int    v4cur_base ;
  28. extern  BASE  *v4base ;
  29.  
  30. char  msg[]  = "\nd4small  database_file_name" ;
  31. char  msg2[] = "\nThe number of blank characters in the database: " ;
  32.  
  33. main( argc, argv )
  34. int   argc ;
  35. char *argv[] ;
  36. {
  37.    long  i_rec, count ;
  38.    int   rec_width, i ;
  39.    char *ptr, output[40] ;
  40.  
  41.    if ( argc < 2 )
  42.    {
  43.       write( 1, msg, sizeof(msg)-1 ) ;
  44.       exit(1) ;
  45.    }
  46.  
  47.    if ( d4use( argv[1] ) < 0 )  exit(2) ;
  48.  
  49.    ptr =  f4record() ;
  50.    rec_width =  f4record_width() ;
  51.    count =  0 ;
  52.  
  53.    for ( i_rec = 1; i_rec <= d4reccount(); i_rec++ )
  54.    {
  55.       if ( d4go(i_rec) < 0 )  exit(2) ;
  56.       for ( i=0; i< rec_width; i++ )
  57.      if ( ptr[i] == ' ' )  count++ ;
  58.    }
  59.  
  60.    ltoa( count, output, 10 ) ;
  61.  
  62.    write( 1, msg2, sizeof(msg2)-1 ) ;
  63.    write( 1, output, strlen(output) ) ;
  64.    write( 1, "\n", 1 ) ;
  65.  
  66.    exit(0) ;
  67. }
  68.  
  69.  
  70.  
  71. /* Pull 'f4record' and 'f4record_width' out of file 'f4.c' so
  72.    that all of the routines in the file do not get linked in !
  73. */
  74.  
  75. void *  f4record()
  76. {
  77.    if ( v4cur_base < 0 )  return ( (void *) 0 ) ;
  78.    return ( (void *) v4base[v4cur_base].buffer ) ;
  79. }
  80.  
  81. int  f4record_width()
  82. {
  83.    if ( v4cur_base < 0 )  return ( -1 ) ;
  84.    return ( v4base[v4cur_base].buffer_len ) ;
  85. }
  86.