gwenhywfar  4.99.8beta
builddefs.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Thu Jul 02 2009
3  copyright : (C) 2009 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 #include "typemaker2.h"
15 #include "tm_typemanager.h"
16 #include "tm_builder_c.h"
17 
18 #include <gwenhywfar/debug.h>
19 #include <gwenhywfar/gwenhywfar.h>
20 #include <gwenhywfar/pathmanager.h>
21 
22 
23 
24 int doBuildDefs(GWEN_DB_NODE *dbArgs, const char *fname) {
27  TYPEMAKER2_TYPE *ty;
28  GWEN_STRINGLIST *sl;
29  TYPEMAKER2_TYPE_LIST2 *tlist;
30  TYPEMAKER2_TYPE_LIST2_ITERATOR *it;
31  const char *s;
32  int i;
33  int rv;
34 
36 
37  s=GWEN_DB_GetCharValue(dbArgs, "api", 0, NULL);
38  if (s && *s)
40 
41  s=GWEN_DB_GetCharValue(dbArgs, "language", 0, "c");
42  if (s && *s) {
44  if (strcasecmp(s, "c")==0) {
47  }
48  else {
49  DBG_ERROR(GWEN_LOGDOMAIN, "Unsupported language [%s]", s);
50  return 1;
51  }
52  }
53  else {
54  DBG_ERROR(GWEN_LOGDOMAIN, "Missing language specification");
55  return 1;
56  }
57 
59 
60  for (i=0; i<99; i++) {
61  s=GWEN_DB_GetCharValue(dbArgs, "include", i, NULL);
62  if (s && *s)
64  else
65  break;
66  }
67 
69  if (sl) {
71 
73  while(se) {
75  if (s) {
76  GWEN_BUFFER *xbuf;
77 
78  xbuf=GWEN_Buffer_new(0, 256, 0, 1);
79  GWEN_Buffer_AppendString(xbuf, s);
80  GWEN_Buffer_AppendString(xbuf, "/typemaker2/");
82  if (s && *s)
83  GWEN_Buffer_AppendString(xbuf, s);
85  GWEN_Buffer_free(xbuf);
86  }
88  }
90  }
91 
92  tlist=Typemaker2_Type_List2_new();
93  rv=Typemaker2_TypeManager_LoadTypeFileNoLookup(tym, fname, tlist);
94  if (rv<0) {
95  DBG_ERROR(GWEN_LOGDOMAIN, "Unable to load file [%s] (%d)", fname, rv);
96  return 2;
97  }
98 
99  it=Typemaker2_Type_List2_First(tlist);
100  if(it) {
101  ty=Typemaker2_Type_List2Iterator_Data(it);
102  while(ty) {
103  /* DEBUG */
104 #if 0
105  Typemaker2_TypeManager_Dump(tym, stderr, 2);
106 #endif
107 
108  /* only write typedef files */
109  rv=Typemaker2_Builder_WriteFiles(tb, ty, 1);
110  if (rv<0) {
111  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
112  return 2;
113  }
114 
115 
116  /* handle next type */
117  ty=Typemaker2_Type_List2Iterator_Next(it);
118  }
119  Typemaker2_Type_List2Iterator_free(it);
120  }
121  Typemaker2_Type_List2_free(tlist);
122 
123 
124  return 0;
125 }
126 
127 
128 
129 
130 int buildDefs(GWEN_DB_NODE *dbArgs) {
131  int i;
132 
133  for (i=0; i<99; i++) {
134  const char *fileName;
135 
136  fileName=GWEN_DB_GetCharValue(dbArgs, "params", i, NULL);
137  if (fileName) {
138  int rv=doBuildDefs(dbArgs, fileName);
139  if (rv != 0) {
140  DBG_ERROR(GWEN_LOGDOMAIN, "Error building type from [%s]", fileName);
141  return 2;
142  }
143  }
144  else {
145  if (i==0) {
146  DBG_ERROR(GWEN_LOGDOMAIN, "No input");
147  return 1;
148  }
149  }
150  }
151 
152  return 0;
153 }
154 
155 
void Typemaker2_TypeManager_AddFolder(TYPEMAKER2_TYPEMANAGER *tym, const char *s)
void Typemaker2_Builder_SetSourceFileName(TYPEMAKER2_BUILDER *tb, const char *s)
Definition: tm_builder.c:239
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:223
struct GWEN_STRINGLISTENTRYSTRUCT GWEN_STRINGLISTENTRY
Definition: stringlist.h:51
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
void Typemaker2_TypeManager_Dump(TYPEMAKER2_TYPEMANAGER *tym, FILE *f, int indent)
#define NULL
Definition: binreloc.c:290
int buildDefs(GWEN_DB_NODE *dbArgs)
Definition: builddefs.c:130
int Typemaker2_Builder_WriteFiles(TYPEMAKER2_BUILDER *tb, TYPEMAKER2_TYPE *ty, int defsOnly)
Definition: tm_builder.c:1163
#define GWEN_LOGDOMAIN
Definition: logger.h:35
void Typemaker2_Builder_SetTypeManager(TYPEMAKER2_BUILDER *tb, TYPEMAKER2_TYPEMANAGER *tm)
Definition: tm_builder.c:110
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition: buffer.c:38
GWEN_STRINGLISTENTRY * GWEN_StringList_FirstEntry(const GWEN_STRINGLIST *sl)
Definition: stringlist.c:352
const char * GWEN_StringListEntry_Data(const GWEN_STRINGLISTENTRY *se)
Definition: stringlist.c:366
void GWEN_StringList_free(GWEN_STRINGLIST *sl)
Definition: stringlist.c:57
struct GWEN_STRINGLISTSTRUCT GWEN_STRINGLIST
Definition: stringlist.h:54
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
Definition: db.c:897
GWEN_STRINGLIST * GWEN_PathManager_GetPaths(const char *destLib, const char *pathName)
Definition: pathmanager.c:483
struct TYPEMAKER2_BUILDER TYPEMAKER2_BUILDER
Definition: tm_builder.h:23
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
TYPEMAKER2_TYPEMANAGER * Typemaker2_TypeManager_new()
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
struct TYPEMAKER2_TYPE TYPEMAKER2_TYPE
Definition: tm_type.h:21
GWEN_STRINGLISTENTRY * GWEN_StringListEntry_Next(const GWEN_STRINGLISTENTRY *se)
Definition: stringlist.c:359
struct TYPEMAKER2_TYPEMANAGER TYPEMAKER2_TYPEMANAGER
TYPEMAKER2_BUILDER * Typemaker2_Builder_C_new()
#define GWEN_PM_DATADIR
Definition: gwenhywfar.h:56
#define GWEN_PM_LIBNAME
Definition: gwenhywfar.h:42
void Typemaker2_TypeManager_SetApiDeclaration(TYPEMAKER2_TYPEMANAGER *tym, const char *s)
void Typemaker2_TypeManager_SetLanguage(TYPEMAKER2_TYPEMANAGER *tym, const char *s)
const char * Typemaker2_TypeManager_GetLanguage(const TYPEMAKER2_TYPEMANAGER *tym)
int doBuildDefs(GWEN_DB_NODE *dbArgs, const char *fname)
Definition: builddefs.c:24
int Typemaker2_TypeManager_LoadTypeFileNoLookup(TYPEMAKER2_TYPEMANAGER *tym, const char *fileName, TYPEMAKER2_TYPE_LIST2 *tlist2)
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition: buffer.c:1014