ire.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 2000-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* ire re implementation
*
* Glenn Fowler
* AT&T Research
*/
#include <ast.h>
#include <vmalloc.h>
struct Ire_s;
#define _IRE_PRIVATE_ \
int left; \
int right; \
int must; \
int keepvm; \
int type; \
#include "ire.h"
#include <error.h>
typedef struct Re_s
{
int invert;
int lo;
int hi;
int n;
} Re_t;
static void*
{
void* r;
else
if (r)
return r;
}
#include "ireexec.h"
#include "ireexec.h"
#include "ireexec.h"
/*
* convert tuple number string
*/
irenum(const char* s, char** e)
{
register Ireint_t n;
char* p;
for (;;)
{
s = (char*)p;
if (*s != '.')
break;
}
if (e)
*e = p;
return n;
}
/*
* compile and return ire re handle
*/
{
register char* s;
char* e;
int m;
int mem;
switch (element)
{
case 1:
case 2:
case 4:
break;
default:
return 0;
}
if (tuple <= 0)
{
return 0;
}
{
if (!disc->resizehandle)
{
if (disc->resizehandle)
return 0;
}
vm = 0;
}
{
return 0;
}
{
return 0;
}
s = (char*)pattern;
pe = 0;
mem = 0;
for (;;)
{
mem = 1;
goto nospace;
for (;;)
{
switch (*s++)
{
case 0:
if (mem != 1)
{
s--;
goto append;
}
{
pe = 0;
mem = 0;
{
break;
{
mem = 0;
}
}
if (pe)
}
switch (element)
{
case 1:
break;
case 2:
break;
case 4:
break;
}
#if 0
sfprintf(sfstderr, "ire: element=%d tuple=%d group=%d left=%d right=%d must=%d type=%d\n", ire->element, ire->tuple, ire->group, ire->left, ire->right, ire->must, ire->type);
sfprintf(sfstderr, " id=%05u n=%d invert=%d lo=%d hi=%d\n", re->id[0], re->n, re->invert, re->lo, re->hi);
#endif
return ire;
case ':':
s--;
goto append;
case ' ':
case '\t':
case '_':
case ',':
case '/':
if (mem != 1)
{
s--;
goto append;
}
continue;
case '^':
if (pe)
goto syntax;
continue;
case '$':
for (; *s == ' ' || *s == '\t'; s++);
if (*s)
goto syntax;
continue;
case '.':
break;
case '-':
goto append;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
re->n = 1;
s = e;
break;
case '[':
m = 1;
for (;;)
{
switch (*s++)
{
case 0:
goto syntax;
case ' ':
case '\t':
case '_':
case ',':
continue;
case '!':
case '^':
goto syntax;
continue;
case ']':
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
if (re->n >= m)
{
if (m == 1)
m = 8;
else
m *= 2;
goto nospace;
}
s = e;
continue;
}
goto nospace;
break;
}
if (!re->n)
goto syntax;
break;
default:
goto syntax;
}
break;
}
for (;;)
{
switch (*s++)
{
case '*':
break;
case '+':
break;
case '{':
if (!group)
goto syntax;
for (s = e; *s == ' ' || *s == '\t'; s++);
if (*s == ',')
{
for (s = e; *s == ' ' || *s == '\t'; s++);
}
else
goto syntax;
s++;
break;
default:
s--;
break;
}
break;
}
if (pe)
else
if (*s == ':')
{
goto syntax;
s++;
if (*s != ' ' && *s != '\t')
continue;
}
{
mem++;
goto nospace;
goto append;
}
}
(*disc->errorf)(NiL, disc, 2, "%-.*s<<<: invalid regular expression", s - (char*)pattern + 1, pattern);
return 0;
}
/*
* match compiled ire re against data with size elements
* return 1:match 0:no-match
*/
int
{
}
/*
* free ire re handle
*/
int
{
if (!ire)
return -1;
return 0;
}