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

  1. /*
  2.  * Usage -  f_trail [/4] < ASCII text > revised
  3.  *
  4.  * F_TRAIL  Remove trailing blanks from lines of ASCII text.  The /4
  5.  *          option is for backward compatability only; it leaves a
  6.  *          blank in the fourth column where a line consists of a
  7.  *          three digit field number only.
  8.  *
  9.  * input:   Any printable ASCII file.
  10.  *
  11.  * output:  The same file with trailing blanks removed from each line.
  12.  *
  13.  *  writeup: MIR TUTORIAL ONE, topic 9
  14.  *
  15.  *  Written:    Douglas Lowry   May 08 92
  16.  *              Copyright (C) 1992 Marpex Inc.
  17.  *
  18.  *    The MIR (Mass Indexing and Retrieval) Tutorials explain detailed
  19.  *    usage and co-ordination of the MIR family of programs to analyze,
  20.  *    prepare and index databases (small through gigabyte size), and
  21.  *    how to build integrated retrieval software around the MIR search
  22.  *    engine.  The fifth of the five MIR tutorial series explains how
  23.  *    to extend indexing capability into leading edge search-related
  24.  *    technologies.  For more information, GO IBMPRO on CompuServe;
  25.  *    MIR files are in the DBMS library.  The same files are on the
  26.  *    Canada Remote Systems BBS.  A diskette copy of the Introduction
  27.  *    is available by mail ($10 US... check, Visa or Mastercard);
  28.  *    diskettes with Introduction, Tutorial ONE software and the
  29.  *    shareware Tutorial ONE text cost $29.  Shareware registration
  30.  *    for a tutorial is also $29.
  31.  *
  32.  *    E-mail...
  33.  *                Compuserve  71431,1337
  34.  *                Internet    doug.lowry%canrem.com
  35.  *                UUCP        canrem!doug.lowry
  36.  *                Others:     doug.lowry@canrem.uucp
  37.  *
  38.  *    FAX...                  416 963-5677
  39.  *
  40.  *    "Snail mail"...         Douglas Lowry, Ph.D.
  41.  *                            Marpex Inc.
  42.  *                            5334 Yonge Street, #1102
  43.  *                            North York, Ontario
  44.  *                            Canada  M2N 6M2
  45.  *
  46.  *    Related database consultation and preparation services are
  47.  *    available through:
  48.  *              Innotech Inc., 2001 Sheppard Avenue E., Suite #118,
  49.  *              North York, Ontario  Canada   M2J 4Z7
  50.  *              Tel.  416 492-3838   FAX  416 492-3843
  51.  *
  52.  *  This program is free software; you may redistribute it and/or
  53.  *  modify it under the terms of the GNU General Public License as
  54.  *  published by the Free Software Foundation; either version 2 of
  55.  *  the License, or (at your option) any later version.
  56.  *
  57.  *  This program is distributed in the hope that it will be useful,
  58.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  59.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  60.  *  GNU General Public License for more details.
  61.  *
  62.  *  You should have received a copy of the GNU General Public License
  63.  *  (file 05LICENS) along with this program; if not, write to the
  64.  *  Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
  65.  *  USA.
  66.  */
  67.  
  68. #include <stdio.h>
  69. #include <stdlib.h>
  70.  
  71. #define     MAX_BYTES   4096
  72. #define     repeat      for(;;)
  73.  
  74. /*
  75.  * declarations
  76.  */
  77.  
  78. typedef     enum        _bool
  79.              { FALSE = 0, TRUE = 1 }  Bool;
  80.  
  81.     void        Usage_(), process();
  82.     char        *Cmdname_() {    return( "f_trail" );  }
  83.  
  84. /*
  85.  * MAIN
  86.  */
  87.  
  88. main( argc, argv )
  89.     int  argc;
  90.     char **argv;
  91. {
  92.     Bool        four ;      /*  Leave blank after field number */
  93.     char        c10 ;
  94.  
  95.     if( argc > 2 )
  96.         Usage_() ;
  97.  
  98.     four = FALSE ;
  99.     if( argc == 2 )
  100.     {
  101.         c10 = argv[1][0] ;
  102.         if(( c10 == '-' || c10 == '/' ) && argv[1][1] == '4' )
  103.             four = TRUE ;
  104.         else
  105.             Usage_() ;
  106.     }
  107.  
  108.     process( four ) ;
  109.  
  110.     exit( 0 );
  111. }
  112. /*
  113.  *  Usage
  114.  */
  115.     void
  116. Usage_()
  117. {
  118.     fprintf( stderr,
  119. "\nUsage:  %s  [/4] < ASCII text > revised\n\n\
  120.         Remove trailing blanks from lines of ASCII text.  The /4\n\
  121.         option is for backward compatability only; it leaves a\n\
  122.         blank in the fourth column where a line consists of a\n\
  123.         three digit field number only.\n\n", Cmdname_() ) ;
  124.     fprintf( stderr,
  125. "input:  Any printable ASCII file.\n\n\
  126. output: The same file with trailing blanks removed from each line.\n\n\
  127. writeup: MIR TUTORIAL ONE, topic 9\n\n" ) ;
  128.     exit( 1 ) ;
  129. }
  130. /*
  131.  *  PROCESS
  132.  */
  133.     void
  134. process( four )
  135.     Bool        four ;      /*  Leave blank after field number */
  136. {
  137.     char    line_in[ MAX_BYTES ];
  138.     int     len ;
  139.  
  140.     while( fgets( line_in, MAX_BYTES, stdin ) != NULL )
  141.     {
  142.         len = strlen( line_in ) - 1 ;
  143.         if( len > MAX_BYTES - 4 )
  144.         {
  145.             fprintf( stderr, "FATAL... line length exceeds %d bytes.\n",
  146.                 MAX_BYTES ) ;
  147.             exit( 1 ) ;
  148.         }
  149.         while( line_in[ len - 1 ] == ' ' )
  150.             len-- ;
  151.  
  152.         if( four && len == 3 )
  153.         {
  154.             line_in[3] = ' ' ;
  155.             len = 4 ;
  156.         }
  157.  
  158.         line_in[ len ] = '\0' ;
  159.  
  160.         if( puts( line_in ))
  161.         {
  162.             fprintf( stderr, "FATAL... unable to write.\n" );
  163.             exit( 1 ) ;
  164.         }
  165.     }
  166.  
  167.     putchar( '\032' ) ;
  168.     return ;
  169. }
  170.