You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/07/09 16:10:12 UTC

[lucy-commits] svn commit: r1144671 - in /incubator/lucy/trunk/clownfish/src: CFCHierarchy.c CFCUtil.c CFCUtil.h

Author: marvin
Date: Sat Jul  9 14:10:12 2011
New Revision: 1144671

URL: http://svn.apache.org/viewvc?rev=1144671&view=rev
Log:
Move dir-handling code into CFCUtil.

Modified:
    incubator/lucy/trunk/clownfish/src/CFCHierarchy.c
    incubator/lucy/trunk/clownfish/src/CFCUtil.c
    incubator/lucy/trunk/clownfish/src/CFCUtil.h

Modified: incubator/lucy/trunk/clownfish/src/CFCHierarchy.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCHierarchy.c?rev=1144671&r1=1144670&r2=1144671&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCHierarchy.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCHierarchy.c Sat Jul  9 14:10:12 2011
@@ -66,18 +66,6 @@ S_fetch_file(CFCHierarchy *self, const c
 static int
 S_do_propagate_modified(CFCHierarchy *self, CFCClass *klass, int modified);
 
-// Platform-agnostic opendir wrapper.
-static void*
-S_opendir(const char *dir);
-
-// Platform-agnostic readdir wrapper.
-static const char*
-S_next_entry(void *dirhandle);
-
-// Platform-agnostic closedir wrapper.
-static void
-S_closedir(void *dirhandle, const char *dir);
-
 // Indicate whether a path is a directory.
 // Note: this has to be defined before including the Perl headers because they
 // redefine stat() in an incompatible way on certain systems (Windows).
@@ -183,11 +171,11 @@ S_parse_file(void *parser, const char *c
 
 static char**
 S_find_cfh(char *dir, char **cfh_list, size_t num_cfh) {
-    void *dirhandle = S_opendir(dir);
+    void *dirhandle = CFCUtil_opendir(dir);
     size_t full_path_cap = strlen(dir) * 2;
     char *full_path = (char*)MALLOCATE(full_path_cap);
     const char *entry = NULL;
-    while (NULL != (entry = S_next_entry(dirhandle))) {
+    while (NULL != (entry = CFCUtil_dirnext(dirhandle))) {
         // Ignore updirs and hidden files.
         if (strncmp(entry, ".", 1) == 0) {
             continue;
@@ -218,7 +206,7 @@ S_find_cfh(char *dir, char **cfh_list, s
     }
 
     FREEMEM(full_path);
-    S_closedir(dirhandle, dir);
+    CFCUtil_closedir(dirhandle, dir);
     return cfh_list;
 }
 
@@ -482,93 +470,4 @@ CFCHierarchy_get_dest(CFCHierarchy *self
     return self->dest;
 }
 
-/******************************** WINDOWS **********************************/
-#ifdef WIN32
-
-#include <windows.h>
-
-typedef struct WinDH {
-    HANDLE handle;
-    WIN32_FIND_DATA *find_data;
-    char path[MAX_PATH + 1];
-    int first_time;
-} WinDH;
-
-static void*
-S_opendir(const char *dir) {
-    size_t dirlen = strlen(dir);
-    if (dirlen >= MAX_PATH - 2) {
-        CFCUtil_die("Exceeded MAX_PATH(%d): %s", (int)MAX_PATH, dir);
-    }
-    WinDH *dh = (WinDH*)CALLOCATE(1, sizeof(WinDH));
-    dh->find_data = (WIN32_FIND_DATA*)MALLOCATE(sizeof(WIN32_FIND_DATA));
-
-    // Tack on wildcard needed by FindFirstFile.
-    sprintf(dh->path, "%s\\*", dir);
-
-    dh->handle = FindFirstFile(dh->path, dh->find_data);
-    if (dh->handle == INVALID_HANDLE_VALUE) {
-        CFCUtil_die("Can't open dir '%s'", dh->path);
-    }
-    dh->first_time = true;
-
-    return dh;
-}
-
-static const char*
-S_next_entry(void *dirhandle) {
-    WinDH *dh = (WinDH*)dirhandle;
-    if (dh->first_time) {
-        dh->first_time = false;
-    }
-    else {
-        if ((FindNextFile(dh->handle, dh->find_data) == 0)) {
-            if (GetLastError() != ERROR_NO_MORE_FILES) {
-                CFCUtil_die("Error occurred while reading '%s'",
-                            dh->path);
-            }
-            return NULL;
-        }
-    }
-    return dh->find_data->cFileName;
-}
-
-static void
-S_closedir(void *dirhandle, const char *dir) {
-    WinDH *dh = (WinDH*)dirhandle;
-    if (!FindClose(dh->handle)) {
-        CFCUtil_die("Error occurred while closing dir '%s'", dir);
-    }
-    FREEMEM(dh->find_data);
-    FREEMEM(dh);
-}
-
-/******************************** UNIXEN ***********************************/
-#else
-
-#include <dirent.h>
-
-static void*
-S_opendir(const char *dir) {
-    DIR *dirhandle = opendir(dir);
-    if (!dirhandle) {
-        CFCUtil_die("Failed to opendir for '%s': %s", dir, strerror(errno));
-    }
-    return dirhandle;
-}
-
-static const char*
-S_next_entry(void *dirhandle) {
-    struct dirent *entry = readdir((DIR*)dirhandle);
-    return entry ? entry->d_name : NULL;
-}
-
-static void
-S_closedir(void *dirhandle, const char *dir) {
-    if (closedir(dirhandle) == -1) {
-        CFCUtil_die("Error closing dir '%s': %s", dir, strerror(errno));
-    }
-}
-
-#endif
 

Modified: incubator/lucy/trunk/clownfish/src/CFCUtil.c
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCUtil.c?rev=1144671&r1=1144670&r2=1144671&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCUtil.c (original)
+++ incubator/lucy/trunk/clownfish/src/CFCUtil.c Sat Jul  9 14:10:12 2011
@@ -282,6 +282,98 @@ CFCUtil_warn(const char* format, ...) {
     fprintf(stderr, "\n");
 }
 
+/******************************** WINDOWS **********************************/
+#ifdef WIN32
+
+#include <windows.h>
+
+typedef struct WinDH {
+    HANDLE handle;
+    WIN32_FIND_DATA *find_data;
+    char path[MAX_PATH + 1];
+    int first_time;
+} WinDH;
+
+void*
+CFCUtil_opendir(const char *dir) {
+    size_t dirlen = strlen(dir);
+    if (dirlen >= MAX_PATH - 2) {
+        CFCUtil_die("Exceeded MAX_PATH(%d): %s", (int)MAX_PATH, dir);
+    }
+    WinDH *dh = (WinDH*)CALLOCATE(1, sizeof(WinDH));
+    dh->find_data = (WIN32_FIND_DATA*)MALLOCATE(sizeof(WIN32_FIND_DATA));
+
+    // Tack on wildcard needed by FindFirstFile.
+    sprintf(dh->path, "%s\\*", dir);
+
+    dh->handle = FindFirstFile(dh->path, dh->find_data);
+    if (dh->handle == INVALID_HANDLE_VALUE) {
+        CFCUtil_die("Can't open dir '%s'", dh->path);
+    }
+    dh->first_time = true;
+
+    return dh;
+}
+
+const char*
+CFCUtil_dirnext(void *dirhandle) {
+    WinDH *dh = (WinDH*)dirhandle;
+    if (dh->first_time) {
+        dh->first_time = false;
+    }
+    else {
+        if ((FindNextFile(dh->handle, dh->find_data) == 0)) {
+            if (GetLastError() != ERROR_NO_MORE_FILES) {
+                CFCUtil_die("Error occurred while reading '%s'",
+                            dh->path);
+            }
+            return NULL;
+        }
+    }
+    return dh->find_data->cFileName;
+}
+
+void
+CFCUtil_closedir(void *dirhandle, const char *dir) {
+    WinDH *dh = (WinDH*)dirhandle;
+    if (!FindClose(dh->handle)) {
+        CFCUtil_die("Error occurred while closing dir '%s'", dir);
+    }
+    FREEMEM(dh->find_data);
+    FREEMEM(dh);
+}
+
+/******************************** UNIXEN ***********************************/
+#else
+
+#include <dirent.h>
+
+void*
+CFCUtil_opendir(const char *dir) {
+    DIR *dirhandle = opendir(dir);
+    if (!dirhandle) {
+        CFCUtil_die("Failed to opendir for '%s': %s", dir, strerror(errno));
+    }
+    return dirhandle;
+}
+
+const char*
+CFCUtil_dirnext(void *dirhandle) {
+    struct dirent *entry = readdir((DIR*)dirhandle);
+    return entry ? entry->d_name : NULL;
+}
+
+void
+CFCUtil_closedir(void *dirhandle, const char *dir) {
+    if (closedir(dirhandle) == -1) {
+        CFCUtil_die("Error closing dir '%s': %s", dir, strerror(errno));
+    }
+}
+
+#endif /* Windows vs. Unix. */
+
+/***************************************************************************/
+
 #include "EXTERN.h"
 #include "perl.h"
 #include "XSUB.h"

Modified: incubator/lucy/trunk/clownfish/src/CFCUtil.h
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/clownfish/src/CFCUtil.h?rev=1144671&r1=1144670&r2=1144671&view=diff
==============================================================================
--- incubator/lucy/trunk/clownfish/src/CFCUtil.h (original)
+++ incubator/lucy/trunk/clownfish/src/CFCUtil.h Sat Jul  9 14:10:12 2011
@@ -111,6 +111,21 @@ CFCUtil_slurp_text(const char *file_path
 long
 CFCUtil_flength(void *file);
 
+/* Platform-agnostic opendir wrapper.
+ */
+void*
+CFCUtil_opendir(const char *dir);
+
+/* Platform-agnostic readdir wrapper.
+ */
+const char*
+CFCUtil_dirnext(void *dirhandle);
+
+/* Platform-agnostic closedir wrapper.
+ */
+void
+CFCUtil_closedir(void *dirhandle, const char *dir);
+
 /* Print an error message to stderr and exit.
  */
 void