Esempio n. 1
0
bool Initialize_C(void)
{
	if(tr_function == NULL && tr_parameters == NULL)
	{
		const TRexChar *error = NULL;
		tr_function = trex_compile("(?:([\\w:]+)[*&]*\\s+(?:[*&]*\\s+)?[*&]*)?([\\w:]+)\\s*(\\([^)]*\\))", &error);
		tr_parameters = trex_compile("(\\$?\\w+|\\.\\.\\.)(\\s*=\\s*[\\\"\\w\\.]+)?\\s*[,)]", &error);

		if(!tr_function || !tr_parameters) return false;
	}
	return true;
}
Esempio n. 2
0
int main(int argc, char* argv[])
{
	const TRexChar *begin,*end;
	TRexChar sTemp[200];
	const TRexChar *error = NULL;
	TRex *x = trex_compile(_TREXC("(x{1,5})xx"),&error);
	if(x) {
		trex_sprintf(sTemp,_TREXC("xxxxxxx"));
		if(trex_search(x,sTemp,&begin,&end))
		{
			int i,n = trex_getsubexpcount(x);
			TRexMatch match;
			for(i = 0; i < n; i++)
			{
				TRexChar t[200];
				trex_getsubexp(x,i,&match);
				trex_sprintf(t,_TREXC("[%%d]%%.%ds\n"),match.len);
				trex_printf(t,i,match.begin);
			}
			trex_printf(_TREXC("match! %d sub matches\n"),trex_getsubexpcount(x));
		}
		else {
			trex_printf(_TREXC("no match!\n"));
		}
		trex_free(x);
	}
	else {
		trex_printf(_TREXC("compilation error [%s]!\n"),error?error:_TREXC("undefined"));
	}
	return 0;
}
Esempio n. 3
0
ret_code amb_init(ambiente_t* ambiente, const char* content, int length)
{
	ret_code ret = ERROR; 
	if (NULL!=content && NULL!=ambiente) {
		const TRexChar *begin, *end, *error;
		TRex* x;		
		CHECK(NULL!=(x=trex_compile(_TREXC("QtdMax=(\\d+)&PdvId=(\\d+)" \
				"&Recibo=(\\d)&Dormir=(\\d)&Cortesias=(\\d)&Credito=(\\d)&"),&error)));
		if (trex_search(x,_TREXC(content),&begin,&end)) {
			int n = trex_getsubexpcount(x);	
			if (n==7) {
				char *qtdMax, *pdvId, *credito;					
				rx_getnext(x, 1, &qtdMax);
				rx_getnext(x, 2, &pdvId);
				rx_getnext(x, 6, &credito);
				CHECK(NULL!=qtdMax);
				CHECK(NULL!=pdvId);
				CHECK(NULL!=credito);
				ambiente->credito = atoi(credito);
				ambiente->qtdMax = atoi(qtdMax);
				ambiente->pdvId = pdvId;
				free(credito);
				free(qtdMax);					
				ret = SUCCESS;
			}
			else {
				ret = ERROR;
			}
		} /* trex_search */
		trex_free(x);
	} /* NULL!=content */
	return ret;
}
Esempio n. 4
0
/**
 *  \brief Initialize the message system
 */
void mess__base__init(void)
{
	int i;
	trex_regexes = malloc(sizeof(TRex*) * MESS__NB_REGEXES);
	for(i = 0; i < MESS__NB_REGEXES; i++) // trouver le moyen de staticifier ça
	{
		trex_regexes[i] = trex_compile(regex_strtable[i], NULL);
	}
	isEverythingInitialized = 1;
}
Esempio n. 5
0
static RegExpInfo *reCompTX (const char *restr, const char **error) {
  *error = NULL;
  TRex *re = trex_compile(restr, error);
  if (!re) return NULL;
  RegExpInfo *res = malloc(sizeof(RegExpInfo));
  if (!res) { free(re); *error = "out of memory"; return NULL; }
  res->type = rexId;
  res->tx = re;
  res->vmtId = 1;
  return res;
}
Esempio n. 6
0
File: zrex.c Progetto: Prarrot/czmq
zrex_t *
zrex_new (const char *expression)
{
    zrex_t *self = (zrex_t *) zmalloc (sizeof (zrex_t));
    assert (self);
    self->strerror = "No error";
    //  Trex cannot handle an empty pattern, which doesn't inspire huge
    //  confidence but apart from this, seems to be working...
    if (expression) {
        if (*expression)
            self->trex = trex_compile (expression, &self->strerror);
        else
            self->strerror = "Missing pattern";
    }
    return self;
}
Esempio n. 7
0
int main(int argc, char *argv[])
{
	TRex *r;
	char *buf, *err = 0, *beg, *end, *q;
	int l = 0;
	if (argc == 1) {
		fprintf(stderr, "Usage: cat in.file | %s <regexp>\n", argv[0]);
		return 0;
	}
	r = trex_compile(argv[1], &err);
	buf = calloc(BUF_SIZE, 1);
	while (fgets(buf, BUF_SIZE - 1, stdin)) {
		++l;
		for (q = buf; *q; ++q); if (q > buf) *(q-1) = 0;
		if (trex_search(r, buf, &beg, &end) == TRex_True)
			printf("%d:%s\n", l, buf);
	}
	free(buf);
	return 0;
}
static re_cache_t *compile_regex(const char *regex)
{
   re_cache_t *re;
   int i;

   for (i = 0; i < MAX_RE_CACHE; i++) {
      re = &d_regex_cache[i];
      if (re->regex == NULL) {
         re->regex = regex;
         re->reg = trex_compile(regex, NULL);
         if (re->reg == NULL) {
            d_abort("error compiling regular expression: ", regex);
         }
      }
      if (re->regex == regex) {
         return re;
      }
   }

   d_abort("too many regular expressions", "");
   return NULL;
}
Esempio n. 9
0
int regcomp(regex_t *preg, const char *regex, int cflags) {
	if (!preg || !regex) {
		return -EINVAL;
	}

	/* Trex is able to search only the first match in the whole string or in
	 * the specified range. Using trex_searchrange() we can get several
	 * matches, but we have to not allow the symbol '^' in the pattern */
	if (regex[0] == '^') {
		return -EINVAL;
	}

	preg->regex_error[0] = '\0';

	preg->regex_extended = trex_compile((char *)regex, preg->regex_error);

	if (!preg->regex_extended) {
		return -EINVAL;
	}

	return 0;
}
Esempio n. 10
0
File: zrex.c Progetto: Prarrot/czmq
int
zrex_eq (zrex_t *self, const char *text, const char *expression)
{
    assert (self);
    assert (text);
    assert (expression);

    //  If we had any previous expression, destroy it
    if (self->trex) {
        trex_free (self->trex);
        self->trex = NULL;
    }
    //  Compile the new expression
    if (*expression)
        self->trex = trex_compile (expression, &self->strerror);
    else
        self->strerror = "Missing pattern";

    //  zrex_hits takes care of the rest for us
    return zrex_hits (self, text);

}
Esempio n. 11
0
void test1()
{
	const char *error = NULL;
	const char *begin,*end;
	char *exp1 = "^([^ ]+) (/[^?# ]*)(\\?[^# ]*)?(#[^ ]*)? HTTP/([^ ]+)$";
	char *exp2 = "^([^ ]+): (.+)$";
	char *exp3 = "([^=]+)(=[^&])?(&([^=]+)(=[^&]))*";


	long long t = counter.Tick();
	TRex *x = trex_compile(exp3, &error);
	printf("compile %lld\n", counter.Tick() - t);

	t = counter.Tick();
	if(trex_search(x,"aaa=bbb&ccc=ddd&eee",&begin,&end))
	{
		printf("execute %lld\n", counter.Tick() - t);
		int i,n = trex_getsubexpcount(x);
		TRexMatch match;
		for(i = 1; i < n; i++)
		{
			t = counter.Tick();
			trex_getsubexp(x,i,&match);
			printf("trex_getsubexp %lld ", counter.Tick() - t);

			for(int j=0;j<match.len;j++)
				putchar(match.begin[j]);
			printf("\n");
		}
		printf("match! %d sub matches\n",trex_getsubexpcount(x));
	}
	else
	{
		printf("execute %lld\n", counter.Tick() - t);
		printf("no match!\n");
	}
}