home *** CD-ROM | disk | FTP | other *** search
- /*
- * Usage - f_trail [/4] < ASCII text > revised
- *
- * F_TRAIL Remove trailing blanks from lines of ASCII text. The /4
- * option is for backward compatability only; it leaves a
- * blank in the fourth column where a line consists of a
- * three digit field number only.
- *
- * input: Any printable ASCII file.
- *
- * output: The same file with trailing blanks removed from each line.
- *
- * writeup: MIR TUTORIAL ONE, topic 9
- *
- * Written: Douglas Lowry May 08 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>
-
- #define MAX_BYTES 4096
- #define repeat for(;;)
-
- /*
- * declarations
- */
-
- typedef enum _bool
- { FALSE = 0, TRUE = 1 } Bool;
-
- void Usage_(), process();
- char *Cmdname_() { return( "f_trail" ); }
-
- /*
- * MAIN
- */
-
- main( argc, argv )
- int argc;
- char **argv;
- {
- Bool four ; /* Leave blank after field number */
- char c10 ;
-
- if( argc > 2 )
- Usage_() ;
-
- four = FALSE ;
- if( argc == 2 )
- {
- c10 = argv[1][0] ;
- if(( c10 == '-' || c10 == '/' ) && argv[1][1] == '4' )
- four = TRUE ;
- else
- Usage_() ;
- }
-
- process( four ) ;
-
- exit( 0 );
- }
- /*
- * Usage
- */
- void
- Usage_()
- {
- fprintf( stderr,
- "\nUsage: %s [/4] < ASCII text > revised\n\n\
- Remove trailing blanks from lines of ASCII text. The /4\n\
- option is for backward compatability only; it leaves a\n\
- blank in the fourth column where a line consists of a\n\
- three digit field number only.\n\n", Cmdname_() ) ;
- fprintf( stderr,
- "input: Any printable ASCII file.\n\n\
- output: The same file with trailing blanks removed from each line.\n\n\
- writeup: MIR TUTORIAL ONE, topic 9\n\n" ) ;
- exit( 1 ) ;
- }
- /*
- * PROCESS
- */
- void
- process( four )
- Bool four ; /* Leave blank after field number */
- {
- char line_in[ MAX_BYTES ];
- int len ;
-
- while( fgets( line_in, MAX_BYTES, stdin ) != NULL )
- {
- len = strlen( line_in ) - 1 ;
- if( len > MAX_BYTES - 4 )
- {
- fprintf( stderr, "FATAL... line length exceeds %d bytes.\n",
- MAX_BYTES ) ;
- exit( 1 ) ;
- }
- while( line_in[ len - 1 ] == ' ' )
- len-- ;
-
- if( four && len == 3 )
- {
- line_in[3] = ' ' ;
- len = 4 ;
- }
-
- line_in[ len ] = '\0' ;
-
- if( puts( line_in ))
- {
- fprintf( stderr, "FATAL... unable to write.\n" );
- exit( 1 ) ;
- }
- }
-
- putchar( '\032' ) ;
- return ;
- }