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

  1. /*
  2.  *  Usage - colrm from_col to_col < printable_ascii > revised_ascii
  3.  *
  4.  *  COLRM   Removes the specified range of columns from each line of an
  5.  *          ASCII file.  This is a clone of the Unix "colrm" utility.
  6.  *
  7.  *  input:  A printable ASCII file with less than 512 characters per
  8.  *          line.  Columns number from 1 upward.
  9.  *
  10.  *  output: The same number of lines, but with one segment of columns
  11.  *          removed from each line.
  12.  *
  13.  *  writeup: MIR TUTORIAL ONE, topic 7
  14.  *
  15.  *  Written:    Douglas Lowry   Jun 21 90
  16.  *  Modified:   Douglas Lowry   Feb 15 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 <dos.h>
  72. #include <ctype.h>
  73. #include <direct.h>
  74.  
  75. #define     MAX_BYTES   512
  76.  
  77. #define     repeat      for(;;)
  78.  
  79. typedef     enum        _bool
  80.             { FALSE = 0, TRUE = 1 }  Bool;
  81. /*
  82.  *  declarations
  83.  */
  84.  
  85.     void    Usage_(), process();
  86.     char    *Cmdname_() {   return( "colrm" );    }
  87.  
  88. /*
  89.  *  MAIN
  90.  */
  91.  
  92. main( argc, argv )
  93.     int argc;
  94.     char    **argv;
  95. {
  96.     int to, from ;
  97.  
  98.     if( argc != 3 || !isdigit( argv[1][0] ))
  99.         Usage_();
  100.  
  101.     from = atoi( argv[1] );
  102.     to   = atoi( argv[2] );
  103.     if( to < from )
  104.         to = from ;
  105.  
  106.     process( from, to );
  107.  
  108.     exit( 0 );
  109. }
  110. /*
  111.  *  Usage
  112.  */
  113.     void
  114. Usage_()
  115. {
  116.     fprintf( stderr,
  117.     "\nusage:  %s from_col to_col < printable_ascii > revised_ascii\n\n\
  118.         Removes the specified range of columns from each line of an\n\
  119.         ASCII file.  This is a clone of the Unix \"colrm\" utility.\n\n",
  120.                 Cmdname_() ) ;
  121.     fprintf( stderr,
  122. "input:  A printable ASCII file with less than 512 characters per\n\
  123.         line.  Columns number from 1 upward.\n\n\
  124. output: The same number of lines, but with one segment of columns\n\
  125.         removed from each line.\n\n\
  126. writeup: MIR TUTORIAL ONE, topic 7\n\n" );
  127.     exit( 1 ) ;
  128. }
  129. /*
  130.  * PROCESS
  131.  */
  132.     void
  133. process( from_col, to_col )
  134.     int from_col, to_col ;
  135. {
  136.     char    line_in[ MAX_BYTES ] ;
  137.     int len, i ;
  138.     Bool    after_nl;   /*  after a new line        */
  139.  
  140.     after_nl = TRUE;
  141.  
  142.     while( gets( line_in ) != NULL )
  143.     {
  144.         len = strlen( line_in );
  145.         if( len > MAX_BYTES - 2 )
  146.         {
  147.             fprintf( stderr, "FATAL... Line exceeds %d bytes.\n\n",
  148.                 len );
  149.             exit( 1 );
  150.         }
  151.         for( i = 0 ; ( i < from_col - 1 && i < len ) ; i++ )
  152.             putchar( line_in[i] );
  153.         for( i = to_col ; i < len ; i++ )
  154.             putchar( line_in[i] );
  155.         putchar( '\n' );
  156.     }
  157.  
  158.     return ;
  159. }
  160.