Beispiel #1
0
int
str_match(const char *string, const char *pattern, struct str_match *m,
    const char **errstr)
{
	struct str_find		 sm[MAXCAPTURES];
	struct match_state	 ms;
	int			 i, ret;
	size_t			 len, nsm;

	nsm = MAXCAPTURES;
	memset(&ms, 0, sizeof(ms));
	memset(sm, 0, sizeof(sm));
	memset(m, 0, sizeof(*m));

	ret = str_find_aux(&ms, pattern, string, sm, nsm, 0);
	if (ret <= 0 || ms.error != NULL) {
		/* Return -1 on error and store the error string */
		*errstr = ms.error;
		return (-1);
	}

	if ((m->sm_match = calloc((size_t)ret, sizeof(char *))) == NULL) {
		*errstr = strerror(errno);
		return (-1);
	}
	m->sm_nmatch = ret;

	for (i = 0; i < ret; i++) {
		if (sm[i].sm_so > sm[i].sm_eo)
			continue;
		len = (size_t)(sm[i].sm_eo - sm[i].sm_so);
		if ((m->sm_match[i] = strndup(string +
		    sm[i].sm_so, len)) == NULL) {
			*errstr = strerror(errno);
			str_match_free(m);
			return (-1);
		}
	}

	*errstr = NULL;
	return (0);
}
Beispiel #2
0
int
str_find(const char *string, const char *pattern, struct str_find *sm,
    size_t nsm, const char **errstr)
{
	struct match_state	ms;
	int			ret;

	memset(&ms, 0, sizeof(ms));
	memset(sm, 0, nsm * sizeof(*sm));

	ret = str_find_aux(&ms, pattern, string, sm, nsm, 0);
	if (ms.error != NULL) {
		/* Return 0 on error and store the error string */
		*errstr = ms.error;
		ret = 0;
	} else
		*errstr = NULL;

	return (ret);
}
Beispiel #3
0
static int str_match (lua_State *L) {
  return str_find_aux(L, 0);
}
Beispiel #4
0
static int str_find (lua_State *L) {
  return str_find_aux(L, 1);
}
Beispiel #5
0
/* EXT - new library function */
static int table_match(lua_State *L) {
  return str_find_aux(L, MODE_TABLE);
}
Beispiel #6
0
static int str_match (lua_State *L) {
  return str_find_aux(L, MODE_MATCH);
}
Beispiel #7
0
static int str_find (lua_State *L) {
  return str_find_aux(L, MODE_FIND);
}
Beispiel #8
0
int lua_match (LuaMatchState *ms, const char *s, size_t ls,const char *p, size_t lp, size_t init, int raw_find)
{
    return str_find_aux(ms, 0, s, ls, p, lp, init, raw_find);
}