gwenhywfar 5.12.0
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
24int doBuildDefs(GWEN_DB_NODE *dbArgs, const char *fname)
25{
30 TYPEMAKER2_TYPE_LIST2 *tlist;
31 TYPEMAKER2_TYPE_LIST2_ITERATOR *it;
32 const char *s;
33 int i;
34 int rv;
35
37
38 s=GWEN_DB_GetCharValue(dbArgs, "api", 0, NULL);
39 if (s && *s)
41
42 s=GWEN_DB_GetCharValue(dbArgs, "language", 0, "c");
43 if (s && *s) {
45 if (strcasecmp(s, "c")==0) {
48 }
49 else {
50 DBG_ERROR(GWEN_LOGDOMAIN, "Unsupported language [%s]", s);
51 return 1;
52 }
53 }
54 else {
55 DBG_ERROR(GWEN_LOGDOMAIN, "Missing language specification");
56 return 1;
57 }
58
59 s = GWEN_DB_GetCharValue(dbArgs, "destFolder", 0, NULL);
60 if (s)
62
63
65
66 for (i=0; i<99; i++) {
67 s=GWEN_DB_GetCharValue(dbArgs, "include", i, NULL);
68 if (s && *s)
70 else
71 break;
72 }
73
75 if (sl) {
77
79 while (se) {
81 if (s) {
82 GWEN_BUFFER *xbuf;
83
84 xbuf=GWEN_Buffer_new(0, 256, 0, 1);
86 GWEN_Buffer_AppendString(xbuf, "/typemaker2/");
88 if (s && *s)
91 GWEN_Buffer_free(xbuf);
92 }
94 }
96 }
97
98 tlist=Typemaker2_Type_List2_new();
100 if (rv<0) {
101 DBG_ERROR(GWEN_LOGDOMAIN, "Unable to load file [%s] (%d)", fname, rv);
102 return 2;
103 }
104
105 it=Typemaker2_Type_List2_First(tlist);
106 if (it) {
107 ty=Typemaker2_Type_List2Iterator_Data(it);
108 while (ty) {
109 /* DEBUG */
110#if 0
111 Typemaker2_TypeManager_Dump(tym, stderr, 2);
112#endif
113
114 /* only write typedef files */
116 if (rv<0) {
117 DBG_ERROR(GWEN_LOGDOMAIN, "here (%d)", rv);
118 return 2;
119 }
120
121
122 /* handle next type */
123 ty=Typemaker2_Type_List2Iterator_Next(it);
124 }
125 Typemaker2_Type_List2Iterator_free(it);
126 }
127 Typemaker2_Type_List2_free(tlist);
128
129
130 return 0;
131}
132
133
134
135
137{
138 int i;
139
140 for (i=0; i<99; i++) {
141 const char *fileName;
142
143 fileName=GWEN_DB_GetCharValue(dbArgs, "params", i, NULL);
144 if (fileName) {
145 int rv=doBuildDefs(dbArgs, fileName);
146 if (rv != 0) {
147 DBG_ERROR(GWEN_LOGDOMAIN, "Error building type from [%s]", fileName);
148 return 2;
149 }
150 }
151 else {
152 if (i==0) {
153 DBG_ERROR(GWEN_LOGDOMAIN, "No input");
154 GWEN_DB_Dump(dbArgs, 2);
155 return 1;
156 }
157 }
158 }
159
160 return 0;
161}
162
163
#define NULL
Definition binreloc.c:300
GWEN_BUFFER * GWEN_Buffer_new(char *buffer, uint32_t size, uint32_t used, int take)
Definition buffer.c:42
void GWEN_Buffer_free(GWEN_BUFFER *bf)
Definition buffer.c:89
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition buffer.c:992
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition buffer.c:235
int doBuildDefs(GWEN_DB_NODE *dbArgs, const char *fname)
Definition builddefs.c:24
int buildDefs(GWEN_DB_NODE *dbArgs)
Definition builddefs.c:136
const char * GWEN_DB_GetCharValue(GWEN_DB_NODE *n, const char *path, int idx, const char *defVal)
Definition db.c:971
void GWEN_DB_Dump(GWEN_DB_NODE *n, int insert)
Definition db.c:1420
struct GWEN_DB_NODE GWEN_DB_NODE
Definition db.h:228
#define DBG_ERROR(dbg_logger, format,...)
Definition debug.h:97
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition buffer.h:38
#define GWEN_PM_LIBNAME
Definition gwenhywfar.h:42
#define GWEN_PM_DATADIR
Definition gwenhywfar.h:56
#define GWEN_LOGDOMAIN
Definition logger.h:35
GWEN_STRINGLIST * GWEN_PathManager_GetPaths(const char *destLib, const char *pathName)
void GWEN_StringList_free(GWEN_STRINGLIST *sl)
Definition stringlist.c:62
const char * GWEN_StringListEntry_Data(const GWEN_STRINGLISTENTRY *se)
Definition stringlist.c:406
GWEN_STRINGLISTENTRY * GWEN_StringListEntry_Next(const GWEN_STRINGLISTENTRY *se)
Definition stringlist.c:398
GWEN_STRINGLISTENTRY * GWEN_StringList_FirstEntry(const GWEN_STRINGLIST *sl)
Definition stringlist.c:390
struct GWEN_STRINGLISTENTRYSTRUCT GWEN_STRINGLISTENTRY
Definition stringlist.h:53
struct GWEN_STRINGLISTSTRUCT GWEN_STRINGLIST
Definition stringlist.h:56
void Typemaker2_Builder_SetSourceFileName(TYPEMAKER2_BUILDER *tb, const char *s)
Definition tm_builder.c:320
void Typemaker2_Builder_SetTypeManager(TYPEMAKER2_BUILDER *tb, TYPEMAKER2_TYPEMANAGER *tm)
Definition tm_builder.c:141
void Typemaker2_Builder_SetDestFolderName(TYPEMAKER2_BUILDER *tb, const char *s)
Definition tm_builder.c:340
int Typemaker2_Builder_WriteFiles(TYPEMAKER2_BUILDER *tb, TYPEMAKER2_TYPE *ty, uint32_t writeFlags)
#define TYPEMAKER2_BUILDER_WRITEFILE_FLAGS_WRITE_DEFS
Definition tm_builder.h:22
struct TYPEMAKER2_BUILDER TYPEMAKER2_BUILDER
Definition tm_builder.h:26
TYPEMAKER2_BUILDER * Typemaker2_Builder_C_new()
struct TYPEMAKER2_TYPE TYPEMAKER2_TYPE
Definition tm_type.h:21
void Typemaker2_TypeManager_AddFolder(TYPEMAKER2_TYPEMANAGER *tym, const char *s)
void Typemaker2_TypeManager_SetLanguage(TYPEMAKER2_TYPEMANAGER *tym, const char *s)
int Typemaker2_TypeManager_LoadTypeFileNoLookup(TYPEMAKER2_TYPEMANAGER *tym, const char *fileName, TYPEMAKER2_TYPE_LIST2 *tlist2)
void Typemaker2_TypeManager_SetApiDeclaration(TYPEMAKER2_TYPEMANAGER *tym, const char *s)
const char * Typemaker2_TypeManager_GetLanguage(const TYPEMAKER2_TYPEMANAGER *tym)
TYPEMAKER2_TYPEMANAGER * Typemaker2_TypeManager_new()
void Typemaker2_TypeManager_Dump(TYPEMAKER2_TYPEMANAGER *tym, FILE *f, int indent)
struct TYPEMAKER2_TYPEMANAGER TYPEMAKER2_TYPEMANAGER