~ubuntu-branches/ubuntu/jaunty/clamav/jaunty-backports

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/Support/regengine.inc

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-10-02 15:36:00 UTC
  • mfrom: (10.1.6 sid)
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: james.westby@ubuntu.com-20101002153600-2tx3vki1u55cdrjy
Tags: 0.96.3+dfsg-2ubuntu0.10.04.1
Microversion update to 0.96.3 for Lucid (LP: #653738)

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
        struct re_guts *g;
73
73
        int eflags;
74
74
        llvm_regmatch_t *pmatch;        /* [nsub+1] (0 element unused) */
75
 
        char *offp;             /* offsets work from here */
76
 
        char *beginp;           /* start of string -- virtual NUL precedes */
77
 
        char *endp;             /* end of string -- virtual NUL here */
78
 
        char *coldp;            /* can be no match starting before here */
79
 
        char **lastpos;         /* [nplus+1] */
 
75
        const char *offp;               /* offsets work from here */
 
76
        const char *beginp;             /* start of string -- virtual NUL precedes */
 
77
        const char *endp;               /* end of string -- virtual NUL here */
 
78
        const char *coldp;              /* can be no match starting before here */
 
79
        const char **lastpos;           /* [nplus+1] */
80
80
        STATEVARS;
81
81
        states st;              /* current states */
82
82
        states fresh;           /* states for a fresh start */
84
84
        states empty;           /* empty set of states */
85
85
};
86
86
 
87
 
static int matcher(struct re_guts *, char *, size_t, llvm_regmatch_t[], int);
88
 
static char *dissect(struct match *, char *, char *, sopno, sopno);
89
 
static char *backref(struct match *, char *, char *, sopno, sopno, sopno, int);
90
 
static char *fast(struct match *, char *, char *, sopno, sopno);
91
 
static char *slow(struct match *, char *, char *, sopno, sopno);
 
87
static int matcher(struct re_guts *, const char *, size_t,
 
88
                   llvm_regmatch_t[], int);
 
89
static const char *dissect(struct match *, const char *, const char *, sopno,
 
90
                           sopno);
 
91
static const char *backref(struct match *, const char *, const char *, sopno,
 
92
                           sopno, sopno, int);
 
93
static const char *fast(struct match *, const char *, const char *, sopno, sopno);
 
94
static const char *slow(struct match *, const char *, const char *, sopno, sopno);
92
95
static states step(struct re_guts *, sopno, sopno, states, int, states);
93
96
#define MAX_RECURSION   100
94
97
#define BOL     (OUT+1)
125
128
 - matcher - the actual matching engine
126
129
 */
127
130
static int                      /* 0 success, REG_NOMATCH failure */
128
 
matcher(struct re_guts *g, char *string, size_t nmatch, llvm_regmatch_t pmatch[],
 
131
matcher(struct re_guts *g, const char *string, size_t nmatch,
 
132
        llvm_regmatch_t pmatch[],
129
133
    int eflags)
130
134
{
131
 
        char *endp;
 
135
        const char *endp;
132
136
        size_t i;
133
137
        struct match mv;
134
138
        struct match *m = &mv;
135
 
        char *dp;
 
139
        const char *dp;
136
140
        const sopno gf = g->firststate+1;       /* +1 for OEND */
137
141
        const sopno gl = g->laststate;
138
 
        char *start;
139
 
        char *stop;
 
142
        const char *start;
 
143
        const char *stop;
140
144
 
141
145
        /* simplify the situation where possible */
142
146
        if (g->cflags&REG_NOSUB)
216
220
                        dp = dissect(m, m->coldp, endp, gf, gl);
217
221
                } else {
218
222
                        if (g->nplus > 0 && m->lastpos == NULL)
219
 
                                m->lastpos = (char **)malloc((g->nplus+1) *
 
223
                                m->lastpos = (const char **)malloc((g->nplus+1) *
220
224
                                                        sizeof(char *));
221
225
                        if (g->nplus > 0 && m->lastpos == NULL) {
222
226
                                free(m->pmatch);
287
291
/*
288
292
 - dissect - figure out what matched what, no back references
289
293
 */
290
 
static char *                   /* == stop (success) always */
291
 
dissect(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
 
294
static const char *                     /* == stop (success) always */
 
295
dissect(struct match *m, const char *start, const char *stop, sopno startst,
 
296
        sopno stopst)
292
297
{
293
298
        int i;
294
299
        sopno ss;       /* start sop of current subRE */
295
300
        sopno es;       /* end sop of current subRE */
296
 
        char *sp;       /* start of string matched by it */
297
 
        char *stp;      /* string matched by it cannot pass here */
298
 
        char *rest;     /* start of rest of string */
299
 
        char *tail;     /* string unmatched by rest of RE */
 
301
        const char *sp; /* start of string matched by it */
 
302
        const char *stp;        /* string matched by it cannot pass here */
 
303
        const char *rest;       /* start of rest of string */
 
304
        const char *tail;       /* string unmatched by rest of RE */
300
305
        sopno ssub;     /* start sop of subsubRE */
301
306
        sopno esub;     /* end sop of subsubRE */
302
 
        char *ssp;      /* start of string matched by subsubRE */
303
 
        char *sep;      /* end of string matched by subsubRE */
304
 
        char *oldssp;   /* previous ssp */
 
307
        const char *ssp;        /* start of string matched by subsubRE */
 
308
        const char *sep;        /* end of string matched by subsubRE */
 
309
        const char *oldssp;     /* previous ssp */
305
310
 
306
311
        AT("diss", start, stop, startst, stopst);
307
312
        sp = start;
360
365
                        esub = es - 1;
361
366
                        /* did innards match? */
362
367
                        if (slow(m, sp, rest, ssub, esub) != NULL) {
363
 
                                char *dp = dissect(m, sp, rest, ssub, esub);
 
368
                                const char *dp = dissect(m, sp, rest, ssub, esub);
364
369
                                (void)dp; /* avoid warning if assertions off */
365
370
                                assert(dp == rest);
366
371
                        } else          /* no */
400
405
                        assert(sep == rest);    /* must exhaust substring */
401
406
                        assert(slow(m, ssp, sep, ssub, esub) == rest);
402
407
                        {
403
 
                                char *dp = dissect(m, ssp, sep, ssub, esub);
 
408
                                const char *dp = dissect(m, ssp, sep, ssub, esub);
404
409
                                (void)dp; /* avoid warning if assertions off */
405
410
                                assert(dp == sep);
406
411
                        }
438
443
                                        assert(OP(m->g->strip[esub]) == O_CH);
439
444
                        }
440
445
                        {
441
 
                                char *dp = dissect(m, sp, rest, ssub, esub);
 
446
                                const char *dp = dissect(m, sp, rest, ssub, esub);
442
447
                                (void)dp; /* avoid warning if assertions off */
443
448
                                assert(dp == rest);
444
449
                        }
474
479
/*
475
480
 - backref - figure out what matched what, figuring in back references
476
481
 */
477
 
static char *                   /* == stop (success) or NULL (failure) */
478
 
backref(struct match *m, char *start, char *stop, sopno startst, sopno stopst,
479
 
    sopno lev, int rec)                 /* PLUS nesting level */
 
482
static const char *                     /* == stop (success) or NULL (failure) */
 
483
backref(struct match *m, const char *start, const char *stop, sopno startst,
 
484
        sopno stopst, sopno lev, int rec)                       /* PLUS nesting level */
480
485
{
481
486
        int i;
482
487
        sopno ss;       /* start sop of current subRE */
483
 
        char *sp;       /* start of string matched by it */
 
488
        const char *sp; /* start of string matched by it */
484
489
        sopno ssub;     /* start sop of subsubRE */
485
490
        sopno esub;     /* end sop of subsubRE */
486
 
        char *ssp;      /* start of string matched by subsubRE */
487
 
        char *dp;
 
491
        const char *ssp;        /* start of string matched by subsubRE */
 
492
        const char *dp;
488
493
        size_t len;
489
494
        int hard;
490
495
        sop s;
674
679
/*
675
680
 - fast - step through the string at top speed
676
681
 */
677
 
static char *                   /* where tentative match ended, or NULL */
678
 
fast(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
 
682
static const char *                     /* where tentative match ended, or NULL */
 
683
fast(struct match *m, const char *start, const char *stop, sopno startst,
 
684
     sopno stopst)
679
685
{
680
686
        states st = m->st;
681
687
        states fresh = m->fresh;
682
688
        states tmp = m->tmp;
683
 
        char *p = start;
 
689
        const char *p = start;
684
690
        int c = (start == m->beginp) ? OUT : *(start-1);
685
691
        int lastc;      /* previous c */
686
692
        int flagch;
687
693
        int i;
688
 
        char *coldp;    /* last p after which no match was underway */
 
694
        const char *coldp;      /* last p after which no match was underway */
689
695
 
690
696
        CLEAR(st);
691
697
        SET1(st, startst);
758
764
/*
759
765
 - slow - step through the string more deliberately
760
766
 */
761
 
static char *                   /* where it ended */
762
 
slow(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
 
767
static const char *                     /* where it ended */
 
768
slow(struct match *m, const char *start, const char *stop, sopno startst,
 
769
     sopno stopst)
763
770
{
764
771
        states st = m->st;
765
772
        states empty = m->empty;
766
773
        states tmp = m->tmp;
767
 
        char *p = start;
 
774
        const char *p = start;
768
775
        int c = (start == m->beginp) ? OUT : *(start-1);
769
776
        int lastc;      /* previous c */
770
777
        int flagch;
771
778
        int i;
772
 
        char *matchp;   /* last p at which a match ended */
 
779
        const char *matchp;     /* last p at which a match ended */
773
780
 
774
781
        AT("slow", start, stop, startst, stopst);
775
782
        CLEAR(st);