code cleanup: quiet warning
[blender.git] / source / blender / makesrna / intern / makesrna.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Blender Foundation (2008).
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/makesrna/intern/makesrna.c
24  *  \ingroup RNA
25  */
26
27
28 #include <float.h>
29 #include <limits.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <errno.h>
34
35 #include "MEM_guardedalloc.h"
36
37 #include "RNA_access.h"
38 #include "RNA_define.h"
39 #include "RNA_types.h"
40
41 #include "rna_internal.h"
42
43 #ifdef _WIN32
44 #  ifndef snprintf
45 #    define snprintf _snprintf
46 #  endif
47 #endif
48
49 /* so we can use __func__ everywhere */
50 #if defined(_MSC_VER)
51 #  define __func__ __FUNCTION__
52 #endif
53
54 /* copied from BLI_utildefines.h ugh */
55 #ifdef __GNUC__
56 #  define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
57 #else
58 #  define UNUSED(x) x
59 #endif
60
61 /* Replace if different */
62 #define TMP_EXT ".tmp"
63
64 /* copied from BLI_file_older */
65 #include <sys/stat.h>
66 static int file_older(const char *file1, const char *file2)
67 {
68         struct stat st1, st2;
69         /* printf("compare: %s %s\n", file1, file2); */
70
71         if (stat(file1, &st1)) return 0;
72         if (stat(file2, &st2)) return 0;
73
74         return (st1.st_mtime < st2.st_mtime);
75 }
76 static const char *makesrna_path = NULL;
77
78 /* forward declarations */
79 static void rna_generate_static_parameter_prototypes(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc,
80                                                      const char *name_override, int close_prototype);
81
82 /* helpers */
83 #define WRITE_COMMA { \
84                 if (!first) \
85                         fprintf(f, ", "); \
86                 first = 0; \
87         } (void)0
88
89 #define WRITE_PARAM(param) { \
90                 WRITE_COMMA; \
91                 fprintf(f, param); \
92         }
93
94 static int replace_if_different(char *tmpfile, const char *dep_files[])
95 {
96         /* return 0;  *//* use for testing had edited rna */
97
98 #define REN_IF_DIFF                                                           \
99         {                                                                         \
100                 FILE *file_test = fopen(orgfile, "rb");                               \
101                 if (file_test) {                                                      \
102                         fclose(file_test);                                                \
103                         if (fp_org) fclose(fp_org);                                       \
104                         if (fp_new) fclose(fp_new);                                       \
105                         if (remove(orgfile) != 0) {                                       \
106                                 fprintf(stderr, "%s:%d, Remove Error (%s): \"%s\"\n",         \
107                                         __FILE__, __LINE__, strerror(errno), orgfile);        \
108                                 return -1;                                                    \
109                         }                                                                 \
110                 }                                                                     \
111         }                                                                         \
112         if (rename(tmpfile, orgfile) != 0) {                                      \
113                 fprintf(stderr, "%s:%d, Rename Error (%s): \"%s\" -> \"%s\"\n",       \
114                         __FILE__, __LINE__, strerror(errno), tmpfile, orgfile);       \
115                 return -1;                                                            \
116         }                                                                         \
117         remove(tmpfile);                                                          \
118         return 1                                                                  \
119
120 /* end REN_IF_DIFF */
121
122
123         FILE *fp_new = NULL, *fp_org = NULL;
124         int len_new, len_org;
125         char *arr_new, *arr_org;
126         int cmp;
127
128         char orgfile[4096];
129
130         strcpy(orgfile, tmpfile);
131         orgfile[strlen(orgfile) - strlen(TMP_EXT)] = '\0'; /* strip '.tmp' */
132
133         fp_org = fopen(orgfile, "rb");
134
135         if (fp_org == NULL) {
136                 REN_IF_DIFF;
137         }
138
139
140         /* XXX, trick to work around dependency problem
141          * assumes dep_files is in the same dir as makesrna.c, which is true for now. */
142
143         if (1) {
144                 /* first check if makesrna.c is newer then generated files
145                  * for development on makesrna.c you may want to disable this */
146                 if (file_older(orgfile, __FILE__)) {
147                         REN_IF_DIFF;
148                 }
149
150                 if (file_older(orgfile, makesrna_path)) {
151                         REN_IF_DIFF;
152                 }
153
154                 /* now check if any files we depend on are newer then any generated files */
155                 if (dep_files) {
156                         int pass;
157                         for (pass = 0; dep_files[pass]; pass++) {
158                                 char from_path[4096] = __FILE__;
159                                 char *p1, *p2;
160
161                                 /* dir only */
162                                 p1 = strrchr(from_path, '/');
163                                 p2 = strrchr(from_path, '\\');
164                                 strcpy((p1 > p2 ? p1 : p2) + 1, dep_files[pass]);
165                                 /* account for build deps, if makesrna.c (this file) is newer */
166                                 if (file_older(orgfile, from_path)) {
167                                         REN_IF_DIFF;
168                                 }
169                         }
170                 }
171         }
172         /* XXX end dep trick */
173
174
175         fp_new = fopen(tmpfile, "rb");
176
177         if (fp_new == NULL) {
178                 /* shouldn't happen, just to be safe */
179                 fprintf(stderr, "%s:%d, open error: \"%s\"\n", __FILE__, __LINE__, tmpfile);
180                 fclose(fp_org);
181                 return -1;
182         }
183
184         fseek(fp_new, 0L, SEEK_END); len_new = ftell(fp_new); fseek(fp_new, 0L, SEEK_SET);
185         fseek(fp_org, 0L, SEEK_END); len_org = ftell(fp_org); fseek(fp_org, 0L, SEEK_SET);
186
187
188         if (len_new != len_org) {
189                 fclose(fp_new);
190                 fclose(fp_org);
191                 REN_IF_DIFF;
192         }
193
194         /* now compare the files... */
195         arr_new = MEM_mallocN(sizeof(char) * len_new, "rna_cmp_file_new");
196         arr_org = MEM_mallocN(sizeof(char) * len_org, "rna_cmp_file_org");
197
198         if (fread(arr_new, sizeof(char), len_new, fp_new) != len_new)
199                 fprintf(stderr, "%s:%d, error reading file %s for comparison.\n", __FILE__, __LINE__, tmpfile);
200         if (fread(arr_org, sizeof(char), len_org, fp_org) != len_org)
201                 fprintf(stderr, "%s:%d, error reading file %s for comparison.\n", __FILE__, __LINE__, orgfile);
202
203         fclose(fp_new);
204         fclose(fp_org);
205
206         cmp = memcmp(arr_new, arr_org, len_new);
207
208         MEM_freeN(arr_new);
209         MEM_freeN(arr_org);
210
211         if (cmp) {
212                 REN_IF_DIFF;
213         }
214         else {
215                 remove(tmpfile);
216                 return 0;
217         }
218
219 #undef REN_IF_DIFF
220 }
221
222 /* Helper to solve keyword problems with C/C++ */
223
224 static const char *rna_safe_id(const char *id)
225 {
226         if (strcmp(id, "default") == 0)
227                 return "default_value";
228         else if (strcmp(id, "operator") == 0)
229                 return "operator_value";
230         else if (strcmp(id, "new") == 0)
231                 return "create";
232
233         return id;
234 }
235
236 /* Sorting */
237
238 static int cmp_struct(const void *a, const void *b)
239 {
240         const StructRNA *structa = *(const StructRNA **)a;
241         const StructRNA *structb = *(const StructRNA **)b;
242
243         return strcmp(structa->identifier, structb->identifier);
244 }
245
246 static int cmp_property(const void *a, const void *b)
247 {
248         const PropertyRNA *propa = *(const PropertyRNA **)a;
249         const PropertyRNA *propb = *(const PropertyRNA **)b;
250
251         if (strcmp(propa->identifier, "rna_type") == 0) return -1;
252         else if (strcmp(propb->identifier, "rna_type") == 0) return 1;
253
254         if (strcmp(propa->identifier, "name") == 0) return -1;
255         else if (strcmp(propb->identifier, "name") == 0) return 1;
256
257         return strcmp(propa->name, propb->name);
258 }
259
260 static int cmp_def_struct(const void *a, const void *b)
261 {
262         const StructDefRNA *dsa = *(const StructDefRNA **)a;
263         const StructDefRNA *dsb = *(const StructDefRNA **)b;
264
265         return cmp_struct(&dsa->srna, &dsb->srna);
266 }
267
268 static int cmp_def_property(const void *a, const void *b)
269 {
270         const PropertyDefRNA *dpa = *(const PropertyDefRNA **)a;
271         const PropertyDefRNA *dpb = *(const PropertyDefRNA **)b;
272
273         return cmp_property(&dpa->prop, &dpb->prop);
274 }
275
276 static void rna_sortlist(ListBase *listbase, int (*cmp)(const void *, const void *))
277 {
278         Link *link;
279         void **array;
280         int a, size;
281         
282         if (listbase->first == listbase->last)
283                 return;
284
285         for (size = 0, link = listbase->first; link; link = link->next)
286                 size++;
287
288         array = MEM_mallocN(sizeof(void *) * size, "rna_sortlist");
289         for (a = 0, link = listbase->first; link; link = link->next, a++)
290                 array[a] = link;
291
292         qsort(array, size, sizeof(void *), cmp);
293
294         listbase->first = listbase->last = NULL;
295         for (a = 0; a < size; a++) {
296                 link = array[a];
297                 link->next = link->prev = NULL;
298                 rna_addtail(listbase, link);
299         }
300
301         MEM_freeN(array);
302 }
303
304 /* Preprocessing */
305
306 static void rna_print_c_string(FILE *f, const char *str)
307 {
308         static const char *escape[] = {"\''", "\"\"", "\??", "\\\\", "\aa", "\bb", "\ff", "\nn", "\rr", "\tt", "\vv", NULL};
309         int i, j;
310
311         if (!str) {
312                 fprintf(f, "NULL");
313                 return;
314         }
315
316         fprintf(f, "\"");
317         for (i = 0; str[i]; i++) {
318                 for (j = 0; escape[j]; j++)
319                         if (str[i] == escape[j][0])
320                                 break;
321
322                 if (escape[j]) fprintf(f, "\\%c", escape[j][1]);
323                 else fprintf(f, "%c", str[i]);
324         }
325         fprintf(f, "\"");
326 }
327
328 static void rna_print_data_get(FILE *f, PropertyDefRNA *dp)
329 {
330         if (dp->dnastructfromname && dp->dnastructfromprop)
331                 fprintf(f, "    %s *data= (%s*)(((%s*)ptr->data)->%s);\n", dp->dnastructname, dp->dnastructname,
332                         dp->dnastructfromname, dp->dnastructfromprop);
333         else
334                 fprintf(f, "    %s *data= (%s*)(ptr->data);\n", dp->dnastructname, dp->dnastructname);
335 }
336
337 static void rna_print_id_get(FILE *f, PropertyDefRNA *UNUSED(dp))
338 {
339         fprintf(f, "    ID *id= ptr->id.data;\n");
340 }
341
342 static void rna_construct_function_name(char *buffer, int size, const char *structname, const char *propname, const char *type)
343 {
344         snprintf(buffer, size, "%s_%s_%s", structname, propname, type);
345 }
346
347 static void rna_construct_wrapper_function_name(char *buffer, int size, const char *structname, const char *propname, const char *type)
348 {
349         if (type == NULL || type[0] == '\0')
350                 snprintf(buffer, size, "%s_%s", structname, propname);
351         else
352                 snprintf(buffer, size, "%s_%s_%s", structname, propname, type);
353 }
354
355 static char *rna_alloc_function_name(const char *structname, const char *propname, const char *type)
356 {
357         AllocDefRNA *alloc;
358         char buffer[2048];
359         char *result;
360
361         rna_construct_function_name(buffer, sizeof(buffer), structname, propname, type);
362         result = MEM_callocN(sizeof(char) * strlen(buffer) + 1, "rna_alloc_function_name");
363         strcpy(result, buffer);
364
365         alloc = MEM_callocN(sizeof(AllocDefRNA), "AllocDefRNA");
366         alloc->mem = result;
367         rna_addtail(&DefRNA.allocs, alloc);
368
369         return result;
370 }
371
372 static StructRNA *rna_find_struct(const char *identifier)
373 {
374         StructDefRNA *ds;
375
376         for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
377                 if (strcmp(ds->srna->identifier, identifier) == 0)
378                         return ds->srna;
379
380         return NULL;
381 }
382
383 static const char *rna_find_type(const char *type)
384 {
385         StructDefRNA *ds;
386
387         for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
388                 if (ds->dnaname && strcmp(ds->dnaname, type) == 0)
389                         return ds->srna->identifier;
390
391         return NULL;
392 }
393
394 static const char *rna_find_dna_type(const char *type)
395 {
396         StructDefRNA *ds;
397
398         for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
399                 if (strcmp(ds->srna->identifier, type) == 0)
400                         return ds->dnaname;
401
402         return NULL;
403 }
404
405 static const char *rna_type_type_name(PropertyRNA *prop)
406 {
407         switch (prop->type) {
408                 case PROP_BOOLEAN:
409                 case PROP_INT:
410                 case PROP_ENUM:
411                         return "int";
412                 case PROP_FLOAT:
413                         return "float";
414                 case PROP_STRING:
415                         if (prop->flag & PROP_THICK_WRAP) {
416                                 return "char*";
417                         }
418                         else {
419                                 return "const char*";
420                         }
421                 default:
422                         return NULL;
423         }
424 }
425
426 static const char *rna_type_type(PropertyRNA *prop)
427 {
428         const char *type;
429
430         type = rna_type_type_name(prop);
431
432         if (type)
433                 return type;
434
435         return "PointerRNA";
436 }
437
438 static const char *rna_type_struct(PropertyRNA *prop)
439 {
440         const char *type;
441
442         type = rna_type_type_name(prop);
443
444         if (type)
445                 return "";
446
447         return "struct ";
448 }
449
450 static const char *rna_parameter_type_name(PropertyRNA *parm)
451 {
452         const char *type;
453
454         type = rna_type_type_name(parm);
455
456         if (type)
457                 return type;
458
459         switch (parm->type) {
460                 case PROP_POINTER:
461                 {
462                         PointerPropertyRNA *pparm = (PointerPropertyRNA *)parm;
463
464                         if (parm->flag & PROP_RNAPTR)
465                                 return "PointerRNA";
466                         else
467                                 return rna_find_dna_type((const char *)pparm->type);
468                 }
469                 case PROP_COLLECTION:
470                 {
471                         return "ListBase";
472                 }
473                 default:
474                         return "<error, no type specified>";
475         }
476 }
477
478 static int rna_enum_bitmask(PropertyRNA *prop)
479 {
480         EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
481         int a, mask = 0;
482
483         if (eprop->item) {
484                 for (a = 0; a < eprop->totitem; a++)
485                         if (eprop->item[a].identifier[0])
486                                 mask |= eprop->item[a].value;
487         }
488         
489         return mask;
490 }
491
492 static int rna_color_quantize(PropertyRNA *prop, PropertyDefRNA *dp)
493 {
494         return ( (prop->type == PROP_FLOAT) &&
495                  (prop->subtype == PROP_COLOR || prop->subtype == PROP_COLOR_GAMMA) &&
496                  (IS_DNATYPE_FLOAT_COMPAT(dp->dnatype) == 0) );
497 }
498
499 static const char *rna_function_string(void *func)
500 {
501         return (func) ? (const char *)func : "NULL";
502 }
503
504 static void rna_float_print(FILE *f, float num)
505 {
506         if (num == -FLT_MAX) fprintf(f, "-FLT_MAX");
507         else if (num == FLT_MAX) fprintf(f, "FLT_MAX");
508         else if ((int)num == num) fprintf(f, "%.1ff", num);
509         else fprintf(f, "%.10ff", num);
510 }
511
512 static void rna_int_print(FILE *f, int num)
513 {
514         if (num == INT_MIN) fprintf(f, "INT_MIN");
515         else if (num == INT_MAX) fprintf(f, "INT_MAX");
516         else fprintf(f, "%d", num);
517 }
518
519 static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp,
520                                        const char *manualfunc)
521 {
522         char *func;
523
524         if (prop->flag & PROP_IDPROPERTY && manualfunc == NULL)
525                 return NULL;
526
527         if (!manualfunc) {
528                 if (!dp->dnastructname || !dp->dnaname) {
529                         fprintf(stderr, "%s (0): %s.%s has no valid dna info.\n",
530                                 __func__, srna->identifier, prop->identifier);
531                         DefRNA.error = 1;
532                         return NULL;
533                 }
534
535                 /* typecheck,  */
536                 if (dp->dnatype && *dp->dnatype) {
537
538                         if (prop->type == PROP_FLOAT) {
539                                 if (IS_DNATYPE_FLOAT_COMPAT(dp->dnatype) == 0) {
540                                         if (prop->subtype != PROP_COLOR_GAMMA) { /* colors are an exception. these get translated */
541                                                 fprintf(stderr, "%s (1): %s.%s is a '%s' but wrapped as type '%s'.\n",
542                                                         __func__, srna->identifier, prop->identifier, dp->dnatype,
543                                                         RNA_property_typename(prop->type));
544                                                 DefRNA.error = 1;
545                                                 return NULL;
546                                         }
547                                 }
548                         }
549                         else if (prop->type == PROP_INT || prop->type == PROP_BOOLEAN || prop->type == PROP_ENUM) {
550                                 if (IS_DNATYPE_INT_COMPAT(dp->dnatype) == 0) {
551                                         fprintf(stderr, "%s (2): %s.%s is a '%s' but wrapped as type '%s'.\n",
552                                                 __func__, srna->identifier, prop->identifier, dp->dnatype,
553                                                 RNA_property_typename(prop->type));
554                                         DefRNA.error = 1;
555                                         return NULL;
556                                 }
557                         }
558                 }
559
560         }
561
562         func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
563
564         switch (prop->type) {
565                 case PROP_STRING:
566                 {
567                         StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
568                         fprintf(f, "void %s(PointerRNA *ptr, char *value)\n", func);
569                         fprintf(f, "{\n");
570                         if (manualfunc) {
571                                 fprintf(f, "    %s(ptr, value);\n", manualfunc);
572                         }
573                         else {
574                                 const PropertySubType subtype = prop->subtype;
575                                 const char *string_copy_func = (subtype == PROP_FILEPATH ||
576                                                                 subtype == PROP_DIRPATH  ||
577                                                                 subtype == PROP_FILENAME ||
578                                                                 subtype == PROP_BYTESTRING) ?
579                                                                "BLI_strncpy" : "BLI_strncpy_utf8";
580
581                                 rna_print_data_get(f, dp);
582
583                                 if (!(prop->flag & PROP_NEVER_NULL)) {
584                                         fprintf(f, "    if (data->%s == NULL) {\n", dp->dnaname);
585                                         fprintf(f, "            *value = '\\0';\n");
586                                         fprintf(f, "            return;\n");
587                                         fprintf(f, "    }\n");
588                                 }
589
590                                 if (sprop->maxlength)
591                                         fprintf(f, "    %s(value, data->%s, %d);\n", string_copy_func, dp->dnaname, sprop->maxlength);
592                                 else
593                                         fprintf(f, "    %s(value, data->%s, sizeof(data->%s));\n", string_copy_func,
594                                                 dp->dnaname, dp->dnaname);
595                         }
596                         fprintf(f, "}\n\n");
597                         break;
598                 }
599                 case PROP_POINTER:
600                 {
601                         fprintf(f, "PointerRNA %s(PointerRNA *ptr)\n", func);
602                         fprintf(f, "{\n");
603                         if (manualfunc) {
604                                 fprintf(f, "    return %s(ptr);\n", manualfunc);
605                         }
606                         else {
607                                 PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
608                                 rna_print_data_get(f, dp);
609                                 if (dp->dnapointerlevel == 0)
610                                         fprintf(f, "    return rna_pointer_inherit_refine(ptr, &RNA_%s, &data->%s);\n",
611                                                 (const char *)pprop->type, dp->dnaname);
612                                 else
613                                         fprintf(f, "    return rna_pointer_inherit_refine(ptr, &RNA_%s, data->%s);\n",
614                                                 (const char *)pprop->type, dp->dnaname);
615                         }
616                         fprintf(f, "}\n\n");
617                         break;
618                 }
619                 case PROP_COLLECTION:
620                 {
621                         CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
622
623                         fprintf(f, "static PointerRNA %s(CollectionPropertyIterator *iter)\n", func);
624                         fprintf(f, "{\n");
625                         if (manualfunc) {
626                                 if (strcmp(manualfunc, "rna_iterator_listbase_get") == 0 ||
627                                     strcmp(manualfunc, "rna_iterator_array_get") == 0 ||
628                                     strcmp(manualfunc, "rna_iterator_array_dereference_get") == 0)
629                                 {
630                                         fprintf(f, "    return rna_pointer_inherit_refine(&iter->parent, &RNA_%s, %s(iter));\n",
631                                                 (cprop->item_type) ? (const char *)cprop->item_type : "UnknownType", manualfunc);
632                                 }
633                                 else {
634                                         fprintf(f, "    return %s(iter);\n", manualfunc);
635                                 }
636                         }
637                         fprintf(f, "}\n\n");
638                         break;
639                 }
640                 default:
641                         if (prop->arraydimension) {
642                                 if (prop->flag & PROP_DYNAMIC)
643                                         fprintf(f, "void %s(PointerRNA *ptr, %s values[])\n", func, rna_type_type(prop));
644                                 else
645                                         fprintf(f, "void %s(PointerRNA *ptr, %s values[%u])\n", func, rna_type_type(prop),
646                                                 prop->totarraylength);
647                                 fprintf(f, "{\n");
648
649                                 if (manualfunc) {
650                                         fprintf(f, "    %s(ptr, values);\n", manualfunc);
651                                 }
652                                 else {
653                                         rna_print_data_get(f, dp);
654
655                                         if (prop->flag & PROP_DYNAMIC) {
656                                                 char *lenfunc = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier),
657                                                                                         "get_length");
658                                                 fprintf(f, "    int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
659                                                 fprintf(f, "    int len= %s(ptr, arraylen);\n\n", lenfunc);
660                                                 fprintf(f, "    for (i=0; i<len; i++) {\n");
661                                                 MEM_freeN(lenfunc);
662                                         }
663                                         else {
664                                                 fprintf(f, "    int i;\n\n");
665                                                 fprintf(f, "    for (i=0; i<%u; i++) {\n", prop->totarraylength);
666                                         }
667
668                                         if (dp->dnaarraylength == 1) {
669                                                 if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
670                                                         fprintf(f, "            values[i] = %s((data->%s & (%d<<i)) != 0);\n",
671                                                                 (dp->booleannegative) ? "!" : "", dp->dnaname, dp->booleanbit);
672                                                 }
673                                                 else {
674                                                         fprintf(f, "            values[i] = (%s)%s((&data->%s)[i]);\n",
675                                                                 rna_type_type(prop), (dp->booleannegative) ? "!" : "", dp->dnaname);
676                                                 }
677                                         }
678                                         else {
679                                                 if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
680                                                         fprintf(f, "            values[i] = %s((data->%s[i] & ", (dp->booleannegative) ? "!" : "",
681                                                                 dp->dnaname);
682                                                         rna_int_print(f, dp->booleanbit);
683                                                         fprintf(f, ") != 0);\n");
684                                                 }
685                                                 else if (rna_color_quantize(prop, dp)) {
686                                                         fprintf(f, "            values[i] = (%s)(data->%s[i]*(1.0f/255.0f));\n",
687                                                                 rna_type_type(prop), dp->dnaname);
688                                                 }
689                                                 else if (dp->dnatype) {
690                                                         fprintf(f, "            values[i] = (%s)%s(((%s*)data->%s)[i]);\n",
691                                                                 rna_type_type(prop), (dp->booleannegative) ? "!" : "", dp->dnatype, dp->dnaname);
692                                                 }
693                                                 else {
694                                                         fprintf(f, "            values[i] = (%s)%s((data->%s)[i]);\n",
695                                                                 rna_type_type(prop), (dp->booleannegative) ? "!" : "", dp->dnaname);
696                                                 }
697                                         }
698                                         fprintf(f, "    }\n");
699                                 }
700                                 fprintf(f, "}\n\n");
701                         }
702                         else {
703                                 fprintf(f, "%s %s(PointerRNA *ptr)\n", rna_type_type(prop), func);
704                                 fprintf(f, "{\n");
705
706                                 if (manualfunc) {
707                                         fprintf(f, "    return %s(ptr);\n", manualfunc);
708                                 }
709                                 else {
710                                         rna_print_data_get(f, dp);
711                                         if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
712                                                 fprintf(f, "    return %s(((data->%s) & ", (dp->booleannegative) ? "!" : "", dp->dnaname);
713                                                 rna_int_print(f, dp->booleanbit);
714                                                 fprintf(f, ") != 0);\n");
715                                         }
716                                         else if (prop->type == PROP_ENUM && dp->enumbitflags) {
717                                                 fprintf(f, "    return ((data->%s) & ", dp->dnaname);
718                                                 rna_int_print(f, rna_enum_bitmask(prop));
719                                                 fprintf(f, ");\n");
720                                         }
721                                         else
722                                                 fprintf(f, "    return (%s)%s(data->%s);\n", rna_type_type(prop),
723                                                         (dp->booleannegative) ? "!" : "", dp->dnaname);
724                                 }
725
726                                 fprintf(f, "}\n\n");
727                         }
728                         break;
729         }
730
731         return func;
732 }
733
734 /* defined min/max variables to be used by rna_clamp_value() */
735 static void rna_clamp_value_range(FILE *f, PropertyRNA *prop)
736 {
737         if (prop->type == PROP_FLOAT) {
738                 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
739                 if (fprop->range) {
740                         fprintf(f,
741                                 "       float prop_clamp_min = -FLT_MAX, prop_clamp_max = FLT_MAX, prop_soft_min, prop_soft_max;\n");
742                         fprintf(f, "    %s(ptr, &prop_clamp_min, &prop_clamp_max, &prop_soft_min, &prop_soft_max);\n",
743                                 rna_function_string(fprop->range));
744                 }
745         }
746         else if (prop->type == PROP_INT) {
747                 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
748                 if (iprop->range) {
749                         fprintf(f, "    int prop_clamp_min = INT_MIN, prop_clamp_max = INT_MAX, prop_soft_min, prop_soft_max;\n");
750                         fprintf(f, "    %s(ptr, &prop_clamp_min, &prop_clamp_max, &prop_soft_min, &prop_soft_max);\n",
751                                 rna_function_string(iprop->range));
752                 }
753         }
754 }
755
756 static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
757 {
758         if (prop->type == PROP_INT) {
759                 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
760
761                 if (iprop->hardmin != INT_MIN || iprop->hardmax != INT_MAX) {
762                         if (array) fprintf(f, "CLAMPIS(values[i], ");
763                         else fprintf(f, "CLAMPIS(value, ");
764                         if (iprop->range) {
765                                 fprintf(f, "prop_clamp_min, prop_clamp_max);");
766                         }
767                         else {
768                                 rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
769                                 rna_int_print(f, iprop->hardmax); fprintf(f, ");\n");
770                         }
771                         return;
772                 }
773         }
774         else if (prop->type == PROP_FLOAT) {
775                 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
776
777                 if (fprop->hardmin != -FLT_MAX || fprop->hardmax != FLT_MAX) {
778                         if (array) fprintf(f, "CLAMPIS(values[i], ");
779                         else fprintf(f, "CLAMPIS(value, ");
780                         if (fprop->range) {
781                                 fprintf(f, "prop_clamp_min, prop_clamp_max);");
782                         }
783                         else {
784                                 rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
785                                 rna_float_print(f, fprop->hardmax); fprintf(f, ");\n");
786                         }
787                         return;
788                 }
789         }
790
791         if (array)
792                 fprintf(f, "values[i];\n");
793         else
794                 fprintf(f, "value;\n");
795 }
796
797 static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp,
798                                        const char *manualfunc)
799 {
800         char *func;
801
802         if (!(prop->flag & PROP_EDITABLE))
803                 return NULL;
804         if (prop->flag & PROP_IDPROPERTY && manualfunc == NULL)
805                 return NULL;
806
807         if (!manualfunc) {
808                 if (!dp->dnastructname || !dp->dnaname) {
809                         if (prop->flag & PROP_EDITABLE) {
810                                 fprintf(stderr, "%s: %s.%s has no valid dna info.\n",
811                                         __func__, srna->identifier, prop->identifier);
812                                 DefRNA.error = 1;
813                         }
814                         return NULL;
815                 }
816         }
817
818         func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "set");
819
820         switch (prop->type) {
821                 case PROP_STRING:
822                 {
823                         StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
824                         fprintf(f, "void %s(PointerRNA *ptr, const char *value)\n", func);
825                         fprintf(f, "{\n");
826                         if (manualfunc) {
827                                 fprintf(f, "    %s(ptr, value);\n", manualfunc);
828                         }
829                         else {
830                                 const PropertySubType subtype = prop->subtype;
831                                 const char *string_copy_func = (subtype == PROP_FILEPATH ||
832                                                                 subtype == PROP_DIRPATH  ||
833                                                                 subtype == PROP_FILENAME ||
834                                                                 subtype == PROP_BYTESTRING) ?
835                                                                "BLI_strncpy" : "BLI_strncpy_utf8";
836
837                                 rna_print_data_get(f, dp);
838
839                                 if (!(prop->flag & PROP_NEVER_NULL)) {
840                                         fprintf(f, "    if (data->%s == NULL) {\n", dp->dnaname);
841                                         fprintf(f, "            return;\n");
842                                         fprintf(f, "    }\n");
843                                 }
844
845                                 if (sprop->maxlength)
846                                         fprintf(f, "    %s(data->%s, value, %d);\n", string_copy_func, dp->dnaname, sprop->maxlength);
847                                 else
848                                         fprintf(f, "    %s(data->%s, value, sizeof(data->%s));\n", string_copy_func,
849                                                 dp->dnaname, dp->dnaname);
850                         }
851                         fprintf(f, "}\n\n");
852                         break;
853                 }
854                 case PROP_POINTER:
855                 {
856                         fprintf(f, "void %s(PointerRNA *ptr, PointerRNA value)\n", func);
857                         fprintf(f, "{\n");
858                         if (manualfunc) {
859                                 fprintf(f, "    %s(ptr, value);\n", manualfunc);
860                         }
861                         else {
862                                 rna_print_data_get(f, dp);
863
864                                 if (prop->flag & PROP_ID_SELF_CHECK) {
865                                         rna_print_id_get(f, dp);
866                                         fprintf(f, "    if (id == value.data) return;\n\n");
867                                 }
868
869                                 if (prop->flag & PROP_ID_REFCOUNT) {
870                                         fprintf(f, "\n  if (data->%s)\n", dp->dnaname);
871                                         fprintf(f, "            id_us_min((ID*)data->%s);\n", dp->dnaname);
872                                         fprintf(f, "    if (value.data)\n");
873                                         fprintf(f, "            id_us_plus((ID*)value.data);\n\n");
874                                 }
875                                 else {
876                                         PointerPropertyRNA *pprop = (PointerPropertyRNA *)dp->prop;
877                                         StructRNA *type = rna_find_struct((const char *)pprop->type);
878                                         if (type && (type->flag & STRUCT_ID)) {
879                                                 fprintf(f, "    if (value.data)\n");
880                                                 fprintf(f, "            id_lib_extern((ID*)value.data);\n\n");
881                                         }
882                                 }
883
884                                 fprintf(f, "    data->%s = value.data;\n", dp->dnaname);
885
886                         }
887                         fprintf(f, "}\n\n");
888                         break;
889                 }
890                 default:
891                         if (prop->arraydimension) {
892                                 if (prop->flag & PROP_DYNAMIC)
893                                         fprintf(f, "void %s(PointerRNA *ptr, const %s values[])\n", func, rna_type_type(prop));
894                                 else
895                                         fprintf(f, "void %s(PointerRNA *ptr, const %s values[%u])\n", func,
896                                                 rna_type_type(prop), prop->totarraylength);
897                                 fprintf(f, "{\n");
898
899                                 if (manualfunc) {
900                                         fprintf(f, "    %s(ptr, values);\n", manualfunc);
901                                 }
902                                 else {
903                                         rna_print_data_get(f, dp);
904
905                                         if (prop->flag & PROP_DYNAMIC) {
906                                                 char *lenfunc = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier),
907                                                                                         "set_length");
908                                                 fprintf(f, "    int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
909                                                 fprintf(f, "    int len= %s(ptr, arraylen);\n\n", lenfunc);
910                                                 rna_clamp_value_range(f, prop);
911                                                 fprintf(f, "    for (i=0; i<len; i++) {\n");
912                                                 MEM_freeN(lenfunc);
913                                         }
914                                         else {
915                                                 fprintf(f, "    int i;\n\n");
916                                                 rna_clamp_value_range(f, prop);
917                                                 fprintf(f, "    for (i=0; i<%u; i++) {\n", prop->totarraylength);
918                                         }
919
920                                         if (dp->dnaarraylength == 1) {
921                                                 if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
922                                                         fprintf(f, "            if (%svalues[i]) data->%s |= (%d<<i);\n",
923                                                                 (dp->booleannegative) ? "!" : "", dp->dnaname, dp->booleanbit);
924                                                         fprintf(f, "            else data->%s &= ~(%d<<i);\n", dp->dnaname, dp->booleanbit);
925                                                 }
926                                                 else {
927                                                         fprintf(f, "            (&data->%s)[i] = %s", dp->dnaname, (dp->booleannegative) ? "!" : "");
928                                                         rna_clamp_value(f, prop, 1);
929                                                 }
930                                         }
931                                         else {
932                                                 if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
933                                                         fprintf(f, "            if (%svalues[i]) data->%s[i] |= ", (dp->booleannegative) ? "!" : "",
934                                                                 dp->dnaname);
935                                                         rna_int_print(f, dp->booleanbit);
936                                                         fprintf(f, ";\n");
937                                                         fprintf(f, "            else data->%s[i] &= ~", dp->dnaname);
938                                                         rna_int_print(f, dp->booleanbit);
939                                                         fprintf(f, ";\n");
940                                                 }
941                                                 else if (rna_color_quantize(prop, dp)) {
942                                                         fprintf(f, "            data->%s[i] = FTOCHAR(values[i]);\n", dp->dnaname);
943                                                 }
944                                                 else {
945                                                         if (dp->dnatype)
946                                                                 fprintf(f, "            ((%s*)data->%s)[i] = %s", dp->dnatype, dp->dnaname,
947                                                                         (dp->booleannegative) ? "!" : "");
948                                                         else
949                                                                 fprintf(f, "            (data->%s)[i] = %s", dp->dnaname, (dp->booleannegative) ? "!" : "");
950                                                         rna_clamp_value(f, prop, 1);
951                                                 }
952                                         }
953                                         fprintf(f, "    }\n");
954                                 }
955                                 fprintf(f, "}\n\n");
956                         }
957                         else {
958                                 fprintf(f, "void %s(PointerRNA *ptr, %s value)\n", func, rna_type_type(prop));
959                                 fprintf(f, "{\n");
960
961                                 if (manualfunc) {
962                                         fprintf(f, "    %s(ptr, value);\n", manualfunc);
963                                 }
964                                 else {
965                                         rna_print_data_get(f, dp);
966                                         if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
967                                                 fprintf(f, "    if (%svalue) data->%s |= ", (dp->booleannegative) ? "!" : "", dp->dnaname);
968                                                 rna_int_print(f, dp->booleanbit);
969                                                 fprintf(f, ";\n");
970                                                 fprintf(f, "    else data->%s &= ~", dp->dnaname);
971                                                 rna_int_print(f, dp->booleanbit);
972                                                 fprintf(f, ";\n");
973                                         }
974                                         else if (prop->type == PROP_ENUM && dp->enumbitflags) {
975                                                 fprintf(f, "    data->%s &= ~", dp->dnaname);
976                                                 rna_int_print(f, rna_enum_bitmask(prop));
977                                                 fprintf(f, ";\n");
978                                                 fprintf(f, "    data->%s |= value;\n", dp->dnaname);
979                                         }
980                                         else {
981                                                 rna_clamp_value_range(f, prop);
982                                                 fprintf(f, "    data->%s = %s", dp->dnaname, (dp->booleannegative) ? "!" : "");
983                                                 rna_clamp_value(f, prop, 0);
984                                         }
985                                 }
986                                 fprintf(f, "}\n\n");
987                         }
988                         break;
989         }
990
991         return func;
992 }
993
994 static char *rna_def_property_length_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp,
995                                           const char *manualfunc)
996 {
997         char *func = NULL;
998
999         if (prop->flag & PROP_IDPROPERTY && manualfunc == NULL)
1000                 return NULL;
1001
1002         if (prop->type == PROP_STRING) {
1003                 if (!manualfunc) {
1004                         if (!dp->dnastructname || !dp->dnaname) {
1005                                 fprintf(stderr, "%s: %s.%s has no valid dna info.\n",
1006                                         __func__, srna->identifier, prop->identifier);
1007                                 DefRNA.error = 1;
1008                                 return NULL;
1009                         }
1010                 }
1011
1012                 func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "length");
1013
1014                 fprintf(f, "int %s(PointerRNA *ptr)\n", func);
1015                 fprintf(f, "{\n");
1016                 if (manualfunc) {
1017                         fprintf(f, "    return %s(ptr);\n", manualfunc);
1018                 }
1019                 else {
1020                         rna_print_data_get(f, dp);
1021                         if (!(prop->flag & PROP_NEVER_NULL)) {
1022                                 fprintf(f, "    if (data->%s == NULL) return 0;\n", dp->dnaname);
1023                         }
1024                         fprintf(f, "    return strlen(data->%s);\n", dp->dnaname);
1025                 }
1026                 fprintf(f, "}\n\n");
1027         }
1028         else if (prop->type == PROP_COLLECTION) {
1029                 if (!manualfunc) {
1030                         if (prop->type == PROP_COLLECTION && (!(dp->dnalengthname || dp->dnalengthfixed) || !dp->dnaname)) {
1031                                 fprintf(stderr, "%s: %s.%s has no valid dna info.\n",
1032                                         __func__, srna->identifier, prop->identifier);
1033                                 DefRNA.error = 1;
1034                                 return NULL;
1035                         }
1036                 }
1037
1038                 func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "length");
1039
1040                 fprintf(f, "int %s(PointerRNA *ptr)\n", func);
1041                 fprintf(f, "{\n");
1042                 if (manualfunc) {
1043                         fprintf(f, "    return %s(ptr);\n", manualfunc);
1044                 }
1045                 else {
1046                         rna_print_data_get(f, dp);
1047                         if (dp->dnalengthname)
1048                                 fprintf(f, "    return (data->%s == NULL)? 0: data->%s;\n", dp->dnaname, dp->dnalengthname);
1049                         else
1050                                 fprintf(f, "    return (data->%s == NULL)? 0: %d;\n", dp->dnaname, dp->dnalengthfixed);
1051                 }
1052                 fprintf(f, "}\n\n");
1053         }
1054
1055         return func;
1056 }
1057
1058 static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp,
1059                                          const char *manualfunc)
1060 {
1061         char *func, *getfunc;
1062
1063         if (prop->flag & PROP_IDPROPERTY && manualfunc == NULL)
1064                 return NULL;
1065
1066         if (!manualfunc) {
1067                 if (!dp->dnastructname || !dp->dnaname) {
1068                         fprintf(stderr, "%s: %s.%s has no valid dna info.\n",
1069                                 __func__, srna->identifier, prop->identifier);
1070                         DefRNA.error = 1;
1071                         return NULL;
1072                 }
1073         }
1074
1075         func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "begin");
1076
1077         fprintf(f, "void %s(CollectionPropertyIterator *iter, PointerRNA *ptr)\n", func);
1078         fprintf(f, "{\n");
1079
1080         if (!manualfunc)
1081                 rna_print_data_get(f, dp);
1082
1083         fprintf(f, "\n  memset(iter, 0, sizeof(*iter));\n");
1084         fprintf(f, "    iter->parent= *ptr;\n");
1085         fprintf(f, "    iter->prop= (PropertyRNA*)&rna_%s_%s;\n", srna->identifier, prop->identifier);
1086
1087         if (dp->dnalengthname || dp->dnalengthfixed) {
1088                 if (manualfunc) {
1089                         fprintf(f, "\n  %s(iter, ptr);\n", manualfunc);
1090                 }
1091                 else {
1092                         if (dp->dnalengthname)
1093                                 fprintf(f, "\n  rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), data->%s, 0, NULL);\n",
1094                                         dp->dnaname, dp->dnaname, dp->dnalengthname);
1095                         else
1096                                 fprintf(f, "\n  rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), %d, 0, NULL);\n",
1097                                         dp->dnaname, dp->dnaname, dp->dnalengthfixed);
1098                 }
1099         }
1100         else {
1101                 if (manualfunc)
1102                         fprintf(f, "\n  %s(iter, ptr);\n", manualfunc);
1103                 else if (dp->dnapointerlevel == 0)
1104                         fprintf(f, "\n  rna_iterator_listbase_begin(iter, &data->%s, NULL);\n", dp->dnaname);
1105                 else
1106                         fprintf(f, "\n  rna_iterator_listbase_begin(iter, data->%s, NULL);\n", dp->dnaname);
1107         }
1108
1109         getfunc = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
1110
1111         fprintf(f, "\n  if (iter->valid)\n");
1112         fprintf(f, "            iter->ptr= %s(iter);\n", getfunc);
1113
1114         fprintf(f, "}\n\n");
1115
1116
1117         return func;
1118 }
1119
1120 static char *rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp,
1121                                               const char *manualfunc, const char *nextfunc)
1122 {
1123         /* note on indices, this is for external functions and ignores skipped values.
1124          * so the the index can only be checked against the length when there is no 'skip' function. */
1125         char *func;
1126
1127         if (prop->flag & PROP_IDPROPERTY && manualfunc == NULL)
1128                 return NULL;
1129
1130         if (!manualfunc) {
1131                 if (!dp->dnastructname || !dp->dnaname)
1132                         return NULL;
1133
1134                 /* only supported in case of standard next functions */
1135                 if (strcmp(nextfunc, "rna_iterator_array_next") == 0) {}
1136                 else if (strcmp(nextfunc, "rna_iterator_listbase_next") == 0) {}
1137                 else return NULL;
1138         }
1139
1140         func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "lookup_int");
1141
1142         fprintf(f, "int %s(PointerRNA *ptr, int index, PointerRNA *r_ptr)\n", func);
1143         fprintf(f, "{\n");
1144
1145         if (manualfunc) {
1146                 fprintf(f, "\n  return %s(ptr, index, r_ptr);\n", manualfunc);
1147                 fprintf(f, "}\n\n");
1148                 return func;
1149         }
1150
1151         fprintf(f, "    int found= 0;\n");
1152         fprintf(f, "    CollectionPropertyIterator iter;\n\n");
1153
1154         fprintf(f, "    %s_%s_begin(&iter, ptr);\n\n", srna->identifier, rna_safe_id(prop->identifier));
1155         fprintf(f, "    if (iter.valid) {\n");
1156
1157         if (strcmp(nextfunc, "rna_iterator_array_next") == 0) {
1158                 fprintf(f, "            ArrayIterator *internal= iter.internal;\n");
1159                 fprintf(f, "            if (index < 0 || index >= internal->length) {\n");
1160                 fprintf(f, "#ifdef __GNUC__\n");
1161                 fprintf(f, "                    printf(\"Array iterator out of range: %%s (index %%d)\\n\", __func__, index);\n");
1162                 fprintf(f, "#else\n");
1163                 fprintf(f, "                    printf(\"Array iterator out of range: (index %%d)\\n\", index);\n");
1164                 fprintf(f, "#endif\n");
1165                 fprintf(f, "            }\n");
1166                 fprintf(f, "            else if (internal->skip) {\n");
1167                 fprintf(f, "                    while (index-- > 0 && iter.valid) {\n");
1168                 fprintf(f, "                            rna_iterator_array_next(&iter);\n");
1169                 fprintf(f, "                    }\n");
1170                 fprintf(f, "                    found= (index == -1 && iter.valid);\n");
1171                 fprintf(f, "            }\n");
1172                 fprintf(f, "            else {\n");
1173                 fprintf(f, "                    internal->ptr += internal->itemsize*index;\n");
1174                 fprintf(f, "                    found= 1;\n");
1175                 fprintf(f, "            }\n");
1176         }
1177         else if (strcmp(nextfunc, "rna_iterator_listbase_next") == 0) {
1178                 fprintf(f, "            ListBaseIterator *internal= iter.internal;\n");
1179                 fprintf(f, "            if (internal->skip) {\n");
1180                 fprintf(f, "                    while (index-- > 0 && iter.valid) {\n");
1181                 fprintf(f, "                            rna_iterator_listbase_next(&iter);\n");
1182                 fprintf(f, "                    }\n");
1183                 fprintf(f, "                    found= (index == -1 && iter.valid);\n");
1184                 fprintf(f, "            }\n");
1185                 fprintf(f, "            else {\n");
1186                 fprintf(f, "                    while (index-- > 0 && internal->link)\n");
1187                 fprintf(f, "                            internal->link= internal->link->next;\n");
1188                 fprintf(f, "                    found= (index == -1 && internal->link);\n");
1189                 fprintf(f, "            }\n");
1190         }
1191
1192         fprintf(f, "            if (found) *r_ptr = %s_%s_get(&iter);\n", srna->identifier, rna_safe_id(prop->identifier));
1193         fprintf(f, "    }\n\n");
1194         fprintf(f, "    %s_%s_end(&iter);\n\n", srna->identifier, rna_safe_id(prop->identifier));
1195
1196         fprintf(f, "    return found;\n");
1197
1198 #if 0
1199         rna_print_data_get(f, dp);
1200         item_type = (cprop->item_type) ? (const char *)cprop->item_type : "UnknownType";
1201
1202         if (dp->dnalengthname || dp->dnalengthfixed) {
1203                 if (dp->dnalengthname)
1204                         fprintf(f, "\n  rna_array_lookup_int(ptr, &RNA_%s, data->%s, sizeof(data->%s[0]), data->%s, index);\n",
1205                                 item_type, dp->dnaname, dp->dnaname, dp->dnalengthname);
1206                 else
1207                         fprintf(f, "\n  rna_array_lookup_int(ptr, &RNA_%s, data->%s, sizeof(data->%s[0]), %d, index);\n",
1208                                 item_type, dp->dnaname, dp->dnaname, dp->dnalengthfixed);
1209         }
1210         else {
1211                 if (dp->dnapointerlevel == 0)
1212                         fprintf(f, "\n  return rna_listbase_lookup_int(ptr, &RNA_%s, &data->%s, index);\n",
1213                                 item_type, dp->dnaname);
1214                 else
1215                         fprintf(f, "\n  return rna_listbase_lookup_int(ptr, &RNA_%s, data->%s, index);\n", item_type, dp->dnaname);
1216         }
1217 #endif
1218
1219         fprintf(f, "}\n\n");
1220
1221         return func;
1222 }
1223
1224 static char *rna_def_property_next_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *UNUSED(dp),
1225                                         const char *manualfunc)
1226 {
1227         char *func, *getfunc;
1228
1229         if (prop->flag & PROP_IDPROPERTY && manualfunc == NULL)
1230                 return NULL;
1231
1232         if (!manualfunc)
1233                 return NULL;
1234
1235         func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "next");
1236
1237         fprintf(f, "void %s(CollectionPropertyIterator *iter)\n", func);
1238         fprintf(f, "{\n");
1239         fprintf(f, "    %s(iter);\n", manualfunc);
1240
1241         getfunc = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
1242
1243         fprintf(f, "\n  if (iter->valid)\n");
1244         fprintf(f, "            iter->ptr= %s(iter);\n", getfunc);
1245
1246         fprintf(f, "}\n\n");
1247
1248         return func;
1249 }
1250
1251 static char *rna_def_property_end_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *UNUSED(dp),
1252                                        const char *manualfunc)
1253 {
1254         char *func;
1255
1256         if (prop->flag & PROP_IDPROPERTY && manualfunc == NULL)
1257                 return NULL;
1258
1259         func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "end");
1260
1261         fprintf(f, "void %s(CollectionPropertyIterator *iter)\n", func);
1262         fprintf(f, "{\n");
1263         if (manualfunc)
1264                 fprintf(f, "    %s(iter);\n", manualfunc);
1265         fprintf(f, "}\n\n");
1266
1267         return func;
1268 }
1269
1270 static void rna_set_raw_property(PropertyDefRNA *dp, PropertyRNA *prop)
1271 {
1272         if (dp->dnapointerlevel != 0)
1273                 return;
1274         if (!dp->dnatype || !dp->dnaname || !dp->dnastructname)
1275                 return;
1276         
1277         if (strcmp(dp->dnatype, "char") == 0) {
1278                 prop->rawtype = PROP_RAW_CHAR;
1279                 prop->flag |= PROP_RAW_ACCESS;
1280         }
1281         else if (strcmp(dp->dnatype, "short") == 0) {
1282                 prop->rawtype = PROP_RAW_SHORT;
1283                 prop->flag |= PROP_RAW_ACCESS;
1284         }
1285         else if (strcmp(dp->dnatype, "int") == 0) {
1286                 prop->rawtype = PROP_RAW_INT;
1287                 prop->flag |= PROP_RAW_ACCESS;
1288         }
1289         else if (strcmp(dp->dnatype, "float") == 0) {
1290                 prop->rawtype = PROP_RAW_FLOAT;
1291                 prop->flag |= PROP_RAW_ACCESS;
1292         }
1293         else if (strcmp(dp->dnatype, "double") == 0) {
1294                 prop->rawtype = PROP_RAW_DOUBLE;
1295                 prop->flag |= PROP_RAW_ACCESS;
1296         }
1297 }
1298
1299 static void rna_set_raw_offset(FILE *f, StructRNA *srna, PropertyRNA *prop)
1300 {
1301         PropertyDefRNA *dp = rna_find_struct_property_def(srna, prop);
1302
1303         fprintf(f, "\toffsetof(%s, %s), %d", dp->dnastructname, dp->dnaname, prop->rawtype);
1304 }
1305
1306 static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1307 {
1308         PropertyRNA *prop;
1309
1310         prop = dp->prop;
1311
1312         switch (prop->type) {
1313                 case PROP_BOOLEAN:
1314                 {
1315                         BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
1316
1317                         if (!prop->arraydimension) {
1318                                 if (!bprop->get && !bprop->set && !dp->booleanbit)
1319                                         rna_set_raw_property(dp, prop);
1320
1321                                 bprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)bprop->get);
1322                                 bprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)bprop->set);
1323                         }
1324                         else {
1325                                 bprop->getarray = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)bprop->getarray);
1326                                 bprop->setarray = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)bprop->setarray);
1327                         }
1328                         break;
1329                 }
1330                 case PROP_INT:
1331                 {
1332                         IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1333
1334                         if (!prop->arraydimension) {
1335                                 if (!iprop->get && !iprop->set)
1336                                         rna_set_raw_property(dp, prop);
1337
1338                                 iprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)iprop->get);
1339                                 iprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)iprop->set);
1340                         }
1341                         else {
1342                                 if (!iprop->getarray && !iprop->setarray)
1343                                         rna_set_raw_property(dp, prop);
1344
1345                                 iprop->getarray = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)iprop->getarray);
1346                                 iprop->setarray = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)iprop->setarray);
1347                         }
1348                         break;
1349                 }
1350                 case PROP_FLOAT:
1351                 {
1352                         FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
1353
1354                         if (!prop->arraydimension) {
1355                                 if (!fprop->get && !fprop->set)
1356                                         rna_set_raw_property(dp, prop);
1357
1358                                 fprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)fprop->get);
1359                                 fprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)fprop->set);
1360                         }
1361                         else {
1362                                 if (!fprop->getarray && !fprop->setarray)
1363                                         rna_set_raw_property(dp, prop);
1364
1365                                 fprop->getarray = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)fprop->getarray);
1366                                 fprop->setarray = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)fprop->setarray);
1367                         }
1368                         break;
1369                 }
1370                 case PROP_ENUM:
1371                 {
1372                         EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
1373
1374                         eprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)eprop->get);
1375                         eprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)eprop->set);
1376                         break;
1377                 }
1378                 case PROP_STRING:
1379                 {
1380                         StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
1381
1382                         sprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)sprop->get);
1383                         sprop->length = (void *)rna_def_property_length_func(f, srna, prop, dp, (const char *)sprop->length);
1384                         sprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)sprop->set);
1385                         break;
1386                 }
1387                 case PROP_POINTER:
1388                 {
1389                         PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
1390
1391                         pprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)pprop->get);
1392                         pprop->set = (void *)rna_def_property_set_func(f, srna, prop, dp, (const char *)pprop->set);
1393                         if (!pprop->type) {
1394                                 fprintf(stderr, "%s: %s.%s, pointer must have a struct type.\n",
1395                                         __func__, srna->identifier, prop->identifier);
1396                                 DefRNA.error = 1;
1397                         }
1398                         break;
1399                 }
1400                 case PROP_COLLECTION:
1401                 {
1402                         CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
1403                         const char *nextfunc = (const char *)cprop->next;
1404
1405                         if (dp->dnatype && strcmp(dp->dnatype, "ListBase") == 0) {
1406                                 /* pass */
1407                         }
1408                         else if (dp->dnalengthname || dp->dnalengthfixed) {
1409                                 cprop->length = (void *)rna_def_property_length_func(f, srna, prop, dp, (const char *)cprop->length);
1410                         }
1411
1412                         /* test if we can allow raw array access, if it is using our standard
1413                          * array get/next function, we can be sure it is an actual array */
1414                         if (cprop->next && cprop->get)
1415                                 if (strcmp((const char *)cprop->next, "rna_iterator_array_next") == 0 &&
1416                                     strcmp((const char *)cprop->get, "rna_iterator_array_get") == 0)
1417                                 {
1418                                         prop->flag |= PROP_RAW_ARRAY;
1419                                 }
1420
1421                         cprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)cprop->get);
1422                         cprop->begin = (void *)rna_def_property_begin_func(f, srna, prop, dp, (const char *)cprop->begin);
1423                         cprop->next = (void *)rna_def_property_next_func(f, srna, prop, dp, (const char *)cprop->next);
1424                         cprop->end = (void *)rna_def_property_end_func(f, srna, prop, dp, (const char *)cprop->end);
1425                         cprop->lookupint = (void *)rna_def_property_lookup_int_func(f, srna, prop, dp,
1426                                                                                     (const char *)cprop->lookupint, nextfunc);
1427
1428                         if (!(prop->flag & PROP_IDPROPERTY)) {
1429                                 if (!cprop->begin) {
1430                                         fprintf(stderr, "%s: %s.%s, collection must have a begin function.\n",
1431                                                 __func__, srna->identifier, prop->identifier);
1432                                         DefRNA.error = 1;
1433                                 }
1434                                 if (!cprop->next) {
1435                                         fprintf(stderr, "%s: %s.%s, collection must have a next function.\n",
1436                                                 __func__, srna->identifier, prop->identifier);
1437                                         DefRNA.error = 1;
1438                                 }
1439                                 if (!cprop->get) {
1440                                         fprintf(stderr, "%s: %s.%s, collection must have a get function.\n",
1441                                                 __func__, srna->identifier, prop->identifier);
1442                                         DefRNA.error = 1;
1443                                 }
1444                         }
1445                         if (!cprop->item_type) {
1446                                 fprintf(stderr, "%s: %s.%s, collection must have a struct type.\n",
1447                                         __func__, srna->identifier, prop->identifier);
1448                                 DefRNA.error = 1;
1449                         }
1450                         break;
1451                 }
1452         }
1453 }
1454
1455 static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1456 {
1457         PropertyRNA *prop;
1458         char *func;
1459
1460         prop = dp->prop;
1461
1462         if (prop->flag & (PROP_IDPROPERTY | PROP_BUILTIN))
1463                 return;
1464
1465         func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "");
1466
1467         switch (prop->type) {
1468                 case PROP_BOOLEAN:
1469                 case PROP_INT:
1470                 {
1471                         if (!prop->arraydimension) {
1472                                 fprintf(f, "int %sget(PointerRNA *ptr);\n", func);
1473                                 fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func);
1474                         }
1475                         else if (prop->arraydimension && prop->totarraylength) {
1476                                 fprintf(f, "void %sget(PointerRNA *ptr, int values[%u]);\n", func, prop->totarraylength);
1477                                 fprintf(f, "void %sset(PointerRNA *ptr, const int values[%d]);\n", func, prop->totarraylength);
1478                         }
1479                         else {
1480                                 fprintf(f, "void %sget(PointerRNA *ptr, int values[]);\n", func);
1481                                 fprintf(f, "void %sset(PointerRNA *ptr, const int values[]);\n", func);
1482                         }
1483                         break;
1484                 }
1485                 case PROP_FLOAT:
1486                 {
1487                         if (!prop->arraydimension) {
1488                                 fprintf(f, "float %sget(PointerRNA *ptr);\n", func);
1489                                 fprintf(f, "void %sset(PointerRNA *ptr, float value);\n", func);
1490                         }
1491                         else if (prop->arraydimension && prop->totarraylength) {
1492                                 fprintf(f, "void %sget(PointerRNA *ptr, float values[%u]);\n", func, prop->totarraylength);
1493                                 fprintf(f, "void %sset(PointerRNA *ptr, const float values[%d]);\n", func, prop->totarraylength);
1494                         }
1495                         else {
1496                                 fprintf(f, "void %sget(PointerRNA *ptr, float values[]);\n", func);
1497                                 fprintf(f, "void %sset(PointerRNA *ptr, const float values[]);", func);
1498                         }
1499                         break;
1500                 }
1501                 case PROP_ENUM:
1502                 {
1503                         EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
1504                         int i;
1505
1506                         if (eprop->item) {
1507                                 fprintf(f, "enum {\n");
1508
1509                                 for (i = 0; i < eprop->totitem; i++)
1510                                         if (eprop->item[i].identifier[0])
1511                                                 fprintf(f, "\t%s_%s_%s = %d,\n", srna->identifier, prop->identifier,
1512                                                         eprop->item[i].identifier, eprop->item[i].value);
1513
1514                                 fprintf(f, "};\n\n");
1515                         }
1516
1517                         fprintf(f, "int %sget(PointerRNA *ptr);\n", func);
1518                         fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func);
1519
1520                         break;
1521                 }
1522                 case PROP_STRING:
1523                 {
1524                         StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
1525
1526                         if (sprop->maxlength) {
1527                                 fprintf(f, "#define %s_%s_MAX %d\n\n", srna->identifier, prop->identifier, sprop->maxlength);
1528                         }
1529                         
1530                         fprintf(f, "void %sget(PointerRNA *ptr, char *value);\n", func);
1531                         fprintf(f, "int %slength(PointerRNA *ptr);\n", func);
1532                         fprintf(f, "void %sset(PointerRNA *ptr, const char *value);\n", func);
1533
1534                         break;
1535                 }
1536                 case PROP_POINTER:
1537                 {
1538                         fprintf(f, "PointerRNA %sget(PointerRNA *ptr);\n", func);
1539                         /*fprintf(f, "void %sset(PointerRNA *ptr, PointerRNA value);\n", func); */
1540                         break;
1541                 }
1542                 case PROP_COLLECTION:
1543                 {
1544                         fprintf(f, "void %sbegin(CollectionPropertyIterator *iter, PointerRNA *ptr);\n", func);
1545                         fprintf(f, "void %snext(CollectionPropertyIterator *iter);\n", func);
1546                         fprintf(f, "void %send(CollectionPropertyIterator *iter);\n", func);
1547                         /*fprintf(f, "int %slength(PointerRNA *ptr);\n", func); */
1548                         /*fprintf(f, "void %slookup_int(PointerRNA *ptr, int key, StructRNA **type);\n", func); */
1549                         /*fprintf(f, "void %slookup_string(PointerRNA *ptr, const char *key, StructRNA **type);\n", func); */
1550                         break;
1551                 }
1552         }
1553
1554         if (prop->getlength) {
1555                 char funcname[2048];
1556                 rna_construct_wrapper_function_name(funcname, sizeof(funcname), srna->identifier, prop->identifier, "get_length");
1557                 fprintf(f, "int %s(PointerRNA *ptr, int *arraylen);\n", funcname);
1558         }
1559
1560         fprintf(f, "\n");
1561 }
1562
1563 static void rna_def_function_funcs_header(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc)
1564 {
1565         FunctionRNA *func = dfunc->func;
1566         char funcname[2048];
1567
1568         rna_construct_wrapper_function_name(funcname, sizeof(funcname), srna->identifier, func->identifier, NULL);
1569         rna_generate_static_parameter_prototypes(f, srna, dfunc, funcname, 1);
1570 }
1571
1572 static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1573 {
1574         PropertyRNA *prop;
1575
1576         prop = dp->prop;
1577
1578         if (prop->flag & (PROP_IDPROPERTY | PROP_BUILTIN))
1579                 return;
1580         
1581         if (prop->name && prop->description && prop->description[0] != '\0')
1582                 fprintf(f, "\t/* %s: %s */\n", prop->name, prop->description);
1583         else if (prop->name)
1584                 fprintf(f, "\t/* %s */\n", prop->name);
1585         else
1586                 fprintf(f, "\t/* */\n");
1587
1588         switch (prop->type) {
1589                 case PROP_BOOLEAN:
1590                 {
1591                         if (!prop->arraydimension) {
1592                                 fprintf(f, "\tinline bool %s(void);\n", rna_safe_id(prop->identifier));
1593                                 fprintf(f, "\tinline void %s(int value);", rna_safe_id(prop->identifier));
1594                         }
1595                         else if (prop->totarraylength) {
1596                                 fprintf(f, "\tinline Array<int, %u> %s(void);\n", prop->totarraylength, rna_safe_id(prop->identifier));
1597                                 fprintf(f, "\tinline void %s(int values[%u]);", rna_safe_id(prop->identifier), prop->totarraylength);
1598                         }
1599                         else if (prop->getlength) {
1600                                 fprintf(f, "\tinline DynamicArray<int> %s(void);\n", rna_safe_id(prop->identifier));
1601                                 fprintf(f, "\tinline void %s(int values[]);", rna_safe_id(prop->identifier));
1602                         }
1603                         break;
1604                 }
1605                 case PROP_INT:
1606                 {
1607                         if (!prop->arraydimension) {
1608                                 fprintf(f, "\tinline int %s(void);\n", rna_safe_id(prop->identifier));
1609                                 fprintf(f, "\tinline void %s(int value);", rna_safe_id(prop->identifier));
1610                         }
1611                         else if (prop->totarraylength) {
1612                                 fprintf(f, "\tinline Array<int, %u> %s(void);\n", prop->totarraylength, rna_safe_id(prop->identifier));
1613                                 fprintf(f, "\tinline void %s(int values[%u]);", rna_safe_id(prop->identifier), prop->totarraylength);
1614                         }
1615                         else if (prop->getlength) {
1616                                 fprintf(f, "\tinline DynamicArray<int> %s(void);\n", rna_safe_id(prop->identifier));
1617                                 fprintf(f, "\tinline void %s(int values[]);", rna_safe_id(prop->identifier));
1618                         }
1619                         break;
1620                 }
1621                 case PROP_FLOAT:
1622                 {
1623                         if (!prop->arraydimension) {
1624                                 fprintf(f, "\tinline float %s(void);\n", rna_safe_id(prop->identifier));
1625                                 fprintf(f, "\tinline void %s(float value);", rna_safe_id(prop->identifier));
1626                         }
1627                         else if (prop->totarraylength) {
1628                                 fprintf(f, "\tinline Array<float, %u> %s(void);\n", prop->totarraylength, rna_safe_id(prop->identifier));
1629                                 fprintf(f, "\tinline void %s(float values[%u]);", rna_safe_id(prop->identifier), prop->totarraylength);
1630                         }
1631                         else if (prop->getlength) {
1632                                 fprintf(f, "\tinline DynamicArray<float> %s(void);\n", rna_safe_id(prop->identifier));
1633                                 fprintf(f, "\tinline void %s(float values[]);", rna_safe_id(prop->identifier));
1634                         }
1635                         break;
1636                 }
1637                 case PROP_ENUM:
1638                 {
1639                         EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
1640                         int i;
1641
1642                         if (eprop->item) {
1643                                 fprintf(f, "\tenum %s_enum {\n", rna_safe_id(prop->identifier));
1644
1645                                 for (i = 0; i < eprop->totitem; i++)
1646                                         if (eprop->item[i].identifier[0])
1647                                                 fprintf(f, "\t\t%s_%s = %d,\n", rna_safe_id(prop->identifier), eprop->item[i].identifier,
1648                                                         eprop->item[i].value);
1649
1650                                 fprintf(f, "\t};\n");
1651                         }
1652
1653                         fprintf(f, "\tinline %s_enum %s(void);\n", rna_safe_id(prop->identifier), rna_safe_id(prop->identifier));
1654                         fprintf(f, "\tinline void %s(%s_enum value);", rna_safe_id(prop->identifier), rna_safe_id(prop->identifier));
1655                         break;
1656                 }
1657                 case PROP_STRING:
1658                 {
1659                         fprintf(f, "\tinline std::string %s(void);", rna_safe_id(prop->identifier));
1660                         break;
1661                 }
1662                 case PROP_POINTER:
1663                 {
1664                         PointerPropertyRNA *pprop = (PointerPropertyRNA *)dp->prop;
1665
1666                         if (pprop->type)
1667                                 fprintf(f, "\tinline %s %s(void);", (const char *)pprop->type, rna_safe_id(prop->identifier));
1668                         else
1669                                 fprintf(f, "\tinline %s %s(void);", "UnknownType", rna_safe_id(prop->identifier));
1670                         break;
1671                 }
1672                 case PROP_COLLECTION:
1673                 {
1674                         CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)dp->prop;
1675
1676                         if (cprop->item_type)
1677                                 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (const char *)cprop->item_type, srna->identifier,
1678                                         rna_safe_id(prop->identifier));
1679                         else
1680                                 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier,
1681                                         rna_safe_id(prop->identifier));
1682                         break;
1683                 }
1684         }
1685
1686         fprintf(f, "\n");
1687 }
1688
1689 static const char *rna_parameter_type_cpp_name(PropertyRNA *prop)
1690 {
1691         if (prop->type == PROP_POINTER) {
1692                 /* for cpp api we need to use RNA structures names for pointers */
1693                 PointerPropertyRNA *pprop = (PointerPropertyRNA *) prop;
1694
1695                 return (const char *) pprop->type;
1696         }
1697         else {
1698                 return rna_parameter_type_name(prop);
1699         }
1700 }
1701
1702 static void rna_def_struct_function_prototype_cpp(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc,
1703                                                   const char *namespace, int close_prototype)
1704 {
1705         PropertyDefRNA *dp;
1706         FunctionRNA *func = dfunc->func;
1707
1708         int first = 1;
1709         const char *retval_type = "void";
1710
1711         if (func->c_ret) {
1712                 dp = rna_find_parameter_def(func->c_ret);
1713                 retval_type = rna_parameter_type_cpp_name(dp->prop);
1714         }
1715
1716         if (namespace && namespace[0])
1717                 fprintf(f, "\tinline %s %s::%s(", retval_type, namespace, rna_safe_id(func->identifier));
1718         else
1719                 fprintf(f, "\tinline %s %s(", retval_type, rna_safe_id(func->identifier));
1720
1721         if (func->flag & FUNC_USE_MAIN)
1722                 WRITE_PARAM("void *main");
1723
1724         if (func->flag & FUNC_USE_CONTEXT)
1725                 WRITE_PARAM("Context C");
1726
1727         if (func->flag & FUNC_USE_REPORTS)
1728                 WRITE_PARAM("void *reports");
1729
1730         for (dp = dfunc->cont.properties.first; dp; dp = dp->next) {
1731                 int type, flag, pout;
1732                 const char *ptrstr;
1733
1734                 if (dp->prop == func->c_ret)
1735                         continue;
1736
1737                 type = dp->prop->type;
1738                 flag = dp->prop->flag;
1739                 pout = (flag & PROP_OUTPUT);
1740
1741                 if (type == PROP_POINTER)
1742                         ptrstr = "";
1743                 else if (type == PROP_POINTER || dp->prop->arraydimension)
1744                         ptrstr = "*";
1745                 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
1746                         ptrstr = "";
1747                 else
1748                         ptrstr = pout ? "*" : "";
1749
1750                 WRITE_COMMA;
1751
1752                 if (flag & PROP_DYNAMIC)
1753                         fprintf(f, "int %s%s_len, ", (flag & PROP_OUTPUT) ? "*" : "", dp->prop->identifier);
1754
1755                 if (!(flag & PROP_DYNAMIC) && dp->prop->arraydimension)
1756                         fprintf(f, "%s %s[%u]", rna_parameter_type_cpp_name(dp->prop),
1757                                 rna_safe_id(dp->prop->identifier), dp->prop->totarraylength);
1758                 else
1759                         fprintf(f, "%s %s%s", rna_parameter_type_cpp_name(dp->prop),
1760                                 ptrstr, rna_safe_id(dp->prop->identifier));
1761         }
1762
1763         fprintf(f, ")");
1764         if (close_prototype)
1765                 fprintf(f, ";\n");
1766 }
1767
1768 static void rna_def_struct_function_header_cpp(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc)
1769 {
1770         FunctionRNA *func = dfunc->func;
1771
1772         if (!dfunc->call)
1773                 return;
1774
1775         fprintf(f, "\n\t/* %s */\n", func->description);
1776
1777         rna_def_struct_function_prototype_cpp(f, srna, dfunc, NULL, 1);
1778 }
1779
1780 static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1781 {
1782         PropertyRNA *prop;
1783
1784         prop = dp->prop;
1785
1786         if (prop->flag & (PROP_IDPROPERTY | PROP_BUILTIN))
1787                 return;
1788
1789         switch (prop->type) {
1790                 case PROP_BOOLEAN:
1791                 {
1792                         if (!prop->arraydimension)
1793                                 fprintf(f, "\tBOOLEAN_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
1794                         else if (prop->totarraylength)
1795                                 fprintf(f, "\tBOOLEAN_ARRAY_PROPERTY(%s, %u, %s)", srna->identifier, prop->totarraylength,
1796                                         rna_safe_id(prop->identifier));
1797                         else if (prop->getlength)
1798                                 fprintf(f, "\tBOOLEAN_DYNAMIC_ARRAY_PROPERTY(%s, %s)", srna->identifier,
1799                                         rna_safe_id(prop->identifier));
1800                         break;
1801                 }
1802                 case PROP_INT:
1803                 {
1804                         if (!prop->arraydimension)
1805                                 fprintf(f, "\tINT_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
1806                         else if (prop->totarraylength)
1807                                 fprintf(f, "\tINT_ARRAY_PROPERTY(%s, %u, %s)", srna->identifier, prop->totarraylength,
1808                                         rna_safe_id(prop->identifier));
1809                         else if (prop->getlength)
1810                                 fprintf(f, "\tINT_DYNAMIC_ARRAY_PROPERTY(%s, %s)", srna->identifier,
1811                                         rna_safe_id(prop->identifier));
1812                         break;
1813                 }
1814                 case PROP_FLOAT:
1815                 {
1816                         if (!prop->arraydimension)
1817                                 fprintf(f, "\tFLOAT_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
1818                         else if (prop->totarraylength)
1819                                 fprintf(f, "\tFLOAT_ARRAY_PROPERTY(%s, %u, %s)", srna->identifier, prop->totarraylength,
1820                                         rna_safe_id(prop->identifier));
1821                         else if (prop->getlength)
1822                                 fprintf(f, "\tFLOAT_DYNAMIC_ARRAY_PROPERTY(%s, %s)", srna->identifier,
1823                                         rna_safe_id(prop->identifier));
1824                         break;
1825                 }
1826                 case PROP_ENUM:
1827                 {
1828                         fprintf(f, "\tENUM_PROPERTY(%s_enum, %s, %s)", rna_safe_id(prop->identifier), srna->identifier,
1829                                 rna_safe_id(prop->identifier));
1830
1831                         break;
1832                 }
1833                 case PROP_STRING:
1834                 {
1835                         fprintf(f, "\tSTRING_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
1836                         break;
1837                 }
1838                 case PROP_POINTER:
1839                 {
1840                         PointerPropertyRNA *pprop = (PointerPropertyRNA *)dp->prop;
1841
1842                         if (pprop->type)
1843                                 fprintf(f, "\tPOINTER_PROPERTY(%s, %s, %s)", (const char *)pprop->type, srna->identifier,
1844                                         rna_safe_id(prop->identifier));
1845                         else
1846                                 fprintf(f, "\tPOINTER_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier,
1847                                         rna_safe_id(prop->identifier));
1848                         break;
1849                 }
1850                 case PROP_COLLECTION:
1851                 {
1852 #if 0
1853                         CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)dp->prop;
1854
1855                         if (cprop->type)
1856                                 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (const char *)cprop->type, srna->identifier,
1857                                         prop->identifier);
1858                         else
1859                                 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, prop->identifier);
1860 #endif
1861                         break;
1862                 }
1863         }
1864
1865         fprintf(f, "\n");
1866 }
1867
1868 static void rna_def_struct_function_call_impl_cpp(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc)
1869 {
1870         PropertyDefRNA *dp;
1871         StructDefRNA *dsrna;
1872         FunctionRNA *func = dfunc->func;
1873         char funcname[2048];
1874
1875         int first = 1;
1876
1877         rna_construct_wrapper_function_name(funcname, sizeof(funcname), srna->identifier, func->identifier, NULL);
1878
1879         fprintf(f, "%s(", funcname);
1880
1881         dsrna = rna_find_struct_def(srna);
1882
1883         if (func->flag & FUNC_USE_SELF_ID)
1884                 WRITE_PARAM("(::ID *) ptr.id.data");
1885
1886         if ((func->flag & FUNC_NO_SELF) == 0) {
1887                 WRITE_COMMA;
1888                 if (dsrna->dnaname) fprintf(f, "(::%s *) this->ptr.data", dsrna->dnaname);
1889                 else fprintf(f, "(::%s *) this->ptr.data", srna->identifier);
1890         }
1891
1892         if (func->flag & FUNC_USE_MAIN)
1893                 WRITE_PARAM("(::Main *) main");
1894
1895         if (func->flag & FUNC_USE_CONTEXT)
1896                 WRITE_PARAM("(::bContext *) C.ptr.data");
1897
1898         if (func->flag & FUNC_USE_REPORTS)
1899                 WRITE_PARAM("(::ReportList *) reports");
1900
1901         dp = dfunc->cont.properties.first;
1902         for (; dp; dp = dp->next) {
1903                 if (dp->prop == func->c_ret)
1904                         continue;
1905
1906                 WRITE_COMMA;
1907
1908                 if (dp->prop->flag & PROP_DYNAMIC)
1909                         fprintf(f, "%s_len, ", dp->prop->identifier);
1910
1911                 if (dp->prop->type == PROP_POINTER)
1912                         fprintf(f, "(::%s *) %s.ptr.data", rna_parameter_type_name(dp->prop), rna_safe_id(dp->prop->identifier));
1913                 else
1914                         fprintf(f, "%s", rna_safe_id(dp->prop->identifier));
1915         }
1916
1917         fprintf(f, ");\n");
1918 }
1919
1920 static void rna_def_struct_function_impl_cpp(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc)
1921 {
1922         PropertyDefRNA *dp;
1923         PointerPropertyRNA *pprop;
1924
1925         FunctionRNA *func = dfunc->func;
1926
1927         if (!dfunc->call)
1928                 return;
1929
1930         rna_def_struct_function_prototype_cpp(f, srna, dfunc, srna->identifier, 0);
1931
1932         fprintf(f, " {\n");
1933
1934         if (func->c_ret) {
1935                 dp = rna_find_parameter_def(func->c_ret);
1936
1937                 if (dp->prop->type == PROP_POINTER) {
1938                         pprop = (PointerPropertyRNA *) dp->prop;
1939
1940                         fprintf(f, "\t\tPointerRNA ptr;\n");
1941
1942                         if ((dp->prop->flag & PROP_RNAPTR) == 0) {
1943                                 StructRNA *ret_srna = rna_find_struct((const char *) pprop->type);
1944                                 fprintf(f, "\t\t::%s *retdata = ", rna_parameter_type_name(dp->prop));
1945                                 rna_def_struct_function_call_impl_cpp(f, srna, dfunc);
1946                                 if (ret_srna->flag & STRUCT_ID)
1947                                         fprintf(f, "\t\tRNA_id_pointer_create((::ID *) retdata, &ptr);\n");
1948                                 else
1949                                         fprintf(f, "\t\tRNA_pointer_create(NULL, &RNA_%s, retdata, &ptr);\n", (const char *) pprop->type);
1950                         }
1951                         else {
1952                                 fprintf(f, "\t\tptr = ");
1953                                 rna_def_struct_function_call_impl_cpp(f, srna, dfunc);
1954                         }
1955
1956                         fprintf(f, "\t\treturn %s(ptr);\n", (const char *) pprop->type);
1957                 }
1958                 else {
1959                         fprintf(f, "\t\treturn ");
1960                         rna_def_struct_function_call_impl_cpp(f, srna, dfunc);
1961                 }
1962         }
1963         else {
1964                 fprintf(f, "\t\t");
1965                 rna_def_struct_function_call_impl_cpp(f, srna, dfunc);
1966         }
1967
1968         fprintf(f, "\t}\n\n");
1969 }
1970
1971 static void rna_def_property_wrapper_funcs(FILE *f, StructDefRNA *dsrna, PropertyDefRNA *dp)
1972 {
1973         if (dp->prop->getlength) {
1974                 char funcname[2048];
1975                 rna_construct_wrapper_function_name(funcname, sizeof(funcname), dsrna->srna->identifier, dp->prop->identifier, "get_length");
1976                 fprintf(f, "int %s(PointerRNA *ptr, int *arraylen)\n", funcname);
1977                 fprintf(f, "{\n");
1978                 fprintf(f, "\treturn %s(ptr, arraylen);\n", rna_function_string(dp->prop->getlength));
1979                 fprintf(f, "}\n\n");
1980         }
1981 }
1982
1983 static void rna_def_function_wrapper_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA *dfunc)
1984 {
1985         StructRNA *srna = dsrna->srna;
1986         FunctionRNA *func = dfunc->func;
1987         PropertyDefRNA *dparm;
1988
1989         int first;
1990         char funcname[2048];
1991
1992         if (!dfunc->call)
1993                 return;
1994
1995         rna_construct_wrapper_function_name(funcname, sizeof(funcname), srna->identifier, func->identifier, NULL);
1996
1997         rna_generate_static_parameter_prototypes(f, srna, dfunc, funcname, 0);
1998
1999         fprintf(f, "\n{\n");
2000
2001         if (func->c_ret)
2002                 fprintf(f, "\treturn %s(", dfunc->call);
2003         else
2004                 fprintf(f, "\t%s(", dfunc->call);
2005
2006         first = 1;
2007
2008         if (func->flag & FUNC_USE_SELF_ID)
2009                 WRITE_PARAM("_selfid");
2010
2011         if ((func->flag & FUNC_NO_SELF) == 0)
2012                 WRITE_PARAM("_self");
2013
2014         if (func->flag & FUNC_USE_MAIN)
2015                 WRITE_PARAM("bmain");
2016
2017         if (func->flag & FUNC_USE_CONTEXT)
2018                 WRITE_PARAM("C");
2019
2020         if (func->flag & FUNC_USE_REPORTS)
2021                 WRITE_PARAM("reports");
2022
2023         dparm = dfunc->cont.properties.first;
2024         for (; dparm; dparm = dparm->next) {
2025                 if (dparm->prop == func->c_ret)
2026                         continue;
2027
2028                 WRITE_COMMA;
2029
2030                 if (dparm->prop->flag & PROP_DYNAMIC)
2031                         fprintf(f, "%s_len, %s", dparm->prop->identifier, dparm->prop->identifier);
2032                 else
2033                         fprintf(f, "%s", rna_safe_id(dparm->prop->identifier));
2034         }
2035
2036         fprintf(f, ");\n");
2037         fprintf(f, "}\n\n");
2038 }
2039
2040 static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA *dfunc)
2041 {
2042         StructRNA *srna;
2043         FunctionRNA *func;
2044         PropertyDefRNA *dparm;
2045         PropertyType type;
2046         const char *funcname, *valstr;
2047         const char *ptrstr;
2048         const short has_data = (dfunc->cont.properties.first != NULL);
2049         int flag, pout, cptr, first;
2050
2051         srna = dsrna->srna;
2052         func = dfunc->func;
2053
2054         if (!dfunc->call)
2055                 return;
2056
2057         funcname = rna_alloc_function_name(srna->identifier, func->identifier, "call");
2058
2059         /* function definition */
2060         fprintf(f, "void %s(bContext *C, ReportList *reports, PointerRNA *_ptr, ParameterList *_parms)", funcname);
2061         fprintf(f, "\n{\n");
2062
2063         /* variable definitions */
2064         
2065         if (func->flag & FUNC_USE_SELF_ID) {
2066                 fprintf(f, "\tstruct ID *_selfid;\n");
2067         }
2068
2069         if ((func->flag & FUNC_NO_SELF) == 0) {
2070                 if (dsrna->dnaname) fprintf(f, "\tstruct %s *_self;\n", dsrna->dnaname);
2071                 else fprintf(f, "\tstruct %s *_self;\n", srna->identifier);
2072         }
2073
2074         dparm = dfunc->cont.properties.first;
2075         for (; dparm; dparm = dparm->next) {
2076                 type = dparm->prop->type;
2077                 flag = dparm->prop->flag;
2078                 pout = (flag & PROP_OUTPUT);
2079                 cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
2080
2081                 if (dparm->prop == func->c_ret)
2082                         ptrstr = cptr || dparm->prop->arraydimension ? "*" : "";
2083                 /* XXX only arrays and strings are allowed to be dynamic, is this checked anywhere? */
2084                 else if (cptr || (flag & PROP_DYNAMIC))
2085                         ptrstr = pout ? "**" : "*";
2086                 /* fixed size arrays and RNA pointers are pre-allocated on the ParameterList stack, pass a pointer to it */
2087                 else if (type == PROP_POINTER || dparm->prop->arraydimension)
2088                         ptrstr = "*";
2089                 /* PROP_THICK_WRAP strings are pre-allocated on the ParameterList stack,
2090                  * but type name for string props is already char*, so leave empty */
2091                 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
2092                         ptrstr = "";
2093                 else
2094                         ptrstr = pout ? "*" : "";
2095
2096                 /* for dynamic parameters we pass an additional int for the length of the parameter */
2097                 if (flag & PROP_DYNAMIC)
2098                         fprintf(f, "\tint %s%s_len;\n", pout ? "*" : "", dparm->prop->identifier);
2099                 
2100                 fprintf(f, "\t%s%s %s%s;\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop),
2101                         ptrstr, dparm->prop->identifier);
2102         }
2103
2104         if (has_data) {
2105                 fprintf(f, "\tchar *_data");
2106                 if (func->c_ret) fprintf(f, ", *_retdata");
2107                 fprintf(f, ";\n");
2108                 fprintf(f, "\t\n");
2109         }
2110
2111         /* assign self */
2112         if (func->flag & FUNC_USE_SELF_ID) {
2113                 fprintf(f, "\t_selfid= (struct ID*)_ptr->id.data;\n");
2114         }
2115         
2116         if ((func->flag & FUNC_NO_SELF) == 0) {
2117                 if (dsrna->dnaname) fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", dsrna->dnaname);
2118                 else fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", srna->identifier);
2119         }
2120
2121         if (has_data) {
2122                 fprintf(f, "\t_data= (char *)_parms->data;\n");
2123         }
2124
2125         dparm = dfunc->cont.properties.first;
2126         for (; dparm; dparm = dparm->next) {
2127                 type = dparm->prop->type;
2128                 flag = dparm->prop->flag;
2129                 pout = (flag & PROP_OUTPUT);
2130                 cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
2131
2132                 if (dparm->prop == func->c_ret)
2133                         fprintf(f, "\t_retdata= _data;\n");
2134                 else {
2135                         const char *data_str;
2136                         if (cptr || (flag & PROP_DYNAMIC)) {
2137                                 ptrstr = "**";
2138                                 valstr = "*";
2139                         }
2140                         else if (type == PROP_POINTER || dparm->prop->arraydimension) {
2141                                 ptrstr = "*";
2142                                 valstr = "";
2143                         }
2144                         else if (type == PROP_STRING && (flag & PROP_THICK_WRAP)) {
2145                                 ptrstr = "";
2146                                 valstr = "";
2147                         }
2148                         else {
2149                                 ptrstr = "*";
2150                                 valstr = "*";
2151                         }
2152
2153                         /* this must be kept in sync with RNA_parameter_length_get_data,
2154                          * we could just call the function directly, but this is faster */
2155                         if (flag & PROP_DYNAMIC) {
2156                                 fprintf(f, "\t%s_len= %s((int *)_data);\n", dparm->prop->identifier, pout ? "" : "*");
2157                                 data_str = "(&(((char *)_data)[sizeof(void *)]))";
2158                         }
2159                         else {
2160                                 data_str = "_data";
2161                         }
2162                         fprintf(f, "\t%s = ", dparm->prop->identifier);
2163
2164                         if (!pout)
2165                                 fprintf(f, "%s", valstr);
2166
2167                         fprintf(f, "((%s%s%s)%s);\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop),
2168                                 ptrstr, data_str);
2169                 }
2170
2171                 if (dparm->next)
2172                         fprintf(f, "\t_data += %d;\n", rna_parameter_size_alloc(dparm->prop));
2173         }
2174
2175         if (dfunc->call) {
2176                 fprintf(f, "\t\n");
2177                 fprintf(f, "\t");
2178                 if (func->c_ret) fprintf(f, "%s = ", func->c_ret->identifier);
2179                 fprintf(f, "%s(", dfunc->call);
2180
2181                 first = 1;
2182
2183                 if (func->flag & FUNC_USE_SELF_ID) {
2184                         fprintf(f, "_selfid");
2185                         first = 0;
2186                 }
2187
2188                 if ((func->flag & FUNC_NO_SELF) == 0) {
2189                         if (!first) fprintf(f, ", ");
2190                         fprintf(f, "_self");
2191                         first = 0;
2192                 }
2193
2194                 if (func->flag & FUNC_USE_MAIN) {
2195                         if (!first) fprintf(f, ", ");
2196                         first = 0;
2197                         fprintf(f, "CTX_data_main(C)"); /* may have direct access later */
2198                 }
2199
2200                 if (func->flag & FUNC_USE_CONTEXT) {
2201                         if (!first) fprintf(f, ", ");
2202                         first = 0;
2203                         fprintf(f, "C");
2204                 }
2205
2206                 if (func->flag & FUNC_USE_REPORTS) {
2207                         if (!first) fprintf(f, ", ");
2208                         first = 0;
2209                         fprintf(f, "reports");
2210                 }
2211
2212                 dparm = dfunc->cont.properties.first;
2213                 for (; dparm; dparm = dparm->next) {
2214                         if (dparm->prop == func->c_ret)
2215                                 continue;
2216
2217                         if (!first) fprintf(f, ", ");
2218                         first = 0;
2219
2220                         if (dparm->prop->flag & PROP_DYNAMIC)
2221                                 fprintf(f, "%s_len, %s", dparm->prop->identifier, dparm->prop->identifier);
2222                         else
2223                                 fprintf(f, "%s", dparm->prop->identifier);
2224                 }
2225
2226                 fprintf(f, ");\n");
2227
2228                 if (func->c_ret) {
2229                         dparm = rna_find_parameter_def(func->c_ret);
2230                         ptrstr = (((dparm->prop->type == PROP_POINTER) && !(dparm->prop->flag & PROP_RNAPTR)) ||
2231                                   (dparm->prop->arraydimension)) ? "*" : "";
2232                         fprintf(f, "\t*((%s%s%s*)_retdata) = %s;\n", rna_type_struct(dparm->prop),
2233                                 rna_parameter_type_name(dparm->prop), ptrstr, func->c_ret->identifier);
2234                 }
2235         }
2236
2237         fprintf(f, "}\n\n");
2238
2239         dfunc->gencall = funcname;
2240 }
2241
2242 static void rna_auto_types(void)
2243 {
2244         StructDefRNA *ds;
2245         PropertyDefRNA *dp;
2246
2247         for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
2248                 /* DNA name for Screen is patched in 2.5, we do the reverse here .. */
2249                 if (ds->dnaname && strcmp(ds->dnaname, "Screen") == 0)
2250                         ds->dnaname = "bScreen";
2251
2252                 for (dp = ds->cont.properties.first; dp; dp = dp->next) {
2253                         if (dp->dnastructname && strcmp(dp->dnastructname, "Screen") == 0)
2254                                 dp->dnastructname = "bScreen";
2255
2256                         if (dp->dnatype) {
2257                                 if (dp->prop->type == PROP_POINTER) {
2258                                         PointerPropertyRNA *pprop = (PointerPropertyRNA *)dp->prop;
2259                                         StructRNA *type;
2260
2261                                         if (!pprop->type && !pprop->get)
2262                                                 pprop->type = (StructRNA *)rna_find_type(dp->dnatype);
2263
2264                                         if (pprop->type) {
2265                                                 type = rna_find_struct((const char *)pprop->type);
2266                                                 if (type && (type->flag & STRUCT_ID_REFCOUNT))
2267                                                         pprop->property.flag |= PROP_ID_REFCOUNT;
2268                                         }
2269                                 }
2270                                 else if (dp->prop->type == PROP_COLLECTION) {
2271                                         CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)dp->prop;
2272
2273                                         if (!cprop->item_type && !cprop->get && strcmp(dp->dnatype, "ListBase") == 0)
2274                                                 cprop->item_type = (StructRNA *)rna_find_type(dp->dnatype);
2275                                 }
2276                         }
2277                 }
2278         }
2279 }
2280
2281 static void rna_sort(BlenderRNA *brna)
2282 {
2283         StructDefRNA *ds;
2284         StructRNA *srna;
2285
2286         rna_sortlist(&brna->structs, cmp_struct);
2287         rna_sortlist(&DefRNA.structs, cmp_def_struct);
2288
2289         for (srna = brna->structs.first; srna; srna = srna->cont.next)
2290                 rna_sortlist(&srna->cont.properties, cmp_property);
2291
2292         for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
2293                 rna_sortlist(&ds->cont.properties, cmp_def_property);
2294 }
2295
2296 static const char *rna_property_structname(PropertyType type)
2297 {
2298         switch (type) {
2299                 case PROP_BOOLEAN: return "BoolPropertyRNA";
2300                 case PROP_INT: return "IntPropertyRNA";
2301                 case PROP_FLOAT: return "FloatPropertyRNA";
2302                 case PROP_STRING: return "StringPropertyRNA";
2303                 case PROP_ENUM: return "EnumPropertyRNA";
2304                 case PROP_POINTER: return "PointerPropertyRNA";
2305                 case PROP_COLLECTION: return "CollectionPropertyRNA";
2306                 default: return "UnknownPropertyRNA";
2307         }
2308 }
2309
2310 static const char *rna_property_subtypename(PropertySubType type)
2311 {
2312         switch (type) {
2313                 case PROP_NONE: return "PROP_NONE";
2314                 case PROP_FILEPATH: return "PROP_FILEPATH";
2315                 case PROP_FILENAME: return "PROP_FILENAME";
2316                 case PROP_DIRPATH: return "PROP_DIRPATH";
2317                 case PROP_BYTESTRING: return "PROP_BYTESTRING";
2318                 case PROP_TRANSLATE: return "PROP_TRANSLATE";
2319                 case PROP_UNSIGNED: return "PROP_UNSIGNED";
2320                 case PROP_PERCENTAGE: return "PROP_PERCENTAGE";
2321                 case PROP_FACTOR: return "PROP_FACTOR";
2322                 case PROP_ANGLE: return "PROP_ANGLE";
2323                 case PROP_TIME: return "PROP_TIME";
2324                 case PROP_DISTANCE: return "PROP_DISTANCE";
2325                 case PROP_COLOR: return "PROP_COLOR";
2326                 case PROP_TRANSLATION: return "PROP_TRANSLATION";
2327                 case PROP_DIRECTION: return "PROP_DIRECTION";
2328                 case PROP_MATRIX: return "PROP_MATRIX";
2329                 case PROP_EULER: return "PROP_EULER";
2330                 case PROP_QUATERNION: return "PROP_QUATERNION";
2331                 case PROP_AXISANGLE: return "PROP_AXISANGLE";
2332                 case PROP_VELOCITY: return "PROP_VELOCITY";
2333                 case PROP_ACCELERATION: return "PROP_ACCELERATION";
2334                 case PROP_XYZ: return "PROP_XYZ";
2335                 case PROP_COLOR_GAMMA: return "PROP_COLOR_GAMMA";
2336                 case PROP_COORDS: return "PROP_COORDS";
2337                 case PROP_LAYER: return "PROP_LAYER";
2338                 case PROP_LAYER_MEMBER: return "PROP_LAYER_MEMBER";
2339                 default: {
2340                         /* in case we don't have a type preset that includes the subtype */
2341                         if (RNA_SUBTYPE_UNIT(type)) {
2342                                 return rna_property_subtypename(type & ~RNA_SUBTYPE_UNIT(type));
2343                         }
2344                         else {
2345                                 return "PROP_SUBTYPE_UNKNOWN";
2346                         }
2347                 }
2348         }
2349 }
2350
2351 static const char *rna_property_subtype_unit(PropertySubType type)
2352 {
2353         switch (RNA_SUBTYPE_UNIT(type)) {
2354                 case PROP_UNIT_NONE:         return "PROP_UNIT_NONE";
2355                 case PROP_UNIT_LENGTH:       return "PROP_UNIT_LENGTH";
2356                 case PROP_UNIT_AREA:         return "PROP_UNIT_AREA";
2357                 case PROP_UNIT_VOLUME:       return "PROP_UNIT_VOLUME";
2358                 case PROP_UNIT_MASS:         return "PROP_UNIT_MASS";
2359                 case PROP_UNIT_ROTATION:     return "PROP_UNIT_ROTATION";
2360                 case PROP_UNIT_TIME:         return "PROP_UNIT_TIME";
2361                 case PROP_UNIT_VELOCITY:     return "PROP_UNIT_VELOCITY";
2362                 case PROP_UNIT_ACCELERATION: return "PROP_UNIT_ACCELERATION";
2363                 default:                     return "PROP_UNIT_UNKNOWN";
2364         }
2365 }
2366
2367 static void rna_generate_prototypes(BlenderRNA *brna, FILE *f)
2368 {
2369         StructRNA *srna;
2370
2371         for (srna = brna->structs.first; srna; srna = srna->cont.next)
2372                 fprintf(f, "extern StructRNA RNA_%s;\n", srna->identifier);
2373         fprintf(f, "\n");
2374 }
2375
2376 static void rna_generate_blender(BlenderRNA *brna, FILE *f)
2377 {
2378         StructRNA *srna;
2379
2380         fprintf(f, "BlenderRNA BLENDER_RNA = {");
2381
2382         srna = brna->structs.first;
2383         if (srna) fprintf(f, "{&RNA_%s, ", srna->identifier);
2384         else fprintf(f, "{NULL, ");
2385
2386         srna = brna->structs.last;
2387         if (srna) fprintf(f, "&RNA_%s}", srna->identifier);
2388         else fprintf(f, "NULL}");
2389
2390         fprintf(f, "};\n\n");
2391 }
2392
2393 static void rna_generate_property_prototypes(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE *f)
2394 {
2395         PropertyRNA *prop;
2396         StructRNA *base;
2397
2398         base = srna->base;
2399         while (base) {
2400                 fprintf(f, "\n");
2401                 for (prop = base->cont.properties.first; prop; prop = prop->next)
2402                         fprintf(f, "%s%s rna_%s_%s;\n", "extern ", rna_property_structname(prop->type),
2403                                 base->identifier, prop->identifier);
2404                 base = base->base;
2405         }
2406
2407         if (srna->cont.properties.first)
2408                 fprintf(f, "\n");
2409
2410         for (prop = srna->cont.properties.first; prop; prop = prop->next)
2411                 fprintf(f, "%s%s rna_%s_%s;\n", (prop->flag & PROP_EXPORT) ? "" : "", rna_property_structname(prop->type),
2412                         srna->identifier, prop->identifier);
2413         fprintf(f, "\n");
2414 }
2415
2416 static void rna_generate_parameter_prototypes(BlenderRNA *UNUSED(brna), StructRNA *srna, FunctionRNA *func, FILE *f)
2417 {
2418         PropertyRNA *parm;
2419
2420         for (parm = func->cont.properties.first; parm; parm = parm->next)
2421                 fprintf(f, "%s%s rna_%s_%s_%s;\n", "extern ", rna_property_structname(parm->type), srna->identifier,
2422                         func->identifier, parm->identifier);
2423
2424         if (func->cont.properties.first)
2425                 fprintf(f, "\n");
2426 }
2427
2428 static void rna_generate_function_prototypes(BlenderRNA *brna, StructRNA *srna, FILE *f)
2429 {
2430         FunctionRNA *func;
2431         StructRNA *base;
2432
2433         base = srna->base;
2434         while (base) {
2435                 for (func = base->functions.first; func; func = func->cont.next) {
2436                         fprintf(f, "%s%s rna_%s_%s_func;\n", "extern ", "FunctionRNA", base->identifier, func->identifier);
2437                         rna_generate_parameter_prototypes(brna, base, func, f);
2438                 }
2439
2440                 if (base->functions.first)
2441                         fprintf(f, "\n");
2442
2443                 base = base->base;
2444         }
2445
2446         for (func = srna->functions.first; func; func = func->cont.next) {
2447                 fprintf(f, "%s%s rna_%s_%s_func;\n", "extern ", "FunctionRNA", srna->identifier, func->identifier);
2448                 rna_generate_parameter_prototypes(brna, srna, func, f);
2449         }
2450
2451         if (srna->functions.first)
2452                 fprintf(f, "\n");
2453 }
2454
2455 static void rna_generate_static_parameter_prototypes(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc, const char *name_override, int close_prototype)
2456 {
2457         FunctionRNA *func;
2458         PropertyDefRNA *dparm;
2459         StructDefRNA *dsrna;
2460         PropertyType type;
2461         int flag, pout, cptr, first;
2462         const char *ptrstr;
2463
2464         dsrna = rna_find_struct_def(srna);
2465         func = dfunc->func;
2466
2467         /* return type */
2468         for (dparm = dfunc->cont.properties.first; dparm; dparm = dparm->next) {
2469                 if (dparm->prop == func->c_ret) {
2470                         if (dparm->prop->arraydimension)
2471                                 fprintf(f, "XXX no array return types yet");  /* XXX not supported */
2472                         else if (dparm->prop->type == PROP_POINTER && !(dparm->prop->flag & PROP_RNAPTR))
2473                                 fprintf(f, "%s%s *", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
2474                         else
2475                                 fprintf(f, "%s%s ", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
2476
2477                         break;
2478                 }
2479         }
2480
2481         /* void if nothing to return */
2482         if (!dparm)
2483                 fprintf(f, "void ");
2484
2485         /* function name */
2486         if (name_override == NULL || name_override[0] == '\0')
2487                 fprintf(f, "%s(", dfunc->call);
2488         else
2489                 fprintf(f, "%s(", name_override);
2490
2491         first = 1;
2492
2493         /* self, context and reports parameters */
2494         if (func->flag & FUNC_USE_SELF_ID) {
2495                 fprintf(f, "struct ID *_selfid");
2496                 first = 0;
2497         }
2498
2499         if ((func->flag & FUNC_NO_SELF) == 0) {
2500                 if (!first) fprintf(f, ", ");
2501                 if (dsrna->dnaname) fprintf(f, "struct %s *_self", dsrna->dnaname);
2502                 else fprintf(f, "struct %s *_self", srna->identifier);
2503                 first = 0;
2504         }
2505
2506         if (func->flag & FUNC_USE_MAIN) {
2507                 if (!first) fprintf(f, ", ");
2508                 first = 0;
2509                 fprintf(f, "Main *bmain");
2510         }
2511
2512         if (func->flag & FUNC_USE_CONTEXT) {
2513                 if (!first) fprintf(f, ", ");
2514                 first = 0;
2515                 fprintf(f, "bContext *C");
2516         }
2517
2518         if (func->flag & FUNC_USE_REPORTS) {
2519                 if (!first) fprintf(f, ", ");
2520                 first = 0;
2521                 fprintf(f, "ReportList *reports");
2522         }
2523
2524         /* defined parameters */
2525         for (dparm = dfunc->cont.properties.first; dparm; dparm = dparm->next) {
2526                 type = dparm->prop->type;
2527                 flag = dparm->prop->flag;
2528                 pout = (flag & PROP_OUTPUT);
2529                 cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
2530
2531                 if (dparm->prop == func->c_ret)
2532                         continue;
2533
2534                 if (cptr || (flag & PROP_DYNAMIC))
2535                         ptrstr = pout ? "**" : "*";
2536                 else if (type == PROP_POINTER || dparm->prop->arraydimension)
2537                         ptrstr = "*";
2538                 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
2539                         ptrstr = "";
2540                 else
2541                         ptrstr = pout ? "*" : "";
2542
2543                 if (!first) fprintf(f, ", ");
2544                 first = 0;
2545
2546                 if (flag & PROP_DYNAMIC)
2547                         fprintf(f, "int %s%s_len, ", pout ? "*" : "", dparm->prop->identifier);
2548
2549                 if (!(flag & PROP_DYNAMIC) && dparm->prop->arraydimension)
2550                         fprintf(f, "%s%s %s[%u]", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop),
2551                                 rna_safe_id(dparm->prop->identifier), dparm->prop->totarraylength);
2552                 else
2553                         fprintf(f, "%s%s %s%s", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop),
2554                                 ptrstr, rna_safe_id(dparm->prop->identifier));
2555
2556         }
2557
2558         fprintf(f, ")");
2559         if (close_prototype)
2560                 fprintf(f, ";\n");
2561 }
2562
2563 static void rna_generate_static_function_prototypes(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE *f)
2564 {
2565         FunctionRNA *func;
2566         FunctionDefRNA *dfunc;
2567         int first = 1;
2568
2569         for (func = srna->functions.first; func; func = func->cont.next) {
2570                 dfunc = rna_find_function_def(func);
2571
2572                 if (dfunc->call) {
2573                         if (first) {
2574                                 fprintf(f, "/* Repeated prototypes to detect errors */\n\n");
2575                                 first = 0;
2576                         }
2577
2578                         rna_generate_static_parameter_prototypes(f, srna, dfunc, NULL, 1);
2579                 }
2580         }
2581
2582         fprintf(f, "\n");
2583 }
2584
2585 static void rna_generate_struct_prototypes(FILE *f)
2586 {
2587         StructDefRNA *ds;
2588         PropertyDefRNA *dp;
2589         FunctionDefRNA *dfunc;
2590         const char *structures[2048];
2591         int all_structures = 0;
2592
2593         /* structures definitions */
2594         for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
2595                 for (dfunc = ds->functions.first; dfunc; dfunc = dfunc->cont.next) {
2596                         if (dfunc->call) {
2597                                 for (dp = dfunc->cont.properties.first; dp; dp = dp->next) {
2598                                         if (dp->prop->type == PROP_POINTER) {
2599                                                 int a, found = 0;
2600                                                 const char *struct_name = rna_parameter_type_name(dp->prop);
2601
2602                                                 for (a = 0; a < all_structures; a++) {
2603                                                         if (strcmp(struct_name, structures[a]) == 0) {
2604                                                                 found = 1;
2605                                                                 break;
2606                                                         }
2607                                                 }
2608
2609                                                 if (found == 0) {
2610                                                         fprintf(f, "struct %s;\n", struct_name);
2611
2612                                                         if (all_structures >= sizeof(structures) / sizeof(structures[0])) {
2613                                                                 printf("Array size to store all structures names is too small\n");
2614                                                                 exit(1);
2615                                                         }
2616
2617                                                         structures[all_structures++] = struct_name;
2618                                                 }
2619                                         }
2620                                 }
2621                         }
2622                 }
2623         }
2624
2625         fprintf(f, "\n");
2626 }
2627
2628 static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, PropertyRNA *prop)
2629 {
2630         char *strnest = "", *errnest = "";
2631         int len, freenest = 0;
2632         
2633         if (nest != NULL) {
2634                 len = strlen(nest);
2635
2636                 strnest = MEM_mallocN(sizeof(char) * (len + 2), "rna_generate_property -> strnest");
2637                 errnest = MEM_mallocN(sizeof(char) * (len + 2), "rna_generate_property -> errnest");
2638
2639                 strcpy(strnest, "_"); strcat(strnest, nest);
2640                 strcpy(errnest, "."); strcat(errnest, nest);
2641
2642                 freenest = 1;
2643         }
2644
2645         switch (prop->type) {
2646                 case PROP_ENUM:
2647                 {
2648                         EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
2649                         int i, defaultfound = 0, totflag = 0;
2650
2651                         if (eprop->item) {
2652                                 fprintf(f, "static EnumPropertyItem rna_%s%s_%s_items[%d] = {\n\t", srna->identifier,
2653                                         strnest, prop->identifier, eprop->totitem + 1);
2654
2655                                 for (i = 0; i < eprop->totitem; i++) {
2656                                         fprintf(f, "{%d, ", eprop->item[i].value);
2657                                         rna_print_c_string(f, eprop->item[i].identifier); fprintf(f, ", ");
2658                                         fprintf(f, "%d, ", eprop->item[i].icon);
2659                                         rna_print_c_string(f, eprop->item[i].name); fprintf(f, ", ");
2660                                         rna_print_c_string(f, eprop->item[i].description); fprintf(f, "},\n\t");
2661
2662                                         if (eprop->item[i].identifier[0]) {
2663                                                 if (prop->flag & PROP_ENUM_FLAG) {
2664                                                         totflag |= eprop->item[i].value;
2665                                                 }
2666                                                 else {
2667                                                         if (eprop->defaultvalue == eprop->item[i].value) {
2668                                                                 defaultfound = 1;
2669                                                         }
2670                                                 }
2671                                         }
2672                                 }
2673
2674                                 fprintf(f, "{0, NULL, 0, NULL, NULL}\n};\n\n");
2675
2676                                 if (prop->flag & PROP_ENUM_FLAG) {
2677                                         if (eprop->defaultvalue & ~totflag) {
2678                                                 fprintf(stderr, "%s: %s%s.%s, enum default includes unused bits (%d).\n",
2679                                                         __func__, srna->identifier, errnest, prop->identifier,
2680                                                         eprop->defaultvalue & ~totflag);
2681                                                 DefRNA.error = 1;
2682                                         }
2683                                 }
2684                                 else {
2685                                         if (!defaultfound) {
2686                                                 fprintf(stderr, "%s: %s%s.%s, enum default is not in items.\n",
2687                                                         __func__, srna->identifier, errnest, prop->identifier);
2688                                                 DefRNA.error = 1;
2689                                         }
2690                                 }
2691                         }
2692                         else {
2693                                 fprintf(stderr, "%s: %s%s.%s, enum must have items defined.\n",
2694                                         __func__, srna->identifier, errnest, prop->identifier);
2695                                 DefRNA.error = 1;
2696                         }
2697                         break;
2698                 }
2699                 case PROP_BOOLEAN:
2700                 {
2701                         BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
2702                         unsigned int i;
2703
2704                         if (prop->arraydimension && prop->totarraylength) {
2705                                 fprintf(f, "static int rna_%s%s_%s_default[%u] = {\n\t", srna->identifier, strnest,
2706                                         prop->identifier, prop->totarraylength);
2707
2708                                 for (i = 0; i < prop->totarraylength; i++) {
2709                                         if (bprop->defaultarray)
2710                                                 fprintf(f, "%d", bprop->defaultarray[i]);
2711                                         else
2712                                                 fprintf(f, "%d", bprop->defaultvalue);
2713                                         if (i != prop->totarraylength - 1)
2714                                                 fprintf(f, ",\n\t");
2715                                 }
2716
2717                                 fprintf(f, "\n};\n\n");
2718                         }
2719                         break;
2720                 }
2721                 case PROP_INT:
2722                 {
2723                         IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2724                         unsigned int i;
2725
2726                         if (prop->arraydimension && prop->totarraylength) {
2727                                 fprintf(f, "static int rna_%s%s_%s_default[%u] = {\n\t", srna->identifier, strnest,
2728                                         prop->identifier, prop->totarraylength);
2729
2730                                 for (i = 0; i < prop->totarraylength; i++) {
2731                                         if (iprop->defaultarray)
2732                                                 fprintf(f, "%d", iprop->defaultarray[i]);
2733                                         else
2734                                                 fprintf(f, "%d", iprop->defaultvalue);
2735                                         if (i != prop->totarraylength - 1)
2736                                                 fprintf(f, ",\n\t");
2737                                 }
2738
2739                                 fprintf(f, "\n};\n\n");
2740                         }
2741                         break;
2742                 }
2743                 case PROP_FLOAT:
2744                 {
2745                         FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2746                         unsigned int i;
2747
2748                         if (prop->arraydimension && prop->totarraylength) {
2749                                 fprintf(f, "static float rna_%s%s_%s_default[%u] = {\n\t", srna->identifier, strnest,
2750                                         prop->identifier, prop->totarraylength);
2751
2752                                 for (i = 0; i < prop->totarraylength; i++) {
2753                                         if (fprop->defaultarray)
2754                                                 rna_float_print(f, fprop->defaultarray[i]);
2755                                         else
2756                                                 rna_float_print(f, fprop->defaultvalue);
2757                                         if (i != prop->totarraylength - 1)
2758                                                 fprintf(f, ",\n\t");
2759                                 }
2760
2761                                 fprintf(f, "\n};\n\n");
2762                         }
2763                         break;
2764                 }
2765                 default:
2766                         break;
2767         }
2768
2769         fprintf(f, "%s%s rna_%s%s_%s = {\n",
2770                 (prop->flag & PROP_EXPORT) ? "" : "",
2771                 rna_property_structname(prop->type),
2772                 srna->identifier, strnest, prop->identifier);
2773
2774         if (prop->next) fprintf(f, "\t{(PropertyRNA*)&rna_%s%s_%s, ", srna->identifier, strnest, prop->next->identifier);
2775         else fprintf(f, "\t{NULL, ");
2776         if (prop->prev) fprintf(f, "(PropertyRNA*)&rna_%s%s_%s,\n", srna->identifier, strnest, prop->prev->identifier);
2777         else fprintf(f, "NULL,\n");
2778         fprintf(f, "\t%d, ", prop->magic);
2779         rna_print_c_string(f, prop->identifier);
2780         fprintf(f, ", %d, ", prop->flag);
2781         rna_print_c_string(f, prop->name); fprintf(f, ",\n\t");
2782         rna_print_c_string(f, prop->description); fprintf(f, ",\n\t");
2783         fprintf(f, "%d,\n", prop->icon);
2784         rna_print_c_string(f, prop->translation_context); fprintf(f, ",\n\t");
2785         fprintf(f, "\t%s, %s|%s, %s, %u, {%u, %u, %u}, %u,\n",
2786                 RNA_property_typename(prop->type),
2787                 rna_property_subtypename(prop->subtype),
2788                 rna_property_subtype_unit(prop->subtype),
2789                 rna_function_string(prop->getlength),
2790                 prop->arraydimension,
2791                 prop->arraylength[0],
2792                 prop->arraylength[1],
2793                 prop->arraylength[2],
2794                 prop->totarraylength);
2795         fprintf(f, "\t%s%s, %d, %s, %s,\n",
2796                 (prop->flag & PROP_CONTEXT_UPDATE) ? "(UpdateFunc)" : "",
2797                 rna_function_string(prop->update),
2798                 prop->noteflag,
2799                 rna_function_string(prop->editable),
2800                 rna_function_string(prop->itemeditable));
2801
2802         if (prop->flag & PROP_RAW_ACCESS) rna_set_raw_offset(f, srna, prop);
2803         else fprintf(f, "\t0, -1");
2804
2805         /* our own type - collections/arrays only */
2806         if (prop->srna) fprintf(f, ", &RNA_%s", (const char *)prop->srna);
2807         else fprintf(f, ", NULL");
2808
2809         fprintf(f, "},\n");
2810
2811         switch (prop->type) {
2812                 case PROP_BOOLEAN:
2813                 {
2814                         BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
2815                         fprintf(f, "\t%s, %s, %s, %s, %d, ",
2816                                 rna_function_string(bprop->get),
2817                                 rna_function_string(bprop->set),
2818                                 rna_function_string(bprop->getarray),
2819                                 rna_function_string(bprop->setarray),
2820                                 bprop->defaultvalue);
2821                         if (prop->arraydimension && prop->totarraylength)
2822                                 fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
2823                         else fprintf(f, "NULL\n");
2824                         break;
2825                 }
2826                 case PROP_INT:
2827                 {
2828                         IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2829                         fprintf(f, "\t%s, %s, %s, %s, %s,\n\t",
2830                                 rna_function_string(iprop->get),
2831                                 rna_function_string(iprop->set),
2832                                 rna_function_string(iprop->getarray),
2833                                 rna_function_string(iprop->setarray),
2834                                 rna_function_string(iprop->range));
2835                         rna_int_print(f, iprop->softmin); fprintf(f, ", ");
2836                         rna_int_print(f, iprop->softmax); fprintf(f, ", ");
2837                         rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
2838                         rna_int_print(f, iprop->hardmax); fprintf(f, ", ");
2839                         rna_int_print(f, iprop->step); fprintf(f, ", ");
2840                         rna_int_print(f, iprop->defaultvalue); fprintf(f, ", ");
2841                         if (prop->arraydimension && prop->totarraylength)
2842                                 fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
2843                         else fprintf(f, "NULL\n");
2844                         break;
2845                 }
2846                 case PROP_FLOAT:
2847                 {
2848                         FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2849                         fprintf(f, "\t%s, %s, %s, %s, %s, ",
2850                                 rna_function_string(fprop->get),
2851                                 rna_function_string(fprop->set),
2852                                 rna_function_string(fprop->getarray),
2853                                 rna_function_string(fprop->setarray),
2854                                 rna_function_string(fprop->range));
2855                         rna_float_print(f, fprop->softmin); fprintf(f, ", ");
2856                         rna_float_print(f, fprop->softmax); fprintf(f, ", ");
2857                         rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
2858                         rna_float_print(f, fprop->hardmax); fprintf(f, ", ");
2859                         rna_float_print(f, fprop->step); fprintf(f, ", ");
2860                         rna_int_print(f, (int)fprop->precision); fprintf(f, ", ");
2861                         rna_float_print(f, fprop->defaultvalue); fprintf(f, ", ");
2862                         if (prop->arraydimension && prop->totarraylength)
2863                                 fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
2864 &