]> git.lizzy.rs Git - plan9front.git/blob - sys/include/ape/regexp.h
libsec: use tsmemcmp() when comparing hashes, use mpfield() for ecc, use mptober...
[plan9front.git] / sys / include / ape / regexp.h
1 #ifndef __REGEXP_H
2 #define __REGEXP_H
3 #ifndef _REGEXP_EXTENSION
4     This header file is an extension to ANSI/POSIX
5 #endif
6 #pragma lib "/$M/lib/ape/libregexp.a"
7
8 #ifdef  UTF
9 #define Runeself        0xA0
10 #else
11 #define Runeself        0
12 #endif
13
14 typedef struct Resub            Resub;
15 typedef struct Reclass          Reclass;
16 typedef struct Reinst           Reinst;
17 typedef struct Reprog           Reprog;
18
19 /*
20  *      Sub expression matches
21  */
22 struct Resub{
23         union
24         {
25                 char *sp;
26                 wchar_t *rsp;
27         } s;
28         union
29         {
30                 char *ep;
31                 wchar_t *rep;
32         } e;
33 };
34
35 /*
36  *      character class, each pair of rune's defines a range
37  */
38 struct Reclass{
39         wchar_t *end;
40         wchar_t spans[64];
41 };
42
43 /*
44  *      Machine instructions
45  */
46 struct Reinst{
47         int     type;                   /* < 0200 ==> literal, otherwise action */
48         union   {
49                 Reclass *cp;            /* class pointer */
50                 wchar_t r;              /* character */
51                 int     subid;          /* sub-expression id for RBRA and LBRA */
52                 Reinst  *right;         /* right child of OR */
53         } r;
54         union { /* regexp relies on these two being in the same union */
55                 Reinst *left;           /* left child of OR */
56                 Reinst *next;           /* next instruction for CAT & LBRA */
57         } l;
58 };
59
60 /*
61  *      Reprogram definition
62  */
63 struct Reprog{
64         Reinst  *startinst;     /* start pc */
65         Reclass class[16];      /* .data */
66         Reinst  firstinst[5];   /* .text */
67 };
68
69 extern Reprog   *regcomp(char*);
70 extern Reprog   *regcomplit(char*);
71 extern Reprog   *regcompnl(char*);
72 extern void     regerror(char*);
73 extern int      regexec(Reprog*, char*, Resub*, int);
74 extern void     regsub(char*, char*, int, Resub*, int);
75 extern int      rregexec(Reprog*, wchar_t*, Resub*, int);
76 extern void     rregsub(wchar_t*, wchar_t*, int, Resub*, int);
77 #endif