portreg.h (3083B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 /* 6 * shexp.h: Defines and prototypes for shell exp. match routines 7 * 8 * This routine will match a string with a shell expression. The expressions 9 * accepted are based loosely on the expressions accepted by zsh. 10 * 11 * o * matches anything 12 * o ? matches one character 13 * o \ will escape a special character 14 * o $ matches the end of the string 15 * Bracketed expressions: 16 * o [abc] matches one occurence of a, b, or c. 17 * o [^abc] matches any character except a, b, or c. 18 * To be matched between [ and ], these characters must be escaped: \ ] 19 * No other characters need be escaped between brackets. 20 * Unnecessary escaping is permitted. 21 * o [a-z] matches any character between a and z, inclusive. 22 * The two range-definition characters must be alphanumeric ASCII. 23 * If one is upper case and the other is lower case, then the ASCII 24 * non-alphanumeric characters between Z and a will also be in range. 25 * o [^a-z] matches any character except those between a and z, inclusive. 26 * These forms cannot be combined, e.g [a-gp-z] does not work. 27 * o Exclusions: 28 * As a top level, outter-most expression only, the expression 29 * foo~bar will match the expression foo, provided it does not also 30 * match the expression bar. Either expression or both may be a union. 31 * Except between brackets, any unescaped ~ is an exclusion. 32 * At most one exclusion is permitted. 33 * Exclusions cannot be nested (contain other exclusions). 34 * example: *~abc will match any string except abc 35 * o Unions: 36 * (foo|bar) will match either the expression foo, or the expression bar. 37 * At least one '|' separator is required. More are permitted. 38 * Expressions inside unions may not include unions or exclusions. 39 * Inside a union, to be matched and not treated as a special character, 40 * these characters must be escaped: \ ( | ) [ ~ except when they occur 41 * inside a bracketed expression, where only \ and ] require escaping. 42 * 43 * The public interface to these routines is documented below. 44 * 45 */ 46 47 #ifndef SHEXP_H 48 #define SHEXP_H 49 50 #include "utilrename.h" 51 /* 52 * Requires that the macro MALLOC be set to a "safe" malloc that will 53 * exit if no memory is available. 54 */ 55 56 /* --------------------------- Public routines ---------------------------- */ 57 58 /* 59 * shexp_valid takes a shell expression exp as input. It returns: 60 * 61 * NON_SXP if exp is a standard string 62 * INVALID_SXP if exp is a shell expression, but invalid 63 * VALID_SXP if exp is a valid shell expression 64 */ 65 66 #define NON_SXP -1 67 #define INVALID_SXP -2 68 #define VALID_SXP 1 69 70 SEC_BEGIN_PROTOS 71 72 extern int PORT_RegExpValid(const char *exp); 73 74 extern int PORT_RegExpSearch(const char *str, const char *exp); 75 76 /* same as above but uses case insensitive search */ 77 extern int PORT_RegExpCaseSearch(const char *str, const char *exp); 78 79 SEC_END_PROTOS 80 81 #endif