Example #1
0
MAIN()
{
    char pattern[50], string[50];

    while (1)
    {
	putchar('\n');
	printf("pattern:  ");
	if (fgets(pattern, sizeof(pattern)-1, stdin) == NULL)
	    break;
	printf("string:   ");
	if (fgets(string, sizeof(pattern)-1, stdin) == NULL)
	    break;
	printf("MATCH is %s\n",
		((strwcmp(pattern, string) == 0) ? "SUCCEEDED" : "FAILED"));
	putchar('\n');
	printf("MATCHI is %s\n",
		((strwcmpi(pattern, string) == 0) ? "SUCCEEDED" : "FAILED"));
    }

    return 0;
}
Example #2
0
int
strwcmp (char *wild_, char *tame_)
{
	while (*wild_ && *tame_)
	{
	    if (*wild_ == ANY)
	    {
		while (*wild_ == ANY)	wild_++;
		if (*wild_)
		{
		    while (*tame_)
		    {
			if (strwcmp (wild_, tame_))
			    tame_++;
			else
			    return (EQUAL);
		    }
		    return (! EQUAL);
		}
		else	/* Match remainder of string	*/
		    return (EQUAL);
	    }
	    else if (*wild_ == ONE)
		wild_++, tame_++;
	    else if (*wild_ == DOT)
	    {
		/*
		 * If we have an ellipsis, we may match any number of directory
		 * names, separated by '.', e.g., [...] matches
		 *	[name]
		 *	[.name]
		 *	[name.name]
		 */
		if (! strncmp (wild_, ELLIPSIS, sizeof(ELLIPSIS)-1))
		{
		    wild_ += sizeof(ELLIPSIS)-1;
		    if (*tame_ == DOT)
		    	tame_++;
		    /*
		     * The inputs to this routine *must* be syntactically
		     * correct.  VMS permits an ellipsis only within brackets.
		     * Therefore, we can safely (?) test the last character
		     * before the current scanning position:
		     */
		    else if (tame_[-1] != '.' && tame_[-1] != '[')
		    	return (! EQUAL);

		    /*
		     * Fall-thru to scan matches against an ellipsis:
		     */
		    while (*tame_ && (*tame_ != ']'))
		    {
			if (strwcmp (wild_, tame_))
			{
			    while ((*tame_ != DOT) && (*tame_ != ']'))
				tame_++;
			    if (*tame_ == DOT)	tame_++;
			}
			else
			    return (EQUAL);
		    }
		    return (strwcmp (wild_, tame_));
		}
		else if (*wild_++ != *tame_++)
		    return (! EQUAL);
	    }
	    else if (*wild_++ != *tame_++)
		return (! EQUAL);
	}

	if (*wild_ == ANY)
	    return (wild_[1] != '\0');
	return (*wild_ || *tame_); /* Equal if both end at the same point */
}