Added support for regular expression matching, if supported by the C
[anag] / anag.c
diff --git a/anag.c b/anag.c
index 939f6b8..6be2a4e 100644 (file)
--- a/anag.c
+++ b/anag.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: anag.c,v 1.4 2001/02/19 19:18:50 mdw Exp $
+ * $Id: anag.c,v 1.5 2002/08/11 12:58:09 mdw Exp $
  *
  * Main driver for anag
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: anag.c,v $
+ * Revision 1.5  2002/08/11 12:58:09  mdw
+ * Added support for regular expression matching, if supported by the C
+ * library.
+ *
  * Revision 1.4  2001/02/19 19:18:50  mdw
  * Minor big fixes to parser.
  *
@@ -85,6 +89,13 @@ The basic tests in the expression are:\n\
 -subgram WORD          matches words which only use letters in WORD\n\
 -wildcard PATTERN      matches with wildcards `*' and `?'\n\
 -trackword WORD                matches words which can be found in a trackword\n\
+"
+#ifdef HAVE_REGCOMP
+"\
+-regexp REGEXP         matches with an (extended) regular expression\n\
+"
+#endif
+"\
 \n\
 These simple tests can be combined using the operators `-a', `-o' and `-n'\n\
 (for `and', `or' and `not'; they may also be written `&', `|' and `!' if\n\
@@ -107,7 +118,7 @@ enum {
   O_HELP, O_VERSION, O_USAGE,
   O_FILE,
   O_AND, O_OR, O_NOT, O_LPAREN, O_RPAREN,
-  O_ANAG, O_SUBG, O_WILD, O_TRACK,
+  O_ANAG, O_SUBG, O_WILD, O_TRACK, O_REGEXP,
   O_EOF
 };
 
@@ -137,6 +148,9 @@ static const struct opt opttab[] = {
   { "subgram",         1,      0,              O_SUBG },
   { "wildcard",                1,      0,              O_WILD },
   { "trackword",       1,      0,              O_TRACK },
+#ifdef HAVE_REGCOMP
+  { "regexp",          1,      0,              O_REGEXP },
+#endif
 
   /* --- End marker --- */
 
@@ -337,6 +351,9 @@ static void p_factor(p_ctx *p, node **nn)
       case O_SUBG: *nn = subgram(p->a + 1); break;
       case O_WILD: *nn = wildcard(p->a + 1); break;
       case O_TRACK: *nn = trackword(p->a + 1); break;
+#ifdef HAVE_REGCOMP
+      case O_REGEXP: *nn = regexp(p->a + 1); break;
+#endif
       default: die("syntax error near `%s': unexpected token", *p->a);
     }
     p_next(p);