gwenhywfar  5.10.1
build.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 buildFile2(GWEN_DB_NODE *dbArgs, const char *fname)
25 {
28  TYPEMAKER2_TYPE *ty;
29  GWEN_STRINGLIST *sl;
30  TYPEMAKER2_TYPE_LIST2 *tlist;
31  TYPEMAKER2_TYPE_LIST2_ITERATOR *it;
32  int noDefs=0;
33  const char *s;
34  int i;
35  int rv;
36 
38 
39  s=GWEN_DB_GetCharValue(dbArgs, "api", 0, NULL);
40  if (s && *s)
42 
43  s=GWEN_DB_GetCharValue(dbArgs, "language", 0, "c");
44  if (s && *s) {
46  if (strcasecmp(s, "c")==0) {
49  }
50  else {
51  DBG_ERROR(GWEN_LOGDOMAIN, "Unsupported language [%s]", s);
52  return 1;
53  }
54  }
55  else {
56  DBG_ERROR(GWEN_LOGDOMAIN, "Missing language specification");
57  return 1;
58  }
59 
60  s = GWEN_DB_GetCharValue(dbArgs, "destFolder", 0, NULL);
61  if (s)
63 
64 
66 
67  noDefs=GWEN_DB_GetIntValue(dbArgs, "noDefs", 0, 0);
68 
69  for (i=0; i<99; i++) {
70  s=GWEN_DB_GetCharValue(dbArgs, "include", i, NULL);
71  if (s && *s)
73  else
74  break;
75  }
76 
78  if (sl) {
80 
82  while (se) {
84  if (s) {
85  GWEN_BUFFER *xbuf;
86 
87  xbuf=GWEN_Buffer_new(0, 256, 0, 1);
88  GWEN_Buffer_AppendString(xbuf, s);
89  GWEN_Buffer_AppendString(xbuf, "/typemaker2/");
91  if (s && *s)
92  GWEN_Buffer_AppendString(xbuf, s);
94  GWEN_Buffer_free(xbuf);
95  }
97  }
99  }
100 
101  s=GWEN_DB_GetCharValue(dbArgs, "destFolder", 0, NULL);
102  if (s)
104 
105  tlist=Typemaker2_Type_List2_new();
106  rv=Typemaker2_TypeManager_LoadTypeFile2(tym, fname, tlist);
107  if (rv<0) {
108  DBG_ERROR(GWEN_LOGDOMAIN, "Unable to load file [%s] (%d)", fname, rv);
109  return 2;
110  }
111 
112  it=Typemaker2_Type_List2_First(tlist);
113  if (it) {
114  ty=Typemaker2_Type_List2Iterator_Data(it);
115  while (ty) {
116  /* DEBUG */
117 #if 0
118  Typemaker2_TypeManager_Dump(tym, stderr, 2);
119 #endif
120 
121  /* build */
122  rv=Typemaker2_Builder_Build(tb, ty);
123  if (rv<0) {
124  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
125  return 2;
126  }
127 
128  /* only write typedef files */
129  if (!noDefs) {
131  if (rv<0) {
132  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
133  return 2;
134  }
135  }
136 
137 
138  /* handle next type */
139  ty=Typemaker2_Type_List2Iterator_Next(it);
140  }
141  Typemaker2_Type_List2Iterator_free(it);
142 
143 
144  s=GWEN_DB_GetCharValue(dbArgs, "publicFile", 0, NULL);
145  if (s)
147 
148  s=GWEN_DB_GetCharValue(dbArgs, "libraryFile", 0, NULL);
149  if (s)
151 
152  s=GWEN_DB_GetCharValue(dbArgs, "protectedFile", 0, NULL);
153  if (s)
155 
156  s=GWEN_DB_GetCharValue(dbArgs, "privateFile", 0, NULL);
157  if (s)
159 
160  s=GWEN_DB_GetCharValue(dbArgs, "codeFile", 0, NULL);
161  if (s)
163 
164  ty=Typemaker2_Type_List2_GetFront(tlist);
166  if (rv<0) {
167  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
168  return 2;
169  }
170 
171  }
172  Typemaker2_Type_List2_free(tlist);
173 
174 
175  return 0;
176 }
177 
178 
179 #if 0
180 int buildFile(GWEN_DB_NODE *dbArgs, const char *fname)
181 {
184  TYPEMAKER2_TYPE *ty;
185  GWEN_STRINGLIST *sl;
186  const char *s;
187  int i;
188  int rv;
189 
191 
192  s=GWEN_DB_GetCharValue(dbArgs, "api", 0, NULL);
193  if (s && *s)
195 
196  s=GWEN_DB_GetCharValue(dbArgs, "language", 0, "c");
197  if (s && *s) {
199  if (strcasecmp(s, "c")==0) {
202  }
203  else {
204  DBG_ERROR(GWEN_LOGDOMAIN, "Unsupported language [%s]", s);
205  return 1;
206  }
207  }
208  else {
209  DBG_ERROR(GWEN_LOGDOMAIN, "Missing language specification");
210  return 1;
211  }
212 
214 
215  for (i=0; i<99; i++) {
216  s=GWEN_DB_GetCharValue(dbArgs, "include", i, NULL);
217  if (s && *s)
219  else
220  break;
221  }
222 
224  if (sl) {
226 
228  while (se) {
230  if (s) {
231  GWEN_BUFFER *xbuf;
232 
233  xbuf=GWEN_Buffer_new(0, 256, 0, 1);
234  GWEN_Buffer_AppendString(xbuf, s);
235  GWEN_Buffer_AppendString(xbuf, "/typemaker2/");
237  if (s && *s)
238  GWEN_Buffer_AppendString(xbuf, s);
240  GWEN_Buffer_free(xbuf);
241  }
243  }
245  }
246 
247  s=GWEN_DB_GetCharValue(dbArgs, "publicFile", 0, NULL);
248  if (s)
250 
251  s=GWEN_DB_GetCharValue(dbArgs, "libraryFile", 0, NULL);
252  if (s)
254 
255  s=GWEN_DB_GetCharValue(dbArgs, "protectedFile", 0, NULL);
256  if (s)
258 
259  s=GWEN_DB_GetCharValue(dbArgs, "privateFile", 0, NULL);
260  if (s)
262 
263  s=GWEN_DB_GetCharValue(dbArgs, "codeFile", 0, NULL);
264  if (s)
266 
267  s = GWEN_DB_GetCharValue(dbArgs, "destFolder", 0, NULL);
268  if (s)
270 
272  if (ty==NULL) {
273  DBG_ERROR(GWEN_LOGDOMAIN, "Unable to load file [%s]", fname);
274  return 2;
275  }
276 
277  /* DEBUG */
278 #if 0
279  Typemaker2_TypeManager_Dump(tym, stderr, 2);
280 #endif
281 
282  /* build */
283  rv=Typemaker2_Builder_Build(tb, ty);
284  if (rv<0) {
285  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
286  return 2;
287  }
288 
292  if (rv<0) {
293  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
294  return 2;
295  }
296 
297  return 0;
298 }
299 #endif
300 
301 
302 
303 int build(GWEN_DB_NODE *dbArgs)
304 {
305  int i;
306 
307  for (i=0; i<99; i++) {
308  const char *fileName;
309 
310  fileName=GWEN_DB_GetCharValue(dbArgs, "params", i, NULL);
311  if (fileName) {
312  int rv=buildFile2(dbArgs, fileName);
313  if (rv != 0) {
314  DBG_ERROR(GWEN_LOGDOMAIN, "Error building type from [%s]", fileName);
315  return 2;
316  }
317  }
318  else {
319  if (i==0) {
320  DBG_ERROR(GWEN_LOGDOMAIN, "No input");
321  return 1;
322  }
323  }
324  }
325 
326  return 0;
327 }
328 
329 
void Typemaker2_TypeManager_AddFolder(TYPEMAKER2_TYPEMANAGER *tym, const char *s)
void Typemaker2_Builder_SetFileNameProtected(TYPEMAKER2_BUILDER *tb, const char *s)
Definition: tm_builder.c:260
void Typemaker2_Builder_SetSourceFileName(TYPEMAKER2_BUILDER *tb, const char *s)
Definition: tm_builder.c:320
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:235
struct GWEN_STRINGLISTENTRYSTRUCT GWEN_STRINGLISTENTRY
Definition: stringlist.h:53
void Typemaker2_Builder_SetFileNameCode(TYPEMAKER2_BUILDER *tb, const char *s)
Definition: tm_builder.c:300
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
void Typemaker2_Builder_SetFileNameLibrary(TYPEMAKER2_BUILDER *tb, const char *s)
Definition: tm_builder.c:240
void Typemaker2_TypeManager_Dump(TYPEMAKER2_TYPEMANAGER *tym, FILE *f, int indent)
#define NULL
Definition: binreloc.c:300
#define TYPEMAKER2_BUILDER_WRITEFILE_FLAGS_WRITE_TYPE
Definition: tm_builder.h:23
#define GWEN_LOGDOMAIN
Definition: logger.h:35
int build(GWEN_DB_NODE *dbArgs)
Definition: build.c:303
void Typemaker2_Builder_SetTypeManager(TYPEMAKER2_BUILDER *tb, TYPEMAKER2_TYPEMANAGER *tm)
Definition: tm_builder.c:141
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition: buffer.c:42
GWEN_STRINGLISTENTRY * GWEN_StringList_FirstEntry(const GWEN_STRINGLIST *sl)
Definition: stringlist.c:390
const char * GWEN_StringListEntry_Data(const GWEN_STRINGLISTENTRY *se)
Definition: stringlist.c:406
void Typemaker2_Builder_SetDestFolderName(TYPEMAKER2_BUILDER *tb, const char *s)
Definition: tm_builder.c:340
void Typemaker2_Builder_SetFileNamePrivate(TYPEMAKER2_BUILDER *tb, const char *s)
Definition: tm_builder.c:280
void GWEN_StringList_free(GWEN_STRINGLIST *sl)
Definition: stringlist.c:62
int Typemaker2_TypeManager_LoadTypeFile2(TYPEMAKER2_TYPEMANAGER *tym, const char *fileName, TYPEMAKER2_TYPE_LIST2 *tlist2)
int Typemaker2_Builder_Build(TYPEMAKER2_BUILDER *tb, TYPEMAKER2_TYPE *ty)
Definition: tm_builder.c:360
int buildFile2(GWEN_DB_NODE *dbArgs, const char *fname)
Definition: build.c:24
struct GWEN_STRINGLISTSTRUCT GWEN_STRINGLIST
Definition: stringlist.h:56
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
Definition: db.c:971
GWEN_STRINGLIST * GWEN_PathManager_GetPaths(const char *destLib, const char *pathName)
Definition: pathmanager.c:494
struct TYPEMAKER2_BUILDER TYPEMAKER2_BUILDER
Definition: tm_builder.h:26
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition: buffer.c:89
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:38
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
void Typemaker2_Builder_SetFileNamePublic(TYPEMAKER2_BUILDER *tb, const char *s)
Definition: tm_builder.c:220
GWEN_STRINGLISTENTRY * GWEN_StringListEntry_Next(const GWEN_STRINGLISTENTRY *se)
Definition: stringlist.c:398
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)
int GWEN_DB_GetIntValue(GWEN_DB_NODE *n, const char *path, int idx, int defVal)
Definition: db.c:1163
void Typemaker2_TypeManager_SetLanguage(TYPEMAKER2_TYPEMANAGER *tym, const char *s)
const char * Typemaker2_TypeManager_GetLanguage(const TYPEMAKER2_TYPEMANAGER *tym)
#define TYPEMAKER2_BUILDER_WRITEFILE_FLAGS_WRITE_DEFS
Definition: tm_builder.h:22
int Typemaker2_Builder_WriteFiles(TYPEMAKER2_BUILDER *tb, TYPEMAKER2_TYPE *ty, uint32_t writeFlags)
Definition: tm_builder.c:1341
TYPEMAKER2_TYPE * Typemaker2_TypeManager_LoadTypeFile(TYPEMAKER2_TYPEMANAGER *tym, const char *fileName)
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition: buffer.c:989