lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r464246 - /lucene/lucy/trunk/charmonizer/charmonize.c
Date Sun, 15 Oct 2006 18:44:45 GMT
Author: marvin
Date: Sun Oct 15 11:44:44 2006
New Revision: 464246

URL: http://svn.apache.org/viewvc?view=rev&rev=464246
Log:
Add a die() function to charmonize.c.

Modified:
    lucene/lucy/trunk/charmonizer/charmonize.c

Modified: lucene/lucy/trunk/charmonizer/charmonize.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/charmonize.c?view=diff&rev=464246&r1=464245&r2=464246
==============================================================================
--- lucene/lucy/trunk/charmonizer/charmonize.c (original)
+++ lucene/lucy/trunk/charmonizer/charmonize.c Sun Oct 15 11:44:44 2006
@@ -6,6 +6,7 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdarg.h>
 #include "Charmonizer.h"
 #include "Charmonizer/FuncMacro.h"
 #include "Charmonizer/Integers.h"
@@ -37,6 +38,11 @@
 static void 
 finish_conf_file(FILE *fh);
 
+/* Print a message to stderr and exit.
+ */
+void
+die(char *format, ...);
+
 int main(int argc, char **argv) 
 {
     FILE *config_fh;
@@ -44,10 +50,8 @@
     /* parse commmand line args, init Charmonizer, open outfile */
     init(argc, argv);
     config_fh = fopen(outpath, "w");
-    if (config_fh == NULL) {
-        fprintf(stderr, "Couldn't open '%s': %s", strerror(errno));
-        exit(1);
-    }
+    if (config_fh == NULL)
+        die("Couldn't open '%s': %s", strerror(errno));
     start_conf_file(config_fh);
 
     /* modules section */
@@ -59,11 +63,8 @@
 
     /* write tail of config and clean up */
     finish_conf_file(config_fh);
-    if (fclose(config_fh)) {
-        fprintf(stderr, 
-            "Error closing file '%s': %s", outpath, strerror(errno));
-        exit(1);
-    }
+    if (fclose(config_fh))
+        die("Error closing file '%s': %s", outpath, strerror(errno));
     free(outpath);
 
     return 0;
@@ -96,11 +97,8 @@
     chaz_set_compiler(compiler);
 
     /* require an outpath */
-    if (outpath == NULL) {
-        fprintf(stderr, 
-            "Usage: ./charmonize --outpath=OUTPATH [--cc=COMPILER]");
-        exit(1);
-    }
+    if (outpath == NULL)
+        die("Usage: ./charmonize --outpath=OUTPATH [--cc=COMPILER]");
 }
 
 static void 
@@ -142,6 +140,16 @@
     );
 }
 
+void 
+die(char* format, ...) 
+{
+    va_list args;
+    va_start(args, format);
+    vfprintf(stderr, format, args);
+    va_end(args);
+    fprintf(stderr, "\n");
+    exit(1);
+}
 
 /**
  * Copyright 2004 The Apache Software Foundation



Mime
View raw message