diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-02-13 03:09:07 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-02-13 03:09:07 +0300 |
commit | ba6cf3cdb6495db7f023a07cf0253c5970211a40 (patch) | |
tree | 8a1eb42fd81c31cd3231de197d41235bf70aa975 /source/blender | |
parent | 4d890f3778582da1b6a9ecc030d1c80079bc8f28 (diff) |
Cleanup: rename variable name for DNA utils
Rename 'elem_dna' to 'elem_full' to signify it has array/pointer chars.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/makesdna/intern/dna_genfile.c | 18 | ||||
-rw-r--r-- | source/blender/makesdna/intern/dna_utils.c | 80 | ||||
-rw-r--r-- | source/blender/makesdna/intern/dna_utils.h | 13 | ||||
-rw-r--r-- | source/blender/makesdna/intern/makesdna.c | 4 |
4 files changed, 64 insertions, 51 deletions
diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c index 6d4eab11c0f..957ce637167 100644 --- a/source/blender/makesdna/intern/dna_genfile.c +++ b/source/blender/makesdna/intern/dna_genfile.c @@ -1402,22 +1402,22 @@ static bool DNA_sdna_patch_struct_member_nr( BLI_assert(member_new != NULL); const short *sp = sdna->structs[struct_name_nr]; for (int member_iter = sp[1]; member_iter > 0; member_iter--, sp += 2) { - const char *member_dna_old = sdna->names[sp[1]]; - /* Start & end offsets in 'member_dna_old'. */ - uint member_dna_offset_start; - if (DNA_elem_id_match(member_old, member_old_len, member_dna_old, &member_dna_offset_start)) { + const char *elem_full_old = sdna->names[sp[1]]; + /* Start & end offsets in 'elem_full_old'. */ + uint elem_full_offset_start; + if (DNA_elem_id_match(member_old, member_old_len, elem_full_old, &elem_full_offset_start)) { if (sdna->mem_arena == NULL) { sdna->mem_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__); } - const int member_dna_old_len = strlen(member_dna_old); - const char *member_dna_new = DNA_elem_id_rename( + const int elem_full_old_len = strlen(elem_full_old); + const char *elem_full_new = DNA_elem_id_rename( sdna->mem_arena, member_old, member_old_len, member_new, member_new_len, - member_dna_old, member_dna_old_len, - member_dna_offset_start); + elem_full_old, elem_full_old_len, + elem_full_offset_start); - sdna->names[sp[1]] = member_dna_new; + sdna->names[sp[1]] = elem_full_new; return true; } } diff --git a/source/blender/makesdna/intern/dna_utils.c b/source/blender/makesdna/intern/dna_utils.c index f1a04eae7aa..8891c009718 100644 --- a/source/blender/makesdna/intern/dna_utils.c +++ b/source/blender/makesdna/intern/dna_utils.c @@ -86,22 +86,34 @@ static bool is_identifier(const char c) (c == '_')); } -uint DNA_elem_id_offset_start(const char *elem_dna) +uint DNA_elem_id_offset_start(const char *elem_full) { - uint elem_dna_offset = 0; - while (!is_identifier(elem_dna[elem_dna_offset])) { - elem_dna_offset++; + uint elem_full_offset = 0; + while (!is_identifier(elem_full[elem_full_offset])) { + elem_full_offset++; } - return elem_dna_offset; + return elem_full_offset; } -uint DNA_elem_id_offset_end(const char *elem_dna) +uint DNA_elem_id_offset_end(const char *elem_full) { - uint elem_dna_offset = 0; - while (is_identifier(elem_dna[elem_dna_offset])) { - elem_dna_offset++; + uint elem_full_offset = 0; + while (is_identifier(elem_full[elem_full_offset])) { + elem_full_offset++; } - return elem_dna_offset; + return elem_full_offset; +} + +/** + * \a elem_dst must be at least the size of \a elem_src. + */ +void DNA_elem_id_strip(char *elem_dst, const char *elem_src) +{ + const uint elem_src_offset = DNA_elem_id_offset_start(elem_src); + const char *elem_src_trim = elem_src + elem_src_offset; + const uint elem_src_trim_len = DNA_elem_id_offset_end(elem_src_trim); + memcpy(elem_dst, elem_src_trim, elem_src_trim_len); + elem_dst[elem_src_trim_len] = '\0'; } /** @@ -110,16 +122,16 @@ uint DNA_elem_id_offset_end(const char *elem_dna) */ bool DNA_elem_id_match( const char *elem_search, const int elem_search_len, - const char *elem_dna, - uint *r_elem_dna_offset) + const char *elem_full, + uint *r_elem_full_offset) { BLI_assert(strlen(elem_search) == elem_search_len); - const uint elem_dna_offset = DNA_elem_id_offset_start(elem_dna); - const char *elem_dna_trim = elem_dna + elem_dna_offset; - if (strncmp(elem_search, elem_dna_trim, elem_search_len) == 0) { - const char c = elem_dna_trim[elem_search_len]; + const uint elem_full_offset = DNA_elem_id_offset_start(elem_full); + const char *elem_full_trim = elem_full + elem_full_offset; + if (strncmp(elem_search, elem_full_trim, elem_search_len) == 0) { + const char c = elem_full_trim[elem_search_len]; if (c == '\0' || !is_identifier(c)) { - *r_elem_dna_offset = elem_dna_offset; + *r_elem_full_offset = elem_full_offset; return true; } } @@ -133,32 +145,32 @@ char *DNA_elem_id_rename( struct MemArena *mem_arena, const char *elem_src, const int elem_src_len, const char *elem_dst, const int elem_dst_len, - const char *elem_dna_src, const int elem_dna_src_len, - const uint elem_dna_offset_start) + const char *elem_full_src, const int elem_full_src_len, + const uint elem_full_offset_start) { BLI_assert(strlen(elem_src) == elem_src_len); BLI_assert(strlen(elem_dst) == elem_dst_len); - BLI_assert(strlen(elem_dna_src) == elem_dna_src_len); - BLI_assert(DNA_elem_id_offset_start(elem_dna_src) == elem_dna_offset_start); + BLI_assert(strlen(elem_full_src) == elem_full_src_len); + BLI_assert(DNA_elem_id_offset_start(elem_full_src) == elem_full_offset_start); UNUSED_VARS_NDEBUG(elem_src); - const int elem_final_len = (elem_dna_src_len - elem_src_len) + elem_dst_len; - char *elem_dna_dst = BLI_memarena_alloc(mem_arena, elem_final_len + 1); + const int elem_final_len = (elem_full_src_len - elem_src_len) + elem_dst_len; + char *elem_full_dst = BLI_memarena_alloc(mem_arena, elem_final_len + 1); uint i = 0; - if (elem_dna_offset_start != 0) { - memcpy(elem_dna_dst, elem_dna_src, elem_dna_offset_start); - i = elem_dna_offset_start; + if (elem_full_offset_start != 0) { + memcpy(elem_full_dst, elem_full_src, elem_full_offset_start); + i = elem_full_offset_start; } - memcpy(&elem_dna_dst[i], elem_dst, elem_dst_len + 1); + memcpy(&elem_full_dst[i], elem_dst, elem_dst_len + 1); i += elem_dst_len; - uint elem_dna_offset_end = elem_dna_offset_start + elem_src_len; - if (elem_dna_src[elem_dna_offset_end] != '\0') { - const int elem_dna_tail_len = (elem_dna_src_len - elem_dna_offset_end); - memcpy(&elem_dna_dst[i], &elem_dna_src[elem_dna_offset_end], elem_dna_tail_len + 1); - i += elem_dna_tail_len; + uint elem_full_offset_end = elem_full_offset_start + elem_src_len; + if (elem_full_src[elem_full_offset_end] != '\0') { + const int elem_full_tail_len = (elem_full_src_len - elem_full_offset_end); + memcpy(&elem_full_dst[i], &elem_full_src[elem_full_offset_end], elem_full_tail_len + 1); + i += elem_full_tail_len; } - BLI_assert((strlen(elem_dna_dst) == elem_final_len) && (i == elem_final_len)); - return elem_dna_dst; + BLI_assert((strlen(elem_full_dst) == elem_final_len) && (i == elem_final_len)); + return elem_full_dst; } /** \} */ diff --git a/source/blender/makesdna/intern/dna_utils.h b/source/blender/makesdna/intern/dna_utils.h index 38fce41440a..fc8e5a87547 100644 --- a/source/blender/makesdna/intern/dna_utils.h +++ b/source/blender/makesdna/intern/dna_utils.h @@ -24,17 +24,18 @@ struct MemArena; int DNA_elem_array_size(const char *str); -uint DNA_elem_id_offset_start(const char *elem_dna); -uint DNA_elem_id_offset_end(const char *elem_dna); +uint DNA_elem_id_offset_start(const char *elem_full); +uint DNA_elem_id_offset_end(const char *elem_full); +void DNA_elem_id_strip(char *elem_dst, const char *elem_src); bool DNA_elem_id_match( const char *elem_search, const int elem_search_len, - const char *elem_dna, - uint *r_elem_dna_offset); + const char *elem_full, + uint *r_elem_full_offset); char *DNA_elem_id_rename( struct MemArena *mem_arena, const char *elem_src, const int elem_src_len, const char *elem_dst, const int elem_dst_len, - const char *elem_dna_src, const int elem_dna_src_len, - const uint elem_dna_offset_start); + const char *elem_full_src, const int elem_full_src_len, + const uint elem_full_offset_start); #endif /* __DNA_UTILS_H__ */ diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c index e2616d91b27..d5a2afd8824 100644 --- a/source/blender/makesdna/intern/makesdna.c +++ b/source/blender/makesdna/intern/makesdna.c @@ -975,7 +975,7 @@ void printStructLengths(void) static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offsets) { - int len, i; + int i; const short *sp; /* str contains filenames. Since we now include paths, I stretched */ /* it a bit. Hope this is enough :) -nzc- */ @@ -1085,7 +1085,7 @@ static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offs } else { const char nil_bytes[4] = {0}; - int len_align; + int len, len_align; dna_write(file, "SDNA", 4); |