diff options
Diffstat (limited to 'source/blender/makesdna')
-rw-r--r-- | source/blender/makesdna/DNA_ID.h | 6 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_meshdata_types.h | 6 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_modifier_types.h | 10 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_movieclip_types.h | 2 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_node_types.h | 78 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_scene_types.h | 5 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_texture_types.h | 3 | ||||
-rw-r--r-- | source/blender/makesdna/intern/dna_genfile.c | 790 | ||||
-rw-r--r-- | source/blender/makesdna/intern/makesdna.c | 494 |
9 files changed, 735 insertions, 659 deletions
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h index 2404459889c..814b1d18876 100644 --- a/source/blender/makesdna/DNA_ID.h +++ b/source/blender/makesdna/DNA_ID.h @@ -226,10 +226,14 @@ typedef struct PreviewImage { #define ID_BLEND_PATH(_bmain, _id) ((_id)->lib ? (_id)->lib->filepath : (_bmain)->name) #ifdef GS -#undef GS +# undef GS #endif #define GS(a) (*((short *)(a))) +#define ID_NEW(a) if ( (a) && (a)->id.newid ) (a) = (void *)(a)->id.newid +#define ID_NEW_US(a) if ( (a)->id.newid) { (a) = (void *)(a)->id.newid; (a)->id.us++; } +#define ID_NEW_US2(a) if (((ID *)a)->newid) { (a) = ((ID *)a)->newid; ((ID *)a)->us++; } + /* id->flag: set frist 8 bits always at zero while reading */ #define LIB_LOCAL 0 #define LIB_EXTERN 1 diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h index b0a1d23f166..70e9cf04b18 100644 --- a/source/blender/makesdna/DNA_meshdata_types.h +++ b/source/blender/makesdna/DNA_meshdata_types.h @@ -189,9 +189,9 @@ typedef struct MDisps { float (*disps)[3]; /* Used for hiding parts of a multires mesh. Essentially the multires - equivalent of MVert.flag's ME_HIDE bit. - - This is a bitmap, keep in sync with type used in BLI_bitmap.h */ + * equivalent of MVert.flag's ME_HIDE bit. + * + * This is a bitmap, keep in sync with type used in BLI_bitmap.h */ unsigned int *hidden; } MDisps; diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index 30280e95646..971ce613edc 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -745,10 +745,11 @@ typedef struct ScrewModifierData { short flag; } ScrewModifierData; -#define MOD_SCREW_NORMAL_FLIP (1<<0) -#define MOD_SCREW_NORMAL_CALC (1<<1) -#define MOD_SCREW_OBJECT_OFFSET (1<<2) -// #define MOD_SCREW_OBJECT_ANGLE (1<<4) +#define MOD_SCREW_NORMAL_FLIP (1 << 0) +#define MOD_SCREW_NORMAL_CALC (1 << 1) +#define MOD_SCREW_OBJECT_OFFSET (1 << 2) +// #define MOD_SCREW_OBJECT_ANGLE (1 << 4) +#define MOD_SCREW_SMOOTH_SHADING (1 << 5) typedef struct OceanModifierData { ModifierData modifier; @@ -1032,6 +1033,7 @@ typedef struct DynamicPaintModifierData { typedef enum RemeshModifierFlags { MOD_REMESH_FLOOD_FILL = 1, + MOD_REMESH_SMOOTH_SHADING = 2, } RemeshModifierFlags; typedef enum RemeshModifierMode { diff --git a/source/blender/makesdna/DNA_movieclip_types.h b/source/blender/makesdna/DNA_movieclip_types.h index ed7310ff883..f073a1957dc 100644 --- a/source/blender/makesdna/DNA_movieclip_types.h +++ b/source/blender/makesdna/DNA_movieclip_types.h @@ -84,7 +84,7 @@ typedef struct MovieClip { struct MovieClipProxy proxy; /* proxy to clip data */ int flag; - int len; /* lenght of movie */ + int len; /* length of movie */ } MovieClip; typedef struct MovieClipScopes { diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 6fbaf1723bc..4bbd1e20973 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -68,6 +68,14 @@ typedef struct bNodeStack { #define NS_OSA_VECTORS 1 #define NS_OSA_VALUES 2 +/* node socket/node socket type -b conversion rules */ +#define NS_CR_CENTER 0 +#define NS_CR_NONE 1 +#define NS_CR_FIT_WIDTH 2 +#define NS_CR_FIT_HEIGHT 3 +#define NS_CR_FIT 4 +#define NS_CR_STRETCH 5 + typedef struct bNodeSocket { struct bNodeSocket *next, *prev, *new_sock; @@ -87,7 +95,7 @@ typedef struct bNodeSocket { short stack_index; /* local stack index */ /* XXX deprecated, kept for forward compatibility */ short stack_type DNA_DEPRECATED; - int pad2; + int resizemode; /* compositor resize mode of the socket */ void *cache; /* cached data from execution */ /* internal data to retrieve relations and groups */ @@ -223,6 +231,11 @@ typedef struct bNodeLink { #define NODE_LINKFLAG_HILITE 1 /* link has been successfully validated */ #define NODE_LINK_VALID 2 +/* tree->edit_quality/tree->render_quality */ +#define NTREE_QUALITY_HIGH 0 +#define NTREE_QUALITY_MEDIUM 1 +#define NTREE_QUALITY_LOW 2 + /* the basis for a Node tree, all links and nodes reside internal here */ /* only re-usable node trees are in the library though, materials and textures allocate own tree struct */ typedef struct bNodeTree { @@ -240,6 +253,10 @@ typedef struct bNodeTree { int update; /* update flags */ int nodetype; /* specific node type this tree is used for */ + + short edit_quality; /* Quality setting when editing */ + short render_quality; /* Quality setting when rendering */ + int chunksize; /* tile size for compositor engine */ ListBase inputs, outputs; /* external sockets for group nodes */ @@ -271,6 +288,7 @@ typedef struct bNodeTree { /* ntree->flag */ #define NTREE_DS_EXPAND 1 /* for animation editors */ +#define NTREE_COM_OPENCL 2 /* use opencl */ /* XXX not nice, but needed as a temporary flags * for group updates after library linking. */ @@ -317,6 +335,16 @@ typedef struct bNodeSocketValueRGBA { /* data structs, for node->storage */ +#define CMP_NODE_MASKTYPE_ADD 0 +#define CMP_NODE_MASKTYPE_SUBTRACT 1 +#define CMP_NODE_MASKTYPE_MULTIPLY 2 +#define CMP_NODE_MASKTYPE_NOT 3 + +#define CMP_NODE_LENSFLARE_GHOST 1 +#define CMP_NODE_LENSFLARE_GLOW 2 +#define CMP_NODE_LENSFLARE_CIRCLE 4 +#define CMP_NODE_LENSFLARE_STREAKS 8 + /* this one has been replaced with ImageUser, keep it for do_versions() */ typedef struct NodeImageAnim { int frames, sfra, nr; @@ -324,10 +352,54 @@ typedef struct NodeImageAnim { short pad; } NodeImageAnim; +typedef struct ColorCorrectionData { + float saturation; + float contrast; + float gamma; + float gain; + float lift; + int pad; +} ColorCorrectionData; + +typedef struct NodeColorCorrection { + ColorCorrectionData master; + ColorCorrectionData shadows; + ColorCorrectionData midtones; + ColorCorrectionData highlights; + float startmidtones; + float endmidtones; +} NodeColorCorrection; + +typedef struct NodeBokehImage { + float angle; + int flaps; + float rounding; + float catadioptric; + float lensshift; +} NodeBokehImage; + +typedef struct NodeBoxMask { + float x; + float y; + float rotation; + float height; + float width; + int pad; +} NodeBoxMask; + +typedef struct NodeEllipseMask { + float x; + float y; + float rotation; + float height; + float width; + int pad; +} NodeEllipseMask; + /* layer info for image node outputs */ typedef struct NodeImageLayer { - /* index in the Image->layers and Image->layers->passes lists */ - int layer_index, pass_index; + /* index in the Image->layers->passes lists */ + int pass_index; /* render pass flag, in case this is an original render pass */ int pass_flag; } NodeImageLayer; diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 85016256129..2a2e312c43b 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -893,7 +893,7 @@ typedef struct ToolSettings { UvSculpt *uvsculpt; /* uv smooth */ /* Vertex group weight - used only for editmode, not weight - paint */ + * paint */ float vgroup_weight; /* Subdivide Settings */ @@ -1340,9 +1340,6 @@ typedef struct Scene { #define V3D_CAMERA_LOCAL(v3d) ((!(v3d)->scenelock && (v3d)->camera) ? (v3d)->camera : NULL) #define V3D_CAMERA_SCENE(scene, v3d) ((!(v3d)->scenelock && (v3d)->camera) ? (v3d)->camera : (scene)->camera) -#define ID_NEW(a) if( (a) && (a)->id.newid ) (a)= (void *)(a)->id.newid -#define ID_NEW_US(a) if( (a)->id.newid) {(a)= (void *)(a)->id.newid; (a)->id.us++;} -#define ID_NEW_US2(a) if( ((ID *)a)->newid) {(a)= ((ID *)a)->newid; ((ID *)a)->us++;} #define CFRA (scene->r.cfra) #define SUBFRA (scene->r.subframe) #define SFRA (scene->r.sfra) diff --git a/source/blender/makesdna/DNA_texture_types.h b/source/blender/makesdna/DNA_texture_types.h index c026c2018fd..7497f5e7449 100644 --- a/source/blender/makesdna/DNA_texture_types.h +++ b/source/blender/makesdna/DNA_texture_types.h @@ -517,9 +517,10 @@ typedef struct ColorMapping { #define MTEX_LIN_LIGHT 16 /* brush_map_mode */ -#define MTEX_MAP_MODE_FIXED 0 +#define MTEX_MAP_MODE_VIEW 0 #define MTEX_MAP_MODE_TILED 1 #define MTEX_MAP_MODE_3D 2 +#define MTEX_MAP_MODE_AREA 3 /* **************** EnvMap ********************* */ diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c index d0429041d9b..80c80d02e06 100644 --- a/source/blender/makesdna/intern/dna_genfile.c +++ b/source/blender/makesdna/intern/dna_genfile.c @@ -143,10 +143,10 @@ static short le_short(short temp); static short le_short(short temp) { short new; - char *rt=(char *)&temp, *rtn=(char *)&new; + char *rt = (char *)&temp, *rtn = (char *)&new; - rtn[0]= rt[1]; - rtn[1]= rt[0]; + rtn[0] = rt[1]; + rtn[1] = rt[0]; return new; } @@ -155,12 +155,12 @@ static short le_short(short temp) static int le_int(int temp) { int new; - char *rt=(char *)&temp, *rtn=(char *)&new; + char *rt = (char *)&temp, *rtn = (char *)&new; - rtn[0]= rt[3]; - rtn[1]= rt[2]; - rtn[2]= rt[1]; - rtn[3]= rt[0]; + rtn[0] = rt[3]; + rtn[1] = rt[2]; + rtn[2] = rt[1]; + rtn[3] = rt[0]; return new; } @@ -171,18 +171,18 @@ static int le_int(int temp) /* allowed duplicate code from makesdna.c */ int DNA_elem_array_size(const char *astr, int len) { - int a, mul=1; - char str[100], *cp= NULL; + int a, mul = 1; + char str[100], *cp = NULL; - memcpy(str, astr, len+1); + memcpy(str, astr, len + 1); - for (a=0; a<len; a++) { - if ( str[a]== '[' ) { - cp= &(str[a+1]); + for (a = 0; a < len; a++) { + if (str[a] == '[') { + cp = &(str[a + 1]); } - else if ( str[a]==']' && cp) { - str[a]= 0; - mul*= atoi(cp); + else if (str[a] == ']' && cp) { + str[a] = 0; + mul *= atoi(cp); } } @@ -210,7 +210,7 @@ void DNA_sdna_free(SDNA *sdna) static int ispointer(const char *name) { /* check if pointer or function pointer */ - return (name[0]=='*' || (name[0]=='(' && name[1]=='*')); + return (name[0] == '*' || (name[0] == '(' && name[1] == '*')); } static int elementsize(SDNA *sdna, short type, short name) @@ -219,24 +219,24 @@ static int elementsize(SDNA *sdna, short type, short name) int mul, namelen, len; const char *cp; - cp= sdna->names[name]; - len= 0; + cp = sdna->names[name]; + len = 0; - namelen= strlen(cp); + namelen = strlen(cp); /* is it a pointer or function pointer? */ if (ispointer(cp)) { /* has the naam an extra length? (array) */ - mul= 1; - if ( cp[namelen-1]==']') mul= DNA_elem_array_size(cp, namelen); + mul = 1; + if (cp[namelen - 1] == ']') mul = DNA_elem_array_size(cp, namelen); - len= sdna->pointerlen*mul; + len = sdna->pointerlen * mul; } - else if ( sdna->typelens[type] ) { + else if (sdna->typelens[type]) { /* has the naam an extra length? (array) */ - mul= 1; - if ( cp[namelen-1]==']') mul= DNA_elem_array_size(cp, namelen); + mul = 1; + if (cp[namelen - 1] == ']') mul = DNA_elem_array_size(cp, namelen); - len= mul*sdna->typelens[type]; + len = mul * sdna->typelens[type]; } @@ -250,13 +250,13 @@ static void printstruct(SDNA *sdna, short strnr) int b, nr; short *sp; - sp= sdna->structs[strnr]; + sp = sdna->structs[strnr]; - printf("struct %s\n", sdna->types[ sp[0] ]); - nr= sp[1]; - sp+= 2; + printf("struct %s\n", sdna->types[sp[0]]); + nr = sp[1]; + sp += 2; - for (b=0; b< nr; b++, sp+= 2) { + for (b = 0; b < nr; b++, sp += 2) { printf(" %s %s\n", sdna->types[sp[0]], sdna->names[sp[1]]); } } @@ -265,14 +265,14 @@ static void printstruct(SDNA *sdna, short strnr) static short *findstruct_name(SDNA *sdna, const char *str) { int a; - short *sp= NULL; + short *sp = NULL; - for (a=0; a<sdna->nr_structs; a++) { + for (a = 0; a < sdna->nr_structs; a++) { - sp= sdna->structs[a]; + sp = sdna->structs[a]; - if (strcmp( sdna->types[ sp[0] ], str )==0) return sp; + if (strcmp(sdna->types[sp[0]], str) == 0) return sp; } return NULL; @@ -280,11 +280,11 @@ static short *findstruct_name(SDNA *sdna, const char *str) int DNA_struct_find_nr(SDNA *sdna, const char *str) { - short *sp= NULL; + short *sp = NULL; - if (sdna->lastfind<sdna->nr_structs) { - sp= sdna->structs[sdna->lastfind]; - if (strcmp( sdna->types[ sp[0] ], str )==0) return sdna->lastfind; + if (sdna->lastfind < sdna->nr_structs) { + sp = sdna->structs[sdna->lastfind]; + if (strcmp(sdna->types[sp[0]], str) == 0) return sdna->lastfind; } #ifdef WITH_DNA_GHASH @@ -293,12 +293,12 @@ int DNA_struct_find_nr(SDNA *sdna, const char *str) { int a; - for (a=0; a<sdna->nr_structs; a++) { + for (a = 0; a < sdna->nr_structs; a++) { - sp= sdna->structs[a]; + sp = sdna->structs[a]; - if (strcmp( sdna->types[ sp[0] ], str )==0) { - sdna->lastfind= a; + if (strcmp(sdna->types[sp[0]], str) == 0) { + sdna->lastfind = a; return a; } } @@ -314,172 +314,172 @@ int DNA_struct_find_nr(SDNA *sdna, const char *str) static void init_structDNA(SDNA *sdna, int do_endian_swap) /* in sdna->data the data, now we convert that to something understandable */ { - int *data, *verg, gravity_fix= -1; + int *data, *verg, gravity_fix = -1; intptr_t nr; short *sp; char str[8], *cp; - verg= (int *)str; - data= (int *)sdna->data; + verg = (int *)str; + data = (int *)sdna->data; strcpy(str, "SDNA"); - if ( *data == *verg ) { + if (*data == *verg) { data++; /* load names array */ strcpy(str, "NAME"); - if ( *data == *verg ) { + if (*data == *verg) { data++; - if (do_endian_swap) sdna->nr_names= le_int(*data); - else sdna->nr_names= *data; + if (do_endian_swap) sdna->nr_names = le_int(*data); + else sdna->nr_names = *data; data++; - sdna->names= MEM_callocN(sizeof(void *)*sdna->nr_names, "sdnanames"); + sdna->names = MEM_callocN(sizeof(void *) * sdna->nr_names, "sdnanames"); } else { printf("NAME error in SDNA file\n"); return; } - nr= 0; - cp= (char *)data; - while (nr<sdna->nr_names) { - sdna->names[nr]= cp; + nr = 0; + cp = (char *)data; + while (nr < sdna->nr_names) { + 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; + 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++; + while (*cp) cp++; cp++; nr++; } - nr= (intptr_t)cp; /* prevent BUS error */ - nr= (nr+3) & ~3; - cp= (char *)nr; + nr = (intptr_t)cp; /* prevent BUS error */ + nr = (nr + 3) & ~3; + cp = (char *)nr; /* load type names array */ - data= (int *)cp; + data = (int *)cp; strcpy(str, "TYPE"); - if ( *data == *verg ) { + if (*data == *verg) { data++; - if (do_endian_swap) sdna->nr_types= le_int(*data); - else sdna->nr_types= *data; + if (do_endian_swap) sdna->nr_types = le_int(*data); + else sdna->nr_types = *data; data++; - sdna->types= MEM_callocN(sizeof(void *)*sdna->nr_types, "sdnatypes"); + sdna->types = MEM_callocN(sizeof(void *) * sdna->nr_types, "sdnatypes"); } else { printf("TYPE error in SDNA file\n"); return; } - nr= 0; - cp= (char *)data; - while (nr<sdna->nr_types) { - sdna->types[nr]= cp; + nr = 0; + cp = (char *)data; + while (nr < sdna->nr_types) { + sdna->types[nr] = cp; /* this is a patch, to change struct names without a conflict with SDNA */ /* be careful to use it, in this case for a system-struct (opengl/X) */ - if ( *cp == 'b') { + if (*cp == 'b') { /* struct Screen was already used by X, 'bScreen' replaces the old IrisGL 'Screen' struct */ - if ( strcmp("bScreen", cp)==0 ) sdna->types[nr]= cp+1; + if (strcmp("bScreen", cp) == 0) sdna->types[nr] = cp + 1; } - while ( *cp) cp++; + while (*cp) cp++; cp++; nr++; } - nr= (intptr_t)cp; /* prevent BUS error */ - nr= (nr+3) & ~3; - cp= (char *)nr; + nr = (intptr_t)cp; /* prevent BUS error */ + nr = (nr + 3) & ~3; + cp = (char *)nr; /* load typelen array */ - data= (int *)cp; + data = (int *)cp; strcpy(str, "TLEN"); - if ( *data == *verg ) { + if (*data == *verg) { data++; - sp= (short *)data; - sdna->typelens= sp; + sp = (short *)data; + sdna->typelens = sp; if (do_endian_swap) { - short a, *spo= sp; + short a, *spo = sp; - a= sdna->nr_types; + a = sdna->nr_types; while (a--) { - spo[0]= le_short(spo[0]); + spo[0] = le_short(spo[0]); spo++; } } - sp+= sdna->nr_types; + sp += sdna->nr_types; } else { printf("TLEN error in SDNA file\n"); return; } - if (sdna->nr_types & 1) sp++; /* prevent BUS error */ + if (sdna->nr_types & 1) sp++; /* prevent BUS error */ /* load struct array */ - data= (int *)sp; + data = (int *)sp; strcpy(str, "STRC"); - if ( *data == *verg ) { + if (*data == *verg) { data++; - if (do_endian_swap) sdna->nr_structs= le_int(*data); - else sdna->nr_structs= *data; + if (do_endian_swap) sdna->nr_structs = le_int(*data); + else sdna->nr_structs = *data; data++; - sdna->structs= MEM_callocN(sizeof(void *)*sdna->nr_structs, "sdnastrcs"); + sdna->structs = MEM_callocN(sizeof(void *) * sdna->nr_structs, "sdnastrcs"); } else { printf("STRC error in SDNA file\n"); return; } - nr= 0; - sp= (short *)data; - while (nr<sdna->nr_structs) { - sdna->structs[nr]= sp; + nr = 0; + sp = (short *)data; + while (nr < sdna->nr_structs) { + sdna->structs[nr] = sp; if (do_endian_swap) { short a; - sp[0]= le_short(sp[0]); - sp[1]= le_short(sp[1]); + sp[0] = le_short(sp[0]); + sp[1] = le_short(sp[1]); - a= sp[1]; - sp+= 2; + a = sp[1]; + sp += 2; while (a--) { - sp[0]= le_short(sp[0]); - sp[1]= le_short(sp[1]); - sp+= 2; + sp[0] = le_short(sp[0]); + sp[1] = le_short(sp[1]); + sp += 2; } } else { - sp+= 2*sp[1]+2; + sp += 2 * sp[1] + 2; } nr++; } /* finally pointerlen: use struct ListBase to test it, never change the size of it! */ - sp= findstruct_name(sdna, "ListBase"); + sp = findstruct_name(sdna, "ListBase"); /* weird; i have no memory of that... I think I used sizeof(void *) before... (ton) */ - sdna->pointerlen= sdna->typelens[ sp[0] ]/2; + sdna->pointerlen = sdna->typelens[sp[0]] / 2; - if (sp[1]!=2 || (sdna->pointerlen!=4 && sdna->pointerlen!=8)) { + if (sp[1] != 2 || (sdna->pointerlen != 4 && sdna->pointerlen != 8)) { printf("ListBase struct error! Needs it to calculate pointerize.\n"); exit(0); /* well, at least sizeof(ListBase) is error proof! (ton) */ @@ -487,19 +487,19 @@ static void init_structDNA(SDNA *sdna, int do_endian_swap) /* second part of gravity problem, setting "gravity" type to void */ if (gravity_fix > -1) { - for (nr=0; nr<sdna->nr_structs; nr++) { - sp= sdna->structs[nr]; + for (nr = 0; nr < sdna->nr_structs; nr++) { + sp = sdna->structs[nr]; if (strcmp(sdna->types[sp[0]], "ClothSimSettings") == 0) - sp[10]= SDNA_TYPE_VOID; + sp[10] = SDNA_TYPE_VOID; } } #ifdef WITH_DNA_GHASH /* create a ghash lookup to speed up */ - sdna->structs_map= BLI_ghash_new(BLI_ghashutil_strhash, BLI_ghashutil_strcmp, "init_structDNA gh"); + sdna->structs_map = BLI_ghash_str_new("init_structDNA gh"); for (nr = 0; nr < sdna->nr_structs; nr++) { - sp= sdna->structs[nr]; + sp = sdna->structs[nr]; BLI_ghash_insert(sdna->structs_map, (void *)sdna->types[sp[0]], (void *)(nr + 1)); } #endif @@ -508,12 +508,12 @@ static void init_structDNA(SDNA *sdna, int do_endian_swap) SDNA *DNA_sdna_from_data(void *data, int datalen, int do_endian_swap) { - SDNA *sdna= MEM_mallocN(sizeof(*sdna), "sdna"); + SDNA *sdna = MEM_mallocN(sizeof(*sdna), "sdna"); - sdna->lastfind= 0; + sdna->lastfind = 0; - sdna->datalen= datalen; - sdna->data= MEM_mallocN(datalen, "sdna_data"); + sdna->datalen = datalen; + sdna->data = MEM_mallocN(datalen, "sdna_data"); memcpy(sdna->data, data, datalen); init_structDNA(sdna, do_endian_swap); @@ -532,19 +532,19 @@ static void recurs_test_compflags(SDNA *sdna, char *compflags, int structnr) const char *cp; /* check all structs, test if it's inside another struct */ - sp= sdna->structs[structnr]; - typenr= sp[0]; + sp = sdna->structs[structnr]; + typenr = sp[0]; - for (a=0; a<sdna->nr_structs; a++) { - if (a!=structnr && compflags[a]==1) { - sp= sdna->structs[a]; - elems= sp[1]; - sp+= 2; - for (b=0; b<elems; b++, sp+=2) { - if (sp[0]==typenr) { - cp= sdna->names[ sp[1] ]; + for (a = 0; a < sdna->nr_structs; a++) { + if (a != structnr && compflags[a] == 1) { + sp = sdna->structs[a]; + elems = sp[1]; + sp += 2; + for (b = 0; b < elems; b++, sp += 2) { + if (sp[0] == typenr) { + cp = sdna->names[sp[1]]; if (!ispointer(cp)) { - compflags[a]= 2; + compflags[a] = 2; recurs_test_compflags(sdna, compflags, a); } } @@ -554,11 +554,11 @@ static void recurs_test_compflags(SDNA *sdna, char *compflags, int structnr) } - /* Unsure of exact function - compares the sdna argument to - * newsdna and sets up the information necessary to convert - * data written with a dna of oldsdna to inmemory data with a - * structure defined by the newsdna sdna (I think). -zr - */ +/* Unsure of exact function - compares the sdna argument to + * newsdna and sets up the information necessary to convert + * data written with a dna of oldsdna to inmemory data with a + * structure defined by the newsdna sdna (I think). -zr + */ /* well, the function below is just a lookup table to speed * up reading files. doh! -ton @@ -576,53 +576,53 @@ char *DNA_struct_get_compareflags(SDNA *sdna, SDNA *newsdna) const char *str1, *str2; char *compflags; - if (sdna->nr_structs==0) { + if (sdna->nr_structs == 0) { printf("error: file without SDNA\n"); return NULL; } - compflags= MEM_callocN(sdna->nr_structs, "compflags"); + compflags = MEM_callocN(sdna->nr_structs, "compflags"); /* we check all structs in 'sdna' and compare them with * the structs in 'newsdna' */ - for (a=0; a<sdna->nr_structs; a++) { - spold= sdna->structs[a]; + for (a = 0; a < sdna->nr_structs; a++) { + spold = sdna->structs[a]; /* search for type in cur */ - spcur= findstruct_name(newsdna, sdna->types[spold[0]]); + spcur = findstruct_name(newsdna, sdna->types[spold[0]]); if (spcur) { - compflags[a]= 2; + compflags[a] = 2; /* compare length and amount of elems */ - if ( spcur[1] == spold[1]) { - if ( newsdna->typelens[spcur[0]] == sdna->typelens[spold[0]] ) { + if (spcur[1] == spold[1]) { + if (newsdna->typelens[spcur[0]] == sdna->typelens[spold[0]]) { /* same length, same amount of elems, now per type and name */ - b= spold[1]; - spold+= 2; - spcur+= 2; + b = spold[1]; + spold += 2; + spcur += 2; while (b > 0) { - str1= newsdna->types[spcur[0]]; - str2= sdna->types[spold[0]]; - if (strcmp(str1, str2)!=0) break; + str1 = newsdna->types[spcur[0]]; + str2 = sdna->types[spold[0]]; + if (strcmp(str1, str2) != 0) break; - str1= newsdna->names[spcur[1]]; - str2= sdna->names[spold[1]]; - if (strcmp(str1, str2)!=0) break; + str1 = newsdna->names[spcur[1]]; + str2 = sdna->names[spold[1]]; + if (strcmp(str1, str2) != 0) break; /* same type and same name, now pointersize */ if (ispointer(str1)) { - if (sdna->pointerlen!=newsdna->pointerlen) break; + if (sdna->pointerlen != newsdna->pointerlen) break; } b--; - spold+= 2; - spcur+= 2; + spold += 2; + spcur += 2; } - if (b==0) compflags[a]= 1; + if (b == 0) compflags[a] = 1; } } @@ -633,20 +633,20 @@ char *DNA_struct_get_compareflags(SDNA *sdna, SDNA *newsdna) /* first struct in util.h is struct Link, this is skipped in compflags (als # 0). * was a bug, and this way dirty patched! Solve this later.... */ - compflags[0]= 1; + compflags[0] = 1; /* Because structs can be inside structs, we recursively * set flags when a struct is altered */ - for (a=0; a<sdna->nr_structs; a++) { - if (compflags[a]==2) recurs_test_compflags(sdna, compflags, a); + for (a = 0; a < sdna->nr_structs; a++) { + if (compflags[a] == 2) recurs_test_compflags(sdna, compflags, a); } #if 0 - for (a=0; a<sdna->nr_structs; a++) { - if (compflags[a]==2) { - spold= sdna->structs[a]; - printf("changed: %s\n", sdna->types[ spold[0] ]); + for (a = 0; a < sdna->nr_structs; a++) { + if (compflags[a] == 2) { + spold = sdna->structs[a]; + printf("changed: %s\n", sdna->types[spold[0]]); } } #endif @@ -656,94 +656,94 @@ char *DNA_struct_get_compareflags(SDNA *sdna, 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, "long")==0) return SDNA_TYPE_LONG; - else if ((strcmp(dna_type, "ulong")==0)||(strcmp(dna_type, "unsigned long")==0)) return SDNA_TYPE_ULONG; - 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; - else return -1; /* invalid! */ + 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, "long") == 0) return SDNA_TYPE_LONG; + else if ((strcmp(dna_type, "ulong") == 0)||(strcmp(dna_type, "unsigned long") == 0)) return SDNA_TYPE_ULONG; + 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; + else return -1; /* invalid! */ } static void cast_elem(const char *ctype, const char *otype, const char *name, char *curdata, char *olddata) { double val = 0.0; - int arrlen, curlen=1, oldlen=1; + int arrlen, curlen = 1, oldlen = 1; eSDNA_Type ctypenr, otypenr; - arrlen= DNA_elem_array_size(name, strlen(name)); + arrlen = DNA_elem_array_size(name, strlen(name)); - if ( (otypenr= sdna_type_nr(otype)) == -1 || - (ctypenr= sdna_type_nr(ctype)) == -1 ) + if ( (otypenr = sdna_type_nr(otype)) == -1 || + (ctypenr = sdna_type_nr(ctype)) == -1) { return; } /* define lengths */ - oldlen= DNA_elem_type_size(otypenr); - curlen= DNA_elem_type_size(ctypenr); + oldlen = DNA_elem_type_size(otypenr); + curlen = DNA_elem_type_size(ctypenr); - while (arrlen>0) { + while (arrlen > 0) { switch (otypenr) { - case SDNA_TYPE_CHAR: - val= *olddata; break; - case SDNA_TYPE_UCHAR: - val= *( (unsigned char *)olddata); break; - case SDNA_TYPE_SHORT: - val= *( (short *)olddata); break; - case SDNA_TYPE_USHORT: - val= *( (unsigned short *)olddata); break; - case SDNA_TYPE_INT: - val= *( (int *)olddata); break; - case SDNA_TYPE_LONG: - val= *( (int *)olddata); break; - case SDNA_TYPE_ULONG: - val= *( (unsigned int *)olddata); break; - case SDNA_TYPE_FLOAT: - val= *( (float *)olddata); break; - case SDNA_TYPE_DOUBLE: - val= *( (double *)olddata); break; - case SDNA_TYPE_INT64: - val= *( (int64_t *)olddata); break; - case SDNA_TYPE_UINT64: - val= *( (uint64_t *)olddata); break; + case SDNA_TYPE_CHAR: + val = *olddata; break; + case SDNA_TYPE_UCHAR: + val = *( (unsigned char *)olddata); break; + case SDNA_TYPE_SHORT: + val = *( (short *)olddata); break; + case SDNA_TYPE_USHORT: + val = *( (unsigned short *)olddata); break; + case SDNA_TYPE_INT: + val = *( (int *)olddata); break; + case SDNA_TYPE_LONG: + val = *( (int *)olddata); break; + case SDNA_TYPE_ULONG: + val = *( (unsigned int *)olddata); break; + case SDNA_TYPE_FLOAT: + val = *( (float *)olddata); break; + case SDNA_TYPE_DOUBLE: + val = *( (double *)olddata); break; + case SDNA_TYPE_INT64: + val = *( (int64_t *)olddata); break; + case SDNA_TYPE_UINT64: + val = *( (uint64_t *)olddata); break; } switch (ctypenr) { - case SDNA_TYPE_CHAR: - *curdata= val; break; - case SDNA_TYPE_UCHAR: - *( (unsigned char *)curdata)= val; break; - case SDNA_TYPE_SHORT: - *( (short *)curdata)= val; break; - case SDNA_TYPE_USHORT: - *( (unsigned short *)curdata)= val; break; - case SDNA_TYPE_INT: - *( (int *)curdata)= val; break; - case SDNA_TYPE_LONG: - *( (int *)curdata)= val; break; - case SDNA_TYPE_ULONG: - *( (unsigned int *)curdata)= val; break; - case SDNA_TYPE_FLOAT: - if (otypenr<2) val/= 255; - *( (float *)curdata)= val; break; - case SDNA_TYPE_DOUBLE: - if (otypenr<2) val/= 255; - *( (double *)curdata)= val; break; - case SDNA_TYPE_INT64: - *( (int64_t *)curdata)= val; break; - case SDNA_TYPE_UINT64: - *( (uint64_t *)curdata)= val; break; + case SDNA_TYPE_CHAR: + *curdata = val; break; + case SDNA_TYPE_UCHAR: + *( (unsigned char *)curdata) = val; break; + case SDNA_TYPE_SHORT: + *( (short *)curdata) = val; break; + case SDNA_TYPE_USHORT: + *( (unsigned short *)curdata) = val; break; + case SDNA_TYPE_INT: + *( (int *)curdata) = val; break; + case SDNA_TYPE_LONG: + *( (int *)curdata) = val; break; + case SDNA_TYPE_ULONG: + *( (unsigned int *)curdata) = val; break; + case SDNA_TYPE_FLOAT: + if (otypenr < 2) val /= 255; + *( (float *)curdata) = val; break; + case SDNA_TYPE_DOUBLE: + if (otypenr < 2) val /= 255; + *( (double *)curdata) = val; break; + case SDNA_TYPE_INT64: + *( (int64_t *)curdata) = val; break; + case SDNA_TYPE_UINT64: + *( (uint64_t *)curdata) = val; break; } - olddata+= oldlen; - curdata+= curlen; + olddata += oldlen; + curdata += curlen; arrlen--; } } @@ -757,26 +757,26 @@ static void cast_pointer(int curlen, int oldlen, const char *name, char *curdata #endif int arrlen; - arrlen= DNA_elem_array_size(name, strlen(name)); + arrlen = DNA_elem_array_size(name, strlen(name)); - while (arrlen>0) { + while (arrlen > 0) { - if (curlen==oldlen) { + if (curlen == oldlen) { memcpy(curdata, olddata, curlen); } - else if (curlen==4 && oldlen==8) { + else if (curlen == 4 && oldlen == 8) { #ifdef WIN32 - lval= *( (__int64 *)olddata ); + lval = *( (__int64 *)olddata); #else - lval= *( (long long *)olddata ); + lval = *( (long long *)olddata); #endif - *((int *)curdata) = lval>>3; /* is of course gambling! */ + *((int *)curdata) = lval >> 3; /* is of course gambling! */ } - else if (curlen==8 && oldlen==4) { + else if (curlen == 8 && oldlen == 4) { #ifdef WIN32 - *( (__int64 *)curdata ) = *((int *)olddata); + *( (__int64 *)curdata) = *((int *)olddata); #else - *( (long long *)curdata ) = *((int *)olddata); + *( (long long *)curdata) = *((int *)olddata); #endif } else { @@ -784,8 +784,8 @@ static void cast_pointer(int curlen, int oldlen, const char *name, char *curdata printf("errpr: illegal pointersize!\n"); } - olddata+= oldlen; - curdata+= curlen; + olddata += oldlen; + curdata += curlen; arrlen--; } @@ -793,14 +793,14 @@ static void cast_pointer(int curlen, int oldlen, const char *name, char *curdata static int elem_strcmp(const char *name, const char *oname) { - int a=0; + int a = 0; /* strcmp without array part */ while (1) { if (name[a] != oname[a]) return 1; - if (name[a]=='[') break; - if (name[a]==0) break; + if (name[a] == '[') break; + if (name[a] == 0) break; a++; } return 0; @@ -814,25 +814,25 @@ static char *find_elem(SDNA *sdna, const char *type, const char *name, short *ol /* without arraypart, so names can differ: return old namenr and type */ /* in old is the old struct */ - elemcount= old[1]; - old+= 2; - for (a=0; a<elemcount; a++, old+=2) { - - otype= sdna->types[old[0]]; - oname= sdna->names[old[1]]; - - len= elementsize(sdna, old[0], old[1]); - - if ( elem_strcmp(name, oname)==0 ) { /* naam equal */ - if ( strcmp(type, otype)==0 ) { /* type equal */ - if (sppo) *sppo= old; + elemcount = old[1]; + old += 2; + for (a = 0; a < elemcount; a++, old += 2) { + + otype = sdna->types[old[0]]; + oname = sdna->names[old[1]]; + + len = elementsize(sdna, old[0], old[1]); + + if (elem_strcmp(name, oname) == 0) { /* naam equal */ + if (strcmp(type, otype) == 0) { /* type equal */ + if (sppo) *sppo = old; return olddata; } return NULL; } - olddata+= len; + olddata += len; } return NULL; } @@ -841,11 +841,11 @@ static void reconstruct_elem(SDNA *newsdna, SDNA *oldsdna, char *type, const char *name, char *curdata, short *old, char *olddata) { /* rules: test for NAME: - * - name equal: - * - cast type - * - name partially equal (array differs) - * - type equal: memcpy - * - types casten + * - name equal: + * - cast type + * - name partially equal (array differs) + * - type equal: memcpy + * - types casten * (nzc 2-4-2001 I want the 'unsigned' bit to be parsed as well. Where * can I force this?) */ @@ -854,61 +854,61 @@ static void reconstruct_elem(SDNA *newsdna, SDNA *oldsdna, const char *oname, *cp; /* is 'name' an array? */ - cp= name; - array= 0; - while ( *cp && *cp!='[') { + cp = name; + array = 0; + while (*cp && *cp != '[') { cp++; array++; } - if ( *cp!= '[' ) array= 0; + if (*cp != '[') array = 0; /* in old is the old struct */ - elemcount= old[1]; - old+= 2; - for (a=0; a<elemcount; a++, old+=2) { - otype= oldsdna->types[old[0]]; - oname= oldsdna->names[old[1]]; - len= elementsize(oldsdna, old[0], old[1]); + elemcount = old[1]; + old += 2; + for (a = 0; a < elemcount; a++, old += 2) { + otype = oldsdna->types[old[0]]; + oname = oldsdna->names[old[1]]; + len = elementsize(oldsdna, old[0], old[1]); - if ( strcmp(name, oname)==0 ) { /* name equal */ + if (strcmp(name, oname) == 0) { /* name equal */ - if (ispointer(name)) { /* pointer of functionpointer afhandelen */ + if (ispointer(name)) { /* pointer of functionpointer afhandelen */ cast_pointer(newsdna->pointerlen, oldsdna->pointerlen, name, curdata, olddata); } - else if ( strcmp(type, otype)==0 ) { /* type equal */ + else if (strcmp(type, otype) == 0) { /* type equal */ memcpy(curdata, olddata, len); } else cast_elem(type, otype, name, curdata, olddata); return; } - else if (array) { /* name is an array */ + else if (array) { /* name is an array */ - if (oname[array]=='[' && strncmp(name, oname, array)==0 ) { /* basis equal */ + if (oname[array] == '[' && strncmp(name, oname, array) == 0) { /* basis equal */ - cursize= DNA_elem_array_size(name, strlen(name)); - oldsize= DNA_elem_array_size(oname, strlen(oname)); + cursize = DNA_elem_array_size(name, strlen(name)); + oldsize = DNA_elem_array_size(oname, strlen(oname)); - if (ispointer(name)) { /* handle pointer or functionpointer */ - if (cursize>oldsize) cast_pointer(newsdna->pointerlen, oldsdna->pointerlen, oname, curdata, olddata); + if (ispointer(name)) { /* handle pointer or functionpointer */ + if (cursize > oldsize) cast_pointer(newsdna->pointerlen, oldsdna->pointerlen, oname, curdata, olddata); else cast_pointer(newsdna->pointerlen, oldsdna->pointerlen, name, curdata, olddata); } - else if (name[0]=='*' || strcmp(type, otype)==0 ) { /* type equal */ - mul= len/oldsize; - mul*= (cursize < oldsize)? cursize: oldsize; + else if (name[0] == '*' || strcmp(type, otype) == 0) { /* type equal */ + mul = len / oldsize; + mul *= (cursize < oldsize) ? cursize : oldsize; memcpy(curdata, olddata, mul); /* terminate strings */ - if (oldsize > cursize && strcmp(type, "char")==0) - curdata[mul-1]= 0; + if (oldsize > cursize && strcmp(type, "char") == 0) + curdata[mul - 1] = 0; } else { - if (cursize>oldsize) cast_elem(type, otype, oname, curdata, olddata); + if (cursize > oldsize) cast_elem(type, otype, oname, curdata, olddata); else cast_elem(type, otype, name, curdata, olddata); } return; } } - olddata+= len; + olddata += len; } } @@ -924,69 +924,69 @@ static void reconstruct_struct(SDNA *newsdna, SDNA *oldsdna, char *type, *cpo, *cpc; const char *name, *nameo; - if (oldSDNAnr== -1) return; - if (curSDNAnr== -1) return; + if (oldSDNAnr == -1) return; + if (curSDNAnr == -1) return; - if ( compflags[oldSDNAnr]==1 ) { /* if recursive: test for equal */ + if (compflags[oldSDNAnr] == 1) { /* if recursive: test for equal */ - spo= oldsdna->structs[oldSDNAnr]; - elen= oldsdna->typelens[ spo[0] ]; + spo = oldsdna->structs[oldSDNAnr]; + elen = oldsdna->typelens[spo[0]]; memcpy(cur, data, elen); return; } - firststructtypenr= *(newsdna->structs[0]); + firststructtypenr = *(newsdna->structs[0]); - spo= oldsdna->structs[oldSDNAnr]; - spc= newsdna->structs[curSDNAnr]; + spo = oldsdna->structs[oldSDNAnr]; + spc = newsdna->structs[curSDNAnr]; - elemcount= spc[1]; + elemcount = spc[1]; - spc+= 2; - cpc= cur; - for (a=0; a<elemcount; a++, spc+=2) { - type= newsdna->types[spc[0]]; - name= newsdna->names[spc[1]]; + spc += 2; + cpc = cur; + for (a = 0; a < elemcount; a++, spc += 2) { + type = newsdna->types[spc[0]]; + name = newsdna->names[spc[1]]; - elen= elementsize(newsdna, spc[0], spc[1]); + elen = elementsize(newsdna, spc[0], spc[1]); /* test: is type a struct? */ - if (spc[0]>=firststructtypenr && !ispointer(name)) { + if (spc[0] >= firststructtypenr && !ispointer(name)) { /* where does the old struct data start (and is there an old one?) */ - cpo= find_elem(oldsdna, type, name, spo, data, &sppo); + cpo = find_elem(oldsdna, type, name, spo, data, &sppo); if (cpo) { - oldSDNAnr= DNA_struct_find_nr(oldsdna, type); - curSDNAnr= DNA_struct_find_nr(newsdna, type); + oldSDNAnr = DNA_struct_find_nr(oldsdna, type); + curSDNAnr = DNA_struct_find_nr(newsdna, type); /* array! */ - mul= DNA_elem_array_size(name, strlen(name)); - nameo= oldsdna->names[sppo[1]]; - mulo= DNA_elem_array_size(nameo, strlen(nameo)); + mul = DNA_elem_array_size(name, strlen(name)); + nameo = oldsdna->names[sppo[1]]; + mulo = DNA_elem_array_size(nameo, strlen(nameo)); - eleno= elementsize(oldsdna, sppo[0], sppo[1]); + eleno = elementsize(oldsdna, sppo[0], sppo[1]); - elen/= mul; - eleno/= mulo; + elen /= mul; + eleno /= mulo; while (mul--) { reconstruct_struct(newsdna, oldsdna, compflags, oldSDNAnr, cpo, curSDNAnr, cpc); - cpo+= eleno; - cpc+= elen; + cpo += eleno; + cpc += elen; /* new struct array larger than old */ mulo--; - if (mulo<=0) break; + if (mulo <= 0) break; } } - else cpc+= elen; + else cpc += elen; } else { reconstruct_elem(newsdna, oldsdna, type, name, cpc, spo, data); - cpc+= elen; + cpc += elen; } } @@ -1002,32 +1002,32 @@ void DNA_struct_switch_endian(SDNA *oldsdna, int oldSDNAnr, char *data) char *type, *cpo, *cur, cval; const char *name; - if (oldSDNAnr== -1) return; - firststructtypenr= *(oldsdna->structs[0]); + if (oldSDNAnr == -1) return; + firststructtypenr = *(oldsdna->structs[0]); - spo= spc= oldsdna->structs[oldSDNAnr]; + spo = spc = oldsdna->structs[oldSDNAnr]; - elemcount= spo[1]; + elemcount = spo[1]; - spc+= 2; - cur= data; + spc += 2; + cur = data; - for (a=0; a<elemcount; a++, spc+=2) { - type= oldsdna->types[spc[0]]; - name= oldsdna->names[spc[1]]; + for (a = 0; a < elemcount; a++, spc += 2) { + type = oldsdna->types[spc[0]]; + name = oldsdna->names[spc[1]]; /* elementsize = including arraysize */ - elen= elementsize(oldsdna, spc[0], spc[1]); + elen = elementsize(oldsdna, spc[0], spc[1]); /* test: is type a struct? */ - if (spc[0]>=firststructtypenr && !ispointer(name)) { + if (spc[0] >= firststructtypenr && !ispointer(name)) { /* where does the old data start (is there one?) */ - cpo= find_elem(oldsdna, type, name, spo, data, NULL); + cpo = find_elem(oldsdna, type, name, spo, data, NULL); if (cpo) { - oldSDNAnr= DNA_struct_find_nr(oldsdna, type); + oldSDNAnr = DNA_struct_find_nr(oldsdna, type); - mul= DNA_elem_array_size(name, strlen(name)); - elena= elen/mul; + mul = DNA_elem_array_size(name, strlen(name)); + elena = elen / mul; while (mul--) { DNA_struct_switch_endian(oldsdna, oldSDNAnr, cpo); @@ -1038,113 +1038,113 @@ void DNA_struct_switch_endian(SDNA *oldsdna, int oldSDNAnr, char *data) else { if (ispointer(name)) { - if (oldsdna->pointerlen==8) { + if (oldsdna->pointerlen == 8) { - mul= DNA_elem_array_size(name, strlen(name)); - cpo= cur; + mul = DNA_elem_array_size(name, strlen(name)); + cpo = cur; while (mul--) { - cval= cpo[0]; cpo[0]= cpo[7]; cpo[7]= cval; - cval= cpo[1]; cpo[1]= cpo[6]; cpo[6]= cval; - cval= cpo[2]; cpo[2]= cpo[5]; cpo[5]= cval; - cval= cpo[3]; cpo[3]= cpo[4]; cpo[4]= cval; + cval = cpo[0]; cpo[0] = cpo[7]; cpo[7] = cval; + cval = cpo[1]; cpo[1] = cpo[6]; cpo[6] = cval; + cval = cpo[2]; cpo[2] = cpo[5]; cpo[5] = cval; + cval = cpo[3]; cpo[3] = cpo[4]; cpo[4] = cval; - cpo+= 8; + cpo += 8; } } } else { - if ( spc[0]==SDNA_TYPE_SHORT || - spc[0]==SDNA_TYPE_USHORT ) + if (spc[0] == SDNA_TYPE_SHORT || + spc[0] == SDNA_TYPE_USHORT) { /* exception: variable called blocktype/ipowin: derived from ID_ */ - skip= 0; - if (name[0]=='b' && name[1]=='l') { - if (strcmp(name, "blocktype")==0) skip= 1; + skip = 0; + if (name[0] == 'b' && name[1] == 'l') { + if (strcmp(name, "blocktype") == 0) skip = 1; } - else if (name[0]=='i' && name[1]=='p') { - if (strcmp(name, "ipowin")==0) skip= 1; + else if (name[0] == 'i' && name[1] == 'p') { + if (strcmp(name, "ipowin") == 0) skip = 1; } - if (skip==0) { - mul= DNA_elem_array_size(name, strlen(name)); - cpo= cur; + if (skip == 0) { + mul = DNA_elem_array_size(name, strlen(name)); + cpo = cur; while (mul--) { - cval= cpo[0]; - cpo[0]= cpo[1]; - cpo[1]= cval; - cpo+= 2; + cval = cpo[0]; + cpo[0] = cpo[1]; + cpo[1] = cval; + cpo += 2; } } } - else if ( (spc[0]==SDNA_TYPE_INT || - spc[0]==SDNA_TYPE_LONG || - spc[0]==SDNA_TYPE_ULONG || - spc[0]==SDNA_TYPE_FLOAT)) + else if ( (spc[0] == SDNA_TYPE_INT || + spc[0] == SDNA_TYPE_LONG || + spc[0] == SDNA_TYPE_ULONG || + spc[0] == SDNA_TYPE_FLOAT)) { - mul= DNA_elem_array_size(name, strlen(name)); - cpo= cur; + mul = DNA_elem_array_size(name, strlen(name)); + cpo = cur; while (mul--) { - cval= cpo[0]; - cpo[0]= cpo[3]; - cpo[3]= cval; - cval= cpo[1]; - cpo[1]= cpo[2]; - cpo[2]= cval; - cpo+= 4; + cval = cpo[0]; + cpo[0] = cpo[3]; + cpo[3] = cval; + cval = cpo[1]; + cpo[1] = cpo[2]; + cpo[2] = cval; + cpo += 4; } } - else if ( (spc[0]==SDNA_TYPE_INT64) || - (spc[0]==SDNA_TYPE_UINT64)) + else if ( (spc[0] == SDNA_TYPE_INT64) || + (spc[0] == SDNA_TYPE_UINT64)) { - mul= DNA_elem_array_size(name, strlen(name)); - cpo= cur; + mul = DNA_elem_array_size(name, strlen(name)); + cpo = cur; while (mul--) { - cval= cpo[0]; cpo[0]= cpo[7]; cpo[7]= cval; - cval= cpo[1]; cpo[1]= cpo[6]; cpo[6]= cval; - cval= cpo[2]; cpo[2]= cpo[5]; cpo[5]= cval; - cval= cpo[3]; cpo[3]= cpo[4]; cpo[4]= cval; + cval = cpo[0]; cpo[0] = cpo[7]; cpo[7] = cval; + cval = cpo[1]; cpo[1] = cpo[6]; cpo[6] = cval; + cval = cpo[2]; cpo[2] = cpo[5]; cpo[5] = cval; + cval = cpo[3]; cpo[3] = cpo[4]; cpo[4] = cval; - cpo+= 8; + cpo += 8; } } } } - cur+= elen; + cur += elen; } } void *DNA_struct_reconstruct(SDNA *newsdna, SDNA *oldsdna, char *compflags, int oldSDNAnr, int blocks, void *data) { - int a, curSDNAnr, curlen=0, oldlen; + int a, curSDNAnr, curlen = 0, oldlen; short *spo, *spc; char *cur, *type, *cpc, *cpo; /* oldSDNAnr == structnr, we're looking for the corresponding 'cur' number */ - spo= oldsdna->structs[oldSDNAnr]; - type= oldsdna->types[ spo[0] ]; - oldlen= oldsdna->typelens[ spo[0] ]; - curSDNAnr= DNA_struct_find_nr(newsdna, type); + spo = oldsdna->structs[oldSDNAnr]; + type = oldsdna->types[spo[0]]; + oldlen = oldsdna->typelens[spo[0]]; + curSDNAnr = DNA_struct_find_nr(newsdna, type); /* init data and alloc */ if (curSDNAnr >= 0) { - spc= newsdna->structs[curSDNAnr]; - curlen= newsdna->typelens[ spc[0] ]; + spc = newsdna->structs[curSDNAnr]; + curlen = newsdna->typelens[spc[0]]; } - if (curlen==0) { + if (curlen == 0) { return NULL; } - cur= MEM_callocN(blocks*curlen, "reconstruct"); - cpc= cur; - cpo= data; - for (a=0; a<blocks; a++) { + cur = MEM_callocN(blocks * curlen, "reconstruct"); + cpc = cur; + cpo = data; + for (a = 0; a < blocks; a++) { reconstruct_struct(newsdna, oldsdna, compflags, oldSDNAnr, cpo, curSDNAnr, cpc); - cpc+= curlen; - cpo+= oldlen; + cpc += curlen; + cpo += oldlen; } return cur; @@ -1153,9 +1153,9 @@ void *DNA_struct_reconstruct(SDNA *newsdna, SDNA *oldsdna, char *compflags, int int DNA_elem_offset(SDNA *sdna, const char *stype, const char *vartype, const char *name) { - int SDNAnr= DNA_struct_find_nr(sdna, stype); - short *spo= sdna->structs[SDNAnr]; - char *cp= find_elem(sdna, vartype, name, spo, NULL, NULL); + int SDNAnr = DNA_struct_find_nr(sdna, stype); + short *spo = sdna->structs[SDNAnr]; + char *cp = find_elem(sdna, vartype, name, spo, NULL, NULL); return (int)((intptr_t)cp); } diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c index ec5b0cb8762..58880be6f5f 100644 --- a/source/blender/makesdna/intern/makesdna.c +++ b/source/blender/makesdna/intern/makesdna.c @@ -139,18 +139,18 @@ static const char *includefiles[] = { "" }; -static int maxdata= 500000, maxnr= 50000; -static int nr_names=0; -static int nr_types=0; -static int nr_structs=0; -static char **names, *namedata; /* at address names[a] is string a */ -static char **types, *typedata; /* at address types[a] is string a */ -static short *typelens; /* at typelens[a] is de length of type a */ -static short *alphalens; /* contains sizes as they are calculated on the DEC Alpha (64 bits), infact any 64bit system */ -static short **structs, *structdata;/* at sp= structs[a] is the first address of a struct definition - * sp[0] is type number - * sp[1] is amount of elements - * sp[2] sp[3] is typenr, namenr (etc) */ +static int maxdata = 500000, maxnr = 50000; +static int nr_names = 0; +static int nr_types = 0; +static int nr_structs = 0; +static char **names, *namedata; /* at address names[a] is string a */ +static char **types, *typedata; /* at address types[a] is string a */ +static short *typelens; /* at typelens[a] is de length of type a */ +static short *alphalens; /* contains sizes as they are calculated on the DEC Alpha (64 bits), infact any 64bit system */ +static short **structs, *structdata; /* at sp= structs[a] is the first address of a struct definition + * sp[0] is type number + * sp[1] is amount of elements + * sp[2] sp[3] is typenr, namenr (etc) */ /** * Variable to control debug output of makesdna. * debugSDNA: @@ -214,7 +214,7 @@ void dna_write(FILE *file, void *pntr, int size); /** * Report all structures found so far, and print their lengths. */ -void printStructLenghts(void); +void printStructLengths(void); @@ -230,7 +230,7 @@ static int add_type(const char *str, int len) char *cp; /* first do validity check */ - if (str[0]==0) { + if (str[0] == 0) { return -1; } else if (strchr(str, '*')) { @@ -240,10 +240,10 @@ static int add_type(const char *str, int len) } /* search through type array */ - for (nr=0; nr<nr_types; nr++) { - if (strcmp(str, types[nr])==0) { + for (nr = 0; nr < nr_types; nr++) { + if (strcmp(str, types[nr]) == 0) { if (len) { - typelens[nr]= len; + typelens[nr] = len; alphalens[nr] = len; } return nr; @@ -251,22 +251,22 @@ static int add_type(const char *str, int len) } /* append new type */ - if (nr_types==0) cp= typedata; + if (nr_types == 0) cp = typedata; else { - cp= types[nr_types-1]+strlen(types[nr_types-1])+1; + cp = types[nr_types - 1] + strlen(types[nr_types - 1]) + 1; } strcpy(cp, str); - types[nr_types]= cp; - typelens[nr_types]= len; - alphalens[nr_types]= len; + types[nr_types] = cp; + typelens[nr_types] = len; + alphalens[nr_types] = len; - if (nr_types>=maxnr) { + if (nr_types >= maxnr) { printf("too many types\n"); - return nr_types-1; + return nr_types - 1; } nr_types++; - return nr_types-1; + return nr_types - 1; } @@ -287,14 +287,14 @@ 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. * void (*function)(...) and float (*array)[..]. the array case * name is still converted to (array*)() though because it is that * way in old dna too, and works correct with elementsize() */ - int isfuncptr = (strchr(str+1, '(')) != NULL; + int isfuncptr = (strchr(str + 1, '(')) != NULL; if (debugSDNA > 3) printf("\t\t\t\t*** Function pointer or multidim array pointer found\n"); /* functionpointer: transform the type (sometimes) */ @@ -313,13 +313,13 @@ static int add_name(const char *str) if (debugSDNA > 3) printf("first brace after offset %d\n", i); j++; /* j beyond closing brace ? */ - while ((str[j] != 0) && (str[j] != ')' )) { + while ((str[j] != 0) && (str[j] != ')')) { if (debugSDNA > 3) printf("seen %c ( %d)\n", str[j], str[j]); j++; } if (debugSDNA > 3) printf("seen %c ( %d)\n" - "special after offset%d\n", - str[j], str[j], j); + "special after offset%d\n", + str[j], str[j], j); if (!isfuncptr) { /* multidimensional array pointer case */ @@ -329,7 +329,7 @@ static int add_name(const char *str) else printf("Error during tokening multidim array pointer\n"); } - else if (str[j] == 0 ) { + else if (str[j] == 0) { if (debugSDNA > 3) printf("offsetting for space\n"); /* get additional offset */ k = 0; @@ -340,7 +340,7 @@ static int add_name(const char *str) if (debugSDNA > 3) printf("extra offset %d\n", k); additional_slen_offset = k; } - else if (str[j] == ')' ) { + else if (str[j] == ')') { if (debugSDNA > 3) printf("offsetting for brace\n"); ; /* don't get extra offset */ } @@ -366,22 +366,22 @@ static int add_name(const char *str) (strncmp(buf, "(*windraw", 9) == 0) ) { buf[i] = ')'; - buf[i+1] = '('; - buf[i+2] = 'v'; - buf[i+3] = 'o'; - buf[i+4] = 'i'; - buf[i+5] = 'd'; - buf[i+6] = ')'; - buf[i+7] = 0; + buf[i + 1] = '('; + buf[i + 2] = 'v'; + buf[i + 3] = 'o'; + buf[i + 4] = 'i'; + buf[i + 5] = 'd'; + buf[i + 6] = ')'; + buf[i + 7] = 0; } else { buf[i] = ')'; - buf[i+1] = '('; - buf[i+2] = ')'; - buf[i+3] = 0; + buf[i + 1] = '('; + buf[i + 2] = ')'; + buf[i + 3] = 0; } /* now precede with buf*/ - if (debugSDNA > 3) printf("\t\t\t\t\tProposing fp name %s\n", buf); + if (debugSDNA > 3) printf("\t\t\t\t\tProposing fp name %s\n", buf); name = buf; } else { @@ -390,27 +390,27 @@ static int add_name(const char *str) } /* search name array */ - for (nr=0; nr<nr_names; nr++) { - if (strcmp(name, names[nr])==0) { + for (nr = 0; nr < nr_names; nr++) { + if (strcmp(name, names[nr]) == 0) { return nr; } } /* append new type */ - if (nr_names==0) cp= namedata; + if (nr_names == 0) cp = namedata; else { - cp= names[nr_names-1]+strlen(names[nr_names-1])+1; + cp = names[nr_names - 1] + strlen(names[nr_names - 1]) + 1; } strcpy(cp, name); - names[nr_names]= cp; + names[nr_names] = cp; - if (nr_names>=maxnr) { + if (nr_names >= maxnr) { printf("too many names\n"); - return nr_names-1; + return nr_names - 1; } nr_names++; - return nr_names-1; + return nr_names - 1; } static short *add_struct(int namecode) @@ -418,19 +418,19 @@ static short *add_struct(int namecode) int len; short *sp; - if (nr_structs==0) { - structs[0]= structdata; + if (nr_structs == 0) { + structs[0] = structdata; } else { - sp= structs[nr_structs-1]; - len= sp[1]; - structs[nr_structs]= sp+ 2*len+2; + sp = structs[nr_structs - 1]; + len = sp[1]; + structs[nr_structs] = sp + 2 * len + 2; } - sp= structs[nr_structs]; - sp[0]= namecode; + sp = structs[nr_structs]; + sp[0] = namecode; - if (nr_structs>=maxnr) { + if (nr_structs >= maxnr) { printf("too many structs\n"); return sp; } @@ -446,58 +446,58 @@ static int preprocess_include(char *maindata, int len) /* note: len + 1, last character is a dummy to prevent * comparisons using uninitialized memory */ - temp= MEM_mallocN(len + 1, "preprocess_include"); - temp[len]= ' '; + temp = MEM_mallocN(len + 1, "preprocess_include"); + temp[len] = ' '; memcpy(temp, maindata, len); // remove all c++ comments /* replace all enters/tabs/etc with spaces */ - cp= temp; - a= len; + cp = temp; + a = len; comment = 0; while (a--) { - if (cp[0]=='/' && cp[1]=='/') { + if (cp[0] == '/' && cp[1] == '/') { comment = 1; } - else if (*cp<32) { + else if (*cp < 32) { comment = 0; } - if (comment || *cp<32 || *cp>128 ) *cp= 32; + if (comment || *cp < 32 || *cp > 128) *cp = 32; cp++; } /* data from temp copy to maindata, remove comments and double spaces */ - cp= temp; - md= maindata; - newlen= 0; - comment= 0; - a= len; + cp = temp; + md = maindata; + newlen = 0; + comment = 0; + a = len; while (a--) { - if (cp[0]=='/' && cp[1]=='*') { - comment= 1; - cp[0]=cp[1]= 32; + if (cp[0] == '/' && cp[1] == '*') { + comment = 1; + cp[0] = cp[1] = 32; } - if (cp[0]=='*' && cp[1]=='/') { - comment= 0; - cp[0]=cp[1]= 32; + if (cp[0] == '*' && cp[1] == '/') { + comment = 0; + cp[0] = cp[1] = 32; } /* do not copy when: */ - if (comment); - else if ( cp[0]==' ' && cp[1]==' ' ); - else if ( cp[-1]=='*' && cp[0]==' ' ); /* pointers with a space */ + if (comment) ; + else if (cp[0] == ' ' && cp[1] == ' ') ; + else if (cp[-1] == '*' && cp[0] == ' ') ; /* pointers with a space */ /* skip special keywords */ - else if (strncmp("DNA_DEPRECATED", cp, 14)==0) { + else if (strncmp("DNA_DEPRECATED", cp, 14) == 0) { /* single values are skipped already, so decrement 1 less */ a -= 13; cp += 13; } else { - md[0]= cp[0]; + md[0] = cp[0]; md++; newlen++; } @@ -511,30 +511,30 @@ static int preprocess_include(char *maindata, int len) static void *read_file_data(char *filename, int *len_r) { #ifdef WIN32 - FILE *fp= fopen(filename, "rb"); + FILE *fp = fopen(filename, "rb"); #else - FILE *fp= fopen(filename, "r"); + FILE *fp = fopen(filename, "r"); #endif void *data; if (!fp) { - *len_r= -1; + *len_r = -1; return NULL; } fseek(fp, 0L, SEEK_END); - *len_r= ftell(fp); + *len_r = ftell(fp); fseek(fp, 0L, SEEK_SET); - data= MEM_mallocN(*len_r, "read_file_data"); + data = MEM_mallocN(*len_r, "read_file_data"); if (!data) { - *len_r= -1; + *len_r = -1; fclose(fp); return NULL; } - if (fread(data, *len_r, 1, fp)!=1) { - *len_r= -1; + if (fread(data, *len_r, 1, fp) != 1) { + *len_r = -1; MEM_freeN(data); fclose(fp); return NULL; @@ -553,38 +553,38 @@ static int convert_include(char *filename) short *structpoin, *sp; char *maindata, *mainend, *md, *md1; - md= maindata= read_file_data(filename, &filelen); - if (filelen==-1) { + md = maindata = read_file_data(filename, &filelen); + if (filelen == -1) { printf("Can't read file %s\n", filename); return 1; } - filelen= preprocess_include(maindata, filelen); - mainend= maindata+filelen-1; + filelen = preprocess_include(maindata, filelen); + mainend = maindata + filelen - 1; /* we look for '{' and then back to 'struct' */ - count= 0; - overslaan= 0; - while (count<filelen) { + count = 0; + overslaan = 0; + while (count < filelen) { /* code for skipping a struct: two hashes on 2 lines. (preprocess added a space) */ - if (md[0]=='#' && md[1]==' ' && md[2]=='#') { - overslaan= 1; + if (md[0] == '#' && md[1] == ' ' && md[2] == '#') { + overslaan = 1; } - if (md[0]=='{') { - md[0]= 0; + if (md[0] == '{') { + md[0] = 0; if (overslaan) { - overslaan= 0; + overslaan = 0; } else { - if (md[-1]==' ') md[-1]= 0; - md1= md-2; - while ( *md1!=32) md1--; /* to beginning of word */ + if (md[-1] == ' ') md[-1] = 0; + md1 = md - 2; + while (*md1 != 32) md1--; /* to beginning of word */ md1++; /* we've got a struct name when... */ - if ( strncmp(md1-7, "struct", 6)==0 ) { + if (strncmp(md1 - 7, "struct", 6) == 0) { strct = add_type(md1, 0); if (strct == -1) { @@ -592,33 +592,33 @@ static int convert_include(char *filename) return 1; } - structpoin= add_struct(strct); - sp= structpoin+2; + structpoin = add_struct(strct); + sp = structpoin + 2; if (debugSDNA > 1) printf("\t|\t|-- detected struct %s\n", types[strct]); /* first lets make it all nice strings */ - md1= md+1; + 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; + md1 = md + 1; + while (*md1 != '}') { + 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); + type = add_type(md1, 0); if (type == -1) { printf("File '%s' contains struct we can't parse \"%s\"\n", filename, md1); return 1; @@ -626,48 +626,48 @@ static int convert_include(char *filename) if (debugSDNA > 1) printf("\t|\t|\tfound type %s (", md1); - md1+= strlen(md1); + md1 += strlen(md1); /* read until ';' */ - while ( *md1 != ';' ) { - if (md1>mainend) break; + while (*md1 != ';') { + if (md1 > mainend) break; if (*md1) { /* We've got a name. slen needs * correction for function * pointers! */ - slen= (int) strlen(md1); - if ( md1[slen-1]==';' ) { - md1[slen-1]= 0; + slen = (int) strlen(md1); + if (md1[slen - 1] == ';') { + md1[slen - 1] = 0; - name= add_name(md1); + name = add_name(md1); slen += additional_slen_offset; - sp[0]= type; - sp[1]= name; + sp[0] = type; + sp[1] = name; - if ((debugSDNA>1) && (names[name] != NULL)) printf("%s |", names[name]); + if ((debugSDNA > 1) && (names[name] != NULL)) printf("%s |", names[name]); structpoin[1]++; - sp+= 2; + sp += 2; - md1+= slen; + md1 += slen; break; } - name= add_name(md1); + name = add_name(md1); slen += additional_slen_offset; - sp[0]= type; - sp[1]= name; + sp[0] = type; + sp[1] = name; if ((debugSDNA > 1) && (names[name] != NULL)) printf("%s ||", names[name]); structpoin[1]++; - sp+= 2; + sp += 2; - md1+= slen; + md1 += slen; } md1++; } @@ -691,20 +691,20 @@ static int convert_include(char *filename) static int arraysize(char *astr, int len) { - int a, mul=1; - char str[100], *cp=NULL; + int a, mul = 1; + char str[100], *cp = NULL; - memcpy(str, astr, len+1); + memcpy(str, astr, len + 1); - for (a=0; a<len; a++) { - if ( str[a]== '[' ) { - cp= &(str[a+1]); + for (a = 0; a < len; a++) { + if (str[a] == '[') { + cp = &(str[a + 1]); } - else if ( str[a]==']' && cp) { - str[a]= 0; + else if (str[a] == ']' && cp) { + str[a] = 0; /* if 'cp' is a preprocessor definition, it will evaluate to 0, * the caller needs to check for this case and throw an error */ - mul*= atoi(cp); + mul *= atoi(cp); } } @@ -713,40 +713,40 @@ static int arraysize(char *astr, int len) static int calculate_structlens(int firststruct) { - int a, b, len, alphalen, unknown= nr_structs, lastunknown, structtype, type, mul, namelen; + int a, b, len, alphalen, unknown = nr_structs, lastunknown, structtype, type, mul, namelen; short *sp, *structpoin; char *cp; int has_pointer, dna_error = 0; while (unknown) { - lastunknown= unknown; - unknown= 0; + lastunknown = unknown; + unknown = 0; /* check all structs... */ - for (a=0; a<nr_structs; a++) { - structpoin= structs[a]; - structtype= structpoin[0]; + for (a = 0; a < nr_structs; a++) { + structpoin = structs[a]; + structtype = structpoin[0]; /* when length is not known... */ - if (typelens[structtype]==0) { + if (typelens[structtype] == 0) { - sp= structpoin+2; - len= 0; + sp = structpoin + 2; + len = 0; alphalen = 0; has_pointer = 0; /* check all elements in struct */ - for (b=0; b<structpoin[1]; b++, sp+=2) { - type= sp[0]; - cp= names[sp[1]]; + for (b = 0; b < structpoin[1]; b++, sp += 2) { + type = sp[0]; + cp = names[sp[1]]; - namelen= (int) strlen(cp); + namelen = (int) strlen(cp); /* is it a pointer or function pointer? */ - if (cp[0]=='*' || cp[1]=='*') { + if (cp[0] == '*' || cp[1] == '*') { has_pointer = 1; /* has the name an extra length? (array) */ - mul= 1; - if ( cp[namelen-1]==']') mul= arraysize(cp, namelen); + mul = 1; + if (cp[namelen - 1] == ']') mul = arraysize(cp, namelen); if (mul == 0) { printf("Zero array size found or could not parse %s: '%.*s'\n", types[structtype], namelen + 1, cp); @@ -776,15 +776,15 @@ static int calculate_structlens(int firststruct) alphalen += 8 * mul; } - else if (cp[0]=='[') { + else if (cp[0] == '[') { /* parsing can cause names "var" and "[3]" to be found for "float var [3]" ... */ printf("Parse error in struct, invalid member name: %s %s\n", types[structtype], cp); dna_error = 1; } - else if ( typelens[type] ) { + else if (typelens[type]) { /* has the name an extra length? (array) */ - mul= 1; - if ( cp[namelen-1]==']') mul= arraysize(cp, namelen); + mul = 1; + if (cp[namelen - 1] == ']') mul = arraysize(cp, namelen); if (mul == 0) { printf("Zero array size found or could not parse %s: '%.*s'\n", types[structtype], namelen + 1, cp); @@ -793,50 +793,50 @@ static int calculate_structlens(int firststruct) /* struct alignment */ if (type >= firststruct) { - if (sizeof(void *)==8 && (len % 8) ) { + if (sizeof(void *) == 8 && (len % 8) ) { printf("Align struct error: %s %s\n", types[structtype], cp); dna_error = 1; } } /* 2-4 aligned/ */ - if (typelens[type]>3 && (len % 4) ) { - printf("Align 4 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len%4); + if (typelens[type] > 3 && (len % 4) ) { + printf("Align 4 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len % 4); dna_error = 1; } - else if (typelens[type]==2 && (len % 2) ) { - printf("Align 2 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len%2); + else if (typelens[type] == 2 && (len % 2) ) { + printf("Align 2 error in struct: %s %s (add %d padding bytes)\n", types[structtype], cp, len % 2); dna_error = 1; } - len += mul*typelens[type]; + len += mul * typelens[type]; alphalen += mul * alphalens[type]; } else { - len= 0; + len = 0; alphalen = 0; break; } } - if (len==0) { + if (len == 0) { unknown++; } else { - typelens[structtype]= len; - alphalens[structtype]= alphalen; + typelens[structtype] = len; + alphalens[structtype] = alphalen; // two ways to detect if a struct contains a pointer: // has_pointer is set or alphalen != len if (has_pointer || alphalen != len) { if (alphalen % 8) { - printf("Sizeerror 8 in struct: %s (add %d bytes)\n", types[structtype], alphalen%8); + printf("Sizeerror 8 in struct: %s (add %d bytes)\n", types[structtype], alphalen % 8); dna_error = 1; } } if (len % 4) { - printf("Sizeerror 4 in struct: %s (add %d bytes)\n", types[structtype], len%4); + printf("Sizeerror 4 in struct: %s (add %d bytes)\n", types[structtype], len % 4); dna_error = 1; } @@ -844,7 +844,7 @@ static int calculate_structlens(int firststruct) } } - if (unknown==lastunknown) break; + if (unknown == lastunknown) break; } if (unknown) { @@ -853,12 +853,12 @@ static int calculate_structlens(int firststruct) if (debugSDNA) { printf("*** Known structs :\n"); - for (a=0; a<nr_structs; a++) { - structpoin= structs[a]; - structtype= structpoin[0]; + for (a = 0; a < nr_structs; a++) { + structpoin = structs[a]; + structtype = structpoin[0]; /* length unknown */ - if (typelens[structtype]!=0) { + if (typelens[structtype] != 0) { printf(" %s\n", types[structtype]); } } @@ -867,12 +867,12 @@ static int calculate_structlens(int firststruct) printf("*** Unknown structs :\n"); - for (a=0; a<nr_structs; a++) { - structpoin= structs[a]; - structtype= structpoin[0]; + for (a = 0; a < nr_structs; a++) { + structpoin = structs[a]; + structtype = structpoin[0]; /* length unknown yet */ - if (typelens[structtype]==0) { + if (typelens[structtype] == 0) { printf(" %s\n", types[structtype]); } } @@ -893,7 +893,7 @@ void dna_write(FILE *file, void *pntr, int size) data = (char *) pntr; - for (i = 0 ; i < size ; i++) { + for (i = 0; i < size; i++) { fprintf(file, "%d, ", data[i]); linelength++; if (linelength >= MAX_DNA_LINE_LENGTH) { @@ -903,21 +903,21 @@ void dna_write(FILE *file, void *pntr, int size) } } -void printStructLenghts(void) +void printStructLengths(void) { - int a, unknown= nr_structs, structtype; + int a, unknown = nr_structs, structtype; /*int lastunknown;*/ /*UNUSED*/ short *structpoin; printf("\n\n*** All detected structs:\n"); while (unknown) { /*lastunknown= unknown;*/ /*UNUSED*/ - unknown= 0; + unknown = 0; /* check all structs... */ - for (a=0; a<nr_structs; a++) { - structpoin= structs[a]; - structtype= structpoin[0]; + for (a = 0; a < nr_structs; a++) { + structpoin = structs[a]; + structtype = structpoin[0]; printf("\t%s\t:%d\n", types[structtype], typelens[structtype]); } } @@ -942,32 +942,32 @@ static int make_structDNA(char *baseDirectory, FILE *file) } /* the longest known struct is 50k, so we assume 100k is sufficent! */ - namedata= MEM_callocN(maxdata, "namedata"); - typedata= MEM_callocN(maxdata, "typedata"); - structdata= MEM_callocN(maxdata, "structdata"); + namedata = MEM_callocN(maxdata, "namedata"); + typedata = MEM_callocN(maxdata, "typedata"); + structdata = MEM_callocN(maxdata, "structdata"); /* a maximum of 5000 variables, must be sufficient? */ - names= MEM_callocN(sizeof(char *)*maxnr, "names"); - types= MEM_callocN(sizeof(char *)*maxnr, "types"); - typelens= MEM_callocN(sizeof(short)*maxnr, "typelens"); - alphalens= MEM_callocN(sizeof(short)*maxnr, "alphalens"); - structs= MEM_callocN(sizeof(short)*maxnr, "structs"); + names = MEM_callocN(sizeof(char *) * maxnr, "names"); + types = MEM_callocN(sizeof(char *) * maxnr, "types"); + typelens = MEM_callocN(sizeof(short) * maxnr, "typelens"); + alphalens = MEM_callocN(sizeof(short) * maxnr, "alphalens"); + structs = MEM_callocN(sizeof(short) * maxnr, "structs"); /* insertion of all known types */ /* watch it: uint is not allowed! use in structs an unsigned int */ /* watch it: sizes must match DNA_elem_type_size() */ - add_type("char", 1); /* SDNA_TYPE_CHAR */ - add_type("uchar", 1); /* SDNA_TYPE_UCHAR */ - add_type("short", 2); /* SDNA_TYPE_SHORT */ - add_type("ushort", 2); /* SDNA_TYPE_USHORT */ - add_type("int", 4); /* SDNA_TYPE_INT */ - add_type("long", 4); /* SDNA_TYPE_LONG */ /* should it be 8 on 64 bits? */ - add_type("ulong", 4); /* SDNA_TYPE_ULONG */ - add_type("float", 4); /* SDNA_TYPE_FLOAT */ - add_type("double", 8); /* SDNA_TYPE_DOUBLE */ - add_type("int64_t", 8); /* SDNA_TYPE_INT64 */ + add_type("char", 1); /* SDNA_TYPE_CHAR */ + add_type("uchar", 1); /* SDNA_TYPE_UCHAR */ + add_type("short", 2); /* SDNA_TYPE_SHORT */ + add_type("ushort", 2); /* SDNA_TYPE_USHORT */ + add_type("int", 4); /* SDNA_TYPE_INT */ + add_type("long", 4); /* SDNA_TYPE_LONG */ /* should it be 8 on 64 bits? */ + add_type("ulong", 4); /* SDNA_TYPE_ULONG */ + add_type("float", 4); /* SDNA_TYPE_FLOAT */ + add_type("double", 8); /* SDNA_TYPE_DOUBLE */ + add_type("int64_t", 8); /* SDNA_TYPE_INT64 */ add_type("uint64_t", 8); /* SDNA_TYPE_UINT64 */ - add_type("void", 0); /* SDNA_TYPE_VOID */ + add_type("void", 0); /* SDNA_TYPE_VOID */ // the defines above shouldn't be output in the padding file... firststruct = nr_types; @@ -979,7 +979,7 @@ static int make_structDNA(char *baseDirectory, FILE *file) if (debugSDNA) printf("\tStart of header scan:\n"); for (i = 0; strlen(includefiles[i]); i++) { sprintf(str, "%s%s", baseDirectory, includefiles[i]); - if (debugSDNA) printf("\t|-- Converting %s\n", str); + if (debugSDNA) printf("\t|-- Converting %s\n", str); if (convert_include(str)) { return (1); } @@ -994,28 +994,28 @@ static int make_structDNA(char *baseDirectory, FILE *file) /* FOR DEBUG */ if (debugSDNA > 1) { int a, b; -/* short *elem; */ +/* short *elem; */ short num_types; printf("nr_names %d nr_types %d nr_structs %d\n", nr_names, nr_types, nr_structs); - for (a=0; a<nr_names; a++) { + for (a = 0; a < nr_names; a++) { printf(" %s\n", names[a]); } printf("\n"); - sp= typelens; - for (a=0; a<nr_types; a++, sp++) { + sp = typelens; + for (a = 0; a < nr_types; a++, sp++) { printf(" %s %d\n", types[a], *sp); } printf("\n"); - for (a=0; a<nr_structs; a++) { - sp= structs[a]; + for (a = 0; a < nr_structs; a++) { + sp = structs[a]; printf(" struct %s elems: %d size: %d\n", types[sp[0]], sp[1], typelens[sp[0]]); num_types = sp[1]; - sp+= 2; + sp += 2; /* ? num_types was elem? */ - for (b=0; b< num_types; b++, sp+= 2) { + for (b = 0; b < num_types; b++, sp += 2) { printf(" %s %s\n", types[sp[0]], names[sp[1]]); } } @@ -1025,7 +1025,7 @@ static int make_structDNA(char *baseDirectory, FILE *file) if (debugSDNA > -1) printf("Writing file ... "); - if (nr_names==0 || nr_structs==0); + if (nr_names == 0 || nr_structs == 0) ; else { strcpy(str, "SDNA"); dna_write(file, str, 4); @@ -1033,27 +1033,27 @@ static int make_structDNA(char *baseDirectory, FILE *file) /* write names */ strcpy(str, "NAME"); dna_write(file, str, 4); - len= nr_names; + len = nr_names; dna_write(file, &len, 4); /* calculate size of datablock with strings */ - cp= names[nr_names-1]; - cp+= strlen(names[nr_names-1]) + 1; /* +1: null-terminator */ - len= (intptr_t) (cp - (char*) names[0]); - len= (len+3) & ~3; + cp = names[nr_names - 1]; + cp += strlen(names[nr_names - 1]) + 1; /* +1: null-terminator */ + len = (intptr_t) (cp - (char *) names[0]); + len = (len + 3) & ~3; dna_write(file, names[0], len); /* write TYPES */ strcpy(str, "TYPE"); dna_write(file, str, 4); - len= nr_types; + len = nr_types; dna_write(file, &len, 4); /* calculate datablock size */ - cp= types[nr_types-1]; - cp+= strlen(types[nr_types-1]) + 1; /* +1: null-terminator */ - len= (intptr_t) (cp - (char*) types[0]); - len= (len+3) & ~3; + cp = types[nr_types - 1]; + cp += strlen(types[nr_types - 1]) + 1; /* +1: null-terminator */ + len = (intptr_t) (cp - (char *) types[0]); + len = (len + 3) & ~3; dna_write(file, types[0], len); @@ -1061,21 +1061,21 @@ static int make_structDNA(char *baseDirectory, FILE *file) strcpy(str, "TLEN"); dna_write(file, str, 4); - len= 2*nr_types; - if (nr_types & 1) len+= 2; + len = 2 * nr_types; + if (nr_types & 1) len += 2; dna_write(file, typelens, len); /* WRITE STRUCTS */ strcpy(str, "STRC"); dna_write(file, str, 4); - len= nr_structs; + len = nr_structs; dna_write(file, &len, 4); /* calc datablock size */ - sp= structs[nr_structs-1]; - sp+= 2+ 2*( sp[1] ); - len= (intptr_t) ((char*) sp - (char*) structs[0]); - len= (len+3) & ~3; + sp = structs[nr_structs - 1]; + sp += 2 + 2 * (sp[1]); + len = (intptr_t) ((char *) sp - (char *) structs[0]); + len = (len + 3) & ~3; dna_write(file, structs[0], len); @@ -1084,8 +1084,8 @@ static int make_structDNA(char *baseDirectory, FILE *file) FILE *fp; int a; - fp= fopen("padding.c", "w"); - if (fp==NULL); + fp = fopen("padding.c", "w"); + if (fp == NULL) ; else { // add all include files defined in the global array @@ -1096,7 +1096,7 @@ static int make_structDNA(char *baseDirectory, FILE *file) fprintf(fp, "main() {\n"); sp = typelens; sp += firststruct; - for (a=firststruct; a<nr_types; a++, sp++) { + for (a = firststruct; a < nr_types; a++, sp++) { if (*sp) { fprintf(fp, "\tif (sizeof(struct %s) - %d) printf(\"ALIGN ERROR:", types[a], *sp); fprintf(fp, "%%d %s %d ", types[a], *sp); @@ -1129,7 +1129,7 @@ static int make_structDNA(char *baseDirectory, FILE *file) static void make_bad_file(const char *file, int line) { - FILE *fp= fopen(file, "w"); + FILE *fp = fopen(file, "w"); fprintf(fp, "#error \"Error! can't make correct DNA.c file from %s:%d, STUPID!\"\n", __FILE__, line); fclose(fp); } @@ -1138,32 +1138,32 @@ static void make_bad_file(const char *file, int line) #define BASE_HEADER "../" #endif -int main(int argc, char ** argv) +int main(int argc, char **argv) { FILE *file; int return_status = 0; - if (argc!=2 && argc!=3) { + if (argc != 2 && argc != 3) { printf("Usage: %s outfile.c [base directory]\n", argv[0]); return_status = 1; } else { file = fopen(argv[1], "w"); if (!file) { - printf ("Unable to open file: %s\n", argv[1]); + printf("Unable to open file: %s\n", argv[1]); return_status = 1; } else { char baseDirectory[256]; - if (argc==3) { + if (argc == 3) { strcpy(baseDirectory, argv[2]); } else { strcpy(baseDirectory, BASE_HEADER); } - fprintf (file, "unsigned char DNAstr[]= {\n"); + fprintf(file, "unsigned char DNAstr[]= {\n"); if (make_structDNA(baseDirectory, file)) { // error fclose(file); |