Merge branch 'blender2.7'
[blender.git] / source / blender / makesdna / intern / makesdna.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup DNA
22  *
23  * \brief Struct muncher for making SDNA.
24  *
25  * \section aboutmakesdnac About makesdna tool
26  * Originally by Ton, some mods by Frank, and some cleaning and
27  * extension by Nzc.
28  *
29  * Makesdna creates a .c file with a long string of numbers that
30  * encode the Blender file format. It is fast, because it is basically
31  * a binary dump. There are some details to mind when reconstructing
32  * the file (endianness and byte-alignment).
33  *
34  * This little program scans all structs that need to be serialized,
35  * and determined the names and types of all members. It calculates
36  * how much memory (on disk or in ram) is needed to store that struct,
37  * and the offsets for reaching a particular one.
38  *
39  * There is a facility to get verbose output from sdna. Search for
40  * \ref debugSDNA. This int can be set to 0 (no output) to some int. Higher
41  * numbers give more output.
42  */
43
44 #include <string.h>
45 #include <stdlib.h>
46 #include <stdio.h>
47 #include <assert.h>
48
49 #include "MEM_guardedalloc.h"
50
51 #include "BLI_utildefines.h"
52 #include "BLI_alloca.h"
53 #include "BLI_ghash.h"
54 #include "BLI_memarena.h"
55 #include "BLI_sys_types.h"  /* for intptr_t support */
56
57 #include "dna_utils.h"
58
59 #define SDNA_MAX_FILENAME_LENGTH 255
60
61 /* Included the path relative from /source/blender/ here, so we can move     */
62 /* headers around with more freedom.                                         */
63 static const char *includefiles[] = {
64
65         /* if you add files here, please add them at the end
66          * of makesdna.c (this file) as well */
67         "DNA_listBase.h",
68         "DNA_vec_types.h",
69         "DNA_ID.h",
70         "DNA_ipo_types.h",
71         "DNA_key_types.h",
72         "DNA_text_types.h",
73         "DNA_packedFile_types.h",
74         "DNA_gpu_types.h",
75         "DNA_camera_types.h",
76         "DNA_image_types.h",
77         "DNA_texture_types.h",
78         "DNA_light_types.h",
79         "DNA_material_types.h",
80         "DNA_vfont_types.h",
81         "DNA_meta_types.h",
82         "DNA_curve_types.h",
83         "DNA_mesh_types.h",
84         "DNA_meshdata_types.h",
85         "DNA_modifier_types.h",
86         "DNA_lattice_types.h",
87         "DNA_object_types.h",
88         "DNA_object_force_types.h",
89         "DNA_object_fluidsim_types.h",
90         "DNA_world_types.h",
91         "DNA_scene_types.h",
92         "DNA_view3d_types.h",
93         "DNA_view2d_types.h",
94         "DNA_space_types.h",
95         "DNA_userdef_types.h",
96         "DNA_screen_types.h",
97         "DNA_sdna_types.h",
98         "DNA_fileglobal_types.h",
99         "DNA_sequence_types.h",
100         "DNA_effect_types.h",
101         "DNA_outliner_types.h",
102         "DNA_sound_types.h",
103         "DNA_collection_types.h",
104         "DNA_armature_types.h",
105         "DNA_action_types.h",
106         "DNA_constraint_types.h",
107         "DNA_nla_types.h",
108         "DNA_node_types.h",
109         "DNA_color_types.h",
110         "DNA_brush_types.h",
111         "DNA_customdata_types.h",
112         "DNA_particle_types.h",
113         "DNA_cloth_types.h",
114         "DNA_gpencil_types.h",
115         "DNA_gpencil_modifier_types.h",
116         "DNA_shader_fx_types.h",
117         "DNA_windowmanager_types.h",
118         "DNA_anim_types.h",
119         "DNA_boid_types.h",
120         "DNA_smoke_types.h",
121         "DNA_speaker_types.h",
122         "DNA_movieclip_types.h",
123         "DNA_tracking_types.h",
124         "DNA_dynamicpaint_types.h",
125         "DNA_mask_types.h",
126         "DNA_rigidbody_types.h",
127         "DNA_freestyle_types.h",
128         "DNA_linestyle_types.h",
129         "DNA_cachefile_types.h",
130         "DNA_layer_types.h",
131         "DNA_workspace_types.h",
132         "DNA_lightprobe_types.h",
133
134         /* see comment above before editing! */
135
136         /* empty string to indicate end of includefiles */
137         "",
138 };
139
140 /* -------------------------------------------------------------------- */
141 /** \name Variables
142  * \{ */
143
144 static MemArena *mem_arena = NULL;
145
146 static int maxdata = 500000, maxnr = 50000;
147 static int nr_names = 0;
148 static int nr_types = 0;
149 static int nr_structs = 0;
150 /** at address names[a] is string a */
151 static char **names;
152 /** at address types[a] is string a */
153 static char **types;
154 /** at typelens[a] is the length of type 'a' on this systems bitness (32 or 64) */
155 static short *typelens_native;
156 /** contains sizes as they are calculated on 32 bit systems */
157 static short *typelens_32;
158 /** contains sizes as they are calculated on 64 bit systems */
159 static short *typelens_64;
160 /** at sp = structs[a] is the first address of a struct definition
161  * sp[0] is type number
162  * sp[1] is amount of elements
163  * sp[2] sp[3] is typenr,  namenr (etc) */
164 static short **structs, *structdata;
165
166 /** Versioning data */
167 static struct {
168         GHash *struct_map_alias_from_static;
169         GHash *struct_map_static_from_alias;
170         GHash *elem_map_static_from_alias;
171 } g_version_data = {NULL};
172
173 /**
174  * Variable to control debug output of makesdna.
175  * debugSDNA:
176  * - 0 = no output, except errors
177  * - 1 = detail actions
178  * - 2 = full trace, tell which names and types were found
179  * - 4 = full trace, plus all gritty details
180  */
181 static int debugSDNA = 0;
182 static int additional_slen_offset;
183
184 #define DEBUG_PRINTF(debug_level, ...) \
185         { if (debugSDNA > debug_level) { printf(__VA_ARGS__); } } ((void)0)
186
187
188 /* stub for BLI_abort() */
189 #ifndef NDEBUG
190 void BLI_system_backtrace(FILE *fp)
191 {
192        (void)fp;
193 }
194 #endif
195
196 /** \} */
197
198 /* -------------------------------------------------------------------- */
199 /** \name Function Declarations
200  * \{ */
201
202 /**
203  * Ensure type \c str to is in the #types array.
204  * \param str: Struct name without any qualifiers.
205  * \param len: The struct size in bytes.
206  * \return Index in the #types array.
207  */
208 static int add_type(const char *str, int len);
209
210 /**
211  * Ensure \c str is int the #names array.
212  * \param str: Struct member name which may include pointer prefix & array size.
213  * \return Index in the #names array.
214  */
215 static int add_name(const char *str);
216
217 /**
218  * Search whether this structure type was already found, and if not,
219  * add it.
220  */
221 static short *add_struct(int namecode);
222
223 /**
224  * Remove comments from this buffer. Assumes that the buffer refers to
225  * ascii-code text.
226  */
227 static int preprocess_include(char *maindata, int len);
228
229 /**
230  * Scan this file for serializable types.
231  */
232 static int convert_include(const char *filename);
233
234 /**
235  * Determine how many bytes are needed for each struct.
236  */
237 static int calculate_structlens(int);
238
239 /**
240  * Construct the DNA.c file
241  */
242 static void dna_write(FILE *file, const void *pntr, const int size);
243
244 /**
245  * Report all structures found so far, and print their lengths.
246  */
247 void printStructLengths(void);
248
249 /** \} */
250
251 /* -------------------------------------------------------------------- */
252 /** \name Implementation
253  *
254  * Make DNA string (write to file).
255  * \{ */
256
257
258 static const char *version_struct_static_from_alias(const char *str)
259 {
260         const char *str_test = BLI_ghash_lookup(g_version_data.struct_map_static_from_alias, str);
261         if (str_test != NULL) {
262                 return str_test;
263         }
264         return str;
265 }
266
267 static const char *version_struct_alias_from_static(const char *str)
268 {
269         const char *str_test = BLI_ghash_lookup(g_version_data.struct_map_alias_from_static, str);
270         if (str_test != NULL) {
271                 return str_test;
272         }
273         return str;
274 }
275
276 static const char *version_elem_static_from_alias(
277         const int strct, const char *elem_alias_full)
278 {
279         const uint elem_alias_full_len = strlen(elem_alias_full);
280         char *elem_alias = alloca(elem_alias_full_len + 1);
281         const int elem_alias_len = DNA_elem_id_strip_copy(elem_alias, elem_alias_full);
282         const char *str_pair[2] = {types[strct], elem_alias};
283         const char *elem_static = BLI_ghash_lookup(g_version_data.elem_map_static_from_alias, str_pair);
284         if (elem_static != NULL) {
285                 return DNA_elem_id_rename(
286                         mem_arena,
287                         elem_alias, elem_alias_len,
288                         elem_static, strlen(elem_static),
289                         elem_alias_full, elem_alias_full_len,
290                         DNA_elem_id_offset_start(elem_alias_full));
291         }
292         return elem_alias_full;
293 }
294
295 /**
296  * Enforce '_pad123' naming convention, disallow 'pad123' or 'pad_123',
297  * special exception for [a-z] after since there is a 'pad_rot_angle' preference.
298  */
299 static bool is_name_legal(const char *name)
300 {
301         const int name_size = strlen(name) + 1;
302         char *name_strip = alloca(name_size);
303         DNA_elem_id_strip_copy(name_strip, name);
304
305         const char prefix[] = {'p', 'a', 'd'};
306
307         if (name[0] == '_') {
308                 if (strncmp(&name_strip[1], prefix, sizeof(prefix)) != 0) {
309                         fprintf(stderr, "Error: only '_pad' variables can start with an underscore, found '%s'\n", name);
310                         return false;
311                 }
312         }
313         else if (strncmp(name_strip, prefix, sizeof(prefix)) == 0) {
314                 int i = sizeof(prefix);
315                 if (name_strip[i] >= 'a' && name_strip[i] <= 'z') {
316                         /* may be part of a word, allow that. */
317                         return true;
318                 }
319                 bool has_only_digit_or_none = true;
320                 for (; name_strip[i]; i++) {
321                         const char c = name_strip[i];
322                         if (!((c >= '0' && c <= '9') || c == '_')) {
323                                 has_only_digit_or_none = false;
324                                 break;
325                         }
326                 }
327                 if (has_only_digit_or_none) {
328                         /* found 'pad' or 'pad123'. */
329                         fprintf(stderr, "Error: padding variables must be formatted '_pad[number]', found '%s'\n", name);
330                         return false;
331                 }
332         }
333         return true;
334 }
335
336
337 static int add_type(const char *str, int len)
338 {
339         int nr;
340         char *cp;
341
342         /* first do validity check */
343         if (str[0] == 0) {
344                 return -1;
345         }
346         else if (strchr(str, '*')) {
347                 /* note: this is valid C syntax but we can't parse, complain!
348                  * 'struct SomeStruct* somevar;' <-- correct but we cant handle right now. */
349                 return -1;
350         }
351
352         str = version_struct_static_from_alias(str);
353
354         /* search through type array */
355         for (nr = 0; nr < nr_types; nr++) {
356                 if (strcmp(str, types[nr]) == 0) {
357                         if (len) {
358                                 typelens_native[nr] = len;
359                                 typelens_32[nr] = len;
360                                 typelens_64[nr] = len;
361                         }
362                         return nr;
363                 }
364         }
365
366         /* append new type */
367         const int str_size = strlen(str) + 1;
368         cp = BLI_memarena_alloc(mem_arena, str_size);
369         memcpy(cp, str, str_size);
370         types[nr_types] = cp;
371         typelens_native[nr_types] = len;
372         typelens_32[nr_types] = len;
373         typelens_64[nr_types] = len;
374
375         if (nr_types >= maxnr) {
376                 printf("too many types\n");
377                 return nr_types - 1;
378         }
379         nr_types++;
380
381         return nr_types - 1;
382 }
383
384
385 /**
386  *
387  * Because of the weird way of tokenizing, we have to 'cast' function
388  * pointers to ... (*f)(), whatever the original signature. In fact,
389  * we add name and type at the same time... There are two special
390  * cases, unfortunately. These are explicitly checked.
391  *
392  * */
393 static int add_name(const char *str)
394 {
395         int nr, i, j, k;
396         char *cp;
397         char buf[255]; /* stupid limit, change it :) */
398         const char *name;
399
400         additional_slen_offset = 0;
401
402         if (str[0] == 0 /*  || (str[1] == 0) */) return -1;
403
404         if (str[0] == '(' && str[1] == '*') {
405                 /* we handle function pointer and special array cases here, e.g.
406                  * void (*function)(...) and float (*array)[..]. the array case
407                  * name is still converted to (array *)() though because it is that
408                  * way in old dna too, and works correct with elementsize() */
409                 int isfuncptr = (strchr(str + 1, '(')) != NULL;
410
411                 DEBUG_PRINTF(3, "\t\t\t\t*** Function pointer or multidim array pointer found\n");
412                 /* functionpointer: transform the type (sometimes) */
413                 i = 0;
414
415                 while (str[i] != ')') {
416                         buf[i] = str[i];
417                         i++;
418                 }
419
420                 /* Another number we need is the extra slen offset. This extra
421                  * offset is the overshoot after a space. If there is no
422                  * space, no overshoot should be calculated. */
423                 j = i; /* j at first closing brace */
424
425                 DEBUG_PRINTF(3, "first brace after offset %d\n", i);
426
427                 j++; /* j beyond closing brace ? */
428                 while ((str[j] != 0) && (str[j] != ')')) {
429                         DEBUG_PRINTF(3, "seen %c (%d)\n", str[j], str[j]);
430                         j++;
431                 }
432                 DEBUG_PRINTF(3, "seen %c (%d)\n" "special after offset%d\n", str[j], str[j], j);
433
434                 if (!isfuncptr) {
435                         /* multidimensional array pointer case */
436                         if (str[j] == 0) {
437                                 DEBUG_PRINTF(3, "offsetting for multidim array pointer\n");
438                         }
439                         else
440                                 printf("Error during tokening multidim array pointer\n");
441                 }
442                 else if (str[j] == 0) {
443                         DEBUG_PRINTF(3, "offsetting for space\n");
444                         /* get additional offset */
445                         k = 0;
446                         while (str[j] != ')') {
447                                 j++;
448                                 k++;
449                         }
450                         DEBUG_PRINTF(3, "extra offset %d\n", k);
451                         additional_slen_offset = k;
452                 }
453                 else if (str[j] == ')') {
454                         DEBUG_PRINTF(3, "offsetting for brace\n");
455                         ; /* don't get extra offset */
456                 }
457                 else {
458                         printf("Error during tokening function pointer argument list\n");
459                 }
460
461                 /*
462                  * Put )(void) at the end? Maybe )(). Should check this with
463                  * old sdna. Actually, sometimes )(), sometimes )(void...)
464                  * Alas.. such is the nature of braindamage :(
465                  *
466                  * Sorted it out: always do )(), except for headdraw and
467                  * windraw, part of ScrArea. This is important, because some
468                  * linkers will treat different fp's differently when called
469                  * !!! This has to do with interference in byte-alignment and
470                  * the way args are pushed on the stack.
471                  *
472                  * */
473                 buf[i] = 0;
474                 DEBUG_PRINTF(3, "Name before chomping: %s\n", buf);
475                 if ((strncmp(buf, "(*headdraw", 10) == 0) ||
476                     (strncmp(buf, "(*windraw", 9) == 0) )
477                 {
478                         buf[i] = ')';
479                         buf[i + 1] = '(';
480                         buf[i + 2] = 'v';
481                         buf[i + 3] = 'o';
482                         buf[i + 4] = 'i';
483                         buf[i + 5] = 'd';
484                         buf[i + 6] = ')';
485                         buf[i + 7] = 0;
486                 }
487                 else {
488                         buf[i] = ')';
489                         buf[i + 1] = '(';
490                         buf[i + 2] = ')';
491                         buf[i + 3] = 0;
492                 }
493                 /* now precede with buf*/
494                 DEBUG_PRINTF(3, "\t\t\t\t\tProposing fp name %s\n", buf);
495                 name = buf;
496         }
497         else {
498                 /* normal field: old code */
499                 name = str;
500         }
501
502         /* search name array */
503         for (nr = 0; nr < nr_names; nr++) {
504                 if (strcmp(name, names[nr]) == 0) {
505                         return nr;
506                 }
507         }
508
509         /* Sanity check the name. */
510         if (!is_name_legal(name)) {
511                 return -1;
512         }
513
514         /* Append new name. */
515         const int name_size = strlen(name) + 1;
516         cp = BLI_memarena_alloc(mem_arena, name_size);
517         memcpy(cp, name, name_size);
518         names[nr_names] = cp;
519
520         if (nr_names >= maxnr) {
521                 printf("too many names\n");
522                 return nr_names - 1;
523         }
524         nr_names++;
525
526         return nr_names - 1;
527 }
528
529 static short *add_struct(int namecode)
530 {
531         int len;
532         short *sp;
533
534         if (nr_structs == 0) {
535                 structs[0] = structdata;
536         }
537         else {
538                 sp = structs[nr_structs - 1];
539                 len = sp[1];
540                 structs[nr_structs] = sp + 2 * len + 2;
541         }
542
543         sp = structs[nr_structs];
544         sp[0] = namecode;
545
546         if (nr_structs >= maxnr) {
547                 printf("too many structs\n");
548                 return sp;
549         }
550         nr_structs++;
551
552         return sp;
553 }
554
555 static int preprocess_include(char *maindata, int len)
556 {
557         int a, newlen, comment = 0;
558         char *cp, *temp, *md;
559
560         /* note: len + 1, last character is a dummy to prevent
561          * comparisons using uninitialized memory */
562         temp = MEM_mallocN(len + 1, "preprocess_include");
563         temp[len] = ' ';
564
565         memcpy(temp, maindata, len);
566
567         /* remove all c++ comments */
568         /* replace all enters/tabs/etc with spaces */
569         cp = temp;
570         a = len;
571         comment = 0;
572         while (a--) {
573                 if (cp[0] == '/' && cp[1] == '/') {
574                         comment = 1;
575                 }
576                 else if (*cp == '\n') {
577                         comment = 0;
578                 }
579                 if (comment || *cp < 32 || *cp > 128) *cp = 32;
580                 cp++;
581         }
582
583
584         /* data from temp copy to maindata, remove comments and double spaces */
585         cp = temp;
586         md = maindata;
587         newlen = 0;
588         comment = 0;
589         a = len;
590         while (a--) {
591
592                 if (cp[0] == '/' && cp[1] == '*') {
593                         comment = 1;
594                         cp[0] = cp[1] = 32;
595                 }
596                 if (cp[0] == '*' && cp[1] == '/') {
597                         comment = 0;
598                         cp[0] = cp[1] = 32;
599                 }
600
601                 /* do not copy when: */
602                 if (comment) {
603                         /* pass */
604                 }
605                 else if (cp[0] == ' ' && cp[1] == ' ') {
606                         /* pass */
607                 }
608                 else if (cp[-1] == '*' && cp[0] == ' ') {
609                         /* pointers with a space */
610                 }       /* skip special keywords */
611                 else if (strncmp("DNA_DEPRECATED", cp, 14) == 0) {
612                         /* single values are skipped already, so decrement 1 less */
613                         a -= 13;
614                         cp += 13;
615                 }
616                 else if (strncmp("DNA_PRIVATE_WORKSPACE", cp, 21) == 0) {
617                         /* Check for DNA_PRIVATE_WORKSPACE_READ_WRITE */
618                         if (strncmp("_READ_WRITE", cp + 21, 11) == 0) {
619                                 a -= 31;
620                                 cp += 31;
621                         }
622                         else {
623                                 a -= 20;
624                                 cp += 20;
625                         }
626                 }
627                 else {
628                         md[0] = cp[0];
629                         md++;
630                         newlen++;
631                 }
632                 cp++;
633         }
634
635         MEM_freeN(temp);
636         return newlen;
637 }
638
639 static void *read_file_data(const char *filename, int *r_len)
640 {
641 #ifdef WIN32
642         FILE *fp = fopen(filename, "rb");
643 #else
644         FILE *fp = fopen(filename, "r");
645 #endif
646         void *data;
647
648         if (!fp) {
649                 *r_len = -1;
650                 return NULL;
651         }
652
653         fseek(fp, 0L, SEEK_END);
654         *r_len = ftell(fp);
655         fseek(fp, 0L, SEEK_SET);
656
657         if (*r_len == -1) {
658                 fclose(fp);
659                 return NULL;
660         }
661
662         data = MEM_mallocN(*r_len, "read_file_data");
663         if (!data) {
664                 *r_len = -1;
665                 fclose(fp);
666                 return NULL;
667         }
668
669         if (fread(data, *r_len, 1, fp) != 1) {
670                 *r_len = -1;
671                 MEM_freeN(data);
672                 fclose(fp);
673                 return NULL;
674         }
675
676         fclose(fp);
677         return data;
678 }
679
680 static int convert_include(const char *filename)
681 {
682         /* read include file, skip structs with a '#' before it.
683          * store all data in temporal arrays.
684          */
685         int filelen, count, slen, type, name, strct;
686         short *structpoin, *sp;
687         char *maindata, *mainend, *md, *md1;
688         bool skip_struct;
689
690         md = maindata = read_file_data(filename, &filelen);
691         if (filelen == -1) {
692                 fprintf(stderr, "Can't read file %s\n", filename);
693                 return 1;
694         }
695
696         filelen = preprocess_include(maindata, filelen);
697         mainend = maindata + filelen - 1;
698
699         /* we look for '{' and then back to 'struct' */
700         count = 0;
701         skip_struct = false;
702         while (count < filelen) {
703
704                 /* code for skipping a struct: two hashes on 2 lines. (preprocess added a space) */
705                 if (md[0] == '#' && md[1] == ' ' && md[2] == '#') {
706                         skip_struct = true;
707                 }
708
709                 if (md[0] == '{') {
710                         md[0] = 0;
711                         if (skip_struct) {
712                                 skip_struct = false;
713                         }
714                         else {
715                                 if (md[-1] == ' ') md[-1] = 0;
716                                 md1 = md - 2;
717                                 while (*md1 != 32) md1--;       /* to beginning of word */
718                                 md1++;
719
720                                 /* we've got a struct name when... */
721                                 if (strncmp(md1 - 7, "struct", 6) == 0) {
722
723                                         strct = add_type(md1, 0);
724                                         if (strct == -1) {
725                                                 fprintf(stderr, "File '%s' contains struct we cant parse \"%s\"\n", filename, md1);
726                                                 return 1;
727                                         }
728
729                                         structpoin = add_struct(strct);
730                                         sp = structpoin + 2;
731
732                                         DEBUG_PRINTF(1, "\t|\t|-- detected struct %s\n", types[strct]);
733
734                                         /* first lets make it all nice strings */
735                                         md1 = md + 1;
736                                         while (*md1 != '}') {
737                                                 if (md1 > mainend) break;
738
739                                                 if (*md1 == ',' || *md1 == ' ') *md1 = 0;
740                                                 md1++;
741                                         }
742
743                                         /* read types and names until first character that is not '}' */
744                                         md1 = md + 1;
745                                         while (*md1 != '}') {
746                                                 if (md1 > mainend) break;
747
748                                                 /* skip when it says 'struct' or 'unsigned' or 'const' */
749                                                 if (*md1) {
750                                                         if (strncmp(md1, "struct", 6) == 0) md1 += 7;
751                                                         if (strncmp(md1, "unsigned", 8) == 0) md1 += 9;
752                                                         if (strncmp(md1, "const", 5) == 0) md1 += 6;
753
754                                                         /* we've got a type! */
755                                                         type = add_type(md1, 0);
756                                                         if (type == -1) {
757                                                                 fprintf(stderr, "File '%s' contains struct we can't parse \"%s\"\n", filename, md1);
758                                                                 return 1;
759                                                         }
760
761                                                         DEBUG_PRINTF(1, "\t|\t|\tfound type %s (", md1);
762
763                                                         md1 += strlen(md1);
764
765
766                                                         /* read until ';' */
767                                                         while (*md1 != ';') {
768                                                                 if (md1 > mainend) break;
769
770                                                                 if (*md1) {
771                                                                         /* We've got a name. slen needs
772                                                                          * correction for function
773                                                                          * pointers! */
774                                                                         slen = (int) strlen(md1);
775                                                                         if (md1[slen - 1] == ';') {
776                                                                                 md1[slen - 1] = 0;
777
778                                                                                 name = add_name(version_elem_static_from_alias(strct, md1));
779                                                                                 if (name == -1) {
780                                                                                         fprintf(stderr, "File '%s' contains struct with name that can't be added \"%s\"\n", filename, md1);
781                                                                                         return 1;
782                                                                                 }
783                                                                                 slen += additional_slen_offset;
784                                                                                 sp[0] = type;
785                                                                                 sp[1] = name;
786
787                                                                                 if (names[name] != NULL) {
788                                                                                         DEBUG_PRINTF(1, "%s |", names[name]);
789                                                                                 }
790
791                                                                                 structpoin[1]++;
792                                                                                 sp += 2;
793
794                                                                                 md1 += slen;
795                                                                                 break;
796                                                                         }
797
798                                                                         name = add_name(version_elem_static_from_alias(strct, md1));
799                                                                         if (name == -1) {
800                                                                                 fprintf(stderr, "File '%s' contains struct with name that can't be added \"%s\"\n", filename, md1);
801                                                                                 return 1;
802                                                                         }
803                                                                         slen += additional_slen_offset;
804
805                                                                         sp[0] = type;
806                                                                         sp[1] = name;
807                                                                         if (names[name] != NULL) {
808                                                                                 DEBUG_PRINTF(1, "%s ||", names[name]);
809                                                                         }
810
811                                                                         structpoin[1]++;
812                                                                         sp += 2;
813
814                                                                         md1 += slen;
815                                                                 }
816                                                                 md1++;
817                                                         }
818
819                                                         DEBUG_PRINTF(1, ")\n");
820
821                                                 }
822                                                 md1++;
823                                         }
824                                 }
825                         }
826                 }
827                 count++;
828                 md++;
829         }
830
831         MEM_freeN(maindata);
832
833         return 0;
834 }
835
836 static bool check_field_alignment(int firststruct, int structtype, int type, int len,
837                                   const char *name, const char *detail)
838 {
839         bool result = true;
840         if (type < firststruct && typelens_native[type] > 4 && (len % 8)) {
841                 fprintf(stderr, "Align 8 error (%s) in struct: %s %s (add %d padding bytes)\n",
842                         detail, types[structtype], name, len % 8);
843                 result = false;
844         }
845         if (typelens_native[type] > 3 && (len % 4) ) {
846                 fprintf(stderr, "Align 4 error (%s) in struct: %s %s (add %d padding bytes)\n",
847                         detail, types[structtype], name, len % 4);
848                 result = false;
849         }
850         if (typelens_native[type] == 2 && (len % 2) ) {
851                 fprintf(stderr, "Align 2 error (%s) in struct: %s %s (add %d padding bytes)\n",
852                         detail, types[structtype], name, len % 2);
853                 result = false;
854         }
855         return result;
856 }
857
858 static int calculate_structlens(int firststruct)
859 {
860         int unknown = nr_structs, lastunknown;
861         bool dna_error = false;
862
863         while (unknown) {
864                 lastunknown = unknown;
865                 unknown = 0;
866
867                 /* check all structs... */
868                 for (int a = 0; a < nr_structs; a++) {
869                         const short *structpoin = structs[a];
870                         const int    structtype = structpoin[0];
871
872                         /* when length is not known... */
873                         if (typelens_native[structtype] == 0) {
874
875                                 const short *sp = structpoin + 2;
876                                 int len_native = 0;
877                                 int len_32 = 0;
878                                 int len_64 = 0;
879                                 bool has_pointer = false;
880
881                                 /* check all elements in struct */
882                                 for (int b = 0; b < structpoin[1]; b++, sp += 2) {
883                                         int type = sp[0];
884                                         const char *cp = names[sp[1]];
885
886                                         int namelen = (int)strlen(cp);
887                                         /* is it a pointer or function pointer? */
888                                         if (cp[0] == '*' || cp[1] == '*') {
889                                                 has_pointer = 1;
890                                                 /* has the name an extra length? (array) */
891                                                 int mul = 1;
892                                                 if (cp[namelen - 1] == ']') {
893                                                         mul = DNA_elem_array_size(cp);
894                                                 }
895
896                                                 if (mul == 0) {
897                                                         fprintf(stderr, "Zero array size found or could not parse %s: '%.*s'\n",
898                                                                 types[structtype], namelen + 1, cp);
899                                                         dna_error = 1;
900                                                 }
901
902                                                 /* 4-8 aligned/ */
903                                                 if (sizeof(void *) == 4) {
904                                                         if (len_native % 4) {
905                                                                 fprintf(stderr, "Align pointer error in struct (len_native 4): %s %s\n",
906                                                                         types[structtype], cp);
907                                                                 dna_error = 1;
908                                                         }
909                                                 }
910                                                 else {
911                                                         if (len_native % 8) {
912                                                                 fprintf(stderr, "Align pointer error in struct (len_native 8): %s %s\n",
913                                                                         types[structtype], cp);
914                                                                 dna_error = 1;
915                                                         }
916                                                 }
917
918                                                 if (len_64 % 8) {
919                                                         fprintf(stderr, "Align pointer error in struct (len_64 8): %s %s\n",
920                                                                 types[structtype], cp);
921                                                         dna_error = 1;
922                                                 }
923
924                                                 len_native += sizeof(void *) * mul;
925                                                 len_32 += 4 * mul;
926                                                 len_64 += 8 * mul;
927
928                                         }
929                                         else if (cp[0] == '[') {
930                                                 /* parsing can cause names "var" and "[3]"
931                                                  * to be found for "float var [3]" */
932                                                 fprintf(stderr, "Parse error in struct, invalid member name: %s %s\n",
933                                                         types[structtype], cp);
934                                                 dna_error = 1;
935                                         }
936                                         else if (typelens_native[type]) {
937                                                 /* has the name an extra length? (array) */
938                                                 int mul = 1;
939                                                 if (cp[namelen - 1] == ']') {
940                                                         mul = DNA_elem_array_size(cp);
941                                                 }
942
943                                                 if (mul == 0) {
944                                                         fprintf(stderr, "Zero array size found or could not parse %s: '%.*s'\n",
945                                                                 types[structtype], namelen + 1, cp);
946                                                         dna_error = 1;
947                                                 }
948
949                                                 /* struct alignment */
950                                                 if (type >= firststruct) {
951                                                         if (sizeof(void *) == 8 && (len_native % 8) ) {
952                                                                 fprintf(stderr, "Align struct error: %s %s\n",
953                                                                         types[structtype], cp);
954                                                                 dna_error = 1;
955                                                         }
956                                                 }
957
958                                                 /* Check 2-4-8 aligned. */
959                                                 if (!check_field_alignment(firststruct, structtype, type, len_32, cp, "32 bit")) {
960                                                         dna_error = 1;
961                                                 }
962                                                 if (!check_field_alignment(firststruct, structtype, type, len_64, cp, "64 bit")) {
963                                                         dna_error = 1;
964                                                 }
965
966                                                 len_native += mul * typelens_native[type];
967                                                 len_32 += mul * typelens_32[type];
968                                                 len_64 += mul * typelens_64[type];
969
970                                         }
971                                         else {
972                                                 len_native = 0;
973                                                 len_32 = 0;
974                                                 len_64 = 0;
975                                                 break;
976                                         }
977                                 }
978
979                                 if (len_native == 0) {
980                                         unknown++;
981                                 }
982                                 else {
983                                         typelens_native[structtype] = len_native;
984                                         typelens_32[structtype] = len_32;
985                                         typelens_64[structtype] = len_64;
986                                         /* two ways to detect if a struct contains a pointer:
987                                          * has_pointer is set or len_native  doesn't match any of 32/64bit lengths*/
988                                         if (has_pointer || len_64 != len_native || len_32 != len_native) {
989                                                 if (len_64 % 8) {
990                                                         fprintf(stderr, "Sizeerror 8 in struct: %s (add %d bytes)\n",
991                                                                 types[structtype], len_64 % 8);
992                                                         dna_error = 1;
993                                                 }
994                                         }
995
996                                         if (len_native % 4) {
997                                                 fprintf(stderr, "Sizeerror 4 in struct: %s (add %d bytes)\n",
998                                                        types[structtype], len_native % 4);
999                                                 dna_error = 1;
1000                                         }
1001
1002                                 }
1003                         }
1004                 }
1005
1006                 if (unknown == lastunknown) break;
1007         }
1008
1009         if (unknown) {
1010                 fprintf(stderr, "ERROR: still %d structs unknown\n", unknown);
1011
1012                 if (debugSDNA) {
1013                         fprintf(stderr, "*** Known structs :\n");
1014
1015                         for (int a = 0; a < nr_structs; a++) {
1016                                 const short *structpoin = structs[a];
1017                                 const int    structtype = structpoin[0];
1018
1019                                 /* length unknown */
1020                                 if (typelens_native[structtype] != 0) {
1021                                         fprintf(stderr, "  %s\n", types[structtype]);
1022                                 }
1023                         }
1024                 }
1025
1026
1027                 fprintf(stderr, "*** Unknown structs :\n");
1028
1029                 for (int a = 0; a < nr_structs; a++) {
1030                         const short *structpoin = structs[a];
1031                         const int    structtype = structpoin[0];
1032
1033                         /* length unknown yet */
1034                         if (typelens_native[structtype] == 0) {
1035                                 fprintf(stderr, "  %s\n", types[structtype]);
1036                         }
1037                 }
1038
1039                 dna_error = 1;
1040         }
1041
1042         return dna_error;
1043 }
1044
1045 #define MAX_DNA_LINE_LENGTH 20
1046
1047 static void dna_write(FILE *file, const void *pntr, const int size)
1048 {
1049         static int linelength = 0;
1050         int i;
1051         const char *data;
1052
1053         data = (const char *)pntr;
1054
1055         for (i = 0; i < size; i++) {
1056                 fprintf(file, "%d, ", data[i]);
1057                 linelength++;
1058                 if (linelength >= MAX_DNA_LINE_LENGTH) {
1059                         fprintf(file, "\n");
1060                         linelength = 0;
1061                 }
1062         }
1063 }
1064
1065 void printStructLengths(void)
1066 {
1067         int a, unknown = nr_structs, structtype;
1068         /*int lastunknown;*/ /*UNUSED*/
1069         const short *structpoin;
1070         printf("\n\n*** All detected structs:\n");
1071
1072         while (unknown) {
1073                 /*lastunknown = unknown;*/ /*UNUSED*/
1074                 unknown = 0;
1075
1076                 /* check all structs... */
1077                 for (a = 0; a < nr_structs; a++) {
1078                         structpoin = structs[a];
1079                         structtype = structpoin[0];
1080                         printf("\t%s\t:%d\n", types[structtype], typelens_native[structtype]);
1081                 }
1082         }
1083
1084         printf("*** End of list\n");
1085
1086 }
1087
1088
1089 static int make_structDNA(const char *baseDirectory, FILE *file, FILE *file_offsets)
1090 {
1091         int i;
1092         const short *sp;
1093         /* str contains filenames. Since we now include paths, I stretched       */
1094         /* it a bit. Hope this is enough :) -nzc-                                */
1095         char str[SDNA_MAX_FILENAME_LENGTH];
1096         int firststruct;
1097
1098         if (debugSDNA > 0) {
1099                 fflush(stdout);
1100                 printf("Running makesdna at debug level %d\n", debugSDNA);
1101         }
1102
1103         mem_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
1104
1105         /* the longest known struct is 50k, so we assume 100k is sufficient! */
1106         structdata = MEM_callocN(maxdata, "structdata");
1107
1108         /* a maximum of 5000 variables, must be sufficient? */
1109         names = MEM_callocN(sizeof(char *) * maxnr, "names");
1110         types = MEM_callocN(sizeof(char *) * maxnr, "types");
1111         typelens_native = MEM_callocN(sizeof(short) * maxnr, "typelens_native");
1112         typelens_32 = MEM_callocN(sizeof(short) * maxnr, "typelens_32");
1113         typelens_64 = MEM_callocN(sizeof(short) * maxnr, "typelens_64");
1114         structs = MEM_callocN(sizeof(short *) * maxnr, "structs");
1115
1116         /* Build versioning data */
1117         DNA_alias_maps(
1118                 DNA_RENAME_ALIAS_FROM_STATIC,
1119                 &g_version_data.struct_map_alias_from_static,
1120                 NULL);
1121         DNA_alias_maps(
1122                 DNA_RENAME_STATIC_FROM_ALIAS,
1123                 &g_version_data.struct_map_static_from_alias,
1124                 &g_version_data.elem_map_static_from_alias);
1125
1126         /**
1127          * Insertion of all known types.
1128          *
1129          * \warning Order of function calls here must be aligned with #eSDNA_Type.
1130          * \warning uint is not allowed! use in structs an unsigned int.
1131          * \warning sizes must match #DNA_elem_type_size().
1132          */
1133         add_type("char", 1);     /* SDNA_TYPE_CHAR */
1134         add_type("uchar", 1);    /* SDNA_TYPE_UCHAR */
1135         add_type("short", 2);    /* SDNA_TYPE_SHORT */
1136         add_type("ushort", 2);   /* SDNA_TYPE_USHORT */
1137         add_type("int", 4);      /* SDNA_TYPE_INT */
1138
1139         /* note, long isn't supported,
1140          * these are place-holders to maintain alignment with eSDNA_Type*/
1141         add_type("long", 4);     /* SDNA_TYPE_LONG */
1142         add_type("ulong", 4);    /* SDNA_TYPE_ULONG */
1143
1144         add_type("float", 4);    /* SDNA_TYPE_FLOAT */
1145         add_type("double", 8);   /* SDNA_TYPE_DOUBLE */
1146         add_type("int64_t", 8);  /* SDNA_TYPE_INT64 */
1147         add_type("uint64_t", 8); /* SDNA_TYPE_UINT64 */
1148         add_type("void", 0);     /* SDNA_TYPE_VOID */
1149
1150         /* the defines above shouldn't be output in the padding file... */
1151         firststruct = nr_types;
1152
1153         /* add all include files defined in the global array                     */
1154         /* Since the internal file+path name buffer has limited length, I do a   */
1155         /* little test first...                                                  */
1156         /* Mind the breaking condition here!                                     */
1157         DEBUG_PRINTF(0, "\tStart of header scan:\n");
1158         for (i = 0; *(includefiles[i]) != '\0'; i++) {
1159                 sprintf(str, "%s%s", baseDirectory, includefiles[i]);
1160                 DEBUG_PRINTF(0, "\t|-- Converting %s\n", str);
1161                 if (convert_include(str)) {
1162                         return 1;
1163                 }
1164         }
1165         DEBUG_PRINTF(0, "\tFinished scanning %d headers.\n", i);
1166
1167         if (calculate_structlens(firststruct)) {
1168                 /* error */
1169                 return 1;
1170         }
1171
1172         /* FOR DEBUG */
1173         if (debugSDNA > 1) {
1174                 int a, b;
1175                 /* short *elem; */
1176                 short num_types;
1177
1178                 printf("nr_names %d nr_types %d nr_structs %d\n", nr_names, nr_types, nr_structs);
1179                 for (a = 0; a < nr_names; a++) {
1180                         printf(" %s\n", names[a]);
1181                 }
1182                 printf("\n");
1183
1184                 sp = typelens_native;
1185                 for (a = 0; a < nr_types; a++, sp++) {
1186                         printf(" %s %d\n", types[a], *sp);
1187                 }
1188                 printf("\n");
1189
1190                 for (a = 0; a < nr_structs; a++) {
1191                         sp = structs[a];
1192                         printf(" struct %s elems: %d size: %d\n", types[sp[0]], sp[1], typelens_native[sp[0]]);
1193                         num_types  = sp[1];
1194                         sp += 2;
1195                         /* ? num_types was elem? */
1196                         for (b = 0; b < num_types; b++, sp += 2) {
1197                                 printf("   %s %s\n", types[sp[0]], names[sp[1]]);
1198                         }
1199                 }
1200         }
1201
1202         /* file writing */
1203
1204         DEBUG_PRINTF(0, "Writing file ... ");
1205
1206         if (nr_names == 0 || nr_structs == 0) {
1207                 /* pass */
1208         }
1209         else {
1210                 const char nil_bytes[4] = {0};
1211                 int len, len_align;
1212
1213                 dna_write(file, "SDNA", 4);
1214
1215                 /* write names */
1216                 dna_write(file, "NAME", 4);
1217                 len = nr_names;
1218                 dna_write(file, &len, 4);
1219                 /* write array */
1220                 len = 0;
1221                 for (int nr = 0; nr < nr_names; nr++) {
1222                         int name_size = strlen(names[nr]) + 1;
1223                         dna_write(file, names[nr], name_size);
1224                         len += name_size;
1225                 }
1226                 len_align = (len + 3) & ~3;
1227                 if (len != len_align) {
1228                         dna_write(file, nil_bytes, len_align - len);
1229                 }
1230
1231                 /* write TYPES */
1232                 dna_write(file, "TYPE", 4);
1233                 len = nr_types;
1234                 dna_write(file, &len, 4);
1235                 /* write array */
1236                 len = 0;
1237                 for (int nr = 0; nr < nr_types; nr++) {
1238                         int type_size = strlen(types[nr]) + 1;
1239                         dna_write(file, types[nr], type_size);
1240                         len += type_size;
1241                 }
1242                 len_align = (len + 3) & ~3;
1243                 if (len != len_align) {
1244                         dna_write(file, nil_bytes, len_align - len);
1245                 }
1246
1247                 /* WRITE TYPELENGTHS */
1248                 dna_write(file, "TLEN", 4);
1249
1250                 len = 2 * nr_types;
1251                 if (nr_types & 1) len += 2;
1252                 dna_write(file, typelens_native, len);
1253
1254                 /* WRITE STRUCTS */
1255                 dna_write(file, "STRC", 4);
1256                 len = nr_structs;
1257                 dna_write(file, &len, 4);
1258
1259                 /* calc datablock size */
1260                 sp = structs[nr_structs - 1];
1261                 sp += 2 + 2 * (sp[1]);
1262                 len = (intptr_t) ((char *) sp - (char *) structs[0]);
1263                 len = (len + 3) & ~3;
1264
1265                 dna_write(file, structs[0], len);
1266
1267                 /* a simple dna padding test */
1268                 if (0) {
1269                         FILE *fp;
1270                         int a;
1271
1272                         fp = fopen("padding.c", "w");
1273                         if (fp == NULL) {
1274                                 /* pass */
1275                         }
1276                         else {
1277
1278                                 /* add all include files defined in the global array */
1279                                 for (i = 0; *(includefiles[i]) != '\0'; i++) {
1280                                         fprintf(fp, "#include \"%s%s\"\n", baseDirectory, includefiles[i]);
1281                                 }
1282
1283                                 fprintf(fp, "main() {\n");
1284                                 sp = typelens_native;
1285                                 sp += firststruct;
1286                                 for (a = firststruct; a < nr_types; a++, sp++) {
1287                                         if (*sp) {
1288                                                 fprintf(fp, "\tif (sizeof(struct %s) - %d) printf(\"ALIGN ERROR:", types[a], *sp);
1289                                                 fprintf(fp, "%%d %s %d ", types[a], *sp);
1290                                                 fprintf(fp, "\\n\",  sizeof(struct %s) - %d);\n", types[a], *sp);
1291                                         }
1292                                 }
1293                                 fprintf(fp, "}\n");
1294                                 fclose(fp);
1295                         }
1296                 }
1297                 /*      end end padding test */
1298         }
1299
1300         /* write a simple enum with all structs offsets,
1301          * should only be accessed via SDNA_TYPE_FROM_STRUCT macro */
1302         {
1303                 fprintf(file_offsets, "#define SDNA_TYPE_FROM_STRUCT(id) _SDNA_TYPE_##id\n");
1304                 fprintf(file_offsets, "enum {\n");
1305                 for (i = 0; i < nr_structs; i++) {
1306                         const short *structpoin = structs[i];
1307                         const int    structtype = structpoin[0];
1308                         fprintf(file_offsets, "\t_SDNA_TYPE_%s = %d,\n", version_struct_alias_from_static(types[structtype]), i);
1309                 }
1310                 fprintf(file_offsets, "\tSDNA_TYPE_MAX = %d,\n", nr_structs);
1311                 fprintf(file_offsets, "};\n");
1312         }
1313
1314         /* Check versioning errors which could cause duplicate names,
1315          * do last because names are stripped. */
1316         {
1317                 GSet *names_unique = BLI_gset_str_new_ex(__func__, 512);
1318                 for (int struct_nr = 0; struct_nr < nr_structs; struct_nr++) {
1319                         sp = structs[struct_nr];
1320                         const char *struct_name = types[sp[0]];
1321                         const int len = sp[1];
1322                         sp += 2;
1323                         for (int a = 0; a < len; a++, sp += 2) {
1324                                 char *name = names[sp[1]];
1325                                 DNA_elem_id_strip(name);
1326                                 if (!BLI_gset_add(names_unique, name)) {
1327                                         fprintf(stderr, "Error: duplicate name found '%s.%s', "
1328                                                "likely cause is 'dna_rename_defs.h'\n",
1329                                                struct_name, name);
1330                                         return 1;
1331                                 }
1332                         }
1333                         BLI_gset_clear(names_unique, NULL);
1334                 }
1335                 BLI_gset_free(names_unique, NULL);
1336         }
1337
1338         MEM_freeN(structdata);
1339         MEM_freeN(names);
1340         MEM_freeN(types);
1341         MEM_freeN(typelens_native);
1342         MEM_freeN(typelens_32);
1343         MEM_freeN(typelens_64);
1344         MEM_freeN(structs);
1345
1346         BLI_memarena_free(mem_arena);
1347
1348         BLI_ghash_free(g_version_data.struct_map_alias_from_static, NULL, NULL);
1349         BLI_ghash_free(g_version_data.struct_map_static_from_alias, NULL, NULL);
1350         BLI_ghash_free(g_version_data.elem_map_static_from_alias, MEM_freeN, NULL);
1351
1352         DEBUG_PRINTF(0, "done.\n");
1353
1354         return 0;
1355 }
1356
1357 /** \} */
1358
1359 /* end make DNA. */
1360
1361 /* -------------------------------------------------------------------- */
1362 /** \name Main Function
1363  * \{ */
1364
1365 static void make_bad_file(const char *file, int line)
1366 {
1367         FILE *fp = fopen(file, "w");
1368         fprintf(fp,
1369                "#error \"Error! can't make correct DNA.c file from %s:%d, check alignment.\"\n",
1370                __FILE__, line);
1371         fclose(fp);
1372 }
1373
1374 #ifndef BASE_HEADER
1375 #define BASE_HEADER "../"
1376 #endif
1377
1378 int main(int argc, char **argv)
1379 {
1380         int return_status = 0;
1381
1382         if (argc != 3 && argc != 4) {
1383                 printf("Usage: %s dna.c dna_struct_offsets.h [base directory]\n", argv[0]);
1384                 return_status = 1;
1385         }
1386         else {
1387                 FILE *file_dna         = fopen(argv[1], "w");
1388                 FILE *file_dna_offsets = fopen(argv[2], "w");
1389                 if (!file_dna) {
1390                         printf("Unable to open file: %s\n", argv[1]);
1391                         return_status = 1;
1392                 }
1393                 else if (!file_dna_offsets) {
1394                         printf("Unable to open file: %s\n", argv[2]);
1395                         return_status = 1;
1396                 }
1397                 else {
1398                         const char *baseDirectory;
1399
1400                         if (argc == 4) {
1401                                 baseDirectory = argv[3];
1402                         }
1403                         else {
1404                                 baseDirectory = BASE_HEADER;
1405                         }
1406
1407                         fprintf(file_dna, "extern const unsigned char DNAstr[];\n");
1408                         fprintf(file_dna, "const unsigned char DNAstr[] = {\n");
1409                         if (make_structDNA(baseDirectory, file_dna, file_dna_offsets)) {
1410                                 /* error */
1411                                 fclose(file_dna);
1412                                 file_dna = NULL;
1413                                 make_bad_file(argv[1], __LINE__);
1414                                 return_status = 1;
1415                         }
1416                         else {
1417                                 fprintf(file_dna, "};\n");
1418                                 fprintf(file_dna, "extern const int DNAlen;\n");
1419                                 fprintf(file_dna, "const int DNAlen = sizeof(DNAstr);\n");
1420                         }
1421                 }
1422
1423                 if (file_dna) {
1424                         fclose(file_dna);
1425                 }
1426                 if (file_dna_offsets) {
1427                         fclose(file_dna_offsets);
1428                 }
1429         }
1430
1431
1432         return return_status;
1433 }
1434
1435 /* handy but fails on struct bounds which makesdna doesn't care about
1436  * with quite the same strictness as GCC does */
1437 #if 0
1438 /* include files for automatic dependencies */
1439
1440 /* extra safety check that we are aligned,
1441  * warnings here are easier to fix the makesdna's */
1442 #ifdef __GNUC__
1443 #  pragma GCC diagnostic error "-Wpadded"
1444 #endif
1445
1446 #endif /* if 0 */
1447
1448 /* even though DNA supports, 'long' shouldn't be used since it can be either 32 or 64bit,
1449  * use int or int64_t instead.
1450  * Only valid use would be as a runtime variable if an API expected a long,
1451  * but so far we dont have this happening. */
1452 #ifdef __GNUC__
1453 #  pragma GCC poison long
1454 #endif
1455
1456 #include "DNA_listBase.h"
1457 #include "DNA_vec_types.h"
1458 #include "DNA_ID.h"
1459 #include "DNA_ipo_types.h"
1460 #include "DNA_key_types.h"
1461 #include "DNA_text_types.h"
1462 #include "DNA_packedFile_types.h"
1463 #include "DNA_camera_types.h"
1464 #include "DNA_image_types.h"
1465 #include "DNA_texture_types.h"
1466 #include "DNA_light_types.h"
1467 #include "DNA_material_types.h"
1468 #include "DNA_vfont_types.h"
1469 #include "DNA_meta_types.h"
1470 #include "DNA_curve_types.h"
1471 #include "DNA_mesh_types.h"
1472 #include "DNA_meshdata_types.h"
1473 #include "DNA_modifier_types.h"
1474 #include "DNA_lattice_types.h"
1475 #include "DNA_object_types.h"
1476 #include "DNA_object_force_types.h"
1477 #include "DNA_object_fluidsim_types.h"
1478 #include "DNA_world_types.h"
1479 #include "DNA_scene_types.h"
1480 #include "DNA_view3d_types.h"
1481 #include "DNA_view2d_types.h"
1482 #include "DNA_space_types.h"
1483 #include "DNA_userdef_types.h"
1484 #include "DNA_screen_types.h"
1485 #include "DNA_sdna_types.h"
1486 #include "DNA_fileglobal_types.h"
1487 #include "DNA_sequence_types.h"
1488 #include "DNA_effect_types.h"
1489 #include "DNA_outliner_types.h"
1490 #include "DNA_sound_types.h"
1491 #include "DNA_collection_types.h"
1492 #include "DNA_armature_types.h"
1493 #include "DNA_action_types.h"
1494 #include "DNA_constraint_types.h"
1495 #include "DNA_nla_types.h"
1496 #include "DNA_node_types.h"
1497 #include "DNA_color_types.h"
1498 #include "DNA_brush_types.h"
1499 #include "DNA_customdata_types.h"
1500 #include "DNA_particle_types.h"
1501 #include "DNA_cloth_types.h"
1502 #include "DNA_gpencil_types.h"
1503 #include "DNA_gpencil_modifier_types.h"
1504 #include "DNA_shader_fx_types.h"
1505 #include "DNA_windowmanager_types.h"
1506 #include "DNA_anim_types.h"
1507 #include "DNA_boid_types.h"
1508 #include "DNA_smoke_types.h"
1509 #include "DNA_speaker_types.h"
1510 #include "DNA_movieclip_types.h"
1511 #include "DNA_tracking_types.h"
1512 #include "DNA_dynamicpaint_types.h"
1513 #include "DNA_mask_types.h"
1514 #include "DNA_rigidbody_types.h"
1515 #include "DNA_freestyle_types.h"
1516 #include "DNA_linestyle_types.h"
1517 #include "DNA_cachefile_types.h"
1518 #include "DNA_layer_types.h"
1519 #include "DNA_workspace_types.h"
1520 #include "DNA_lightprobe_types.h"
1521
1522 /* end of list */
1523
1524 /** \} */
1525
1526
1527 /* -------------------------------------------------------------------- */
1528 /** \name DNA Renaming Sanity Check
1529  *
1530  * Without this it's possible to reference struct members that don't exist,
1531  * breaking backward & forward compatibility.
1532  *
1533  * \{ */
1534
1535 static void UNUSED_FUNCTION(dna_rename_defs_ensure)(void)
1536 {
1537 #define DNA_STRUCT_RENAME(old, new) (void)sizeof(new);
1538 #define DNA_STRUCT_RENAME_ELEM(struct_name, old, new) (void)offsetof(struct_name, new);
1539 #include "dna_rename_defs.h"
1540 #undef DNA_STRUCT_RENAME
1541 #undef DNA_STRUCT_RENAME_ELEM
1542 }
1543
1544 /** \} */