diff options
Diffstat (limited to '')
-rw-r--r-- | src/bin/eolian/main.c | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/src/bin/eolian/main.c b/src/bin/eolian/main.c index 754f6e8bb8..6fe3e9d705 100644 --- a/src/bin/eolian/main.c +++ b/src/bin/eolian/main.c | |||
@@ -13,6 +13,24 @@ | |||
13 | static int eo_version = 0; | 13 | static int eo_version = 0; |
14 | static Eina_Bool legacy_support = EINA_FALSE; | 14 | static Eina_Bool legacy_support = EINA_FALSE; |
15 | 15 | ||
16 | static char* | ||
17 | _include_guard_enclose(const char *fname, const char *fbody) | ||
18 | { | ||
19 | char incname[0xFF]; | ||
20 | strcpy (incname, fname); | ||
21 | char *p = incname; | ||
22 | eina_str_toupper(&p); | ||
23 | |||
24 | Eina_Strbuf *incguard = eina_strbuf_new(); | ||
25 | eina_strbuf_append_printf(incguard, | ||
26 | "#ifndef _%s_\n#define _%s_\n\n_code_\n#endif", | ||
27 | incname, | ||
28 | incname); | ||
29 | eina_strbuf_replace_all(incguard, ".", "_"); | ||
30 | eina_strbuf_replace_all(incguard, "_code_", fbody); | ||
31 | return eina_strbuf_string_steal(incguard); | ||
32 | } | ||
33 | |||
16 | static Eina_Bool | 34 | static Eina_Bool |
17 | _generate_h_file(char *filename, const char *classname, Eina_Bool append) | 35 | _generate_h_file(char *filename, const char *classname, Eina_Bool append) |
18 | { | 36 | { |
@@ -44,6 +62,7 @@ _generate_h_file(char *filename, const char *classname, Eina_Bool append) | |||
44 | goto end; | 62 | goto end; |
45 | } | 63 | } |
46 | } | 64 | } |
65 | |||
47 | const char *htext = eina_strbuf_string_get(hfile); | 66 | const char *htext = eina_strbuf_string_get(hfile); |
48 | 67 | ||
49 | FILE* fd = fopen(filename, "w"); | 68 | FILE* fd = fopen(filename, "w"); |
@@ -52,7 +71,14 @@ _generate_h_file(char *filename, const char *classname, Eina_Bool append) | |||
52 | ERR ("Couldn't open file %s for writing", filename); | 71 | ERR ("Couldn't open file %s for writing", filename); |
53 | goto end; | 72 | goto end; |
54 | } | 73 | } |
55 | if (htext) fputs(htext, fd); | 74 | |
75 | if (htext) | ||
76 | { | ||
77 | char *fcontent = _include_guard_enclose(ecore_file_file_get(filename), htext); | ||
78 | fputs(fcontent, fd); | ||
79 | free(fcontent); | ||
80 | } | ||
81 | |||
56 | fclose(fd); | 82 | fclose(fd); |
57 | 83 | ||
58 | ret = EINA_TRUE; | 84 | ret = EINA_TRUE; |
@@ -117,7 +143,7 @@ _generate_legacy_header_file(char *filename, const char *classname, Eina_Bool ap | |||
117 | } | 143 | } |
118 | else | 144 | else |
119 | { | 145 | { |
120 | if (!eo1_header_generate(classname, lfile)) | 146 | if (!legacy_header_generate(classname, eo_version, lfile)) |
121 | { | 147 | { |
122 | ERR("Failed to generate header for %s", classname); | 148 | ERR("Failed to generate header for %s", classname); |
123 | goto end; | 149 | goto end; |
@@ -130,8 +156,16 @@ _generate_legacy_header_file(char *filename, const char *classname, Eina_Bool ap | |||
130 | ERR ("Couldnt open file %s for writing", filename); | 156 | ERR ("Couldnt open file %s for writing", filename); |
131 | goto end; | 157 | goto end; |
132 | } | 158 | } |
159 | |||
133 | const char *ltext = eina_strbuf_string_get(lfile); | 160 | const char *ltext = eina_strbuf_string_get(lfile); |
134 | if (ltext) fputs(ltext, fd); | 161 | |
162 | if (ltext) | ||
163 | { | ||
164 | char *fcontent = _include_guard_enclose(ecore_file_file_get(filename), ltext); | ||
165 | fputs(fcontent, fd); | ||
166 | free(fcontent); | ||
167 | } | ||
168 | |||
135 | fclose(fd); | 169 | fclose(fd); |
136 | 170 | ||
137 | ret = EINA_TRUE; | 171 | ret = EINA_TRUE; |
@@ -222,7 +256,6 @@ int main(int argc, char **argv) | |||
222 | {"gc", no_argument, &gen_opt, C_GEN}, | 256 | {"gc", no_argument, &gen_opt, C_GEN}, |
223 | {"ah", no_argument, &gen_opt, H_EO_APP}, | 257 | {"ah", no_argument, &gen_opt, H_EO_APP}, |
224 | {"al", no_argument, &gen_opt, H_LEG_APP}, | 258 | {"al", no_argument, &gen_opt, H_LEG_APP}, |
225 | {"gle", no_argument, &gen_opt, H_LEG_EO_GEN}, | ||
226 | {"output", required_argument, 0, 'o'}, | 259 | {"output", required_argument, 0, 'o'}, |
227 | {"legacy", no_argument, (int *)&legacy_support, EINA_TRUE}, | 260 | {"legacy", no_argument, (int *)&legacy_support, EINA_TRUE}, |
228 | {"include", required_argument, 0, 'I'}, | 261 | {"include", required_argument, 0, 'I'}, |
@@ -281,7 +314,6 @@ int main(int argc, char **argv) | |||
281 | printf(" --gc Generate c source file [.c]\n"); | 314 | printf(" --gc Generate c source file [.c]\n"); |
282 | printf(" --ah Append eo class definitions to an existing c header file [.h]\n"); | 315 | printf(" --ah Append eo class definitions to an existing c header file [.h]\n"); |
283 | printf(" --al Append legacy function definitions to an existing c header file [.h]\n"); | 316 | printf(" --al Append legacy function definitions to an existing c header file [.h]\n"); |
284 | printf(" --gle Generate eo and legacy file [.h]\n"); | ||
285 | printf(" --legacy Generate legacy\n"); | 317 | printf(" --legacy Generate legacy\n"); |
286 | ret = 0; | 318 | ret = 0; |
287 | goto end; | 319 | goto end; |
@@ -343,7 +375,10 @@ int main(int argc, char **argv) | |||
343 | case H_GEN: case H_EO_APP: | 375 | case H_GEN: case H_EO_APP: |
344 | { | 376 | { |
345 | INF("%s header file %s\n", (gen_opt == H_EO_APP) ? "Appending" : "Generating", output_filename); | 377 | INF("%s header file %s\n", (gen_opt == H_EO_APP) ? "Appending" : "Generating", output_filename); |
346 | ret = (_generate_h_file(output_filename, classname, gen_opt == H_EO_APP)?0:1); | 378 | if (legacy_support) |
379 | ret = ( _generate_legacy_header_file(output_filename, classname, EINA_FALSE) ? 0 : 1 ); | ||
380 | else | ||
381 | ret = ( _generate_h_file(output_filename, classname, EINA_FALSE) ? 0 : 1 ); | ||
347 | break; | 382 | break; |
348 | } | 383 | } |
349 | case H_LEG_APP: | 384 | case H_LEG_APP: |