summaryrefslogtreecommitdiff
path: root/sys/src/ape/lib/regexp/regaux.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/ape/lib/regexp/regaux.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/ape/lib/regexp/regaux.c')
-rwxr-xr-xsys/src/ape/lib/regexp/regaux.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/sys/src/ape/lib/regexp/regaux.c b/sys/src/ape/lib/regexp/regaux.c
new file mode 100755
index 000000000..6643b8ff8
--- /dev/null
+++ b/sys/src/ape/lib/regexp/regaux.c
@@ -0,0 +1,56 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include "regexp.h"
+#include "regcomp.h"
+
+/*
+ * Machine state
+ */
+Relist* _relist[2];
+Relist* _reliste[2];
+int _relistsize = LISTINCREMENT;
+
+/*
+ * save a new match in mp
+ */
+extern void
+_renewmatch(Resub *mp, int ms, Resublist *sp)
+{
+ int i;
+
+ if(mp==0 || ms<=0)
+ return;
+ if(mp[0].s.sp==0 || sp->m[0].s.sp<mp[0].s.sp ||
+ (sp->m[0].s.sp==mp[0].s.sp && sp->m[0].e.ep>mp[0].e.ep)){
+ for(i=0; i<ms && i<NSUBEXP; i++)
+ mp[i] = sp->m[i];
+ for(; i<ms; i++)
+ mp[i].s.sp = mp[i].e.ep = 0;
+ }
+}
+
+/*
+ * Note optimization in _renewthread:
+ * *lp must be pending when _renewthread called; if *l has been looked
+ * at already, the optimization is a bug.
+ */
+extern Relist*
+_renewthread(Relist *lp, /* _relist to add to */
+ Reinst *ip, /* instruction to add */
+ Resublist *sep) /* pointers to subexpressions */
+{
+ Relist *p;
+
+ for(p=lp; p->inst; p++){
+ if(p->inst == ip){
+ if((sep)->m[0].s.sp < p->se.m[0].s.sp)
+ p->se = *sep;
+ return 0;
+ }
+ }
+ p->inst = ip;
+ p->se = *sep;
+ (++p)->inst = 0;
+ return p;
+}
+