gwenhywfar  5.10.1
code_c.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Mon Mar 01 2004
3  copyright : (C) 2004-2010 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * Please see toplevel file COPYING for license details *
8  ***************************************************************************/
9 
10 #ifdef HAVE_CONFIG_H
11 # include <config.h>
12 #endif
13 
14 
15 
16 #include "args.h"
17 #include "typemaker_p.h"
18 #include <gwenhywfar/debug.h>
19 #include <gwenhywfar/logger.h>
20 #include <gwenhywfar/xml.h>
21 #include <gwenhywfar/syncio_file.h>
22 
23 #include <stdlib.h>
24 #include <assert.h>
25 
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <fcntl.h>
29 #include <errno.h>
30 #include <string.h>
31 #include <ctype.h>
32 
33 
34 
36  GWEN_SYNCIO *sio)
37 {
38  GWEN_XMLNODE *n;
39 
40  n=GWEN_XMLNode_FindFirstTag(node, "subtypes", 0, 0);
41  if (n)
42  n=GWEN_XMLNode_FindFirstTag(n, "type", "mode", "enum");
43  if (n) {
44  GWEN_BUFFER *tprefix;
45  GWEN_BUFFER *tid;
46  uint32_t ppos;
47  uint32_t tpos;
48  const char *s;
49 
50  tprefix=GWEN_Buffer_new(0, 64, 0, 1);
51  tid=GWEN_Buffer_new(0, 64, 0, 1);
52 
53  s=get_struct_property(node, "prefix", 0);
54  assert(s);
55  GWEN_Buffer_AppendString(tprefix, s);
56  GWEN_Buffer_AppendString(tprefix, "_");
57  ppos=GWEN_Buffer_GetPos(tprefix);
58 
59  s=get_struct_property(node, "id", 0);
60  assert(s);
62  GWEN_Buffer_AppendString(tid, "_");
63  tpos=GWEN_Buffer_GetPos(tid);
64 
65  while (n) {
66  GWEN_XMLNODE *nn;
67  s=GWEN_XMLNode_GetProperty(n, "access", "public");
68 
69  s=GWEN_XMLNode_GetProperty(n, "id", 0);
70  assert(s);
72  s=GWEN_XMLNode_GetProperty(n, "prefix", 0);
73  assert(s);
74  GWEN_Buffer_AppendString(tprefix, s);
75 
77  GWEN_SyncIo_WriteString(sio, " ");
79  GWEN_SyncIo_WriteLine(sio, "_fromString(const char *s) {");
80  GWEN_SyncIo_WriteLine(sio, " if (s) {");
81 
82  nn=GWEN_XMLNode_FindFirstTag(n, "values", 0, 0);
83  if (nn)
84  nn=GWEN_XMLNode_FindFirstTag(nn, "value", 0, 0);
85  if (nn) {
86  uint32_t vpos;
87  int first=1;
88 
89  vpos=GWEN_Buffer_GetPos(tprefix);
90  while (nn) {
91  GWEN_XMLNODE *nnn;
92 
94  if (!nnn) {
95  DBG_ERROR(0, "No values in enum description for \"%s\"",
97  GWEN_Buffer_free(tid);
98  GWEN_Buffer_free(tprefix);
99  return -1;
100  }
101  if (first)
102  GWEN_SyncIo_WriteString(sio, " if (strcasecmp(s, \"");
103  else
104  GWEN_SyncIo_WriteString(sio, " else if (strcasecmp(s, \"");
105  s=GWEN_XMLNode_GetData(nnn);
106  assert(s);
107  GWEN_SyncIo_WriteString(sio, s);
108  GWEN_SyncIo_WriteLine(sio, "\")==0)");
109  GWEN_SyncIo_WriteString(sio, " return ");
110 
111  GWEN_Buffer_AppendByte(tprefix, toupper(*s));
112  GWEN_Buffer_AppendString(tprefix, s+1);
114  GWEN_SyncIo_WriteLine(sio, ";");
115 
116  GWEN_Buffer_Crop(tprefix, 0, vpos);
117  GWEN_Buffer_SetPos(tprefix, vpos);
118  first=0;
119  nn=GWEN_XMLNode_FindNextTag(nn, "value", 0, 0);
120  }
121  }
122  GWEN_SyncIo_WriteLine(sio, " }");
123  GWEN_SyncIo_WriteString(sio, " return ");
125  GWEN_SyncIo_WriteLine(sio, "Unknown;");
126  GWEN_SyncIo_WriteLine(sio, "}");
127  GWEN_SyncIo_WriteLine(sio, "");
128  GWEN_SyncIo_WriteLine(sio, "");
129 
130  GWEN_SyncIo_WriteString(sio, "const char *");
132  GWEN_SyncIo_WriteString(sio, "_toString(");
134  GWEN_SyncIo_WriteLine(sio, " v) {");
135  GWEN_SyncIo_WriteLine(sio, " switch(v) {");
136 
137  nn=GWEN_XMLNode_FindFirstTag(n, "values", 0, 0);
138  if (nn)
139  nn=GWEN_XMLNode_FindFirstTag(nn, "value", 0, 0);
140  if (nn) {
141  uint32_t vpos;
142 
143  vpos=GWEN_Buffer_GetPos(tprefix);
144  while (nn) {
145  GWEN_XMLNODE *nnn;
146 
148  if (!nnn) {
149  DBG_ERROR(0, "No values in enum description for \"%s\"",
150  GWEN_Buffer_GetStart(tid));
151  GWEN_Buffer_free(tid);
152  GWEN_Buffer_free(tprefix);
153  return -1;
154  }
155  s=GWEN_XMLNode_GetData(nnn);
156  assert(s);
157  GWEN_Buffer_AppendByte(tprefix, toupper(*s));
158  GWEN_Buffer_AppendString(tprefix, s+1);
159 
160  GWEN_SyncIo_WriteString(sio, " case ");
162  GWEN_SyncIo_WriteLine(sio, ":");
163  GWEN_SyncIo_WriteString(sio, " return \"");
164  GWEN_SyncIo_WriteString(sio, s);
165  GWEN_SyncIo_WriteLine(sio, "\";");
166  GWEN_SyncIo_WriteLine(sio, "");
167 
168  GWEN_Buffer_Crop(tprefix, 0, vpos);
169  GWEN_Buffer_SetPos(tprefix, vpos);
170  nn=GWEN_XMLNode_FindNextTag(nn, "value", 0, 0);
171  }
172  }
173  GWEN_SyncIo_WriteLine(sio, " default:");
174  GWEN_SyncIo_WriteLine(sio, " return \"unknown\";");
175 
176 
177  GWEN_SyncIo_WriteLine(sio, " } /* switch */");
178  GWEN_SyncIo_WriteLine(sio, "} ");
179  GWEN_SyncIo_WriteLine(sio, "");
180  GWEN_SyncIo_WriteLine(sio, "");
181 
182  GWEN_Buffer_Crop(tprefix, 0, ppos);
183  GWEN_Buffer_Crop(tid, 0, tpos);
184  n=GWEN_XMLNode_FindNextTag(n, "type", "mode", "enum");
185  } /* while n */
186 
187  GWEN_Buffer_free(tid);
188  GWEN_Buffer_free(tprefix);
189  } /* if enum types found */
190 
191  return 0;
192 }
193 
194 
195 
197  GWEN_XMLNODE *node,
198  GWEN_SYNCIO *sio)
199 {
200  const char *typ;
201  const char *name;
202  int doCopy;
203  int takeOver;
204  int err;
205 
206  if (atoi(get_property(node, "ptr", "0"))==0)
207  return 0;
208 
209  doCopy=atoi(GWEN_XMLNode_GetProperty(node, "copy", "1"));
210  takeOver=atoi(GWEN_XMLNode_GetProperty(node, "takeOver", "0"));
211 
212  if (!doCopy && !takeOver)
213  return 0;
214 
215  typ=GWEN_XMLNode_GetProperty(node, "type", 0);
216  if (!typ) {
217  DBG_ERROR(0, "No type for element");
218  return -1;
219  }
220 
221  name=GWEN_XMLNode_GetProperty(node, "name", 0);
222  if (!name) {
223  DBG_ERROR(0, "No type for element");
224  return -1;
225  }
226 
227  err=GWEN_SyncIo_WriteString(sio, " if (st->");
228  if (err) {
229  DBG_ERROR_ERR(0, err);
230  return -1;
231  }
232  err=GWEN_SyncIo_WriteString(sio, name);
233  if (err) {
234  DBG_ERROR_ERR(0, err);
235  return -1;
236  }
237  err=GWEN_SyncIo_WriteLine(sio, ")");
238  if (err) {
239  DBG_ERROR_ERR(0, err);
240  return -1;
241  }
242 
243  if (strcmp(typ, "char")==0) {
244  /* we can handle chars */
245  err=GWEN_SyncIo_WriteString(sio, " free(st->");
246  if (err) {
247  DBG_ERROR_ERR(0, err);
248  return -1;
249  }
250  err=GWEN_SyncIo_WriteString(sio, name);
251  if (err) {
252  DBG_ERROR_ERR(0, err);
253  return -1;
254  }
255  err=GWEN_SyncIo_WriteLine(sio, ");");
256  if (err) {
257  DBG_ERROR_ERR(0, err);
258  return -1;
259  }
260  return 0;
261  }
262  else {
263  const char *fname;
264 
265  fname=get_function_name(node, "free");
266  if (fname) {
267  err=GWEN_SyncIo_WriteString(sio, " ");
268  if (err) {
269  DBG_ERROR_ERR(0, err);
270  return -1;
271  }
272  err=GWEN_SyncIo_WriteString(sio, fname);
273  if (err) {
274  DBG_ERROR_ERR(0, err);
275  return -1;
276  }
277  err=GWEN_SyncIo_WriteString(sio, "(st->");
278  if (err) {
279  DBG_ERROR_ERR(0, err);
280  return -1;
281  }
282  err=GWEN_SyncIo_WriteString(sio, name);
283  if (err) {
284  DBG_ERROR_ERR(0, err);
285  return -1;
286  }
287  err=GWEN_SyncIo_WriteLine(sio, ");");
288  if (err) {
289  DBG_ERROR_ERR(0, err);
290  return -1;
291  }
292  return 0;
293  }
294  }
295 
296  DBG_ERROR(0, "Unknown \"free\" function for type \"%s\"", typ);
297  return -1;
298 }
299 
300 
301 
303  GWEN_XMLNODE *node,
304  GWEN_SYNCIO *sio)
305 {
307  GWEN_XMLNODE *n;
308 
309  n=GWEN_XMLNode_GetFirstTag(node);
310  while (n) {
311  int rv;
312 
313  if (strcasecmp(GWEN_XMLNode_GetData(n), "group")==0)
314  rv=write_code_freeElems_c(args, n, sio);
315  else if (strcasecmp(GWEN_XMLNode_GetData(n), "elem")==0) {
316  rv=write_code_freeElem_c(args, n, sio);
317  }
318  else {
319  rv=0;
320  }
321 
322  if (rv)
323  return rv;
325  } /* while */
326  }
327 
328  return 0;
329 }
330 
331 
332 
334  GWEN_XMLNODE *node,
335  GWEN_SYNCIO *sio,
336  const char *param)
337 {
338  const char *typ;
339  const char *name;
340  int err;
341 
342  typ=GWEN_XMLNode_GetProperty(node, "type", 0);
343  if (!typ) {
344  DBG_ERROR(0, "No type for element");
345  return -1;
346  }
347 
348  name=GWEN_XMLNode_GetProperty(node, "name", 0);
349  if (!name) {
350  DBG_ERROR(0, "No type for element");
351  return -1;
352  }
353 
354  if (strcmp(typ, "char")==0) {
355  /* we can handle chars */
356  err=GWEN_SyncIo_WriteString(sio, "strdup(");
357  if (err) {
358  DBG_ERROR_ERR(0, err);
359  return -1;
360  }
361  err=GWEN_SyncIo_WriteString(sio, param);
362  if (err) {
363  DBG_ERROR_ERR(0, err);
364  return -1;
365  }
366  err=GWEN_SyncIo_WriteLine(sio, ");");
367  if (err) {
368  DBG_ERROR_ERR(0, err);
369  return -1;
370  }
371  return 0;
372  }
373  else {
374  const char *fname;
375 
376  fname=get_function_name(node, "dup");
377  if (!fname) {
378  DBG_ERROR(0, "No dup function set for type %s", typ);
379  return -1;
380  }
381  err=GWEN_SyncIo_WriteString(sio, fname);
382  if (err) {
383  DBG_ERROR_ERR(0, err);
384  return -1;
385  }
386  err=GWEN_SyncIo_WriteString(sio, "(");
387  err=GWEN_SyncIo_WriteString(sio, param);
388  if (err) {
389  DBG_ERROR_ERR(0, err);
390  return -1;
391  }
392  err=GWEN_SyncIo_WriteLine(sio, ");");
393  if (err) {
394  DBG_ERROR_ERR(0, err);
395  return -1;
396  }
397  return 0;
398  }
399 
400  DBG_ERROR(0, "Unknown \"dup\" function for type \"%s\"", typ);
401  return -1;
402 }
403 
404 
405 
407  GWEN_XMLNODE *node,
408  GWEN_SYNCIO *sio)
409 {
410  const char *btype;
411  const char *typ;
412  const char *name;
413  const char *mode;
414  int isPtr;
415 
416  isPtr=atoi(get_property(node, "ptr", "0"));
417 
418  name=GWEN_XMLNode_GetProperty(node, "name", 0);
419  if (!name) {
420  DBG_ERROR(0, "No name for element");
421  return -1;
422  }
423 
424  /* "single" as opposed to "list" or "list2" */
425  mode=GWEN_XMLNode_GetProperty(node, "mode", "single");
426  if (strcasecmp(mode, "list")==0 ||
427  strcasecmp(mode, "list2")==0)
428  /* all list modes operate on pointers */
429  isPtr=1;
430 
431  typ=GWEN_XMLNode_GetProperty(node, "type", 0);
432  if (!typ) {
433  DBG_ERROR(0, "No type for element");
434  return -1;
435  }
436 
437  if (isPtr) {
438  const char *fname;
439 
440  fname=get_function_name(node, "todb");
441  if (fname) {
442  GWEN_SyncIo_WriteString(sio, " if (");
443  GWEN_SyncIo_WriteString(sio, fname);
444  GWEN_SyncIo_WriteString(sio, "(st->");
445  GWEN_SyncIo_WriteChar(sio, tolower(*name));
446  GWEN_SyncIo_WriteString(sio, name+1);
448  ", GWEN_DB_GetGroup(db, "
449  "GWEN_DB_FLAGS_DEFAULT, \"");
450  GWEN_SyncIo_WriteChar(sio, tolower(*name));
451  GWEN_SyncIo_WriteString(sio, name+1);
452  GWEN_SyncIo_WriteLine(sio, "\")))");
453  GWEN_SyncIo_WriteLine(sio, " return -1;");
454  }
455  else {
456  if (strcasecmp(typ, "char")==0) {
458  " if (GWEN_DB_SetCharValue(db, "
459  "GWEN_DB_FLAGS_OVERWRITE_VARS, \"");
460  GWEN_SyncIo_WriteChar(sio, tolower(*name));
461  GWEN_SyncIo_WriteString(sio, name+1);
462  GWEN_SyncIo_WriteString(sio, "\", st->");
463  GWEN_SyncIo_WriteChar(sio, tolower(*name));
464  GWEN_SyncIo_WriteString(sio, name+1);
465  GWEN_SyncIo_WriteLine(sio, "))");
466  GWEN_SyncIo_WriteLine(sio, " return -1;");
467  }
468  else if (strcasecmp(typ, "GWEN_STRINGLIST")==0) {
469  GWEN_SyncIo_WriteLine(sio, " {");
470  GWEN_SyncIo_WriteLine(sio, " GWEN_STRINGLISTENTRY *se;");
471 
472  GWEN_SyncIo_WriteLine(sio, "");
473  GWEN_SyncIo_WriteString(sio, " GWEN_DB_DeleteVar(db, \"");
474  GWEN_SyncIo_WriteChar(sio, tolower(*name));
475  GWEN_SyncIo_WriteString(sio, name+1);
476  GWEN_SyncIo_WriteLine(sio, "\");");
477 
478  GWEN_SyncIo_WriteString(sio, " se=GWEN_StringList_FirstEntry(st->");
479  GWEN_SyncIo_WriteChar(sio, tolower(*name));
480  GWEN_SyncIo_WriteString(sio, name+1);
481  GWEN_SyncIo_WriteLine(sio, ");");
482 
483  GWEN_SyncIo_WriteLine(sio, " while(se) {");
484  GWEN_SyncIo_WriteLine(sio, " const char *s;");
485  GWEN_SyncIo_WriteLine(sio, "");
486 
487  GWEN_SyncIo_WriteLine(sio, " s=GWEN_StringListEntry_Data(se);");
488  GWEN_SyncIo_WriteLine(sio, " assert(s);");
490  " if (GWEN_DB_SetCharValue(db, "
491  "GWEN_DB_FLAGS_DEFAULT, \"");
492  GWEN_SyncIo_WriteChar(sio, tolower(*name));
493  GWEN_SyncIo_WriteString(sio, name+1);
494  GWEN_SyncIo_WriteLine(sio, "\", s))");
495  GWEN_SyncIo_WriteLine(sio, " return -1;");
496 
497  GWEN_SyncIo_WriteLine(sio, " se=GWEN_StringListEntry_Next(se);");
498  GWEN_SyncIo_WriteLine(sio, " } /* while */");
499  GWEN_SyncIo_WriteLine(sio, " }");
500  }
501  else if (strcasecmp(mode, "list")==0) {
502  const char *elemType;
503  const char *elemPrefix;
504  GWEN_XMLNODE *elemNode;
505 
506  /* create list code */
507  elemType=GWEN_XMLNode_GetProperty(node, "elemType", 0);
508  if (!elemType) {
509  DBG_ERROR(0, "No \"type\" for list type \"%s\"", typ);
510  return -1;
511  }
512 
513  elemNode=get_typedef(node, elemType);
514  if (!elemNode) {
515  DBG_ERROR(0, "Undefined type %s", elemType);
516  return -1;
517  }
518  elemPrefix=GWEN_XMLNode_GetProperty(elemNode, "prefix", 0);
519  if (!elemPrefix) {
520  DBG_ERROR(0, "No \"prefix\" for type \"%s\" (within %s)",
521  elemType, typ);
522  return -1;
523  }
524 
525  /* actually generate the code */
526  GWEN_SyncIo_WriteLine(sio, " if (1) {");
527  GWEN_SyncIo_WriteLine(sio, " GWEN_DB_NODE *dbT;");
528 
529  GWEN_SyncIo_WriteString(sio, " ");
530  GWEN_SyncIo_WriteString(sio, elemType);
531  GWEN_SyncIo_WriteLine(sio, " *e;");
532  GWEN_SyncIo_WriteLine(sio, "");
534  " dbT=GWEN_DB_GetGroup(db, "
535  "GWEN_PATH_FLAGS_CREATE_GROUP, \"");
536  GWEN_SyncIo_WriteChar(sio, tolower(*name));
537  GWEN_SyncIo_WriteString(sio, name+1);
538  GWEN_SyncIo_WriteLine(sio, "\");");
539  GWEN_SyncIo_WriteLine(sio, " assert(dbT);");
540 
541  /* e=ElemType_List_First(st->name) */
542  GWEN_SyncIo_WriteString(sio, " e=");
543  GWEN_SyncIo_WriteString(sio, elemPrefix);
544  GWEN_SyncIo_WriteString(sio, "_List_First(st->");
545  GWEN_SyncIo_WriteChar(sio, tolower(*name));
546  GWEN_SyncIo_WriteString(sio, name+1);
547  GWEN_SyncIo_WriteLine(sio, ");");
548 
549  /* while (e) */
550  GWEN_SyncIo_WriteLine(sio, " while(e) {");
551 
552  /* handle element type */
553  GWEN_SyncIo_WriteString(sio, " if (");
554  GWEN_SyncIo_WriteString(sio, elemPrefix);
555  GWEN_SyncIo_WriteString(sio, "_toDb(e, ");
557  "GWEN_DB_GetGroup(dbT, "
558  "GWEN_PATH_FLAGS_CREATE_GROUP, \"");
559  GWEN_SyncIo_WriteString(sio, "element");
560  GWEN_SyncIo_WriteLine(sio, "\")))");
561  GWEN_SyncIo_WriteLine(sio, " return -1;");
562 
563  /* e=ElemType_List_Next(e) */
564  GWEN_SyncIo_WriteString(sio, " e=");
565  GWEN_SyncIo_WriteString(sio, elemPrefix);
566  GWEN_SyncIo_WriteLine(sio, "_List_Next(e);");
567 
568  GWEN_SyncIo_WriteLine(sio, " } /* while */");
569 
570  GWEN_SyncIo_WriteLine(sio, " } /* if (1) */");
571 
572  }
573  else if (strcasecmp(mode, "list2")==0) {
574  const char *elemType;
575  const char *elemPrefix;
576  GWEN_XMLNODE *elemNode;
577 
578  /* create list2 code */
579  elemType=GWEN_XMLNode_GetProperty(node, "elemType", 0);
580  if (!elemType) {
581  DBG_ERROR(0, "No \"type\" for list type \"%s\"", typ);
582  return -1;
583  }
584 
585  elemNode=get_typedef(node, elemType);
586  if (!elemNode) {
587  DBG_ERROR(0, "Undefined type %s", elemType);
588  return -1;
589  }
590  elemPrefix=GWEN_XMLNode_GetProperty(elemNode, "prefix", 0);
591  if (!elemPrefix) {
592  DBG_ERROR(0, "No \"prefix\" for type \"%s\" (within %s)",
593  elemType, typ);
594  return -1;
595  }
596 
597  /* actually generate the code */
598  GWEN_SyncIo_WriteLine(sio, " if (1) {");
599  GWEN_SyncIo_WriteLine(sio, " GWEN_DB_NODE *dbT;");
600  GWEN_SyncIo_WriteString(sio, " ");
601  GWEN_SyncIo_WriteString(sio, elemType);
602  GWEN_SyncIo_WriteLine(sio, "_LIST2_ITERATOR *it;");
603  GWEN_SyncIo_WriteLine(sio, "");
605  " dbT=GWEN_DB_GetGroup(db, "
606  "GWEN_PATH_FLAGS_CREATE_GROUP, \"");
607  GWEN_SyncIo_WriteChar(sio, tolower(*name));
608  GWEN_SyncIo_WriteString(sio, name+1);
609  GWEN_SyncIo_WriteLine(sio, "\");");
610  GWEN_SyncIo_WriteLine(sio, " assert(dbT);");
611 
612  /* it=ElemType_List2_First(st->name) */
613  GWEN_SyncIo_WriteString(sio, " it=");
614  GWEN_SyncIo_WriteString(sio, elemPrefix);
615  GWEN_SyncIo_WriteString(sio, "_List2_First(st->");
616  GWEN_SyncIo_WriteChar(sio, tolower(*name));
617  GWEN_SyncIo_WriteString(sio, name+1);
618  GWEN_SyncIo_WriteLine(sio, ");");
619 
620  /* if (it) */
621  GWEN_SyncIo_WriteLine(sio, " if (it) {");
622  GWEN_SyncIo_WriteString(sio, " ");
623  GWEN_SyncIo_WriteString(sio, elemType);
624  GWEN_SyncIo_WriteLine(sio, " *e;");
625  GWEN_SyncIo_WriteLine(sio, "");
626 
627  /* e=ElemType_List2Iterator_Data(it) */
628  GWEN_SyncIo_WriteString(sio, " e=");
629  GWEN_SyncIo_WriteString(sio, elemPrefix);
630  GWEN_SyncIo_WriteLine(sio, "_List2Iterator_Data(it);");
631  GWEN_SyncIo_WriteString(sio, " assert(e);");
632 
633  /* while (e) */
634  GWEN_SyncIo_WriteLine(sio, " while(e) {");
635 
636  /* handle element type */
637  GWEN_SyncIo_WriteString(sio, " if (");
638  GWEN_SyncIo_WriteString(sio, elemPrefix);
639  GWEN_SyncIo_WriteString(sio, "_toDb(e, ");
641  "GWEN_DB_GetGroup(dbT, "
642  "GWEN_PATH_FLAGS_CREATE_GROUP, \"");
643  GWEN_SyncIo_WriteString(sio, "element");
644  GWEN_SyncIo_WriteLine(sio, "\")))");
645  GWEN_SyncIo_WriteLine(sio, " return -1;");
646 
647  /* e=ElemType_List2Iterator_Next(it) */
648  GWEN_SyncIo_WriteString(sio, " e=");
649  GWEN_SyncIo_WriteString(sio, elemPrefix);
650  GWEN_SyncIo_WriteLine(sio, "_List2Iterator_Next(it);");
651 
652  GWEN_SyncIo_WriteLine(sio, " } /* while */");
653 
654  /* free iterator */
655  GWEN_SyncIo_WriteString(sio, " ");
656  GWEN_SyncIo_WriteString(sio, elemPrefix);
657  GWEN_SyncIo_WriteString(sio, "_List2Iterator_free(it);");
658 
659  GWEN_SyncIo_WriteLine(sio, " } /* if (it) */");
660 
661  GWEN_SyncIo_WriteLine(sio, " } /* if (1) */");
662 
663  }
664  else {
665  DBG_ERROR(0, "No toDb function for type \"%s\"", typ);
666  return -1;
667  }
668  }
669 
670  }
671  else {
672  btype=get_property(node, "basetype", 0);
673  if (!btype) {
674  if (strcasecmp(typ, "char")==0)
675  btype="char";
676  else if (strcasecmp(typ, "uint32_t")==0)
677  btype="int";
678  else if (strcasecmp(typ, "GWEN_TYPE_UINT64")==0)
679  btype="int";
680  else {
681  btype=typ;
682  }
683  }
684  if (strcasecmp(btype, "int")==0) {
686  " if (GWEN_DB_SetIntValue(db, "
687  "GWEN_DB_FLAGS_OVERWRITE_VARS, \"");
688  }
689  else if (strcasecmp(btype, "char")==0) {
691  " if (GWEN_DB_SetCharValue(db, "
692  "GWEN_DB_FLAGS_OVERWRITE_VARS, \"");
693  }
694  else {
695  GWEN_XMLNODE *tnode;
696  const char *tmode;
697 
698  tnode=get_typedef(node, typ);
699  if (!tnode) {
700  DBG_ERROR(0, "Undefined type %s", typ);
701  return -1;
702  }
703  tmode=GWEN_XMLNode_GetProperty(tnode, "mode", "single");
704  if (strcasecmp(tmode, "enum")==0) {
705  GWEN_XMLNODE *tnode;
706  const char *tmode;
707 
708  tnode=get_typedef(node, typ);
709  if (!tnode) {
710  DBG_ERROR(0, "Undefined type %s", typ);
711  return -1;
712  }
713  tmode=GWEN_XMLNode_GetProperty(tnode, "mode", "single");
714  if (strcasecmp(tmode, "enum")==0) {
715  GWEN_BUFFER *tprefix;
716  const char *s;
717 
718  tprefix=GWEN_Buffer_new(0, 64, 0, 1);
719 
720  s=get_struct_property(node, "prefix", 0);
721  assert(s);
722  GWEN_Buffer_AppendString(tprefix, s);
723  GWEN_Buffer_AppendString(tprefix, "_");
724 
725  s=GWEN_XMLNode_GetProperty(tnode, "prefix", 0);
726  assert(s);
727  GWEN_SyncIo_WriteString(sio, " if (GWEN_DB_SetCharValue(db, ");
728  GWEN_SyncIo_WriteString(sio, "GWEN_DB_FLAGS_OVERWRITE_VARS, \"");
729  GWEN_SyncIo_WriteChar(sio, tolower(*name));
730  GWEN_SyncIo_WriteString(sio, name+1);
731  GWEN_SyncIo_WriteString(sio, "\", ");
732 
733  GWEN_Buffer_AppendString(tprefix, s);
735  GWEN_SyncIo_WriteString(sio, "_toString(st->");
736  GWEN_SyncIo_WriteChar(sio, tolower(*name));
737  GWEN_SyncIo_WriteString(sio, name+1);
738  GWEN_SyncIo_WriteString(sio, ")");
739  GWEN_SyncIo_WriteString(sio, ")");
740  GWEN_SyncIo_WriteLine(sio, ") ");
741  GWEN_SyncIo_WriteLine(sio, " return -1;");
742 
743  GWEN_Buffer_free(tprefix);
744  return 0;
745  } /* if enum */
746  else {
747  DBG_ERROR(0, "Bad non-pointer type \"%s\" (not a base type)", typ);
748  return -1;
749  }
750 
751  }
752  else {
753  DBG_ERROR(0, "Bad non-pointer type \"%s\" (not a base type)", typ);
754  return -1;
755  }
756  }
757 
758  GWEN_SyncIo_WriteChar(sio, tolower(*name));
759  GWEN_SyncIo_WriteString(sio, name+1);
760  GWEN_SyncIo_WriteString(sio, "\", st->");
761  GWEN_SyncIo_WriteChar(sio, tolower(*name));
762  GWEN_SyncIo_WriteString(sio, name+1);
763  GWEN_SyncIo_WriteLine(sio, "))");
764  GWEN_SyncIo_WriteLine(sio, " return -1;");
765  }
766 
767  return 0;
768 }
769 
770 
771 
773  GWEN_XMLNODE *node,
774  GWEN_SYNCIO *sio)
775 {
776  const char *btype;
777  const char *typ;
778  const char *name;
779  const char *mode;
780  int isPtr;
781  const char *defval;
782  int isVolatile;
783 
784  isVolatile=atoi(GWEN_XMLNode_GetProperty(node, "volatile", "0"));
785  if (isVolatile)
786  /* don't save volatile data */
787  return 0;
788 
789  isPtr=atoi(get_property(node, "ptr", "0"));
790 
791  name=GWEN_XMLNode_GetProperty(node, "name", 0);
792  if (!name) {
793  DBG_ERROR(0, "No name for element");
794  return -1;
795  }
796 
797  mode=GWEN_XMLNode_GetProperty(node, "mode", "single");
798  if (strcasecmp(mode, "single")!=0)
799  /* all list modes operate on pointers */
800  isPtr=1;
801 
802  typ=GWEN_XMLNode_GetProperty(node, "type", 0);
803  if (!typ) {
804  DBG_ERROR(0, "No type for element");
805  return -1;
806  }
807 
808  defval=get_property(node, "default", 0);
809 
810  if (isPtr) {
811  const char *fname;
812 
813  fname=get_function_name(node, "fromdb");
814  if (fname) {
815  GWEN_SyncIo_WriteString(sio, fname);
816  GWEN_SyncIo_WriteString(sio, "(dbT)");
817  }
818  else {
819  if (strcasecmp(typ, "char")==0) {
820  GWEN_SyncIo_WriteString(sio, "GWEN_DB_GetCharValue(db, \"");
821  GWEN_SyncIo_WriteChar(sio, tolower(*name));
822  GWEN_SyncIo_WriteString(sio, name+1);
823  GWEN_SyncIo_WriteString(sio, "\", 0, ");
824  if (defval) {
825  GWEN_SyncIo_WriteString(sio, "\"");
826  GWEN_SyncIo_WriteString(sio, defval);
827  GWEN_SyncIo_WriteString(sio, "\"");
828  }
829  else {
830  GWEN_SyncIo_WriteString(sio, "0");
831  }
832  GWEN_SyncIo_WriteString(sio, ")");
833  }
834  else {
835  DBG_ERROR(0, "No fromDb function for type \"%s\"", typ);
836  return -1;
837  }
838  }
839 
840  }
841  else {
842  btype=get_property(node, "basetype", 0);
843  if (!btype) {
844  if (strcasecmp(typ, "char")==0)
845  btype="char";
846  else if (strcasecmp(typ, "uint32_t")==0)
847  btype="int";
848  else if (strcasecmp(typ, "GWEN_TYPE_UINT64")==0)
849  btype="int";
850  else {
851  btype=typ;
852  }
853  }
854  if (strcasecmp(btype, "int")==0) {
855  GWEN_SyncIo_WriteString(sio, "GWEN_DB_GetIntValue(db, \"");
856  GWEN_SyncIo_WriteChar(sio, tolower(*name));
857  GWEN_SyncIo_WriteString(sio, name+1);
858  GWEN_SyncIo_WriteString(sio, "\", 0, ");
859  if (defval) {
860  GWEN_SyncIo_WriteString(sio, defval);
861  }
862  else {
863  GWEN_SyncIo_WriteString(sio, "0");
864  }
865  GWEN_SyncIo_WriteString(sio, ")");
866  }
867  else if (strcasecmp(btype, "char")==0) {
868  GWEN_SyncIo_WriteString(sio, "GWEN_DB_GetCharValue(db, \"");
869  GWEN_SyncIo_WriteChar(sio, tolower(*name));
870  GWEN_SyncIo_WriteString(sio, name+1);
871  GWEN_SyncIo_WriteString(sio, "\", 0, ");
872  if (defval) {
873  GWEN_SyncIo_WriteString(sio, "\"");
874  GWEN_SyncIo_WriteString(sio, defval);
875  GWEN_SyncIo_WriteString(sio, "\"");
876  }
877  else {
878  GWEN_SyncIo_WriteString(sio, "0");
879  }
880  GWEN_SyncIo_WriteString(sio, ")");
881  }
882  else {
883  GWEN_XMLNODE *tnode;
884  const char *tmode;
885 
886  tnode=get_typedef(node, typ);
887  if (!tnode) {
888  DBG_ERROR(0, "Undefined type %s", typ);
889  return -1;
890  }
891  tmode=GWEN_XMLNode_GetProperty(tnode, "mode", "single");
892  if (strcasecmp(tmode, "enum")==0) {
893  GWEN_BUFFER *tprefix;
894  const char *s;
895 
896  tprefix=GWEN_Buffer_new(0, 64, 0, 1);
897 
898  s=get_struct_property(node, "prefix", 0);
899  assert(s);
900  GWEN_Buffer_AppendString(tprefix, s);
901  GWEN_Buffer_AppendString(tprefix, "_");
902 
903  s=GWEN_XMLNode_GetProperty(tnode, "prefix", 0);
904  assert(s);
905  GWEN_Buffer_AppendString(tprefix, s);
907  GWEN_SyncIo_WriteString(sio, "_fromString(");
908  GWEN_SyncIo_WriteString(sio, "GWEN_DB_GetCharValue(db, \"");
909  GWEN_SyncIo_WriteChar(sio, tolower(*name));
910  GWEN_SyncIo_WriteString(sio, name+1);
911  GWEN_SyncIo_WriteString(sio, "\", 0, ");
912  if (defval) {
913  GWEN_SyncIo_WriteString(sio, "\"");
914  GWEN_SyncIo_WriteString(sio, defval);
915  GWEN_SyncIo_WriteString(sio, "\"");
916  }
917  else {
918  GWEN_SyncIo_WriteString(sio, "0");
919  }
920  GWEN_SyncIo_WriteString(sio, ")");
921  GWEN_SyncIo_WriteString(sio, ")");
922  GWEN_Buffer_free(tprefix);
923  } /* if enum */
924  else {
925  DBG_ERROR(0, "Bad non-pointer type \"%s\" (not a base type)", typ);
926  return -1;
927  }
928  }
929  }
930 
931  return 0;
932 }
933 
934 
935 
937  GWEN_XMLNODE *node,
938  GWEN_SYNCIO *sio)
939 {
940  GWEN_XMLNODE *n;
941  int rv;
942  const char *prefix;
943  const char *styp;
944 
945  prefix=get_struct_property(node, "prefix", 0);
946  if (!prefix) {
947  DBG_ERROR(0, "No prefix in struct");
948  return -1;
949  }
950  styp=get_struct_property(node, "id", 0);
951  if (!styp) {
952  DBG_ERROR(0, "No id in struct");
953  return -1;
954  }
955 
956  n=GWEN_XMLNode_GetFirstTag(node);
957  while (n) {
959  if (strcasecmp(GWEN_XMLNode_GetData(n), "group")==0) {
960  rv=write_code_constrec_c(args, n, sio);
961  if (rv) {
962  DBG_ERROR(0, "Error in dup");
963  return rv;
964  }
965  }
966  else if (strcasecmp(GWEN_XMLNode_GetData(n), "elem")==0) {
967  int isPtr;
968  const char *typ;
969  const char *name;
970  const char *setval;
971  const char *mode;
972 
973  name=GWEN_XMLNode_GetProperty(n, "name", 0);
974  if (!name) {
975  DBG_ERROR(0, "No name for element");
976  return -1;
977  }
978 
979  typ=GWEN_XMLNode_GetProperty(n, "type", 0);
980  if (!typ) {
981  DBG_ERROR(0, "No type for element");
982  return -1;
983  }
984 
985  setval=GWEN_XMLNode_GetProperty(n, "preset", 0);
986  isPtr=atoi(get_property(n, "ptr", "0"));
987  mode=GWEN_XMLNode_GetProperty(n, "mode", "single");
988 
989  if (strcasecmp(mode, "single")!=0)
990  /* lists always use pointers */
991  isPtr=1;
992 
993  if (isPtr) {
994  if (strcasecmp(typ, "GWEN_STRINGLIST")==0) {
995  GWEN_SyncIo_WriteString(sio, " st->");
996  GWEN_SyncIo_WriteChar(sio, tolower(*name));
997  GWEN_SyncIo_WriteString(sio, name+1);
998  GWEN_SyncIo_WriteLine(sio, "=GWEN_StringList_new();");
999  }
1000  else if (strcasecmp(mode, "single")!=0) {
1001  int initVar;
1002 
1003  initVar=atoi(get_property(n, "init", "0"));
1004  if (initVar) {
1005  const char *fname;
1006 
1007  fname=get_function_name(n, "new");
1008  if (!fname) {
1009  DBG_ERROR(0, "No new-function set for type %s", typ);
1010  return -1;
1011  }
1012  GWEN_SyncIo_WriteString(sio, " st->");
1013  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1014  GWEN_SyncIo_WriteString(sio, name+1);
1015  GWEN_SyncIo_WriteString(sio, "=");
1016  GWEN_SyncIo_WriteString(sio, fname);
1017  GWEN_SyncIo_WriteLine(sio, "();");
1018  } /* if init requested */
1019  } /* if !single */
1020  else {
1021  if (setval) {
1022  GWEN_SyncIo_WriteString(sio, " st->");
1023  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1024  GWEN_SyncIo_WriteString(sio, name+1);
1025  GWEN_SyncIo_WriteString(sio, "=");
1026  GWEN_SyncIo_WriteString(sio, setval);
1027  GWEN_SyncIo_WriteLine(sio, ";");
1028  }
1029  }
1030  }
1031  else {
1032  if (setval) {
1033  /* TODO: check for enum values */
1034  GWEN_SyncIo_WriteString(sio, " st->");
1035  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1036  GWEN_SyncIo_WriteString(sio, name+1);
1037  GWEN_SyncIo_WriteString(sio, "=");
1038  GWEN_SyncIo_WriteString(sio, setval);
1039  GWEN_SyncIo_WriteLine(sio, ";");
1040  }
1041  }
1042  }
1043  else if (strcasecmp(GWEN_XMLNode_GetData(n), "func")==0) {
1044  }
1045  }
1047  }
1048  return 0;
1049 }
1050 
1051 
1052 
1053 
1055  GWEN_XMLNODE *node,
1056  GWEN_SYNCIO *sio)
1057 {
1058  const char *prefix;
1059  const char *styp;
1060  const char *constName;
1061  int rv;
1062 
1063  prefix=get_struct_property(node, "prefix", 0);
1064  if (!prefix) {
1065  DBG_ERROR(0, "No prefix in struct");
1066  return -1;
1067  }
1068  styp=get_struct_property(node, "id", 0);
1069  if (!styp) {
1070  DBG_ERROR(0, "No id in struct");
1071  return -1;
1072  }
1073  constName=get_struct_property(node, "constructor-name", 0);
1074 
1075  GWEN_SyncIo_WriteString(sio, styp);
1076  GWEN_SyncIo_WriteString(sio, " *");
1077  GWEN_SyncIo_WriteString(sio, prefix);
1078  if (constName && *constName)
1079  GWEN_SyncIo_WriteString(sio, constName);
1080  else
1081  GWEN_SyncIo_WriteString(sio, "_new");
1082  GWEN_SyncIo_WriteLine(sio, "(void) {");
1083 
1084  GWEN_SyncIo_WriteString(sio, " ");
1085  GWEN_SyncIo_WriteString(sio, styp);
1086  GWEN_SyncIo_WriteLine(sio, " *st;");
1087  GWEN_SyncIo_WriteLine(sio, "");
1088 
1089  GWEN_SyncIo_WriteString(sio, " GWEN_NEW_OBJECT(");
1090  GWEN_SyncIo_WriteString(sio, styp);
1091  GWEN_SyncIo_WriteLine(sio, ", st)");
1092  GWEN_SyncIo_WriteLine(sio, " st->_usage=1;");
1093 
1094  // add inherit functions
1095  if (get_struct_property(node, "inherit", 0)) {
1096  GWEN_SyncIo_WriteString(sio, " GWEN_INHERIT_INIT(");
1097  GWEN_SyncIo_WriteString(sio, styp);
1098  GWEN_SyncIo_WriteLine(sio, ", st)");
1099  }
1100 
1101  // add list functions
1102  if (get_struct_property(node, "list", 0)) {
1103  GWEN_SyncIo_WriteString(sio, " GWEN_LIST_INIT(");
1104  GWEN_SyncIo_WriteString(sio, styp);
1105  GWEN_SyncIo_WriteLine(sio, ", st)");
1106  }
1107 
1108  rv=write_code_constrec_c(args, node, sio);
1109  if (rv)
1110  return rv;
1111 
1112  GWEN_SyncIo_WriteLine(sio, " return st;");
1113  GWEN_SyncIo_WriteLine(sio, "}");
1114 
1115  return 0;
1116 }
1117 
1118 
1119 
1121  GWEN_XMLNODE *node,
1122  GWEN_SYNCIO *sio)
1123 {
1124  const char *prefix;
1125  const char *styp;
1126  int rv;
1127 
1128  prefix=get_struct_property(node, "prefix", 0);
1129  if (!prefix) {
1130  DBG_ERROR(0, "No prefix in struct");
1131  return -1;
1132  }
1133  styp=get_struct_property(node, "id", 0);
1134  if (!styp) {
1135  DBG_ERROR(0, "No id in struct");
1136  return -1;
1137  }
1138 
1139  GWEN_SyncIo_WriteString(sio, "void ");
1140  GWEN_SyncIo_WriteString(sio, prefix);
1141  GWEN_SyncIo_WriteString(sio, "_free(");
1142  GWEN_SyncIo_WriteString(sio, styp);
1143  GWEN_SyncIo_WriteLine(sio, " *st) {");
1144 
1145  GWEN_SyncIo_WriteLine(sio, " if (st) {");
1146 
1147  GWEN_SyncIo_WriteLine(sio, " assert(st->_usage);");
1148  GWEN_SyncIo_WriteLine(sio, " if (--(st->_usage)==0) {");
1149 
1150  // add inherit functions
1151  if (get_struct_property(node, "inherit", 0)) {
1152  GWEN_SyncIo_WriteString(sio, " GWEN_INHERIT_FINI(");
1153  GWEN_SyncIo_WriteString(sio, styp);
1154  GWEN_SyncIo_WriteLine(sio, ", st)");
1155  }
1156 
1157  rv=write_code_freeElems_c(args, node, sio);
1158  if (rv) {
1159  DBG_ERROR(0, "Error in freeElems");
1160  return rv;
1161  }
1162 
1163  // add list functions
1164  if (get_struct_property(node, "list", 0)) {
1165  GWEN_SyncIo_WriteString(sio, " GWEN_LIST_FINI(");
1166  GWEN_SyncIo_WriteString(sio, styp);
1167  GWEN_SyncIo_WriteLine(sio, ", st)");
1168  }
1169 
1170  GWEN_SyncIo_WriteLine(sio, " GWEN_FREE_OBJECT(st);");
1171  GWEN_SyncIo_WriteLine(sio, " }");
1172  GWEN_SyncIo_WriteLine(sio, " }");
1173  GWEN_SyncIo_WriteLine(sio, "");
1174  GWEN_SyncIo_WriteLine(sio, "}");
1175 
1176  return 0;
1177 }
1178 
1179 
1180 
1182  GWEN_XMLNODE *node,
1183  GWEN_SYNCIO *sio)
1184 {
1185  GWEN_XMLNODE *n;
1186  int rv;
1187  const char *prefix;
1188  const char *styp;
1189 
1190  prefix=get_struct_property(node, "prefix", 0);
1191  if (!prefix) {
1192  DBG_ERROR(0, "No prefix in struct");
1193  return -1;
1194  }
1195  styp=get_struct_property(node, "id", 0);
1196  if (!styp) {
1197  DBG_ERROR(0, "No id in struct");
1198  return -1;
1199  }
1200  n=GWEN_XMLNode_GetFirstTag(node);
1201  while (n) {
1203  if (strcasecmp(GWEN_XMLNode_GetData(n), "group")==0) {
1204  rv=write_code_setget_c(args, n, sio);
1205  if (rv) {
1206  DBG_ERROR(0, "Error in setget");
1207  return rv;
1208  }
1209  }
1210  else if (strcasecmp(GWEN_XMLNode_GetData(n), "elem")==0) {
1211  int isPtr;
1212  const char *typ;
1213  const char *name;
1214  const char *mode;
1215  GWEN_XMLNODE *tnode;
1216  const char *tmode;
1217  int isConst;
1218  int doCopy;
1219 
1220  GWEN_SyncIo_WriteLine(sio, "");
1221  GWEN_SyncIo_WriteLine(sio, "");
1222 
1223  name=GWEN_XMLNode_GetProperty(n, "name", 0);
1224  if (!name) {
1225  DBG_ERROR(0, "No name for element");
1226  return -1;
1227  }
1228 
1229  typ=GWEN_XMLNode_GetProperty(n, "type", 0);
1230  if (!typ) {
1231  DBG_ERROR(0, "No type for element");
1232  return -1;
1233  }
1234 
1235  isPtr=atoi(get_property(n, "ptr", "0"));
1236  isConst=atoi(get_property(n, "const", "1"));
1237  doCopy=atoi(get_property(n, "copy", "1"));
1238  mode=GWEN_XMLNode_GetProperty(n, "mode", "single");
1239 
1240  tnode=get_typedef(node, typ);
1241  if (tnode)
1242  tmode=GWEN_XMLNode_GetProperty(tnode, "mode", "single");
1243  else
1244  tmode=mode;
1245 
1246  if (isPtr &&
1247  (/*strcasecmp(mode, "single")==0 ||*/ isConst)) {
1248  GWEN_SyncIo_WriteString(sio, "const ");
1249  }
1250  if (strcasecmp(tmode, "enum")!=0)
1251  GWEN_SyncIo_WriteString(sio, typ);
1252  else {
1253  GWEN_BUFFER *tid;
1254  const char *s;
1255 
1256  tid=GWEN_Buffer_new(0, 64, 0, 1);
1257  s=get_struct_property(node, "id", 0);
1258  assert(s);
1259  GWEN_Buffer_AppendString(tid, s);
1260  GWEN_Buffer_AppendString(tid, "_");
1261  GWEN_Buffer_AppendString(tid, typ);
1263  GWEN_Buffer_free(tid);
1264  }
1265  if (isPtr) {
1266  GWEN_SyncIo_WriteString(sio, " *");
1267  }
1268  else {
1269  GWEN_SyncIo_WriteString(sio, " ");
1270  }
1271  GWEN_SyncIo_WriteString(sio, prefix);
1272  GWEN_SyncIo_WriteString(sio, "_Get");
1273  GWEN_SyncIo_WriteChar(sio, toupper(*name));
1274  GWEN_SyncIo_WriteString(sio, name+1);
1275  GWEN_SyncIo_WriteString(sio, "(const ");
1276  GWEN_SyncIo_WriteString(sio, styp);
1277  GWEN_SyncIo_WriteLine(sio, " *st) {");
1278 
1279  GWEN_SyncIo_WriteLine(sio, " assert(st);");
1280 
1281  GWEN_SyncIo_WriteString(sio, " return st->");
1282  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1283  GWEN_SyncIo_WriteString(sio, name+1);
1284  GWEN_SyncIo_WriteLine(sio, ";");
1285  GWEN_SyncIo_WriteLine(sio, "}");
1286  GWEN_SyncIo_WriteLine(sio, "");
1287  GWEN_SyncIo_WriteLine(sio, "");
1288 
1289  /* write setter */
1290  GWEN_SyncIo_WriteString(sio, "void ");
1291  GWEN_SyncIo_WriteString(sio, prefix);
1292  GWEN_SyncIo_WriteString(sio, "_Set");
1293  GWEN_SyncIo_WriteChar(sio, toupper(*name));;
1294  GWEN_SyncIo_WriteString(sio, name+1);
1295  GWEN_SyncIo_WriteString(sio, "(");
1296  GWEN_SyncIo_WriteString(sio, styp);
1297  GWEN_SyncIo_WriteString(sio, " *st, ");
1298  if (isPtr && isConst) {
1299  GWEN_SyncIo_WriteString(sio, "const ");
1300  }
1301  if (strcasecmp(tmode, "enum")!=0)
1302  GWEN_SyncIo_WriteString(sio, typ);
1303  else {
1304  GWEN_BUFFER *tid;
1305  const char *s;
1306 
1307  tid=GWEN_Buffer_new(0, 64, 0, 1);
1308  s=get_struct_property(node, "id", 0);
1309  assert(s);
1310  GWEN_Buffer_AppendString(tid, s);
1311  GWEN_Buffer_AppendString(tid, "_");
1312  GWEN_Buffer_AppendString(tid, typ);
1314  GWEN_Buffer_free(tid);
1315  }
1316  if (isPtr) {
1317  GWEN_SyncIo_WriteString(sio, " *");
1318  }
1319  else {
1320  GWEN_SyncIo_WriteString(sio, " ");
1321  }
1322  GWEN_SyncIo_WriteLine(sio, "d) {");
1323  GWEN_SyncIo_WriteLine(sio, " assert(st);");
1324 
1325  if (isPtr) {
1326  /* free old pointer if any */
1327  rv=write_code_freeElem_c(args, n, sio);
1328  if (rv)
1329  return rv;
1330 
1331  /* copy argument if any */
1332  if (strcasecmp(mode, "single")==0) {
1333  if (strcasecmp(typ, "char")==0)
1334  GWEN_SyncIo_WriteLine(sio, " if (d && *d)");
1335  else
1336  GWEN_SyncIo_WriteLine(sio, " if (d)");
1337 
1338  GWEN_SyncIo_WriteString(sio, " st->");
1339  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1340  GWEN_SyncIo_WriteString(sio, name+1);
1341  GWEN_SyncIo_WriteString(sio, "=");
1342 
1343  if (doCopy) {
1344  rv=write_code_dupArg_c(args, n, sio, "d");
1345  if (rv)
1346  return rv;
1347  }
1348  else {
1349  GWEN_SyncIo_WriteLine(sio, "d;");
1350  }
1351  }
1352  else {
1353  if (doCopy) {
1354  rv=write_code_dupList_c(args, n, sio, "d");
1355  if (rv)
1356  return rv;
1357  }
1358  else {
1359  if (isConst) {
1360  DBG_ERROR(0, "Properties: CONST but not COPY");
1361  return -1;
1362  }
1363  GWEN_SyncIo_WriteString(sio, " st->");
1364  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1365  GWEN_SyncIo_WriteString(sio, name+1);
1366  GWEN_SyncIo_WriteLine(sio, "=d;");
1367  }
1368  }
1369  GWEN_SyncIo_WriteLine(sio, " else");
1370  GWEN_SyncIo_WriteString(sio, " st->");
1371  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1372  GWEN_SyncIo_WriteString(sio, name+1);
1373  GWEN_SyncIo_WriteLine(sio, "=0;");
1374  }
1375  else {
1376  GWEN_SyncIo_WriteString(sio, " st->");
1377  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1378  GWEN_SyncIo_WriteString(sio, name+1);
1379  GWEN_SyncIo_WriteLine(sio, "=d;");
1380  }
1381  GWEN_SyncIo_WriteLine(sio, " st->_modified=1;");
1382  GWEN_SyncIo_WriteLine(sio, "}");
1383  GWEN_SyncIo_WriteLine(sio, "");
1384  GWEN_SyncIo_WriteLine(sio, "");
1385 
1386  if (strcasecmp(typ, "GWEN_STRINGLIST")==0) {
1387  /* special functions for string lists */
1388  GWEN_SyncIo_WriteLine(sio, "");
1389  GWEN_SyncIo_WriteLine(sio, "");
1390  GWEN_SyncIo_WriteString(sio, "void ");
1391  GWEN_SyncIo_WriteString(sio, prefix);
1392  GWEN_SyncIo_WriteString(sio, "_Add");
1393  GWEN_SyncIo_WriteChar(sio, toupper(*name));
1394  GWEN_SyncIo_WriteString(sio, name+1);
1395  GWEN_SyncIo_WriteString(sio, "(");
1396  GWEN_SyncIo_WriteString(sio, styp);
1397  GWEN_SyncIo_WriteLine(sio, " *st, const char *d, int chk){");
1398  GWEN_SyncIo_WriteLine(sio, " assert(st);");
1399  GWEN_SyncIo_WriteLine(sio, " assert(d);");
1400  GWEN_SyncIo_WriteString(sio, " if (GWEN_StringList_AppendString(st->");
1401  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1402  GWEN_SyncIo_WriteString(sio, name+1);
1403  GWEN_SyncIo_WriteLine(sio, ", d, 0, chk))");
1404  GWEN_SyncIo_WriteLine(sio, " st->_modified=1;");
1405  GWEN_SyncIo_WriteLine(sio, "}");
1406  GWEN_SyncIo_WriteLine(sio, "");
1407  GWEN_SyncIo_WriteLine(sio, "");
1408 
1409  /* remove */
1410  GWEN_SyncIo_WriteString(sio, "void ");
1411  GWEN_SyncIo_WriteString(sio, prefix);
1412  GWEN_SyncIo_WriteString(sio, "_Remove");
1413  GWEN_SyncIo_WriteChar(sio, toupper(*name));
1414  GWEN_SyncIo_WriteString(sio, name+1);
1415  GWEN_SyncIo_WriteString(sio, "(");
1416  GWEN_SyncIo_WriteString(sio, styp);
1417  GWEN_SyncIo_WriteLine(sio, " *st, const char *d) {");
1418  GWEN_SyncIo_WriteString(sio, " if (GWEN_StringList_RemoveString(st->");
1419  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1420  GWEN_SyncIo_WriteString(sio, name+1);
1421  GWEN_SyncIo_WriteLine(sio, ", d))");
1422  GWEN_SyncIo_WriteLine(sio, " st->_modified=1;");
1423  GWEN_SyncIo_WriteLine(sio, "}");
1424  GWEN_SyncIo_WriteLine(sio, "");
1425  GWEN_SyncIo_WriteLine(sio, "");
1426 
1427  /* clear */
1428  GWEN_SyncIo_WriteString(sio, "void ");
1429  GWEN_SyncIo_WriteString(sio, prefix);
1430  GWEN_SyncIo_WriteString(sio, "_Clear");
1431  GWEN_SyncIo_WriteChar(sio, toupper(*name));
1432  GWEN_SyncIo_WriteString(sio, name+1);
1433  GWEN_SyncIo_WriteString(sio, "(");
1434  GWEN_SyncIo_WriteString(sio, styp);
1435  GWEN_SyncIo_WriteLine(sio, " *st) {");
1436  GWEN_SyncIo_WriteString(sio, " if (GWEN_StringList_Count(st->");
1437  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1438  GWEN_SyncIo_WriteString(sio, name+1);
1439  GWEN_SyncIo_WriteLine(sio, ")) {");
1440  GWEN_SyncIo_WriteString(sio, " GWEN_StringList_Clear(st->");
1441  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1442  GWEN_SyncIo_WriteString(sio, name+1);
1443  GWEN_SyncIo_WriteLine(sio, ");");
1444  GWEN_SyncIo_WriteLine(sio, " st->_modified=1;");
1445  GWEN_SyncIo_WriteLine(sio, " }");
1446  GWEN_SyncIo_WriteLine(sio, "}");
1447  GWEN_SyncIo_WriteLine(sio, "");
1448  GWEN_SyncIo_WriteLine(sio, "");
1449 
1450  /* has */
1451  GWEN_SyncIo_WriteString(sio, "int ");
1452  GWEN_SyncIo_WriteString(sio, prefix);
1453  GWEN_SyncIo_WriteString(sio, "_Has");
1454  GWEN_SyncIo_WriteChar(sio, toupper(*name));
1455  GWEN_SyncIo_WriteString(sio, name+1);
1456  GWEN_SyncIo_WriteString(sio, "(const ");
1457  GWEN_SyncIo_WriteString(sio, styp);
1458  GWEN_SyncIo_WriteLine(sio, " *st, const char *d) {");
1459  GWEN_SyncIo_WriteString(sio, " return GWEN_StringList_HasString(st->");
1460  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1461  GWEN_SyncIo_WriteString(sio, name+1);
1462  GWEN_SyncIo_WriteLine(sio, ", d);");
1463  GWEN_SyncIo_WriteLine(sio, "}");
1464  GWEN_SyncIo_WriteLine(sio, "");
1465  GWEN_SyncIo_WriteLine(sio, "");
1466  }
1467  }
1468  else if (strcasecmp(GWEN_XMLNode_GetData(n), "func")==0) {
1469  const char *typ;
1470  const char *name;
1471  const char *rettype;
1472  const char *defret;
1473  GWEN_XMLNODE *anode;
1474  int isPtr;
1475  int isVoid;
1476  int idx;
1477 
1478  name=GWEN_XMLNode_GetProperty(n, "name", 0);
1479  if (!name) {
1480  DBG_ERROR(0, "No name for element");
1481  return -1;
1482  }
1483 
1484  typ=GWEN_XMLNode_GetProperty(n, "type", 0);
1485  if (!typ) {
1486  DBG_ERROR(0, "No type for element");
1487  return -1;
1488  }
1489 
1490  rettype=GWEN_XMLNode_GetProperty(n, "return", 0);
1491  if (!rettype) {
1492  DBG_ERROR(0, "No return type for function");
1493  return -1;
1494  }
1495 
1496  isPtr=atoi(get_property(n, "ptr", "0"));
1497  isVoid=(!isPtr && strcasecmp(rettype, "void")==0);
1498 
1499  defret=GWEN_XMLNode_GetProperty(n, "default", 0);
1500  if (!defret && !isVoid) {
1501  DBG_ERROR(0, "No default return value for function %s", name);
1502  return -1;
1503  }
1504 
1505  /* getter */
1506  GWEN_SyncIo_WriteString(sio, styp);
1507  GWEN_SyncIo_WriteString(sio, "_");
1508  GWEN_SyncIo_WriteString(sio, typ);
1509  GWEN_SyncIo_WriteString(sio, " ");
1510  GWEN_SyncIo_WriteString(sio, prefix);
1511  GWEN_SyncIo_WriteString(sio, "_Get");
1512  GWEN_SyncIo_WriteChar(sio, toupper(*name));
1513  GWEN_SyncIo_WriteString(sio, name+1);
1514  GWEN_SyncIo_WriteString(sio, "(const ");
1515  GWEN_SyncIo_WriteString(sio, styp);
1516  GWEN_SyncIo_WriteLine(sio, " *st) {");
1517  GWEN_SyncIo_WriteLine(sio, " assert(st);");
1518  GWEN_SyncIo_WriteString(sio, " return st->");
1519  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1520  GWEN_SyncIo_WriteString(sio, name+1);
1521  GWEN_SyncIo_WriteLine(sio, ";");
1522  GWEN_SyncIo_WriteLine(sio, "}");
1523  GWEN_SyncIo_WriteLine(sio, "");
1524  GWEN_SyncIo_WriteLine(sio, "");
1525 
1526  /* setter */
1527  GWEN_SyncIo_WriteString(sio, "void ");
1528  GWEN_SyncIo_WriteString(sio, prefix);
1529  GWEN_SyncIo_WriteString(sio, "_Set");
1530  GWEN_SyncIo_WriteChar(sio, toupper(*name));
1531  GWEN_SyncIo_WriteString(sio, name+1);
1532  GWEN_SyncIo_WriteString(sio, "(");
1533  GWEN_SyncIo_WriteString(sio, styp);
1534  GWEN_SyncIo_WriteString(sio, " *st, ");
1535  GWEN_SyncIo_WriteString(sio, styp);
1536  GWEN_SyncIo_WriteString(sio, "_");
1537  GWEN_SyncIo_WriteString(sio, typ);
1538  GWEN_SyncIo_WriteLine(sio, " d) {");
1539  GWEN_SyncIo_WriteLine(sio, " assert(st);");
1540  GWEN_SyncIo_WriteString(sio, " st->");
1541  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1542  GWEN_SyncIo_WriteString(sio, name+1);
1543  GWEN_SyncIo_WriteLine(sio, "=d;");
1544  GWEN_SyncIo_WriteLine(sio, "}");
1545  GWEN_SyncIo_WriteLine(sio, "");
1546  GWEN_SyncIo_WriteLine(sio, "");
1547 
1548  /* function call */
1549  GWEN_SyncIo_WriteString(sio, rettype);
1550  if (isPtr)
1551  GWEN_SyncIo_WriteString(sio, "*");
1552  GWEN_SyncIo_WriteString(sio, " ");
1553  GWEN_SyncIo_WriteString(sio, prefix);
1554  GWEN_SyncIo_WriteString(sio, "_");
1555  GWEN_SyncIo_WriteChar(sio, toupper(*name));
1556  GWEN_SyncIo_WriteString(sio, name+1);
1557  GWEN_SyncIo_WriteString(sio, "(");
1558 
1559  GWEN_SyncIo_WriteString(sio, styp);
1560  GWEN_SyncIo_WriteString(sio, " *st");
1561 
1562  anode=GWEN_XMLNode_FindFirstTag(n, "arg", 0, 0);
1563  idx=0;
1564  while (anode) {
1565  const char *aname;
1566  const char *atype;
1567  int aisPtr;
1568 
1569  GWEN_SyncIo_WriteString(sio, ", ");
1570 
1571  aisPtr=atoi(GWEN_XMLNode_GetProperty(anode, "ptr", "0"));
1572  aname=GWEN_XMLNode_GetProperty(anode, "name", 0);
1573  if (!aname || !*aname) {
1574  DBG_ERROR(0, "No name for argument %d in function %s", idx, name);
1575  return -1;
1576  }
1577  atype=GWEN_XMLNode_GetProperty(anode, "type", 0);
1578  if (!atype || !*atype) {
1579  DBG_ERROR(0, "No type for argument %d in function %s", idx, name);
1580  return -1;
1581  }
1582 
1583  GWEN_SyncIo_WriteString(sio, atype);
1584  if (aisPtr)
1585  GWEN_SyncIo_WriteString(sio, "*");
1586  GWEN_SyncIo_WriteString(sio, " ");
1587  GWEN_SyncIo_WriteString(sio, aname);
1588 
1589  idx++;
1590  anode=GWEN_XMLNode_FindNextTag(anode, "arg", 0, 0);
1591  }
1592 
1593  GWEN_SyncIo_WriteLine(sio, ") {");
1594  GWEN_SyncIo_WriteLine(sio, " assert(st);");
1595  GWEN_SyncIo_WriteString(sio, " if (st->");
1596  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1597  GWEN_SyncIo_WriteString(sio, name+1);
1598  GWEN_SyncIo_WriteLine(sio, ")");
1599  GWEN_SyncIo_WriteString(sio, " ");
1600  if (!isVoid)
1601  GWEN_SyncIo_WriteString(sio, "return ");
1602  GWEN_SyncIo_WriteString(sio, "st->");
1603  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1604  GWEN_SyncIo_WriteString(sio, name+1);
1605  GWEN_SyncIo_WriteString(sio, "(st");
1606 
1607  anode=GWEN_XMLNode_FindFirstTag(n, "arg", 0, 0);
1608  while (anode) {
1609  const char *aname;
1610 
1611  GWEN_SyncIo_WriteString(sio, ", ");
1612  aname=GWEN_XMLNode_GetProperty(anode, "name", 0);
1613  GWEN_SyncIo_WriteString(sio, aname);
1614  anode=GWEN_XMLNode_FindNextTag(anode, "arg", 0, 0);
1615  }
1616  GWEN_SyncIo_WriteLine(sio, ");");
1617  if (!isVoid) {
1618  GWEN_SyncIo_WriteString(sio, "return ");
1619  GWEN_SyncIo_WriteString(sio, defret);
1620  GWEN_SyncIo_WriteLine(sio, ";");
1621  }
1622  GWEN_SyncIo_WriteLine(sio, "}");
1623  GWEN_SyncIo_WriteLine(sio, "");
1624  GWEN_SyncIo_WriteLine(sio, "");
1625  }
1626  }
1628  }
1629  return 0;
1630 }
1631 
1632 
1633 
1634 
1635 
1636 
1638  GWEN_SYNCIO *sio,
1639  const char *listName)
1640 {
1641  int isPtr;
1642  const char *typ;
1643  const char *name;
1644  const char *mode;
1645 
1646  name=GWEN_XMLNode_GetProperty(n, "name", 0);
1647  if (!name) {
1648  DBG_ERROR(0, "No name for element");
1649  return -1;
1650  }
1651 
1652  typ=GWEN_XMLNode_GetProperty(n, "type", 0);
1653  if (!typ) {
1654  DBG_ERROR(0, "No type for element");
1655  return -1;
1656  }
1657 
1658  isPtr=atoi(get_property(n, "ptr", "0"));
1659  mode=GWEN_XMLNode_GetProperty(n, "mode", "single");
1660  if (strcasecmp(mode, "single")!=0)
1661  /* lists are always pointers */
1662  isPtr=1;
1663 
1664  if (isPtr) {
1665  if (strcasecmp(mode, "list")==0) {
1666  const char *prefix;
1667  const char *elemType;
1668  const char *elemPrefix;
1669  GWEN_XMLNODE *elemNode;
1670 
1671  prefix=get_struct_property(n, "prefix", 0);
1672  assert(prefix);
1673 
1674  /* create list code */
1675  elemType=GWEN_XMLNode_GetProperty(n, "elemType", 0);
1676  if (!elemType) {
1677  DBG_ERROR(0, "No \"type\" for list type \"%s\"", typ);
1678  return -1;
1679  }
1680 
1681  elemNode=get_typedef(n, elemType);
1682  if (!elemNode) {
1683  DBG_ERROR(0, "Undefined type %s", elemType);
1684  return -1;
1685  }
1686  elemPrefix=GWEN_XMLNode_GetProperty(elemNode, "prefix", 0);
1687  if (!elemPrefix) {
1688  DBG_ERROR(0, "No \"prefix\" for type \"%s\" (within %s)",
1689  elemType, typ);
1690  return -1;
1691  }
1692 
1693  /* actually generate the code */
1694  GWEN_SyncIo_WriteString(sio, " if (");
1695  GWEN_SyncIo_WriteString(sio, listName);
1696  GWEN_SyncIo_WriteLine(sio, ") {");
1697 
1698  /* ELEMTYPE *e; */
1699  GWEN_SyncIo_WriteString(sio, " ");
1700  GWEN_SyncIo_WriteString(sio, elemType);
1701  GWEN_SyncIo_WriteLine(sio, " *e;");
1702  GWEN_SyncIo_WriteLine(sio, "");
1703 
1704  /* st->LIST=LIST_new() */
1705  GWEN_SyncIo_WriteString(sio, " ");
1706  GWEN_SyncIo_WriteString(sio, "st->");
1707  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1708  GWEN_SyncIo_WriteString(sio, name+1);
1709  GWEN_SyncIo_WriteString(sio, "=");
1710  GWEN_SyncIo_WriteString(sio, elemPrefix);
1711  GWEN_SyncIo_WriteLine(sio, "_List_new();");
1712 
1713 
1714  /* e=ElemType_List_First */
1715  GWEN_SyncIo_WriteString(sio, " e=");
1716  GWEN_SyncIo_WriteString(sio, elemPrefix);
1717  GWEN_SyncIo_WriteString(sio, "_List_First(");
1718  GWEN_SyncIo_WriteString(sio, listName);
1719  GWEN_SyncIo_WriteLine(sio, ");");
1720 
1721  /* while (e) ; */
1722  GWEN_SyncIo_WriteLine(sio, " while(e) {");
1723 
1724  /* ELEMTYPE *ne; */
1725  GWEN_SyncIo_WriteString(sio, " ");
1726  GWEN_SyncIo_WriteString(sio, elemType);
1727  GWEN_SyncIo_WriteLine(sio, " *ne;");
1728  GWEN_SyncIo_WriteLine(sio, "");
1729 
1730  /* ne=ElemType_dup; assert(ne); */
1731  GWEN_SyncIo_WriteString(sio, " ne=");
1732  GWEN_SyncIo_WriteString(sio, elemPrefix);
1733  GWEN_SyncIo_WriteLine(sio, "_dup(e);");
1734  GWEN_SyncIo_WriteLine(sio, " assert(ne);");
1735 
1736  /* ElemType_List_Add(ne, st->NAME); */
1737  GWEN_SyncIo_WriteString(sio, " ");
1738  GWEN_SyncIo_WriteString(sio, elemPrefix);
1739  GWEN_SyncIo_WriteString(sio, "_List_Add(ne, st->");
1740  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1741  GWEN_SyncIo_WriteString(sio, name+1);
1742  GWEN_SyncIo_WriteLine(sio, ");");
1743 
1744  /* e=ElemType_List_Next */
1745  GWEN_SyncIo_WriteString(sio, " e=");
1746  GWEN_SyncIo_WriteString(sio, elemPrefix);
1747  GWEN_SyncIo_WriteLine(sio, "_List_Next(e);");
1748 
1749  GWEN_SyncIo_WriteLine(sio, " } /* while (e) */");
1750 
1751  GWEN_SyncIo_WriteLine(sio, " } /* if LIST */");
1752  }
1753  else if (strcasecmp(mode, "list2")==0) {
1754  const char *prefix;
1755  const char *elemType;
1756  const char *elemPrefix;
1757  GWEN_XMLNODE *elemNode;
1758 
1759  prefix=get_struct_property(n, "prefix", 0);
1760  assert(prefix);
1761 
1762  /* create list code */
1763  elemType=GWEN_XMLNode_GetProperty(n, "elemType", 0);
1764  if (!elemType) {
1765  DBG_ERROR(0, "No \"type\" for list type \"%s\"", typ);
1766  return -1;
1767  }
1768 
1769  elemNode=get_typedef(n, elemType);
1770  if (!elemNode) {
1771  DBG_ERROR(0, "Undefined type %s", elemType);
1772  return -1;
1773  }
1774  elemPrefix=GWEN_XMLNode_GetProperty(elemNode, "prefix", 0);
1775  if (!elemPrefix) {
1776  DBG_ERROR(0, "No \"prefix\" for type \"%s\" (within %s)",
1777  elemType, typ);
1778  return -1;
1779  }
1780 
1781  /* actually generate the code */
1782  GWEN_SyncIo_WriteString(sio, " st->");
1783  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1784  GWEN_SyncIo_WriteString(sio, name+1);
1785  GWEN_SyncIo_WriteString(sio, "=");
1786  GWEN_SyncIo_WriteString(sio, elemPrefix);
1787  GWEN_SyncIo_WriteLine(sio, "_List2_new();");
1788 
1789  GWEN_SyncIo_WriteString(sio, " if (");
1790  GWEN_SyncIo_WriteString(sio, listName);
1791  GWEN_SyncIo_WriteLine(sio, ") {");
1792 
1793  GWEN_SyncIo_WriteString(sio, " ");
1794  GWEN_SyncIo_WriteString(sio, elemType);
1795  GWEN_SyncIo_WriteLine(sio, "_LIST2_ITERATOR *it;");
1796  GWEN_SyncIo_WriteLine(sio, "");
1797 
1798  /* it=ElemType_List2_First */
1799  GWEN_SyncIo_WriteString(sio, " it=");
1800  GWEN_SyncIo_WriteString(sio, elemPrefix);
1801  GWEN_SyncIo_WriteString(sio, "_List2_First(");
1802  GWEN_SyncIo_WriteString(sio, listName);
1803  GWEN_SyncIo_WriteLine(sio, ");");
1804 
1805  /* if (it) */
1806  GWEN_SyncIo_WriteLine(sio, " if (it) {");
1807 
1808  /* ELEMTYPE *e; */
1809  GWEN_SyncIo_WriteString(sio, " ");
1810  GWEN_SyncIo_WriteString(sio, elemType);
1811  GWEN_SyncIo_WriteLine(sio, " *e;");
1812  GWEN_SyncIo_WriteLine(sio, "");
1813 
1814  /* e=ElemType_List2Iterator_Data */
1815  GWEN_SyncIo_WriteString(sio, " e=");
1816  GWEN_SyncIo_WriteString(sio, elemPrefix);
1817  GWEN_SyncIo_WriteLine(sio, "_List2Iterator_Data(it);");
1818  GWEN_SyncIo_WriteLine(sio, " assert(e);");
1819 
1820  /* while (e) ; */
1821  GWEN_SyncIo_WriteLine(sio, " while(e) {");
1822 
1823  /* ELEMTYPE *ne; */
1824  GWEN_SyncIo_WriteString(sio, " ");
1825  GWEN_SyncIo_WriteString(sio, elemType);
1826  GWEN_SyncIo_WriteLine(sio, " *ne;");
1827  GWEN_SyncIo_WriteLine(sio, "");
1828 
1829  /* ne=ElemType_dup; assert(ne); */
1830  GWEN_SyncIo_WriteString(sio, " ne=");
1831  GWEN_SyncIo_WriteString(sio, elemPrefix);
1832  GWEN_SyncIo_WriteLine(sio, "_dup(e);");
1833  GWEN_SyncIo_WriteLine(sio, " assert(ne);");
1834 
1835  /* ElemType_List2_PushBack(st->NAME, ne); */
1836  GWEN_SyncIo_WriteString(sio, " ");
1837  GWEN_SyncIo_WriteString(sio, elemPrefix);
1838  GWEN_SyncIo_WriteString(sio, "_List2_PushBack(st->");
1839  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1840  GWEN_SyncIo_WriteString(sio, name+1);
1841  GWEN_SyncIo_WriteLine(sio, ", ne);");
1842 
1843  /* e=ElemType_List2Iterator_Next */
1844  GWEN_SyncIo_WriteString(sio, " e=");
1845  GWEN_SyncIo_WriteString(sio, elemPrefix);
1846  GWEN_SyncIo_WriteLine(sio, "_List2Iterator_Next(it);");
1847 
1848  GWEN_SyncIo_WriteLine(sio, " } /* while (e) */");
1849 
1850  /* ElemType_List2Iterator_free */
1851  GWEN_SyncIo_WriteString(sio, " ");
1852  GWEN_SyncIo_WriteString(sio, elemPrefix);
1853  GWEN_SyncIo_WriteLine(sio, "_List2Iterator_free(it);");
1854 
1855  GWEN_SyncIo_WriteLine(sio, " } /* if (it) */");
1856 
1857  GWEN_SyncIo_WriteLine(sio, " } /* LIST */");
1858  }
1859  }
1860 
1861  return 0;
1862 }
1863 
1864 
1865 
1867  GWEN_SYNCIO *sio)
1868 {
1869  GWEN_XMLNODE *n;
1870  int rv;
1871  const char *prefix;
1872  const char *styp;
1873 
1874  prefix=get_struct_property(node, "prefix", 0);
1875  if (!prefix) {
1876  DBG_ERROR(0, "No prefix in struct");
1877  return -1;
1878  }
1879  styp=get_struct_property(node, "id", 0);
1880  if (!styp) {
1881  DBG_ERROR(0, "No id in struct");
1882  return -1;
1883  }
1884 
1885  n=GWEN_XMLNode_GetFirstTag(node);
1886  while (n) {
1888  if (strcasecmp(GWEN_XMLNode_GetData(n), "group")==0) {
1889  rv=write_code_duprec_c(args, n, sio);
1890  if (rv) {
1891  DBG_ERROR(0, "Error in dup");
1892  return rv;
1893  }
1894  }
1895  else if (strcasecmp(GWEN_XMLNode_GetData(n), "elem")==0) {
1896  int isPtr;
1897  const char *typ;
1898  const char *name;
1899  const char *mode;
1900  int doCopy;
1901  int takeOver;
1902 
1903  name=GWEN_XMLNode_GetProperty(n, "name", 0);
1904  if (!name) {
1905  DBG_ERROR(0, "No name for element");
1906  return -1;
1907  }
1908 
1909  typ=GWEN_XMLNode_GetProperty(n, "type", 0);
1910  if (!typ) {
1911  DBG_ERROR(0, "No type for element");
1912  return -1;
1913  }
1914 
1915  isPtr=atoi(get_property(n, "ptr", "0"));
1916  doCopy=atoi(get_property(n, "copy", "1"));
1917  takeOver=atoi(get_property(n, "takeOver", "0"));
1918  mode=GWEN_XMLNode_GetProperty(n, "mode", "single");
1919  if (strcasecmp(mode, "single")!=0)
1920  /* lists are always pointers */
1921  isPtr=1;
1922 
1923  if (isPtr) {
1924  GWEN_BUFFER *pbuf;
1925  const char *fname;
1926 
1927  fname=get_function_name(n, "dup");
1928 
1929  pbuf=GWEN_Buffer_new(0, 256, 0, 1);
1930  GWEN_Buffer_AppendString(pbuf, "d->");
1931  GWEN_Buffer_AppendByte(pbuf, tolower(*name));
1932  GWEN_Buffer_AppendString(pbuf, name+1);
1933 
1934  if (strcasecmp(mode, "single")!=0 && !fname) {
1935  rv=write_code_dupList_c(args, n, sio, GWEN_Buffer_GetStart(pbuf));
1936  GWEN_Buffer_free(pbuf);
1937  if (rv)
1938  return rv;
1939  }
1940  else {
1941  /* copy argument if any */
1942  GWEN_SyncIo_WriteString(sio, " if (d->");
1943  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1944  GWEN_SyncIo_WriteString(sio, name+1);
1945  GWEN_SyncIo_WriteLine(sio, ")");
1946 
1947  GWEN_SyncIo_WriteString(sio, " st->");
1948  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1949  GWEN_SyncIo_WriteString(sio, name+1);
1950  GWEN_SyncIo_WriteString(sio, "=");
1951  if (doCopy || takeOver) {
1952  rv=write_code_dupArg_c(args, n, sio, GWEN_Buffer_GetStart(pbuf));
1953  GWEN_Buffer_free(pbuf);
1954  if (rv)
1955  return rv;
1956  }
1957  else {
1959  GWEN_Buffer_free(pbuf);
1960  GWEN_SyncIo_WriteString(sio, ";");
1961  }
1962  }
1963  }
1964  else {
1965  GWEN_SyncIo_WriteString(sio, " st->");
1966  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1967  GWEN_SyncIo_WriteString(sio, name+1);
1968  GWEN_SyncIo_WriteString(sio, "=d->");
1969  GWEN_SyncIo_WriteChar(sio, tolower(*name));
1970  GWEN_SyncIo_WriteString(sio, name+1);
1971  GWEN_SyncIo_WriteLine(sio, ";");
1972  }
1973  }
1974  }
1976  }
1977  return 0;
1978 }
1979 
1980 
1981 
1983  GWEN_SYNCIO *sio)
1984 {
1985  int rv;
1986  const char *prefix;
1987  const char *styp;
1988  const char *dupAcc;
1989  const char *dupName;
1990 
1991  prefix=get_struct_property(node, "prefix", 0);
1992  if (!prefix) {
1993  DBG_ERROR(0, "No prefix in struct");
1994  return -1;
1995  }
1996  styp=get_struct_property(node, "id", 0);
1997  if (!styp) {
1998  DBG_ERROR(0, "No id in struct");
1999  return -1;
2000  }
2001  dupAcc=get_struct_property(node, "dup-access",
2002  get_struct_property(node, "access", 0));
2003  dupName=get_struct_property(node, "dup-name", 0);
2004 
2005  if (dupAcc && strcasecmp(dupAcc, "none")!=0) {
2006  GWEN_SyncIo_WriteString(sio, styp);
2007  GWEN_SyncIo_WriteString(sio, " *");
2008  GWEN_SyncIo_WriteString(sio, prefix);
2009  if (dupName)
2010  GWEN_SyncIo_WriteString(sio, dupName);
2011  else
2012  GWEN_SyncIo_WriteString(sio, "_dup");
2013  GWEN_SyncIo_WriteString(sio, "(const ");
2014  GWEN_SyncIo_WriteString(sio, styp);
2015  GWEN_SyncIo_WriteLine(sio, " *d) {");
2016 
2017  GWEN_SyncIo_WriteString(sio, " ");
2018  GWEN_SyncIo_WriteString(sio, styp);
2019  GWEN_SyncIo_WriteLine(sio, " *st;");
2020  GWEN_SyncIo_WriteLine(sio, "");
2021 
2022  GWEN_SyncIo_WriteLine(sio, " assert(d);");
2023 
2024  GWEN_SyncIo_WriteString(sio, " st=");
2025  GWEN_SyncIo_WriteString(sio, prefix);
2026  GWEN_SyncIo_WriteLine(sio, "_new();");
2027 
2028  rv=write_code_duprec_c(args, node, sio);
2029  if (rv) {
2030  DBG_ERROR(0, "Error in dup");
2031  return rv;
2032  }
2033  GWEN_SyncIo_WriteLine(sio, " return st;");
2034  GWEN_SyncIo_WriteLine(sio, "}");
2035  }
2036  return 0;
2037 }
2038 
2039 
2040 
2042  GWEN_SYNCIO *sio)
2043 {
2044  GWEN_XMLNODE *n;
2045  int rv;
2046  const char *prefix;
2047  const char *styp;
2048 
2049  prefix=get_struct_property(node, "prefix", 0);
2050  if (!prefix) {
2051  DBG_ERROR(0, "No prefix in struct");
2052  return -1;
2053  }
2054  styp=get_struct_property(node, "id", 0);
2055  if (!styp) {
2056  DBG_ERROR(0, "No id in struct");
2057  return -1;
2058  }
2059 
2060  n=GWEN_XMLNode_GetFirstTag(node);
2061  while (n) {
2063  if (strcasecmp(GWEN_XMLNode_GetData(n), "group")==0) {
2064  rv=write_code_todbrec_c(args, n, sio);
2065  if (rv) {
2066  DBG_ERROR(0, "Error in todb");
2067  return rv;
2068  }
2069  }
2070  else if (strcasecmp(GWEN_XMLNode_GetData(n), "elem")==0) {
2071  int isVolatile;
2072 
2073  isVolatile=atoi(GWEN_XMLNode_GetProperty(n, "volatile", "0"));
2074  if (isVolatile==0) {
2075  int isPtr;
2076  const char *typ;
2077  const char *name;
2078 
2079  name=GWEN_XMLNode_GetProperty(n, "name", 0);
2080  if (!name) {
2081  DBG_ERROR(0, "No name for element");
2082  return -1;
2083  }
2084 
2085  typ=GWEN_XMLNode_GetProperty(n, "type", 0);
2086  if (!typ) {
2087  DBG_ERROR(0, "No type for element");
2088  return -1;
2089  }
2090 
2091  isPtr=atoi(get_property(n, "ptr", "0"));
2092  if (isPtr) {
2093  GWEN_SyncIo_WriteString(sio, " if (st->");
2094  GWEN_SyncIo_WriteChar(sio, tolower(*name));
2095  GWEN_SyncIo_WriteString(sio, name+1);
2096  GWEN_SyncIo_WriteLine(sio, ")");
2097  }
2098 
2099  rv=write_code_todbArg_c(args, n, sio);
2100  if (rv) {
2101  DBG_ERROR(0, "Error in toDb function");
2102  return rv;
2103  }
2104  }
2105  }
2106  }
2108  }
2109  return 0;
2110 }
2111 
2112 
2113 
2115  GWEN_SYNCIO *sio)
2116 {
2117  int rv;
2118  const char *prefix;
2119  const char *styp;
2120 
2121  prefix=get_struct_property(node, "prefix", 0);
2122  if (!prefix) {
2123  DBG_ERROR(0, "No prefix in struct");
2124  return -1;
2125  }
2126  styp=get_struct_property(node, "id", 0);
2127  if (!styp) {
2128  DBG_ERROR(0, "No id in struct");
2129  return -1;
2130  }
2131 
2132  GWEN_SyncIo_WriteString(sio, "int ");
2133  GWEN_SyncIo_WriteString(sio, prefix);
2134  GWEN_SyncIo_WriteString(sio, "_toDb(const ");
2135  GWEN_SyncIo_WriteString(sio, styp);
2136  GWEN_SyncIo_WriteLine(sio, " *st, GWEN_DB_NODE *db) {");
2137 
2138 
2139  GWEN_SyncIo_WriteLine(sio, " assert(st);");
2140  GWEN_SyncIo_WriteLine(sio, " assert(db);");
2141 
2142  rv=write_code_todbrec_c(args, node, sio);
2143  if (rv) {
2144  DBG_ERROR(0, "Error in todb");
2145  return rv;
2146  }
2147  GWEN_SyncIo_WriteLine(sio, " return 0;");
2148  GWEN_SyncIo_WriteLine(sio, "}");
2149  return 0;
2150 }
2151 
2152 
2153 
2155  GWEN_SYNCIO *sio)
2156 {
2157  GWEN_XMLNODE *n;
2158  int rv;
2159  const char *prefix;
2160  const char *styp;
2161  int isVolatile;
2162 
2163  isVolatile=atoi(GWEN_XMLNode_GetProperty(node, "volatile", "0"));
2164  if (isVolatile)
2165  /* don't save volatile data */
2166  return 0;
2167 
2168  prefix=get_struct_property(node, "prefix", 0);
2169  if (!prefix) {
2170  DBG_ERROR(0, "No prefix in struct");
2171  return -1;
2172  }
2173  styp=get_struct_property(node, "id", 0);
2174  if (!styp) {
2175  DBG_ERROR(0, "No id in struct");
2176  return -1;
2177  }
2178 
2179  n=GWEN_XMLNode_GetFirstTag(node);
2180  while (n) {
2182  if (strcasecmp(GWEN_XMLNode_GetData(n), "group")==0) {
2183  rv=write_code_fromdbrec_c(args, n, sio);
2184  if (rv) {
2185  DBG_ERROR(0, "Error in fromdb");
2186  return rv;
2187  }
2188  }
2189  else if (strcasecmp(GWEN_XMLNode_GetData(n), "elem")==0) {
2190  int isVolatile;
2191 
2192  isVolatile=atoi(GWEN_XMLNode_GetProperty(n, "volatile", "0"));
2193  if (isVolatile==0) {
2194  int isPtr;
2195  const char *typ;
2196  const char *name;
2197  const char *mode;
2198 
2199  name=GWEN_XMLNode_GetProperty(n, "name", 0);
2200  if (!name) {
2201  DBG_ERROR(0, "No name for element");
2202  return -1;
2203  }
2204 
2205  mode=GWEN_XMLNode_GetProperty(n, "mode", "single");
2206 
2207  typ=GWEN_XMLNode_GetProperty(n, "type", 0);
2208  if (!typ) {
2209  DBG_ERROR(0, "No type for element");
2210  return -1;
2211  }
2212 
2213  if (strcasecmp(mode, "list")==0) {
2214  const char *prefix;
2215  const char *elemType;
2216  const char *elemPrefix;
2217  GWEN_XMLNODE *elemNode;
2218 
2219  prefix=get_struct_property(node, "prefix", 0);
2220  assert(prefix);
2221 
2222  /* create list code */
2223  elemType=GWEN_XMLNode_GetProperty(n, "elemType", 0);
2224  if (!elemType) {
2225  DBG_ERROR(0, "No \"type\" for list type \"%s\"", typ);
2226  return -1;
2227  }
2228 
2229  elemNode=get_typedef(n, elemType);
2230  if (!elemNode) {
2231  DBG_ERROR(0, "Undefined type %s", elemType);
2232  return -1;
2233  }
2234  elemPrefix=GWEN_XMLNode_GetProperty(elemNode, "prefix", 0);
2235  if (!elemPrefix) {
2236  DBG_ERROR(0, "No \"prefix\" for type \"%s\" (within %s)",
2237  elemType, typ);
2238  return -1;
2239  }
2240 
2241  /* actually generate the code */
2242  GWEN_SyncIo_WriteString(sio, " st->");
2243  GWEN_SyncIo_WriteChar(sio, tolower(*name));
2244  GWEN_SyncIo_WriteString(sio, name+1);
2245  GWEN_SyncIo_WriteString(sio, "=");
2246  GWEN_SyncIo_WriteString(sio, elemPrefix);
2247  GWEN_SyncIo_WriteLine(sio, "_List_new();");
2248 
2250  " if (1) {/* just for local vars */");
2251  GWEN_SyncIo_WriteLine(sio, " GWEN_DB_NODE *dbT;");
2252  GWEN_SyncIo_WriteString(sio, " ");
2253  GWEN_SyncIo_WriteString(sio, elemType);
2254  GWEN_SyncIo_WriteLine(sio, " *e;");
2255  GWEN_SyncIo_WriteLine(sio, "");
2257  " dbT=GWEN_DB_GetGroup(db, "
2258  "GWEN_PATH_FLAGS_NAMEMUSTEXIST, \"");
2259  GWEN_SyncIo_WriteChar(sio, tolower(*name));
2260  GWEN_SyncIo_WriteString(sio, name+1);
2261  GWEN_SyncIo_WriteLine(sio, "\");");
2262  GWEN_SyncIo_WriteLine(sio, " if (dbT) {");
2263  GWEN_SyncIo_WriteLine(sio, " GWEN_DB_NODE *dbT2;");
2264  GWEN_SyncIo_WriteLine(sio, "");
2265 
2267  " dbT2=GWEN_DB_FindFirstGroup(dbT, \"");
2268  GWEN_SyncIo_WriteString(sio, "element");
2269  GWEN_SyncIo_WriteLine(sio, "\");");
2270 
2271  /* while (e) */
2272  GWEN_SyncIo_WriteLine(sio, " while(dbT2) {");
2273 
2274  /* e=ElemType_fromDb(e) */
2275  GWEN_SyncIo_WriteString(sio, " e=");
2276  GWEN_SyncIo_WriteString(sio, elemPrefix);
2277  GWEN_SyncIo_WriteLine(sio, "_fromDb(dbT2);");
2278 
2279  /* if (!e) */
2280  GWEN_SyncIo_WriteLine(sio, " if (!e) {");
2281  GWEN_SyncIo_WriteString(sio, " "
2282  "DBG_ERROR(0, \"Bad element for type \\\"");
2283  GWEN_SyncIo_WriteString(sio, elemType);
2284  GWEN_SyncIo_WriteLine(sio, "\\\"\");");
2285  GWEN_SyncIo_WriteLine(sio, " "
2286  "if (GWEN_Logger_GetLevel(0)>="
2287  "GWEN_LoggerLevel_Debug)");
2288  GWEN_SyncIo_WriteLine(sio, " "
2289  "GWEN_DB_Dump(dbT2, 2);");
2290  GWEN_SyncIo_WriteString(sio, " ");
2291  GWEN_SyncIo_WriteString(sio, prefix);
2292  GWEN_SyncIo_WriteLine(sio, "_free(st);");
2293  GWEN_SyncIo_WriteLine(sio, " return 0;");
2294  GWEN_SyncIo_WriteLine(sio, " }");
2295 
2296  /* ElemType_List_Add(e, st->NAME); */
2297  GWEN_SyncIo_WriteString(sio, " ");
2298  GWEN_SyncIo_WriteString(sio, elemPrefix);
2299  GWEN_SyncIo_WriteString(sio, "_List_Add(e, st->");
2300  GWEN_SyncIo_WriteChar(sio, tolower(*name));
2301  GWEN_SyncIo_WriteString(sio, name+1);
2302  GWEN_SyncIo_WriteString(sio, ");");
2303 
2305  " dbT2=GWEN_DB_FindNextGroup(dbT2, \"");
2306  GWEN_SyncIo_WriteString(sio, "element");
2307  GWEN_SyncIo_WriteLine(sio, "\");");
2308 
2309  GWEN_SyncIo_WriteLine(sio, " } /* while */");
2310 
2311  GWEN_SyncIo_WriteLine(sio, " } /* if (dbT) */");
2312 
2313  GWEN_SyncIo_WriteLine(sio, " } /* if (1) */");
2314  }
2315  else if (strcasecmp(mode, "list2")==0) {
2316  const char *prefix;
2317  const char *elemType;
2318  const char *elemPrefix;
2319  GWEN_XMLNODE *elemNode;
2320 
2321  prefix=get_struct_property(node, "prefix", 0);
2322  assert(prefix);
2323 
2324  /* create list code */
2325  elemType=GWEN_XMLNode_GetProperty(n, "elemType", 0);
2326  if (!elemType) {
2327  DBG_ERROR(0, "No \"type\" for list type \"%s\"", typ);
2328  return -1;
2329  }
2330 
2331  elemNode=get_typedef(node, elemType);
2332  if (!elemNode) {
2333  DBG_ERROR(0, "Undefined type %s", elemType);
2334  return -1;
2335  }
2336  elemPrefix=GWEN_XMLNode_GetProperty(elemNode, "prefix", 0);
2337  if (!elemPrefix) {
2338  DBG_ERROR(0, "No \"prefix\" for type \"%s\" (within %s)",
2339  elemType, typ);
2340  return -1;
2341  }
2342 
2343  /* actually generate the code */
2344  GWEN_SyncIo_WriteString(sio, " st->");
2345  GWEN_SyncIo_WriteChar(sio, tolower(*name));
2346  GWEN_SyncIo_WriteString(sio, name+1);
2347  GWEN_SyncIo_WriteString(sio, "=");
2348  GWEN_SyncIo_WriteString(sio, elemPrefix);
2349  GWEN_SyncIo_WriteLine(sio, "_List2_new();");
2350 
2351  GWEN_SyncIo_WriteLine(sio, " if (1) {");
2352  GWEN_SyncIo_WriteLine(sio, " GWEN_DB_NODE *dbT;");
2353  GWEN_SyncIo_WriteString(sio, " ");
2354  GWEN_SyncIo_WriteString(sio, elemType);
2355  GWEN_SyncIo_WriteLine(sio, " *e;");
2356  GWEN_SyncIo_WriteLine(sio, "");
2358  " dbT=GWEN_DB_GetGroup(db, "
2359  "GWEN_PATH_FLAGS_NAMEMUSTEXIST, \"");
2360  GWEN_SyncIo_WriteChar(sio, tolower(*name));
2361  GWEN_SyncIo_WriteString(sio, name+1);
2362  GWEN_SyncIo_WriteLine(sio, "\");");
2363  GWEN_SyncIo_WriteLine(sio, " if (dbT) {");
2364  GWEN_SyncIo_WriteLine(sio, " GWEN_DB_NODE *dbT2;");
2365  GWEN_SyncIo_WriteLine(sio, "");
2366 
2368  " dbT2=GWEN_DB_FindFirstGroup(dbT, \"");
2369  GWEN_SyncIo_WriteString(sio, "element");
2370  GWEN_SyncIo_WriteLine(sio, "\");");
2371 
2372  /* while (e) */
2373  GWEN_SyncIo_WriteLine(sio, " while(dbT2) {");
2374 
2375  /* e=ElemType_fromDb(e) */
2376  GWEN_SyncIo_WriteString(sio, " e=");
2377  GWEN_SyncIo_WriteString(sio, elemPrefix);
2378  GWEN_SyncIo_WriteLine(sio, "_fromDb(dbT2);");
2379 
2380  /* if (!e) */
2381  GWEN_SyncIo_WriteLine(sio, " if (!e) {");
2382  GWEN_SyncIo_WriteString(sio, " "
2383  "DBG_ERROR(0, \"Bad element for type \\\"");
2384  GWEN_SyncIo_WriteString(sio, elemType);
2385  GWEN_SyncIo_WriteLine(sio, "\\\"\");");
2386  GWEN_SyncIo_WriteLine(sio, " "
2387  "if (GWEN_Logger_GetLevel(0)>="
2388  "GWEN_LoggerLevel_Debug)");
2389  GWEN_SyncIo_WriteLine(sio, " "
2390  "GWEN_DB_Dump(dbT2, 2);");
2391  GWEN_SyncIo_WriteString(sio, " ");
2392  GWEN_SyncIo_WriteString(sio, prefix);
2393  GWEN_SyncIo_WriteLine(sio, "_free(st);");
2394  GWEN_SyncIo_WriteLine(sio, " return 0;");
2395  GWEN_SyncIo_WriteLine(sio, " } /* if !e */");
2396 
2397  /* ElemType_List_Add(e, st->NAME); */
2398  GWEN_SyncIo_WriteString(sio, " ");
2399  GWEN_SyncIo_WriteString(sio, elemPrefix);
2400  GWEN_SyncIo_WriteString(sio, "_List2_PushBack(st->");
2401  GWEN_SyncIo_WriteChar(sio, tolower(*name));
2402  GWEN_SyncIo_WriteString(sio, name+1);
2403  GWEN_SyncIo_WriteLine(sio, ", e);");
2404 
2405  GWEN_SyncIo_WriteString(sio, " "
2406  "dbT2=GWEN_DB_FindNextGroup(dbT2, \"");
2407  GWEN_SyncIo_WriteString(sio, "element");
2408  GWEN_SyncIo_WriteLine(sio, "\");");
2409 
2410  GWEN_SyncIo_WriteLine(sio, " } /* while */");
2411 
2412  GWEN_SyncIo_WriteLine(sio, " } /* if (dbT) */");
2413 
2414  GWEN_SyncIo_WriteLine(sio, " } /* if (1) */");
2415  }
2416  else if (strcasecmp(typ, "GWEN_STRINGLIST")==0) {
2417  GWEN_SyncIo_WriteLine(sio, " if (1) {");
2418  GWEN_SyncIo_WriteLine(sio, " int i;");
2419  GWEN_SyncIo_WriteLine(sio, "");
2420  GWEN_SyncIo_WriteLine(sio, " for (i=0; ; i++) {");
2421  GWEN_SyncIo_WriteLine(sio, " const char *s;");
2422  GWEN_SyncIo_WriteLine(sio, "");
2423  GWEN_SyncIo_WriteString(sio, " s=GWEN_DB_GetCharValue(db, \"");
2424  GWEN_SyncIo_WriteChar(sio, tolower(*name));
2425  GWEN_SyncIo_WriteString(sio, name+1);
2426  GWEN_SyncIo_WriteLine(sio, "\", i, 0);");
2427  GWEN_SyncIo_WriteLine(sio, " if (!s)");
2428  GWEN_SyncIo_WriteLine(sio, " break;");
2429  GWEN_SyncIo_WriteString(sio, " ");
2430  GWEN_SyncIo_WriteString(sio, prefix);
2431  GWEN_SyncIo_WriteString(sio, "_Add");
2432  GWEN_SyncIo_WriteChar(sio, toupper(*name));
2433  GWEN_SyncIo_WriteString(sio, name+1);
2434  GWEN_SyncIo_WriteLine(sio, "(st, s, 0);");
2435  GWEN_SyncIo_WriteLine(sio, " } /* for */");
2436  GWEN_SyncIo_WriteLine(sio, " }");
2437  }
2438  else {
2439  isPtr=atoi(get_property(n, "ptr", "0"));
2440 
2441  if (isPtr) {
2442  if (strcasecmp(typ, "char")!=0) {
2444  " if (1) { /* for local vars */");
2445  GWEN_SyncIo_WriteLine(sio, " GWEN_DB_NODE *dbT;");
2446  GWEN_SyncIo_WriteLine(sio, "");
2448  " dbT=GWEN_DB_GetGroup(db, "
2449  "GWEN_PATH_FLAGS_NAMEMUSTEXIST, \"");
2450  GWEN_SyncIo_WriteChar(sio, tolower(*name));
2451  GWEN_SyncIo_WriteString(sio, name+1);
2452  GWEN_SyncIo_WriteLine(sio, "\");");
2453  GWEN_SyncIo_WriteString(sio, " if (dbT)");
2454  }
2455  }
2456  if (isPtr && strcasecmp(typ, "char")!=0) {
2457  GWEN_SyncIo_WriteLine(sio, " {");
2458  rv=write_code_freeElem_c(args, n, sio);
2459  if (rv)
2460  return rv;
2461  GWEN_SyncIo_WriteString(sio, " st->");
2462  GWEN_SyncIo_WriteString(sio, name);
2463  GWEN_SyncIo_WriteString(sio, "=");
2464  rv=write_code_fromdbArg_c(args, n, sio);
2465  if (rv)
2466  return rv;
2467  GWEN_SyncIo_WriteLine(sio, ";");
2468  GWEN_SyncIo_WriteLine(sio, "}");
2469  }
2470  else {
2471  GWEN_SyncIo_WriteString(sio, " ");
2472  GWEN_SyncIo_WriteString(sio, prefix);
2473  GWEN_SyncIo_WriteString(sio, "_Set");
2474  GWEN_SyncIo_WriteChar(sio, toupper(*name));
2475  GWEN_SyncIo_WriteString(sio, name+1);
2476  GWEN_SyncIo_WriteString(sio, "(st, ");
2477 
2478  rv=write_code_fromdbArg_c(args, n, sio);
2479  if (rv)
2480  return rv;
2481  GWEN_SyncIo_WriteLine(sio, ");");
2482  }
2483 
2484  if (isPtr && strcasecmp(typ, "char")!=0) {
2485  GWEN_SyncIo_WriteLine(sio, " }");
2486  }
2487  }
2488  }
2489  }
2490  }
2492  }
2493  return 0;
2494 }
2495 
2496 
2497 
2499  GWEN_SYNCIO *sio)
2500 {
2501  int rv;
2502  const char *prefix;
2503  const char *styp;
2504 
2505  prefix=get_struct_property(node, "prefix", 0);
2506  if (!prefix) {
2507  DBG_ERROR(0, "No prefix in struct");
2508  return -1;
2509  }
2510  styp=get_struct_property(node, "id", 0);
2511  if (!styp) {
2512  DBG_ERROR(0, "No id in struct");
2513  return -1;
2514  }
2515 
2516  GWEN_SyncIo_WriteString(sio, "int ");
2517  GWEN_SyncIo_WriteString(sio, prefix);
2518  GWEN_SyncIo_WriteString(sio, "_ReadDb(");
2519  GWEN_SyncIo_WriteString(sio, styp);
2520  GWEN_SyncIo_WriteLine(sio, " *st, GWEN_DB_NODE *db) {");
2521 
2522  GWEN_SyncIo_WriteLine(sio, " assert(st);");
2523  GWEN_SyncIo_WriteLine(sio, " assert(db);");
2524 
2525  rv=write_code_fromdbrec_c(args, node, sio);
2526  if (rv) {
2527  DBG_ERROR(0, "Error in fromdb");
2528  return rv;
2529  }
2530 
2531  GWEN_SyncIo_WriteLine(sio, " return 0;");
2532  GWEN_SyncIo_WriteLine(sio, "}");
2533  return 0;
2534 }
2535 
2536 
2537 
2539  GWEN_SYNCIO *sio)
2540 {
2541  const char *prefix;
2542  const char *styp;
2543  const char *fromDbName;
2544  const char *fromDbAcc;
2545 
2546  prefix=get_struct_property(node, "prefix", 0);
2547  if (!prefix) {
2548  DBG_ERROR(0, "No prefix in struct");
2549  return -1;
2550  }
2551  styp=get_struct_property(node, "id", 0);
2552  if (!styp) {
2553  DBG_ERROR(0, "No id in struct");
2554  return -1;
2555  }
2556  fromDbAcc=get_struct_property(node, "dup-access",
2557  get_struct_property(node, "access", 0));
2558  fromDbName=get_struct_property(node, "fromdb-name", 0);
2559  if (fromDbAcc && strcasecmp(fromDbAcc, "none")!=0) {
2560  GWEN_SyncIo_WriteString(sio, styp);
2561  GWEN_SyncIo_WriteString(sio, " *");
2562  GWEN_SyncIo_WriteString(sio, prefix);
2563  if (fromDbName)
2564  GWEN_SyncIo_WriteString(sio, fromDbName);
2565  else
2566  GWEN_SyncIo_WriteString(sio, "_fromDb");
2567  GWEN_SyncIo_WriteLine(sio, "(GWEN_DB_NODE *db) {");
2568 
2569  GWEN_SyncIo_WriteString(sio, " ");
2570  GWEN_SyncIo_WriteString(sio, styp);
2571  GWEN_SyncIo_WriteLine(sio, " *st;");
2572  GWEN_SyncIo_WriteLine(sio, "");
2573  GWEN_SyncIo_WriteLine(sio, " assert(db);");
2574  GWEN_SyncIo_WriteString(sio, " st=");
2575  GWEN_SyncIo_WriteString(sio, prefix);
2576  GWEN_SyncIo_WriteLine(sio, "_new();");
2577 
2578  GWEN_SyncIo_WriteString(sio, " ");
2579  GWEN_SyncIo_WriteString(sio, prefix);
2580  GWEN_SyncIo_WriteLine(sio, "_ReadDb(st, db);");
2581 
2582  GWEN_SyncIo_WriteLine(sio, " st->_modified=0;");
2583  GWEN_SyncIo_WriteLine(sio, " return st;");
2584  GWEN_SyncIo_WriteLine(sio, "}");
2585  } /* if fromDb wanted */
2586  return 0;
2587 }
2588 
2589 
2590 
2592  GWEN_SYNCIO *sio)
2593 {
2594  const char *prefix;
2595  const char *styp;
2596  const char *dupAcc;
2597 
2598  prefix=get_struct_property(node, "prefix", 0);
2599  if (!prefix) {
2600  DBG_ERROR(0, "No prefix in struct");
2601  return -1;
2602  }
2603  styp=get_struct_property(node, "id", 0);
2604  if (!styp) {
2605  DBG_ERROR(0, "No id in struct");
2606  return -1;
2607  }
2608  dupAcc=get_struct_property(node, "dup-access",
2609  get_struct_property(node, "access", 0));
2610 
2611  /* IsModified */
2612  GWEN_SyncIo_WriteString(sio, "int ");
2613  GWEN_SyncIo_WriteString(sio, prefix);
2614  GWEN_SyncIo_WriteString(sio, "_IsModified(const ");
2615  GWEN_SyncIo_WriteString(sio, styp);
2616  GWEN_SyncIo_WriteLine(sio, " *st) {");
2617  GWEN_SyncIo_WriteLine(sio, " assert(st);");
2618  GWEN_SyncIo_WriteLine(sio, " return st->_modified;");
2619  GWEN_SyncIo_WriteLine(sio, "}");
2620 
2621  GWEN_SyncIo_WriteLine(sio, "");
2622  GWEN_SyncIo_WriteLine(sio, "");
2623 
2624  /* SetModified */
2625  GWEN_SyncIo_WriteString(sio, "void ");
2626  GWEN_SyncIo_WriteString(sio, prefix);
2627  GWEN_SyncIo_WriteString(sio, "_SetModified(");
2628  GWEN_SyncIo_WriteString(sio, styp);
2629  GWEN_SyncIo_WriteLine(sio, " *st, int i) {");
2630  GWEN_SyncIo_WriteLine(sio, " assert(st);");
2631  GWEN_SyncIo_WriteLine(sio, " st->_modified=i;");
2632  GWEN_SyncIo_WriteLine(sio, "}");
2633 
2634  GWEN_SyncIo_WriteLine(sio, "");
2635  GWEN_SyncIo_WriteLine(sio, "");
2636 
2637  /* Attach */
2638  GWEN_SyncIo_WriteString(sio, "void ");
2639  GWEN_SyncIo_WriteString(sio, prefix);
2640  GWEN_SyncIo_WriteString(sio, "_Attach(");
2641  GWEN_SyncIo_WriteString(sio, styp);
2642  GWEN_SyncIo_WriteLine(sio, " *st) {");
2643  GWEN_SyncIo_WriteLine(sio, " assert(st);");
2644  GWEN_SyncIo_WriteLine(sio, " st->_usage++;");
2645  GWEN_SyncIo_WriteLine(sio, "}");
2646 
2647  /* list2 functions */
2648  if (get_struct_property(node, "list2", 0)) {
2649  /* List2_freeAll */
2650  GWEN_SyncIo_WriteString(sio, styp);
2651  GWEN_SyncIo_WriteString(sio, " *");
2652  GWEN_SyncIo_WriteString(sio, prefix);
2653  GWEN_SyncIo_WriteString(sio, "_List2__freeAll_cb(");
2654  GWEN_SyncIo_WriteString(sio, styp);
2655  GWEN_SyncIo_WriteString(sio, " *");
2656  GWEN_SyncIo_WriteLine(sio, "st, void *user_data) {");
2657 
2658  GWEN_SyncIo_WriteString(sio, " ");
2659  GWEN_SyncIo_WriteString(sio, prefix);
2660  GWEN_SyncIo_WriteLine(sio, "_free(st);");
2661  GWEN_SyncIo_WriteLine(sio, "return 0;");
2662 
2663  GWEN_SyncIo_WriteLine(sio, "}");
2664  GWEN_SyncIo_WriteLine(sio, "");
2665  GWEN_SyncIo_WriteLine(sio, "");
2666 
2667  GWEN_SyncIo_WriteString(sio, "void ");
2668  GWEN_SyncIo_WriteString(sio, prefix);
2669  GWEN_SyncIo_WriteString(sio, "_List2_freeAll(");
2670  GWEN_SyncIo_WriteString(sio, styp);
2671  GWEN_SyncIo_WriteLine(sio, "_LIST2 *stl) {");
2672 
2673  GWEN_SyncIo_WriteLine(sio, " if (stl) {");
2674 
2675  GWEN_SyncIo_WriteString(sio, " ");
2676  GWEN_SyncIo_WriteString(sio, prefix);
2677  GWEN_SyncIo_WriteString(sio, "_List2_ForEach(stl, ");
2678  GWEN_SyncIo_WriteString(sio, prefix);
2679  GWEN_SyncIo_WriteLine(sio, "_List2__freeAll_cb, 0);");
2680 
2681  GWEN_SyncIo_WriteString(sio, " ");
2682  GWEN_SyncIo_WriteString(sio, prefix);
2683  GWEN_SyncIo_WriteLine(sio, "_List2_free(stl); ");
2684 
2685  GWEN_SyncIo_WriteLine(sio, " }");
2686  GWEN_SyncIo_WriteLine(sio, "}");
2687  GWEN_SyncIo_WriteLine(sio, "");
2688  GWEN_SyncIo_WriteLine(sio, "");
2689  }
2690  /* list functions */
2691  if (get_struct_property(node, "list", 0)) {
2692  /* LIST_dup functions */
2693  if (dupAcc && strcasecmp(dupAcc, "none")!=0) {
2694  const char *dupName;
2695 
2696  dupName=get_struct_property(node, "dup-name", 0);
2697  GWEN_SyncIo_WriteString(sio, styp);
2698  GWEN_SyncIo_WriteString(sio, "_LIST *");
2699 
2700  GWEN_SyncIo_WriteString(sio, prefix);
2701  GWEN_SyncIo_WriteString(sio, "_List_dup(const ");
2702  GWEN_SyncIo_WriteString(sio, styp);
2703  GWEN_SyncIo_WriteLine(sio, "_LIST *stl) {");
2704 
2705  GWEN_SyncIo_WriteLine(sio, " if (stl) {");
2706 
2707  /* ELEMTYPE_LIST *nl; */
2708  GWEN_SyncIo_WriteString(sio, " ");
2709  GWEN_SyncIo_WriteString(sio, styp);
2710  GWEN_SyncIo_WriteLine(sio, "_LIST *nl;");
2711 
2712  /* ELEMTYPE *e; */
2713  GWEN_SyncIo_WriteString(sio, " ");
2714  GWEN_SyncIo_WriteString(sio, styp);
2715  GWEN_SyncIo_WriteLine(sio, " *e;");
2716  GWEN_SyncIo_WriteLine(sio, "");
2717 
2718  /* nl=ElemType_List */
2719  GWEN_SyncIo_WriteString(sio, " nl=");
2720  GWEN_SyncIo_WriteString(sio, prefix);
2721  GWEN_SyncIo_WriteLine(sio, "_List_new();");
2722 
2723  /* e=ElemType_List_First */
2724  GWEN_SyncIo_WriteString(sio, " e=");
2725  GWEN_SyncIo_WriteString(sio, prefix);
2726  GWEN_SyncIo_WriteLine(sio, "_List_First(stl);");
2727 
2728  /* while (e) ; */
2729  GWEN_SyncIo_WriteLine(sio, " while(e) {");
2730 
2731  /* ELEMTYPE *ne; */
2732  GWEN_SyncIo_WriteString(sio, " ");
2733  GWEN_SyncIo_WriteString(sio, styp);
2734  GWEN_SyncIo_WriteLine(sio, " *ne;");
2735  GWEN_SyncIo_WriteLine(sio, "");
2736 
2737  /* ne=ElemType_dup; assert(ne); */
2738  GWEN_SyncIo_WriteString(sio, " ne=");
2739  GWEN_SyncIo_WriteString(sio, prefix);
2740  if (dupName)
2741  GWEN_SyncIo_WriteString(sio, dupName);
2742  else
2743  GWEN_SyncIo_WriteString(sio, "_dup");
2744  GWEN_SyncIo_WriteLine(sio, "(e);");
2745  GWEN_SyncIo_WriteLine(sio, " assert(ne);");
2746 
2747  /* ElemType_List_Add(ne, st->NAME); */
2748  GWEN_SyncIo_WriteString(sio, " ");
2749  GWEN_SyncIo_WriteString(sio, prefix);
2750  GWEN_SyncIo_WriteLine(sio, "_List_Add(ne, nl);");
2751 
2752  /* e=ElemType_List_Next */
2753  GWEN_SyncIo_WriteString(sio, " e=");
2754  GWEN_SyncIo_WriteString(sio, prefix);
2755  GWEN_SyncIo_WriteLine(sio, "_List_Next(e);");
2756 
2757  GWEN_SyncIo_WriteLine(sio, " } /* while (e) */");
2758 
2759 
2760  GWEN_SyncIo_WriteLine(sio, " return nl;");
2761 
2762  GWEN_SyncIo_WriteLine(sio, " }");
2763  GWEN_SyncIo_WriteLine(sio, " else");
2764  GWEN_SyncIo_WriteLine(sio, " return 0;");
2765  GWEN_SyncIo_WriteLine(sio, "}");
2766  GWEN_SyncIo_WriteLine(sio, "");
2767  GWEN_SyncIo_WriteLine(sio, "");
2768  } /* if we have a dup function */
2769 
2770  }
2771 
2772 
2773 
2774  return 0;
2775 }
2776 
2777 
2778 
2779 
2781 {
2782  int rv;
2783  const char *f;
2784  GWEN_BUFFER *fname;
2785  /*const char *nacc;*/
2786  GWEN_SYNCIO *sio;
2787  int err;
2788  const char *id;
2789  const char *prefix;
2790  GWEN_XMLNODE *n;
2791 
2792  id=get_struct_property(node, "id", 0);
2793  if (!id) {
2794  DBG_ERROR(0, "No id for struct");
2795  return -1;
2796  }
2797 
2798  f=get_struct_property(node, "filename", 0);
2799  if (!f) {
2800  DBG_ERROR(0, "No filename given");
2801  return -1;
2802  }
2803 
2804  prefix=get_struct_property(node, "prefix", 0);
2805  if (!prefix) {
2806  DBG_ERROR(0, "No prefix in struct");
2807  return -1;
2808  }
2809 
2810  /*nacc=get_struct_property(node, "access", "public");*/
2811 
2812  fname=GWEN_Buffer_new(0, 256, 0, 1);
2813  GWEN_Buffer_AppendString(fname, f);
2814  GWEN_Buffer_AppendString(fname, ".c");
2815 
2825  rv=GWEN_SyncIo_Connect(sio);
2826  if (rv<0) {
2827  DBG_ERROR(0, "open(%s): %s",
2828  GWEN_Buffer_GetStart(fname),
2829  strerror(errno));
2830  GWEN_Buffer_free(fname);
2831  GWEN_SyncIo_free(sio);
2832  return -1;
2833  }
2834  GWEN_Buffer_free(fname);
2835 
2836  /* Insert the auto-generation warning */
2837  GWEN_SyncIo_WriteString(sio, "/* This file is auto-generated from \"");
2838  GWEN_SyncIo_WriteString(sio, f);
2839  GWEN_SyncIo_WriteLine(sio, ".xml\" by the typemaker");
2840  GWEN_SyncIo_WriteLine(sio, " tool of Gwenhywfar. ");
2841  GWEN_SyncIo_WriteLine(sio, " Do not edit this file -- all changes will be lost! */");
2842 
2843  GWEN_SyncIo_WriteLine(sio, "#ifdef HAVE_CONFIG_H");
2844  GWEN_SyncIo_WriteLine(sio, "# include \"config.h\"");
2845  GWEN_SyncIo_WriteLine(sio, "#endif");
2846  GWEN_SyncIo_WriteLine(sio, "");
2847 
2848  fname=GWEN_Buffer_new(0, 256, 0, 1);
2849  GWEN_Buffer_AppendString(fname, f);
2850  GWEN_Buffer_AppendString(fname, "_p.h");
2851 
2852  GWEN_SyncIo_WriteString(sio, "#include \"");
2854  GWEN_SyncIo_WriteLine(sio, "\"");
2855  GWEN_Buffer_free(fname);
2856 
2857  GWEN_SyncIo_WriteLine(sio, "#include <gwenhywfar/misc.h>");
2858  GWEN_SyncIo_WriteLine(sio, "#include <gwenhywfar/db.h>");
2859  GWEN_SyncIo_WriteLine(sio, "#include <gwenhywfar/debug.h>");
2860  GWEN_SyncIo_WriteLine(sio, "#include <assert.h>");
2861  GWEN_SyncIo_WriteLine(sio, "#include <stdlib.h>");
2862  GWEN_SyncIo_WriteLine(sio, "#include <strings.h>");
2863  GWEN_SyncIo_WriteLine(sio, "");
2864 
2865  /* write headers */
2866  n=GWEN_XMLNode_FindFirstTag(node, "headers", 0, 0);
2867  if (n) {
2868  n=GWEN_XMLNode_FindFirstTag(n, "header", 0, 0);
2869  while (n) {
2870  write_h_header(args, n, sio, "source");
2871  n=GWEN_XMLNode_FindNextTag(n, "header", 0, 0);
2872  }
2873  GWEN_SyncIo_WriteLine(sio, "");
2874  GWEN_SyncIo_WriteLine(sio, "");
2875  }
2876 
2877  /* write c-headers */
2878  n=GWEN_XMLNode_FindFirstTag(node, "c-headers", 0, 0);
2879  if (n) {
2880  n=GWEN_XMLNode_FindFirstTag(n, "header", 0, 0);
2881  while (n) {
2882  write_h_header(args, n, sio, "source");
2883  n=GWEN_XMLNode_FindNextTag(n, "header", 0, 0);
2884  }
2885  GWEN_SyncIo_WriteLine(sio, "");
2886  GWEN_SyncIo_WriteLine(sio, "");
2887  }
2888 
2889  if (get_struct_property(node, "inherit", 0)) {
2890  GWEN_SyncIo_WriteString(sio, "GWEN_INHERIT_FUNCTIONS(");
2891  GWEN_SyncIo_WriteString(sio, id);
2892  GWEN_SyncIo_WriteLine(sio, ")");
2893  }
2894 
2895  if (get_struct_property(node, "list", 0)) {
2896  GWEN_SyncIo_WriteString(sio, "GWEN_LIST_FUNCTIONS(");
2897  GWEN_SyncIo_WriteString(sio, id);
2898  GWEN_SyncIo_WriteString(sio, ", ");
2899  GWEN_SyncIo_WriteString(sio, prefix);
2900  GWEN_SyncIo_WriteLine(sio, ")");
2901  }
2902 
2903  if (get_struct_property(node, "list2", 0)) {
2904  GWEN_SyncIo_WriteString(sio, "GWEN_LIST2_FUNCTIONS(");
2905  GWEN_SyncIo_WriteString(sio, id);
2906  GWEN_SyncIo_WriteString(sio, ", ");
2907  GWEN_SyncIo_WriteString(sio, prefix);
2908  GWEN_SyncIo_WriteLine(sio, ")");
2909  }
2910  GWEN_SyncIo_WriteLine(sio, "");
2911  GWEN_SyncIo_WriteLine(sio, "");
2912 
2913  rv=write_c_enums(args, node, sio);
2914  if (rv) {
2916  GWEN_SyncIo_free(sio);
2917  return rv;
2918  }
2919  GWEN_SyncIo_WriteLine(sio, "");
2920  GWEN_SyncIo_WriteLine(sio, "");
2921 
2922  rv=write_code_const_c(args, node, sio);
2923  if (rv) {
2925  GWEN_SyncIo_free(sio);
2926  return rv;
2927  }
2928  GWEN_SyncIo_WriteLine(sio, "");
2929  GWEN_SyncIo_WriteLine(sio, "");
2930 
2931  rv=write_code_dest_c(args, node, sio);
2932  if (rv) {
2934  GWEN_SyncIo_free(sio);
2935  return rv;
2936  }
2937  GWEN_SyncIo_WriteLine(sio, "");
2938  GWEN_SyncIo_WriteLine(sio, "");
2939 
2940  rv=write_code_dup_c(args, node, sio);
2941  if (rv) {
2943  GWEN_SyncIo_free(sio);
2944  return rv;
2945  }
2946  GWEN_SyncIo_WriteLine(sio, "");
2947  GWEN_SyncIo_WriteLine(sio, "");
2948 
2949  rv=write_code_todb_c(args, node, sio);
2950  if (rv) {
2952  GWEN_SyncIo_free(sio);
2953  return rv;
2954  }
2955  GWEN_SyncIo_WriteLine(sio, "");
2956  GWEN_SyncIo_WriteLine(sio, "");
2957 
2958  rv=write_code_readdb_c(args, node, sio);
2959  if (rv) {
2961  GWEN_SyncIo_free(sio);
2962  return rv;
2963  }
2964  GWEN_SyncIo_WriteLine(sio, "");
2965  GWEN_SyncIo_WriteLine(sio, "");
2966 
2967  rv=write_code_fromdb_c(args, node, sio);
2968  if (rv) {
2970  GWEN_SyncIo_free(sio);
2971  return rv;
2972  }
2973  GWEN_SyncIo_WriteLine(sio, "");
2974  GWEN_SyncIo_WriteLine(sio, "");
2975 
2976  rv=write_code_setget_c(args, node, sio);
2977  if (rv) {
2979  GWEN_SyncIo_free(sio);
2980  return rv;
2981  }
2982  GWEN_SyncIo_WriteLine(sio, "");
2983  GWEN_SyncIo_WriteLine(sio, "");
2984 
2985  rv=write_code_builtin_c(args, node, sio);
2986  if (rv) {
2988  GWEN_SyncIo_free(sio);
2989  return rv;
2990  }
2991  GWEN_SyncIo_WriteLine(sio, "");
2992  GWEN_SyncIo_WriteLine(sio, "");
2993 
2994  /* close stream */
2995  err=GWEN_SyncIo_Disconnect(sio);
2996  if (err) {
2997  DBG_ERROR_ERR(0, err);
2998  GWEN_SyncIo_free(sio);
2999  return -1;
3000  }
3001 
3002  GWEN_SyncIo_free(sio);
3003  return 0;
3004 }
3005 
3006 
3007 
3009 {
3010  GWEN_XMLNODE *n;
3011  int rv;
3012 
3013  n=GWEN_XMLNode_FindFirstTag(node, "type", 0, 0);
3014  while (n) {
3015  rv=write_code_file_c(args, n);
3016  if (rv)
3017  return rv;
3018  n=GWEN_XMLNode_FindNextTag(n, "type", 0, 0);
3019  }
3020  return 0;
3021 }
3022 
3023 
3024 
3025 
3026 
3027 
3028 
3029 
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:235
int write_code_setget_c(ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio)
Definition: code_c.c:1181
int GWEN_SyncIo_Connect(GWEN_SYNCIO *sio)
Definition: syncio.c:97
#define GWEN_SYNCIO_FILE_FLAGS_WRITE
Definition: syncio_file.h:54
#define GWEN_SYNCIO_FILE_FLAGS_READ
Definition: syncio_file.h:53
const char * GWEN_XMLNode_GetProperty(const GWEN_XMLNODE *n, const char *name, const char *defaultValue)
Definition: xml.c:239
GWEN_XMLNODE * GWEN_XMLNode_FindNextTag(const GWEN_XMLNODE *n, const char *tname, const char *pname, const char *pvalue)
Definition: xml.c:794
GWEN_XMLNODE * GWEN_XMLNode_GetFirstData(const GWEN_XMLNODE *n)
Definition: xml.c:724
int write_code_freeElem_c(GWEN_UNUSED ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio)
Definition: code_c.c:196
int write_code_todbArg_c(GWEN_UNUSED ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio)
Definition: code_c.c:406
int write_code_todb_c(ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio)
Definition: code_c.c:2114
#define GWEN_SYNCIO_FILE_FLAGS_UREAD
Definition: syncio_file.h:58
int write_code_dupArg_c(GWEN_UNUSED ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio, const char *param)
Definition: code_c.c:333
int write_code_freeElems_c(ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio)
Definition: code_c.c:302
#define DBG_ERROR_ERR(dbg_logger, dbg_err)
Definition: debug.h:113
uint32_t GWEN_Buffer_GetPos(const GWEN_BUFFER *bf)
Definition: buffer.c:253
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition: buffer.c:42
#define GWEN_SYNCIO_FILE_FLAGS_GREAD
Definition: syncio_file.h:62
int GWEN_SyncIo_WriteLine(GWEN_SYNCIO *sio, const char *s)
Definition: syncio.c:407
int write_code_readdb_c(ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio)
Definition: code_c.c:2498
GWEN_XMLNODE * GWEN_XMLNode_FindFirstTag(const GWEN_XMLNODE *n, const char *tname, const char *pname, const char *pvalue)
Definition: xml.c:776
int write_code_todbrec_c(ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio)
Definition: code_c.c:2041
int write_code_dupList_c(GWEN_UNUSED ARGUMENTS *args, GWEN_XMLNODE *n, GWEN_SYNCIO *sio, const char *listName)
Definition: code_c.c:1637
GWEN_XMLNODE * get_typedef(GWEN_XMLNODE *node, const char *name)
struct GWEN_SYNCIO GWEN_SYNCIO
Definition: syncio.h:40
GWEN_XMLNODE_TYPE GWEN_XMLNode_GetType(const GWEN_XMLNODE *n)
Definition: xml.c:458
const char * get_struct_property(GWEN_XMLNODE *node, const char *pname, const char *defval)
int write_c_enums(GWEN_UNUSED ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio)
Definition: code_c.c:35
GWEN_XMLNODE * GWEN_XMLNode_GetNextTag(const GWEN_XMLNODE *n)
Definition: xml.c:712
int write_code_fromdbArg_c(GWEN_UNUSED ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio)
Definition: code_c.c:772
int write_code_constrec_c(ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio)
Definition: code_c.c:936
#define GWEN_SYNCIO_FILE_FLAGS_GWRITE
Definition: syncio_file.h:63
int GWEN_Buffer_AppendByte(GWEN_BUFFER *bf, char c)
Definition: buffer.c:394
#define GWEN_SYNCIO_FILE_FLAGS_UWRITE
Definition: syncio_file.h:59
int write_code_fromdb_c(GWEN_UNUSED ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio)
Definition: code_c.c:2538
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:89
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:38
void GWEN_SyncIo_free(GWEN_SYNCIO *sio)
Definition: syncio.c:78
const char * get_property(GWEN_XMLNODE *node, const char *pname, const char *defval)
void GWEN_SyncIo_AddFlags(GWEN_SYNCIO *sio, uint32_t fl)
Definition: syncio.c:179
int GWEN_Buffer_Crop(GWEN_BUFFER *bf, uint32_t pos, uint32_t l)
Definition: buffer.c:947
int write_code_file_c(ARGUMENTS *args, GWEN_XMLNODE *node)
Definition: code_c.c:2780
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
GWEN_XMLNODE * GWEN_XMLNode_GetFirstTag(const GWEN_XMLNODE *n)
Definition: xml.c:705
int GWEN_SyncIo_WriteString(GWEN_SYNCIO *sio, const char *s)
Definition: syncio.c:392
const char * GWEN_XMLNode_GetData(const GWEN_XMLNODE *n)
Definition: xml.c:370
int GWEN_Buffer_SetPos(GWEN_BUFFER *bf, uint32_t i)
Definition: buffer.c:261
int GWEN_SyncIo_Disconnect(GWEN_SYNCIO *sio)
Definition: syncio.c:109
int write_code_const_c(ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio)
Definition: code_c.c:1054
int write_code_dest_c(ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio)
Definition: code_c.c:1120
const char * get_function_name(GWEN_XMLNODE *node, const char *ftype)
int write_code_files_c(ARGUMENTS *args, GWEN_XMLNODE *node)
Definition: code_c.c:3008
GWENHYWFAR_API GWEN_SYNCIO * GWEN_SyncIo_File_new(const char *path, GWEN_SYNCIO_FILE_CREATIONMODE cm)
int write_code_dup_c(ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio)
Definition: code_c.c:1982
int write_code_fromdbrec_c(ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio)
Definition: code_c.c:2154
int write_h_header(GWEN_UNUSED ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio, GWEN_UNUSED const char *where)
struct GWEN__XMLNODE GWEN_XMLNODE
Definition: xml.h:156
int write_code_duprec_c(ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio)
Definition: code_c.c:1866
#define GWEN_UNUSED
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition: buffer.c:989
int write_code_builtin_c(GWEN_UNUSED ARGUMENTS *args, GWEN_XMLNODE *node, GWEN_SYNCIO *sio)
Definition: code_c.c:2591
int GWEN_SyncIo_WriteChar(GWEN_SYNCIO *sio, char s)
Definition: syncio.c:431