2 * Copyright (c) 1994, 1995. Netscape Communications Corporation. All
5 * Use of this software is governed by the terms of the license agreement for
6 * the Netscape Communications or Netscape Comemrce Server between the
11 /* ------------------------------------------------------------------------ */
15 * shexp.h: Defines and prototypes for shell exp. match routines
17 * This routine will match a string with a shell expression. The expressions
18 * accepted are based loosely on the expressions accepted by zsh.
20 * o * matches anything
21 * o ? matches one character
22 * o \ will escape a special character
23 * o $ matches the end of the string
24 * o [abc] matches one occurrence of a, b, or c. The only character that needs
25 * to be escaped in this is ], all others are not special.
26 * o [a-z] matches any character between a and z
27 * o [^az] matches any character except a or z
28 * o ~ followed by another shell expression will remove any pattern
29 * matching the shell expression from the match list
30 * o (foo|bar) will match either the substring foo, or the substring bar.
31 * These can be shell expressions as well.
33 * The public interface to these routines is documented below.
42 * Requires that the macro MALLOC be set to a "safe" malloc that will
43 * exit if no memory is available. If not under MCC httpd, define MALLOC
44 * to be the real malloc and play with fire, or make your own function.
47 #include "../netsite.h"
49 #include <ctype.h> /* isalnum */
50 #include <string.h> /* strlen */
53 /* --------------------------- Public routines ---------------------------- */
57 * shexp_valid takes a shell expression exp as input. It returns:
59 * NON_SXP if exp is a standard string
60 * INVALID_SXP if exp is a shell expression, but invalid
61 * VALID_SXP if exp is a valid shell expression
65 #define INVALID_SXP -2
68 int shexp_valid(char *exp
);
73 * Takes a prevalidated shell expression exp, and a string str.
75 * Returns 0 on match and 1 on non-match.
78 int shexp_match(char *str
, char *exp
);
84 * Same as above, but validates the exp first. 0 on match, 1 on non-match,
85 * -1 on invalid exp. shexp_casecmp does the same thing but is case
89 int shexp_cmp(char *str
, char *exp
);
90 int shexp_casecmp(char *str
, char *exp
);