9base

revived minimalist port of Plan 9 userland to Unix
git clone git://git.suckless.org/9base
Log | Files | Refs | README | LICENSE

regcomp.h (2091B)


      1 /*
      2  *  substitution list
      3  */
      4 #define uchar __reuchar
      5 typedef unsigned char uchar;
      6 #define nelem(x) (sizeof(x)/sizeof((x)[0]))
      7 
      8 #define NSUBEXP 32
      9 typedef struct Resublist	Resublist;
     10 struct	Resublist
     11 {
     12 	Resub	m[NSUBEXP];
     13 };
     14 
     15 /* max character classes per program */
     16 extern Reprog	RePrOg;
     17 #define	NCLASS	(sizeof(RePrOg.class)/sizeof(Reclass))
     18 
     19 /* max rune ranges per character class */
     20 #define NCCRUNE	(sizeof(Reclass)/sizeof(Rune))
     21 
     22 /*
     23  * Actions and Tokens (Reinst types)
     24  *
     25  *	02xx are operators, value == precedence
     26  *	03xx are tokens, i.e. operands for operators
     27  */
     28 #define RUNE		0177
     29 #define	OPERATOR	0200	/* Bitmask of all operators */
     30 #define	START		0200	/* Start, used for marker on stack */
     31 #define	RBRA		0201	/* Right bracket, ) */
     32 #define	LBRA		0202	/* Left bracket, ( */
     33 #define	OR		0203	/* Alternation, | */
     34 #define	CAT		0204	/* Concatentation, implicit operator */
     35 #define	STAR		0205	/* Closure, * */
     36 #define	PLUS		0206	/* a+ == aa* */
     37 #define	QUEST		0207	/* a? == a|nothing, i.e. 0 or 1 a's */
     38 #define	ANY		0300	/* Any character except newline, . */
     39 #define	ANYNL		0301	/* Any character including newline, . */
     40 #define	NOP		0302	/* No operation, internal use only */
     41 #define	BOL		0303	/* Beginning of line, ^ */
     42 #define	EOL		0304	/* End of line, $ */
     43 #define	CCLASS		0305	/* Character class, [] */
     44 #define	NCCLASS		0306	/* Negated character class, [] */
     45 #define	END		0377	/* Terminate: match found */
     46 
     47 /*
     48  *  regexec execution lists
     49  */
     50 #define LISTSIZE	10
     51 #define BIGLISTSIZE	(10*LISTSIZE)
     52 typedef struct Relist	Relist;
     53 struct Relist
     54 {
     55 	Reinst*		inst;		/* Reinstruction of the thread */
     56 	Resublist	se;		/* matched subexpressions in this thread */
     57 };
     58 typedef struct Reljunk	Reljunk;
     59 struct	Reljunk
     60 {
     61 	Relist*	relist[2];
     62 	Relist*	reliste[2];
     63 	int	starttype;
     64 	Rune	startchar;
     65 	char*	starts;
     66 	char*	eol;
     67 	Rune*	rstarts;
     68 	Rune*	reol;
     69 };
     70 
     71 extern Relist*	_renewthread(Relist*, Reinst*, int, Resublist*);
     72 extern void	_renewmatch(Resub*, int, Resublist*);
     73 extern Relist*	_renewemptythread(Relist*, Reinst*, int, char*);
     74 extern Relist*	_rrenewemptythread(Relist*, Reinst*, int, Rune*);