summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2015-10-23 14:43:57 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2015-11-09 15:02:32 +0000
commit10883d080f100f47446873847df2ee30278f3d76 (patch)
tree2659b646e960157eafcd7823a758bd6910b35dda
parenta29d6aed6630c7d598695539ea85ca4535891e57 (diff)
eolian generator: refactor the main function (remove cruft)
-rw-r--r--src/bin/eolian/main.c204
1 files changed, 89 insertions, 115 deletions
diff --git a/src/bin/eolian/main.c b/src/bin/eolian/main.c
index 8b5d02d73e..3ea03695ec 100644
--- a/src/bin/eolian/main.c
+++ b/src/bin/eolian/main.c
@@ -48,7 +48,7 @@ _filename_get(const char *path)
48} 48}
49 49
50static Eina_Bool 50static Eina_Bool
51_read_file(char *filename, Eina_Strbuf **buf) 51_read_file(const char *filename, Eina_Strbuf **buf)
52{ 52{
53 FILE *fd = fopen(filename, "rb"); 53 FILE *fd = fopen(filename, "rb");
54 if (!fd) 54 if (!fd)
@@ -92,7 +92,7 @@ _read_file(char *filename, Eina_Strbuf **buf)
92} 92}
93 93
94static Eina_Bool 94static Eina_Bool
95_write_file(char *filename, const Eina_Strbuf *buffer, Eina_Bool append) 95_write_file(const char *filename, const Eina_Strbuf *buffer, Eina_Bool append)
96{ 96{
97 FILE *fd = fopen(filename, append ? "ab" : "wb"); 97 FILE *fd = fopen(filename, append ? "ab" : "wb");
98 if (!fd) 98 if (!fd)
@@ -109,7 +109,7 @@ _write_file(char *filename, const Eina_Strbuf *buffer, Eina_Bool append)
109} 109}
110 110
111static Eina_Bool 111static Eina_Bool
112_generate_header_file(char *filename, const char *eo_filename, Eina_Bool legacy) 112_generate_header_file(const char *filename, const char *eo_filename, Eina_Bool legacy)
113{ 113{
114 Eina_Bool ret = EINA_FALSE; 114 Eina_Bool ret = EINA_FALSE;
115 115
@@ -160,7 +160,7 @@ end:
160} 160}
161 161
162static Eina_Bool 162static Eina_Bool
163_generate_stub_header_file(char *filename, const char *eo_filename) 163_generate_stub_header_file(const char *filename, const char *eo_filename)
164{ 164{
165 Eina_Bool ret = EINA_FALSE; 165 Eina_Bool ret = EINA_FALSE;
166 166
@@ -190,7 +190,7 @@ end:
190} 190}
191 191
192static Eina_Bool 192static Eina_Bool
193_generate_c_file(char *filename, const char *eo_filename, Eina_Bool legacy_support) 193_generate_c_file(const char *filename, const char *eo_filename, Eina_Bool legacy_support)
194{ 194{
195 Eina_Bool ret = EINA_FALSE; 195 Eina_Bool ret = EINA_FALSE;
196 196
@@ -226,7 +226,7 @@ end:
226} 226}
227 227
228static Eina_Bool 228static Eina_Bool
229_generate_impl_c_file(char *filename, const char *eo_filename) 229_generate_impl_c_file(const char *filename, const char *eo_filename)
230{ 230{
231 const Eolian_Class *class = eolian_class_get_by_file(eo_filename); 231 const Eolian_Class *class = eolian_class_get_by_file(eo_filename);
232 if (!class) 232 if (!class)
@@ -251,80 +251,66 @@ _generate_impl_c_file(char *filename, const char *eo_filename)
251 251
252enum 252enum
253{ 253{
254 NO_WAY_GEN, 254 GEN_NOTHING = 0,
255 H_GEN, 255 GEN_H,
256 H_STUB_GEN, 256 GEN_H_STUB,
257 C_GEN, 257 GEN_C,
258 C_IMPL_GEN 258 GEN_C_IMPL
259}; 259};
260static int gen_opt = NO_WAY_GEN;
261static int legacy_support = 0;
262 260
263#define EO_SUFFIX ".eo" 261int
264#define EOT_SUFFIX ".eot" 262main(int argc, char **argv)
265
266int main(int argc, char **argv)
267{ 263{
268 int ret = 1; 264 int gen_what = GEN_NOTHING, do_legacy = 0, ret = 1;
269 Eina_Bool help = EINA_FALSE; 265 Eina_Bool help = EINA_FALSE;
270 const char *eo_filename = NULL; 266 const char *outf = NULL;
271 char *output_filename = NULL; /* if NULL, have to generate, otherwise use the name stored there */
272 char *eo_filename_copy = NULL, *eo_file_basename;
273 Eina_Bool is_eo = EINA_FALSE;
274 267
275 eina_init(); 268 eina_init();
276 eolian_init(); 269 eolian_init();
277 270
278 const char *log_dom = "eolian_gen"; 271 const char *dom = "eolian_gen";
279 _eolian_gen_log_dom = eina_log_domain_register(log_dom, EINA_COLOR_GREEN); 272 _eolian_gen_log_dom = eina_log_domain_register(dom, EINA_COLOR_GREEN);
280 if (_eolian_gen_log_dom < 0) 273 if (_eolian_gen_log_dom < 0)
281 { 274 {
282 EINA_LOG_ERR("Could not register log domain: %s", log_dom); 275 EINA_LOG_ERR("Could not register log domain: %s", dom);
283 goto end; 276 goto end;
284 } 277 }
285 278
286 eina_log_timing(_eolian_gen_log_dom, 279 eina_log_timing(_eolian_gen_log_dom, EINA_LOG_STATE_STOP, EINA_LOG_STATE_INIT);
287 EINA_LOG_STATE_STOP, 280
288 EINA_LOG_STATE_INIT); 281 struct option opts[] = {
289 282 { "help", no_argument, NULL, 'h' },
290 static struct option long_options[] = 283 { "gh", no_argument, &gen_what, GEN_H },
291 { 284 { "gc", no_argument, &gen_what, GEN_C },
292 /* These options set a flag. */ 285 { "gi", no_argument, &gen_what, GEN_C_IMPL },
293 {"help", no_argument, 0, 'h'}, 286 { "gs", no_argument, &gen_what, GEN_H_STUB },
294 {"gh", no_argument, &gen_opt, H_GEN}, 287 { "output", required_argument, NULL, 'o' },
295 {"gc", no_argument, &gen_opt, C_GEN}, 288 { "legacy", no_argument, &do_legacy, 1 },
296 {"gi", no_argument, &gen_opt, C_IMPL_GEN}, 289 { "include", required_argument, NULL, 'I' },
297 {"gs", no_argument, &gen_opt, H_STUB_GEN}, 290 { NULL, 0, NULL, 0 }
298 {"output", required_argument, 0, 'o'}, 291 };
299 {"legacy", no_argument, &legacy_support, 1}, 292
300 {"include", required_argument, 0, 'I'}, 293 for (int opt; (opt = getopt_long(argc, argv, "vho:I:", opts, NULL)) != -1; )
301 {0, 0, 0, 0} 294 switch (opt)
302 }; 295 {
303 int long_index =0, opt; 296 case 0: break;
304 while ((opt = getopt_long(argc, argv,"vho:I:", long_options, &long_index )) != -1) 297 case 'o':
305 { 298 outf = optarg;
306 switch (opt) { 299 break;
307 case 0: break; 300 case 'h':
308 case 'o': 301 help = EINA_TRUE;
309 { 302 break;
310 output_filename = strdup(optarg); 303 case 'I':
311 break; 304 if (!eolian_directory_scan(optarg))
312 } 305 {
313 case 'h': help = EINA_TRUE; break; 306 fprintf(stderr, "eolian: could not scan '%s'\n", optarg);
314 case 'I': 307 goto end;
315 { 308 }
316 const char *dir = optarg; 309 break;
317 if (!eolian_directory_scan(dir)) 310 default:
318 { 311 help = EINA_TRUE;
319 fprintf(stderr, "eolian: could not scan '%s'\n", dir); 312 break;
320 goto end; 313 }
321 }
322 break;
323 }
324 default: help = EINA_TRUE;
325 }
326 }
327 eo_filename = argv[optind++];
328 314
329 if (help) 315 if (help)
330 { 316 {
@@ -342,17 +328,16 @@ int main(int argc, char **argv)
342 goto end; 328 goto end;
343 } 329 }
344 330
345 if (!eo_filename) 331 const char *eof = argv[optind++];
332 if (!eof)
346 { 333 {
347 fprintf(stderr, "eolian: no input file specified\n"); 334 fprintf(stderr, "eolian: no input file\n");
348 goto end; 335 goto end;
349 } 336 }
350 337
351 is_eo = eina_str_has_suffix(eo_filename, EO_SUFFIX); 338 if (!eolian_file_parse(eof))
352
353 if (!eolian_file_parse(eo_filename))
354 { 339 {
355 fprintf(stderr, "eolian: error parsing file '%s'\n", eo_filename); 340 fprintf(stderr, "eolian: could not parse file '%s'\n", eof);
356 goto end; 341 goto end;
357 } 342 }
358 343
@@ -362,60 +347,49 @@ int main(int argc, char **argv)
362 goto end; 347 goto end;
363 } 348 }
364 349
365 eo_filename_copy = strdup(eo_filename); 350 char *eofc = strdup(eof);
366 eo_file_basename = basename(eo_filename_copy); 351 char *eobn = basename(eofc);
367 352
368 if (gen_opt) 353 if (gen_what)
369 { 354 {
370 if (!output_filename) 355 if (!outf)
371 { 356 {
372 fprintf(stderr, "eolian: no output file specified\n"); 357 fprintf(stderr, "eolian: no output file\n");
358 free(eofc);
373 goto end; 359 goto end;
374 } 360 }
375 switch (gen_opt) 361 switch (gen_what)
376 { 362 {
377 case H_GEN: 363 case GEN_H:
378 { 364 INF("Generating header file %s\n", outf);
379 INF("Generating header file %s\n", output_filename); 365 ret = !_generate_header_file(outf, eobn, do_legacy);
380 ret = !_generate_header_file(output_filename, eo_file_basename, legacy_support); 366 break;
381 break; 367 case GEN_H_STUB:
382 } 368 INF("Generating stub header file %s\n", outf);
383 case H_STUB_GEN: 369 ret = !_generate_stub_header_file(outf, eobn);
384 { 370 break;
385 INF("Generating stubs header file %s\n", output_filename); 371 case GEN_C:
386 ret = !_generate_stub_header_file(output_filename, eo_file_basename); 372 INF("Generating source file %s\n", outf);
387 break; 373 ret = !_generate_c_file(outf, eobn, do_legacy);
388 } 374 break;
389 case C_GEN: 375 case GEN_C_IMPL:
390 { 376 INF("Generating user source file %s\n", outf);
391 INF("Generating source file %s\n", output_filename); 377 ret = !_generate_impl_c_file(outf, eobn);
392 ret = !_generate_c_file(output_filename, eo_file_basename, !!legacy_support); 378 break;
393 break;
394 }
395 case C_IMPL_GEN:
396 {
397 INF("Generating user source file %s\n", output_filename);
398 ret = !_generate_impl_c_file(output_filename, eo_file_basename);
399 break;
400 }
401 default: 379 default:
402 ERR("Bad generation option\n"); 380 ERR("Wrong generation option\n");
403 break; 381 break;
404 } 382 }
405 } 383 }
406 else ret = 0; 384 else
385 ret = 0;
407 386
408end: 387 free(eofc);
409 free(eo_filename_copy);
410 free(output_filename);
411 388
412 eina_log_timing(_eolian_gen_log_dom, 389end:
413 EINA_LOG_STATE_START, 390 eina_log_timing(_eolian_gen_log_dom, EINA_LOG_STATE_START, EINA_LOG_STATE_SHUTDOWN);
414 EINA_LOG_STATE_SHUTDOWN);
415 eina_log_domain_unregister(_eolian_gen_log_dom); 391 eina_log_domain_unregister(_eolian_gen_log_dom);
416 _eolian_gen_log_dom = -1;
417
418 eolian_shutdown(); 392 eolian_shutdown();
419 eina_shutdown(); 393 eina_shutdown();
420 return ret; 394 return ret;
421} 395} \ No newline at end of file