use set as a suffix (matches operators)
[blender-staging.git] / source / blender / makesdna / intern / makesdna.c
index bf2f0f3900e2d04a35ee4e069e6defd5846fae31..7a2d659755afb2cfa5bca442071dd721a6001ce1 100644 (file)
@@ -15,7 +15,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  * All rights reserved.
 
 #include "BLO_sys_types.h" // for intptr_t support
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #define SDNA_MAX_FILENAME_LENGTH 255
 
 
@@ -76,14 +72,12 @@ char *includefiles[] = {
        "DNA_ID.h",
        "DNA_ipo_types.h",
        "DNA_key_types.h",
-       "DNA_scriptlink_types.h",
        "DNA_text_types.h",
        "DNA_packedFile_types.h",
        "DNA_camera_types.h",
        "DNA_image_types.h",
        "DNA_texture_types.h",
        "DNA_lamp_types.h",
-       "DNA_wave_types.h",
        "DNA_material_types.h",
        "DNA_vfont_types.h",
        // if you add files here, please add them at the end
@@ -98,7 +92,6 @@ char *includefiles[] = {
        "DNA_object_force.h",
        "DNA_object_fluidsim.h",
        "DNA_world_types.h",
-       "DNA_radio_types.h",
        "DNA_scene_types.h",
        "DNA_view3d_types.h",
        "DNA_view2d_types.h",   
@@ -133,6 +126,8 @@ char *includefiles[] = {
        // of makesdna.c (this file) as well
        "DNA_windowmanager_types.h",
        "DNA_anim_types.h",
+       "DNA_boid_types.h",
+       "DNA_smoke_types.h",
 
        // empty string to indicate end of includefiles
        ""
@@ -142,11 +137,11 @@ int maxdata= 500000, maxnr= 50000;
 int nr_names=0;
 int nr_types=0;
 int nr_structs=0;
-char **names, *namedata;               /* at adress names[a] is string a */
-char **types, *typedata;               /* at adress types[a] is string a */
+char **names, *namedata;               /* at address names[a] is string a */
+char **types, *typedata;               /* at address types[a] is string a */
 short *typelens;                               /* at typelens[a] is de length of type a */
 short *alphalens;                          /* contains sizes as they are calculated on the DEC Alpha (64 bits) */
-short **structs, *structdata;  /* at sp= structs[a] is the first adress of a struct definition
+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) */
@@ -207,7 +202,7 @@ static int calculate_structlens(int);
 void dna_write(FILE *file, void *pntr, int size);
 
 /**
- * Report all structures found so far, and print their lenghts.
+ * Report all structures found so far, and print their lengths.
  */
 void printStructLenghts(void);
 
@@ -277,7 +272,13 @@ int add_name(char *str)
        if((str[0]==0) /*  || (str[1]==0) */) return -1;
 
        if (str[0] == '(' && str[1] == '*') {
-               if (debugSDNA > 3) printf("\t\t\t\t*** Function pointer found\n");
+               /* 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;
+
+               if (debugSDNA > 3) printf("\t\t\t\t*** Function pointer or multidim array pointer found\n");
                /* functionpointer: transform the type (sometimes) */
                i = 0;
                j = 0;
@@ -302,7 +303,15 @@ int add_name(char *str)
                if (debugSDNA > 3) printf("seen %c ( %d) \n", str[j], str[j]); 
                if (debugSDNA > 3) printf("special after offset %d\n", j); 
                                
-               if (str[j] == 0 ) {
+               if (!isfuncptr) {
+                       /* multidimensional array pointer case */
+                       if(str[j] == 0) {
+                               if (debugSDNA > 3) printf("offsetting for multidim array pointer\n");
+                       }
+                       else
+                               printf("Error during tokening multidim array pointer\n");
+               }
+               else if (str[j] == 0 ) {
                        if (debugSDNA > 3) printf("offsetting for space\n"); 
                        /* get additional offset */
                        k = 0;
@@ -321,8 +330,8 @@ int add_name(char *str)
                                
                /*
                 * Put )(void) at the end? Maybe )(). Should check this with
-         * old sdna. Actually, sometimes )(), sometimes )(void...)
-         * Alas.. such is the nature of braindamage :(
+                * old sdna. Actually, sometimes )(), sometimes )(void...)
+                * Alas.. such is the nature of braindamage :(
                 *
                 * Sorted it out: always do )(), except for headdraw and
                 * windraw, part of ScrArea. This is important, because some
@@ -485,15 +494,18 @@ static void *read_file_data(char *filename, int *len_r)
        data= MEM_mallocN(*len_r, "read_file_data");
        if (!data) {
                *len_r= -1;
+               fclose(fp);
                return NULL;
        }
 
        if (fread(data, *len_r, 1, fp)!=1) {
                *len_r= -1;
                MEM_freeN(data);
+               fclose(fp);
                return NULL;
        }
-
+       
+       fclose(fp);
        return data;
 }
 
@@ -560,10 +572,11 @@ int convert_include(char *filename)
                                        while( *md1 != '}' ) {
                                                if(md1>mainend) break;
                                                
-                                               /* skip when it says 'struct' or 'unsigned' */
+                                               /* skip when it says 'struct' or 'unsigned' or 'const' */
                                                if(*md1) {
                                                        if( strncmp(md1, "struct", 6)==0 ) md1+= 7;
-                                                       if( strncmp(md1, "unsigned", 6)==0 ) md1+= 9;
+                                                       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);
@@ -681,7 +694,7 @@ static int calculate_structlens(int firststruct)
                                for(b=0; b<structpoin[1]; b++, sp+=2) {
                                        type= sp[0];
                                        cp= names[sp[1]];
-                                       
+
                                        namelen= (int) strlen(cp);
                                        /* is it a pointer or function pointer? */
                                        if(cp[0]=='*' || cp[1]=='*') {
@@ -711,6 +724,10 @@ static int calculate_structlens(int firststruct)
                                                len += sizeof(void *) * mul;
                                                alphalen += 8 * mul;
 
+                                       } 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] ) {
                                                /* has the name an extra length? (array) */
                                                mul= 1;
@@ -898,7 +915,7 @@ 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);
                }
@@ -955,6 +972,8 @@ int make_structDNA(char *baseDirectory, FILE *file)
                dna_write(file, str, 4);
                len= nr_names;
                dna_write(file, &len, 4);
+               printf("LEEEN %d\n", len);
+               
                
                /* calculate size of datablock with strings */
                cp= names[nr_names-1];
@@ -1046,10 +1065,10 @@ int make_structDNA(char *baseDirectory, FILE *file)
 
 /* ************************* END MAKE DNA ********************** */
 
-static void make_bad_file(char *file)
+static void make_bad_file(char *file, int line)
 {
        FILE *fp= fopen(file, "w");
-       fprintf(fp, "ERROR! Cannot make correct DNA.c file, STUPID!\n");
+       fprintf(fp, "#error \"Error! can't make correct DNA.c file from %s:%d, STUPID!\"\n", __FILE__, line);
        fclose(fp);
 }
 
@@ -1083,7 +1102,7 @@ int main(int argc, char ** argv)
                        if (make_structDNA(baseDirectory, file)) {
                                // error
                                fclose(file);
-                               make_bad_file(argv[1]);
+                               make_bad_file(argv[1], __LINE__);
                                return_status = 1;
                        } else {
                                fprintf(file, "};\n");
@@ -1104,14 +1123,12 @@ int main(int argc, char ** argv)
 #include "DNA_ID.h"
 #include "DNA_ipo_types.h"
 #include "DNA_key_types.h"
-#include "DNA_scriptlink_types.h"
 #include "DNA_text_types.h"
 #include "DNA_packedFile_types.h"
 #include "DNA_camera_types.h"
 #include "DNA_image_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_lamp_types.h"
-#include "DNA_wave_types.h"
 #include "DNA_material_types.h"
 #include "DNA_vfont_types.h"
 #include "DNA_meta_types.h"
@@ -1124,7 +1141,6 @@ int main(int argc, char ** argv)
 #include "DNA_object_force.h"
 #include "DNA_object_fluidsim.h"
 #include "DNA_world_types.h"
-#include "DNA_radio_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_view3d_types.h"
 #include "DNA_view2d_types.h"  
@@ -1155,4 +1171,6 @@ int main(int argc, char ** argv)
 #include "DNA_gpencil_types.h"
 #include "DNA_windowmanager_types.h"
 #include "DNA_anim_types.h"
+#include "DNA_boid_types.h"
+#include "DNA_smoke_types.h"
 /* end of list */