remove old libregexp files; add headers for upas/bayes

This commit is contained in:
ben 2016-04-26 22:26:03 -05:00
parent 0a460e1722
commit 0f8168038a
3 changed files with 66 additions and 113 deletions

View file

@ -0,0 +1,66 @@
#pragma src "/sys/src/oldlibregexp"
#pragma lib "oldlibregexp.a"
typedef struct Resub Resub;
typedef struct Reclass Reclass;
typedef struct Reinst Reinst;
typedef struct Reprog Reprog;
/*
* Sub expression matches
*/
struct Resub{
union
{
char *sp;
Rune *rsp;
};
union
{
char *ep;
Rune *rep;
};
};
/*
* character class, each pair of rune's defines a range
*/
struct Reclass{
Rune *end;
Rune spans[64];
};
/*
* Machine instructions
*/
struct Reinst{
int type;
union {
Reclass *cp; /* class pointer */
Rune r; /* character */
int subid; /* sub-expression id for RBRA and LBRA */
Reinst *right; /* right child of OR */
};
union { /* regexp relies on these two being in the same union */
Reinst *left; /* left child of OR */
Reinst *next; /* next instruction for CAT & LBRA */
};
};
/*
* Reprogram definition
*/
struct Reprog{
Reinst *startinst; /* start pc */
Reclass class[16]; /* .data */
Reinst firstinst[5]; /* .text */
};
extern Reprog *regcomp(char*);
extern Reprog *regcomplit(char*);
extern Reprog *regcompnl(char*);
extern void regerror(char*);
extern int regexec(Reprog*, char*, Resub*, int);
extern void regsub(char*, char*, int, Resub*, int);
extern int rregexec(Reprog*, Rune*, Resub*, int);
extern void rregsub(Rune*, Rune*, int, Resub*, int);

View file

@ -1,113 +0,0 @@
#include <u.h>
#include <libc.h>
#include "regexp.h"
#include "regcomp.h"
/*
* 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].sp==0 || sp->m[0].sp<mp[0].sp ||
(sp->m[0].sp==mp[0].sp && sp->m[0].ep>mp[0].ep)){
for(i=0; i<ms && i<NSUBEXP; i++)
mp[i] = sp->m[i];
for(; i<ms; i++)
mp[i].sp = mp[i].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 */
int ms,
Resublist *sep) /* pointers to subexpressions */
{
Relist *p;
for(p=lp; p->inst; p++){
if(p->inst == ip){
if(sep->m[0].sp < p->se.m[0].sp){
if(ms > 1)
p->se = *sep;
else
p->se.m[0] = sep->m[0];
}
return 0;
}
}
p->inst = ip;
if(ms > 1)
p->se = *sep;
else
p->se.m[0] = sep->m[0];
(++p)->inst = 0;
return p;
}
/*
* same as renewthread, but called with
* initial empty start pointer.
*/
extern Relist*
_renewemptythread(Relist *lp, /* _relist to add to */
Reinst *ip, /* instruction to add */
int ms,
char *sp) /* pointers to subexpressions */
{
Relist *p;
for(p=lp; p->inst; p++){
if(p->inst == ip){
if(sp < p->se.m[0].sp) {
if(ms > 1)
memset(&p->se, 0, sizeof(p->se));
p->se.m[0].sp = sp;
}
return 0;
}
}
p->inst = ip;
if(ms > 1)
memset(&p->se, 0, sizeof(p->se));
p->se.m[0].sp = sp;
(++p)->inst = 0;
return p;
}
extern Relist*
_rrenewemptythread(Relist *lp, /* _relist to add to */
Reinst *ip, /* instruction to add */
int ms,
Rune *rsp) /* pointers to subexpressions */
{
Relist *p;
for(p=lp; p->inst; p++){
if(p->inst == ip){
if(rsp < p->se.m[0].rsp) {
if(ms > 1)
memset(&p->se, 0, sizeof(p->se));
p->se.m[0].rsp = rsp;
}
return 0;
}
}
p->inst = ip;
if(ms > 1)
memset(&p->se, 0, sizeof(p->se));
p->se.m[0].rsp = rsp;
(++p)->inst = 0;
return p;
}