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 2006/11/04 03:11:50 UTC

svn commit: r471097 - in /lucene/lucy/trunk: charmonizer/ charmonizer/src/Charmonizer/ charmonizer/src/Charmonizer/Core/ perl/buildlib/Lucy/

Author: marvin
Date: Fri Nov  3 18:11:50 2006
New Revision: 471097

URL: http://svn.apache.org/viewvc?view=rev&rev=471097
Log:
Remove all responsibility for opening charmony.h from the user and place
matters in the library's hands.

Modified:
    lucene/lucy/trunk/charmonizer/charmonize.c
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ModHandler.charm
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ModHandler.harm
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe.charm
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe.harm
    lucene/lucy/trunk/perl/buildlib/Lucy/Build.pm

Modified: lucene/lucy/trunk/charmonizer/charmonize.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/charmonize.c?view=diff&rev=471097&r1=471096&r2=471097
==============================================================================
--- lucene/lucy/trunk/charmonizer/charmonize.c (original)
+++ lucene/lucy/trunk/charmonizer/charmonize.c Fri Nov  3 18:11:50 2006
@@ -14,10 +14,9 @@
 #include "Charmonizer/Probe/UnusedVars.h"
 #include "Charmonizer/Probe/VariadicMacros.h"
 
-/* Process command line args, set up Charmonizer, etc. Returns the outpath
- * (where the config file should be written to).
+/* Process command line args, set up Charmonizer, etc. 
  */
-FILE*
+void
 init(int argc, char **argv);
 
 /* Find <tag_name> and </tag_name> within a string and return the text between
@@ -32,16 +31,6 @@
 extract_delim_and_verify(char *source, size_t source_len, 
                          const char *tag_name);
 
-/* Start the config file.
- */
-static void 
-start_conf_file();
-
-/* Write the last bit of the config file.
- */
-static void 
-finish_conf_file(FILE *fh);
-
 /* Print a message to stderr and exit.
  */
 void
@@ -49,7 +38,7 @@
 
 int main(int argc, char **argv) 
 {
-    FILE *config_fh = init(argc, argv);
+    init(argc, argv);
 
     /* modules section */
     chaz_Headers_run();
@@ -59,22 +48,18 @@
     chaz_UnusedVars_run();
     chaz_VariadicMacros_run();
 
-    /* write tail of config and clean up */
-    finish_conf_file(config_fh);
-    if (fclose(config_fh))
-        die("Error closing config file: %s", strerror(errno));
+    /* clean up */
     chaz_Probe_clean_up();
 
     return 0;
 }
 
-FILE* 
+void
 init(int argc, char **argv) 
 {
-    char *outpath, *cc_command, *cc_flags, *os_name, *verbosity_str;
+    char *cc_command, *cc_flags, *os_name, *verbosity_str;
     char *infile_str;
     size_t infile_len;
-    FILE *conf_fh;
 
     /* parse the infile */
     if (argc != 2)
@@ -84,24 +69,16 @@
         "charm_cc_command");
     cc_flags = extract_delim_and_verify(infile_str, infile_len, 
         "charm_cc_flags");
-    outpath = extract_delim_and_verify(infile_str, infile_len, 
-        "charm_outpath");
     os_name = extract_delim_and_verify(infile_str, infile_len, 
         "charm_os_name");
     verbosity_str = extract_delim(infile_str, infile_len, "charm_verbosity");
 
-    /* open outfile */
-    conf_fh = fopen(outpath, "w");
-    if (conf_fh == NULL)
-        die("Couldn't open '%s': %s", strerror(errno));
-    start_conf_file(conf_fh);
-
     /* set up Charmonizer */
     if (verbosity_str != NULL) {
         const long verbosity = strtol(verbosity_str, NULL, 10);
         chaz_Probe_set_verbosity(verbosity);
     }
-    chaz_Probe_init(conf_fh, os_name, cc_command, cc_flags);
+    chaz_Probe_init(os_name, cc_command, cc_flags, NULL);
     chaz_Probe_set_prefixes("LUCY_", "Lucy_", "lucy_", "lucy_");
 
     /* clean up */
@@ -109,10 +86,7 @@
     free(cc_command);
     free(cc_flags);
     free(os_name);
-    free(outpath);
     free(verbosity_str);
-
-    return conf_fh;
 }
 
 static char*
@@ -162,24 +136,6 @@
     if (retval == NULL)
         die("Couldn't extract value for '%s'", tag_name);
     return retval;
-}
-
-static void 
-start_conf_file(FILE *conf_fh) 
-{
-    fprintf(conf_fh,
-        "/* Header file auto-generated by Charmonizer. \n"
-        " * DO NOT EDIT THIS FILE!!\n"
-        " */\n\n"
-        "#ifndef H_CHARMONY\n"
-        "#define H_CHARMONY 1\n\n"
-    );
-}
-
-static void
-finish_conf_file(FILE *conf_fh) 
-{
-    fprintf(conf_fh, "\n\n#endif /* H_CHARMONY */\n\n");
 }
 
 void 

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ModHandler.charm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ModHandler.charm?view=diff&rev=471097&r1=471096&r2=471097
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ModHandler.charm (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ModHandler.charm Fri Nov  3 18:11:50 2006
@@ -29,7 +29,7 @@
 struct chaz_OperSys  *chaz_ModHand_os = NULL;
 struct chaz_Compiler *chaz_ModHand_compiler = NULL;
 chaz_bool_t chaz_ModHand_charm_run_available = false;
-FILE* chaz_ModHand_conf_fh = NULL;
+FILE* chaz_ModHand_charmony_fh = NULL;
 
 char *constant_prefix = NULL;
 char *macro_prefix    = NULL;
@@ -57,6 +57,40 @@
     write_charm_h();
 }
 
+void
+chaz_ModHand_open_charmony_h(const char *charmony_start)
+{
+    /* open the filehandle */
+    charmony_fh = fopen("charmony.h", "w+");
+    if (charmony_fh == NULL) 
+        die("Can't open 'charmony.h': %s", strerror(errno));
+
+    /* print supplied text (if any), then open include guard */
+    if (charmony_start != NULL)
+        fprintf(charmony_fh, charmony_start);
+    fprintf(charmony_fh,
+        "/* Header file auto-generated by Charmonizer. \n"
+        " * DO NOT EDIT THIS FILE!!\n"
+        " */\n\n"
+        "#ifndef H_CHARMONY\n"
+        "#define H_CHARMONY 1\n\n"
+    );
+}
+
+void
+chaz_ModHand_clean_up(void)
+{
+    /* clean up some temp files */
+    remove("_charm.h");
+    os->remove_exe(os, "_charm_run");
+    os->remove_exe(os, "_charm_stat");
+
+    /* write the last bit of charmony.h and close */
+    fprintf(charmony_fh, "#endif /* H_CHARMONY */\n\n");
+    if (fclose(charmony_fh))
+        die("Couldn't close 'charmony.h': %s", strerror(errno));
+}
+
 static char charm_h_code[] = METAQUOTE
     #ifndef CHARM_H
     #define CHARM_H 1
@@ -188,7 +222,7 @@
     va_list args;
 
     va_start(args, fmt);
-    vfprintf(chaz_ModHand_conf_fh, fmt, args);
+    vfprintf(chaz_ModHand_charmony_fh, fmt, args);
     va_end(args);
 }
 

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ModHandler.harm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ModHandler.harm?view=diff&rev=471097&r1=471096&r2=471097
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ModHandler.harm (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/ModHandler.harm Fri Nov  3 18:11:50 2006
@@ -22,7 +22,7 @@
 extern struct chaz_OperSys  *chaz_ModHand_os;
 extern struct chaz_Compiler *chaz_ModHand_compiler;
 extern chaz_bool_t chaz_ModHand_charm_run_available;
-extern FILE* chaz_ModHand_conf_fh;
+extern FILE* chaz_ModHand_charmony_fh;
 
 extern char *chaz_ModHand_constant_prefix;
 extern char *chaz_ModHand_macro_prefix;
@@ -36,6 +36,18 @@
 void
 chaz_ModHand_init();
 
+/* Open the charmony.h file handle.  Print supplied text to it, if non-null.
+ * Print an explanatory comment and open the include guard.
+ */
+void
+chaz_ModHand_open_charmony_h(const char *charmony_start);
+
+/* Close the include guard on charmony.h, then close the file.  Delete temp
+ * files and perform any other needed cleanup.
+ */
+void
+chaz_ModHand_clean_up(void);
+
 /* Attempt to compile the supplied source code and return true if the
  * effort succeeds.
  */
@@ -109,12 +121,15 @@
 # define os                     chaz_ModHand_os
 # define compiler               chaz_ModHand_compiler
 # define charm_run_available    chaz_ModHand_charm_run_available
+# define charmony_fh            chaz_ModHand_charmony_fh
 # define constant_prefix        chaz_ModHand_constant_prefix
 # define macro_prefix           chaz_ModHand_macro_prefix
 # define typedef_prefix         chaz_ModHand_typedef_prefix
 # define function_prefix        chaz_ModHand_function_prefix
 # define want_short_names       chaz_ModHand_want_short_names
 # define ModHand_init           chaz_ModHand_init
+# define ModHand_open_charmony_h  chaz_ModHand_open_charmony_h
+# define ModHand_clean_up       chaz_ModHand_clean_up
 # define write_charm_h          chaz_ModHand_write_charm_h
 # define build_charm_run        chaz_ModHand_build_charm_run
 # define START_SHORT_NAMES      CHAZ_MODHAND_START_SHORT_NAMES

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe.charm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe.charm?view=diff&rev=471097&r1=471096&r2=471097
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe.charm (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe.charm Fri Nov  3 18:11:50 2006
@@ -11,11 +11,9 @@
 #include "Charmonizer/Core/OperSys.h"
 
 void
-chaz_Probe_init(FILE *conf_fh, const char *osname, const char *cc_command,    
-          const char *cc_flags)
+chaz_Probe_init(const char *osname, const char *cc_command,
+                const char *cc_flags, const char *charmony_start)
 {
-    chaz_ModHand_conf_fh = conf_fh;
-
     /* create os and compiler objects */
     os       = OS_new(osname);
     compiler = CC_new(os, cc_command, cc_flags);
@@ -27,6 +25,7 @@
     /* dispatch other tasks */
     ModHand_init();
     HeadCheck_init();
+    ModHand_open_charmony_h(charmony_start);
 
     if (verbosity)
         printf("Initialization complete.\n");
@@ -38,9 +37,7 @@
     if (verbosity)
         printf("Cleaning up...\n");
 
-    remove("_charm.h");
-    os->remove_exe(os, "_charm_run");
-    os->remove_exe(os, "_charm_stat");
+    ModHand_clean_up();
     os->destroy(os);
     compiler->destroy(compiler);
 

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe.harm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe.harm?view=diff&rev=471097&r1=471096&r2=471097
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe.harm (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Probe.harm Fri Nov  3 18:11:50 2006
@@ -6,10 +6,15 @@
 
 /* Set up the Charmonizer environment.  This should be called before anything
  * else.
+ * 
+ * @param os_name a lowercase string representing the operating system
+ * @param cc_command the string used to invoke the C compiler via system()
+ * @param cc_flags flags which will be passed on to the C compiler
+ * @param charmony_start Code to prepend onto the front of charmony.h
  */
 void
-chaz_Probe_init(FILE *conf_fh, const char *os_name, const char *cc_command, 
-          const char *cc_flags);
+chaz_Probe_init(const char *os_name, const char *cc_command, 
+                const char *cc_flags, const char *charmony_start);
 
 /* Clean up the Charmonizer environment -- deleting tempfiles, etc.  This
  * should be called only after everything else finishes.

Modified: lucene/lucy/trunk/perl/buildlib/Lucy/Build.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/buildlib/Lucy/Build.pm?view=diff&rev=471097&r1=471096&r2=471097
==============================================================================
--- lucene/lucy/trunk/perl/buildlib/Lucy/Build.pm (original)
+++ lucene/lucy/trunk/perl/buildlib/Lucy/Build.pm Fri Nov  3 18:11:50 2006
@@ -159,7 +159,6 @@
     open( my $infile_fh, '>', $lucyconf_in )
         or die "Can't open '$lucyconf_in': $!";
     print $infile_fh qq|
-        <charm_outpath>$lucyconf_path</charm_outpath>
         <charm_os_name>$os_name</charm_os_name>
         <charm_cc_command>$cc</charm_cc_command>
         <charm_cc_flags>$flags</charm_cc_flags>