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

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