~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/script-fu/re/regex2.h

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-10-06 13:30:41 UTC
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: james.westby@ubuntu.com-20081006133041-3panbkcanaymfsmp
Tags: upstream-2.6.0
ImportĀ upstreamĀ versionĀ 2.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * First, the stuff that ends up in the outside-world include file
3
 
 = #ifdef WIN32
4
 
 = #define API_EXPORT(type)    __declspec(dllexport) type __stdcall
5
 
 = #else
6
 
 = #define API_EXPORT(type)    type
7
 
 = #endif
8
 
 =
9
 
 = typedef off_t regoff_t;
10
 
 = typedef struct {
11
 
 =      int re_magic;
12
 
 =      size_t re_nsub;         // number of parenthesized subexpressions
13
 
 =      const char *re_endp;    // end pointer for REG_PEND
14
 
 =      struct re_guts *re_g;   // none of your business :-)
15
 
 = } regex_t;
16
 
 = typedef struct {
17
 
 =      regoff_t rm_so;         // start of match
18
 
 =      regoff_t rm_eo;         // end of match
19
 
 = } regmatch_t;
20
 
 */
21
 
/*
22
 
 * internals of regex_t
23
 
 */
24
 
#define MAGIC1  ((('r'^0200)<<8) | 'e')
25
 
 
26
 
/*
27
 
 * The internal representation is a *strip*, a sequence of
28
 
 * operators ending with an endmarker.  (Some terminology etc. is a
29
 
 * historical relic of earlier versions which used multiple strips.)
30
 
 * Certain oddities in the representation are there to permit running
31
 
 * the machinery backwards; in particular, any deviation from sequential
32
 
 * flow must be marked at both its source and its destination.  Some
33
 
 * fine points:
34
 
 *
35
 
 * - OPLUS_ and O_PLUS are *inside* the loop they create.
36
 
 * - OQUEST_ and O_QUEST are *outside* the bypass they create.
37
 
 * - OCH_ and O_CH are *outside* the multi-way branch they create, while
38
 
 *   OOR1 and OOR2 are respectively the end and the beginning of one of
39
 
 *   the branches.  Note that there is an implicit OOR2 following OCH_
40
 
 *   and an implicit OOR1 preceding O_CH.
41
 
 *
42
 
 * In state representations, an operator's bit is on to signify a state
43
 
 * immediately *preceding* "execution" of that operator.
44
 
 */
45
 
typedef unsigned long sop;      /* strip operator */
46
 
typedef long sopno;
47
 
#define OPRMASK 0xf8000000
48
 
#define OPDMASK 0x07ffffff
49
 
#define OPSHIFT ((unsigned)27)
50
 
#define OP(n)   ((n)&OPRMASK)
51
 
#define OPND(n) ((n)&OPDMASK)
52
 
#define SOP(op, opnd)   ((op)|(opnd))
53
 
/* operators                       meaning      operand                 */
54
 
/*                                              (back, fwd are offsets) */
55
 
#define OEND    (1<<OPSHIFT)    /* endmarker    -                       */
56
 
#define OCHAR   (2<<OPSHIFT)    /* character    unsigned char           */
57
 
#define OBOL    (3<<OPSHIFT)    /* left anchor  -                       */
58
 
#define OEOL    (4<<OPSHIFT)    /* right anchor -                       */
59
 
#define OANY    (5<<OPSHIFT)    /* .            -                       */
60
 
#define OANYOF  (6<<OPSHIFT)    /* [...]        set number              */
61
 
#define OBACK_  (7<<OPSHIFT)    /* begin \d     paren number            */
62
 
#define O_BACK  (8<<OPSHIFT)    /* end \d       paren number            */
63
 
#define OPLUS_  (9<<OPSHIFT)    /* + prefix     fwd to suffix           */
64
 
#define O_PLUS  (10<<OPSHIFT)   /* + suffix     back to prefix          */
65
 
#define OQUEST_ (11<<OPSHIFT)   /* ? prefix     fwd to suffix           */
66
 
#define O_QUEST (12<<OPSHIFT)   /* ? suffix     back to prefix          */
67
 
#define OLPAREN (13<<OPSHIFT)   /* (            fwd to )                */
68
 
#define ORPAREN (14<<OPSHIFT)   /* )            back to (               */
69
 
#define OCH_    (15<<OPSHIFT)   /* begin choice fwd to OOR2             */
70
 
#define OOR1    (16u<<OPSHIFT)  /* | pt. 1      back to OOR1 or OCH_    */
71
 
#define OOR2    (17u<<OPSHIFT)  /* | pt. 2      fwd to OOR2 or O_CH     */
72
 
#define O_CH    (18u<<OPSHIFT)  /* end choice   back to OOR1            */
73
 
#define OBOW    (19u<<OPSHIFT)  /* begin word   -                       */
74
 
#define OEOW    (20u<<OPSHIFT)  /* end word     -                       */
75
 
 
76
 
/*
77
 
 * Structure for [] character-set representation.  Character sets are
78
 
 * done as bit vectors, grouped 8 to a byte vector for compactness.
79
 
 * The individual set therefore has both a pointer to the byte vector
80
 
 * and a mask to pick out the relevant bit of each byte.  A hash code
81
 
 * simplifies testing whether two sets could be identical.
82
 
 *
83
 
 * This will get trickier for multicharacter collating elements.  As
84
 
 * preliminary hooks for dealing with such things, we also carry along
85
 
 * a string of multi-character elements, and decide the size of the
86
 
 * vectors at run time.
87
 
 */
88
 
typedef struct {
89
 
        uch *ptr;               /* -> uch [csetsize] */
90
 
        uch mask;               /* bit within array */
91
 
        uch hash;               /* hash code */
92
 
        size_t smultis;
93
 
        char *multis;           /* -> char[smulti]  ab\0cd\0ef\0\0 */
94
 
} cset;
95
 
/* note that CHadd and CHsub are unsafe, and CHIN doesn't yield 0/1 */
96
 
#define CHadd(cs, c)    ((cs)->ptr[(uch)(c)] |= (cs)->mask, (cs)->hash += (c))
97
 
#define CHsub(cs, c)    ((cs)->ptr[(uch)(c)] &= ~(cs)->mask, (cs)->hash -= (c))
98
 
#define CHIN(cs, c)     ((cs)->ptr[(uch)(c)] & (cs)->mask)
99
 
#define MCadd(p, cs, cp)        mcadd(p, cs, cp)        /* regcomp() internal fns */
100
 
 
101
 
/* stuff for character categories */
102
 
typedef unsigned char cat_t;
103
 
 
104
 
/*
105
 
 * main compiled-expression structure
106
 
 */
107
 
struct re_guts {
108
 
        int magic;
109
 
#               define  MAGIC2  ((('R'^0200)<<8)|'E')
110
 
        sop *strip;             /* malloced area for strip */
111
 
        int csetsize;           /* number of bits in a cset vector */
112
 
        int ncsets;             /* number of csets in use */
113
 
        cset *sets;             /* -> cset [ncsets] */
114
 
        uch *setbits;           /* -> uch[csetsize][ncsets/CHAR_BIT] */
115
 
        int cflags;             /* copy of regcomp() cflags argument */
116
 
        sopno nstates;          /* = number of sops */
117
 
        sopno firststate;       /* the initial OEND (normally 0) */
118
 
        sopno laststate;        /* the final OEND */
119
 
        int iflags;             /* internal flags */
120
 
#               define  USEBOL  01      /* used ^ */
121
 
#               define  USEEOL  02      /* used $ */
122
 
#               define  BAD     04      /* something wrong */
123
 
        int nbol;               /* number of ^ used */
124
 
        int neol;               /* number of $ used */
125
 
        int ncategories;        /* how many character categories */
126
 
        cat_t *categories;      /* ->catspace[-CHAR_MIN] */
127
 
        char *must;             /* match must contain this string */
128
 
        int mlen;               /* length of must */
129
 
        size_t nsub;            /* copy of re_nsub */
130
 
        int backrefs;           /* does it use back references? */
131
 
        sopno nplus;            /* how deep does it nest +s? */
132
 
        /* catspace must be last */
133
 
        cat_t catspace[1];      /* actually [NC] */
134
 
};
135
 
 
136
 
/* misc utilities */
137
 
#define OUT     (CHAR_MAX+1)    /* a non-character value */
138
 
#define ISWORD(c)       (isalnum(c) || (c) == '_')