Back to index

radiance  4R0+20100331
Defines | Functions | Variables
rexpr.c File Reference
#include "copyright.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "rtio.h"

Go to the source code of this file.

Defines

#define CCHR   2
#define CDOT   4
#define CCL   6
#define NCCL   8
#define CDOL   10
#define CEOF   11
#define CBRC   14
#define CLET   15
#define STAR   01
#define ESIZE   255
#define same(a, b)   (a==b || (iflag && (a^b)==' ' && isalpha(a)))

Functions

static int advance (char *, char *)
static int cclass (char *, int c, int af)
int ecompile (char *sp, int iflg, int wflag)
char * expsave ()
void expset (char *ep)
char * eindex (char *sp)

Variables

static const char RCSid [] = "$Id: rexpr.c,v 2.9 2003/07/17 09:21:29 schorsch Exp $"
static char expbuf [ESIZE]
static int iflag
static int circf
int explen

Define Documentation

#define CBRC   14

Definition at line 29 of file rexpr.c.

#define CCHR   2

Definition at line 23 of file rexpr.c.

#define CCL   6

Definition at line 25 of file rexpr.c.

#define CDOL   10

Definition at line 27 of file rexpr.c.

#define CDOT   4

Definition at line 24 of file rexpr.c.

#define CEOF   11

Definition at line 28 of file rexpr.c.

#define CLET   15

Definition at line 30 of file rexpr.c.

#define ESIZE   255

Definition at line 33 of file rexpr.c.

#define NCCL   8

Definition at line 26 of file rexpr.c.

#define same (   a,
 
)    (a==b || (iflag && (a^b)==' ' && isalpha(a)))

Definition at line 35 of file rexpr.c.

#define STAR   01

Definition at line 31 of file rexpr.c.


Function Documentation

static int advance ( char *  alp,
char *  ep 
) [static]

Definition at line 184 of file rexpr.c.

{
        register char *lp;
       char *curlp;

        lp = alp;
        for (;;) switch (*ep++) {

        case CCHR:
                if (!same(*ep, *lp))
                        return (0);
                ep++, lp++;
                continue;

        case CDOT:
                if (*lp++)
                        continue;
                return(0);

        case CDOL:
                if (*lp==0)
                        continue;
                return(0);

        case CEOF:
                explen = lp - alp;
                return(1);

        case CCL:
                if (cclass(ep, *lp++, 1)) {
                        ep += *ep;
                        continue;
                }
                return(0);

        case NCCL:
                if (cclass(ep, *lp++, 0)) {
                        ep += *ep;
                        continue;
                }
                return(0);

        case CDOT|STAR:
                curlp = lp;
                while (*lp++);
                goto star;

        case CCHR|STAR:
                curlp = lp;
                while (same(*lp, *ep))
                        lp++;
                lp++;
                ep++;
                goto star;

        case CCL|STAR:
        case NCCL|STAR:
                curlp = lp;
                while (cclass(ep, *lp++, ep[-1]==(CCL|STAR)));
                ep += *ep;
        star:
                do {
                        lp--;
                        if (advance(lp, ep)) {
                                explen += lp - alp;
                                return(1);
                        }
                } while (lp > curlp);
                return(0);

        case CBRC:
                if ((isalnum(*lp) || *lp == '_') && !(isalnum(lp[-1]) || lp[-1] == '_'))
                        continue;
                return (0);

        case CLET:
                if (!isalnum(*lp) && *lp != '_')
                        continue;
                return (0);

        default:
                fprintf(stderr, "RE botch\n");
        }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int cclass ( char *  set,
int  c,
int  af 
) [static]

Definition at line 272 of file rexpr.c.

{
        register int n;

        if (c == 0)
                return(0);
        n = *set++;
        while (--n)
                if (n > 2 && set[1] == '-') {
                        if (c >= set[0] && c <= set[2])
                                return (af);
                        set += 3;
                        n -= 2;
                } else
                        if (*set++ == c)
                                return(af);
        return(!af);
}

Here is the caller graph for this function:

int ecompile ( char *  sp,
int  iflg,
int  wflag 
)

Definition at line 48 of file rexpr.c.

{
        register int c;
        register char *ep;
        char *lastep = NULL;
        int cclcnt;
        
        iflag = iflg;
        ep = expbuf;
       explen = 0;
        if (*sp == '^') {
                circf = 1;
                sp++;
        } else
              circf = 0;
        if (wflag)
                *ep++ = CBRC;
        for (;;) {
                if (ep >= &expbuf[ESIZE])
                        return(-1);
                if ((c = *sp++) != '*')
                        lastep = ep;
                switch (c) {

                case '\0':
                        if (wflag)
                                *ep++ = CLET;
                        *ep++ = CEOF;
                     explen = ep - expbuf;
                        return(0);

                case '.':
                        *ep++ = CDOT;
                        continue;

                case '*':
                        if (lastep==0)
                                goto defchar;
                        *lastep |= STAR;
                        continue;

                case '$':
                        if (*sp != '\0')
                                goto defchar;
                        *ep++ = CDOL;
                        continue;

                case '[':
                        *ep++ = CCL;
                        *ep++ = 0;
                        cclcnt = 1;
                        if ((c = *sp++) == '^') {
                                c = *sp++;
                                ep[-2] = NCCL;
                        }
                        do {
                                *ep++ = c;
                                cclcnt++;
                                if (c=='\0' || ep >= &expbuf[ESIZE])
                                        return(-1);
                        } while ((c = *sp++) != ']');
                        lastep[1] = cclcnt;
                        continue;

                case '\\':
                        if ((c = *sp++) == '\0')
                                return(-1);
                        if (c == '<') {
                            if (ep == expbuf || ep[-1] != CBRC)
                                   *ep++ = CBRC;
                                continue;
                        }
                        if (c == '>') {
                                *ep++ = CLET;
                                continue;
                        }
                defchar:
                default:
                        *ep++ = CCHR;
                        *ep++ = c;
                }
        }
}

Here is the caller graph for this function:

char* eindex ( char *  sp)

Definition at line 160 of file rexpr.c.

{
       /* check for match at beginning of line, watch CBRC */
       if (advance(sp, expbuf[0]==CBRC ? expbuf+1 : expbuf))
              return(sp);
       if (circf)
                return(NULL);
        /* fast check for first character */
        if (expbuf[0]==CCHR) {
              register int c = expbuf[1];
              while (*++sp)
                     if (same(*sp, c) && advance(sp, expbuf))
                            return(sp);
                return(NULL);
        }
        /* regular algorithm */
       while (*++sp)
                if (advance(sp, expbuf))
                        return(sp);
        return(NULL);
}

Here is the call graph for this function:

char* expsave ( void  )

Definition at line 135 of file rexpr.c.

{
       register char  *ep;

       if (explen == 0)
              return(NULL);
       if ((ep = (char *)malloc(explen+3)) == NULL)
              return(NULL);
       ep[0] = iflag;
       ep[1] = circf;
       ep[2] = explen;
       (void)memcpy(ep+3, expbuf, explen);
       return(ep);
}

Here is the caller graph for this function:

void expset ( char *  ep)

Definition at line 151 of file rexpr.c.

{
       iflag = ep[0];
       circf = ep[1];
       (void)memcpy(expbuf, ep+3, ep[2]&0xff);
}

Here is the caller graph for this function:


Variable Documentation

int circf [static]

Definition at line 43 of file rexpr.c.

char expbuf[ESIZE] [static]

Definition at line 41 of file rexpr.c.

int explen

Definition at line 45 of file rexpr.c.

int iflag [static]

Definition at line 42 of file rexpr.c.

const char RCSid[] = "$Id: rexpr.c,v 2.9 2003/07/17 09:21:29 schorsch Exp $" [static]

Definition at line 2 of file rexpr.c.