From 3248801a925449644071671dcd85e370303071b4 Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer <wellnhofer@aevum.de>
Date: Fri, 23 Jan 2015 17:04:14 +0100
Subject: Improve version information

Add version number and string as macros and symbols. Version numbers can
be easily compared, for example in the C preprocessor:

    #include <cmark.h>

    #if CMARK_VERSION < 0x020200
    #error Requires libcmark 2.2.0 or higher
    #endif

Storing the version in a global variable allows to check the library
version at runtime. For example:

    if (CMARK_VERSION != cmark_version) {
        warn("Compiled against libcmark %s, but using %s",
             CMARK_VERSION_STRING, cmark_version_string);
    }

The version should be updated whenever the public API is changed.
---
 src/cmark.h | 33 +++++++++++++++++++++++++++++----
 1 file changed, 29 insertions(+), 4 deletions(-)

(limited to 'src/cmark.h')

diff --git a/src/cmark.h b/src/cmark.h
index 8177fa8..faa5150 100644
--- a/src/cmark.h
+++ b/src/cmark.h
@@ -18,10 +18,6 @@ extern "C" {
  * ## Simple Interface
  */
 
-/** Current version of library.
- */
-#define CMARK_VERSION "0.1"
-
 /** Convert 'text' (assumed to be a UTF-8 encoded string with length
  * 'len' from CommonMark Markdown to HTML, returning a null-terminated,
  * UTF-8-encoded string.
@@ -499,6 +495,35 @@ char *cmark_render_man(cmark_node *root, long options);
  */
 #define CMARK_OPT_NORMALIZE 4
 
+/**
+ * ## Version information
+ */
+
+/** Macro containing the library version as integer for compile time
+ * checks.
+ *
+ * * Bits 16-23 contain the major version.
+ * * Bits 8-15 contain the minor version.
+ * * Bits 0-7 contain the patchlevel.
+ *
+ * In hexadecimal format, the number 0x010203 represents version 1.2.3.
+ */
+#define CMARK_VERSION 0x000100
+
+/** Macro containing the library version string for compile time checks.
+ */
+#define CMARK_VERSION_STRING "0.1.0"
+
+/** The library version as integer for runtime checks.
+ */
+CMARK_EXPORT
+extern const int cmark_version;
+
+/** The library version string for runtime checks.
+ */
+CMARK_EXPORT
+extern const char cmark_version_string[];
+
 /** # AUTHORS
  *
  * John MacFarlane, Vicent Marti,  Kārlis Gaņģis, Nick Wellnhofer.
-- 
cgit v1.2.3