[hawkmoth] [PATCH] doc: add example with preprocessor

  • From: Bruno Santos <brunomanuelsantos@xxxxxxxxxxxxxxxxxx>
  • To: hawkmoth@xxxxxxxxxxxxx
  • Date: Sat, 2 Feb 2019 19:29:48 +0100

Turns out this is already handled quite well. This should also be an
important test case.
---
 doc/examples.rst                     | 27 +++++++++++++++++++++++++++
 test/example-70-preprocessor.c       |  8 ++++++++
 test/example-70-preprocessor.options |  1 +
 test/example-70-preprocessor.rst     |  5 +++++
 4 files changed, 41 insertions(+)
 create mode 100644 test/example-70-preprocessor.c
 create mode 100644 test/example-70-preprocessor.options
 create mode 100644 test/example-70-preprocessor.rst

diff --git a/doc/examples.rst b/doc/examples.rst
index 3a4dea3..6be635d 100644
--- a/doc/examples.rst
+++ b/doc/examples.rst
@@ -181,6 +181,33 @@ Output
 
    .. include:: examples/example-70-function.rst
 
+Preprocessor
+------------
+
+Source
+~~~~~~
+
+.. literalinclude:: examples/example-70-preprocessor.c
+   :language: C
+
+Directive
+~~~~~~~~~
+
+.. code-block:: rest
+
+   .. c:autodoc:: examples/example-70-preprocessor.c
+      :clang: -DDEEP_THOUGHT
+
+Output
+~~~~~~
+
+.. c:autodoc:: examples/example-70-preprocessor.c
+   :clang: -DDEEP_THOUGHT
+
+.. only:: not have_hawkmoth
+
+   .. include:: examples/example-70-preprocessor.rst
+
 Compat
 ------
 
diff --git a/test/example-70-preprocessor.c b/test/example-70-preprocessor.c
new file mode 100644
index 0000000..a8fe530
--- /dev/null
+++ b/test/example-70-preprocessor.c
@@ -0,0 +1,8 @@
+/**
+ * Answer to the Ultimate Question of Life, The Universe, and Everything.
+ */
+#ifdef DEEP_THOUGHT
+#define MEANING_OF_LIFE 42
+#else
+#error "Does not compute."
+#endif
diff --git a/test/example-70-preprocessor.options 
b/test/example-70-preprocessor.options
new file mode 100644
index 0000000..9319b0a
--- /dev/null
+++ b/test/example-70-preprocessor.options
@@ -0,0 +1 @@
+clang=-DDEEP_THOUGHT
diff --git a/test/example-70-preprocessor.rst b/test/example-70-preprocessor.rst
new file mode 100644
index 0000000..8ceccca
--- /dev/null
+++ b/test/example-70-preprocessor.rst
@@ -0,0 +1,5 @@
+
+.. c:macro:: MEANING_OF_LIFE
+
+   Answer to the Ultimate Question of Life, The Universe, and Everything.
+
-- 
2.20.1


Other related posts: