diff options
author | Nick Wellnhofer <wellnhofer@aevum.de> | 2015-01-23 17:04:14 +0100 |
---|---|---|
committer | Nick Wellnhofer <wellnhofer@aevum.de> | 2015-01-23 17:23:35 +0100 |
commit | 3248801a925449644071671dcd85e370303071b4 (patch) | |
tree | daf4bd900de49effe12e035f924e517d9716cd96 | |
parent | 96a4e04522584aab4ea1fe444f971bec935abc8a (diff) |
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.
-rw-r--r-- | api_test/main.c | 9 | ||||
-rw-r--r-- | man/man3/cmark.3 | 74 | ||||
-rw-r--r-- | src/cmark.c | 3 | ||||
-rw-r--r-- | src/cmark.h | 33 | ||||
-rw-r--r-- | src/main.c | 2 |
5 files changed, 103 insertions, 18 deletions
diff --git a/api_test/main.c b/api_test/main.c index af40a9f..d341246 100644 --- a/api_test/main.c +++ b/api_test/main.c @@ -53,6 +53,14 @@ static void test_continuation_byte(test_batch_runner *runner, const char *utf8); static void +version(test_batch_runner *runner) +{ + INT_EQ(runner, cmark_version, CMARK_VERSION, "cmark_version"); + STR_EQ(runner, cmark_version_string, CMARK_VERSION_STRING, + "cmark_version_string"); +} + +static void constructor(test_batch_runner *runner) { for (int i = 0; i < num_node_types; ++i) { @@ -666,6 +674,7 @@ int main() { int retval; test_batch_runner *runner = test_batch_runner_new(); + version(runner); constructor(runner); accessors(runner); node_check(runner); diff --git a/man/man3/cmark.3 b/man/man3/cmark.3 index f889521..f03a3ae 100644 --- a/man/man3/cmark.3 +++ b/man/man3/cmark.3 @@ -1,4 +1,4 @@ -.TH cmark 3 "January 20, 2015" "LOCAL" "Library Functions Manual" +.TH cmark 3 "January 23, 2015" "LOCAL" "Library Functions Manual" .SH NAME .PP @@ -10,18 +10,6 @@ DESCRIPTION Simple Interface .PP -.nf -\fC -.RS 0n -#define CMARK_VERSION "0.1" -.RE -\f[] -.fi - -.PP -Current version of library. - -.PP \fIchar *\f[] \fBcmark_markdown_to_html\f[](\fIconst char *text\f[], \fIint len\f[]) .PP @@ -532,6 +520,66 @@ Render \f[C]softbreak\f[] elements as hard line breaks. .PP Normalize tree by consolidating adjacent text nodes. +.SS +Version information + +.PP +.nf +\fC +.RS 0n +#define CMARK_VERSION 0x000100 +.RE +\f[] +.fi + +.PP +Macro containing the library version as integer for compile time +checks. +.IP \[bu] 2 +Bits 16\-23 contain the major version. +.IP \[bu] 2 +Bits 8\-15 contain the minor version. +.IP \[bu] 2 +Bits 0\-7 contain the patchlevel. +.PP +In hexadecimal format, the number 0x010203 represents version 1.2.3. + +.PP +.nf +\fC +.RS 0n +#define CMARK_VERSION_STRING "0.1.0" +.RE +\f[] +.fi + +.PP +Macro containing the library version string for compile time checks. + +.PP +.nf +\fC +.RS 0n +extern const int cmark_version; +.RE +\f[] +.fi + +.PP +The library version as integer for runtime checks. + +.PP +.nf +\fC +.RS 0n +extern const char cmark_version_string[]; +.RE +\f[] +.fi + +.PP +The library version string for runtime checks. + .SH AUTHORS .PP diff --git a/src/cmark.c b/src/cmark.c index 1d7a500..2ec9be9 100644 --- a/src/cmark.c +++ b/src/cmark.c @@ -6,6 +6,9 @@ #include "cmark.h" #include "buffer.h" +const int cmark_version = CMARK_VERSION; +const char cmark_version_string[] = CMARK_VERSION_STRING; + char *cmark_markdown_to_html(const char *text, int len) { cmark_node *doc; 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. @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) for (i = 1; i < argc; i++) { if (strcmp(argv[i], "--version") == 0) { - printf("cmark %s", CMARK_VERSION); + printf("cmark %s", CMARK_VERSION_STRING); printf(" - CommonMark converter (c) 2014 John MacFarlane\n"); exit(0); } else if (strcmp(argv[i], "--sourcepos") == 0) { |