library.
/* -*-java-*-
*
- * $Id: AnagGUI.java,v 1.4 2001/02/19 19:19:11 mdw Exp $
+ * $Id: AnagGUI.java,v 1.5 2002/08/11 12:58:09 mdw Exp $
*
* Front-end GUI
*
/*----- Revision history --------------------------------------------------*
*
* $Log: AnagGUI.java,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:19:11 mdw
* Add `help' button. Lowercase input to the command.
*
});
add(b, g);
+ b = new Button("Regexp");
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) { getlist("-regexp"); }
+ });
+ add(b, g);
+
b = new Button("Trackword");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { getlist("-trackword"); }
/* -*-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.
*
-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\
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
};
{ "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 --- */
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);
/* -*-c-*-
*
- * $Id: anag.h,v 1.1 2001/02/04 17:14:42 mdw Exp $
+ * $Id: anag.h,v 1.2 2002/08/11 12:58:09 mdw Exp $
*
* External definitions for Anag
*
/*----- Revision history --------------------------------------------------*
*
* $Log: anag.h,v $
+ * Revision 1.2 2002/08/11 12:58:09 mdw
+ * Added support for regular expression matching, if supported by the C
+ * library.
+ *
* Revision 1.1 2001/02/04 17:14:42 mdw
* Initial checkin
*
extern node *subgram(const char *const */*av*/);
extern node *wildcard(const char *const */*av*/);
extern node *trackword(const char *const */*av*/);
+extern node *regexp(const char *const */*av*/);
/*----- Error reporting ---------------------------------------------------*/
--- /dev/null
+/* -*-c-*-
+ *
+ * $Id: regexp.c,v 1.1 2002/08/11 12:58:09 mdw Exp $
+ *
+ * Matches regular expressions
+ *
+ * (c) 2002 Mark Wooding
+ */
+
+/*----- Licensing notice --------------------------------------------------*
+ *
+ * This file is part of Anag: a simple wordgame helper.
+ *
+ * Anag is free software; you can 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.
+ *
+ * Anag 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
+ * along with Anag; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/*----- Revision history --------------------------------------------------*
+ *
+ * $Log: regexp.c,v $
+ * Revision 1.1 2002/08/11 12:58:09 mdw
+ * Added support for regular expression matching, if supported by the C
+ * library.
+ *
+ * Revision 1.1 2001/02/04 17:14:42 mdw
+ * Initial checkin
+ *
+ */
+
+/*----- Header files ------------------------------------------------------*/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#ifndef HAVE_REGCOMP
+ extern int dummy;
+#else
+
+#include "anag.h"
+#include <regex.h>
+
+/*----- Data structures ---------------------------------------------------*/
+
+typedef struct node_regexp {
+ node n;
+ const char *s;
+ regex_t rx;
+} node_regexp;
+
+/*----- Main code ---------------------------------------------------------*/
+
+/* --- Node matcher --- */
+
+static int n_regexp(node *nn, const char *p, size_t sz)
+{
+ node_regexp *n = (node_regexp *)nn;
+ int e;
+
+ switch (e = regexec(&n->rx, p, 0, 0, 0)) {
+ case 0:
+ return 1;
+ case REG_NOMATCH:
+ return 0;
+ default: {
+ char buf[256];
+ regerror(e, &n->rx, buf, sizeof(buf));
+ die("error matching regexp `%s' against `%s': %s",
+ n->s, p, buf);
+ } break;
+ }
+ return (0);
+}
+
+/* --- Node creation --- */
+
+node *regexp(const char *const *av)
+{
+ node_regexp *n = xmalloc(sizeof(*n));
+ int e;
+ n->n.func = n_regexp;
+ if ((e = regcomp(&n->rx, av[0],
+ REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0) {
+ char buf[256];
+ regerror(e, &n->rx, buf, sizeof(buf));
+ die("bad regular expression `%s': %s", av[0], buf);
+ }
+ return (&n->n);
+}
+
+/*----- That's all, folks -------------------------------------------------*/
+
+#endif