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 2014/08/31 15:34:01 UTC
[2/8] git commit: Don't hardcode POD and man page headers
Don't hardcode POD and man page headers
Use the supplied autogen header and footer instead.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/19011e04
Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/19011e04
Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/19011e04
Branch: refs/heads/documentation
Commit: 19011e0496c63aea525e6b213be4c9bcfe524ffd
Parents: af31761
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Sat Aug 23 17:41:01 2014 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sun Aug 31 15:32:07 2014 +0200
----------------------------------------------------------------------
compiler/src/CFCC.c | 19 ++++++++++----
compiler/src/CFCCClass.c | 28 +++++---------------
compiler/src/CFCPerl.c | 14 ++++++++--
compiler/src/CFCPerlClass.c | 55 ++++++++++++++--------------------------
compiler/src/CFCUtil.c | 10 ++++++++
compiler/src/CFCUtil.h | 10 ++++++++
6 files changed, 72 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/19011e04/compiler/src/CFCC.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCC.c b/compiler/src/CFCC.c
index e0a355d..60a949b 100644
--- a/compiler/src/CFCC.c
+++ b/compiler/src/CFCC.c
@@ -32,6 +32,8 @@ struct CFCC {
CFCHierarchy *hierarchy;
char *c_header;
char *c_footer;
+ char *man_header;
+ char *man_footer;
};
static const CFCMeta CFCC_META = {
@@ -52,9 +54,11 @@ CFCC_init(CFCC *self, CFCHierarchy *hierarchy, const char *header,
CFCUTIL_NULL_CHECK(hierarchy);
CFCUTIL_NULL_CHECK(header);
CFCUTIL_NULL_CHECK(footer);
- self->hierarchy = (CFCHierarchy*)CFCBase_incref((CFCBase*)hierarchy);
- self->c_header = CFCUtil_make_c_comment(header);
- self->c_footer = CFCUtil_make_c_comment(footer);
+ self->hierarchy = (CFCHierarchy*)CFCBase_incref((CFCBase*)hierarchy);
+ self->c_header = CFCUtil_make_c_comment(header);
+ self->c_footer = CFCUtil_make_c_comment(footer);
+ self->man_header = CFCUtil_make_troff_comment(header);
+ self->man_footer = CFCUtil_make_troff_comment(footer);
return self;
}
@@ -63,6 +67,8 @@ CFCC_destroy(CFCC *self) {
CFCBase_decref((CFCBase*)self->hierarchy);
FREEMEM(self->c_header);
FREEMEM(self->c_footer);
+ FREEMEM(self->man_header);
+ FREEMEM(self->man_footer);
CFCBase_destroy((CFCBase*)self);
}
@@ -151,8 +157,10 @@ CFCC_write_man_pages(CFCC *self) {
CFCClass *klass = ordered[i];
if (CFCClass_included(klass)) { continue; }
- char *man_page = man_pages[j++];
- if (!man_page) { continue; }
+ char *raw_man_page = man_pages[j++];
+ if (!raw_man_page) { continue; }
+ char *man_page = CFCUtil_sprintf("%s%s%s", self->man_header,
+ raw_man_page, self->man_footer);
const char *full_struct_sym = CFCClass_full_struct_sym(klass);
char *filename = CFCUtil_sprintf("%s" CHY_DIR_SEP "%s.3", man3_path,
@@ -160,6 +168,7 @@ CFCC_write_man_pages(CFCC *self) {
CFCUtil_write_if_changed(filename, man_page, strlen(man_page));
FREEMEM(filename);
FREEMEM(man_page);
+ FREEMEM(raw_man_page);
}
FREEMEM(man3_path);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/19011e04/compiler/src/CFCCClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCCClass.c b/compiler/src/CFCCClass.c
index b6def3b..8dfe9db 100644
--- a/compiler/src/CFCCClass.c
+++ b/compiler/src/CFCCClass.c
@@ -121,27 +121,13 @@ CFCCClass_create_man_page(CFCClass *klass) {
// Put it all together.
const char pattern[] =
- ".\\\" Licensed to the Apache Software Foundation (ASF) under one or more\n"
- ".\\\" contributor license agreements. See the NOTICE file distributed with\n"
- ".\\\" this work for additional information regarding copyright ownership.\n"
- ".\\\" The ASF licenses this file to You under the Apache License, Version 2.0\n"
- ".\\\" (the \"License\"); you may not use this file except in compliance with\n"
- ".\\\" the License. You may obtain a copy of the License at\n"
- ".\\\"\n"
- ".\\\" http://www.apache.org/licenses/LICENSE-2.0\n"
- ".\\\"\n"
- ".\\\" Unless required by applicable law or agreed to in writing, software\n"
- ".\\\" distributed under the License is distributed on an \"AS IS\" BASIS,\n"
- ".\\\" WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
- ".\\\" See the License for the specific language governing permissions and\n"
- ".\\\" limitations under the License.\n"
- ".TH %s 3\n"
- "%s"
- "%s"
- "%s"
- "%s"
- "%s"
- "%s";
+ ".TH %s 3\n"
+ "%s"
+ "%s"
+ "%s"
+ "%s"
+ "%s"
+ "%s";
char *man_page
= CFCUtil_sprintf(pattern, class_name, name, synopsis, description,
functions_man, methods_man, inheritance);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/19011e04/compiler/src/CFCPerl.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerl.c b/compiler/src/CFCPerl.c
index c78fcbf..a04bb61 100644
--- a/compiler/src/CFCPerl.c
+++ b/compiler/src/CFCPerl.c
@@ -43,6 +43,8 @@ struct CFCPerl {
char *footer;
char *c_header;
char *c_footer;
+ char *pod_header;
+ char *pod_footer;
char *xs_path;
char *boot_func;
};
@@ -82,6 +84,8 @@ CFCPerl_init(CFCPerl *self, CFCHierarchy *hierarchy, const char *lib_dir,
self->footer = CFCUtil_strdup(footer);
self->c_header = CFCUtil_make_c_comment(header);
self->c_footer = CFCUtil_make_c_comment(footer);
+ self->pod_header = CFCUtil_make_perl_comment(header);
+ self->pod_footer = CFCUtil_make_perl_comment(footer);
// Derive path to generated .xs file.
self->xs_path = CFCUtil_sprintf("%s" CHY_DIR_SEP "%s.xs", lib_dir,
@@ -108,6 +112,8 @@ CFCPerl_destroy(CFCPerl *self) {
FREEMEM(self->footer);
FREEMEM(self->c_header);
FREEMEM(self->c_footer);
+ FREEMEM(self->pod_header);
+ FREEMEM(self->pod_footer);
FREEMEM(self->xs_path);
FREEMEM(self->boot_func);
CFCBase_destroy((CFCBase*)self);
@@ -141,8 +147,10 @@ CFCPerl_write_pod(CFCPerl *self) {
// generating pod, we leak memory but don't clutter up the file system.
for (size_t i = 0; i < num_registered; i++) {
const char *class_name = CFCPerlClass_get_class_name(registry[i]);
- char *pod = CFCPerlClass_create_pod(registry[i]);
- if (!pod) { continue; }
+ char *raw_pod = CFCPerlClass_create_pod(registry[i]);
+ if (!raw_pod) { continue; }
+ char *pod = CFCUtil_sprintf("%s\n%s%s", self->pod_header, raw_pod,
+ self->pod_footer);
char *pod_path = CFCUtil_sprintf("%s" CHY_DIR_SEP "%s.pod",
self->lib_dir, class_name);
S_replace_double_colons(pod_path, CHY_DIR_SEP_CHAR);
@@ -150,6 +158,8 @@ CFCPerl_write_pod(CFCPerl *self) {
pods[count] = pod;
pod_paths[count] = pod_path;
count++;
+
+ FREEMEM(raw_pod);
}
// Write out any POD files that have changed.
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/19011e04/compiler/src/CFCPerlClass.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCPerlClass.c b/compiler/src/CFCPerlClass.c
index 7c018de..a71de04 100644
--- a/compiler/src/CFCPerlClass.c
+++ b/compiler/src/CFCPerlClass.c
@@ -432,42 +432,25 @@ CFCPerlClass_create_pod(CFCPerlClass *self) {
}
// Put it all together.
- const char pattern[] =
- "# Auto-generated file -- DO NOT EDIT!!!!!\n"
- "\n"
- "# Licensed to the Apache Software Foundation (ASF) under one or more\n"
- "# contributor license agreements. See the NOTICE file distributed with\n"
- "# this work for additional information regarding copyright ownership.\n"
- "# The ASF licenses this file to You under the Apache License, Version 2.0\n"
- "# (the \"License\"); you may not use this file except in compliance with\n"
- "# the License. You may obtain a copy of the License at\n"
- "#\n"
- "# http://www.apache.org/licenses/LICENSE-2.0\n"
- "#\n"
- "# Unless required by applicable law or agreed to in writing, software\n"
- "# distributed under the License is distributed on an \"AS IS\" BASIS,\n"
- "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
- "# See the License for the specific language governing permissions and\n"
- "# limitations under the License.\n"
- "\n"
- "=head1 NAME\n"
- "\n"
- "%s - %s\n"
- "\n"
- "%s\n"
- "\n"
- "=head1 DESCRIPTION\n"
- "\n"
- "%s\n"
- "\n"
- "%s\n"
- "\n"
- "%s\n"
- "\n"
- "%s\n"
- "\n"
- "=cut\n"
- "\n";
+ const char pattern[] =
+ "=head1 NAME\n"
+ "\n"
+ "%s - %s\n"
+ "\n"
+ "%s\n"
+ "\n"
+ "=head1 DESCRIPTION\n"
+ "\n"
+ "%s\n"
+ "\n"
+ "%s\n"
+ "\n"
+ "%s\n"
+ "\n"
+ "%s\n"
+ "\n"
+ "=cut\n"
+ "\n";
char *pod
= CFCUtil_sprintf(pattern, class_name, brief, synopsis, description,
constructor_pod, methods_pod, inheritance);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/19011e04/compiler/src/CFCUtil.c
----------------------------------------------------------------------
diff --git a/compiler/src/CFCUtil.c b/compiler/src/CFCUtil.c
index 3b62408..b7e37b5 100644
--- a/compiler/src/CFCUtil.c
+++ b/compiler/src/CFCUtil.c
@@ -194,6 +194,16 @@ CFCUtil_make_c_comment(const char *text) {
return CFCUtil_enclose_lines(text, " * ", "", "/*\n", " */\n");
}
+char*
+CFCUtil_make_perl_comment(const char *text) {
+ return CFCUtil_enclose_lines(text, "# ", "", "", "");
+}
+
+char*
+CFCUtil_make_troff_comment(const char *text) {
+ return CFCUtil_enclose_lines(text, ".\\\" ", "", "", "");
+}
+
void*
CFCUtil_wrapped_malloc(size_t count, const char *file, int line) {
void *pointer = malloc(count);
http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/19011e04/compiler/src/CFCUtil.h
----------------------------------------------------------------------
diff --git a/compiler/src/CFCUtil.h b/compiler/src/CFCUtil.h
index 6012b3d..6540672 100644
--- a/compiler/src/CFCUtil.h
+++ b/compiler/src/CFCUtil.h
@@ -82,6 +82,16 @@ CFCUtil_enclose_lines(const char *text, const char *line_prefix,
char*
CFCUtil_make_c_comment(const char *text);
+/** Create a Perl comment.
+ */
+char*
+CFCUtil_make_perl_comment(const char *text);
+
+/** Create a troff comment.
+ */
+char*
+CFCUtil_make_troff_comment(const char *text);
+
/** Attempt to allocate memory with malloc, but print an error and exit if the
* call fails.
*/