gwenhywfar 5.14.1
typemaker2/main.c
Go to the documentation of this file.
1
2
3#include "typemaker2.h"
4
5#include <gwenhywfar/args.h>
6#include <gwenhywfar/debug.h>
7#include <gwenhywfar/cgui.h>
8#include <gwenhywfar/db.h>
9#include <gwenhywfar/gwenhywfar.h>
10
11
12#define I18N(msg) msg
13
14
15
16
17int main(int argc, char **argv)
18{
19 GWEN_DB_NODE *db;
20 int rv;
21 int err;
22 int defsOnly=0;
23 GWEN_GUI *gui;
24 const GWEN_ARGS args[]= {
25 {
27 GWEN_ArgsType_Char, /* type */
28 "api", /* name */
29 0, /* minnum */
30 1, /* maxnum */
31 "D", /* short option */
32 "api", /* long option */
33 "API declaration prefix (like GWENHYWFAR_API)",
34 "API declaration prefix (like GWENHYWFAR_API)"
35 },
36 {
38 GWEN_ArgsType_Char, /* type */
39 "publicFile", /* name */
40 0, /* minnum */
41 1, /* maxnum */
42 0, /* short option */
43 "public", /* long option */
44 "Name of the public header file to create",
45 "Name of the public header file to create"
46 },
47 {
49 GWEN_ArgsType_Char, /* type */
50 "libraryFile", /* name */
51 0, /* minnum */
52 1, /* maxnum */
53 0, /* short option */
54 "library", /* long option */
55 "Name of the library header file to create",
56 "Name of the library header file to create"
57 },
58 {
60 GWEN_ArgsType_Char, /* type */
61 "protectedFile", /* name */
62 0, /* minnum */
63 1, /* maxnum */
64 0, /* short option */
65 "protected", /* long option */
66 "Name of the protected header file to create",
67 "Name of the protected header file to create"
68 },
69 {
71 GWEN_ArgsType_Char, /* type */
72 "privateFile", /* name */
73 0, /* minnum */
74 1, /* maxnum */
75 0, /* short option */
76 "private", /* long option */
77 "Name of the private header file to create",
78 "Name of the private header file to create"
79 },
80 {
82 GWEN_ArgsType_Char, /* type */
83 "codeFile", /* name */
84 0, /* minnum */
85 1, /* maxnum */
86 0, /* short option */
87 "code", /* long option */
88 "Name of the code file to create",
89 "Name of the code file to create"
90 },
91 {
93 GWEN_ArgsType_Char, /* type */
94 "destFolder", /* name */
95 0, /* minnum */
96 1, /* maxnum */
97 0, /* short option */
98 "destfolder", /* long option */
99 "Destination folder",
100 "Destination folder"
101 },
102 {
104 GWEN_ArgsType_Char, /* type */
105 "language", /* name */
106 0, /* minnum */
107 1, /* maxnum */
108 0, /* short option */
109 "lang", /* long option */
110 "Language for which to create the headers and code",
111 "Language for which to create the headers and code"
112 },
113 {
115 GWEN_ArgsType_Char, /* type */
116 "include", /* name */
117 0, /* minnum */
118 99, /* maxnum */
119 "I", /* short option */
120 "include", /* long option */
121 "Add folder to include for type lookup",
122 "Add folder to include for type lookup"
123 },
124 {
125 0, /* flags */
126 GWEN_ArgsType_Int, /* type */
127 "defsOnly", /* name */
128 0, /* minnum */
129 1, /* maxnum */
130 "d", /* short option */
131 "defs-only", /* long option */
132 "Only write def files (*.tm2)",
133 "Only write def files (*.tm2)"
134 },
135 {
136 0, /* flags */
137 GWEN_ArgsType_Int, /* type */
138 "noDefs", /* name */
139 0, /* minnum */
140 1, /* maxnum */
141 NULL, /* short option */
142 "no-defs", /* long option */
143 "Dont write def files (*.tm2)",
144 "Dont write def files (*.tm2)"
145 },
146
147 {
149 GWEN_ArgsType_Int, /* type */
150 "help", /* name */
151 0, /* minnum */
152 0, /* maxnum */
153 "h", /* short option */
154 "help", /* long option */
155 "Show this help screen", /* short description */
156 "Show this help screen" /* long description */
157 }
158 };
159
160 err=GWEN_Init();
161 if (err) {
162 fprintf(stderr, "Could not initialize Gwenhywfar.\n");
163 return 2;
164 }
165
166 gui=GWEN_Gui_CGui_new();
167 GWEN_Gui_SetGui(gui);
168
169 GWEN_Logger_Open(0, "typemaker2", 0,
172
173 db=GWEN_DB_Group_new("arguments");
174 rv=GWEN_Args_Check(argc, argv, 1,
176 args,
177 db);
178 if (rv==GWEN_ARGS_RESULT_ERROR) {
179 fprintf(stderr, "ERROR: Could not parse arguments main\n");
180 return -1;
181 }
182 else if (rv==GWEN_ARGS_RESULT_HELP) {
183 GWEN_BUFFER *ubuf;
184
185 ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
187 I18N("Usage: "));
188 GWEN_Buffer_AppendString(ubuf, argv[0]);
190 I18N(" [GLOBAL OPTIONS] COMMAND "
191 "[LOCAL OPTIONS]\n"));
193 I18N("\nGlobal Options:\n"));
194 if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
195 fprintf(stderr, "ERROR: Could not create help string\n");
196 return 1;
197 }
199 I18N("\nCommands:\n\n"));
201 I18N(" build:\n"
202 " This command creates source and header files for the given file"
203 "\n\n"));
204
205 fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
206 GWEN_Buffer_free(ubuf);
207 return 0;
208 }
209 if (rv) {
210 argc-=rv-1;
211 argv+=rv-1;
212 }
213
214 defsOnly=GWEN_DB_GetIntValue(db, "defsOnly", 0, 0);
215
216 if (defsOnly)
217 rv=buildDefs(db);
218 else
219 rv=build(db);
220
221 err=GWEN_Fini();
222 if (err) {
223 fprintf(stderr,
224 "WARNING: Could not deinitialize Gwenhywfar.\n");
225 }
226
227 return rv;
228}
229
#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 build(GWEN_DB_NODE *dbArgs)
Definition build.c:303
int buildDefs(GWEN_DB_NODE *dbArgs)
Definition builddefs.c:136
GWEN_GUI * GWEN_Gui_CGui_new(void)
Definition cgui.c:77
GWEN_DB_NODE * GWEN_DB_Group_new(const char *name)
Definition db.c:173
int GWEN_DB_GetIntValue(GWEN_DB_NODE *n, const char *path, int idx, int defVal)
Definition db.c:1163
struct GWEN_DB_NODE GWEN_DB_NODE
Definition db.h:228
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition buffer.h:38
void GWEN_Gui_SetGui(GWEN_GUI *gui)
Definition gui.c:170
struct GWEN_GUI GWEN_GUI
Definition gui.h:176
int GWEN_Init(void)
Definition gwenhywfar.c:92
int GWEN_Fini(void)
Definition gwenhywfar.c:303
int GWEN_Logger_Open(const char *logDomain, const char *ident, const char *file, GWEN_LOGGER_LOGTYPE logtype, GWEN_LOGGER_FACILITY facility)
Definition logger.c:281
@ GWEN_LoggerType_Console
Definition logger.h:41
@ GWEN_LoggerFacility_User
Definition logger.h:55
int GWEN_Args_Check(int argc, char **argv, int startAt, uint32_t mode, const GWEN_ARGS *args, GWEN_DB_NODE *db)
int GWEN_Args_Usage(const GWEN_ARGS *args, GWEN_BUFFER *ubuf, GWEN_ARGS_OUTTYPE ot)
#define GWEN_ARGS_FLAGS_HAS_ARGUMENT
#define GWEN_ARGS_RESULT_ERROR
#define GWEN_ARGS_MODE_ALLOW_FREEPARAM
#define GWEN_ARGS_FLAGS_HELP
#define GWEN_ARGS_FLAGS_LAST
@ GWEN_ArgsOutType_Txt
@ GWEN_ArgsType_Int
@ GWEN_ArgsType_Char
#define GWEN_ARGS_RESULT_HELP
int main(int argc, char **argv)
#define I18N(msg)