home *** CD-ROM | disk | FTP | other *** search
-
- /* (c)Copyright Sequiter Software Inc., 1989. All rights reserved.
-
- This program counts the number of non-blank data bytes in
- a database.
-
- It illustrates how small an EXE file for a Code Base application can be.
-
- This application was compiled with the NOIO, SMALL and switches set.
-
- After compiling and linking with the Turbo C 2.0 Tiny memory model,
- the EXE size was 23.5K. Refer to file 'd4small.prj'.
-
- After compiling and linking with the Microsoft C 5.1 compiler, with
- size optimization, the EXE size was 13.5K. Refer to file 'd4sm.bat'.
-
- */
-
- #include "d4base.h"
- #include "p4misc.h"
-
- #ifndef UNIX
- #include <io.h>
- #endif
-
- #include <stdlib.h>
- #include <string.h>
-
- extern int v4cur_base ;
- extern BASE *v4base ;
-
- char msg[] = "\nd4small database_file_name" ;
- char msg2[] = "\nThe number of blank characters in the database: " ;
-
- main( int argc, char **argv )
- {
- long i_rec, count ;
- int rec_width, i ;
- char *ptr, output[40] ;
-
- if ( argc < 2 )
- {
- write( 1, msg, sizeof(msg)-1 ) ;
- exit(1) ;
- }
-
- if ( d4use( argv[1] ) < 0 ) exit(2) ;
-
- ptr = (char *) f4record() ;
- rec_width = f4record_width() ;
- count = 0 ;
-
- for ( i_rec = 1; i_rec <= d4reccount(); i_rec++ )
- {
- if ( d4go(i_rec) < 0 ) exit(2) ;
- for ( i=0; i< rec_width; i++ )
- if ( ptr[i] == ' ' ) count++ ;
- }
-
- c4ltoa( count, output, 10 ) ;
- output[10] = '\0' ;
-
- write( 1, msg2, sizeof(msg2)-1 ) ;
- write( 1, output, strlen(output) ) ;
- write( 1, "\n", 1 ) ;
-
- exit(0) ;
- }
-
-
-
- /* c4ltoa
-
- Converts a RECNUM to a string. Fill with '0's rather than blanks if
- 'num' is less than zero.
-
- Copy 'c4ltoa' from 'c4.c' so that all of the code in 'c4.c' does
- not get linked in.
- */
-
- char *c4ltoa( long l_val, char *ptr, int num)
- {
- int n, num_pos ;
- long i_long ;
-
- i_long = (l_val>0) ? l_val : -l_val ;
- num_pos = n = (num > 0) ? num : -num ;
-
- while (n-- > 0)
- {
- ptr[n] = (char) ('0'+ i_long%10) ;
- i_long = i_long/10 ;
- }
-
- if ( i_long > 0 )
- {
- memset( ptr, (int) '*', (size_t) num_pos ) ;
- return ptr ;
- }
-
- num--;
- for (n=0; n<num; n++)
- if (ptr[n]=='0')
- ptr[n]= ' ';
- else
- break ;
-
- if (l_val < 0)
- {
- if ( ptr[0] != ' ' )
- {
- memset( ptr, (int) '*', (size_t) num_pos ) ;
- return ptr ;
- }
- for (n=num; n>=0; n--)
- if (ptr[n]==' ')
- {
- ptr[n]= '-' ;
- break ;
- }
- }
-
- return(ptr) ;
- }
-