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