obj/lib/conf-test: obj/lib/conf-test.o obj/lib/libsh.a
obj/lib/sort-test: obj/lib/sort-test.o obj/lib/libsh.a
obj/lib/lfs-test: obj/lib/lfs-test.o obj/lib/libsh.a
+obj/lib/regex-test: obj/lib/regex-test.o obj/lib/libsh.a
typedef struct regex regex;
-regex *rx_compile(byte *r);
+regex *rx_compile(byte *r, int icase);
void rx_free(regex *r);
int rx_match(regex *r, byte *s);
int rx_subst(regex *r, byte *by, byte *src, byte *dest, uns destlen);
--- /dev/null
+/*
+ * Sherlock Library -- Regular Expressions Test
+ *
+ * (c) 2001 Robert Spalek <robert@ucw.cz>
+ */
+
+#include "lib/lib.h"
+
+#include <stdio.h>
+
+#define TEST(txt, should) printf(#txt ": %d (should %d)\n", rx_match(r, #txt), should)
+int
+main(void)
+{
+ regex *r;
+ r = rx_compile("a.*b.*c", 0);
+ TEST(abc, 1);
+ TEST(ajkhkbbbbbc, 1);
+ TEST(Aabc, 0);
+ rx_free(r);
+ r = rx_compile("a.*b.*c", 1);
+ TEST(aBc, 1);
+ TEST(ajkhkbBBBBC, 1);
+ TEST(Aabc, 1);
+ rx_free(r);
+ return 0;
+}
* Sherlock Library -- Regular Expressions
*
* (c) 1997 Martin Mares <mj@ucw.cz>
+ * (c) 2001 Robert Spalek <robert@ucw.cz>
*/
#include "lib/lib.h"
+#include "lib/chartype.h"
+#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <regex.h>
#define INITIAL_MEM 1024 /* Initial space allocated for each pattern */
+#define CHAR_SET_SIZE 256 /* How many characters in the character set. */
struct regex {
struct re_pattern_buffer buf;
};
regex *
-rx_compile(byte *p)
+rx_compile(byte *p, int icase)
{
regex *r = xmalloc_zero(sizeof(regex));
const char *msg;
r->buf.buffer = xmalloc(INITIAL_MEM);
r->buf.allocated = INITIAL_MEM;
+ if (icase)
+ {
+ unsigned i;
+ r->buf.translate = xmalloc (CHAR_SET_SIZE);
+ /* Map uppercase characters to corresponding lowercase ones. */
+ for (i = 0; i < CHAR_SET_SIZE; i++)
+ r->buf.translate[i] = Cupper(i) ? tolower (i) : i;
+ }
+ else
+ r->buf.translate = NULL;
msg = re_compile_pattern(p, strlen(p), &r->buf);
if (!msg)
return r;