home *** CD-ROM | disk | FTP | other *** search
- /*
- * Usage - cpb byte_count start_byte input_file output_file
- *
- * CPB - Copy bytes... Copy any portion of any file to a new file.
- * Start at a specified byte, copy a specified byte count.
- * Standard output may not be used because DOS drops carriage
- * returns and CTL-Z.
- *
- * input: Any file whatsoever.
- *
- * output: Portion of the same file.
- *
- * writeup: MIR TUTORIAL ONE, topic 4
- *
- * Written: Douglas Lowry Oct 11 91
- * Modified: Douglas Lowry Jan 07 92
- * Copyright (C) 1992 Marpex Inc.
- *
- * The MIR (Mass Indexing and Retrieval) Tutorials explain detailed
- * usage and co-ordination of the MIR family of programs to analyze,
- * prepare and index databases (small through gigabyte size), and
- * how to build integrated retrieval software around the MIR search
- * engine. The fifth of the five MIR tutorial series explains how
- * to extend indexing capability into leading edge search-related
- * technologies. For more information, GO IBMPRO on CompuServe;
- * MIR files are in the DBMS library. The same files are on the
- * Canada Remote Systems BBS. A diskette copy of the Introduction
- * is available by mail ($10 US... check, Visa or Mastercard);
- * diskettes with Introduction, Tutorial ONE software and the
- * shareware Tutorial ONE text cost $29. Shareware registration
- * for a tutorial is also $29.
- *
- * E-mail...
- * Compuserve 71431,1337
- * Internet doug.lowry%canrem.com
- * UUCP canrem!doug.lowry
- * Others: doug.lowry@canrem.uucp
- *
- * FAX... 416 963-5677
- *
- * "Snail mail"... Douglas Lowry, Ph.D.
- * Marpex Inc.
- * 5334 Yonge Street, #1102
- * North York, Ontario
- * Canada M2N 6M2
- *
- * Related database consultation and preparation services are
- * available through:
- * Innotech Inc., 2001 Sheppard Avenue E., Suite #118,
- * North York, Ontario Canada M2J 4Z7
- * Tel. 416 492-3838 FAX 416 492-3843
- *
- * This program is free software; you may redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * (file 05LICENS) along with this program; if not, write to the
- * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
- * USA.
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
-
- #define repeat for(;;)
-
- /*
- * declarations
- */
-
- typedef enum _bool
- { FALSE = 0, TRUE = 1 } Bool;
-
- void Usage_(), process();
- char *Cmdname_() { return( "cpb" ); }
-
- /*
- * MAIN
- */
-
- main( argc, argv )
- int argc;
- char **argv;
- {
- FILE *fp, *fp_out ;
- char c ;
- long byte_ct, start_at, i ;
-
- if( argc != 5 || !isdigit( argv[1][0] ))
- Usage_() ;
-
- if(( fp = fopen( argv[3], "rb" )) == NULL )
- {
- fprintf( stderr, "\nUnable to open file %s.\n", argv[3] );
- Usage_();
- }
-
- if(( fp_out = fopen( argv[4], "wb" )) == NULL )
- {
- fprintf( stderr, "\nUnable to open file %s.\n", argv[4] );
- Usage_();
- }
-
- byte_ct = atol( argv[1] );
- start_at = atol( argv[2] );
-
- if( start_at )
- {
- if( fseek( fp, start_at, SEEK_SET ))
- {
- fprintf( stderr, "Unable to position %s to %ld\n",
- argv[3], start_at );
- Usage_() ;
- }
- }
-
- for( i = 0 ; i < byte_ct ; i++ )
- {
- c = fgetc( fp ) ;
- if( feof( fp ))
- break ;
- fputc( c, fp_out );
- if( ferror( fp_out ))
- {
- fprintf( stderr, "FATAL write problem\n\n" );
- exit( 1 ) ;
- }
- }
-
- fclose( fp );
- fclose( fp_out );
- exit( 0 );
- }
- /*
- * Usage
- */
- void
- Usage_()
- {
- fprintf( stderr,
- "\nUsage: %s byte_count start_byte input_file output_file\n\n\
- Copy bytes... Copy any portion of any file to a new file.\n\
- Start at a specified byte, copy a specified byte count.\n\n",
- Cmdname_() );
- fprintf( stderr,
- " Standard output may not be used because DOS drops carriage\n\
- returns and CTL-Z.\n\n\
- input: Any file whatsoever.\n\n\
- output: Portion of the same file.\n\n\
- writeup: MIR TUTORIAL ONE, topic 4\n\n" ) ;
- exit( 1 ) ;
- }