home *** CD-ROM | disk | FTP | other *** search
- /*
- * Usage - line_num [ starting_line_no ] < stdin > stdout
- *
- * LINE_NUM Assign a sequence number to each line in a file, starting
- * either at zero or at a user-specified sequence number.
- *
- * input: Any printable ASCII file.
- *
- * output: One line for each line of input. A sequence number is left
- * justified, followed by a tab, then the input line exactly as
- * received. Empty lines are counted, but left empty.
- *
- * writeup: MIR TUTORIAL ONE, topic 6
- *
- * Written: Douglas Lowry Feb 17 92
- * Modified: Douglas Lowry May 08 92 argument
- * 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>
- #include <ctype.h>
-
- #define MAX_BYTES 4096
- #define repeat for(;;)
-
- /*
- * declarations
- */
-
- typedef enum _bool
- { FALSE = 0, TRUE = 1 } Bool;
-
- void Usage_(), process();
- char *Cmdname_() { return( "line_num" ); }
-
- /*
- * MAIN
- */
-
- main( argc, argv )
- int argc;
- char **argv;
- {
- long int bgn_at ; /* opening sequence number */
-
- if( argc > 2 )
- Usage_() ;
- bgn_at = 0 ;
-
- if( argc == 2 )
- {
- if( !isdigit( argv[1][0] ))
- Usage_() ;
- bgn_at = atol( argv[ 1 ] ) ;
- }
-
- process( bgn_at ) ;
-
- exit( 0 );
- }
- /*
- * Usage
- */
- void
- Usage_()
- {
- fprintf( stderr,
- "\nUsage: %s [ starting_line_no ] < stdin > stdout\n\n\
- Assign a sequence number to each line in a file, starting\n\
- either at zero or at a user-specified sequence number.\n\n\
- input: Any printable ASCII file.\n\n", Cmdname_() );
- fprintf( stderr,
- "output: One line for each line of input. A sequence number is left\n\
- justified, followed by a tab, then the input line exactly as\n\
- received. Empty lines are counted, but left empty.\n\n\
- writeup: MIR TUTORIAL ONE, topic 6\n\n" ) ;
- exit( 1 ) ;
- }
- /*
- * PROCESS
- */
- void
- process( bgn_at )
- long int bgn_at ;
- {
- char line_in[ MAX_BYTES ];
- long int line_no ;
- int len ;
-
- line_no = bgn_at - 1 ;
-
- while( fgets( line_in, MAX_BYTES, stdin ) != NULL )
- {
- line_no++ ;
- len = strlen( line_in ) - 1 ;
- if( len > MAX_BYTES - 4 )
- {
- fprintf( stderr, "FATAL... line length exceeds %d bytes.\n",
- MAX_BYTES ) ;
- exit( 1 ) ;
- }
- line_in[ len ] = '\0' ;
- if( len )
- {
- if( !printf( "%ld\t%s\n", line_no, line_in ))
- {
- fprintf( stderr, "FATAL... unable to write.\n" );
- exit( 1 ) ;
- }
- }
- else
- putchar( '\n' );
- }
-
- return ;
- }