From 73f64102bd839c6dae1a72574c1e4223a87a9a34 Mon Sep 17 00:00:00 2001 From: "Alexander S. Aganichev" Date: Thu, 3 Apr 2003 14:10:24 +0000 Subject: [PATCH] Fix license issue --- goldlib/msgidlib/patmat.c | 158 ++++++++------------------------------ 1 file changed, 34 insertions(+), 124 deletions(-) diff --git a/goldlib/msgidlib/patmat.c b/goldlib/msgidlib/patmat.c index 4b7591b..19d9bd6 100755 --- a/goldlib/msgidlib/patmat.c +++ b/goldlib/msgidlib/patmat.c @@ -3,140 +3,50 @@ */ /* - * Copyright (c) 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Kenneth Almquist. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. + * Written by Alexander S. Aganichev. * + * Released to public domain. */ - -#include - -#define CTLESC '\\' - /* * Returns true if the pattern matches the string. */ -int patmat(char *string, char *pattern) +int patmat (char *tag, char *mask) { - register char *p, *q; - register char c; - - p = pattern; - q = string; - for (;;) { - switch (c = *p++) { - case '\0': - goto breakloop; - case CTLESC: - if (*q++ != *p++) - return 0; - break; - case '?': - if (*q++ == '\0') - return 0; - break; - case '*': - c = *p; - if (c != CTLESC && c != '?' && c != '*' && c != '[') { - while (*q != c) { - if (*q == '\0') - return 0; - q++; - } - } - do { - if (patmat(q, p)) - return 1; - } while (*q++ != '\0'); - return 0; - case '[': { - char *endp; - int invert, found; - char chr; - - endp = p; - if (*endp == '!') - endp++; - for (;;) { - if (*endp == '\0') - goto dft; /* no matching ] */ - if (*endp == CTLESC) - endp++; - if (*++endp == ']') - break; - } - invert = 0; - if (*p == '!') { - invert++; - p++; - } - found = 0; - chr = *q++; - c = *p++; - do { - if (c == CTLESC) - c = *p++; - if (*p == '-' && p[1] != ']') { - p++; - if (*p == CTLESC) - p++; - if (chr >= c && chr <= *p) - found = 1; - p++; - } else { - if (chr == c) - found = 1; - } - } while ((c = *p++) != ']'); - if (found == invert) - return 0; - break; - } -dft: default: - if (*q++ != c) - return 0; - break; - } - } -breakloop: - if (*q != '\0') - return 0; - return 1; + if (tag && mask) { + while (*tag && *mask) + if ((*tag == *mask) || (*mask == '?')) { + ++ tag; + ++ mask; + } else if (*mask == '*') { + while ((*mask == '*') || (*mask == '?')) { + if (*mask == '?') { + if (*tag) + ++ tag; + else + return 0; + } + ++ mask; + } + if (*mask) { + while (*tag && !patmat (tag, mask)) + ++ tag; + if (*tag) + return 1; + } else + return 1; + } else + return 0; + while (*mask == '*') + ++ mask; + if (*mask) + return 0; + return (*tag) ? 0 : 1; + } + return 0; } - #ifdef TEST #include