lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r468612 - in /lucene/lucy/trunk/charmonizer/src/Charmonizer/Core: Stat.charm Stat.harm
Date Sat, 28 Oct 2006 02:16:23 GMT
Author: marvin
Date: Fri Oct 27 19:16:22 2006
New Revision: 468612

URL: http://svn.apache.org/viewvc?view=rev&rev=468612
Log:
Add Charmonizer/Core/Stat, which compiles a helper app that lets us stat a
file.

Added:
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Stat.charm
    lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Stat.harm

Added: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Stat.charm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Stat.charm?view=auto&rev=468612
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Stat.charm (added)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Stat.charm Fri Oct 27 19:16:22 2006
@@ -0,0 +1,106 @@
+#define CHAZ_USE_SHORT_NAMES
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "Charmonizer/Core/Stat.h"
+
+#include "Charmonizer/Core/Compiler.h"
+#include "Charmonizer/Core/HeadCheck.h"
+#include "Charmonizer/Core/ModHandler.h"
+#include "Charmonizer/Core/OperSys.h"
+#include "Charmonizer/Core/Util.h"
+
+static chaz_bool_t initialized    = false;
+static chaz_bool_t stat_available = false;
+
+/* lazily compile _charm_stat */
+static void
+init();
+
+void
+chaz_Stat_stat(const char *filepath, chaz_Stat *target)
+{
+    char *stat_output;
+    size_t output_len;
+
+    /* failsafe */
+    target->valid = false;
+
+    /* lazy init */
+    if (!initialized)
+        init();
+
+    /* bail out if we didn't succeed in compiling/using _charm_stat */
+    if (!stat_available)
+        return;
+
+    /* run _charm_stat */
+    remove_and_verify("_charm_statout");
+    os->run_local(os, "_charm_stat ", filepath, NULL);
+    stat_output = slurp_file("_charm_statout", &output_len);
+    remove_and_verify("_charm_statout");
+
+    /* parse the output of _charm_stat and store vars in Stat struct */
+    if (stat_output != NULL) {
+        char *end_ptr = stat_output;
+        target->size     = strtol(stat_output, &end_ptr, 10);
+        stat_output      = end_ptr;
+        target->blocks   = strtol(stat_output, &end_ptr, 10);
+        target->valid = true;
+    }
+
+    return;
+}
+
+/* source code for the _charm_stat utility */
+static char charm_stat_code[] = METAQUOTE
+    #include <stdio.h>
+    #include <sys/stat.h>
+    int main(int argc, char **argv) {
+        FILE *out_fh = fopen("_charm_statout", "w+");
+        struct stat st;
+        if (argc != 2)
+            return 1;
+        if (stat(argv[1], &st) == -1)
+            return 2;
+        fprintf(out_fh, "%ld %ld\n", (long)st.st_size, (long)st.st_blocks);
+        return 0;
+    }
+METAQUOTE;
+
+static void
+init()
+{
+    /* only try this once */
+    initialized = true;
+    if (verbosity)
+        printf("Attempting to compile _charm_stat utility...\n");
+
+    /* bail if sys/stat.h isn't available */
+    if (!check_header("sys/stat.h"))
+        return;
+
+    /* if the compile succeeds, open up for business */
+    stat_available = compiler->compile_exe(compiler, "_charm_stat.c",
+        "_charm_stat", charm_stat_code, strlen(charm_stat_code));
+    remove("_charm_stat.c");
+}
+
+
+/**
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Added: lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Stat.harm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Stat.harm?view=auto&rev=468612
==============================================================================
--- lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Stat.harm (added)
+++ lucene/lucy/trunk/charmonizer/src/Charmonizer/Core/Stat.harm Fri Oct 27 19:16:22 2006
@@ -0,0 +1,52 @@
+/* Charmonizer/Core/Stat.h - stat a file, if possible.
+ *
+ * This component works by attempting to compile a utility program called
+ * "_charm_stat".  When Charmonizer needs to stat a file, it shells out to
+ * this utility, which communicates via a file a la capture_output().
+ *
+ * Since we don't know whether we have 64-bit integers when Charmonizer itself
+ * gets compiled, the items in the stat structure are whatever size longs are.
+ * 
+ * TODO: probe for which fields are available.
+ */
+
+#ifndef H_CHAZ_STAT
+#define H_CHAZ_STAT
+
+#include "Charmonizer/Core/Defines.h"
+
+typedef struct chaz_Stat chaz_Stat;
+
+struct chaz_Stat {
+    chaz_bool_t valid;
+    long size;
+    long blocks;
+};
+
+void
+chaz_Stat_stat(const char *filepath, chaz_Stat *target);
+
+#ifdef CHAZ_USE_SHORT_NAMES
+# define Stat                  chaz_Stat
+# define Stat_stat             chaz_Stat_stat
+#endif
+
+#endif /* H_CHAZ_COMPILER */
+
+
+/**
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+



Mime
View raw message