Пример #1
0
/* PATCH IDEA FROM Issei.Suzuki VERY THANKS */
void
autoset_dspmbyte(const Char *pcp)
{
    int i;
    static const struct dspm_autoset_Table {
	Char *n;
	Char *v;
    } dspmt[] = {
	{ STRLANGEUCJP, STReuc },
	{ STRLANGEUCKR, STReuc },
	{ STRLANGEUCZH, STReuc },
	{ STRLANGEUCJPB, STReuc },
	{ STRLANGEUCKRB, STReuc },
	{ STRLANGEUCZHB, STReuc },
#ifdef __linux__
	{ STRLANGEUCJPC, STReuc },
#endif
	{ STRLANGSJIS, STRsjis },
	{ STRLANGSJISB, STRsjis },
	{ STRLANGBIG5, STRbig5 },
	{ STRstarutfstar8, STRutf8 },
	{ NULL, NULL }
    };
#if defined(HAVE_NL_LANGINFO) && defined(CODESET)
    static const struct dspm_autoset_Table dspmc[] = {
	{ STRstarutfstar8, STRutf8 },
	{ STReuc, STReuc },
	{ STRGB2312, STReuc },
	{ STRLANGBIG5, STRbig5 },
	{ NULL, NULL }
    };
    Char *codeset;

    codeset = str2short(nl_langinfo(CODESET));
    if (*codeset != '\0') {
	for (i = 0; dspmc[i].n; i++) {
	    const Char *estr;
	    if (dspmc[i].n[0] && t_pmatch(pcp, dspmc[i].n, &estr, 0) > 0) {
		setcopy(CHECK_MBYTEVAR, dspmc[i].v, VAR_READWRITE);
		update_dspmbyte_vars();
		return;
	    }
	}
    }
#endif
    
    if (*pcp == '\0')
	return;

    for (i = 0; dspmt[i].n; i++) {
	const Char *estr;
	if (dspmt[i].n[0] && t_pmatch(pcp, dspmt[i].n, &estr, 0) > 0) {
	    setcopy(CHECK_MBYTEVAR, dspmt[i].v, VAR_READWRITE);
	    update_dspmbyte_vars();
	    break;
	}
    }
}
Пример #2
0
int
Gnmatch(const Char *string, const Char *pattern, const Char **endstr)
{
    Char ***fblk, **p;
    const Char *tstring = string;
    int	   gpol = 1, gres = 0;

    if (*pattern == '^') {
	gpol = 0;
	pattern++;
    }

    fblk = xmalloc(sizeof(Char ***));
    *fblk = xmalloc(GLOBSPACE * sizeof(Char *));
    (*fblk)[0] = Strsave(pattern);
    (*fblk)[1] = NULL;

    cleanup_push(fblk, blk_indirect_cleanup);
    expbrace(fblk, NULL, GLOBSPACE);

    if (endstr == NULL)
	/* Exact matches only */
	for (p = *fblk; *p; p++) 
	    gres |= t_pmatch(string, *p, &tstring, 1) == 2 ? 1 : 0;
    else {
	const Char *end;

	/* partial matches */
        end = Strend(string);
	for (p = *fblk; *p; p++)
	    if (t_pmatch(string, *p, &tstring, 1) != 0) {
		gres |= 1;
		if (end > tstring)
		    end = tstring;
	    }
	*endstr = end;
    }

    cleanup_until(fblk);
    return(gres == gpol);
} 
Пример #3
0
/* t_pmatch():
 *	Return 2 on exact match, 	
 *	Return 1 on substring match.
 *	Return 0 on no match.
 *	*estr will point to the end of the longest exact or substring match.
 */
int
t_pmatch(const Char *string, const Char *pattern, const Char **estr, int cs)
{
    Char stringc, patternc, rangec;
    int     match, negate_range;
    const Char *pestr, *nstring;

    for (nstring = string;; string = nstring) {
	stringc = *nstring++ & TRIM;
	patternc = *pattern++ & TRIM;
	switch (patternc) {
	case '\0':
	    *estr = string;
	    return (stringc == '\0' ? 2 : 1);
	case '?':
	    if (stringc == 0)
		return (0);
	    break;
	case '*':
	    if (!*pattern) {
		*estr = Strend(string);
		return (2);
	    }
	    pestr = NULL;

	    for (;;) {
		switch(t_pmatch(string, pattern, estr, cs)) {
		case 0:
		    break;
		case 1:
		    pestr = *estr;/*FIXME: does not guarantee longest match */
		    break;
		case 2:
		    return 2;
		default:
		    abort();	/* Cannot happen */
		}
		stringc = *string++ & TRIM;
		if (!stringc)
		    break;
	    }

	    if (pestr) {
		*estr = pestr;
		return 1;
	    }
	    else
		return 0;

	case '[':
	    match = 0;
	    if ((negate_range = (*pattern == '^')) != 0)
		pattern++;
	    while ((rangec = *pattern++ & TRIM) != '\0') {
		if (rangec == ']')
		    break;
		if (match)
		    continue;
		if (*pattern == '-' && pattern[1] != ']') {
		    Char rangec2;
		    pattern++;
		    rangec2 = *pattern++ & TRIM;
		    match = (globcharcoll(stringc, rangec2, 0) <= 0 &&
			globcharcoll(rangec, stringc, 0) <= 0);
		}
		else 
		    match = (stringc == rangec);
	    }
	    if (rangec == '\0')
		stderror(ERR_NAME | ERR_MISSING, ']');
	    if ((!match) && (stringc == '\0'))
		return (0);
	    if (match == negate_range)
		return (0);
	    break;
	default:
	    if (cs ? patternc  != stringc
		: Tolower(patternc) != Tolower(stringc))
		return (0);
	    break;
	}
    }
}