home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 336.lha / BreakUp / BU.C < prev    next >
C/C++ Source or Header  |  1990-01-05  |  2KB  |  96 lines

  1. /* BU.C    'BREAKUP'    
  2.  *
  3.  *  written for MANX 3.6a using 16-bits
  4.  *   
  5.  *  compile with:       cc bu
  6.  *  link with:          ln bu.o -lc
  7.  *
  8.  * This is designed to break large files into
  9.  * smaller, more manageable chunks.  Each new
  10.  * file will be sized to MAXLINES.
  11.  *
  12.  *          8-18-88
  13.  */
  14.  
  15.  #include <stdio.h>
  16.  #include <libraries/dos.h>
  17.  #include <exec/io.h>
  18.  #include <functions.h>
  19.  
  20.  #define MAXLINES 1000               /* how many lines in each new file */
  21.  #define BUFSIZE  256                /* maximum input line length       */
  22.  char *name = "Writing FILE_ \x9bE" ;
  23.  char *fnam = "FILE_ " ;
  24.  char *iter = "ABCDEFGHIJKLMNOPQRSTUVWZYX" ;
  25.  char *argstring = "args = BU infile\x9bE" ;
  26.  char *author = "Brian Jackson 8-88" ;
  27.  
  28.  FILE *infile, *outfile ;
  29.  int  count = 0 ;
  30.  int  linecount = 0 ;
  31.  char buffer[BUFSIZE] ;
  32.  char *p, *fgets() ;
  33.  int fileopen = 0 ;
  34.  
  35.  main( argc, argv )
  36.  int argc ;
  37.  char *argv[] ;
  38.  {
  39.   
  40.     if( argc != 2 ) {
  41.         Write( (long)Output(), argstring, 18L ) ;
  42.         exit( 1L ) ;
  43.         }
  44.  
  45.     if( ( infile = fopen( argv[1], "r" )) == 0) {
  46.         Write( (long)Output(),"can't open source file\x9bE.", 24L ) ;
  47.         exit( 1L ) ;
  48.         }
  49.  
  50.     newfile() ;
  51.  
  52.     while( 1 ) {
  53.         
  54.         if( ! ( p = fgets( buffer, BUFSIZE, infile ))) {
  55.              fclose( infile ) ;
  56.              break ;
  57.              }
  58.         else {   
  59.              fwrite( buffer, _BUILTIN_strlen(buffer), 1, outfile ) ;
  60.              if( ++linecount == MAXLINES ) {
  61.                   newfile() ;
  62.                   }
  63.              }
  64.         }
  65.  
  66.  } 
  67.     
  68.  
  69.  /*-----------------------------------------------
  70.   * newfile - closes any open dest file and opens    
  71.   *           a new one
  72.   */
  73.  
  74.    newfile()
  75.    {
  76.  
  77.      if( fileopen ) {
  78.           fclose( outfile ) ;
  79.           fileopen = 0 ;
  80.           }
  81.    
  82.      name[13] = fnam[5] = *(iter + count++) ;
  83.      Write( (long)Output(), name, 16L ) ;
  84.  
  85.      if( ( outfile = fopen( fnam, "w" ) ) == 0 ) {
  86.           Write( ( long )Output(), "Can't open dest file - ", 23L ) ;
  87.           Write( ( long )Output(), fnam, 6L ) ;
  88.           fclose( infile ) ;
  89.           exit( 1L ) ;
  90.           }
  91.      else {
  92.           fileopen = 1 ;
  93.           linecount = 0 ;
  94.           }
  95.    }
  96.