Example #1
0
/*
 - regexec - match a regexp against a string
 */
int
regexec(
    register regexp *prog,
    register const char *string )
{
    register char *s;

    /* Be paranoid... */
    if (prog == NULL || string == NULL) {
        regerror("NULL parameter");
        return(0);
    }

    /* Check validity of program. */
    if (UCHARAT(prog->program) != MAGIC) {
        regerror("corrupted program");
        return(0);
    }

    /* If there is a "must appear" string, look for it. */
    if ( prog->regmust != NULL )
    {
        s = (char *)string;
        while ( ( s = strchr( s, prog->regmust[ 0 ] ) ) != NULL )
        {
            if ( !strncmp( s, prog->regmust, prog->regmlen ) )
                break;  /* Found it. */
            ++s;
        }
        if ( s == NULL )  /* Not present. */
            return 0;
    }

    /* Mark beginning of line for ^ . */
    regbol = (char *)string;

    /* Simplest case:  anchored match need be tried only once. */
    if ( prog->reganch )
        return regtry( prog, string );

    /* Messy cases:  unanchored match. */
    s = (char *)string;
    if (prog->regstart != '\0')
        /* We know what char it must start with. */
        while ((s = strchr(s, prog->regstart)) != NULL) {
            if (regtry(prog, s))
                return(1);
            s++;
        }
    else
        /* We do not -- general case. */
        do {
            if ( regtry( prog, s ) )
                return( 1 );
        } while ( *s++ != '\0' );

    /* Failure. */
    return 0;
}
Example #2
0
/*
 - _XmRegexec - match a regexp against a string
 */
int
_XmRegexec(XmRegexpRec *prog, char *string)
{
	register char	*s;
	/*	extern char	*strchr();*/

	/* Be paranoid... */
	if (prog == NULL || string == NULL) {
		return(0);
	}

	/* Check validity of program. */
	if (UCHARAT(prog->program) != MAGIC) {
		return(0);
	}

	/* If there is a "must appear" string, look for it. */
	if (prog->regmust != NULL && MB_CUR_MAX == 1) {
		s = (char *)string;
		while ((s = strchr(s, prog->regmust[0])) != NULL) {
			if (strncmp(s, prog->regmust, prog->regmlen) == 0)
				break;	/* Found it. */
			s++;
		}
		if (s == NULL)	/* Not present. */
			return(0);
	}

	/* Mark beginning of line for ^ . */
	regbol = (char *)string;

	/* Simplest case:  anchored match need be tried only once. */
	if (prog->reganch)
		return(regtry(prog, string));

	/* Messy cases:  unanchored match. */
	s = (char *)string;
	if (prog->regstart != '\0' && MB_CUR_MAX == 1)
		/* We know what char it must start with. */
		while ((s = strchr(s, prog->regstart)) != NULL) {
			if (regtry(prog, s))
				return(1);
			s++;
		}
	else
		/* We don't -- general case. */
		while(1){
			int len;

			if (regtry(prog, s))
				return(1);
			if(!(len = CHARLEN(s)))
				break;
			s += len;
		};

	/* Failure. */
	return(0);
}
Example #3
0
/*
 - regexec - match a regexp against a string
 */
int
pgpRegExec(regexp *prog, char const *string)
{
	char const *s;
	regexecState s_res;
	regexecState *res = &s_res;

	/* Be paranoid... */
	if (prog == NULL || string == NULL) {
		FAIL("NULL parameter");
	}

	/* Check validity of program. */
	if (UCHARAT(prog->program) != MAGIC) {
		FAIL("corrupted program");
		return(0);
	}

	pgpClearMemory( &s_res, sizeof(s_res) );

	/* If there is a "must appear" string, look for it. */
	if (prog->regmust != NULL) {
		s = string;
		while ((s = strchr(s, prog->regmust[0])) != NULL) {
			if (strncmp(s, prog->regmust, prog->regmlen) == 0)
				break;	/* Found it. */
			s++;
		}
		if (s == NULL)	/* Not present. */
			return(0);
	}

	/* Mark beginning of line for ^ . */
	res->regbol = string;

	/* Simplest case:  anchored match need be tried only once. */
	if (prog->reganch)
		return(regtry(res, prog, string));

	/* Messy cases:  unanchored match. */
	s = string;
	if (prog->regstart != '\0')
		/* We know what char it must start with. */
		while ((s = strchr(s, prog->regstart)) != NULL) {
			if (regtry(res, prog, s))
				return(1);
			s++;
		}
	else
		/* We don't -- general case. */
		do {
			if (regtry(res, prog, s))
				return(1);
		} while (*s++ != '\0');

	/* Failure. */
	return(0);
}
Example #4
0
bool ossimRegExp::find (const char* string) {
    const char* s = 0;

    if(!string) return false;
    this->searchstring = string;

    // Check validity of program.
    if (!this->program || UCHARAT(this->program) != MAGIC) {
        //RAISE Error, SYM(ossimRegExp), SYM(Internal_Error),
        printf ("ossimRegExp::find(): Compiled regular expression corrupted.\n");
        return 0;
    }

    // If there is a "must appear" string, look for it.
    if (this->regmust != NULL) {
        s = string;
        while ((s = strchr(s, this->regmust[0])) != NULL) {
            if (strncmp(s, this->regmust, this->regmlen) == 0)
                break;		// Found it.
            s++;
        }
        if (s == NULL)		// Not present.
            return (0);
    }

    // Mark beginning of line for ^ .
    regbol = string;

    // Simplest case:  anchored match need be tried only once.
    if (this->reganch)
        return (regtry(string, this->startp, this->endp, this->program));

    // Messy cases:  unanchored match.
    s = string;
    if (this->regstart != '\0')
        // We know what char it must start with.
        while ((s = strchr(s, this->regstart)) != NULL) {
            if (regtry(s, this->startp, this->endp, this->program))
                return (1);
            s++;

        }
    else
        // We don't -- general case.
        do {
            if (regtry(s, this->startp, this->endp, this->program))
                return (1);
        } while (*s++ != '\0');

    // Failure.
    return (0);
}
Example #5
0
/*
 * REexec - match a RE_EXP against a string
 */
bool
REexec( RE_EXP *prog, char *string)
{
    register char *s;

    /* Be paranoid... */
    if (prog == NULL || string == NULL) {
        _error("NULL parameter");
        return( FALSE );
    }

    /* Check validity of program. */
    if (UCHARAT(prog->program) != MAGIC) {
        _error("corrupted program");
        return( FALSE );
    }

    /* If there is a "must appear" string, look for it. */
    if (prog->regmust != NULL) {
        s = string;
        while ((s = STchr(s, *prog->regmust)) != NULL) {
            if (STncmp( s, prog->regmust, prog->regmlen ) == 0
               )
                break;	/* Found it. */
            CMnext( s );
        }
        if (s == NULL)	/* Not present. */
            return( FALSE );
    }

    /* Mark beginning of line for ^ . */
    regbol = string;

    /* Simplest case:  anchored match need be tried only once. */
    if (prog->reganch)
        return(regtry(prog, string));

    /* Messy cases:  unanchored match. */
    s = string;
    if (prog->regstart != '\0')
        /* We know what char it must start with. */
        while ((s = STchr(s, prog->regstart)) != NULL) {
            if (regtry(prog, s))
                return( TRUE );
            CMnext( s );
        }
    else
        /* We don't -- general case. */
        while( TRUE ) {
            if (regtry(prog, s))
                return( TRUE );
            if( *s == '\0' )
                break;
            CMnext( s );
        }
# ifndef DOUBLEBYTE
    CMnext( s );
# else
    /*		CMnext( s ); */
# endif /* #ifndef DOUBLEBYTE */

    /* Failure. */
    return( FALSE );
}
Example #6
0
// RegFind	- match a regexp against a string
// Returns	- Returns position of regexp or -1
//			  if regular expression not found
// Note		- The regular expression should have been
//			  previously compiled using RegComp
int CRegExp::RegFind(const TCHAR *str)
{
	TCHAR *string = (TCHAR *)str;	// avert const poisoning
	TCHAR *s;

	// Delete any previously stored found string
	delete sFoundText;
	sFoundText = NULL;

	// Be paranoid.
	if(string == NULL)
	{
		TRACE0("NULL argument to regexec\n");
		return(-1);
	}

	// Check validity of regex
	if (!bCompiled)
	{
		TRACE0("No regular expression provided yet.\n");
		return(-1);
	}

	// If there is a "must appear" string, look for it.
	if (regmust != NULL && _tcsstr(string, regmust) == NULL)
		return(-1);

	// Mark beginning of line for ^
	regbol = string;

	// Simplest case:  anchored match need be tried only once.
	if (reganch)
	{
		if( regtry(string) )
		{
			// Save the found substring in case we need it
			sFoundText = new TCHAR[GetFoundLength()+1];
			sFoundText[GetFoundLength()] = _T('\0');
			_tcsncpy(sFoundText, string, GetFoundLength() );

			return 0;
		}
		//String not found
		return -1;
	}

	// Messy cases:  unanchored match.
	if (regstart != _T('\0'))
	{
		// We know what TCHAR it must start with.
		for (s = string; s != NULL; s = _tcschr(s+1, regstart))
			if (regtry(s))
			{
				int nPos = s-str;

				// Save the found substring in case we need it later
				sFoundText = new TCHAR[GetFoundLength()+1];
				sFoundText[GetFoundLength()] = _T('\0');
				_tcsncpy(sFoundText, s, GetFoundLength() );

				return nPos;
			}
		return -1;
	}
	else
	{
		// We don't -- general case
		for (s = string; !regtry(s); s++)
			if (*s == _T('\0'))
				return(-1);

		int nPos = s-str;

		// Save the found substring in case we need it later
		sFoundText = new TCHAR[GetFoundLength()+1];
		sFoundText[GetFoundLength()] = _T('\0');
		_tcsncpy(sFoundText, s, GetFoundLength() );

		return nPos;
	}
	// NOTREACHED
}
Example #7
0
/*
 - regexec - match a regexp against a string
 */
int regexec(regex_t  *preg,  const  char *string, size_t nmatch, regmatch_t pmatch[], int eflags)
{
	const char *s;
	int scan;

	/* Be paranoid... */
	if (preg == NULL || preg->program == NULL || string == NULL) {
		return REG_ERR_NULL_ARGUMENT;
	}

	/* Check validity of program. */
	if (*preg->program != REG_MAGIC) {
		return REG_ERR_CORRUPTED;
	}

#ifdef DEBUG
	fprintf(stderr, "regexec: %s\n", string);
	regdump(preg);
#endif

	preg->eflags = eflags;
	preg->pmatch = pmatch;
	preg->nmatch = nmatch;
	preg->start = string;	/* All offsets are computed from here */

	/* Must clear out the embedded repeat counts of REPX and REPXMIN opcodes */
	for (scan = OPERAND(1); scan != 0; scan += regopsize(preg, scan)) {
		int op = OP(preg, scan);
		if (op == END)
			break;
		if (op == REPX || op == REPXMIN)
			preg->program[scan + 4] = 0;
	}

	/* If there is a "must appear" string, look for it. */
	if (preg->regmust != 0) {
		s = string;
		while ((s = str_find(s, preg->program[preg->regmust], preg->cflags & REG_ICASE)) != NULL) {
			if (prefix_cmp(preg->program + preg->regmust, preg->regmlen, s, preg->cflags & REG_ICASE) >= 0) {
				break;
			}
			s++;
		}
		if (s == NULL)	/* Not present. */
			return REG_NOMATCH;
	}

	/* Mark beginning of line for ^ . */
	preg->regbol = string;

	/* Simplest case:  anchored match need be tried only once (maybe per line). */
	if (preg->reganch) {
		if (eflags & REG_NOTBOL) {
			/* This is an anchored search, but not an BOL, so possibly skip to the next line */
			goto nextline;
		}
		while (1) {
			if (regtry(preg, string)) {
				return REG_NOERROR;
			}
			if (*string) {
nextline:
				if (preg->cflags & REG_NEWLINE) {
					/* Try the next anchor? */
					string = strchr(string, '\n');
					if (string) {
						preg->regbol = ++string;
						continue;
					}
				}
			}
			return REG_NOMATCH;
		}
	}

	/* Messy cases:  unanchored match. */
	s = string;
	if (preg->regstart != '\0') {
		/* We know what char it must start with. */
		while ((s = str_find(s, preg->regstart, preg->cflags & REG_ICASE)) != NULL) {
			if (regtry(preg, s))
				return REG_NOERROR;
			s++;
		}
	}
	else
		/* We don't -- general case. */
		while (1) {
			if (regtry(preg, s))
				return REG_NOERROR;
			if (*s == '\0') {
				break;
			}
			else {
				int c;
				s += utf8_tounicode(s, &c);
			}
		}

	/* Failure. */
	return REG_NOMATCH;
}
Example #8
0
/*
 - regexec - match a regexp against a string
 */
cst_regstate *
hs_regexec(const cst_regex *prog, const char *string)
{
	cst_regstate *state;
	char *s;

	/* Be paranoid... */
	if (prog == NULL || string == NULL) {
		FAIL("NULL parameter");
		return(0);
	}

	/* Check validity of program. */
	if (UCHARAT(prog->program) != CST_REGMAGIC) {
		FAIL("corrupted program");
		return(0);
	}

	/* If there is a "must appear" string, look for it. */
	if (prog->regmust != NULL) {
		s = (char *)string;
		while ((s = strchr(s, prog->regmust[0])) != NULL) {
			if (strncmp(s, prog->regmust, prog->regmlen) == 0)
				break;	/* Found it. */
			s++;
		}
		if (s == NULL)	/* Not present. */
			return(0);
	}

	state = cst_alloc(cst_regstate, 1);
	/* Mark beginning of line for ^ . */
	state->bol = string;

	/* Simplest case:  anchored match need be tried only once. */
	if (prog->reganch) {
		if (regtry(state, string, prog->program+1))
			return state;
		else {
			cst_free(state);
			return NULL;
		}
	}

	/* Messy cases:  unanchored match. */
	s = (char *)string;
	if (prog->regstart != '\0')
		/* We know what char it must start with. */
		while ((s = strchr(s, prog->regstart)) != NULL) {
			if (regtry(state, s, prog->program+1))
				return state;
			s++;
		}
	else
		/* We don't -- general case. */
		do {
			if (regtry(state, s, prog->program+1))
				return state;
		} while (*s++ != '\0');

	cst_free(state);
	return NULL;
}
Example #9
0
/*
 - SREexec - match a SRE against a string
 */
int
SREexec(SRE *prog, char *string)
{
	register char *s;
	extern char *strchr();

	/* Be paranoid... */
	if (prog == (SRE *) NULL || string == (char *) NULL) {
		SREerror("NULL parameter");
		return(0);
	}

	/* Check validity of program. */
	if (UCHARAT(prog->program) != SRE_MAGIC) {
		SREerror("corrupted program");
		return(0);
	}

	/* If there is a "must appear" string, look for it. */
	if (prog->regmust != NULL) {
		s = string;
		while ((s = strchr(s, prog->regmust[0])) != NULL) {
			if (strncmp(s, prog->regmust, prog->regmlen) == 0) {
				break;	/* Found it. */
			}
			s++;
		}
		if (s == NULL)	/* Not present. */
			return(0);
	}

	/* Mark beginning of line for ^ . */
	regbol = string;

	/* Simplest case:  anchored match need be tried only once. */
	if (prog->reganch) {
		return(regtry(prog, string));
	}

	/* Messy cases:  unanchored match. */
	s = string;
	if (prog->regstart != '\0') {
		/* We know what char it must start with. */
		while ((s = strchr(s, prog->regstart)) != NULL) {
			if (regtry(prog, s)) {
				return(1);
			}
			if (*s++ == '\n') {
				regbol = s;
			}
		}
	} else {
		/* We don't -- general case. */
		do {
			if (regtry(prog, s)) {
				return(1);
			}
			if (*s++ == '\n') {
				regbol = s;
			}
		} while (*s != '\0');
	}
	/* Failure. */
	return(0);
}