home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / doc / mir / cpb.c < prev    next >
Text File  |  1992-07-02  |  5KB  |  161 lines

  1. /*
  2.  * Usage -  cpb  byte_count  start_byte  input_file  output_file
  3.  *
  4.  *   CPB -  Copy bytes...  Copy any portion of any file to a new file.
  5.  *          Start at a specified byte, copy a specified byte count.
  6.  *          Standard output may not be used because DOS drops carriage
  7.  *          returns and CTL-Z.
  8.  *
  9.  *  input:  Any file whatsoever.
  10.  *
  11.  *  output: Portion of the same file.
  12.  *
  13.  *  writeup: MIR TUTORIAL ONE, topic 4
  14.  *
  15.  *  Written:    Douglas Lowry   Oct 11 91
  16.  *  Modified:   Douglas Lowry   Jan 07 92
  17.  *              Copyright (C) 1992 Marpex Inc.
  18.  *
  19.  *    The MIR (Mass Indexing and Retrieval) Tutorials explain detailed
  20.  *    usage and co-ordination of the MIR family of programs to analyze,
  21.  *    prepare and index databases (small through gigabyte size), and
  22.  *    how to build integrated retrieval software around the MIR search
  23.  *    engine.  The fifth of the five MIR tutorial series explains how
  24.  *    to extend indexing capability into leading edge search-related
  25.  *    technologies.  For more information, GO IBMPRO on CompuServe;
  26.  *    MIR files are in the DBMS library.  The same files are on the
  27.  *    Canada Remote Systems BBS.  A diskette copy of the Introduction
  28.  *    is available by mail ($10 US... check, Visa or Mastercard);
  29.  *    diskettes with Introduction, Tutorial ONE software and the
  30.  *    shareware Tutorial ONE text cost $29.  Shareware registration
  31.  *    for a tutorial is also $29.
  32.  *
  33.  *    E-mail...
  34.  *                Compuserve  71431,1337
  35.  *                Internet    doug.lowry%canrem.com
  36.  *                UUCP        canrem!doug.lowry
  37.  *                Others:     doug.lowry@canrem.uucp
  38.  *
  39.  *    FAX...                  416 963-5677
  40.  *
  41.  *    "Snail mail"...         Douglas Lowry, Ph.D.
  42.  *                            Marpex Inc.
  43.  *                            5334 Yonge Street, #1102
  44.  *                            North York, Ontario
  45.  *                            Canada  M2N 6M2
  46.  *
  47.  *    Related database consultation and preparation services are
  48.  *    available through:
  49.  *              Innotech Inc., 2001 Sheppard Avenue E., Suite #118,
  50.  *              North York, Ontario  Canada   M2J 4Z7
  51.  *              Tel.  416 492-3838   FAX  416 492-3843
  52.  *
  53.  *  This program is free software; you may redistribute it and/or
  54.  *  modify it under the terms of the GNU General Public License as
  55.  *  published by the Free Software Foundation; either version 2 of
  56.  *  the License, or (at your option) any later version.
  57.  *
  58.  *  This program is distributed in the hope that it will be useful,
  59.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  60.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  61.  *  GNU General Public License for more details.
  62.  *
  63.  *  You should have received a copy of the GNU General Public License
  64.  *  (file 05LICENS) along with this program; if not, write to the
  65.  *  Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
  66.  *  USA.
  67.  */
  68.  
  69. #include <stdio.h>
  70. #include <stdlib.h>
  71. #include <ctype.h>
  72.  
  73. #define     repeat      for(;;)
  74.  
  75. /*
  76.  * declarations 
  77.  */
  78.  
  79. typedef     enum        _bool
  80.              { FALSE = 0, TRUE = 1 }  Bool;
  81.  
  82.     void        Usage_(), process();
  83.     char        *Cmdname_() {    return( "cpb" );  }
  84.  
  85. /*
  86.  * MAIN
  87.  */
  88.  
  89. main( argc, argv )
  90.     int  argc;
  91.     char **argv;
  92. {
  93.     FILE    *fp, *fp_out ;
  94.     char    c ;
  95.     long    byte_ct, start_at, i ;
  96.  
  97.     if( argc != 5 || !isdigit( argv[1][0] ))
  98.         Usage_() ;
  99.  
  100.     if(( fp = fopen( argv[3], "rb" )) == NULL )
  101.     {
  102.         fprintf( stderr, "\nUnable to open file %s.\n", argv[3] );
  103.         Usage_();
  104.     }
  105.  
  106.     if(( fp_out = fopen( argv[4], "wb" )) == NULL )
  107.     {
  108.         fprintf( stderr, "\nUnable to open file %s.\n", argv[4] );
  109.         Usage_();
  110.     }
  111.  
  112.     byte_ct = atol( argv[1] );
  113.     start_at = atol( argv[2] );
  114.  
  115.     if( start_at )
  116.     {
  117.         if( fseek( fp, start_at, SEEK_SET ))
  118.         {
  119.             fprintf( stderr, "Unable to position %s to %ld\n",
  120.                 argv[3], start_at );
  121.             Usage_() ;
  122.         }
  123.     }
  124.  
  125.     for( i = 0 ; i < byte_ct ; i++ )
  126.     {
  127.         c = fgetc( fp ) ;
  128.         if( feof( fp ))
  129.             break ;
  130.         fputc( c, fp_out );
  131.         if( ferror( fp_out ))
  132.         {
  133.             fprintf( stderr, "FATAL write problem\n\n" );
  134.             exit( 1 ) ;
  135.         }
  136.     }
  137.  
  138.     fclose( fp );
  139.     fclose( fp_out );
  140.     exit( 0 );
  141. }
  142. /*
  143.  *  Usage
  144.  */
  145.     void
  146. Usage_()
  147. {
  148.     fprintf( stderr,
  149. "\nUsage: %s  byte_count  start_byte  input_file  output_file\n\n\
  150.         Copy bytes...  Copy any portion of any file to a new file.\n\
  151.         Start at a specified byte, copy a specified byte count.\n\n",
  152.             Cmdname_() );
  153.     fprintf( stderr,
  154. "        Standard output may not be used because DOS drops carriage\n\
  155.         returns and CTL-Z.\n\n\
  156. input:  Any file whatsoever.\n\n\
  157. output: Portion of the same file.\n\n\
  158. writeup: MIR TUTORIAL ONE, topic 4\n\n" ) ;
  159.     exit( 1 ) ;
  160. }
  161.