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

« back to all changes in this revision

Viewing changes to plug-ins/script-fu/re/regexec.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * the outer shell of regexec()
 
3
 *
 
4
 * This file includes engine.c *twice*, after muchos fiddling with the
 
5
 * macros that code uses.  This lets the same code operate on two different
 
6
 * representations for state sets.
 
7
 */
 
8
#include "regex.h"
 
9
 
 
10
#include "utils.h"
 
11
#include "regex2.h"
 
12
 
 
13
#ifndef NDEBUG
 
14
static int nope = 0;          /* for use in asserts; shuts lint up */
 
15
#endif
 
16
 
 
17
/* macros for manipulating states, small version */
 
18
#define   states    long
 
19
#define   states1   states         /* for later use in regexec() decision */
 
20
#define   CLEAR(v)  ((v) = 0)
 
21
#define   SET0(v, n)     ((v) &= ~(1 << (n)))
 
22
#define   SET1(v, n)     ((v) |= 1 << (n))
 
23
#define   ISSET(v, n)    ((v) & (1 << (n)))
 
24
#define   ASSIGN(d, s)   ((d) = (s))
 
25
#define   EQ(a, b)  ((a) == (b))
 
26
#define   STATEVARS int dummy /* dummy version */
 
27
#define   STATESETUP(m, n)    /* nothing */
 
28
#define   STATETEARDOWN(m)    /* nothing */
 
29
#define   SETUP(v)  ((v) = 0)
 
30
#define   onestate  int
 
31
#define   INIT(o, n)     ((o) = (unsigned)1 << (n))
 
32
#define   INC(o)    ((o) <<= 1)
 
33
#define   ISSTATEIN(v, o)     ((v) & (o))
 
34
/* some abbreviations; note that some of these know variable names! */
 
35
/* do "if I'm here, I can also be there" etc without branches */
 
36
#define   FWD(dst, src, n)    ((dst) |= ((unsigned)(src)&(here)) << (n))
 
37
#define   BACK(dst, src, n)   ((dst) |= ((unsigned)(src)&(here)) >> (n))
 
38
#define   ISSETBACK(v, n)     ((v) & ((unsigned)here >> (n)))
 
39
/* function names */
 
40
#define SNAMES           /* engine.c looks after details */
 
41
 
 
42
#include "engine.c"
 
43
 
 
44
/* now undo things */
 
45
#undef    states
 
46
#undef    CLEAR
 
47
#undef    SET0
 
48
#undef    SET1
 
49
#undef    ISSET
 
50
#undef    ASSIGN
 
51
#undef    EQ
 
52
#undef    STATEVARS
 
53
#undef    STATESETUP
 
54
#undef    STATETEARDOWN
 
55
#undef    SETUP
 
56
#undef    onestate
 
57
#undef    INIT
 
58
#undef    INC
 
59
#undef    ISSTATEIN
 
60
#undef    FWD
 
61
#undef    BACK
 
62
#undef    ISSETBACK
 
63
#undef    SNAMES
 
64
 
 
65
/* macros for manipulating states, large version */
 
66
#define   states    char *
 
67
#define   CLEAR(v)  memset(v, 0, m->g->nstates)
 
68
#define   SET0(v, n)     ((v)[n] = 0)
 
69
#define   SET1(v, n)     ((v)[n] = 1)
 
70
#define   ISSET(v, n)    ((v)[n])
 
71
#define   ASSIGN(d, s)   memcpy(d, s, m->g->nstates)
 
72
#define   EQ(a, b)  (memcmp(a, b, m->g->nstates) == 0)
 
73
#define   STATEVARS int vn; char *space
 
74
#define   STATESETUP(m, nv)   { (m)->space = malloc((nv)*(m)->g->nstates); \
 
75
                    if ((m)->space == NULL) return(REG_ESPACE); \
 
76
                    (m)->vn = 0; }
 
77
#define   STATETEARDOWN(m)    { free((m)->space); }
 
78
#define   SETUP(v)  ((v) = &m->space[m->vn++ * m->g->nstates])
 
79
#define   onestate  int
 
80
#define   INIT(o, n)     ((o) = (n))
 
81
#define   INC(o)    ((o)++)
 
82
#define   ISSTATEIN(v, o)     ((v)[o])
 
83
/* some abbreviations; note that some of these know variable names! */
 
84
/* do "if I'm here, I can also be there" etc without branches */
 
85
#define   FWD(dst, src, n)    ((dst)[here+(n)] |= (src)[here])
 
86
#define   BACK(dst, src, n)   ((dst)[here-(n)] |= (src)[here])
 
87
#define   ISSETBACK(v, n)     ((v)[here - (n)])
 
88
/* function names */
 
89
#define   LNAMES              /* flag */
 
90
 
 
91
#include "engine.c"
 
92
 
 
93
/*
 
94
 - regexec - interface for matching
 
95
 = API_EXPORT(int) regexec(const regex_t *, const char *, size_t, \
 
96
 =                       regmatch_t [], int);
 
97
 = #define     REG_NOTBOL     00001
 
98
 = #define     REG_NOTEOL     00002
 
99
 = #define     REG_STARTEND   00004
 
100
 = #define     REG_TRACE 00400     // tracing of execution
 
101
 = #define     REG_LARGE 01000     // force large representation
 
102
 = #define     REG_BACKR 02000     // force use of backref code
 
103
 *
 
104
 * We put this here so we can exploit knowledge of the state representation
 
105
 * when choosing which matcher to call.  Also, by this point the matchers
 
106
 * have been prototyped.
 
107
 */
 
108
API_EXPORT(int)                    /* 0 success, REG_NOMATCH failure */
 
109
regexec(preg, string, nmatch, pmatch, eflags)
 
110
const regex_t *preg;
 
111
const char *string;
 
112
size_t nmatch;
 
113
regmatch_t pmatch[];
 
114
int eflags;
 
115
{
 
116
     register struct re_guts *g = preg->re_g;
 
117
#ifdef REDEBUG
 
118
#    define    GOODFLAGS(f)   (f)
 
119
#else
 
120
#    define    GOODFLAGS(f)   ((f)&(REG_NOTBOL|REG_NOTEOL|REG_STARTEND))
 
121
#endif
 
122
 
 
123
     if (preg->re_magic != MAGIC1 || g->magic != MAGIC2)
 
124
          return(REG_BADPAT);
 
125
     assert(!(g->iflags&BAD));
 
126
     if (g->iflags&BAD)       /* backstop for no-debug case */
 
127
          return(REG_BADPAT);
 
128
     eflags = GOODFLAGS(eflags);
 
129
 
 
130
     if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags&REG_LARGE))
 
131
          return(smatcher(g, (char *)string, nmatch, pmatch, eflags));
 
132
     else
 
133
          return(lmatcher(g, (char *)string, nmatch, pmatch, eflags));
 
134
}