Animato - Basic version patching support
[blender.git] / source / blender / makesrna / intern / makesrna.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * Contributor(s): Blender Foundation (2008).
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 #include <float.h>
26 #include <limits.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "MEM_guardedalloc.h"
32
33 #include "RNA_access.h"
34 #include "RNA_define.h"
35 #include "RNA_types.h"
36
37 #include "rna_internal.h"
38
39 #define RNA_VERSION_DATE "$Id$"
40
41 #ifdef _WIN32
42 #ifndef snprintf
43 #define snprintf _snprintf
44 #endif
45 #endif
46
47 /* Sorting */
48
49 int cmp_struct(const void *a, const void *b)
50 {
51         const StructRNA *structa= *(const StructRNA**)a;
52         const StructRNA *structb= *(const StructRNA**)b;
53
54         return strcmp(structa->identifier, structb->identifier);
55 }
56
57 int cmp_property(const void *a, const void *b)
58 {
59         const PropertyRNA *propa= *(const PropertyRNA**)a;
60         const PropertyRNA *propb= *(const PropertyRNA**)b;
61
62         if(strcmp(propa->identifier, "rna_type") == 0) return -1;
63         else if(strcmp(propb->identifier, "rna_type") == 0) return 1;
64
65         if(strcmp(propa->identifier, "name") == 0) return -1;
66         else if(strcmp(propb->identifier, "name") == 0) return 1;
67
68         return strcmp(propa->name, propb->name);
69 }
70
71 void rna_sortlist(ListBase *listbase, int(*cmp)(const void*, const void*))
72 {
73         Link *link;
74         void **array;
75         int a, size;
76         
77         if(listbase->first == listbase->last)
78                 return;
79
80         for(size=0, link=listbase->first; link; link=link->next)
81                 size++;
82
83         array= MEM_mallocN(sizeof(void*)*size, "rna_sortlist");
84         for(a=0, link=listbase->first; link; link=link->next, a++)
85                 array[a]= link;
86
87         qsort(array, size, sizeof(void*), cmp);
88
89         listbase->first= listbase->last= NULL;
90         for(a=0; a<size; a++) {
91                 link= array[a];
92                 link->next= link->prev= NULL;
93                 rna_addtail(listbase, link);
94         }
95
96         MEM_freeN(array);
97 }
98
99 /* Preprocessing */
100
101 static void rna_print_c_string(FILE *f, const char *str)
102 {
103         static char *escape[] = {"\''", "\"\"", "\??", "\\\\","\aa", "\bb", "\ff", "\nn", "\rr", "\tt", "\vv", NULL};
104         int i, j;
105
106         fprintf(f, "\"");
107         for(i=0; str[i]; i++) {
108                 for(j=0; escape[j]; j++)
109                         if(str[i] == escape[j][0])
110                                 break;
111
112                 if(escape[j]) fprintf(f, "\\%c", escape[j][1]);
113                 else fprintf(f, "%c", str[i]);
114         }
115         fprintf(f, "\"");
116 }
117
118 static void rna_print_data_get(FILE *f, PropertyDefRNA *dp)
119 {
120         if(dp->dnastructfromname && dp->dnastructfromprop)
121                 fprintf(f, "    %s *data= (%s*)(((%s*)ptr->data)->%s);\n", dp->dnastructname, dp->dnastructname, dp->dnastructfromname, dp->dnastructfromprop);
122         else
123                 fprintf(f, "    %s *data= (%s*)(ptr->data);\n", dp->dnastructname, dp->dnastructname);
124 }
125
126 static char *rna_alloc_function_name(const char *structname, const char *propname, const char *type)
127 {
128         AllocDefRNA *alloc;
129         char buffer[2048];
130         char *result;
131
132         snprintf(buffer, sizeof(buffer), "rna_%s_%s_%s", structname, propname, type);
133         result= MEM_callocN(sizeof(char)*strlen(buffer)+1, "rna_alloc_function_name");
134         strcpy(result, buffer);
135
136         alloc= MEM_callocN(sizeof(AllocDefRNA), "AllocDefRNA");
137         alloc->mem= result;
138         rna_addtail(&DefRNA.allocs, alloc);
139
140         return result;
141 }
142
143 static const char *rna_type_type(PropertyRNA *prop)
144 {
145         switch(prop->type) {
146                 case PROP_BOOLEAN:
147                 case PROP_INT:
148                 case PROP_ENUM:
149                         return "int";
150                 case PROP_FLOAT:
151                         return "float";
152                 case PROP_STRING:
153                         return "char*";
154                 default:
155                         return "void*";
156         }
157 }
158
159 static int rna_enum_bitmask(PropertyRNA *prop)
160 {
161         EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
162         int a, mask= 0;
163
164         for(a=0; a<eprop->totitem; a++)
165                 mask |= eprop->item[a].value;
166         
167         return mask;
168 }
169
170 static int rna_color_quantize(PropertyRNA *prop, PropertyDefRNA *dp)
171 {
172         if(prop->type == PROP_FLOAT && prop->subtype == PROP_COLOR)
173                 if(strcmp(dp->dnatype, "float") != 0 && strcmp(dp->dnatype, "double") != 0)
174                         return 1;
175         
176         return 0;
177 }
178
179 static const char *rna_function_string(void *func)
180 {
181         return (func)? (const char*)func: "NULL";
182 }
183
184 static void rna_float_print(FILE *f, float num)
185 {
186         if(num == -FLT_MAX) fprintf(f, "-FLT_MAX");
187         else if(num == FLT_MAX) fprintf(f, "FLT_MAX");
188         else if((int)num == num) fprintf(f, "%.1ff", num);
189         else fprintf(f, "%.10ff", num);
190 }
191
192 static void rna_int_print(FILE *f, int num)
193 {
194         if(num == INT_MIN) fprintf(f, "INT_MIN");
195         else if(num == INT_MAX) fprintf(f, "INT_MAX");
196         else fprintf(f, "%d", num);
197 }
198
199 static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp)
200 {
201         char *func;
202
203         if(prop->flag & PROP_IDPROPERTY)
204                 return NULL;
205
206         if(!dp->dnastructname || !dp->dnaname) {
207                 fprintf(stderr, "rna_def_property_get_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
208                 DefRNA.error= 1;
209                 return NULL;
210         }
211
212         if(prop->type == PROP_STRING && ((StringPropertyRNA*)prop)->maxlength == 0) {
213                 fprintf(stderr, "rna_def_property_get_func: string %s.%s has max length 0.\n", srna->identifier, prop->identifier);
214                 DefRNA.error= 1;
215                 return NULL;
216         }
217
218         func= rna_alloc_function_name(srna->identifier, prop->identifier, "get");
219
220         switch(prop->type) {
221                 case PROP_STRING: {
222                         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
223                         fprintf(f, "static void %s(PointerRNA *ptr, char *value)\n", func);
224                         fprintf(f, "{\n");
225                         rna_print_data_get(f, dp);
226                         fprintf(f, "    BLI_strncpy(value, data->%s, %d);\n", dp->dnaname, sprop->maxlength);
227                         fprintf(f, "}\n\n");
228                         break;
229                 }
230                 default:
231                         if(prop->arraylength) {
232                                 fprintf(f, "static %s %s(PointerRNA *ptr, int index)\n", rna_type_type(prop), func);
233                                 fprintf(f, "{\n");
234                                 rna_print_data_get(f, dp);
235                                 if(dp->dnaarraylength == 1) {
236                                         if(prop->type == PROP_BOOLEAN && dp->booleanbit)
237                                                 fprintf(f, "    return (%s(data->%s & (%d<<index)) != 0);\n", (dp->booleannegative)? "!": "", dp->dnaname, dp->booleanbit);
238                                         else
239                                                 fprintf(f, "    return (%s)%s((&data->%s)[index]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname);
240                                 }
241                                 else {
242                                         if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
243                                                 fprintf(f, "    return (%s(data->%s[index] & ", (dp->booleannegative)? "!": "", dp->dnaname);
244                                                 rna_int_print(f, dp->booleanbit);
245                                                 fprintf(f, ") != 0);\n");
246                                         }
247                                         else if(rna_color_quantize(prop, dp))
248                                                 fprintf(f, "    return (%s)(data->%s[index]/255.0f);\n", rna_type_type(prop), dp->dnaname);
249                                         else
250                                                 fprintf(f, "    return (%s)%s(data->%s[index]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname);
251                                 }
252                                 fprintf(f, "}\n\n");
253                         }
254                         else {
255                                 fprintf(f, "static %s %s(PointerRNA *ptr)\n", rna_type_type(prop), func);
256                                 fprintf(f, "{\n");
257                                 rna_print_data_get(f, dp);
258                                 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
259                                         fprintf(f, "    return (%s((data->%s) & ", (dp->booleannegative)? "!": "", dp->dnaname);
260                                         rna_int_print(f, dp->booleanbit);
261                                         fprintf(f, ") != 0);\n");
262                                 }
263                                 else if(prop->type == PROP_ENUM && dp->enumbitflags) {
264                                         fprintf(f, "    return ((data->%s) & ", dp->dnaname);
265                                         rna_int_print(f, rna_enum_bitmask(prop));
266                                         fprintf(f, ");\n");
267                                 }
268                                 else if(prop->type == PROP_POINTER && dp->dnapointerlevel == 0)
269                                         fprintf(f, "    return (%s)&(data->%s);\n", rna_type_type(prop), dp->dnaname);
270                                 else
271                                         fprintf(f, "    return (%s)%s(data->%s);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname);
272                                 fprintf(f, "}\n\n");
273                         }
274                         break;
275         }
276
277         return func;
278 }
279
280 static void rna_clamp_value(FILE *f, PropertyRNA *prop)
281 {
282         if(prop->type == PROP_INT) {
283                 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
284
285                 if(iprop->hardmin != INT_MIN || iprop->hardmax != INT_MAX) {
286                         fprintf(f, "    CLAMP(value, ");
287                         rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
288                         rna_int_print(f, iprop->hardmax); fprintf(f, ");\n");
289                 }
290         }
291         else if(prop->type == PROP_FLOAT) {
292                 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
293
294                 if(fprop->hardmin != -FLT_MAX || fprop->hardmax != FLT_MAX) {
295                         fprintf(f, "    CLAMP(value, ");
296                         rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
297                         rna_float_print(f, fprop->hardmax); fprintf(f, ");\n");
298                 }
299         }
300 }
301
302 static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp)
303 {
304         char *func;
305
306         if(prop->flag & (PROP_IDPROPERTY|PROP_NOT_EDITABLE))
307                 return NULL;
308
309         if(!dp->dnastructname || !dp->dnaname) {
310                 if(!(prop->flag & PROP_NOT_EDITABLE)) {
311                         fprintf(stderr, "rna_def_property_set_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
312                         DefRNA.error= 1;
313                 }
314                 return NULL;
315         }
316
317         func= rna_alloc_function_name(srna->identifier, prop->identifier, "set");
318
319         switch(prop->type) {
320                 case PROP_STRING: {
321                         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
322                         fprintf(f, "static void %s(PointerRNA *ptr, const char *value)\n", func);
323                         fprintf(f, "{\n");
324                         rna_print_data_get(f, dp);
325                         fprintf(f, "    BLI_strncpy(data->%s, value, %d);\n", dp->dnaname, sprop->maxlength);
326                         fprintf(f, "}\n\n");
327                         break;
328                 }
329                 default:
330                         if(prop->arraylength) {
331                                 fprintf(f, "static void %s(PointerRNA *ptr, int index, %s value)\n", func, rna_type_type(prop));
332                                 fprintf(f, "{\n");
333                                 rna_print_data_get(f, dp);
334                                 if(dp->dnaarraylength == 1) {
335                                         if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
336                                                 fprintf(f, "    if(%svalue) data->%s |= (%d<<index);\n", (dp->booleannegative)? "!": "", dp->dnaname, dp->booleanbit);
337                                                 fprintf(f, "    else data->%s &= ~(%d<<index);\n", dp->dnaname, dp->booleanbit);
338                                         }
339                                         else {
340                                                 rna_clamp_value(f, prop);
341                                                 fprintf(f, "    (&data->%s)[index]= %svalue;\n", dp->dnaname, (dp->booleannegative)? "!": "");
342                                         }
343                                 }
344                                 else {
345                                         if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
346                                                 fprintf(f, "    if(%svalue) data->%s[index] |= ", (dp->booleannegative)? "!": "", dp->dnaname);
347                                                 rna_int_print(f, dp->booleanbit);
348                                                 fprintf(f, ";\n");
349                                                 fprintf(f, "    else data->%s[index] &= ~", dp->dnaname);
350                                                 rna_int_print(f, dp->booleanbit);
351                                                 fprintf(f, ";\n");
352                                         }
353                                         else if(rna_color_quantize(prop, dp)) {
354                                                 fprintf(f, "    data->%s[index]= FTOCHAR(value);\n", dp->dnaname);
355                                         }
356                                         else {
357                                                 rna_clamp_value(f, prop);
358                                                 fprintf(f, "    data->%s[index]= %svalue;\n", dp->dnaname, (dp->booleannegative)? "!": "");
359                                         }
360                                 }
361                                 fprintf(f, "}\n\n");
362                         }
363                         else {
364                                 fprintf(f, "static void %s(PointerRNA *ptr, %s value)\n", func, rna_type_type(prop));
365                                 fprintf(f, "{\n");
366                                 rna_print_data_get(f, dp);
367                                 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
368                                         fprintf(f, "    if(%svalue) data->%s |= ", (dp->booleannegative)? "!": "", dp->dnaname);
369                                         rna_int_print(f, dp->booleanbit);
370                                         fprintf(f, ";\n");
371                                         fprintf(f, "    else data->%s &= ~", dp->dnaname);
372                                         rna_int_print(f, dp->booleanbit);
373                                         fprintf(f, ";\n");
374                                 }
375                                 else if(prop->type == PROP_ENUM && dp->enumbitflags) {
376                                         fprintf(f, "    data->%s &= ~", dp->dnaname);
377                                         rna_int_print(f, rna_enum_bitmask(prop));
378                                         fprintf(f, ";\n");
379                                         fprintf(f, "    data->%s |= value;\n", dp->dnaname);
380                                 }
381                                 else {
382                                         rna_clamp_value(f, prop);
383                                         fprintf(f, "    data->%s= %svalue;\n", dp->dnaname, (dp->booleannegative)? "!": "");
384                                 }
385                                 fprintf(f, "}\n\n");
386                         }
387                         break;
388         }
389
390         return func;
391 }
392
393 static char *rna_def_property_length_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp)
394 {
395         char *func= NULL;
396
397         if(prop->flag & PROP_IDPROPERTY)
398                 return NULL;
399
400         if(prop->type == PROP_STRING) {
401                 if(!dp->dnastructname || !dp->dnaname) {
402                         fprintf(stderr, "rna_def_property_length_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
403                         DefRNA.error= 1;
404                         return NULL;
405                 }
406
407                 func= rna_alloc_function_name(srna->identifier, prop->identifier, "length");
408
409                 fprintf(f, "static int %s(PointerRNA *ptr)\n", func);
410                 fprintf(f, "{\n");
411                 rna_print_data_get(f, dp);
412                 fprintf(f, "    return strlen(data->%s);\n", dp->dnaname);
413                 fprintf(f, "}\n\n");
414         }
415         else if(prop->type == PROP_COLLECTION) {
416                 if(prop->type == PROP_COLLECTION && (!(dp->dnalengthname || dp->dnalengthfixed)|| !dp->dnaname)) {
417                         fprintf(stderr, "rna_def_property_length_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
418                         DefRNA.error= 1;
419                         return NULL;
420                 }
421
422                 func= rna_alloc_function_name(srna->identifier, prop->identifier, "length");
423
424                 fprintf(f, "static int %s(PointerRNA *ptr)\n", func);
425                 fprintf(f, "{\n");
426                 rna_print_data_get(f, dp);
427                 if(dp->dnalengthname)
428                         fprintf(f, "    return (data->%s == NULL)? 0: data->%s;\n", dp->dnaname, dp->dnalengthname);
429                 else
430                         fprintf(f, "    return (data->%s == NULL)? 0: %d;\n", dp->dnaname, dp->dnalengthfixed);
431                 fprintf(f, "}\n\n");
432         }
433
434         return func;
435 }
436
437 static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp)
438 {
439         char *func;
440
441         if(prop->flag & PROP_IDPROPERTY)
442                 return NULL;
443
444         if(!dp->dnastructname || !dp->dnaname) {
445                 fprintf(stderr, "rna_def_property_begin_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
446                 DefRNA.error= 1;
447                 return NULL;
448         }
449
450         func= rna_alloc_function_name(srna->identifier, prop->identifier, "begin");
451
452         if(dp->dnalengthname || dp->dnalengthfixed) {
453                 fprintf(f, "static void %s(CollectionPropertyIterator *iter, PointerRNA *ptr)\n", func);
454                 fprintf(f, "{\n");
455                 rna_print_data_get(f, dp);
456                 if(dp->dnalengthname)
457                         fprintf(f, "    rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), data->%s, NULL);\n", dp->dnaname, dp->dnaname, dp->dnalengthname);
458                 else
459                         fprintf(f, "    rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), %d, NULL);\n", dp->dnaname, dp->dnaname, dp->dnalengthfixed);
460                 fprintf(f, "}\n\n");
461         }
462         else {
463                 fprintf(f, "static void %s(CollectionPropertyIterator *iter, PointerRNA *ptr)\n", func);
464                 fprintf(f, "{\n");
465                 rna_print_data_get(f, dp);
466                 fprintf(f, "    rna_iterator_listbase_begin(iter, &data->%s, NULL);\n", dp->dnaname);
467                 fprintf(f, "}\n\n");
468         }
469
470         return func;
471 }
472
473 static void rna_def_property_funcs(FILE *f, PropertyDefRNA *dp)
474 {
475         PropertyRNA *prop;
476         StructRNA *srna;
477
478         srna= dp->srna;
479         prop= dp->prop;
480
481         switch(prop->type) {
482                 case PROP_BOOLEAN: {
483                         BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
484
485                         if(!prop->arraylength) {
486                                 if(!bprop->get) bprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp);
487                                 if(!bprop->set) bprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp);
488                         }
489                         else {
490                                 if(!bprop->getarray) bprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp);
491                                 if(!bprop->setarray) bprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp);
492                         }
493                         break;
494                 }
495                 case PROP_INT: {
496                         IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
497
498                         if(!prop->arraylength) {
499                                 if(!iprop->get) iprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp);
500                                 if(!iprop->set) iprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp);
501                         }
502                         else {
503                                 if(!iprop->getarray) iprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp);
504                                 if(!iprop->setarray) iprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp);
505                         }
506                         break;
507                 }
508                 case PROP_FLOAT: {
509                         FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
510
511                         if(!prop->arraylength) {
512                                 if(!fprop->get) fprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp);
513                                 if(!fprop->set) fprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp);
514                         }
515                         else {
516                                 if(!fprop->getarray) fprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp);
517                                 if(!fprop->setarray) fprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp);
518                         }
519                         break;
520                 }
521                 case PROP_ENUM: {
522                         EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
523
524                         if(!eprop->get) eprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp);
525                         if(!eprop->set) eprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp);
526                         break;
527                 }
528                 case PROP_STRING: {
529                         StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
530
531                         if(!sprop->get) sprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp);
532                         if(!sprop->length) sprop->length= (void*)rna_def_property_length_func(f, srna, prop, dp);
533                         if(!sprop->set) sprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp);
534                         break;
535                 }
536                 case PROP_POINTER: {
537                         PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
538
539                         if(!pprop->get) pprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp);
540                         if(!pprop->set) pprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp);
541                         if(!pprop->structtype && !pprop->type) {
542                                 fprintf(stderr, "rna_def_property_funcs: %s.%s, pointer must have either type function or fixed type.\n", srna->identifier, prop->identifier);
543                                 DefRNA.error= 1;
544                         }
545                         break;
546                 }
547                 case PROP_COLLECTION: {
548                         CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
549
550                         if(dp->dnatype && strcmp(dp->dnatype, "ListBase")==0) {
551                                 if(!cprop->begin)
552                                         cprop->begin= (void*)rna_def_property_begin_func(f, srna, prop, dp);
553                         }
554                         else if(dp->dnalengthname || dp->dnalengthfixed) {
555                                 if(!cprop->begin)
556                                         cprop->begin= (void*)rna_def_property_begin_func(f, srna, prop, dp);
557                                 if(!cprop->length)
558                                         cprop->length= (void*)rna_def_property_length_func(f, srna, prop, dp);
559                         }
560
561                         if(!(prop->flag & PROP_IDPROPERTY)) {
562                                 if(!cprop->begin) {
563                                         fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a begin function.\n", srna->identifier, prop->identifier);
564                                         DefRNA.error= 1;
565                                 }
566                                 if(!cprop->next) {
567                                         fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a next function.\n", srna->identifier, prop->identifier);
568                                         DefRNA.error= 1;
569                                 }
570                                 if(!cprop->get) {
571                                         fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a get function.\n", srna->identifier, prop->identifier);
572                                         DefRNA.error= 1;
573                                 }
574                         }
575                         if(!cprop->structtype && !cprop->type) {
576                                 fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have either type function or fixed type.\n", srna->identifier, prop->identifier);
577                                 DefRNA.error= 1;
578                         }
579                         break;
580                 }
581         }
582 }
583
584 static const char *rna_find_type(const char *type)
585 {
586         StructDefRNA *ds;
587
588         for(ds=DefRNA.structs.first; ds; ds=ds->next)
589                 if(ds->dnaname && strcmp(ds->dnaname, type)==0)
590                         return ds->srna->identifier;
591         
592         return NULL;
593 }
594
595 static void rna_auto_types()
596 {
597         StructDefRNA *ds;
598         PropertyDefRNA *dp;
599
600         for(ds=DefRNA.structs.first; ds; ds=ds->next) {
601                 /* DNA name for Screen is patched in 2.5, we do the reverse here .. */
602                 if(ds->dnaname && strcmp(ds->dnaname, "Screen") == 0)
603                         ds->dnaname= "bScreen";
604
605                 for(dp=ds->properties.first; dp; dp=dp->next) {
606                         if(dp->dnastructname && strcmp(dp->dnastructname, "Screen") == 0)
607                                 dp->dnastructname= "bScreen";
608
609                         if(dp->dnatype) {
610                                 if(dp->prop->type == PROP_POINTER) {
611                                         PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
612
613                                         if(!pprop->structtype && !pprop->type)
614                                                 pprop->structtype= (StructRNA*)rna_find_type(dp->dnatype);
615                                 }
616                                 else if(dp->prop->type== PROP_COLLECTION) {
617                                         CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
618
619                                         if(!cprop->structtype && !cprop->type && strcmp(dp->dnatype, "ListBase")==0)
620                                                 cprop->structtype= (StructRNA*)rna_find_type(dp->dnatype);
621                                 }
622                         }
623                 }
624         }
625 }
626
627 static void rna_sort(BlenderRNA *brna)
628 {
629         StructRNA *srna;
630
631         rna_sortlist(&brna->structs, cmp_struct);
632
633         for(srna=brna->structs.first; srna; srna=srna->next)
634                 rna_sortlist(&srna->properties, cmp_property);
635 }
636
637 static const char *rna_property_structname(PropertyType type)
638 {
639         switch(type) {
640                 case PROP_BOOLEAN: return "BooleanPropertyRNA";
641                 case PROP_INT: return "IntPropertyRNA";
642                 case PROP_FLOAT: return "FloatPropertyRNA";
643                 case PROP_STRING: return "StringPropertyRNA";
644                 case PROP_ENUM: return "EnumPropertyRNA";
645                 case PROP_POINTER: return "PointerPropertyRNA";
646                 case PROP_COLLECTION: return "CollectionPropertyRNA";
647                 default: return "UnknownPropertyRNA";
648         }
649 }
650
651 static const char *rna_property_typename(PropertyType type)
652 {
653         switch(type) {
654                 case PROP_BOOLEAN: return "PROP_BOOLEAN";
655                 case PROP_INT: return "PROP_INT";
656                 case PROP_FLOAT: return "PROP_FLOAT";
657                 case PROP_STRING: return "PROP_STRING";
658                 case PROP_ENUM: return "PROP_ENUM";
659                 case PROP_POINTER: return "PROP_POINTER";
660                 case PROP_COLLECTION: return "PROP_COLLECTION";
661                 default: return "PROP_UNKNOWN";
662         }
663 }
664
665 static const char *rna_property_subtypename(PropertyType type)
666 {
667         switch(type) {
668                 case PROP_NONE: return "PROP_NONE";
669                 case PROP_UNSIGNED: return "PROP_UNSIGNED";
670                 case PROP_FILEPATH: return "PROP_FILEPATH";
671                 case PROP_DIRPATH: return "PROP_DIRPATH";
672                 case PROP_COLOR: return "PROP_COLOR";
673                 case PROP_VECTOR: return "PROP_VECTOR";
674                 case PROP_MATRIX: return "PROP_MATRIX";
675                 case PROP_ROTATION: return "PROP_ROTATION";
676                 case PROP_NEVER_NULL: return "PROP_NEVER_NULL";
677                 default: return "PROP_UNKNOWN";
678         }
679 }
680
681 static void rna_generate_prototypes(BlenderRNA *brna, FILE *f)
682 {
683         StructRNA *srna;
684
685         for(srna=brna->structs.first; srna; srna=srna->next)
686                 fprintf(f, "extern StructRNA RNA_%s;\n", srna->identifier);
687         fprintf(f, "\n");
688 }
689
690 static void rna_generate_blender(BlenderRNA *brna, FILE *f)
691 {
692         StructRNA *srna;
693
694         fprintf(f, "BlenderRNA BLENDER_RNA = {");
695
696         srna= brna->structs.first;
697         if(srna) fprintf(f, "{&RNA_%s, ", srna->identifier);
698         else fprintf(f, "{NULL, ");
699
700         srna= brna->structs.last;
701         if(srna) fprintf(f, "&RNA_%s}", srna->identifier);
702         else fprintf(f, "NULL}");
703
704         fprintf(f, "};\n\n");
705 }
706
707 static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
708 {
709         PropertyRNA *prop;
710
711         fprintf(f, "/* %s */\n", srna->name);
712
713         if(srna->properties.first)
714                 fprintf(f, "\n");
715
716         for(prop=srna->properties.first; prop; prop=prop->next)
717                 fprintf(f, "%s%s rna_%s_%s;\n", (prop->flag & PROP_EXPORT)? "": "static ", rna_property_structname(prop->type), srna->identifier, prop->identifier);
718         fprintf(f, "\n");
719
720         for(prop=srna->properties.first; prop; prop=prop->next) {
721                 switch(prop->type) {
722                         case PROP_ENUM: {
723                                 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
724                                 int i;
725
726                                 if(eprop->item) {
727                                         fprintf(f, "static EnumPropertyItem rna_%s_%s_items[%d] = {", srna->identifier, prop->identifier, eprop->totitem);
728
729                                         for(i=0; i<eprop->totitem; i++) {
730                                                 fprintf(f, "{%d, ", eprop->item[i].value);
731                                                 rna_print_c_string(f, eprop->item[i].identifier); fprintf(f, ", ");
732                                                 rna_print_c_string(f, eprop->item[i].name); fprintf(f, ", ");
733                                                 rna_print_c_string(f, eprop->item[i].description); fprintf(f, "}");
734                                                 if(i != eprop->totitem-1)
735                                                         fprintf(f, ", ");
736                                         }
737
738                                         fprintf(f, "};\n\n");
739                                 }
740                                 else {
741                                         fprintf(stderr, "rna_generate_structs: %s.%s, enum must have items defined.\n", srna->identifier, prop->identifier);
742                                         DefRNA.error= 1;
743                                 }
744                                 break;
745                         }
746                         case PROP_BOOLEAN: {
747                                 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
748                                 unsigned int i;
749
750                                 if(prop->arraylength) {
751                                         fprintf(f, "static int rna_%s_%s_default[%d] = {", srna->identifier, prop->identifier, prop->arraylength);
752
753                                         for(i=0; i<prop->arraylength; i++) {
754                                                 if(bprop->defaultarray)
755                                                         fprintf(f, "%d", bprop->defaultarray[i]);
756                                                 else
757                                                         fprintf(f, "%d", bprop->defaultvalue);
758                                                 if(i != prop->arraylength-1)
759                                                         fprintf(f, ", ");
760                                         }
761
762                                         fprintf(f, "};\n\n");
763                                 }
764                                 break;
765                         }
766                         case PROP_INT: {
767                                 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
768                                 unsigned int i;
769
770                                 if(prop->arraylength) {
771                                         fprintf(f, "static int rna_%s_%s_default[%d] = {", srna->identifier, prop->identifier, prop->arraylength);
772
773                                         for(i=0; i<prop->arraylength; i++) {
774                                                 if(iprop->defaultarray)
775                                                         fprintf(f, "%d", iprop->defaultarray[i]);
776                                                 else
777                                                         fprintf(f, "%d", iprop->defaultvalue);
778                                                 if(i != prop->arraylength-1)
779                                                         fprintf(f, ", ");
780                                         }
781
782                                         fprintf(f, "};\n\n");
783                                 }
784                                 break;
785                         }
786                         case PROP_FLOAT: {
787                                 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
788                                 unsigned int i;
789
790                                 if(prop->arraylength) {
791                                         fprintf(f, "static float rna_%s_%s_default[%d] = {", srna->identifier, prop->identifier, prop->arraylength);
792
793                                         for(i=0; i<prop->arraylength; i++) {
794                                                 if(fprop->defaultarray)
795                                                         rna_float_print(f, fprop->defaultarray[i]);
796                                                 else
797                                                         rna_float_print(f, fprop->defaultvalue);
798                                                 if(i != prop->arraylength-1)
799                                                         fprintf(f, ", ");
800                                         }
801
802                                         fprintf(f, "};\n\n");
803                                 }
804                                 break;
805                         }
806                         default:
807                                 break;
808                 }
809
810                 fprintf(f, "%s%s rna_%s_%s = {\n", (prop->flag & PROP_EXPORT)? "": "static ", rna_property_structname(prop->type), srna->identifier, prop->identifier);
811
812                 if(prop->next) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s, ", srna->identifier, prop->next->identifier);
813                 else fprintf(f, "\t{NULL, ");
814                 if(prop->prev) fprintf(f, "(PropertyRNA*)&rna_%s_%s,\n", srna->identifier, prop->prev->identifier);
815                 else fprintf(f, "NULL,\n");
816                 fprintf(f, "\t%d, ", prop->magic);
817                 rna_print_c_string(f, prop->identifier);
818                 fprintf(f, ", %d, ", prop->flag);
819                 rna_print_c_string(f, prop->name); fprintf(f, ",\n\t");
820                 rna_print_c_string(f, prop->description); fprintf(f, ",\n");
821                 fprintf(f, "\t%s, %s, %d,\n", rna_property_typename(prop->type), rna_property_subtypename(prop->subtype), prop->arraylength);
822                 fprintf(f, "\t%s, %d, %s},\n", rna_function_string(prop->update), prop->noteflag, rna_function_string(prop->editable));
823
824                 switch(prop->type) {
825                         case PROP_BOOLEAN: {
826                                 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
827                                 fprintf(f, "\t%s, %s, %s, %s, %d, ", rna_function_string(bprop->get), rna_function_string(bprop->set), rna_function_string(bprop->getarray), rna_function_string(bprop->setarray), bprop->defaultvalue);
828                                 if(prop->arraylength) fprintf(f, "rna_%s_%s_default\n", srna->identifier, prop->identifier);
829                                 else fprintf(f, "NULL\n");
830                                 break;
831                         }
832                         case PROP_INT: {
833                                 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
834                                 fprintf(f, "\t%s, %s, %s, %s, %s,\n\t", rna_function_string(iprop->get), rna_function_string(iprop->set), rna_function_string(iprop->getarray), rna_function_string(iprop->setarray), rna_function_string(iprop->range));
835                                 rna_int_print(f, iprop->softmin); fprintf(f, ", ");
836                                 rna_int_print(f, iprop->softmax); fprintf(f, ", ");
837                                 rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
838                                 rna_int_print(f, iprop->hardmax); fprintf(f, ", ");
839                                 rna_int_print(f, iprop->step); fprintf(f, ", ");
840                                 rna_int_print(f, iprop->defaultvalue); fprintf(f, ", ");
841                                 if(prop->arraylength) fprintf(f, "rna_%s_%s_default\n", srna->identifier, prop->identifier);
842                                 else fprintf(f, "NULL\n");
843                                 break;
844                         }
845                         case PROP_FLOAT: {
846                                 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
847                                 fprintf(f, "\t%s, %s, %s, %s, %s, ", rna_function_string(fprop->get), rna_function_string(fprop->set), rna_function_string(fprop->getarray), rna_function_string(fprop->setarray), rna_function_string(fprop->range));
848                                 rna_float_print(f, fprop->softmin); fprintf(f, ", ");
849                                 rna_float_print(f, fprop->softmax); fprintf(f, ", ");
850                                 rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
851                                 rna_float_print(f, fprop->hardmax); fprintf(f, ", ");
852                                 rna_float_print(f, fprop->step); fprintf(f, ", ");
853                                 rna_int_print(f, (int)fprop->precision); fprintf(f, ", ");
854                                 rna_float_print(f, fprop->defaultvalue); fprintf(f, ", ");
855                                 if(prop->arraylength) fprintf(f, "rna_%s_%s_default\n", srna->identifier, prop->identifier);
856                                 else fprintf(f, "NULL\n");
857                                 break;
858                         }
859                         case PROP_STRING: {
860                                 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
861                                 fprintf(f, "\t%s, %s, %s, %d, ", rna_function_string(sprop->get), rna_function_string(sprop->length), rna_function_string(sprop->set), sprop->maxlength);
862                                 rna_print_c_string(f, sprop->defaultvalue); fprintf(f, "\n");
863                                 break;
864                         }
865                         case PROP_ENUM: {
866                                 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
867                                 fprintf(f, "\t%s, %s, rna_%s_%s_items, %d, %d\n", rna_function_string(eprop->get), rna_function_string(eprop->set), srna->identifier, prop->identifier, eprop->totitem, eprop->defaultvalue);
868                                 break;
869                         }
870                         case PROP_POINTER: {
871                                 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
872                                 fprintf(f, "\t%s, %s, %s, ", rna_function_string(pprop->get), rna_function_string(pprop->set), rna_function_string(pprop->type));
873                                 if(pprop->structtype) fprintf(f, "&RNA_%s\n", (char*)pprop->structtype);
874                                 else fprintf(f, "NULL\n");
875                                 break;
876                         }
877                         case PROP_COLLECTION: {
878                                 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
879                                 fprintf(f, "\t%s, %s, %s, %s, %s, %s, %s, %s, ", rna_function_string(cprop->begin), rna_function_string(cprop->next), rna_function_string(cprop->end), rna_function_string(cprop->get), rna_function_string(cprop->type), rna_function_string(cprop->length), rna_function_string(cprop->lookupint), rna_function_string(cprop->lookupstring));
880                                 if(cprop->structtype) fprintf(f, "&RNA_%s\n", (char*)cprop->structtype);
881                                 else fprintf(f, "NULL\n");
882                                 break;
883                         }
884                 }
885
886                 fprintf(f, "};\n\n");
887         }
888
889         fprintf(f, "StructRNA RNA_%s = {\n", srna->identifier);
890
891         if(srna->next) fprintf(f, "\t&RNA_%s, ", srna->next->identifier);
892         else fprintf(f, "\tNULL, ");
893         if(srna->prev) fprintf(f, "&RNA_%s,\n", srna->prev->identifier);
894         else fprintf(f, "NULL,\n");
895
896         fprintf(f, "\t");
897         rna_print_c_string(f, srna->identifier);
898         fprintf(f, ", %d, ", srna->flag);
899         rna_print_c_string(f, srna->name);
900         fprintf(f, ", ");
901         rna_print_c_string(f, srna->description);
902         fprintf(f, ",\n");
903
904         prop= srna->nameproperty;
905         if(prop) fprintf(f, "\t(PropertyRNA*)&rna_%s_%s, ", srna->identifier, prop->identifier);
906         else fprintf(f, "\tNULL, ");
907
908         fprintf(f, "(PropertyRNA*)&rna_%s_rna_properties,\n", srna->identifier);
909
910         if(srna->base) fprintf(f, "\t&RNA_%s,\n", srna->base->identifier);
911         else fprintf(f, "\tNULL,\n");
912
913         if(srna->nested) fprintf(f, "\t&RNA_%s,\n", srna->nested->identifier);
914         else fprintf(f, "\tNULL,\n");
915
916         fprintf(f, "\t%s,\n", rna_function_string(srna->refine));
917
918         prop= srna->properties.first;
919         if(prop) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s, ", srna->identifier, prop->identifier);
920         else fprintf(f, "\t{NULL, ");
921
922         prop= srna->properties.last;
923         if(prop) fprintf(f, "(PropertyRNA*)&rna_%s_%s}\n", srna->identifier, prop->identifier);
924         else fprintf(f, "NULL}\n");
925
926         fprintf(f, "};\n");
927
928         fprintf(f, "\n");
929 }
930
931 typedef struct RNAProcessItem {
932         char *filename;
933         void (*define)(BlenderRNA *brna);
934 } RNAProcessItem;
935
936 RNAProcessItem PROCESS_ITEMS[]= {
937         {"rna_ID.c", RNA_def_ID},
938         {"rna_texture.c", RNA_def_texture},
939         {"rna_action.c", RNA_def_action},
940         {"rna_actuator.c", RNA_def_actuator},
941         {"rna_armature.c", RNA_def_armature},
942         {"rna_brush.c", RNA_def_brush},
943         {"rna_camera.c", RNA_def_camera},
944         {"rna_cloth.c", RNA_def_cloth},
945         {"rna_color.c", RNA_def_color},
946         {"rna_constraint.c", RNA_def_constraint},
947         {"rna_controller.c", RNA_def_controller},
948         {"rna_curve.c", RNA_def_curve},
949         {"rna_fluidsim.c", RNA_def_fluidsim},
950         {"rna_group.c", RNA_def_group},
951         {"rna_image.c", RNA_def_image},
952         {"rna_ipo.c", RNA_def_ipo},
953         {"rna_key.c", RNA_def_key},
954         {"rna_lamp.c", RNA_def_lamp},
955         {"rna_lattice.c", RNA_def_lattice},
956         {"rna_main.c", RNA_def_main},
957         {"rna_material.c", RNA_def_material},
958         {"rna_mesh.c", RNA_def_mesh},
959         {"rna_meta.c", RNA_def_meta},
960         {"rna_modifier.c", RNA_def_modifier},
961         {"rna_nodetree.c", RNA_def_nodetree},
962         {"rna_object.c", RNA_def_object},
963         {"rna_object_force.c", RNA_def_object_force},
964         {"rna_packedfile.c", RNA_def_packedfile},
965         {"rna_particle.c", RNA_def_particle},
966         {"rna_pose.c", RNA_def_pose},
967         {"rna_property.c", RNA_def_gameproperty},
968         {"rna_radio.c", RNA_def_radio},
969         {"rna_rna.c", RNA_def_rna},
970         {"rna_scene.c", RNA_def_scene},
971         {"rna_screen.c", RNA_def_screen},
972         {"rna_scriptlink.c", RNA_def_scriptlink},
973         {"rna_sensor.c", RNA_def_sensor},
974         {"rna_sequence.c", RNA_def_sequence},
975         {"rna_space.c", RNA_def_space},
976         {"rna_text.c", RNA_def_text},
977         {"rna_sound.c", RNA_def_sound},
978         {"rna_userdef.c", RNA_def_userdef},
979         {"rna_vfont.c", RNA_def_vfont},
980         {"rna_vpaint.c", RNA_def_vpaint},
981         {"rna_wm.c", RNA_def_wm},
982         {"rna_world.c", RNA_def_world}, 
983         {NULL, NULL}};
984
985 static void rna_generate(BlenderRNA *brna, FILE *f, char *filename)
986 {
987         StructDefRNA *ds;
988         PropertyDefRNA *dp;
989         
990         fprintf(f, "\n/* Automatically generated struct definitions for the Data API.\n"
991                         "   Do not edit manually, changes will be overwritten */\n\n"
992                         "#define RNA_RUNTIME\n\n");
993
994         fprintf(f, "#include <float.h>\n");
995         fprintf(f, "#include <limits.h>\n");
996         fprintf(f, "#include <string.h>\n\n");
997
998         fprintf(f, "#include \"BLI_blenlib.h\"\n\n");
999
1000         fprintf(f, "#include \"BKE_utildefines.h\"\n\n");
1001
1002         fprintf(f, "#include \"RNA_define.h\"\n");
1003         fprintf(f, "#include \"RNA_types.h\"\n");
1004         fprintf(f, "#include \"rna_internal.h\"\n\n");
1005
1006         rna_generate_prototypes(brna, f);
1007
1008         fprintf(f, "#include \"%s\"\n\n", filename);
1009
1010         fprintf(f, "/* Autogenerated Functions */\n\n");
1011
1012         for(ds=DefRNA.structs.first; ds; ds=ds->next)
1013                 if(!filename || ds->filename == filename)
1014                         for(dp=ds->properties.first; dp; dp=dp->next)
1015                                 rna_def_property_funcs(f, dp);
1016
1017         for(ds=DefRNA.structs.first; ds; ds=ds->next)
1018                 if(!filename || ds->filename == filename)
1019                         rna_generate_struct(brna, ds->srna, f);
1020
1021         if(strcmp(filename, "rna_ID.c") == 0) {
1022                 /* this is ugly, but we cannot have c files compiled for both
1023                  * makesrna and blender with some build systems at the moment */
1024                 fprintf(f, "#include \"rna_define.c\"\n\n");
1025
1026                 rna_generate_blender(brna, f);
1027         }
1028 }
1029
1030 static void make_bad_file(char *file)
1031 {
1032         FILE *fp= fopen(file, "w");
1033         fprintf(fp, "ERROR! Cannot make correct RNA file, STUPID!\n");
1034         fclose(fp);
1035 }
1036
1037 static int rna_preprocess(char *outfile)
1038 {
1039         BlenderRNA *brna;
1040         StructDefRNA *ds;
1041         FILE *file;
1042         char deffile[4096];
1043         int i, status, len;
1044
1045         /* define rna */
1046         brna= RNA_create();
1047
1048         for(i=0; PROCESS_ITEMS[i].filename; i++) {
1049                 if(PROCESS_ITEMS[i].define) {
1050                         PROCESS_ITEMS[i].define(brna);
1051
1052                         for(ds=DefRNA.structs.first; ds; ds=ds->next)
1053                                 if(!ds->filename)
1054                                         ds->filename= PROCESS_ITEMS[i].filename;
1055                 }
1056         }
1057
1058         rna_sort(brna);
1059         rna_auto_types();
1060
1061         status= (DefRNA.error != 0);
1062
1063         len= strlen(outfile);
1064
1065         for(i=0; PROCESS_ITEMS[i].filename; i++) {
1066                 strcpy(deffile, outfile);
1067                 strcat(deffile, PROCESS_ITEMS[i].filename);
1068                 deffile[strlen(deffile)-2] = '\0';
1069                 strcat(deffile, "_gen.c");
1070
1071                 if(status) {
1072                         make_bad_file(deffile);
1073                 }
1074                 else {
1075                         file = fopen(deffile, "w");
1076
1077                         if(!file) {
1078                                 printf ("Unable to open file: %s\n", deffile);
1079                                 status = 1;
1080                         }
1081                         else {
1082                                 rna_generate(brna, file, PROCESS_ITEMS[i].filename);
1083                                 fclose(file);
1084
1085                                 status= (DefRNA.error != 0);
1086                         }
1087                 }
1088         }
1089
1090         RNA_define_free(brna);
1091         RNA_free(brna);
1092
1093         return status;
1094 }
1095
1096 int main(int argc, char **argv)
1097 {
1098         int totblock, return_status = 0;
1099
1100         if (argc<2) {
1101                 printf("Usage: %s outdirectory/\n", argv[0]);
1102                 return_status = 1;
1103         }
1104         else {
1105                 printf("Running makesrna, program versions %s\n",  RNA_VERSION_DATE);
1106                 return_status= rna_preprocess(argv[1]);
1107         }
1108
1109         totblock= MEM_get_memory_blocks_in_use();
1110         if(totblock!=0) {
1111                 printf("Error Totblock: %d\n",totblock);
1112                 MEM_printmemlist();
1113         }
1114
1115         return return_status;
1116 }
1117
1118