plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

dump.c (1232B)


      1 #include <u.h>
      2 #include <libc.h>
      3 #include <bio.h>
      4 #include <regexp.h>
      5 #include "/sys/src/libregexp/regcomp.h"
      6 #include "dfa.h"
      7 
      8 #define DUMP
      9 
     10 void
     11 dump(Dreprog *pp)
     12 {
     13 	int i, j;
     14 	Dreinst *l;
     15 
     16 	print("start %ld %ld %ld %ld\n",
     17 		pp->start[0]-pp->inst,
     18 		pp->start[1]-pp->inst,
     19 		pp->start[2]-pp->inst,
     20 		pp->start[3]-pp->inst);
     21 
     22 	for(i=0; i<pp->ninst; i++){
     23 		l = &pp->inst[i];
     24 		print("%d:", i);
     25 		for(j=0; j<l->nc; j++){
     26 			print(" [");
     27 			if(j == 0)
     28 				if(l->c[j].start > 1)
     29 					print("<bad start %d>\n", l->c[j].start);
     30 			if(j != 0)
     31 				print("%C%s", l->c[j].start&0xFFFF, (l->c[j].start&0x10000) ? "$" : "");
     32 			print("-");
     33 			if(j != l->nc-1)
     34 				print("%C%s", (l->c[j+1].start&0xFFFF)-1, (l->c[j+1].start&0x10000) ? "$" : "");
     35 			print("] %ld", l->c[j].next - pp->inst);
     36 		}
     37 		if(l->isfinal)
     38 			print(" final");
     39 		if(l->isloop)
     40 			print(" loop");
     41 		print("\n");
     42 	}
     43 }
     44 
     45 
     46 void
     47 main(int argc, char **argv)
     48 {
     49 	int i;
     50 	Reprog *p;
     51 	Dreprog *dp;
     52 
     53 	i = 1;
     54 		p = regcomp(argv[i]);
     55 		if(p == 0){
     56 			print("=== %s: bad regexp\n", argv[i]);
     57 		}
     58 	/*	print("=== %s\n", argv[i]); */
     59 	/*	rdump(p); */
     60 		dp = dregcvt(p);
     61 		print("=== dfa\n");
     62 		dump(dp);
     63 
     64 	for(i=2; i<argc; i++)
     65 		print("match %d\n", dregexec(dp, argv[i], 1));
     66 	exits(0);
     67 }