diff options
Diffstat (limited to 'source/blender/makesdna/intern/dna_genfile.c')
-rw-r--r-- | source/blender/makesdna/intern/dna_genfile.c | 275 |
1 files changed, 136 insertions, 139 deletions
diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c index 3d95eba4aed..8ad0271f355 100644 --- a/source/blender/makesdna/intern/dna_genfile.c +++ b/source/blender/makesdna/intern/dna_genfile.c @@ -356,141 +356,140 @@ static bool init_structDNA(SDNA *sdna, bool do_endian_swap, const char **r_error *r_error_message = "SDNA error in SDNA file"; return false; } - else { - const char *cp; - data++; - /* Names array ('NAME') */ - if (*data == MAKE_ID('N', 'A', 'M', 'E')) { - data++; + const char *cp; - sdna->names_len = *data; - if (do_endian_swap) { - BLI_endian_switch_int32(&sdna->names_len); - } - sdna->names_len_alloc = sdna->names_len; + data++; + /* Names array ('NAME') */ + if (*data == MAKE_ID('N', 'A', 'M', 'E')) { + data++; - data++; - sdna->names = MEM_callocN(sizeof(void *) * sdna->names_len, "sdnanames"); - } - else { - *r_error_message = "NAME error in SDNA file"; - return false; + sdna->names_len = *data; + if (do_endian_swap) { + BLI_endian_switch_int32(&sdna->names_len); } + sdna->names_len_alloc = sdna->names_len; - cp = (char *)data; - for (int nr = 0; nr < sdna->names_len; nr++) { - sdna->names[nr] = cp; - - /* "float gravity [3]" was parsed wrong giving both "gravity" and - * "[3]" members. we rename "[3]", and later set the type of - * "gravity" to "void" so the offsets work out correct */ - if (*cp == '[' && strcmp(cp, "[3]") == 0) { - if (nr && strcmp(sdna->names[nr - 1], "Cvi") == 0) { - sdna->names[nr] = "gravity[3]"; - gravity_fix = nr; - } - } - while (*cp) { - cp++; + data++; + sdna->names = MEM_callocN(sizeof(void *) * sdna->names_len, "sdnanames"); + } + else { + *r_error_message = "NAME error in SDNA file"; + return false; + } + + cp = (char *)data; + for (int nr = 0; nr < sdna->names_len; nr++) { + sdna->names[nr] = cp; + + /* "float gravity [3]" was parsed wrong giving both "gravity" and + * "[3]" members. we rename "[3]", and later set the type of + * "gravity" to "void" so the offsets work out correct */ + if (*cp == '[' && STREQ(cp, "[3]")) { + if (nr && STREQ(sdna->names[nr - 1], "Cvi")) { + sdna->names[nr] = "gravity[3]"; + gravity_fix = nr; } + } + while (*cp) { cp++; } + cp++; + } - cp = pad_up_4(cp); - - /* Type names array ('TYPE') */ - data = (int *)cp; - if (*data == MAKE_ID('T', 'Y', 'P', 'E')) { - data++; + cp = pad_up_4(cp); - sdna->types_len = *data; - if (do_endian_swap) { - BLI_endian_switch_int32(&sdna->types_len); - } + /* Type names array ('TYPE') */ + data = (int *)cp; + if (*data == MAKE_ID('T', 'Y', 'P', 'E')) { + data++; - data++; - sdna->types = MEM_callocN(sizeof(void *) * sdna->types_len, "sdnatypes"); - } - else { - *r_error_message = "TYPE error in SDNA file"; - return false; + sdna->types_len = *data; + if (do_endian_swap) { + BLI_endian_switch_int32(&sdna->types_len); } - cp = (char *)data; - for (int nr = 0; nr < sdna->types_len; nr++) { - /* WARNING! See: DNA_struct_rename_legacy_hack_static_from_alias docs. */ - sdna->types[nr] = DNA_struct_rename_legacy_hack_static_from_alias(cp); - while (*cp) { - cp++; - } + data++; + sdna->types = MEM_callocN(sizeof(void *) * sdna->types_len, "sdnatypes"); + } + else { + *r_error_message = "TYPE error in SDNA file"; + return false; + } + + cp = (char *)data; + for (int nr = 0; nr < sdna->types_len; nr++) { + /* WARNING! See: DNA_struct_rename_legacy_hack_static_from_alias docs. */ + sdna->types[nr] = DNA_struct_rename_legacy_hack_static_from_alias(cp); + while (*cp) { cp++; } + cp++; + } - cp = pad_up_4(cp); - - /* Type lengths array ('TLEN') */ - data = (int *)cp; - if (*data == MAKE_ID('T', 'L', 'E', 'N')) { - data++; - sp = (short *)data; - sdna->types_size = sp; + cp = pad_up_4(cp); - if (do_endian_swap) { - BLI_endian_switch_int16_array(sp, sdna->types_len); - } + /* Type lengths array ('TLEN') */ + data = (int *)cp; + if (*data == MAKE_ID('T', 'L', 'E', 'N')) { + data++; + sp = (short *)data; + sdna->types_size = sp; - sp += sdna->types_len; - } - else { - *r_error_message = "TLEN error in SDNA file"; - return false; - } - /* prevent BUS error */ - if (sdna->types_len & 1) { - sp++; + if (do_endian_swap) { + BLI_endian_switch_int16_array(sp, sdna->types_len); } - /* Struct array ('STRC') */ - data = (int *)sp; - if (*data == MAKE_ID('S', 'T', 'R', 'C')) { - data++; + sp += sdna->types_len; + } + else { + *r_error_message = "TLEN error in SDNA file"; + return false; + } + /* prevent BUS error */ + if (sdna->types_len & 1) { + sp++; + } - sdna->structs_len = *data; - if (do_endian_swap) { - BLI_endian_switch_int32(&sdna->structs_len); - } + /* Struct array ('STRC') */ + data = (int *)sp; + if (*data == MAKE_ID('S', 'T', 'R', 'C')) { + data++; - data++; - sdna->structs = MEM_callocN(sizeof(void *) * sdna->structs_len, "sdnastrcs"); - } - else { - *r_error_message = "STRC error in SDNA file"; - return false; + sdna->structs_len = *data; + if (do_endian_swap) { + BLI_endian_switch_int32(&sdna->structs_len); } - sp = (short *)data; - for (int nr = 0; nr < sdna->structs_len; nr++) { - sdna->structs[nr] = sp; + data++; + sdna->structs = MEM_callocN(sizeof(void *) * sdna->structs_len, "sdnastrcs"); + } + else { + *r_error_message = "STRC error in SDNA file"; + return false; + } + + sp = (short *)data; + for (int nr = 0; nr < sdna->structs_len; nr++) { + sdna->structs[nr] = sp; - if (do_endian_swap) { - short a; + if (do_endian_swap) { + short a; + BLI_endian_switch_int16(&sp[0]); + BLI_endian_switch_int16(&sp[1]); + + a = sp[1]; + sp += 2; + while (a--) { BLI_endian_switch_int16(&sp[0]); BLI_endian_switch_int16(&sp[1]); - - a = sp[1]; sp += 2; - while (a--) { - BLI_endian_switch_int16(&sp[0]); - BLI_endian_switch_int16(&sp[1]); - sp += 2; - } - } - else { - sp += 2 * sp[1] + 2; } } + else { + sp += 2 * sp[1] + 2; + } } { @@ -498,7 +497,7 @@ static bool init_structDNA(SDNA *sdna, bool do_endian_swap, const char **r_error if (gravity_fix > -1) { for (int nr = 0; nr < sdna->structs_len; nr++) { sp = sdna->structs[nr]; - if (strcmp(sdna->types[sp[0]], "ClothSimSettings") == 0) { + if (STREQ(sdna->types[sp[0]], "ClothSimSettings")) { sp[10] = SDNA_TYPE_VOID; } } @@ -578,16 +577,15 @@ SDNA *DNA_sdna_from_data(const void *data, if (init_structDNA(sdna, do_endian_swap, &error_message)) { return sdna; } + + if (r_error_message == NULL) { + fprintf(stderr, "Error decoding blend file SDNA: %s\n", error_message); + } else { - if (r_error_message == NULL) { - fprintf(stderr, "Error decoding blend file SDNA: %s\n", error_message); - } - else { - *r_error_message = error_message; - } - DNA_sdna_free(sdna); - return NULL; + *r_error_message = error_message; } + DNA_sdna_free(sdna); + return NULL; } /** @@ -700,13 +698,13 @@ const char *DNA_struct_get_compareflags(const SDNA *oldsdna, const SDNA *newsdna while (b > 0) { str1 = newsdna->types[sp_new[0]]; str2 = oldsdna->types[sp_old[0]]; - if (strcmp(str1, str2) != 0) { + if (!STREQ(str1, str2)) { break; } str1 = newsdna->names[sp_new[1]]; str2 = oldsdna->names[sp_old[1]]; - if (strcmp(str1, str2) != 0) { + if (!STREQ(str1, str2)) { break; } @@ -764,34 +762,33 @@ static eSDNA_Type sdna_type_nr(const char *dna_type) if (STR_ELEM(dna_type, "char", "const char")) { return SDNA_TYPE_CHAR; } - else if (STR_ELEM(dna_type, "uchar", "unsigned char")) { + if (STR_ELEM(dna_type, "uchar", "unsigned char")) { return SDNA_TYPE_UCHAR; } - else if (STR_ELEM(dna_type, "short")) { + if (STR_ELEM(dna_type, "short")) { return SDNA_TYPE_SHORT; } - else if (STR_ELEM(dna_type, "ushort", "unsigned short")) { + if (STR_ELEM(dna_type, "ushort", "unsigned short")) { return SDNA_TYPE_USHORT; } - else if (STR_ELEM(dna_type, "int")) { + if (STR_ELEM(dna_type, "int")) { return SDNA_TYPE_INT; } - else if (STR_ELEM(dna_type, "float")) { + if (STR_ELEM(dna_type, "float")) { return SDNA_TYPE_FLOAT; } - else if (STR_ELEM(dna_type, "double")) { + if (STR_ELEM(dna_type, "double")) { return SDNA_TYPE_DOUBLE; } - else if (STR_ELEM(dna_type, "int64_t")) { + if (STR_ELEM(dna_type, "int64_t")) { return SDNA_TYPE_INT64; } - else if (STR_ELEM(dna_type, "uint64_t")) { + if (STR_ELEM(dna_type, "uint64_t")) { return SDNA_TYPE_UINT64; } /* invalid! */ - else { - return -1; - } + + return -1; } /** @@ -940,13 +937,13 @@ static void cast_pointer( /** * Equality test on name and oname excluding any array-size suffix. */ -static int elem_strcmp(const char *name, const char *oname) +static bool elem_streq(const char *name, const char *oname) { int a = 0; while (1) { if (name[a] != oname[a]) { - return 1; + return false; } if (name[a] == '[' || oname[a] == '[') { break; @@ -956,7 +953,7 @@ static int elem_strcmp(const char *name, const char *oname) } a++; } - return 0; + return true; } /** @@ -987,8 +984,8 @@ static bool elem_exists_impl( otype = types[old[0]]; oname = names[old[1]]; - if (elem_strcmp(name, oname) == 0) { /* name equal */ - return strcmp(type, otype) == 0; /* type equal */ + if (elem_streq(name, oname)) { /* name equal */ + return STREQ(type, otype); /* type equal */ } } return false; @@ -1063,8 +1060,8 @@ static const char *find_elem(const SDNA *sdna, len = DNA_elem_size_nr(sdna, old[0], old[1]); - if (elem_strcmp(name, oname) == 0) { /* name equal */ - if (strcmp(type, otype) == 0) { /* type equal */ + if (elem_streq(name, oname)) { /* name equal */ + if (STREQ(type, otype)) { /* type equal */ if (sppo) { *sppo = old; } @@ -1132,7 +1129,7 @@ static void reconstruct_elem(const SDNA *newsdna, oname = oldsdna->names[old[1]]; len = DNA_elem_size_nr(oldsdna, old[0], old[1]); - if (strcmp(name, oname) == 0) { /* name equal */ + if (STREQ(name, oname)) { /* name equal */ if (ispointer(name)) { /* pointer of functionpointer afhandelen */ cast_pointer(newsdna->pointer_size, @@ -1141,7 +1138,7 @@ static void reconstruct_elem(const SDNA *newsdna, curdata, olddata); } - else if (strcmp(type, otype) == 0) { /* type equal */ + else if (STREQ(type, otype)) { /* type equal */ memcpy(curdata, olddata, len); } else { @@ -1150,7 +1147,7 @@ static void reconstruct_elem(const SDNA *newsdna, return; } - else if (countpos != 0) { /* name is an array */ + if (countpos != 0) { /* name is an array */ if (oname[countpos] == '[' && strncmp(name, oname, countpos) == 0) { /* basis equal */ const int new_name_array_len = newsdna->names_array_len[new_name_nr]; @@ -1161,7 +1158,7 @@ static void reconstruct_elem(const SDNA *newsdna, cast_pointer( newsdna->pointer_size, oldsdna->pointer_size, min_name_array_len, curdata, olddata); } - else if (strcmp(type, otype) == 0) { /* type equal */ + else if (STREQ(type, otype)) { /* type equal */ /* size of single old array element */ mul = len / old_name_array_len; /* smaller of sizes of old and new arrays */ @@ -1169,7 +1166,7 @@ static void reconstruct_elem(const SDNA *newsdna, memcpy(curdata, olddata, mul); - if (old_name_array_len > new_name_array_len && strcmp(type, "char") == 0) { + if (old_name_array_len > new_name_array_len && STREQ(type, "char")) { /* string had to be truncated, ensure it's still null-terminated */ curdata[mul - 1] = '\0'; } @@ -1368,7 +1365,7 @@ void DNA_struct_switch_endian(const SDNA *oldsdna, int oldSDNAnr, char *data) /* exception: variable called blocktype: derived from ID_ */ bool skip = false; if (name[0] == 'b' && name[1] == 'l') { - if (strcmp(name, "blocktype") == 0) { + if (STREQ(name, "blocktype")) { skip = true; } } |