Anonymous avatar Anonymous committed 07d0054

Various fixed and added minifind, which is our first test program.

Note, however, that minifind does not work.

Comments (0)

Files changed (4)

libfilefind/c_glib_based/CMakeLists.txt

     PROPERTIES VERSION 0.1.0 SOVERSION 0
     )
 
-TARGET_LINK_LIBRARIES ("${LIBNAME}" pthread)
+PKG_CHECK_MODULES (GLIB2 REQUIRED glib-2.0)
+
+ADD_EXECUTABLE("minifind" "minifind.c")
+TARGET_LINK_LIBRARIES("minifind" "${LIBNAME}")
+SET_TARGET_PROPERTIES("minifind" PROPERTIES LINK_FLAGS ${GLIB2_LDFLAGS})
 
 INSTALL(
     FILES

libfilefind/c_glib_based/filefind.c

 
 typedef struct file_finder_struct file_finder_t;
 
+static void item_result_free(item_result_t * item);
+
+static GCC_INLINE void free_item_obj(file_finder_t * self)
+{
+    if (self->item_obj)
+    {
+        item_result_free(self->item_obj);
+        self->item_obj = NULL;
+    }
+
+    return;
+}
+
 static GPtrArray * string_array_copy(GPtrArray * arr)
 {
     GPtrArray * ret;
 
         if (self->curr_comps)
         {
-            g_ptr_array_free(self->dir_stack, 1);
+            g_ptr_array_free(self->curr_comps, 1);
             self->curr_comps = NULL;
         }
 
             g_ptr_array_free(self->targets, 1);
             self->targets = NULL;
         }
-        
-        g_free(self);   
+
+        g_free(self);
     }
 
     return FILE_FIND_OUT_OF_MEMORY;
     GPtrArray * dir_components;
     gchar * comp_copy;
 
-    *item = NULL;
     dir_components = NULL;
 
     ret = g_new0(item_result_t, 1);
 
     if (curr_not_a_dir)
     {
-        if (!(ret->basename = 
+        if (!(ret->basename =
             g_strdup(
                 g_ptr_array_index(self->curr_comps, comp_idx)
             ))
     }
     else
     {
-        self->item_obj = NULL;
+        free_item_obj(self);
 
         return FILEFIND_STATUS_OK;
     }
 
 static status_t file_finder_set_obj(file_finder_t * self)
 {
-    self->item_obj = NULL;
+    free_item_obj(self);
     return file_finder_calc_current_item_obj(self, &(self->item_obj));
 }
 
             );
 }
 
+extern int file_find_free(
+    file_find_handle_t * handle
+)
+{
+    file_finder_t * self;
+    gint i;
+    
+    self = (file_finder_t *)handle;
+  
+    for (i = 0 ; i < self->dir_stack->len ; i++)
+    {
+        path_component_free(g_ptr_array_index(self->dir_stack, i));
+    }
+    g_ptr_array_free(self->dir_stack, 1);
+    self->dir_stack = NULL;
+
+    if (self->curr_comps)
+    {
+        g_ptr_array_free(self->curr_comps, 1);
+        self->curr_comps = NULL;
+    }
+
+    if (self->targets)
+    {
+        g_ptr_array_free(self->targets, 1);
+        self->targets = NULL;
+    }
+
+    if (self->curr_path)
+    {
+        g_free(self->curr_path);
+        self->curr_path = NULL;
+    }
+
+    free_item_obj(self);
+
+    g_free (self);
+
+    return FILE_FIND_OK;
+}
+

libfilefind/c_glib_based/filefind.h

 
 extern int file_find_next(file_find_handle_t * handle);
 
-extern const gchar * file_find_get_path(file_find_handle_t * handle);
+extern const char * file_find_get_path(file_find_handle_t * handle);
 
 extern int file_find_set_traverse_to(
     file_find_handle_t * handle,
     char * * * ptr_to_file_names
 );
 
-
 extern int file_find_get_traverse_to(
     file_find_handle_t * handle,
     int * ptr_to_num_files,
     char * * * ptr_to_file_names
 );
 
+extern int file_find_free(
+    file_find_handle_t * handle
+);
+
 #endif /* #ifndef FILEFIND_H */

libfilefind/c_glib_based/minifind.c

+#include <stdio.h>
+
+#include "filefind.h"
+
+int main(int argc, char * argv[])
+{
+    file_find_handle_t * tree;
+
+    if (argc < 2)
+    {
+        fprintf(stderr, "%s\n", "Usage: minifind [path]");
+        return -1;
+    }
+
+    if (file_find_new(&tree, argv[1]) != FILE_FIND_OK)
+    {
+        fprintf(stderr, "%s\n", "Could not allocate file finder.");
+        return -1;
+    }
+
+    while (file_find_next(tree) == FILE_FIND_OK)
+    {
+        printf("%s\n", file_find_get_path(tree));
+    }
+
+    if (file_find_free(tree) != FILE_FIND_OK)
+    {
+        fprintf(stderr, "%s\n", "Not succesful in freeing the finder.");
+        return -1;
+    }
+
+    return 0;
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.