/** * $Id:$ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** * * The contents of this file may be used under the terms of either the GNU * General Public License Version 2 or later (the "GPL", see * http://www.gnu.org/licenses/gpl.html ), or the Blender License 1.0 or * later (the "BL", see http://www.blender.org/BL/ ) which has to be * bought from the Blender Foundation to become active, in which case the * above mentioned GPL option does not apply. * * The Original Code is Copyright (C) 2002 by NaN Holding BV. * All rights reserved. * * The Original Code is: all of this file. * * Contributor(s): none yet. * * ***** END GPL/BL DUAL LICENSE BLOCK ***** */ /* makesdna.c */ #include #include char *includefiles[] = { "util.h", "blender.h", "screen.h", "file.h", "sequence.h", "effect_types.h", "ika.h", "oops.h", "imasel.h", "game.h", "old_game.h", "sound.h", "group.h", // empty string to indicate end of includefiles "" }; #ifdef WIN32 typedef unsigned int uint; #endif #ifndef WIN32 #include #include #endif #include #include "file.h" #include "util.h" int maxdata= 100000, maxnr= 5000; int nr_names=0; int nr_types=0; int nr_structs=0; char **names, *namedata; /* op adres names[a] staat string a */ char **types, *typedata; /* op adres types[a] staat string a */ short *typelens; /* op typelens[a] staat de lengte van type a */ short **structs, *structdata; /* op sp= structs[a] staat eerste adres structdefinitie sp[0] is typenummer sp[1] is aantal elementen sp[2] sp[3] is typenr, namenr (enz) */ /* stubs */ int filesize(int file) { struct stat buf; if (file <= 0) return (-1); fstat(file, &buf); return (buf.st_size); } /* ************************* MAKEN DNA ********************** */ int add_type(char *str, int len) { int nr; char *cp; if(str[0]==0) return -1; /* zoek typearray door */ for(nr=0; nr=maxnr) { printf("too many types\n"); return nr_types-1;; } nr_types++; return nr_types-1; } int add_name(char *str) { int nr; char *cp; if(str[0]==0) return -1; /* zoek name array door */ for(nr=0; nr=maxnr) { printf("too many names\n"); return nr_names-1; } nr_names++; return nr_names-1; } short *add_struct(int namecode) { int len; short *sp; 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]; sp[0]= namecode; if(nr_structs>=maxnr) { printf("too many structs\n"); return sp; } nr_structs++; return sp; } int preprocess_include(char *maindata, int len) { int a, newlen, comment; char *cp, *temp, *md; temp= mallocN(len, "preprocess_include"); memcpy(temp, maindata, len); /* alle enters/tabs/etc vervangen door spaties */ cp= temp; a= len; while(a--) { if( *cp<32 || *cp>128 ) *cp= 32; cp++; } /* data uit temp naar maindata kopieeren, verwijder commentaar en dubbele spaties */ 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= 0; cp[0]=cp[1]= 32; } /* niet kopieeren als: */ if(comment); else if( cp[0]==' ' && cp[1]==' ' ); else if( cp[-1]=='*' && cp[0]==' ' ); /* pointers met spatie */ else { md[0]= cp[0]; md++; newlen++; } cp++; } freeN(temp); return newlen; } void convert_include(char *filename) { /* lees includefile, sla structen over die op regel ervoor '#' hebben. sla alle data op in tijdelijke arrays. */ int file, filelen, count, overslaan, slen, type, name, strct; short *structpoin, *sp; char *maindata, *mainend, *md, *md1; file= open(filename, O_BINARY|O_RDONLY); if(file== -1) { printf("Can't read file %s\n", filename); } else { filelen= filesize(file); md= maindata= mallocN(filelen, "convert_include"); read(file, maindata, filelen); close(file); filelen= preprocess_include(maindata, filelen); mainend= maindata+filelen-1; /* we zoeken naar '{' en dan terug naar 'struct' */ count= 0; overslaan= 0; while(count ((long)mainend) ) break; if(*md1==',' || *md1==' ') *md1= 0; md1++; } /* types en namen lezen tot eerste karakter niet '}' */ md1= md+1; while( *md1 != '}' ) { if( ((long)md1) > ((long)mainend) ) break; /* als er 'struct' of 'unsigned' staat, overslaan */ if(*md1) { if( strncmp(md1, "struct", 6)==0 ) md1+= 7; if( strncmp(md1, "unsigned", 6)==0 ) md1+= 9; /* type te pakken! */ type= add_type(md1, 0); md1+= strlen(md1); /* doorlezen tot ';' */ while( *md1 != ';' ) { if( ((long)md1) > ((long)mainend) ) break; if(*md1) { /* name te pakken */ slen= strlen(md1); if( md1[slen-1]==';' ) { md1[slen-1]= 0; name= add_name(md1); sp[0]= type; sp[1]= name; structpoin[1]++; sp+= 2; md1+= slen; break; } name= add_name(md1); sp[0]= type; sp[1]= name; structpoin[1]++; sp+= 2; md1+= slen; } md1++; } } md1++; } } } } count++; md++; } freeN(maindata); } } int arraysize(char *astr, int len) { int a, mul=1; char str[100], *cp=0; memcpy(str, astr, len+1); for(a=0; a3 && (len % 4) ) { printf("Align 4 error in struct: %s %s\n", types[structtype], cp); } else if(typelens[type]==2 && (len % 2) ) { printf("Align 2 error in struct: %s %s\n", types[structtype], cp); } len+= mul*typelens[type]; } else { len= 0; break; } } if(len==0) unknown++; else { typelens[structtype]= len; } } } if(unknown==lastunknown) break; } if(unknown) { printf("error: still %d structs unknown\n", unknown); for(a=0; a= MAX_DNA_LINE_LENGTH) { fprintf(file, "\n"); linelength = 0; } } } void make_structDNA(FILE *file) { int len, i; short *sp; char str[40], *cp; int firststruct; /* de allerlangst bekende struct is 50k, 100k is ruimte genoeg! */ namedata= callocN(maxdata, "namedata"); typedata= callocN(maxdata, "typedata"); structdata= callocN(maxdata, "structdata"); /* maximaal 5000 variablen, vast voldoende? */ names= callocN(sizeof(char *)*maxnr, "names"); types= callocN(sizeof(char *)*maxnr, "types"); typelens= callocN(sizeof(short)*maxnr, "typelens"); structs= callocN(sizeof(short)*maxnr, "structs"); /* inserten alle bekende types */ /* let op: uint komt niet voor! gebruik in structen unsigned int */ add_type("char", 1); /* 0 */ add_type("uchar", 1); /* 1 */ add_type("short", 2); /* 2 */ add_type("ushort", 2); /* 3 */ add_type("int", 4); /* 4 */ add_type("long", 4); /* 5 */ add_type("ulong", 4); /* 6 */ add_type("float", 4); /* 7 */ add_type("double", 8); /* 8 */ add_type("void", 0); /* 9 */ // the defines above shouldn't be output in the padding file... firststruct = nr_types; /* eerste struct in util.h is struct Link, deze wordt in de compflags overgeslagen (als # 0). * Vuile patch! Nog oplossen.... */ #ifdef IRISGL #ifdef NINCLUDES #define BASE_HEADER "../include/" #else #ifdef MIPS1 #define BASE_HEADER "./" #else #define BASE_HEADER "../" #endif #endif #else #define BASE_HEADER "../include/" #endif // add all include files defined in the global array for (i = 0; strlen(includefiles[i]); i++) { sprintf(str, "%s%s", BASE_HEADER, includefiles[i]); convert_include(str); } calculate_structlens(); /* DIT DEEL VOOR DEBUG */ /* printf("nr_names %d nr_types %d nr_structs %d\n", nr_names, nr_types, nr_structs); for(a=0; a