
/*******************************   stopper.c   ********************************
 *
 *  Program to demonstrate and test stop list filtering lexical analyzer DFA
 *  generator and driver functions.  This program assumes a stop list in the
 *  file stop.wrd.  It takes a single filename on the command line and lists
 *  unfiltered terms on stdout.
 *
**/

#include <stdio.h>

#include "strlist.h"
#include "stop.h"

/******************************************************************************/
/*FN***************************************************************************

        main( argc, argv )

   Returns: int -- 0 on success, 1 on failure

   Purpose: Program main function

   Plan:    Part 1: Read the stop list from the stop words file
            Part 2: Create a DFA from a stop list
            Part 3: Open the input file and list its terms
            Part 4: Close the input file and return

   Notes:   This program reads a stop list from a file called "stop.wrd,"
            and uses it in generating the terms in a file named on the
            command line.
**/

int
main( argc, argv )
   int argc;     /* in: how many arguments */
   char *argv[]; /* in: text of the arguments */
   {
   char term[128];  /* for the next term found */
   FILE *stream;    /* where to read characters from */
   StrList words;   /* the stop list filtered */
   DFA machine;     /* build from the stop list */

           /* Part 1: Read the stop list from the stop words file */
   words = StrListCreate();
   StrListAppendFile( words, "stop.wrd" );

                   /* Part 2: Create a DFA from a stop list */
   machine = BuildDFA( words );

              /* Part 3: Open the input file and list its terms */
   if ( !(stream = fopen(argv[1],"r")) ) exit(1);
   while ( NULL != GetTerm(stream,machine,128,term) )
      (void)printf( "%s\n", term );

                 /* Part 4: Close the input file and return */
   (void)fclose( stream );
   return(0);

   } /* main */
