andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: /* andre@0: * shexp.h: Defines and prototypes for shell exp. match routines andre@0: * andre@0: * This routine will match a string with a shell expression. The expressions andre@0: * accepted are based loosely on the expressions accepted by zsh. andre@0: * andre@0: * o * matches anything andre@0: * o ? matches one character andre@0: * o \ will escape a special character andre@0: * o $ matches the end of the string andre@0: * Bracketed expressions: andre@0: * o [abc] matches one occurence of a, b, or c. andre@0: * o [^abc] matches any character except a, b, or c. andre@0: * To be matched between [ and ], these characters must be escaped: \ ] andre@0: * No other characters need be escaped between brackets. andre@0: * Unnecessary escaping is permitted. andre@0: * o [a-z] matches any character between a and z, inclusive. andre@0: * The two range-definition characters must be alphanumeric ASCII. andre@0: * If one is upper case and the other is lower case, then the ASCII andre@0: * non-alphanumeric characters between Z and a will also be in range. andre@0: * o [^a-z] matches any character except those between a and z, inclusive. andre@0: * These forms cannot be combined, e.g [a-gp-z] does not work. andre@0: * o Exclusions: andre@0: * As a top level, outter-most expression only, the expression andre@0: * foo~bar will match the expression foo, provided it does not also andre@0: * match the expression bar. Either expression or both may be a union. andre@0: * Except between brackets, any unescaped ~ is an exclusion. andre@0: * At most one exclusion is permitted. andre@0: * Exclusions cannot be nested (contain other exclusions). andre@0: * example: *~abc will match any string except abc andre@0: * o Unions: andre@0: * (foo|bar) will match either the expression foo, or the expression bar. andre@0: * At least one '|' separator is required. More are permitted. andre@0: * Expressions inside unions may not include unions or exclusions. andre@0: * Inside a union, to be matched and not treated as a special character, andre@0: * these characters must be escaped: \ ( | ) [ ~ except when they occur andre@0: * inside a bracketed expression, where only \ and ] require escaping. andre@0: * andre@0: * The public interface to these routines is documented below. andre@0: * andre@0: */ andre@0: andre@0: #ifndef SHEXP_H andre@0: #define SHEXP_H andre@0: andre@0: #include "utilrename.h" andre@0: /* andre@0: * Requires that the macro MALLOC be set to a "safe" malloc that will andre@0: * exit if no memory is available. andre@0: */ andre@0: andre@0: andre@0: /* --------------------------- Public routines ---------------------------- */ andre@0: andre@0: andre@0: /* andre@0: * shexp_valid takes a shell expression exp as input. It returns: andre@0: * andre@0: * NON_SXP if exp is a standard string andre@0: * INVALID_SXP if exp is a shell expression, but invalid andre@0: * VALID_SXP if exp is a valid shell expression andre@0: */ andre@0: andre@0: #define NON_SXP -1 andre@0: #define INVALID_SXP -2 andre@0: #define VALID_SXP 1 andre@0: andre@0: SEC_BEGIN_PROTOS andre@0: andre@0: extern int PORT_RegExpValid(const char *exp); andre@0: andre@0: extern int PORT_RegExpSearch(const char *str, const char *exp); andre@0: andre@0: /* same as above but uses case insensitive search */ andre@0: extern int PORT_RegExpCaseSearch(const char *str, const char *exp); andre@0: andre@0: SEC_END_PROTOS andre@0: andre@0: #endif