chiark / gitweb /
buf.h: Spurious `\' prevents declaration of `buf_putstr*'.
[mLib] / str.h
diff --git a/str.h b/str.h
index 1581e500111aef150acf758a14b3b41d90d50a53..9d3192e1064cd99edf698bcccf6a47bb82b0940b 100644 (file)
--- a/str.h
+++ b/str.h
@@ -1,13 +1,13 @@
 /* -*-c-*-
  *
- * $Id: str.h,v 1.3 1999/12/10 23:42:04 mdw Exp $
+ * $Id: str.h,v 1.5 2004/04/08 01:36:13 mdw Exp $
  *
  * Functions for hacking with strings
  *
  * (c) 1999 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of the mLib utilities library.
  *
  * it under the terms of the GNU Library General Public License as
  * published by the Free Software Foundation; either version 2 of the
  * License, or (at your option) any later version.
- * 
+ *
  * mLib is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Library General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Library General Public
  * License along with mLib; if not, write to the Free
  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  * MA 02111-1307, USA.
  */
 
-/*----- Revision history --------------------------------------------------* 
- *
- * $Log: str.h,v $
- * Revision 1.3  1999/12/10 23:42:04  mdw
- * Change header file guard names.
- *
- * Revision 1.2  1999/05/26 20:52:57  mdw
- * Add new `rest' argument for `str_split'.
- *
- * Revision 1.1  1999/05/17 20:37:01  mdw
- * Some trivial string hacks.
- *
- */
-
 #ifndef MLIB_STR_H
 #define MLIB_STR_H
 
 
 /*----- Functions provided ------------------------------------------------*/
 
-/* --- @str_getword@ --- *
+/* --- @str_qword@ --- *
  *
  * Arguments:  @char **pp@ = address of pointer into string
+ *             @unsigned f@ = various flags
  *
- * Returns:    Pointer to the next space-separated word from the string,
- *             or null.
+ * Returns:    Pointer to the next space-separated possibly-quoted word from
+ *             the string, or null.
  *
- * Use:                Parses off space-separated words from a string.
+ * Use:                Fetches the next word from a string.  If the flag
+ *             @STRF_QUOTE@ is set, the `\' character acts as an escape, and
+ *             single and double quotes protect whitespace.
  */
 
-extern char *str_getword(char **/*pp*/);
+#define STRF_QUOTE 1u
 
-/* --- @str_split@ --- *
+extern char *str_qword(char **/*pp*/, unsigned /*f*/);
+
+/* --- @str_qsplit@ --- *
  *
  * Arguments:  @char *p@ = pointer to string
  *             @char *v[]@ = pointer to array to fill in
  *             @size_t c@ = count of strings to fill in
  *             @char **rest@ = where to store the remainder of the string
+ *             @unsigned f@ = flags for @str_qword@
  *
  * Returns:    Number of strings filled in.
  *
@@ -86,9 +78,69 @@ extern char *str_getword(char **/*pp*/);
  *             @rest@ is set to a null pointer.
  */
 
+extern size_t str_qsplit(char */*p*/, char */*v*/[], size_t /*c*/,
+                        char **/*rest*/, unsigned /*f*/);
+
+/* --- @str_getword@ --- *
+ *
+ * Arguments:  @char **pp@ = address of pointer into string
+ *
+ * Returns:    Pointer to the next space-separated word from the string,
+ *             or null.
+ *
+ * Use:                Parses off space-separated words from a string.  This is a
+ *             compatibility veneer over @str_qword@.
+ */
+
+extern char *str_getword(char **/*pp*/);
+
+/* --- @str_split@ --- *
+ *
+ * Arguments:  @char *p@ = pointer to string
+ *             @char *v[]@ = pointer to array to fill in
+ *             @size_t c@ = count of strings to fill in
+ *             @char **rest@ = where to store the remainder of the string
+ *
+ * Returns:    Number of strings filled in.
+ *
+ * Use:                Fills an array with pointers to the individual words of a
+ *             string.  This is a compatibility veneer over @str_qsplit@.
+ */
+
 extern size_t str_split(char */*p*/, char */*v*/[],
                        size_t /*c*/, char **/*rest*/);
 
+/* --- @str_matchx@ --- *
+ *
+ * Arguments:  @const char *p@ = pointer to pattern string
+ *             @const char *s@ = string to compare with
+ *             @unsigned f@ = various flags
+ *
+ * Returns:    Nonzero if the pattern matches the string.
+ *
+ * Use:                Does simple wildcard matching.  This is quite nasty and more
+ *             than a little slow.  Supports metacharacters `*', `?' and
+ *             '['.
+ */
+
+#define STRF_PREFIX 1u                 /* Accept if @s@ is exhausted during
+                                        *   the attempted match */
+
+extern int str_matchx(const char */*p*/, const char */*s*/, unsigned /*f*/);
+
+/* --- @str_match@ --- *
+ *
+ * Arguments:  @const char *p@ = pointer to pattern string
+ *             @const char *s@ = string to compare with
+ *
+ * Returns:    Nonzero if the pattern matches the string.
+ *
+ * Use:                Does simple wildcard matching.  Equivalent to @str_matchx@
+ *             with zero flags word.
+ */
+
+extern int str_match(const char */*p*/, const char */*s*/);
+
 /* --- @str_sanitize@ --- *
  *
  * Arguments:  @char *d@ = destination buffer