From 74a4d8c26dd3c1e9febcb717cfd6cb6512991a7a Mon Sep 17 00:00:00 2001 From: "Charles.Forsyth" Date: Fri, 22 Dec 2006 21:39:35 +0000 Subject: 20060303 --- utils/libregexp/test.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 utils/libregexp/test.c (limited to 'utils/libregexp/test.c') diff --git a/utils/libregexp/test.c b/utils/libregexp/test.c new file mode 100644 index 00000000..49afd9bb --- /dev/null +++ b/utils/libregexp/test.c @@ -0,0 +1,46 @@ +#include +#include + +struct x +{ + char *re; + char *s; + Reprog *p; +}; + +struct x t[] = { + { "^[^!@]+$", "/bin/upas/aliasmail '&'", 0 }, + { "^local!(.*)$", "/mail/box/\\1/mbox", 0 }, + { "^plan9!(.*)$", "\\1", 0 }, + { "^helix!(.*)$", "\\1", 0 }, + { "^([^!]+)@([^!@]+)$", "\\2!\\1", 0 }, + { "^(uk\\.[^!]*)(!.*)$", "/bin/upas/uk2uk '\\1' '\\2'", 0 }, + { "^[^!]*\\.[^!]*!.*$", "inet!&", 0 }, + { "^(coma|research|pipe|pyxis|inet|hunny|gauss)!(.*)$", "/mail/lib/qmail '\s' 'net!\\1' '\\2'", 0 }, + { "^.*$", "/mail/lib/qmail '\s' 'net!research' '&'", 0 }, + { 0, 0, 0 }, +}; + + + +main(int ac, char **av) +{ + Resub rs[10]; + char dst[128]; + int n; + struct x *tp; + + for(tp = t; tp->re; tp++) + tp->p = regcomp(tp->re); + + + for(tp = t; tp->re; tp++){ + print("%s VIA %s", av[1], tp->re); + if(regexec(tp->p, av[1], rs, 10)){ + regsub(tp->s, dst, rs, 10); + print(" sub %s -> %s", tp->s, dst); + } + print("\n"); + } + exits(0); +} -- cgit v1.2.3