ref: ff8ae67b705129e20b4177aa4a0c85dab343e5bb
parent: c00c60d327168c25e56077c8310cf2380833e9be
author: spew <devnull@localhost>
date: Sun Apr 30 11:08:36 EDT 2017
libregexp: miscellaneous little cleanups
--- a/sys/man/2/regexp
+++ b/sys/man/2/regexp
@@ -210,6 +210,8 @@
is not matched.
.SH BUGS
There is no way to specify or match a NUL character; NULs terminate patterns and strings.
+The size of a character class and the number of sub-expression matches are hard-coded
+limits. The library uses the worst-case space estimate for allocating VM runtime threads.
.SH HISTORY
.IR Regexp (2)
first appeared in Plan 9 from Bell Labs. This implementation was written from
--- a/sys/src/libregexp/regcomp.c
+++ b/sys/src/libregexp/regcomp.c
@@ -308,7 +308,7 @@
{
l->literal = 0;
if(l->done) {
- l->rune = 0;
+ l->rune = L'\0';
return;
}
l->rawexp += chartorune(&l->rune, l->rawexp);
@@ -327,7 +327,7 @@
l->literal = 1;
if(l->done) {
l->literal = 0;
- l->rune = 0;
+ l->rune = L'\0';
return;
}
l->rawexp += chartorune(&l->rune, l->rawexp);
@@ -347,7 +347,7 @@
if(l->literal)
return l->peeklex = LRUNE;
switch(l->rune){
- case 0:
+ case L'\0':
return l->peeklex = LEND;
case L'*':
case L'?':
@@ -375,16 +375,20 @@
static int
pcmp(void *va, void *vb)
{
- vlong n;
Rune *a, *b;
a = va;
b = vb;
- n = (vlong)b[0] - (vlong)a[0];
- if(n)
- return n;
- return (vlong)b[1] - (vlong)a[1];
+ if(a[0] < b[0])
+ return 1;
+ if(a[0] > b[0])
+ return -1;
+ if(a[1] < b[1])
+ return 1;
+ if(a[1] > b[1])
+ return -1;
+ return 0;
}
static void
@@ -460,7 +464,7 @@
q[2] = 0;
}
-/* classes are in descending order */
+/* classes are in descending order see pcmp */
static Renode*
buildclassn(Parselex *l)
{
--- a/sys/src/libregexp/regimpl.h
+++ b/sys/src/libregexp/regimpl.h
@@ -23,7 +23,7 @@
TSTAR,
TSUB,
- NSUBEXPM = 32
+ NSUBEXPM = 32,
};
typedef struct Parselex Parselex;
@@ -31,22 +31,15 @@
struct Parselex {
/* Parse */
- Renode *next;
- Renode *nodes;
- int sub;
- int instrs;
+ Renode *next, *nodes;
+ int sub, instrs;
jmp_buf exitenv;
/* Lex */
void (*getnextr)(Parselex*);
- char *rawexp;
- char *orig;
+ char *rawexp, *orig;
Rune rune;
- Rune peek;
- int peeklex;
- int done;
- int literal;
+ int peek, peeklex, done, literal, nc;
Rune cpairs[400+2];
- int nc;
};
struct Renode {
@@ -53,8 +46,7 @@
int op;
Renode *left;
Rune r;
- union
- {
+ union {
Rune r1;
int sub;
Renode *right;
@@ -73,13 +65,11 @@
char op;
int gen;
Reinst *a;
- union
- {
+ union {
Rune r;
int sub;
};
- union
- {
+ union {
Rune r1;
Reinst *b;
};