Example #1
0
File: misc.c Project: adtools/abcsh
int
gmatch(const char *s, const char *p, int isfile)
{
        const char *se, *pe;

        if (s == NULL || p == NULL)
                return 0;
        se = s + strlen(s);
        pe = p + strlen(p);
        /* isfile is false iff no syntax check has been done on
         * the pattern.  If check fails, just to a strcmp().
         */
        if (!isfile && !has_globbing(p, pe)) {
                int len = pe - p + 1;
                char tbuf[64];
                char *t = len <= sizeof(tbuf) ? tbuf :
                        (char *) alloc(len, ATEMP);
                debunk(t, p, len);
                return !strcmp(t, s);
        }
        return do_gmatch((const unsigned char *) s, (const unsigned char *) se,
                         (const unsigned char *) p, (const unsigned char *) pe);
}
Example #2
0
/*
 * int gmatch(string, pattern)
 * char *string, *pattern;
 *
 * Match a pattern as in sh(1).
 * pattern character are prefixed with MAGIC by expand.
 */
int
gmatchx(const char *s, const char *p, bool isfile)
{
	const char *se, *pe;
	char *pnew;
	int rv;

	if (s == NULL || p == NULL)
		return (0);

	se = s + strlen(s);
	pe = p + strlen(p);
	/*
	 * isfile is false iff no syntax check has been done on
	 * the pattern. If check fails, just to a strcmp().
	 */
	if (!isfile && !has_globbing(p, pe)) {
		size_t len = pe - p + 1;
		char tbuf[64];
		char *t = len <= sizeof(tbuf) ? tbuf : alloc(len, ATEMP);
		debunk(t, p, len);
		return (!strcmp(t, s));
	}

	/*
	 * since the do_gmatch() engine sucks so much, we must do some
	 * pattern simplifications
	 */
	pnew = simplify_gmatch_pattern((const unsigned char *)p);
	pe = pnew + strlen(pnew);

	rv = do_gmatch((const unsigned char *)s, (const unsigned char *)se,
	    (const unsigned char *)pnew, (const unsigned char *)pe);
	afree(pnew, ATEMP);
	return (rv);
}