lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r464782 - in /lucene/lucy/trunk/charmonizer/src/Charmonizer: Integers.charm Integers.harm
Date Tue, 17 Oct 2006 03:32:51 GMT
Author: marvin
Date: Mon Oct 16 20:32:49 2006
New Revision: 464782

URL: http://svn.apache.org/viewvc?view=rev&rev=464782
Log:
Add I64P and U64P printf macros for 64-bit integers.

Modified:
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Integers.charm
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Integers.harm

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Integers.charm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Integers.charm?view=diff&rev=464782&r1=464781&r2=464782
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Integers.charm (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Integers.charm Mon Oct 16 20:32:49 2006
@@ -148,8 +148,36 @@
             type, typedef_prefix
         );
     }
+
     if (sizeof_long == 8 || sizeof_long_long == 8) {
+        int i;
         char *type = sizeof_long == 8 ? "long" : "long long";
+
+        /* printf format for 64-bit integer */
+        char *options[] = {
+            "ll",
+            "l",
+            "L",
+            "q",  /* Some *BSDs */
+            "I64", /* Microsoft */
+            NULL,
+        };
+
+        /* buffer to hold the code, and its start and end */
+        char format_64_code[1000];
+        static char format_64_code_a[] = METAQUOTE
+            #include "_charm.h"
+            int main() {
+                Charm_Setup;
+                printf(
+        METAQUOTE;
+        static char format_64_code_b[] = METAQUOTE
+                );
+                return 0;
+            }
+        METAQUOTE;
+
+        /* we have 64-bit ints, so add the typedef */
         has_64 = true;
         fprintf(conf_fh,
             "typedef %s %si64_t;\n"
@@ -157,6 +185,28 @@
             type, typedef_prefix, 
             type, typedef_prefix
         );
+
+        /* create the I64P and U64P printf macros */
+        for (i = 0; options[i] != NULL; i++) {
+            /* try to print 2**64-1, and see if we get it back intact */
+            sprintf(format_64_code, 
+                "%s\"%%%su\", (unsigned %s)18446744073709551615%s", 
+                format_64_code_a, options[i], type, format_64_code_b);
+            output = capture_output(format_64_code, strlen(format_64_code),
+                &output_len);
+
+            if (   output_len != 0 
+                && strcmp(output, "18446744073709551615") == 0
+            ) {
+                fprintf(conf_fh, 
+                    "#define I64P \"%%%sd\"\n"
+                    "#define U64P \"%%%su\"\n",
+                    options[i], options[i]
+                );
+                break;
+            }
+        }
+
     }
 
     /* true and false */
@@ -204,6 +254,8 @@
         if (has_64) {
             shorten_typedef(conf_fh, "i64_t");
             shorten_typedef(conf_fh, "u64_t");
+            shorten_macro(conf_fh, "I64P");
+            shorten_macro(conf_fh, "U64P");
         } 
 
         End_Short_Names(conf_fh);

Modified: lucene/lucy/trunk/charmonizer/src/Charmonizer/Integers.harm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Integers.harm?view=diff&rev=464782&r1=464781&r2=464782
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Integers.harm (original)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Integers.harm Mon Oct 16 20:32:49 2006
@@ -32,6 +32,13 @@
  * i64_t
  * u64_t
  *
+ * If 64-bit integers type are available, these macros will expand to the 
+ * printf formats for signed and unsigned versions (most commonly "%lld" and
+ * "%llu").
+ *
+ * I64P
+ * U64P
+ *
  * These symbols will be defined if they are not already: 
  * 
  * true



Mime
View raw message