diff options
author | Hans Goudey <h.goudey@me.com> | 2022-08-31 16:07:51 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-08-31 16:15:09 +0300 |
commit | 3ecb21346248014aff621ec3b97ccbc1e7774653 (patch) | |
tree | b571a51b93d61efc01bf8a75a74ecade8e463d16 /source/blender/makesdna/intern/makesdna.c | |
parent | b5af7f967e6d5d2e7432d6efa2f47050a5bfc576 (diff) | |
parent | 773241add9d876aa0b4ba011745208f61b53a4e2 (diff) |
Merge branch 'master' into refactor-mesh-material-index-genericrefactor-mesh-material-index-generic
Diffstat (limited to 'source/blender/makesdna/intern/makesdna.c')
-rw-r--r-- | source/blender/makesdna/intern/makesdna.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c index 806513009be..36abe970b31 100644 --- a/source/blender/makesdna/intern/makesdna.c +++ b/source/blender/makesdna/intern/makesdna.c @@ -506,6 +506,54 @@ static short *add_struct(int namecode) return sp; } +/* Copied from `BLI_str_startswith` string.c + * to avoid complicating the compilation process of makesdna. */ +static bool str_startswith(const char *__restrict str, const char *__restrict start) +{ + for (; *str && *start; str++, start++) { + if (*str != *start) { + return false; + } + } + + return (*start == '\0'); +} + +/** + * Check if `str` is a preprocessor string that starts with `start`. + * The `start` doesn't need the `#` prefix. + * `ifdef VALUE` will match `#ifdef VALUE` as well as `# ifdef VALUE`. + */ +static bool match_preproc_prefix(const char *__restrict str, const char *__restrict start) +{ + if (*str != '#') { + return false; + } + str++; + while (*str == ' ') { + str++; + } + return str_startswith(str, start); +} + +/** + * \return The point in `str` that starts with `start` or NULL when not found. + * + */ +static char *match_preproc_strstr(char *__restrict str, const char *__restrict start) +{ + while ((str = strchr(str, '#'))) { + str++; + while (*str == ' ') { + str++; + } + if (str_startswith(str, start)) { + return str; + } + } + return NULL; +} + static int preprocess_include(char *maindata, const int maindata_len) { /* NOTE: len + 1, last character is a dummy to prevent @@ -533,6 +581,10 @@ static int preprocess_include(char *maindata, const int maindata_len) cp++; } + /* No need for leading '#' character. */ + const char *cpp_block_start = "ifdef __cplusplus"; + const char *cpp_block_end = "endif"; + /* data from temp copy to maindata, remove comments and double spaces */ cp = temp; char *md = maindata; @@ -577,6 +629,18 @@ static int preprocess_include(char *maindata, const int maindata_len) skip_until_closing_brace = false; } } + else if (match_preproc_prefix(cp, cpp_block_start)) { + char *end_ptr = match_preproc_strstr(cp, cpp_block_end); + + if (end_ptr == NULL) { + fprintf(stderr, "Error: '%s' block must end with '%s'\n", cpp_block_start, cpp_block_end); + } + else { + const int skip_offset = end_ptr - cp + strlen(cpp_block_end); + a -= skip_offset; + cp += skip_offset; + } + } else { md[0] = cp[0]; md++; |