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 2010/01/04 23:00:07 UTC

svn commit: r895798 - in /lucene/lucy/trunk/charmonizer/src/Charmonizer: ./ Core/

Author: marvin
Date: Mon Jan  4 22:00:06 2010
New Revision: 895798

URL: http://svn.apache.org/viewvc?rev=895798&view=rev
Log:
Refactor Charmonizer/Core/Compiler and Charmonizer/Core/OperatingSystem
towards a procedural rather than OO interface.  Roll
Charmonizer/Core/CompilerSpec into Compiler.  (LUCY-94)

Removed:
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/CompilerSpec.c
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/CompilerSpec.h
Modified:
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.c
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.h
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ConfWriter.c
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ConfWriter.h
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Dir.c
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/OperatingSystem.c
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/OperatingSystem.h
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Stat.c
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe.c

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.c?rev=895798&r1=895797&r2=895798&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.c (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.c Mon Jan  4 22:00:06 2010
@@ -4,142 +4,129 @@
 #include <stdlib.h>
 #include "Charmonizer/Core/Util.h"
 #include "Charmonizer/Core/Compiler.h"
-#include "Charmonizer/Core/CompilerSpec.h"
 #include "Charmonizer/Core/ConfWriter.h"
 #include "Charmonizer/Core/OperatingSystem.h"
 
-static void
-S_destroy(Compiler *self);
-
-static chaz_bool_t
-S_compile_exe(Compiler *self, const char *source_path, const char *exe_name, 
-              const char *code, size_t code_len);
-
-static chaz_bool_t
-S_compile_obj(Compiler *self, const char *source_path, const char *obj_name, 
-              const char *code, size_t code_len);
-
-static void
-S_add_inc_dir(Compiler *self, const char *dir);
+static char     *cc_command   = NULL;
+static char     *cc_flags     = NULL;
+static char    **inc_dirs     = NULL;
+
+/* Detect a supported compiler, or assume a generic GCC-compatible compiler
+ * and hope for the best.  */
+#ifdef __GNUC__
+static char *compiler_nickname = "gcc";
+static char *include_flag      = "-I ";
+static char *object_flag       = "-o ";
+static char *exe_flag          = "-o ";
+#elif defined(_MSC_VER)
+static char *compiler_nickname = "MSVC";
+static char *include_flag      = "/I";
+static char *object_flag       = "/Fo";
+static char *exe_flag          = "/Fe";
+#else
+static char *compiler_nickname = "cc";
+static char *include_flag      = "-I ";
+static char *object_flag       = "-o ";
+static char *exe_flag          = "-o ";
+#endif
 
 static void
-S_do_test_compile(Compiler *self);
+S_do_test_compile();
 
-Compiler*
-CC_new(OperSys *oper_sys, const char *cc_command, const char *cc_flags)
+void
+CC_init(const char *compiler_command, const char *compiler_flags)
 {
-    CompilerSpec *compiler_spec = CCSpec_find_spec();
-    Compiler *self = (Compiler*)malloc(sizeof(Compiler));
-
     if (Util_verbosity) { printf("Creating compiler object...\n"); }
 
     /* Assign. */
-    self->os              = oper_sys;
-    self->cc_command      = strdup(cc_command);
-    self->cc_flags        = strdup(cc_flags);
+    cc_command      = strdup(compiler_command);
+    cc_flags        = strdup(compiler_flags);
 
     /* Init. */
-    self->compile_exe     = S_compile_exe;
-    self->compile_obj     = S_compile_obj;
-    self->add_inc_dir     = S_add_inc_dir;
-    self->destroy         = S_destroy;
-    self->inc_dirs        = (char**)calloc(sizeof(char*), 1);
-
-    /* Set compiler-specific vars. */
-    self->include_flag    = strdup(compiler_spec->include_flag);
-    self->object_flag     = strdup(compiler_spec->object_flag);
-    self->exe_flag        = strdup(compiler_spec->exe_flag);
+    inc_dirs              = (char**)calloc(sizeof(char*), 1);
 
     /* Add the current directory as an include dir. */
-    self->add_inc_dir(self, ".");
+    CC_add_inc_dir(".");
 
     /* If we can't compile anything, game over. */
-    S_do_test_compile(self);
-
-    return self;
+    S_do_test_compile();
 }
 
-static void
-S_destroy(Compiler *self)
+void
+CC_clean_up()
 {
-    char **inc_dirs;
+    char **dirs;
 
-    for (inc_dirs = self->inc_dirs; *inc_dirs != NULL; inc_dirs++) {
-        free(*inc_dirs);
+    for (dirs = inc_dirs; *dirs != NULL; dirs++) {
+        free(*dirs);
     }
-    free(self->inc_dirs);
+    free(inc_dirs);
 
-    free(self->cc_command);
-    free(self->cc_flags);
-    free(self->include_flag);
-    free(self->object_flag);
-    free(self->exe_flag);
-    free(self);
+    free(cc_command);
+    free(cc_flags);
 }
 
 static char*
-S_inc_dir_string(Compiler *self)
+S_inc_dir_string()
 {
     size_t needed = 0;
     char  *inc_dir_string;
-    char **inc_dirs;
-    for (inc_dirs = self->inc_dirs; *inc_dirs != NULL; inc_dirs++) {
-        needed += strlen(self->include_flag) + 2;
-        needed += strlen(*inc_dirs);
+    char **dirs;
+    for (dirs = inc_dirs; *dirs != NULL; dirs++) {
+        needed += strlen(include_flag) + 2;
+        needed += strlen(*dirs);
     }
     inc_dir_string = (char*)malloc(needed + 1);
     inc_dir_string[0] = '\0';
-    for (inc_dirs = self->inc_dirs; *inc_dirs != NULL; inc_dirs++) {
-        strcat(inc_dir_string, self->include_flag);
-        strcat(inc_dir_string, *inc_dirs);
+    for (dirs = inc_dirs; *dirs != NULL; dirs++) {
+        strcat(inc_dir_string, include_flag);
+        strcat(inc_dir_string, *dirs);
         strcat(inc_dir_string, " ");
     }
     return inc_dir_string;
 }
 
-static chaz_bool_t
-S_compile_exe(Compiler *self, const char *source_path, const char *exe_name, 
-              const char *code, size_t code_len)
+chaz_bool_t
+CC_compile_exe(const char *source_path, const char *exe_name, 
+               const char *code, size_t code_len)
 {
-    OperSys *os                = self->os;
-    size_t   exe_file_buf_size = strlen(exe_name) + strlen(os->exe_ext) + 1;
+    const char *exe_ext        = OS_exe_ext();
+    size_t   exe_file_buf_size = strlen(exe_name) + strlen(exe_ext) + 1;
     char    *exe_file          = (char*)malloc(exe_file_buf_size);
-    size_t   exe_file_buf_len  = sprintf(exe_file, "%s%s", exe_name, os->exe_ext);
-    char    *inc_dir_string    = S_inc_dir_string(self);
-    size_t   command_max_size  = strlen(os->local_command_start)
-                               + strlen(self->cc_command)
+    size_t   exe_file_buf_len  = sprintf(exe_file, "%s%s", exe_name, exe_ext);
+    char    *inc_dir_string    = S_inc_dir_string();
+    size_t   command_max_size  = strlen(cc_command)
                                + strlen(source_path)
-                               + strlen(self->exe_flag)
+                               + strlen(exe_flag)
                                + exe_file_buf_len
                                + strlen(inc_dir_string)
-                               + strlen(self->cc_flags)
-                               + 200;
+                               + strlen(cc_flags)
+                               + 200; /* command start, _charm_run, etc.  */
     char *command = (char*)malloc(command_max_size);
     chaz_bool_t result;
     (void)code_len; /* Unused. */
-    
-    /* Prepare the compiler command. */
+       
+    /* Write the source file. */
+    Util_write_file(source_path, code);
+
+    /* Prepare and run the compiler command. */
     if (Util_verbosity < 2 && chaz_ConfWriter_charm_run_available) {
-        sprintf(command, "%s%s %s %s %s%s %s %s",
-            os->local_command_start, "_charm_run ", 
-            self->cc_command, source_path, 
-            self->exe_flag, exe_file, 
-            inc_dir_string,
-            self->cc_flags);
+        sprintf(command, "%s %s %s %s%s %s %s",
+            "_charm_run ", 
+            cc_command, source_path, 
+            exe_flag, exe_file, 
+            inc_dir_string, cc_flags);
+        OS_run_local(command, NULL);
     }
     else {
         sprintf(command, "%s %s %s%s %s %s", 
-            self->cc_command, source_path,
-            self->exe_flag, exe_file,
-            inc_dir_string,
-            self->cc_flags);
+            cc_command, source_path,
+            exe_flag, exe_file,
+            inc_dir_string, cc_flags);
+        system(command);
     }
 
-    /* Write the source file. */
-    Util_write_file(source_path, code);
-
-    /* Run the compiler command.  See if compilation was successful. */
-    system(command);
+    /* See if compilation was successful. */
     result = Util_can_open_file(exe_file);
 
     free(command);
@@ -148,49 +135,49 @@
     return result;
 }
 
-static chaz_bool_t
-S_compile_obj(Compiler *self, const char *source_path, const char *obj_name, 
-              const char *code, size_t code_len)
+chaz_bool_t
+CC_compile_obj(const char *source_path, const char *obj_name, 
+               const char *code, size_t code_len)
 {
-    OperSys *os                = self->os;
-    size_t   obj_file_buf_size = strlen(obj_name) + strlen(os->obj_ext) + 1;
+    const char *obj_ext        = OS_obj_ext();
+    size_t   obj_file_buf_size = strlen(obj_name) + strlen(obj_ext) + 1;
     char    *obj_file          = (char*)malloc(obj_file_buf_size);
-    size_t   obj_file_buf_len  = sprintf(obj_file, "%s%s", obj_name, os->obj_ext);
-    char    *inc_dir_string    = S_inc_dir_string(self);
-    size_t   command_max_size  = strlen(os->local_command_start)
-                               + strlen(self->cc_command)
+    size_t   obj_file_buf_len  = sprintf(obj_file, "%s%s", obj_name, obj_ext);
+    char    *inc_dir_string    = S_inc_dir_string();
+    size_t   command_max_size  = strlen(cc_command)
                                + strlen(source_path)
-                               + strlen(self->object_flag)
+                               + strlen(object_flag)
                                + obj_file_buf_len
                                + strlen(inc_dir_string)
-                               + strlen(self->cc_flags)
-                               + 200;
+                               + strlen(cc_flags)
+                               + 200; /* command start, _charm_run, etc.  */
     char *command = (char*)malloc(command_max_size);
     chaz_bool_t result;
     (void)code_len; /* Unused. */
     
-    /* Prepare the compiler command. */
+    /* Write the source file. */
+    Util_write_file(source_path, code);
+
+    /* Prepare and run the compiler command. */
     if (Util_verbosity < 2 && chaz_ConfWriter_charm_run_available) {
-        sprintf(command, "%s%s %s %s %s%s %s %s",
-            os->local_command_start, "_charm_run ", 
-            self->cc_command, source_path, 
-            self->object_flag, obj_file, 
+        sprintf(command, "%s %s %s %s%s %s %s",
+            "_charm_run ", 
+            cc_command, source_path, 
+            object_flag, obj_file, 
             inc_dir_string,
-            self->cc_flags);
+            cc_flags);
+        OS_run_local(command, NULL);
     }
     else {
         sprintf(command, "%s %s %s%s %s %s", 
-            self->cc_command, source_path,
-            self->object_flag, obj_file,
+            cc_command, source_path,
+            object_flag, obj_file,
             inc_dir_string,
-            self->cc_flags);
+            cc_flags);
+        system(command);
     }
 
-    /* Write the source file. */
-    Util_write_file(source_path, code);
-
-    /* Run the compiler command.  See if compilation was successful. */
-    system(command);
+    /* See if compilation was successful. */
     result = Util_can_open_file(obj_file);
 
     free(command);
@@ -200,7 +187,7 @@
 }
 
 static void
-S_do_test_compile(Compiler *self)
+S_do_test_compile()
 {
     char *code = "int main() { return 0; }\n";
     chaz_bool_t success;
@@ -210,29 +197,29 @@
     }
 
     /* Attempt compilation. */
-    success = self->compile_exe(self, "_charm_try.c", 
-        "_charm_try", code, strlen(code));
+    success = CC_compile_exe("_charm_try.c", "_charm_try", 
+        code, strlen(code));
     if (!success) { Util_die("Failed to compile a small test file"); }
     
     /* Clean up. */
     remove("_charm_try.c");
-    self->os->remove_exe(self->os, "_charm_try");
+    OS_remove_exe("_charm_try");
 }
 
-static void
-S_add_inc_dir(Compiler *self, const char *dir)
+void
+CC_add_inc_dir(const char *dir)
 {
     size_t num_dirs = 0; 
-    char **dirs = self->inc_dirs;
+    char **dirs = inc_dirs;
 
     /* Count up the present number of dirs, reallocate. */
     while (*dirs++ != NULL) { num_dirs++; }
     num_dirs += 1; /* Passed-in dir. */
-    self->inc_dirs = (char**)realloc(self->inc_dirs, (num_dirs + 1)*sizeof(char*));
+    inc_dirs = (char**)realloc(inc_dirs, (num_dirs + 1)*sizeof(char*));
 
     /* Put the passed-in dir at the end of the list. */
-    self->inc_dirs[num_dirs - 1] = strdup(dir);
-    self->inc_dirs[num_dirs] = NULL;
+    inc_dirs[num_dirs - 1] = strdup(dir);
+    inc_dirs[num_dirs] = NULL;
 }
 
 /**

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.h
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.h?rev=895798&r1=895797&r2=895798&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.h (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Compiler.h Mon Jan  4 22:00:06 2010
@@ -11,63 +11,42 @@
 #include <stddef.h>
 #include "Charmonizer/Core/Defines.h"
 
-typedef struct chaz_Compiler chaz_Compiler;
-struct chaz_OperSys;
-
 /* Attempt to compile and link an executable.  Return true if the executable
  * file exists after the attempt.
  */
-typedef chaz_bool_t
-(*chaz_CC_compile_exe_t)(chaz_Compiler *self, const char *source_path, 
-                         const char *exe_path, const char *code, 
-                         size_t code_len);
+chaz_bool_t
+chaz_CC_compile_exe(const char *source_path, const char *exe_path, 
+                    const char *code, size_t code_len);
 
 /* Attempt to compile an object file.  Return true if the object file
  * exists after the attempt.
  */
-typedef chaz_bool_t
-(*chaz_CC_compile_obj_t)(chaz_Compiler *self, const char *source_path, 
-                         const char *obj_path, const char *code, 
-                         size_t code_len);
+chaz_bool_t
+chaz_CC_compile_obj(const char *source_path, const char *obj_path, 
+                    const char *code, size_t code_len);
 
 /* Add an include directory which will be used for all future compilation
  * attempts.
  */
-typedef void
-(*chaz_CC_add_inc_dir_t)(chaz_Compiler *self, const char *dir);
+void
+chaz_CC_add_inc_dir(const char *dir);
 
-/* Destructor.
+/** Initialize the compiler environment.
  */
-typedef void
-(*chaz_CC_destroy_t)(chaz_Compiler *self);
+void
+chaz_CC_init(const char *cc_command, const char *cc_flags);
 
-struct chaz_Compiler {
-    struct chaz_OperSys *os;
-    char          *cc_command;
-    char          *cc_flags;
-    char          *include_flag;
-    char          *object_flag;
-    char          *exe_flag;
-    char         **inc_dirs;
-    chaz_CC_compile_exe_t compile_exe;
-    chaz_CC_compile_obj_t compile_obj;
-    chaz_CC_add_inc_dir_t add_inc_dir;
-    chaz_CC_destroy_t     destroy;
-};
-
-/** Constructor.
- */
-chaz_Compiler*
-chaz_CC_new(struct chaz_OperSys *oper_sys, const char *cc_command, 
-            const char *cc_flags);
+/* Clean up the environment.
+ */
+void
+chaz_CC_clean_up();
 
 #ifdef CHAZ_USE_SHORT_NAMES
-  #define Compiler                    chaz_Compiler
-  #define CC_compile_exe_t            chaz_CC_compile_exe_t
-  #define CC_compile_obj_t            chaz_CC_compile_obj_t
-  #define CC_add_inc_dir_t            chaz_CC_add_inc_dir_t
-  #define CC_destroy_t                chaz_CC_destroy_t
-  #define CC_new                      chaz_CC_new
+  #define CC_compile_exe              chaz_CC_compile_exe
+  #define CC_compile_obj              chaz_CC_compile_obj
+  #define CC_add_inc_dir              chaz_CC_add_inc_dir
+  #define CC_clean_up                 chaz_CC_clean_up
+  #define CC_init                     chaz_CC_init
 #endif
 
 #ifdef __cplusplus

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ConfWriter.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ConfWriter.c?rev=895798&r1=895797&r2=895798&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ConfWriter.c (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ConfWriter.c Mon Jan  4 22:00:06 2010
@@ -16,7 +16,7 @@
 S_write_charm_h();
 
 /* Compile a small wrapper application which is used to redirect error output
- * to devnull.
+ * to dev_null.
  */
 static void
 S_build_charm_run();
@@ -27,27 +27,20 @@
 S_clean_up_try();
 
 /* Global vars. */
-struct OperSys  *ConfWriter_os = NULL;
-struct Compiler *ConfWriter_compiler = NULL;
 chaz_bool_t chaz_ConfWriter_charm_run_available = false;
 FILE* ConfWriter_charmony_fh = NULL;
 
 /* Static vars. */
-static char *try_app_path = NULL;
-static char *try_app_command = NULL;
+static char *try_app_name = NULL;
 
 void
 ConfWriter_init()
 {
     /* Set the name of the application which we "try" to execute. */
-    size_t len = strlen(TRY_APP_BASENAME) + strlen(ConfWriter_os->exe_ext) + 1;
-    try_app_path = (char*)malloc(len);
-    sprintf(try_app_path, "%s%s", TRY_APP_BASENAME, ConfWriter_os->exe_ext);
-
-    /* Set the invocation string for the "try" application. */
-    len = strlen(ConfWriter_os->local_command_start) + strlen(try_app_path) + 1;
-    try_app_command = (char*)malloc(len);
-    sprintf(try_app_command, "%s%s", ConfWriter_os->local_command_start, try_app_path);
+    const char *exe_ext = OS_exe_ext();
+    size_t len = strlen(TRY_APP_BASENAME) + strlen(exe_ext) + 1;
+    try_app_name = (char*)malloc(len);
+    sprintf(try_app_name, "%s%s", TRY_APP_BASENAME, exe_ext);
 
     /* Write files needed by this module and others. */
     S_build_charm_run();
@@ -81,8 +74,8 @@
 {
     /* Clean up some temp files. */
     remove("_charm.h");
-    ConfWriter_os->remove_exe(ConfWriter_os, "_charm_run");
-    ConfWriter_os->remove_exe(ConfWriter_os, "_charm_stat");
+    OS_remove_exe("_charm_run");
+    OS_remove_exe("_charm_stat");
 
     /* Write the last bit of charmony.h and close. */
     fprintf(ConfWriter_charmony_fh, "#endif /* H_CHARMONY */\n\n");
@@ -160,11 +153,12 @@
 S_build_charm_run()
 {
     chaz_bool_t compile_succeeded = false;
+    const char *dev_null = OS_dev_null();
     size_t needed = sizeof(charm_run_code_a)
                   + sizeof(charm_run_code_b)
-                  + strlen(ConfWriter_os->devnull)
+                  + strlen(dev_null)
                   + sizeof(charm_run_code_c)
-                  + strlen(ConfWriter_os->devnull)
+                  + strlen(dev_null)
                   + sizeof(charm_run_code_d)
                   + 20;
     char *code = (char*)malloc(needed);
@@ -172,12 +166,12 @@
     sprintf(code, "%s%s \"%s\" %s \"%s\" %s", 
         charm_run_code_a, 
         charm_run_code_b,
-        ConfWriter_os->devnull,
+        dev_null,
         charm_run_code_c,
-        ConfWriter_os->devnull,
+        dev_null,
         charm_run_code_d);
-    compile_succeeded = ConfWriter_compiler->compile_exe(ConfWriter_compiler, 
-        "_charm_run.c", "_charm_run", code, strlen(code));
+    compile_succeeded = CC_compile_exe("_charm_run.c", "_charm_run", 
+        code, strlen(code));
     if (!compile_succeeded) {
         Util_die("failed to compile _charm_run helper utility");
     }
@@ -192,12 +186,12 @@
 {
     chaz_bool_t compile_succeeded;
 
-    if ( !Util_remove_and_verify(try_app_path) ) {
-        Util_die("Failed to delete file '%s'", try_app_path);
+    if ( !Util_remove_and_verify(try_app_name) ) {
+        Util_die("Failed to delete file '%s'", try_app_name);
     }
 
-    compile_succeeded = ConfWriter_compiler->compile_exe(ConfWriter_compiler, 
-        TRY_SOURCE_PATH, TRY_APP_BASENAME, source, source_len);
+    compile_succeeded = CC_compile_exe(TRY_SOURCE_PATH, TRY_APP_BASENAME,
+        source, source_len);
 
     S_clean_up_try();
 
@@ -212,18 +206,18 @@
     chaz_bool_t compile_succeeded;
 
     /* Clear out previous versions and test to make sure removal worked. */
-    if ( !Util_remove_and_verify(try_app_path) ) {
-        Util_die("Failed to delete file '%s'", try_app_path);
+    if ( !Util_remove_and_verify(try_app_name) ) {
+        Util_die("Failed to delete file '%s'", try_app_name);
     }
     if ( !Util_remove_and_verify(TARGET_PATH) ) {
         Util_die("Failed to delete file '%s'", TARGET_PATH);
     }
 
     /* Attempt compilation; if successful, run app and slurp output. */
-    compile_succeeded = ConfWriter_compiler->compile_exe(ConfWriter_compiler, 
-        TRY_SOURCE_PATH, TRY_APP_BASENAME, source, source_len);
+    compile_succeeded = CC_compile_exe(TRY_SOURCE_PATH, TRY_APP_BASENAME, 
+        source, source_len);
     if (compile_succeeded) {
-        system(try_app_command);
+        OS_run_local(try_app_name, NULL);
         captured_output = Util_slurp_file(TARGET_PATH, output_len);
     }
     else {
@@ -250,7 +244,7 @@
 S_clean_up_try()
 {
     remove(TRY_SOURCE_PATH);
-    ConfWriter_os->remove_exe(ConfWriter_os, TRY_APP_BASENAME);
+    OS_remove_exe(TRY_APP_BASENAME);
     remove(TARGET_PATH);
 }
 

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ConfWriter.h
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ConfWriter.h?rev=895798&r1=895797&r2=895798&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ConfWriter.h (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ConfWriter.h Mon Jan  4 22:00:06 2010
@@ -12,9 +12,6 @@
 #include <stddef.h>
 #include "Charmonizer/Core/Defines.h"
 
-struct chaz_OperSys;
-struct chaz_Compiler;
-
 /* Temporary files used by Charmonizer. 
  */
 #define CHAZ_CONFWRITER_TRY_SOURCE_PATH  "_charmonizer_try.c"
@@ -23,13 +20,11 @@
 
 /* Global variables.
  */
-extern struct chaz_OperSys  *chaz_ConfWriter_os;
-extern struct chaz_Compiler *chaz_ConfWriter_compiler;
 extern chaz_bool_t chaz_ConfWriter_charm_run_available;
 extern FILE* chaz_ConfWriter_charmony_fh;
 
 /* Initialize elements needed by ConfWriter.  Must be called before anything 
- * else, but after os and compiler are created.
+ * else, but after os and compiler are initialized.
  */
 void
 chaz_ConfWriter_init();
@@ -108,8 +103,6 @@
   #define TRY_SOURCE_PATH                   CHAZ_CONFWRITER_TRY_SOURCE_PATH
   #define TRY_APP_BASENAME                  CHAZ_CONFWRITER_TRY_APP_BASENAME
   #define TARGET_PATH                       CHAZ_CONFWRITER_TARGET_PATH
-  #define ConfWriter_os                     chaz_ConfWriter_os
-  #define ConfWriter_compiler               chaz_ConfWriter_compiler
   #define ConfWriter_charm_run_available    chaz_ConfWriter_charm_run_available
   #define ConfWriter_charmony_fh            chaz_ConfWriter_charmony_fh
   #define ConfWriter_init                   chaz_ConfWriter_init

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Dir.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Dir.c?rev=895798&r1=895797&r2=895798&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Dir.c (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Dir.c Mon Jan  4 22:00:06 2010
@@ -56,8 +56,8 @@
 
     /* Attempt compilation. */
     sprintf(code_buf, posix_mkdir_code, header);
-    mkdir_available = ConfWriter_compiler->compile_exe(ConfWriter_compiler, "_charm_mkdir.c",
-        "_charm_mkdir", code_buf, strlen(code_buf));
+    mkdir_available = CC_compile_exe("_charm_mkdir.c", "_charm_mkdir", 
+        code_buf, strlen(code_buf));
 
     /* Set vars on success. */
     if (mkdir_available) {
@@ -77,8 +77,8 @@
 static chaz_bool_t
 S_try_init_win_mkdir()
 {
-    mkdir_available = ConfWriter_compiler->compile_exe(ConfWriter_compiler, "_charm_mkdir.c",
-        "_charm_mkdir", win_mkdir_code, strlen(win_mkdir_code));
+    mkdir_available = CC_compile_exe("_charm_mkdir.c", "_charm_mkdir", 
+        win_mkdir_code, strlen(win_mkdir_code));
     if (mkdir_available) {
         strcpy(mkdir_command, "_mkdir");
         Dir_mkdir_num_args = 1;
@@ -107,8 +107,8 @@
     size_t needed = sizeof(posix_mkdir_code) + 30;
     char *code_buf = (char*)malloc(needed);
     sprintf(code_buf, rmdir_code, header);
-    rmdir_available = ConfWriter_compiler->compile_exe(ConfWriter_compiler, "_charm_rmdir.c",
-        "_charm_rmdir", code_buf, strlen(code_buf));
+    rmdir_available = CC_compile_exe("_charm_rmdir.c", "_charm_rmdir", 
+        code_buf, strlen(code_buf));
     free(code_buf);
     return rmdir_available;
 }
@@ -139,14 +139,14 @@
 Dir_mkdir(const char *filepath)
 {
     if (!initialized) { Dir_init(); }
-    return ConfWriter_os->run_local(ConfWriter_os, "_charm_mkdir ", filepath, NULL);
+    return OS_run_local("_charm_mkdir ", filepath, NULL);
 }
 
 chaz_bool_t
 Dir_rmdir(const char *filepath)
 {
     if (!initialized) { Dir_init(); }
-    return ConfWriter_os->run_local(ConfWriter_os, "_charm_rmdir ", filepath, NULL);
+    return OS_run_local("_charm_rmdir ", filepath, NULL);
 }
 
 /**

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/OperatingSystem.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/OperatingSystem.c?rev=895798&r1=895797&r2=895798&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/OperatingSystem.c (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/OperatingSystem.c Mon Jan  4 22:00:06 2010
@@ -7,119 +7,117 @@
 #include "Charmonizer/Core/Util.h"
 #include "Charmonizer/Core/OperatingSystem.h"
 
-static void
-S_probe_devnull(OperSys *self);
-
-static void
-S_destroy(OperSys *self);
+static char dev_null[20] = "";
 
-static void
-S_remove_exe(OperSys *self, char *name);
+#ifdef _WIN32
+static char *exe_ext = ".exe";
+static char *obj_ext = ".obj";
+static char *local_command_start = ".\\";
+#else
+static char *exe_ext = "";
+static char *obj_ext = "";
+static char *local_command_start = "./";
+#endif
 
 static void
-S_remove_obj(OperSys *self, char *name);
-
-static int 
-S_run_local(OperSys *self, ...);
+S_probe_dev_null(void);
 
-OperSys*
-OS_new() 
+void
+OS_init() 
 {
-    OperSys *self = (OperSys*)malloc(sizeof(OperSys));
-
     if (Util_verbosity) {
-        printf("Creating os object...\n");
+        printf("Initializing Charmonizer/Core/OperatingSystem...\n");
     }
 
-    /* Init. */
-    self->buf        = NULL;
-    self->buf_len    = 0;
-    self->remove_obj = S_remove_obj;
-    self->remove_exe = S_remove_exe;
-    self->run_local  = S_run_local;
-    self->destroy    = S_destroy;
-#ifdef _WIN32
-    /* Assign. */
-    self->obj_ext = strdup(".obj");
-    self->exe_ext = strdup(".exe");
-    self->local_command_start = strdup(".\\");
-    self->devnull = strdup("nul");
-#else
-    self->obj_ext = strdup("");
-    self->exe_ext = strdup("");
-    self->local_command_start = strdup("./");
-    S_probe_devnull(self);
-#endif
-
-    return self;
+    S_probe_dev_null();
 }
 
 static void
-S_probe_devnull(OperSys *self)
+S_probe_dev_null(void)
 {
-    char *const devnull_options[] = {
-        "/dev/null", 
-        "/dev/nul", 
-        NULL
-    };
-    int i;
-
     if (Util_verbosity) {
         printf("Trying to find a bit-bucket a la /dev/null...\n");
     }
 
-    /* Iterate through names of possible devnulls trying to open them. */
-    for (i = 0; devnull_options[i] != NULL; i++) {
-        if (Util_can_open_file(devnull_options[i])) {
-            self->devnull = strdup(devnull_options[i]);
-            return;
+#ifdef _WIN32
+    strcpy(dev_null, "nul");
+#else
+    {
+        char *const options[] = {
+            "/dev/null", 
+            "/dev/nul", 
+            NULL
+        };
+        int i;
+
+        /* Iterate through names of possible devnulls trying to open them. */
+        for (i = 0; options[i] != NULL; i++) {
+            if (Util_can_open_file(options[i])) {
+                strcpy(dev_null, options[i]);
+                return;
+            }
         }
+
+        /* Bail out because we couldn't find anything like /dev/null. */
+        Util_die("Couldn't find anything like /dev/null");
     }
+#endif
+}
 
-    /* Bail out we couldn't find a devnull. */
-    Util_die("Couldn't find anything like /dev/null");
+void
+OS_clean_up(void)
+{
+    return;
 }
 
-static void
-S_destroy(OperSys *self)
+const char*
+OS_exe_ext(void)
 {
-    free(self->buf);
-    free(self->obj_ext);
-    free(self->exe_ext);
-    free(self->local_command_start);
-    free(self->devnull);
-    free(self);
+    return exe_ext;
 }
 
-static void
-S_remove_exe(OperSys *self, char *name)
+const char*
+OS_obj_ext(void)
 {
-    char *exe_name = (char*)malloc(strlen(name) + strlen(self->exe_ext) + 1);
-    sprintf(exe_name, "%s%s", name, self->exe_ext);
+    return obj_ext;
+}
+
+const char*
+OS_dev_null(void)
+{
+    return dev_null;
+}
+
+void
+OS_remove_exe(char *name)
+{
+    char *exe_name = (char*)malloc(strlen(name) + strlen(exe_ext) + 1);
+    sprintf(exe_name, "%s%s", name, exe_ext);
     remove(exe_name);
     free(exe_name);
 }
 
-static void
-S_remove_obj(OperSys *self, char *name)
+void
+OS_remove_obj(char *name)
 {
-    char *obj_name = (char*)malloc(strlen(name) + strlen(self->obj_ext) + 1);
-    sprintf(obj_name, "%s%s", name, self->obj_ext);
+    char *obj_name = (char*)malloc(strlen(name) + strlen(obj_ext) + 1);
+    sprintf(obj_name, "%s%s", name, obj_ext);
     remove(obj_name);
     free(obj_name);
 }
 
-static int
-S_run_local(OperSys *self, ...)
+int
+OS_run_local(char *arg1, ...)
 {
     va_list  args;
-    char    *command = strdup(self->local_command_start);
-    size_t   len     = strlen(command);
+    size_t   len     = strlen(local_command_start) + strlen(arg1);
+    char    *command = (char*)malloc(len + 1);
     int      retval;
     char    *arg;
 
     /* Append all supplied texts. */
-    va_start(args, self);
+    sprintf(command, "%s%s", local_command_start, arg1);
+    va_start(args, arg1);
     while (NULL != (arg = va_arg(args, char*))) {
         len += strlen(arg);
         command = (char*)realloc(command, len + 1);

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/OperatingSystem.h
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/OperatingSystem.h?rev=895798&r1=895797&r2=895798&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/OperatingSystem.h (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/OperatingSystem.h Mon Jan  4 22:00:06 2010
@@ -9,54 +9,56 @@
 extern "C" {
 #endif
 
-typedef struct chaz_OperSys chaz_OperSys;
-
 /* Remove an executable file named [name], appending the exe_ext if needed.
  */
-typedef void
-(*chaz_OS_remove_exe_t)(chaz_OperSys *self, char *name);
+void
+chaz_OS_remove_exe(char *name);
 
 /* Remove an object file named [name], appending the obj_ext if needed.
  */
-typedef void
-(*chaz_OS_remove_obj_t)(chaz_OperSys *self, char *name);
+void
+chaz_OS_remove_obj(char *name);
 
 /* Concatenate all arguments in a NULL-terminated list into a single command
  * string, prepend the appropriate prefix, and invoke via system().
  */
-typedef int 
-(*chaz_OS_run_local_t)(chaz_OperSys *self, ...);
+int 
+chaz_OS_run_local(char *arg1, ...);
+
+/* Return the extension for an executable on this system.
+ */
+const char*
+chaz_OS_exe_ext(void);
 
-/* Destructor.
+/* Return the extension for a compiled object on this system.
  */
-typedef void
-(*chaz_OS_destroy_t)(chaz_OperSys *self);
+const char*
+chaz_OS_obj_ext(void);
 
-struct chaz_OperSys {
-    char       *obj_ext;
-    char       *exe_ext;
-    char       *local_command_start;
-    char       *devnull;
-    char       *buf;
-    size_t      buf_len;
-    chaz_OS_remove_exe_t remove_exe;
-    chaz_OS_remove_obj_t remove_obj;
-    chaz_OS_run_local_t  run_local;
-    chaz_OS_destroy_t    destroy;
-};
+/* Return the equivalent of /dev/null on this system. 
+ */
+const char*
+chaz_OS_dev_null(void);
 
-/** Constructor. 
+/* Initialize the Charmonizer/Core/OperatingSystem module.
  */
-chaz_OperSys*
-chaz_OS_new();
+void
+chaz_OS_init(void);
+
+/* Tear down the Charmonizer/Core/OperatingSystem module. 
+ */
+void
+chaz_OS_clean_up(void);
 
 #ifdef CHAZ_USE_SHORT_NAMES
-  #define OperSys                      chaz_OperSys
-  #define OS_remove_exe_t              chaz_OS_remove_exe_t
-  #define OS_remove_obj_t              chaz_OS_remove_obj_t
-  #define OS_run_local_t               chaz_OS_run_local_t
-  #define OS_destroy_t                 chaz_OS_destroy_t
-  #define OS_new                       chaz_OS_new
+  #define OS_remove_exe                chaz_OS_remove_exe
+  #define OS_remove_obj                chaz_OS_remove_obj
+  #define OS_run_local                 chaz_OS_run_local
+  #define OS_exe_ext                   chaz_OS_exe_ext
+  #define OS_obj_ext                   chaz_OS_obj_ext
+  #define OS_dev_null                  chaz_OS_dev_null
+  #define OS_init                      chaz_OS_init
+  #define OS_clean_up                  chaz_OS_clean_up
 #endif
 
 #ifdef __cplusplus
@@ -65,7 +67,6 @@
 
 #endif /* H_CHAZ_COMPILER */
 
-
 /**
  * Copyright 2006 The Apache Software Foundation
  *

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Stat.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Stat.c?rev=895798&r1=895797&r2=895798&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Stat.c (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Stat.c Mon Jan  4 22:00:06 2010
@@ -35,7 +35,7 @@
 
     /* Run _charm_stat. */
     Util_remove_and_verify("_charm_statout");
-    ConfWriter_os->run_local(ConfWriter_os, "_charm_stat ", filepath, NULL);
+    OS_run_local("_charm_stat ", filepath, NULL);
     stat_output = Util_slurp_file("_charm_statout", &output_len);
     Util_remove_and_verify("_charm_statout");
 
@@ -79,8 +79,8 @@
 
 
     /* If the compile succeeds, open up for business. */
-    stat_available = ConfWriter_compiler->compile_exe(ConfWriter_compiler, 
-        "_charm_stat.c", "_charm_stat", charm_stat_code, strlen(charm_stat_code));
+    stat_available = CC_compile_exe("_charm_stat.c", "_charm_stat", 
+        charm_stat_code, strlen(charm_stat_code));
     remove("_charm_stat.c");
 }
 

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe.c?rev=895798&r1=895797&r2=895798&view=diff
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe.c (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe.c Mon Jan  4 22:00:06 2010
@@ -14,11 +14,9 @@
 Probe_init(const char *cc_command, const char *cc_flags, 
            const char *charmony_start)
 {
-    /* Create os and compiler objects. */
-    ConfWriter_os       = OS_new();
-    ConfWriter_compiler = CC_new(ConfWriter_os, cc_command, cc_flags);
-
-    /* Dispatch other tasks. */
+    /* Dispatch other initializers. */
+    OS_init();
+    CC_init(cc_command, cc_flags);
     ConfWriter_init();
     HeadCheck_init();
     ConfWriter_open_charmony_h(charmony_start);
@@ -31,10 +29,10 @@
 {
     if (Util_verbosity) { printf("Cleaning up...\n"); }
 
-    /* Dispatch ConfWriter's clean up routines, destroy objects. */
+    /* Dispatch various clean up routines. */
     ConfWriter_clean_up();
-    ConfWriter_os->destroy(ConfWriter_os);
-    ConfWriter_compiler->destroy(ConfWriter_compiler);
+    CC_clean_up();
+    OS_clean_up();
 
     if (Util_verbosity) { printf("Cleanup complete.\n"); }
 }