Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
[privoxy.git] / miscutil.c
similarity index 98%
rename from src/miscutil.c
rename to miscutil.c
index 6f6a8eb..5679ca2 100644 (file)
@@ -1,7 +1,7 @@
-const char miscutil_rcs[] = "$Id: miscutil.c,v 2.4 2002/11/12 14:30:04 oes Exp $";
+const char miscutil_rcs[] = "$Id: miscutil.c,v 1.37.2.4 2003/12/01 14:45:14 oes Exp $";
 /*********************************************************************
  *
- * File        :  $Source: /cvsroot/ijbswa/current/src/miscutil.c,v $
+ * File        :  $Source: /cvsroot/ijbswa/current/Attic/miscutil.c,v $
  *
  * Purpose     :  zalloc, hash_string, safe_strerror, strcmpic,
  *                strncmpic, chomp, and MinGW32 strdup
@@ -36,22 +36,19 @@ const char miscutil_rcs[] = "$Id: miscutil.c,v 2.4 2002/11/12 14:30:04 oes Exp $
  *
  * Revisions   :
  *    $Log: miscutil.c,v $
- *    Revision 2.4  2002/11/12 14:30:04  oes
+ *    Revision 1.37.2.4  2003/12/01 14:45:14  oes
+ *    Fixed two more problems with wildcarding in simplematch()
+ *
+ *    Revision 1.37.2.3  2003/11/20 11:39:24  oes
+ *    Bugfix: The "?" wildcard for domain names had never been implemented. Ooops\!
+ *
+ *    Revision 1.37.2.2  2002/11/12 14:28:18  oes
  *    Proper backtracking in simplematch; fixes bug #632888
  *
- *    Revision 2.3  2002/09/25 13:00:41  oes
+ *    Revision 1.37.2.1  2002/09/25 12:58:51  oes
  *    Made strcmpic and strncmpic safe against NULL arguments
  *    (which are now treated as empty strings).
  *
- *    Revision 2.2  2002/08/26 11:16:33  sarantis
- *    Fix typo.
- *
- *    Revision 2.1  2002/06/04 17:22:37  jongfoster
- *    Adding comments
- *
- *    Revision 2.0  2002/06/04 14:34:21  jongfoster
- *    Moving source files to src/
- *
  *    Revision 1.37  2002/04/26 18:29:43  jongfoster
  *    Fixing this Visual C++ warning:
  *    miscutil.c(710) : warning C4090: '=' : different 'const' qualifiers
@@ -312,7 +309,7 @@ void write_pid_file(void)
  *                to "switch" a string the one of my favorites.
  *
  * Parameters  :
- *          1  :  s = string to be hashed.
+ *          1  :  s : string to be hashed.
  *
  * Returns     :  an unsigned long variable with the hashed value.
  *
@@ -475,7 +472,7 @@ int strncmpic(const char *s1, const char *s2, size_t n)
  *                from a string.
  *
  * Parameters  :
- *          1  :  string = string to be chomped.
+ *          1  :  s : string to be chomped.
  *
  * Returns     :  chomped string
  *
@@ -643,8 +640,9 @@ jb_err string_append(char **target_string, const char *text_to_append)
    if (NULL == (new_string = realloc(*target_string,
           strlen(text_to_append) + old_len + 1)))
    {
-      freez(*target_string);
+      free(*target_string);
 
+      *target_string = NULL;
       return JB_ERR_MEMORY;
    }
 
@@ -772,14 +770,20 @@ int simplematch(char *pattern, char *text)
    unsigned i;
    unsigned char charmap[32];
   
-  
    while (*txt)
    {
 
       /* EOF pattern but !EOF text? */
       if (*pat == '\0')
       {
-         return 1;
+         if (wildcard)
+         {
+            pat = fallback;
+         }
+         else
+         {
+            return 1;
+         }
       }
 
       /* '*' in the pattern?  */
@@ -828,9 +832,12 @@ int simplematch(char *pattern, char *text)
       } /* -END- if Character range specification */
 
 
-      /* Compare: Char match, or char range match*/
-      if ((*pat == *txt)  
-      || ((*pat == ']') && (charmap[*txt / 8] & (1 << (*txt % 8)))) )
+      /* 
+       * Char match, or char range match? 
+       */
+      if ( (*pat == *txt)
+      ||   (*pat == '?')
+      ||   ((*pat == ']') && (charmap[*txt / 8] & (1 << (*txt % 8)))) )
       {
          /* 
           * Sucess: Go ahead
@@ -850,10 +857,9 @@ int simplematch(char *pattern, char *text)
           * Wildcard mode && nonmatch beyond fallback: Rewind pattern
           */
          pat = fallback;
-         continue;
       }
       txt++;
-   } 
+   }
 
    /* Cut off extra '*'s */
    if(*pat == '*')  pat++;
@@ -875,7 +881,7 @@ int simplematch(char *pattern, char *text)
  *          1  :  string = string to be duplicated
  *          2  :  len = number of bytes to duplicate
  *
- * Returns     :  pointer to copy, or NULL if failure
+ * Returns     :  pointer to copy, or NULL if failiure
  *
  *********************************************************************/
 char *bindup(const char *string, size_t len)
@@ -907,8 +913,8 @@ char *bindup(const char *string, size_t len)
  *                the filename. 
  *
  * Parameters  :
- *          1  :  dir = Name of directory or NULL for none.
- *          2  :  file = Name of file.  Should not be NULL or empty.
+ *          1  :  dir: Name of directory or NULL for none.
+ *          2  :  file: Name of file.  Should not be NULL or empty.
  *
  * Returns     :  "dir/file" (Or on windows, "dir\file").
  *                It allocates the string on the heap.  Caller frees.