Back to index

lightning-sunbird  0.9+nobinonly
nsWildCard.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /*
00039  * shexp.h: Defines and prototypes for shell exp. match routines
00040  * 
00041  *
00042  * This routine will match a string with a shell expression. The expressions
00043  * accepted are based loosely on the expressions accepted by zsh.
00044  * 
00045  * o * matches anything
00046  * o ? matches one character
00047  * o \ will escape a special character
00048  * o $ matches the end of the string
00049  * o [abc] matches one occurence of a, b, or c. The only character that needs
00050  *         to be escaped in this is ], all others are not special.
00051  * o [a-z] matches any character between a and z
00052  * o [^az] matches any character except a or z
00053  * o ~ followed by another shell expression will remove any pattern
00054  *     matching the shell expression from the match list
00055  * o (foo|bar) will match either the substring foo, or the substring bar.
00056  *             These can be shell expressions as well.
00057  * 
00058  * The public interface to these routines is documented below.
00059  * 
00060  * Rob McCool
00061  * 
00062  */
00063  
00064 #ifndef nsWildCard_h__
00065 #define nsWildCard_h__
00066 
00067 #include "prtypes.h"
00068 #include <ctype.h>  /* isalnum */
00069 #include <string.h> /* strlen */
00070 
00071 /* --------------------------- Public routines ---------------------------- */
00072 
00073 
00074 /*
00075  * NS_WildCardValid takes a shell expression exp as input. It returns:
00076  * 
00077  *  NON_SXP      if exp is a standard string
00078  *  INVALID_SXP  if exp is a shell expression, but invalid
00079  *  VALID_SXP    if exp is a valid shell expression
00080  */
00081 
00082 #define NON_SXP -1
00083 #define INVALID_SXP -2
00084 #define VALID_SXP 1
00085 
00086 extern int NS_WildCardValid(char *expr);
00087 
00088 
00089 /* return values for the search routines */
00090 #define MATCH 0
00091 #define NOMATCH 1
00092 #define ABORTED -1
00093 
00094 /*
00095  * NS_WildCardMatch
00096  * 
00097  * Takes a prevalidated shell expression exp, and a string str.
00098  *
00099  * Returns 0 on match and 1 on non-match.
00100  */
00101 
00102 extern int NS_WildCardMatch(char *str, char *expr, PRBool case_insensitive);
00103 
00104 /*
00105  * Same as above, but validates the exp first. 0 on match, 1 on non-match,
00106  * -1 on invalid exp.
00107  */
00108 
00109 extern int NS_WildCardSearch(char *str, char *expr);
00110 
00111 /*
00112  * Same as above but uses case insensitive search.
00113  */
00114 extern int NS_WildCardCaseSearch(char *str, char *expr);
00115 
00116 #endif /* nsWildCard_h__ */