diff options
author | David Robillard <d@drobilla.net> | 2021-01-01 18:02:52 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-01-01 18:59:14 +0100 |
commit | e359b144ba32139a8d62d34e9c10cdf494b8360b (patch) | |
tree | 8b74109140994c6a25adaa42ff774630a91a5c5e /src | |
parent | 87aca493cd6ad0ffc49a896c9f8342d52ad6aa96 (diff) | |
download | sord-e359b144ba32139a8d62d34e9c10cdf494b8360b.tar.gz sord-e359b144ba32139a8d62d34e9c10cdf494b8360b.tar.bz2 sord-e359b144ba32139a8d62d34e9c10cdf494b8360b.zip |
Remove the need for a generated configuration header
Diffstat (limited to 'src')
-rw-r--r-- | src/sord_config.h | 61 | ||||
-rw-r--r-- | src/sord_validate.c | 11 |
2 files changed, 67 insertions, 5 deletions
diff --git a/src/sord_config.h b/src/sord_config.h new file mode 100644 index 0000000..f4b54c1 --- /dev/null +++ b/src/sord_config.h @@ -0,0 +1,61 @@ +/* + Copyright 2021 David Robillard <http://drobilla.net> + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +/* + Configuration header that defines reasonable defaults at compile time. + + This allows compile-time configuration from the command line (typically via + the build system) while still allowing the source to be built without any + configuration. The build system can define SORD_NO_DEFAULT_CONFIG to disable + defaults, in which case it must define things like HAVE_FEATURE to enable + features. The design here ensures that compiler warnings or + include-what-you-use will catch any mistakes. +*/ + +#ifndef SORD_CONFIG_H +#define SORD_CONFIG_H + +// Define version unconditionally so a warning will catch a mismatch +#define SORD_VERSION "0.16.7" + +#if !defined(SORD_NO_DEFAULT_CONFIG) + +// The validator uses PCRE for literal pattern matching +# ifndef HAVE_PCRE +# ifdef __has_include +# if __has_include(<pcre.h>) +# define HAVE_PCRE 1 +# endif +# endif +# endif + +#endif // !defined(SORD_NO_DEFAULT_CONFIG) + +/* + Make corresponding USE_FEATURE defines based on the HAVE_FEATURE defines from + above or the command line. The code checks for these using #if (not #ifdef), + so there will be an undefined warning if it checks for an unknown feature, + and this header is always required by any code that checks for features, even + if the build system defines them all. +*/ + +#ifdef HAVE_PCRE +# define USE_PCRE 1 +#else +# define USE_PCRE 0 +#endif + +#endif // SORD_CONFIG_H diff --git a/src/sord_validate.c b/src/sord_validate.c index 0acb0a4..fffc6a1 100644 --- a/src/sord_validate.c +++ b/src/sord_validate.c @@ -1,5 +1,5 @@ /* - Copyright 2012-2017 David Robillard <http://drobilla.net> + Copyright 2012-2021 David Robillard <http://drobilla.net> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -21,9 +21,10 @@ #include "sord/sord.h" #include "sord_config.h" -#ifdef HAVE_PCRE +#if USE_PCRE # include <pcre.h> #endif + #ifdef _WIN32 # include <windows.h> #endif @@ -190,7 +191,7 @@ is_descendant_of(SordModel* model, static bool regexp_match(const uint8_t* pat, const char* str) { -#ifdef HAVE_PCRE +#if USE_PCRE // Append a $ to the pattern so we only match if the entire string matches const size_t len = strlen((const char*)pat); char* const regx = (char*)malloc(len + 2); @@ -211,7 +212,7 @@ regexp_match(const uint8_t* pat, const char* str) const bool ret = pcre_exec(re, NULL, str, strlen(str), 0, 0, NULL, 0) >= 0; pcre_free(re); return ret; -#endif // HAVE_PCRE +#endif // USE_PCRE return true; } @@ -785,7 +786,7 @@ main(int argc, char** argv) URI(xsd, pattern); URI(xsd, string); -#ifndef HAVE_PCRE +#if !USE_PCRE fprintf(stderr, "warning: Built without PCRE, datatypes not checked.\n"); #endif |