home *** CD-ROM | disk | FTP | other *** search
- /*
- * usage - a_occur3 < occur_file > expanded_file
- *
- * A_OCCUR3 Reverse an A_OCCUR file by removing the initial count,
- * then outputting each line the number of times indicated
- * by the count. Useful if editing an A_OCCUR file, then
- * reconstituting it.
- *
- * input: ASCII file with each line containing a count, blank
- * padded to the sixth character, then the line content.
- *
- * output: Same content, but with leading six characters removed
- * and content repeated for "count" lines.
- *
- * writeup: MIR TUTORIAL ONE, topic five.
- *
- * Written: Douglas Lowry Oct 28 91
- * Modified: Douglas Lowry Apr 30 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 512
- #define repeat for(;;)
-
- /*
- * declarations
- */
-
- typedef enum _bool
- { FALSE = 0, TRUE = 1 } Bool;
-
- void Usage_(), process();
- char *Cmdname_() { return( "a_occur3" ); }
-
- /*
- * MAIN
- */
-
- main( argc, argv )
- int argc;
- char **argv;
- {
- if( argc != 1 )
- Usage_() ;
-
- process() ;
-
- exit( 0 ) ;
- }
- /*
- * Usage_
- */
- void
- Usage_()
- {
- fprintf( stderr,
- "\nusage: %s < occur_file > expanded_file\n\n\
- Reverse an A_OCCUR file by removing the initial count,\n\
- then outputting each line the number of times indicated\n\
- by the count. Useful if editing an A_OCCUR file, then\n\
- reconstituting it.\n\n",
- Cmdname_() );
- fprintf( stderr,
- "input: ASCII file with each line containing a count, blank\n\
- padded to the sixth character, then the line content.\n\n\
- output: Same content, but with leading six characters removed\n\
- and content repeated for \"count\" lines.\n\n\
- writeup: MIR TUTORIAL ONE, topic five.\n\n" ) ;
- exit( 1 ) ;
- }
- /*
- * PROCESS
- */
- void
- process()
- {
- char buf[ MAX_BYTES ];
- long int
- freq ; /* count of occurrences of line */
- int lines_in, /* count */
- len, j;
-
- lines_in = 0 ;
-
- while( fgets( buf, MAX_BYTES, stdin ) != NULL )
- {
- lines_in++ ;
- len = strlen( buf ) - 1 ;
- buf[len] = '\0'; /* replace linefeed */
-
- freq = atol( buf ) ;
- if( freq < 1 )
- {
- fprintf( stderr, "\tCheck line %d...\n%s\n",
- lines_in, buf );
- Usage_() ;
- }
-
- for( j = 0 ; j < freq ; j++ )
- puts( &buf[ 6 ] );
- }
-
- return ;
- }