You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2015/07/11 15:01:36 UTC

[1/5] lucy-clownfish git commit: Support POD links to standalone documentation files

Repository: lucy-clownfish
Updated Branches:
  refs/heads/master b055f09c8 -> 5469b104f


Support POD links to standalone documentation files


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/608a5428
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/608a5428
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/608a5428

Branch: refs/heads/master
Commit: 608a5428f7f039bf466918a19c93729e2278b73d
Parents: dc32569
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Wed Jul 8 15:25:55 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Jul 11 14:54:59 2015 +0200

----------------------------------------------------------------------
 compiler/src/CFCPerlPod.c | 49 +++++++++++++++++++++++++++---------------
 compiler/src/CFCUri.c     |  5 +----
 2 files changed, 33 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/608a5428/compiler/src/CFCPerlPod.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlPod.c b/compiler/src/CFCPerlPod.c
index bc99a6a..24d6c4b 100644
--- a/compiler/src/CFCPerlPod.c
+++ b/compiler/src/CFCPerlPod.c
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 
+#include "charmony.h"
+
 #include <string.h>
 #include <ctype.h>
 
@@ -30,6 +32,7 @@
 #include "CFCFunction.h"
 #include "CFCDocuComment.h"
 #include "CFCUri.h"
+#include "CFCDocument.h"
 
 #ifndef true
   #define true 1
@@ -557,14 +560,29 @@ S_convert_link(cmark_node *link, CFCClass *klass, int header_level) {
         case CFC_URI_CLASS: {
             const char *full_struct_sym = CFCUri_full_struct_sym(uri_obj);
             CFCClass *uri_class
-                = CFCClass_fetch_by_struct_sym(full_struct_sym);
-
-            if (!uri_class) {
-                CFCUtil_warn("URI class not found: %s", full_struct_sym);
+                = full_struct_sym
+                ? CFCClass_fetch_by_struct_sym(full_struct_sym)
+                : NULL;
+
+            if (uri_class) {
+                if (uri_class != klass) {
+                    const char *class_name = CFCClass_get_name(uri_class);
+                    new_uri = CFCUtil_strdup(class_name);
+                }
             }
-            else if (uri_class != klass) {
-                const char *class_name = CFCClass_get_name(uri_class);
-                new_uri = CFCUtil_strdup(class_name);
+            else {
+                const char *doc_name = CFCUri_get_struct_sym(uri_obj);
+                CFCDocument *doc = CFCDocument_fetch(doc_name);
+
+                if (!doc) {
+                    CFCUtil_warn("No class or document found for URI '%s'",
+                                 uri);
+                }
+                else {
+                    const char *path_part = CFCDocument_get_path_part(doc);
+                    new_uri = CFCUtil_global_replace(path_part, CHY_DIR_SEP,
+                                                     "::");
+                }
             }
 
             if (text[0] != '\0') {
@@ -572,8 +590,10 @@ S_convert_link(cmark_node *link, CFCClass *klass, int header_level) {
                 break;
             }
 
-            if (strcmp(CFCUri_get_prefix(uri_obj),
-                       CFCClass_get_prefix(klass)) == 0
+            if (!uri_class
+                || !klass
+                || strcmp(CFCUri_get_prefix(uri_obj),
+                          CFCClass_get_prefix(klass)) == 0
             ) {
                 // Same parcel.
                 const char *struct_sym = CFCUri_get_struct_sym(uri_obj);
@@ -581,14 +601,9 @@ S_convert_link(cmark_node *link, CFCClass *klass, int header_level) {
             }
             else {
                 // Other parcel.
-                if (!uri_class) {
-                    new_text = CFCUtil_strdup(full_struct_sym);
-                }
-                else {
-                    const char *class_name
-                        = CFCClass_get_name(uri_class);
-                    new_text = CFCUtil_strdup(class_name);
-                }
+                const char *class_name
+                    = CFCClass_get_name(uri_class);
+                new_text = CFCUtil_strdup(class_name);
             }
 
             break;

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/608a5428/compiler/src/CFCUri.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCUri.c b/compiler/src/CFCUri.c
index 530196e..4799d6a 100644
--- a/compiler/src/CFCUri.c
+++ b/compiler/src/CFCUri.c
@@ -124,10 +124,7 @@ S_parse_uri(CFCUri *self, const char *uri, CFCClass *klass) {
         self->prefix = CFCUtil_sprintf("%s_", components[i]);
         ++i;
     }
-    else {
-        if (!klass) {
-            CFCUtil_die("Class needed to complete URI: %s", uri);
-        }
+    else if (klass) {
         self->prefix = CFCUtil_strdup(CFCClass_get_prefix(klass));
     }
 


[3/5] lucy-clownfish git commit: Helper function to extract path parts

Posted by nw...@apache.org.
Helper function to extract path parts


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/692f8ad1
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/692f8ad1
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/692f8ad1

Branch: refs/heads/master
Commit: 692f8ad186ee0dc50cb4b4937845fad8bfc87714
Parents: b055f09
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Wed Jul 8 13:59:25 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Jul 11 14:54:59 2015 +0200

----------------------------------------------------------------------
 compiler/src/CFCHierarchy.c  | 77 +++++++++++++++++++--------------------
 compiler/src/CFCTestParcel.c |  6 +--
 2 files changed, 40 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/692f8ad1/compiler/src/CFCHierarchy.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCHierarchy.c b/compiler/src/CFCHierarchy.c
index ea4f8d7..a9bda94 100644
--- a/compiler/src/CFCHierarchy.c
+++ b/compiler/src/CFCHierarchy.c
@@ -81,6 +81,9 @@ S_parse_cf_files(CFCHierarchy *self, const char *source_dir, int is_included);
 static void
 S_find_files(const char *path, void *arg);
 
+static char*
+S_extract_path_part(const char *path, const char *dir, const char *ext);
+
 static void
 S_connect_classes(CFCHierarchy *self);
 
@@ -251,26 +254,10 @@ S_parse_parcel_files(const char *source_dir, int is_included) {
     context.num_paths = 0;
     CFCUtil_walk(source_dir, S_find_files, &context);
 
-    size_t source_dir_len = strlen(source_dir);
-
     // Parse .cfp files and register the parcels they define.
     for (int i = 0; context.paths[i] != NULL; i++) {
         const char *path = context.paths[i];
-
-        if (strncmp(path, source_dir, source_dir_len) != 0) {
-            CFCUtil_die("'%s' doesn't start with '%s'", path, source_dir);
-        }
-        const char *path_part = path + source_dir_len;
-        while (*path_part == CHY_DIR_SEP_CHAR) {
-            ++path_part;
-        }
-
-        // Ignore hidden files.
-        if (path_part[0] == '.'
-            || strstr(path_part, CHY_DIR_SEP ".") != NULL) {
-            continue;
-        }
-
+        char *path_part = S_extract_path_part(path, source_dir, ".cfp");
         CFCFileSpec *file_spec
             = CFCFileSpec_new(source_dir, path_part, is_included);
         CFCParcel *parcel = CFCParcel_new_from_file(path, file_spec);
@@ -293,6 +280,7 @@ S_parse_parcel_files(const char *source_dir, int is_included) {
         }
         CFCBase_decref((CFCBase*)parcel);
         CFCBase_decref((CFCBase*)file_spec);
+        FREEMEM(path_part);
     }
 
     CFCUtil_free_string_array(context.paths);
@@ -328,33 +316,12 @@ S_parse_cf_files(CFCHierarchy *self, const char *source_dir, int is_included) {
     context.paths     = (char**)CALLOCATE(1, sizeof(char*));
     context.num_paths = 0;
     CFCUtil_walk(source_dir, S_find_files, &context);
-    size_t source_dir_len  = strlen(source_dir);
-    char *path_part = NULL;
-    size_t path_part_max = 0;
 
     // Process any file that has at least one class declaration.
     for (int i = 0; context.paths[i] != NULL; i++) {
         // Derive the name of the class that owns the module file.
         char *source_path = context.paths[i];
-        size_t source_path_len = strlen(source_path);
-        if (strncmp(source_path, source_dir, source_dir_len) != 0) {
-            CFCUtil_die("'%s' doesn't start with '%s'", source_path,
-                        source_dir);
-        }
-        size_t path_part_len = source_path_len
-                               - source_dir_len
-                               - strlen(".cfh");
-        if (path_part_max < path_part_len + 1) {
-            path_part_max = path_part_len + 1;
-            path_part = (char*)REALLOCATE(path_part, path_part_max);
-        }
-        const char *src = source_path + source_dir_len;
-        while (*src == CHY_DIR_SEP_CHAR) {
-            ++src;
-            --path_part_len;
-        }
-        memcpy(path_part, src, path_part_len);
-        path_part[path_part_len] = '\0';
+        char *path_part = S_extract_path_part(source_path, source_dir, ".cfh");
 
         // Ignore hidden files.
         if (path_part[0] == '.'
@@ -397,11 +364,11 @@ S_parse_cf_files(CFCHierarchy *self, const char *source_dir, int is_included) {
 
         CFCBase_decref((CFCBase*)file);
         CFCBase_decref((CFCBase*)file_spec);
+        FREEMEM(path_part);
     }
     self->classes[self->num_classes] = NULL;
 
     CFCUtil_free_string_array(context.paths);
-    FREEMEM(path_part);
 }
 
 static void
@@ -424,6 +391,36 @@ S_find_files(const char *path, void *arg) {
     }
 }
 
+static char*
+S_extract_path_part(const char *path, const char *dir, const char *ext) {
+    size_t path_len = strlen(path);
+    size_t dir_len  = strlen(dir);
+    size_t ext_len  = strlen(ext);
+
+    if (path_len <= dir_len + ext_len) {
+        CFCUtil_die("Unexpected path '%s'", path);
+    }
+    if (strncmp(path, dir, dir_len) != 0) {
+        CFCUtil_die("'%s' doesn't start with '%s'", path, dir);
+    }
+    if (strcmp(path + path_len - ext_len, ext) != 0) {
+        CFCUtil_die("'%s' doesn't end with '%s'", path, ext);
+    }
+
+    const char *src = path + dir_len;
+    size_t path_part_len = path_len - (dir_len + ext_len);
+    while (path_part_len && *src == CHY_DIR_SEP_CHAR) {
+        ++src;
+        --path_part_len;
+    }
+
+    char *path_part = (char*)MALLOCATE(path_part_len + 1);
+    memcpy(path_part, src, path_part_len);
+    path_part[path_part_len] = '\0';
+
+    return path_part;
+}
+
 static void
 S_connect_classes(CFCHierarchy *self) {
     // Wrangle the classes into hierarchies and figure out inheritance.

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/692f8ad1/compiler/src/CFCTestParcel.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCTestParcel.c b/compiler/src/CFCTestParcel.c
index 8d57b0c..eec782a 100644
--- a/compiler/src/CFCTestParcel.c
+++ b/compiler/src/CFCTestParcel.c
@@ -86,7 +86,7 @@ S_run_parcel_tests(CFCTest *test) {
     }
 
     {
-        CFCFileSpec *file_spec = CFCFileSpec_new(".", "Parcel.cfp", true);
+        CFCFileSpec *file_spec = CFCFileSpec_new(".", "Parcel", true);
         CFCParcel *parcel = CFCParcel_new("Foo", NULL, NULL, file_spec);
         OK(test, CFCParcel_included(parcel), "included");
         CFCBase_decref((CFCBase*)parcel);
@@ -163,13 +163,13 @@ S_run_parcel_tests(CFCTest *test) {
     }
 
     {
-        CFCFileSpec *foo_file_spec = CFCFileSpec_new(".", "Foo.cfp", true);
+        CFCFileSpec *foo_file_spec = CFCFileSpec_new(".", "Foo", true);
         CFCParcel *foo = CFCParcel_new("Foo", NULL, NULL, foo_file_spec);
         CFCParcel_register(foo);
 
         CFCVersion *cfish_version = CFCVersion_new("v0.8.7");
         CFCFileSpec *cfish_file_spec
-            = CFCFileSpec_new(".", "Clownfish.cfp", true);
+            = CFCFileSpec_new(".", "Clownfish", true);
         CFCParcel *cfish
             = CFCParcel_new("Clownfish", NULL, cfish_version, cfish_file_spec);
         CFCParcel_register(cfish);


[4/5] lucy-clownfish git commit: Implement class CFCDocument for standalone documentation

Posted by nw...@apache.org.
Implement class CFCDocument for standalone documentation


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/5cdc2b94
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/5cdc2b94
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/5cdc2b94

Branch: refs/heads/master
Commit: 5cdc2b9499740f843fc500a7f9622163a8db149d
Parents: 692f8ad
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Wed Jul 8 14:40:24 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Jul 11 14:54:59 2015 +0200

----------------------------------------------------------------------
 compiler/include/CFC.h      |   1 +
 compiler/src/CFCDocument.c  | 141 +++++++++++++++++++++++++++++++++++++++
 compiler/src/CFCDocument.h  |  62 +++++++++++++++++
 compiler/src/CFCHierarchy.c |  27 +++++++-
 4 files changed, 230 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5cdc2b94/compiler/include/CFC.h
----------------------------------------------------------------------
diff --git a/compiler/include/CFC.h b/compiler/include/CFC.h
index 486aec0..e57c873 100644
--- a/compiler/include/CFC.h
+++ b/compiler/include/CFC.h
@@ -19,6 +19,7 @@
 #include "CFCCallable.h"
 #include "CFCClass.h"
 #include "CFCDocuComment.h"
+#include "CFCDocument.h"
 #include "CFCFile.h"
 #include "CFCFileSpec.h"
 #include "CFCFunction.h"

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5cdc2b94/compiler/src/CFCDocument.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCDocument.c b/compiler/src/CFCDocument.c
new file mode 100644
index 0000000..8993b9c
--- /dev/null
+++ b/compiler/src/CFCDocument.c
@@ -0,0 +1,141 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+#include "charmony.h"
+
+#include <string.h>
+
+#define CFC_NEED_BASE_STRUCT_DEF
+#include "CFCBase.h"
+#include "CFCDocument.h"
+#include "CFCUtil.h"
+
+struct CFCDocument {
+    CFCBase base;
+    char *path;
+    char *path_part;
+    char *name;
+};
+
+static const CFCMeta CFCDOCUMENT_META = {
+    "Clownfish::CFC::Model::Document",
+    sizeof(CFCDocument),
+    (CFCBase_destroy_t)CFCDocument_destroy
+};
+
+static CFCDocument **registry = NULL;
+static size_t registry_size = 0;
+static size_t registry_cap  = 0;
+
+static void
+S_register(CFCDocument *self);
+
+CFCDocument*
+CFCDocument_create(const char *path, const char *path_part) {
+    CFCDocument *self = (CFCDocument*)CFCBase_allocate(&CFCDOCUMENT_META);
+    return CFCDocument_do_create(self, path, path_part);
+}
+
+CFCDocument*
+CFCDocument_do_create(CFCDocument *self, const char *path,
+                      const char *path_part) {
+    self->path      = CFCUtil_strdup(path);
+    self->path_part = CFCUtil_strdup(path_part);
+
+    if (CHY_DIR_SEP_CHAR != '/') {
+        for (size_t i = 0; self->path_part[i]; i++) {
+            if (self->path_part[i] == '/') {
+                self->path_part[i] = CHY_DIR_SEP_CHAR;
+            }
+        }
+    }
+
+    const char *last_dir_sep = strrchr(self->path_part, CHY_DIR_SEP_CHAR);
+    self->name = CFCUtil_strdup(last_dir_sep + 1);
+
+    S_register(self);
+
+    return self;
+}
+
+void
+CFCDocument_destroy(CFCDocument *self) {
+    FREEMEM(self->path);
+    FREEMEM(self->path_part);
+    FREEMEM(self->name);
+}
+
+static void
+S_register(CFCDocument *self) {
+    if (CFCDocument_fetch(self->name) != NULL) {
+        CFCUtil_die("Two documents with name %s", self->name);
+    }
+
+    if (registry_size == registry_cap) {
+        size_t new_cap = registry_cap + 10;
+        size_t bytes   = (new_cap + 1) * sizeof(CFCDocument*);
+        registry = (CFCDocument**)REALLOCATE(registry, bytes);
+        registry_cap = new_cap;
+    }
+
+    registry[registry_size]   = (CFCDocument*)CFCBase_incref((CFCBase*)self);
+    registry[registry_size+1] = NULL;
+    registry_size++;
+}
+
+CFCDocument**
+CFCDocument_get_registry() {
+    if (registry == NULL) {
+        registry = (CFCDocument**)CALLOCATE(1, sizeof(CFCDocument*));
+    }
+
+    return registry;
+}
+
+CFCDocument*
+CFCDocument_fetch(const char *name) {
+    for (size_t i = 0; i < registry_size; i++) {
+        CFCDocument *doc = registry[i];
+
+        if (strcmp(doc->name, name) == 0) {
+            return doc;
+        }
+    }
+
+    return NULL;
+}
+
+char*
+CFCDocument_get_contents(CFCDocument *self) {
+    size_t len;
+    return CFCUtil_slurp_text(self->path, &len);
+}
+
+const char*
+CFCDocument_get_path(CFCDocument *self) {
+    return self->path;
+}
+
+const char*
+CFCDocument_get_path_part(CFCDocument *self) {
+    return self->path_part;
+}
+
+const char*
+CFCDocument_get_name(CFCDocument *self) {
+    return self->name;
+}
+

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5cdc2b94/compiler/src/CFCDocument.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCDocument.h b/compiler/src/CFCDocument.h
new file mode 100644
index 0000000..5a32cf5
--- /dev/null
+++ b/compiler/src/CFCDocument.h
@@ -0,0 +1,62 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+/** Clownfish::CFC::Model::Document - A standalone documentatio file.
+ */
+
+#ifndef H_CFCDOCUMENT
+#define H_CFCDOCUMENT
+
+#ifdef __cplusplus
+extern "C";
+#endif
+
+typedef struct CFCDocument CFCDocument;
+
+CFCDocument*
+CFCDocument_create(const char *path, const char *path_part);
+
+CFCDocument*
+CFCDocument_do_create(CFCDocument *self, const char *path,
+                      const char *path_part);
+
+void
+CFCDocument_destroy(CFCDocument *self);
+
+CFCDocument**
+CFCDocument_get_registry(void);
+
+CFCDocument*
+CFCDocument_fetch(const char *name);
+
+char*
+CFCDocument_get_contents(CFCDocument *self);
+
+const char*
+CFCDocument_get_path(CFCDocument *self);
+
+const char*
+CFCDocument_get_path_part(CFCDocument *self);
+
+const char*
+CFCDocument_get_name(CFCDocument *self);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* H_CFCDOCUMENT */
+

http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/5cdc2b94/compiler/src/CFCHierarchy.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCHierarchy.c b/compiler/src/CFCHierarchy.c
index a9bda94..57d3bfc 100644
--- a/compiler/src/CFCHierarchy.c
+++ b/compiler/src/CFCHierarchy.c
@@ -38,6 +38,7 @@
 #include "CFCSymbol.h"
 #include "CFCUtil.h"
 #include "CFCParser.h"
+#include "CFCDocument.h"
 
 struct CFCHierarchy {
     CFCBase base;
@@ -79,6 +80,9 @@ static void
 S_parse_cf_files(CFCHierarchy *self, const char *source_dir, int is_included);
 
 static void
+S_find_doc_files(const char *source_dir);
+
+static void
 S_find_files(const char *path, void *arg);
 
 static char*
@@ -228,9 +232,10 @@ CFCHierarchy_build(CFCHierarchy *self) {
 
     S_check_prereqs(self);
 
-    // Read .cfh files.
+    // Read .cfh and .md files.
     for (size_t i = 0; self->sources[i] != NULL; i++) {
         S_parse_cf_files(self, self->sources[i], false);
+        S_find_doc_files(self->sources[i]);
     }
     for (size_t i = 0; self->includes[i] != NULL; i++) {
         S_parse_cf_files(self, self->includes[i], true);
@@ -372,6 +377,26 @@ S_parse_cf_files(CFCHierarchy *self, const char *source_dir, int is_included) {
 }
 
 static void
+S_find_doc_files(const char *source_dir) {
+    CFCFindFilesContext context;
+    context.ext       = ".md";
+    context.paths     = (char**)CALLOCATE(1, sizeof(char*));
+    context.num_paths = 0;
+    CFCUtil_walk(source_dir, S_find_files, &context);
+
+    for (int i = 0; context.paths[i] != NULL; i++) {
+        char *path = context.paths[i];
+        char *path_part = S_extract_path_part(path, source_dir, ".md");
+        CFCDocument *doc = CFCDocument_create(path, path_part);
+
+        CFCBase_decref((CFCBase*)doc);
+        FREEMEM(path_part);
+    }
+
+    CFCUtil_free_string_array(context.paths);
+}
+
+static void
 S_find_files(const char *path, void *arg) {
     CFCFindFilesContext *context = (CFCFindFilesContext*)arg;
     const char  *ext       = context->ext;


[5/5] lucy-clownfish git commit: Merge branch 'standalone_docs'

Posted by nw...@apache.org.
Merge branch 'standalone_docs'


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/5469b104
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/5469b104
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/5469b104

Branch: refs/heads/master
Commit: 5469b104f019ba6f836f1a9f61733966045f9cab
Parents: b055f09 608a542
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Jul 11 14:57:27 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Jul 11 14:57:27 2015 +0200

----------------------------------------------------------------------
 compiler/include/CFC.h       |   1 +
 compiler/src/CFCDocument.c   | 141 ++++++++++++++++++++++++++++++++++++++
 compiler/src/CFCDocument.h   |  62 +++++++++++++++++
 compiler/src/CFCHierarchy.c  | 104 +++++++++++++++++-----------
 compiler/src/CFCPerl.c       | 119 ++++++++++++++++++++++++++------
 compiler/src/CFCPerlPod.c    |  49 ++++++++-----
 compiler/src/CFCTestParcel.c |   6 +-
 compiler/src/CFCUri.c        |   5 +-
 8 files changed, 402 insertions(+), 85 deletions(-)
----------------------------------------------------------------------



[2/5] lucy-clownfish git commit: Convert standalone Markdown documentation to POD

Posted by nw...@apache.org.
Convert standalone Markdown documentation to POD


Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/dc325698
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/dc325698
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/dc325698

Branch: refs/heads/master
Commit: dc325698e896b9ee20b74cf98827b6256a7d75c0
Parents: 5cdc2b9
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon Jul 6 16:24:47 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sat Jul 11 14:54:59 2015 +0200

----------------------------------------------------------------------
 compiler/src/CFCPerl.c | 119 ++++++++++++++++++++++++++++++++++++--------
 1 file changed, 99 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/dc325698/compiler/src/CFCPerl.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerl.c b/compiler/src/CFCPerl.c
index ecfb35e..04ccacb 100644
--- a/compiler/src/CFCPerl.c
+++ b/compiler/src/CFCPerl.c
@@ -32,7 +32,14 @@
 #include "CFCPerlConstructor.h"
 #include "CFCPerlMethod.h"
 #include "CFCPerlTypeMap.h"
+#include "CFCPerlPod.h"
 #include "CFCBindCore.h"
+#include "CFCDocument.h"
+
+typedef struct CFCPerlPodFile {
+    char *path;
+    char *contents;
+} CFCPerlPodFile;
 
 struct CFCPerl {
     CFCBase base;
@@ -53,6 +60,12 @@ struct CFCPerl {
 static void
 S_replace_double_colons(char *text, char replacement);
 
+static CFCPerlPodFile*
+S_write_class_pod(CFCPerl *self);
+
+static CFCPerlPodFile*
+S_write_standalone_pod(CFCPerl *self);
+
 static void
 S_write_callbacks_c(CFCPerl *self);
 
@@ -136,12 +149,64 @@ S_replace_double_colons(char *text, char replacement) {
 
 char**
 CFCPerl_write_pod(CFCPerl *self) {
+    CFCPerlPodFile *class_pods      = S_write_class_pod(self);
+    CFCPerlPodFile *standalone_pods = S_write_standalone_pod(self);
+
+    size_t max_paths = 0;
+    for (size_t i = 0; class_pods[i].contents; i++)      { max_paths++; }
+    for (size_t i = 0; standalone_pods[i].contents; i++) { max_paths++; }
+    char **pod_paths = (char**)CALLOCATE(max_paths + 1, sizeof(char*));
+
+    // Write out any POD files that have changed.
+    CFCPerlPodFile *file_arrays[2] = {
+        class_pods,
+        standalone_pods
+    };
+    size_t num_written = 0;
+    for (size_t j = 0; j < 2; ++j) {
+        CFCPerlPodFile *pod_files = file_arrays[j];
+
+        for (size_t i = 0; pod_files[i].contents; i++) {
+            char *pod      = pod_files[i].contents;
+            char *pod_path = pod_files[i].path;
+            char *pod_dir  = CFCUtil_strdup(pod_path);
+
+            char *last_dir_sep = strrchr(pod_dir, CHY_DIR_SEP_CHAR);
+            if (last_dir_sep) {
+                *last_dir_sep = '\0';
+                if (!CFCUtil_make_path(pod_dir)) {
+                    CFCUtil_die("Can't make path %s", pod_dir);
+                }
+            }
+
+            if (CFCUtil_write_if_changed(pod_path, pod, strlen(pod))) {
+                pod_paths[num_written] = pod_path;
+                num_written++;
+            }
+            else {
+                FREEMEM(pod_path);
+            }
+
+            FREEMEM(pod);
+            FREEMEM(pod_dir);
+        }
+
+        FREEMEM(pod_files);
+    }
+    pod_paths[num_written] = NULL;
+
+    return pod_paths;
+}
+
+static CFCPerlPodFile*
+S_write_class_pod(CFCPerl *self) {
     CFCPerlClass **registry  = CFCPerlClass_registry();
     size_t num_registered = 0;
     while (registry[num_registered] != NULL) { num_registered++; }
-    char     **pod_paths = (char**)CALLOCATE(num_registered + 1, sizeof(char*));
-    char     **pods      = (char**)CALLOCATE(num_registered + 1, sizeof(char*));
-    size_t     count     = 0;
+    CFCPerlPodFile *pod_files
+        = (CFCPerlPodFile*)CALLOCATE(num_registered + 1,
+                                     sizeof(CFCPerlPodFile));
+    size_t count = 0;
 
     // Generate POD, but don't write.  That way, if there's an error while
     // generating pod, we leak memory but don't clutter up the file system.
@@ -155,30 +220,44 @@ CFCPerl_write_pod(CFCPerl *self) {
                                          self->lib_dir, class_name);
         S_replace_double_colons(pod_path, CHY_DIR_SEP_CHAR);
 
-        pods[count] = pod;
-        pod_paths[count] = pod_path;
+        pod_files[count].contents = pod;
+        pod_files[count].path     = pod_path;
         count++;
 
         FREEMEM(raw_pod);
     }
+    pod_files[count].contents = NULL;
+    pod_files[count].path     = NULL;
 
-    // Write out any POD files that have changed.
-    size_t num_written = 0;
-    for (size_t i = 0; i < count; i++) {
-        char *pod      = pods[i];
-        char *pod_path = pod_paths[i];
-        if (CFCUtil_write_if_changed(pod_path, pod, strlen(pod))) {
-            pod_paths[num_written] = pod_path;
-            num_written++;
-        }
-        else {
-            FREEMEM(pod_path);
-        }
-        FREEMEM(pod);
+    return pod_files;
+}
+
+static CFCPerlPodFile*
+S_write_standalone_pod(CFCPerl *self) {
+    CFCDocument **docs = CFCDocument_get_registry();
+    size_t num_pod_files = 0;
+    while (docs[num_pod_files]) { num_pod_files++; }
+    size_t alloc_size = (num_pod_files + 1) * sizeof(CFCPerlPodFile);
+    CFCPerlPodFile *pod_files = (CFCPerlPodFile*)MALLOCATE(alloc_size);
+
+    for (size_t i = 0; i < num_pod_files; i++) {
+        CFCDocument *doc = docs[i];
+        char *md  = CFCDocument_get_contents(doc);
+        char *pod = CFCPerlPod_md_to_pod(md, NULL, 1);
+        FREEMEM(md);
+
+        const char *path_part = CFCDocument_get_path_part(doc);
+        char *pod_path = CFCUtil_sprintf("%s" CHY_DIR_SEP "%s.pod",
+                                         self->lib_dir, path_part);
+
+        pod_files[i].contents = pod;
+        pod_files[i].path     = pod_path;
     }
-    pod_paths[num_written] = NULL;
 
-    return pod_paths;
+    pod_files[num_pod_files].contents = NULL;
+    pod_files[num_pod_files].path     = NULL;
+
+    return pod_files;
 }
 
 static void