Try to fix some of the build problems, it still bumms out on:
[obnox/wireshark/wip.git] / filters.c
index e8c22d1c3a9de7ead1b999f9481383f15a651e2c..d2c63f711186640a27e9dbe340ec5b98faa8f1d2 100644 (file)
--- a/filters.c
+++ b/filters.c
@@ -40,7 +40,7 @@
 #include <epan/filesystem.h>
 
 #include "filters.h"
 #include <epan/filesystem.h>
 
 #include "filters.h"
-#include "file_util.h"
+#include <wsutil/file_util.h>
 
 /*
  * Old filter file name.
 
 /*
  * Old filter file name.
@@ -88,7 +88,7 @@ static GList *display_edited_filters = NULL;
 
 #define INIT_BUF_SIZE  128
 
 
 #define INIT_BUF_SIZE  128
 
-GList *
+static GList *
 add_filter_entry(GList *fl, const char *filt_name, const char *filt_expr)
 {
     filter_def *filt;
 add_filter_entry(GList *fl, const char *filt_name, const char *filt_expr)
 {
     filter_def *filt;
@@ -99,7 +99,7 @@ add_filter_entry(GList *fl, const char *filt_name, const char *filt_expr)
     return g_list_append(fl, filt);
 }
 
     return g_list_append(fl, filt);
 }
 
-GList *
+static GList *
 remove_filter_entry(GList *fl, GList *fl_entry)
 {
   filter_def *filt;
 remove_filter_entry(GList *fl, GList *fl_entry)
 {
   filter_def *filt;
@@ -145,8 +145,8 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return,
   }
 
   /* try to open personal "cfilters"/"dfilters" file */
   }
 
   /* try to open personal "cfilters"/"dfilters" file */
-  ff_path = get_persconffile_path(ff_name, FALSE);
-  if ((ff = eth_fopen(ff_path, "r")) == NULL) {
+  ff_path = get_persconffile_path(ff_name, TRUE, FALSE);
+  if ((ff = ws_fopen(ff_path, "r")) == NULL) {
     /*
      * Did that fail because the file didn't exist?
      */
     /*
      * Did that fail because the file didn't exist?
      */
@@ -168,49 +168,52 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return,
      * a particular list.
      */
     g_free(ff_path);
      * a particular list.
      */
     g_free(ff_path);
-    ff_path = get_persconffile_path(FILTER_FILE_NAME, FALSE);
-    if ((ff = eth_fopen(ff_path, "r")) == NULL) {
-    /*
-     * Did that fail because the file didn't exist?
-     */
-      if (errno != ENOENT) {
+    ff_path = get_persconffile_path(FILTER_FILE_NAME, FALSE, FALSE);
+    if ((ff = ws_fopen(ff_path, "r")) == NULL) {
       /*
       /*
-       * No.  Just give up.
+       * Did that fail because the file didn't exist?
        */
        */
-       *pref_path_return = ff_path;
-       *errno_return = errno;
-    return;
-      }
-
-    /*
-     * Try to open the global "cfilters/dfilters" file */
-    ff_path = get_datafile_path(ff_name);
-    if ((ff = eth_fopen(ff_path, "r")) == NULL) {
+       if (errno != ENOENT) {
+       /*
+        * No.  Just give up.
+        */
+         *pref_path_return = ff_path;
+         *errno_return = errno;
+         return;
+       }
 
       /*
 
       /*
-       * Well, that didn't work, either.  Just give up.
-       * Return an error if the file existed but we couldn't open it.
-       */
-      if (errno != ENOENT) {
-       *pref_path_return = ff_path;
-       *errno_return = errno;
-    }
-    return;
-    }
+       * Try to open the global "cfilters/dfilters" file */
+      g_free(ff_path);
+      ff_path = get_datafile_path(ff_name);
+      if ((ff = ws_fopen(ff_path, "r")) == NULL) {
+
+       /*
+        * Well, that didn't work, either.  Just give up.
+        * Return an error if the file existed but we couldn't open it.
+        */
+       if (errno != ENOENT) {
+         *pref_path_return = ff_path;
+         *errno_return = errno;
+       } else {
+         g_free(ff_path);
+       }
+       return;
+      }
     }
   }
 
   /* If we already have a list of filters, discard it. */
   /* this should never happen - this function is called only once for each list! */
   while(*flpp) {
     }
   }
 
   /* If we already have a list of filters, discard it. */
   /* this should never happen - this function is called only once for each list! */
   while(*flpp) {
-    *flpp = remove_filter_entry(*flpp, g_list_first(*flpp));        
+    *flpp = remove_filter_entry(*flpp, g_list_first(*flpp));
   }
 
   /* Allocate the filter name buffer. */
   filt_name_len = INIT_BUF_SIZE;
   }
 
   /* Allocate the filter name buffer. */
   filt_name_len = INIT_BUF_SIZE;
-  filt_name = g_malloc(filt_name_len + 1);
+  filt_name = (char *)g_malloc(filt_name_len + 1);
   filt_expr_len = INIT_BUF_SIZE;
   filt_expr_len = INIT_BUF_SIZE;
-  filt_expr = g_malloc(filt_expr_len + 1);
+  filt_expr = (char *)g_malloc(filt_expr_len + 1);
 
   for (line = 1; ; line++) {
     /* Lines in a filter file are of the form
 
   for (line = 1; ; line++) {
     /* Lines in a filter file are of the form
@@ -254,7 +257,7 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return,
        if (filt_name_index >= filt_name_len) {
          /* Filter name buffer isn't long enough; double its length. */
          filt_name_len *= 2;
        if (filt_name_index >= filt_name_len) {
          /* Filter name buffer isn't long enough; double its length. */
          filt_name_len *= 2;
-         filt_name = g_realloc(filt_name, filt_name_len + 1);
+         filt_name = (char *)g_realloc(filt_name, filt_name_len + 1);
        }
        filt_name[filt_name_index] = '\0';
        break;
        }
        filt_name[filt_name_index] = '\0';
        break;
@@ -269,7 +272,7 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return,
       if (filt_name_index >= filt_name_len) {
        /* Filter name buffer isn't long enough; double its length. */
        filt_name_len *= 2;
       if (filt_name_index >= filt_name_len) {
        /* Filter name buffer isn't long enough; double its length. */
        filt_name_len *= 2;
-       filt_name = g_realloc(filt_name, filt_name_len + 1);
+       filt_name = (char *)g_realloc(filt_name, filt_name_len + 1);
       }
       filt_name[filt_name_index] = c;
       filt_name_index++;
       }
       filt_name[filt_name_index] = c;
       filt_name_index++;
@@ -321,7 +324,7 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return,
       if (filt_expr_index >= filt_expr_len) {
        /* Filter expressioin buffer isn't long enough; double its length. */
        filt_expr_len *= 2;
       if (filt_expr_index >= filt_expr_len) {
        /* Filter expressioin buffer isn't long enough; double its length. */
        filt_expr_len *= 2;
-       filt_expr = g_realloc(filt_expr, filt_expr_len + 1);
+       filt_expr = (char *)g_realloc(filt_expr, filt_expr_len + 1);
       }
       filt_expr[filt_expr_index] = c;
       filt_expr_index++;
       }
       filt_expr[filt_expr_index] = c;
       filt_expr_index++;
@@ -345,7 +348,7 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return,
     if (filt_expr_index >= filt_expr_len) {
       /* Filter expressioin buffer isn't long enough; double its length. */
       filt_expr_len *= 2;
     if (filt_expr_index >= filt_expr_len) {
       /* Filter expressioin buffer isn't long enough; double its length. */
       filt_expr_len *= 2;
-      filt_expr = g_realloc(filt_expr, filt_expr_len + 1);
+      filt_expr = (char *)g_realloc(filt_expr, filt_expr_len + 1);
     }
     filt_expr[filt_expr_index] = '\0';
 
     }
     filt_expr[filt_expr_index] = '\0';
 
@@ -360,7 +363,7 @@ read_filter_list(filter_list_type_t list_type, char **pref_path_return,
   fclose(ff);
   g_free(filt_name);
   g_free(filt_expr);
   fclose(ff);
   g_free(filt_name);
   g_free(filt_expr);
-  
+
   /* init the corresponding edited list */
   switch (list_type) {
   case CFILTER_LIST:
   /* init the corresponding edited list */
   switch (list_type) {
   case CFILTER_LIST:
@@ -487,14 +490,14 @@ save_filter_list(filter_list_type_t list_type, char **pref_path_return,
     return;
   }
 
     return;
   }
 
-  ff_path = get_persconffile_path(ff_name, TRUE);
+  ff_path = get_persconffile_path(ff_name, TRUE, TRUE);
 
   /* Write to "XXX.new", and rename if that succeeds.
      That means we don't trash the file if we fail to write it out
      completely. */
   ff_path_new = g_strdup_printf("%s.new", ff_path);
 
 
   /* Write to "XXX.new", and rename if that succeeds.
      That means we don't trash the file if we fail to write it out
      completely. */
   ff_path_new = g_strdup_printf("%s.new", ff_path);
 
-  if ((ff = eth_fopen(ff_path_new, "w")) == NULL) {
+  if ((ff = ws_fopen(ff_path_new, "w")) == NULL) {
     *pref_path_return = ff_path;
     *errno_return = errno;
     g_free(ff_path_new);
     *pref_path_return = ff_path;
     *errno_return = errno;
     g_free(ff_path_new);
@@ -523,7 +526,7 @@ save_filter_list(filter_list_type_t list_type, char **pref_path_return,
       *pref_path_return = ff_path;
       *errno_return = errno;
       fclose(ff);
       *pref_path_return = ff_path;
       *errno_return = errno;
       fclose(ff);
-      eth_unlink(ff_path_new);
+      ws_unlink(ff_path_new);
       g_free(ff_path_new);
       return;
     }
       g_free(ff_path_new);
       return;
     }
@@ -532,7 +535,7 @@ save_filter_list(filter_list_type_t list_type, char **pref_path_return,
   if (fclose(ff) == EOF) {
     *pref_path_return = ff_path;
     *errno_return = errno;
   if (fclose(ff) == EOF) {
     *pref_path_return = ff_path;
     *errno_return = errno;
-    eth_unlink(ff_path_new);
+    ws_unlink(ff_path_new);
     g_free(ff_path_new);
     return;
   }
     g_free(ff_path_new);
     return;
   }
@@ -542,22 +545,22 @@ save_filter_list(filter_list_type_t list_type, char **pref_path_return,
      exists; the Win32 call to rename files doesn't do so, which I
      infer is the reason why the MSVC++ "rename()" doesn't do so.
      We must therefore remove the target file first, on Windows. */
      exists; the Win32 call to rename files doesn't do so, which I
      infer is the reason why the MSVC++ "rename()" doesn't do so.
      We must therefore remove the target file first, on Windows. */
-  if (eth_remove(ff_path) < 0 && errno != ENOENT) {
+  if (ws_remove(ff_path) < 0 && errno != ENOENT) {
     /* It failed for some reason other than "it's not there"; if
        it's not there, we don't need to remove it, so we just
        drive on. */
     *pref_path_return = ff_path;
     *errno_return = errno;
     /* It failed for some reason other than "it's not there"; if
        it's not there, we don't need to remove it, so we just
        drive on. */
     *pref_path_return = ff_path;
     *errno_return = errno;
-    eth_unlink(ff_path_new);
+    ws_unlink(ff_path_new);
     g_free(ff_path_new);
     return;
   }
 #endif
 
     g_free(ff_path_new);
     return;
   }
 #endif
 
-  if (eth_rename(ff_path_new, ff_path) < 0) {
+  if (ws_rename(ff_path_new, ff_path) < 0) {
     *pref_path_return = ff_path;
     *errno_return = errno;
     *pref_path_return = ff_path;
     *errno_return = errno;
-    eth_unlink(ff_path_new);
+    ws_unlink(ff_path_new);
     g_free(ff_path_new);
     return;
   }
     g_free(ff_path_new);
     return;
   }
@@ -579,20 +582,17 @@ void copy_filter_list(filter_list_type_t dest_type, filter_list_type_t src_type)
 
     flpp_dest = get_filter_list(dest_type);
     flpp_src = get_filter_list(src_type);
 
     flpp_dest = get_filter_list(dest_type);
     flpp_src = get_filter_list(src_type);
-    flp_src = *flpp_src;
-
     /* throw away the "old" destination list - a NULL list is ok here */
     while(*flpp_dest) {
     /* throw away the "old" destination list - a NULL list is ok here */
     while(*flpp_dest) {
-        *flpp_dest = remove_filter_entry(*flpp_dest, g_list_first(*flpp_dest));        
+        *flpp_dest = remove_filter_entry(*flpp_dest, g_list_first(*flpp_dest));
     }
     g_assert(g_list_length(*flpp_dest) == 0);
 
     /* copy the list entries */
     }
     g_assert(g_list_length(*flpp_dest) == 0);
 
     /* copy the list entries */
-    while(flp_src) {
-        filt = (flp_src)->data;
+    for(flp_src = g_list_first(*flpp_src); flp_src; flp_src = g_list_next(flp_src)) {
+        filt = (filter_def *)(flp_src->data);
 
         *flpp_dest = add_filter_entry(*flpp_dest, filt->name, filt->strval);
 
         *flpp_dest = add_filter_entry(*flpp_dest, filt->name, filt->strval);
-        flp_src = g_list_next(flp_src);
     }
 }
 
     }
 }