gwenhywfar  4.99.8beta
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) {
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_LoadTypeFile2(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  /* build */
109  rv=Typemaker2_Builder_Build(tb, ty);
110  if (rv<0) {
111  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
112  return 2;
113  }
114 
115  /* only write typedef files */
116  rv=Typemaker2_Builder_WriteFiles(tb, ty, 1);
117  if (rv<0) {
118  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
119  return 2;
120  }
121 
122 
123  /* handle next type */
124  ty=Typemaker2_Type_List2Iterator_Next(it);
125  }
126  Typemaker2_Type_List2Iterator_free(it);
127 
128 
129  s=GWEN_DB_GetCharValue(dbArgs, "publicFile", 0, NULL);
130  if (s)
132 
133  s=GWEN_DB_GetCharValue(dbArgs, "libraryFile", 0, NULL);
134  if (s)
136 
137  s=GWEN_DB_GetCharValue(dbArgs, "protectedFile", 0, NULL);
138  if (s)
140 
141  s=GWEN_DB_GetCharValue(dbArgs, "privateFile", 0, NULL);
142  if (s)
144 
145  s=GWEN_DB_GetCharValue(dbArgs, "codeFile", 0, NULL);
146  if (s)
148 
149  s = GWEN_DB_GetCharValue(dbArgs, "destFolder", 0, NULL);
150  if (s)
152 
153  ty=Typemaker2_Type_List2_GetFront(tlist);
154  rv=Typemaker2_Builder_WriteFiles(tb, ty, 0);
155  if (rv<0) {
156  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
157  return 2;
158  }
159 
160  }
161  Typemaker2_Type_List2_free(tlist);
162 
163 
164  return 0;
165 }
166 
167 
168 
169 int buildFile(GWEN_DB_NODE *dbArgs, const char *fname) {
172  TYPEMAKER2_TYPE *ty;
173  GWEN_STRINGLIST *sl;
174  const char *s;
175  int i;
176  int rv;
177 
179 
180  s=GWEN_DB_GetCharValue(dbArgs, "api", 0, NULL);
181  if (s && *s)
183 
184  s=GWEN_DB_GetCharValue(dbArgs, "language", 0, "c");
185  if (s && *s) {
187  if (strcasecmp(s, "c")==0) {
190  }
191  else {
192  DBG_ERROR(GWEN_LOGDOMAIN, "Unsupported language [%s]", s);
193  return 1;
194  }
195  }
196  else {
197  DBG_ERROR(GWEN_LOGDOMAIN, "Missing language specification");
198  return 1;
199  }
200 
202 
203  for (i=0; i<99; i++) {
204  s=GWEN_DB_GetCharValue(dbArgs, "include", i, NULL);
205  if (s && *s)
207  else
208  break;
209  }
210 
212  if (sl) {
214 
216  while(se) {
218  if (s) {
219  GWEN_BUFFER *xbuf;
220 
221  xbuf=GWEN_Buffer_new(0, 256, 0, 1);
222  GWEN_Buffer_AppendString(xbuf, s);
223  GWEN_Buffer_AppendString(xbuf, "/typemaker2/");
225  if (s && *s)
226  GWEN_Buffer_AppendString(xbuf, s);
228  GWEN_Buffer_free(xbuf);
229  }
231  }
233  }
234 
235  s=GWEN_DB_GetCharValue(dbArgs, "publicFile", 0, NULL);
236  if (s)
238 
239  s=GWEN_DB_GetCharValue(dbArgs, "libraryFile", 0, NULL);
240  if (s)
242 
243  s=GWEN_DB_GetCharValue(dbArgs, "protectedFile", 0, NULL);
244  if (s)
246 
247  s=GWEN_DB_GetCharValue(dbArgs, "privateFile", 0, NULL);
248  if (s)
250 
251  s=GWEN_DB_GetCharValue(dbArgs, "codeFile", 0, NULL);
252  if (s)
254 
255  s = GWEN_DB_GetCharValue(dbArgs, "destFolder", 0, NULL);
256  if (s)
258 
260  if (ty==NULL) {
261  DBG_ERROR(GWEN_LOGDOMAIN, "Unable to load file [%s]", fname);
262  return 2;
263  }
264 
265  /* DEBUG */
266 #if 0
267  Typemaker2_TypeManager_Dump(tym, stderr, 2);
268 #endif
269 
270  /* build */
271  rv=Typemaker2_Builder_Build(tb, ty);
272  if (rv<0) {
273  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
274  return 2;
275  }
276 
277  rv=Typemaker2_Builder_WriteFiles(tb, ty, 0);
278  if (rv<0) {
279  DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
280  return 2;
281  }
282 
283  return 0;
284 }
285 
286 
287 
288 int build(GWEN_DB_NODE *dbArgs) {
289  int i;
290 
291  for (i=0; i<99; i++) {
292  const char *fileName;
293 
294  fileName=GWEN_DB_GetCharValue(dbArgs, "params", i, NULL);
295  if (fileName) {
296  int rv=buildFile2(dbArgs, fileName);
297  if (rv != 0) {
298  DBG_ERROR(GWEN_LOGDOMAIN, "Error building type from [%s]", fileName);
299  return 2;
300  }
301  }
302  else {
303  if (i==0) {
304  DBG_ERROR(GWEN_LOGDOMAIN, "No input");
305  return 1;
306  }
307  }
308  }
309 
310  return 0;
311 }
312 
313 
void Typemaker2_TypeManager_AddFolder(TYPEMAKER2_TYPEMANAGER *tym, const char *s)
void Typemaker2_Builder_SetFileNameProtected(TYPEMAKER2_BUILDER *tb, const char *s)
Definition: tm_builder.c:191
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
void Typemaker2_Builder_SetFileNameCode(TYPEMAKER2_BUILDER *tb, const char *s)
Definition: tm_builder.c:223
int buildFile(GWEN_DB_NODE *dbArgs, const char *fname)
Definition: build.c:169
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:175
void Typemaker2_TypeManager_Dump(TYPEMAKER2_TYPEMANAGER *tym, FILE *f, int indent)
#define NULL
Definition: binreloc.c:290
int Typemaker2_Builder_WriteFiles(TYPEMAKER2_BUILDER *tb, TYPEMAKER2_TYPE *ty, int defsOnly)
Definition: tm_builder.c:1163
#define GWEN_LOGDOMAIN
Definition: logger.h:35
int build(GWEN_DB_NODE *dbArgs)
Definition: build.c:288
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 Typemaker2_Builder_SetDestFolderName(TYPEMAKER2_BUILDER *tb, const char *s)
Definition: tm_builder.c:255
void Typemaker2_Builder_SetFileNamePrivate(TYPEMAKER2_BUILDER *tb, const char *s)
Definition: tm_builder.c:207
void GWEN_StringList_free(GWEN_STRINGLIST *sl)
Definition: stringlist.c:57
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:271
int buildFile2(GWEN_DB_NODE *dbArgs, const char *fname)
Definition: build.c:24
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
void Typemaker2_Builder_SetFileNamePublic(TYPEMAKER2_BUILDER *tb, const char *s)
Definition: tm_builder.c:159
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)
TYPEMAKER2_TYPE * Typemaker2_TypeManager_LoadTypeFile(TYPEMAKER2_TYPEMANAGER *tym, const char *fileName)
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition: buffer.c:1014