From Stefan Metzmacher
[obnox/wireshark/wip.git] / fileset.c
index c0c192d65d590590765409a8cd5b3c0a4e9f67da..f3697e8390daaeef8ff01b1599955bc94e36e1c5 100644 (file)
--- a/fileset.c
+++ b/fileset.c
@@ -51,7 +51,7 @@
 
 #include <glib.h>
 
-#include <wiretap/file_util.h>
+#include <wsutil/file_util.h>
 #include "globals.h"
 
 #include <epan/filesystem.h>
@@ -74,18 +74,18 @@ gboolean
 fileset_filename_match_pattern(const char *fname)
 {
     char        *pfx;
-    int         baselen;
-    int         minlen = strlen("_00001_20050418010750");
+    size_t       baselen;
+    size_t      minlen = strlen("_00001_20050418010750");
     char        *filename;
-  
+
 
     /* d:\dir1\test_00001_20050418010750.cap */
     filename = g_strdup(get_basename(fname));
 
     /* test_00001_20050418010750.cap */
     pfx = strrchr(filename, '.');
-    if(pfx == NULL) {
-        return FALSE;
+    if(pfx == NULL) {  /* suffix is optional */
+        pfx = filename + strlen(filename);
     }
     /* test_00001_20050418010750 */
     *pfx = '\0';
@@ -111,7 +111,7 @@ fileset_filename_match_pattern(const char *fname)
     while(minlen--) {
         baselen--;
 
-        if(!isdigit( (int) filename[baselen])) {
+        if(!isdigit( (guchar) filename[baselen])) {
             g_free(filename);
             return FALSE;
         }
@@ -133,7 +133,7 @@ fileset_is_file_in_set(const char *fname1, const char *fname2)
     char        *pfx2;
     char        *dup_f1;
     char        *dup_f2;
-    int         minlen = strlen("_00001_20050418010750");
+    size_t       minlen = strlen("_00001_20050418010750");
 
 
     /* just to be sure ... */
@@ -145,6 +145,9 @@ fileset_is_file_in_set(const char *fname1, const char *fname2)
 
     pfx1 = strrchr(dup_f1, '.');
     pfx2 = strrchr(dup_f2, '.');
+    /* suffix is optional */
+    if (!pfx1) pfx1 = dup_f1 + strlen(dup_f1);
+    if (!pfx2) pfx2 = dup_f2 + strlen(dup_f2);
 
     /* the optional suffix (file extension) must be equal */
     if(strcmp(pfx1, pfx2) != 0) {
@@ -180,7 +183,7 @@ fileset_add_file(const char *dirname, const char *fname, gboolean current)
 
     path = g_strdup_printf("%s%s", dirname, fname);
 
-    fh = eth_open( path, O_RDONLY, 0000 /* no creation so don't matter */);
+    fh = ws_open( path, O_RDONLY, 0000 /* no creation so don't matter */);
     if(fh !=  -1) {
 
         /* Get statistics */
@@ -200,7 +203,7 @@ fileset_add_file(const char *dirname, const char *fname, gboolean current)
             set.entries = g_list_append(set.entries, entry);
         }
 
-        eth_close(fh);
+        ws_close(fh);
     }
 
     g_free(path);
@@ -239,8 +242,8 @@ void fileset_update_dlg(void)
 void
 fileset_add_dir(const char *fname)
 {
-    ETH_DIR       *dir;             /* scanned directory */
-    ETH_DIRENT    *file;            /* current file */
+    WS_DIR        *dir;             /* scanned directory */
+    WS_DIRENT     *file;            /* current file */
     const char    *name;
     fileset_entry *entry;
     GString       *dirname;
@@ -252,22 +255,22 @@ fileset_add_dir(const char *fname)
     dirname = g_string_new(fname_dup);
     g_free(fname_dup);
 
-    set.dirname = g_strdup(dirname->str);    
-    
+    set.dirname = g_strdup(dirname->str);
+
     dirname = g_string_append_c(dirname, G_DIR_SEPARATOR);
 
     /* is the current file probably a part of any fileset? */
     if(fileset_filename_match_pattern(fname)) {
         /* yes, go through the files in the directory and check if the file in question is part of the current file set */
-        if ((dir = eth_dir_open(dirname->str, 0, NULL)) != NULL) {
-               while ((file = eth_dir_read_name(dir)) != NULL) {
-                   name = eth_dir_get_name(file);
+        if ((dir = ws_dir_open(dirname->str, 0, NULL)) != NULL) {
+               while ((file = ws_dir_read_name(dir)) != NULL) {
+                   name = ws_dir_get_name(file);
                 if(fileset_filename_match_pattern(name) && fileset_is_file_in_set(name, get_basename(fname))) {
                     fileset_add_file(dirname->str, name, strcmp(name, get_basename(fname))== 0 /* current */);
                 }
             } /* while */
 
-            eth_dir_close(dir);
+            ws_dir_close(dir);
         } /* if */
     } else {
         /* no, this is a "standalone file", just add this one */