hbase

heirloom base
git clone git://git.2f30.org/hbase
Log | Files | Refs | README

test.c (1003B)


      1 #include "lib9.h"
      2 #include <regexp9.h>
      3 
      4 struct x
      5 {
      6 	char *re;
      7 	char *s;
      8 	Reprog *p;
      9 };
     10 
     11 struct x t[] = {
     12 	{ "^[^!@]+$", "/bin/upas/aliasmail '&'", 0 },
     13 	{ "^local!(.*)$", "/mail/box/\\1/mbox", 0 },
     14 	{ "^plan9!(.*)$", "\\1", 0 },
     15 	{ "^helix!(.*)$", "\\1", 0 },
     16 	{ "^([^!]+)@([^!@]+)$", "\\2!\\1", 0 },
     17 	{ "^(uk\\.[^!]*)(!.*)$", "/bin/upas/uk2uk '\\1' '\\2'", 0 },
     18 	{ "^[^!]*\\.[^!]*!.*$", "inet!&", 0 },
     19 	{ "^\xE2\x98\xBA$", "smiley", 0 },
     20 	{ "^(coma|research|pipe|pyxis|inet|hunny|gauss)!(.*)$", "/mail/lib/qmail '\\s' 'net!\\1' '\\2'", 0 },
     21 	{ "^.*$", "/mail/lib/qmail '\\s' 'net!research' '&'", 0 },
     22 	{ 0, 0, 0 },
     23 };
     24 
     25 main(int ac, char **av)
     26 {
     27 	Resub rs[10];
     28 	char dst[128];
     29 	int n;
     30 	struct x *tp;
     31 
     32 	for(tp = t; tp->re; tp++)
     33 		tp->p = regcomp(tp->re);
     34 
     35 
     36 	for(tp = t; tp->re; tp++){
     37 		print("%s VIA %s", av[1], tp->re);
     38 		memset(rs, 0, sizeof rs);
     39 		if(regexec(tp->p, av[1], rs, 10)){
     40 			regsub(tp->s, dst, sizeof dst, rs, 10);
     41 			print(" sub %s -> %s", tp->s, dst);
     42 		}
     43 		print("\n");
     44 	}
     45 	exit(0);
     46 }