summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2017-11-10 14:46:00 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2017-11-10 14:48:59 +0100
commit753359230ab33e07f0c52acf943db75c692f8aa1 (patch)
tree8424b07764e728af56223171b154a9db4b0083d1 /src
parent7c0f1fdd34186220ca01d6b52b02b94cf6db9962 (diff)
eolian: more intuitive generation options and mrge impls into .c
Previously the output base name used to include extension, now you don't need to specify an extension and it's determined from the input file name instead. Also, implementation boilerplate used to merge with .eo.c before, which made no sense. Now it's merged with .c instead when it exists or makes a new .c file when it doesn't.
Diffstat (limited to 'src')
-rw-r--r--src/bin/eolian/main.c79
1 files changed, 58 insertions, 21 deletions
diff --git a/src/bin/eolian/main.c b/src/bin/eolian/main.c
index 20c53bc401..65ee41c5ba 100644
--- a/src/bin/eolian/main.c
+++ b/src/bin/eolian/main.c
@@ -44,19 +44,23 @@ _print_usage(const char *progn, FILE *outf)
44 " -v print version and exit\n" 44 " -v print version and exit\n"
45 "\n" 45 "\n"
46 "Available types:\n" 46 "Available types:\n"
47 " h: C header file (.h)\n" 47 " h: C header file (.eo.h/.eot.h)\n"
48 " l: Legacy C header file (.legacy.h)\n" 48 " l: Legacy C header file (.eo.legacy.h/.eot.legacy.h)\n"
49 " s: Stub C header file (.stub.h)\n" 49 " s: Stub C header file (.eo.stub.h/.eot.stub.h)\n"
50 " c: C source file (.c)\n" 50 " c: C source file (.eo.c)\n"
51 " i: Implementation file (added into .c)\n" 51 " i: Implementation file (.c, merged with existing)\n"
52 "\n" 52 "\n"
53 "By default, the 'hc' set is used ('h' for .eot files).\n" 53 "By default, the 'hc' set is used ('h' for .eot files).\n"
54 "Output filenames are determined from input .eo filename.\n" 54 "Output filenames are determined from input .eo filename.\n"
55 "Default filenames include input extension. (e.g. \".eo.c\")\n"
56 "Default output path is where the input file is.\n\n" 55 "Default output path is where the input file is.\n\n"
57 "Also, specifying a type-dependent input file automatically\n" 56 "Also, specifying a type-dependent input file automatically\n"
58 "adds it to generated files, so if you specify those, you\n" 57 "adds it to generated files, so if you specify those, you\n"
59 "don't need to explicitly specify -g for those types anymore.\n"); 58 "don't need to explicitly specify -g for those types anymore.\n\n"
59 "Explicit output base name is without extension. The extension\n"
60 "is determined from the input file name. If that is not possible\n"
61 "for some reason, it defaults to \".eo\". Obviously, this does not\n"
62 "affect specific filenames (-o x:y) as these are full names.\n"
63 "Implementation files are a special case (no \".eo\" added).\n");
60} 64}
61 65
62static void 66static void
@@ -100,20 +104,44 @@ _try_set_out(char t, char **outs, const char *val, int *what)
100 return EINA_TRUE; 104 return EINA_TRUE;
101} 105}
102 106
103static void _fill_all_outs(char **outs, const char *val) 107static void _fill_all_outs(char **outs, const char *val, char *base)
104{ 108{
105 size_t vlen = strlen(val); 109 const char *ext = strrchr(val, '.');
110 if (!ext)
111 ext = ".eo";
112
113 char *basen = base;
114 if (!basen)
115 {
116 basen = strdup(val);
117 char *p = strrchr(basen, '.');
118 if (p) *p = '\0';
119 }
120
121 size_t blen = strlen(basen),
122 elen = strlen(ext);
123
106 for (size_t i = 0; i < (sizeof(_dexts) / sizeof(char *)); ++i) 124 for (size_t i = 0; i < (sizeof(_dexts) / sizeof(char *)); ++i)
107 { 125 {
108 if (outs[i]) 126 if (outs[i])
109 continue; 127 continue;
110 size_t dlen = strlen(_dexts[i]); 128 size_t dlen = strlen(_dexts[i]);
111 char *str = malloc(vlen + dlen + 1); 129 char *str = malloc(blen + elen + dlen + 1);
112 memcpy(str, val, vlen); 130 char *p = str;
113 memcpy(str + vlen, _dexts[i], dlen); 131 memcpy(p, basen, blen);
114 str[vlen + dlen] = '\0'; 132 p += blen;
115 outs[i] = str; 133 if ((1 << i) != GEN_C_IMPL)
116 } 134 {
135 memcpy(p, ext, elen);
136 p += elen;
137 }
138 memcpy(p, _dexts[i], dlen);
139 p[dlen] = '\0';
140 outs[i] = str;
141 }
142
143 if (!base)
144 free(basen);
117} 145}
118 146
119static Eina_Strbuf * 147static Eina_Strbuf *
@@ -406,6 +434,7 @@ main(int argc, char **argv)
406 eina_log_timing(_eolian_gen_log_dom, EINA_LOG_STATE_STOP, EINA_LOG_STATE_INIT); 434 eina_log_timing(_eolian_gen_log_dom, EINA_LOG_STATE_STOP, EINA_LOG_STATE_INIT);
407 435
408 char *outs[5] = { NULL, NULL, NULL, NULL, NULL }; 436 char *outs[5] = { NULL, NULL, NULL, NULL, NULL };
437 char *basen = NULL;
409 438
410 int gen_what = 0; 439 int gen_what = 0;
411 for (int opt; (opt = getopt(argc, argv, "I:g:o:hv")) != -1;) 440 for (int opt; (opt = getopt(argc, argv, "I:g:o:hv")) != -1;)
@@ -459,7 +488,12 @@ main(int argc, char **argv)
459 goto end; 488 goto end;
460 } 489 }
461 } 490 }
462 else _fill_all_outs(outs, optarg); 491 else
492 {
493 if (basen)
494 free(basen);
495 basen = strdup(optarg);
496 }
463 break; 497 break;
464 case 'h': 498 case 'h':
465 _print_usage(argv[0], stdout); 499 _print_usage(argv[0], stdout);
@@ -495,7 +529,7 @@ main(int argc, char **argv)
495 goto end; 529 goto end;
496 } 530 }
497 531
498 _fill_all_outs(outs, input); 532 _fill_all_outs(outs, input, basen);
499 533
500 const char *eobn = _get_filename(input); 534 const char *eobn = _get_filename(input);
501 535
@@ -524,8 +558,11 @@ end:
524 eina_log_timing(_eolian_gen_log_dom, EINA_LOG_STATE_START, EINA_LOG_STATE_SHUTDOWN); 558 eina_log_timing(_eolian_gen_log_dom, EINA_LOG_STATE_START, EINA_LOG_STATE_SHUTDOWN);
525 eina_log_domain_unregister(_eolian_gen_log_dom); 559 eina_log_domain_unregister(_eolian_gen_log_dom);
526 } 560 }
561
527 for (size_t i = 0; i < (sizeof(_dexts) / sizeof(char *)); ++i) 562 for (size_t i = 0; i < (sizeof(_dexts) / sizeof(char *)); ++i)
528 free(outs[i]); 563 free(outs[i]);
564 free(basen);
565
529 eolian_shutdown(); 566 eolian_shutdown();
530 eina_shutdown(); 567 eina_shutdown();
531 568