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