From c11a317ee15a2e4405cad550e54bd6cf552cb546 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 28 Mar 2019 09:49:10 +1100 Subject: Cleanup: style, use braces for makesdna, datatoc --- source/blender/makesdna/intern/dna_genfile.c | 96 +++++++++++++++++++--------- source/blender/makesdna/intern/makesdna.c | 46 +++++++++---- 2 files changed, 100 insertions(+), 42 deletions(-) (limited to 'source/blender/makesdna/intern') diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c index f53651621c2..60e9b69923d 100644 --- a/source/blender/makesdna/intern/dna_genfile.c +++ b/source/blender/makesdna/intern/dna_genfile.c @@ -345,7 +345,9 @@ static bool init_structDNA( gravity_fix = nr; } } - while (*cp) cp++; + while (*cp) { + cp++; + } cp++; } @@ -373,7 +375,9 @@ static bool init_structDNA( for (int nr = 0; nr < sdna->nr_types; 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++; + while (*cp) { + cp++; + } cp++; } @@ -396,7 +400,10 @@ static bool init_structDNA( *r_error_message = "TLEN error in SDNA file"; return false; } - if (sdna->nr_types & 1) sp++; /* prevent BUS error */ + /* prevent BUS error */ + if (sdna->nr_types & 1) { + sp++; + } /* Struct array ('STRC') */ data = (int *)sp; @@ -445,8 +452,9 @@ static bool init_structDNA( if (gravity_fix > -1) { for (int nr = 0; nr < sdna->nr_structs; nr++) { sp = sdna->structs[nr]; - if (strcmp(sdna->types[sp[0]], "ClothSimSettings") == 0) + if (strcmp(sdna->types[sp[0]], "ClothSimSettings") == 0) { sp[10] = SDNA_TYPE_VOID; + } } } } @@ -646,15 +654,21 @@ 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) break; + if (strcmp(str1, str2) != 0) { + break; + } str1 = newsdna->names[sp_new[1]]; str2 = oldsdna->names[sp_old[1]]; - if (strcmp(str1, str2) != 0) break; + if (strcmp(str1, str2) != 0) { + break; + } /* same type and same name, now pointersize */ if (ispointer(str1)) { - if (oldsdna->pointer_size != newsdna->pointer_size) break; + if (oldsdna->pointer_size != newsdna->pointer_size) { + break; + } } b--; @@ -703,17 +717,17 @@ const char *DNA_struct_get_compareflags(const SDNA *oldsdna, const SDNA *newsdna */ static eSDNA_Type sdna_type_nr(const char *dna_type) { - if ((strcmp(dna_type, "char") == 0) || (strcmp(dna_type, "const char") == 0)) return SDNA_TYPE_CHAR; - else if ((strcmp(dna_type, "uchar") == 0) || (strcmp(dna_type, "unsigned char") == 0)) return SDNA_TYPE_UCHAR; - else if ( strcmp(dna_type, "short") == 0) return SDNA_TYPE_SHORT; - else if ((strcmp(dna_type, "ushort") == 0) || (strcmp(dna_type, "unsigned short") == 0)) return SDNA_TYPE_USHORT; - else if ( strcmp(dna_type, "int") == 0) return SDNA_TYPE_INT; - else if ( strcmp(dna_type, "float") == 0) return SDNA_TYPE_FLOAT; - else if ( strcmp(dna_type, "double") == 0) return SDNA_TYPE_DOUBLE; - else if ( strcmp(dna_type, "int64_t") == 0) return SDNA_TYPE_INT64; - else if ( strcmp(dna_type, "uint64_t") == 0) return SDNA_TYPE_UINT64; + if ((strcmp(dna_type, "char") == 0) || (strcmp(dna_type, "const char") == 0)) { return SDNA_TYPE_CHAR; } + else if ((strcmp(dna_type, "uchar") == 0) || (strcmp(dna_type, "unsigned char") == 0)) { return SDNA_TYPE_UCHAR; } + else if ( strcmp(dna_type, "short") == 0) { return SDNA_TYPE_SHORT; } + else if ((strcmp(dna_type, "ushort") == 0) || (strcmp(dna_type, "unsigned short") == 0)) { return SDNA_TYPE_USHORT; } + else if ( strcmp(dna_type, "int") == 0) { return SDNA_TYPE_INT; } + else if ( strcmp(dna_type, "float") == 0) { return SDNA_TYPE_FLOAT; } + else if ( strcmp(dna_type, "double") == 0) { return SDNA_TYPE_DOUBLE; } + else if ( strcmp(dna_type, "int64_t") == 0) { return SDNA_TYPE_INT64; } + else if ( strcmp(dna_type, "uint64_t") == 0) { return SDNA_TYPE_UINT64; } /* invalid! */ - else return -1; + else { return -1; } } /** @@ -780,10 +794,14 @@ static void cast_elem( case SDNA_TYPE_INT: *( (int *)curdata) = val; break; case SDNA_TYPE_FLOAT: - if (otypenr < 2) val /= 255; + if (otypenr < 2) { + val /= 255; + } *( (float *)curdata) = val; break; case SDNA_TYPE_DOUBLE: - if (otypenr < 2) val /= 255; + if (otypenr < 2) { + val /= 255; + } *( (double *)curdata) = val; break; case SDNA_TYPE_INT64: *( (int64_t *)curdata) = val; break; @@ -848,9 +866,15 @@ static int elem_strcmp(const char *name, const char *oname) int a = 0; while (1) { - if (name[a] != oname[a]) return 1; - if (name[a] == '[' || oname[a] == '[') break; - if (name[a] == 0 || oname[a] == 0) break; + if (name[a] != oname[a]) { + return 1; + } + if (name[a] == '[' || oname[a] == '[') { + break; + } + if (name[a] == 0 || oname[a] == 0) { + break; + } a++; } return 0; @@ -931,7 +955,9 @@ static const char *find_elem( if (elem_strcmp(name, oname) == 0) { /* name equal */ if (strcmp(type, otype) == 0) { /* type equal */ - if (sppo) *sppo = old; + if (sppo) { + *sppo = old; + } return olddata; } @@ -983,7 +1009,9 @@ static void reconstruct_elem( while (*cp && *cp != '[') { cp++; countpos++; } - if (*cp != '[') countpos = 0; + if (*cp != '[') { + countpos = 0; + } /* in old is the old struct */ elemcount = old[1]; @@ -1087,8 +1115,12 @@ static void reconstruct_struct( unsigned int cursdna_index_last = UINT_MAX; - if (oldSDNAnr == -1) return; - if (curSDNAnr == -1) return; + if (oldSDNAnr == -1) { + return; + } + if (curSDNAnr == -1) { + return; + } if (compflags[oldSDNAnr] == SDNA_CMP_EQUAL) { /* if recursive: test for equal */ @@ -1146,7 +1178,9 @@ static void reconstruct_struct( /* new struct array larger than old */ mulo--; - if (mulo <= 0) break; + if (mulo <= 0) { + break; + } } } else { @@ -1179,7 +1213,9 @@ void DNA_struct_switch_endian(const SDNA *oldsdna, int oldSDNAnr, char *data) const char *type, *name; unsigned int oldsdna_index_last = UINT_MAX; - if (oldSDNAnr == -1) return; + if (oldSDNAnr == -1) { + return; + } firststructtypenr = *(oldsdna->structs[0]); spo = spc = oldsdna->structs[oldSDNAnr]; @@ -1227,7 +1263,9 @@ 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) skip = true; + if (strcmp(name, "blocktype") == 0) { + skip = true; + } } if (skip == false) { diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c index edf15c5fe39..4e16aec5fdc 100644 --- a/source/blender/makesdna/intern/makesdna.c +++ b/source/blender/makesdna/intern/makesdna.c @@ -400,7 +400,9 @@ static int add_name(const char *str) additional_slen_offset = 0; - if (str[0] == 0 /* || (str[1] == 0) */) return -1; + if (str[0] == 0 /* || (str[1] == 0) */) { + return -1; + } if (str[0] == '(' && str[1] == '*') { /* we handle function pointer and special array cases here, e.g. @@ -437,8 +439,9 @@ static int add_name(const char *str) if (str[j] == 0) { DEBUG_PRINTF(3, "offsetting for multidim array pointer\n"); } - else + else { printf("Error during tokening multidim array pointer\n"); + } } else if (str[j] == 0) { DEBUG_PRINTF(3, "offsetting for space\n"); @@ -713,9 +716,14 @@ static int convert_include(const char *filename) skip_struct = false; } else { - if (md[-1] == ' ') md[-1] = 0; + if (md[-1] == ' ') { + md[-1] = 0; + } md1 = md - 2; - while (*md1 != 32) md1--; /* to beginning of word */ + while (*md1 != 32) { + /* to beginning of word */ + md1--; + } md1++; /* we've got a struct name when... */ @@ -735,22 +743,28 @@ static int convert_include(const char *filename) /* first lets make it all nice strings */ md1 = md + 1; while (*md1 != '}') { - if (md1 > mainend) break; + if (md1 > mainend) { + break; + } - if (*md1 == ',' || *md1 == ' ') *md1 = 0; + if (*md1 == ',' || *md1 == ' ') { + *md1 = 0; + } md1++; } /* read types and names until first character that is not '}' */ md1 = md + 1; while (*md1 != '}') { - if (md1 > mainend) break; + if (md1 > mainend) { + break; + } /* skip when it says 'struct' or 'unsigned' or 'const' */ if (*md1) { - if (strncmp(md1, "struct", 6) == 0) md1 += 7; - if (strncmp(md1, "unsigned", 8) == 0) md1 += 9; - if (strncmp(md1, "const", 5) == 0) md1 += 6; + if (strncmp(md1, "struct", 6) == 0) { md1 += 7; } + if (strncmp(md1, "unsigned", 8) == 0) { md1 += 9; } + if (strncmp(md1, "const", 5) == 0) { md1 += 6; } /* we've got a type! */ type = add_type(md1, 0); @@ -766,7 +780,9 @@ static int convert_include(const char *filename) /* read until ';' */ while (*md1 != ';') { - if (md1 > mainend) break; + if (md1 > mainend) { + break; + } if (*md1) { /* We've got a name. slen needs @@ -1004,7 +1020,9 @@ static int calculate_struct_sizes(int firststruct) } } - if (unknown == lastunknown) break; + if (unknown == lastunknown) { + break; + } } if (unknown) { @@ -1249,7 +1267,9 @@ static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offs dna_write(file, "TLEN", 4); len = 2 * nr_types; - if (nr_types & 1) len += 2; + if (nr_types & 1) { + len += 2; + } dna_write(file, types_size_native, len); /* WRITE STRUCTS */ -- cgit v1.2.3