home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume36 / unpost / part06 / retest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-18  |  1.8 KB  |  68 lines

  1. /******************************************************************************
  2. * Module    :   Regular Expression Test Driver --- Test the regular expression
  3. *               package.
  4. *
  5. * Author    :   John Stevens
  6. ******************************************************************************/
  7.  
  8. #include    "compiler.h"
  9.  
  10. #include    "sets.h"
  11. #include    "regexp.h"
  12. #include    "utils.h"
  13.  
  14. FILE    *ErrFile = stderr;
  15.  
  16. int     main(int    argc,
  17.              char   **argv)
  18. {
  19.     register    int             i;
  20.     auto        REG_EXP_NODE    *ReExpr;
  21.     auto        FILE            *fp;
  22.     auto        char            **SubStrs;
  23.     auto        char            Bfr[256];
  24.  
  25.     /*  Check command line parameters.  */
  26.     if (argc != 3)
  27.     {
  28.         fprintf(stderr,
  29.                 "%s %d : Error - Syntax is: ",
  30.                 __FILE__,
  31.                 __LINE__);
  32.         fprintf(stderr,
  33.                 "%s <regular expression> <file name>\n",
  34.                 argv[0]);
  35.         exit( 1 );
  36.     }
  37.  
  38.     /*  Compile the regular expression. */
  39.     ReExpr = ReCompile( argv[1] );
  40.  
  41.     /*  Match against a line from a test file.  */
  42.     if ((fp = fopen(argv[2], TXT_READ)) == NULL)
  43.     {
  44.         fprintf(stderr,
  45.                 "Error, could not open file '%s' for reading.\n",
  46.                 argv[2]);
  47.         exit( 1 );
  48.     }
  49.  
  50.     /*  Search file for matching regular expressions, and print all
  51.     *   matched sub-strings.
  52.     */
  53.     while (fgets(Bfr, 256, fp) != NULL)
  54.     {
  55.         /*  Attempt match.  */
  56.         SubStrs = NULL;
  57.         if (ReMatch(Bfr, CASE_SENSITIVE, ReExpr, &SubStrs) != 0)
  58.         {
  59.             /*  Print matching line and matching sub-strings.   */
  60.             printf("Line: '%s'\n", Bfr);
  61.             for (i = 0; i < MAX_SUB_EXPRS; i++)
  62.                 if ( SubStrs[i] )
  63.                     printf("    #%2d: '%s'\n", i, SubStrs[i]);
  64.         }
  65.     }
  66.     return( 0 );
  67. }
  68.