summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2015-11-06 15:08:56 +0000
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2015-11-09 15:02:32 +0000
commit247c860aac234b2183c8c6d12f5f87dee4e23229 (patch)
tree349cb6db286fc374af8896814762b2b18579a04c
parent10883d080f100f47446873847df2ee30278f3d76 (diff)
eolian generator: finalize refactoring main.c
-rw-r--r--src/bin/eolian/main.c177
1 files changed, 88 insertions, 89 deletions
diff --git a/src/bin/eolian/main.c b/src/bin/eolian/main.c
index 3ea03695ec..66249e45f0 100644
--- a/src/bin/eolian/main.c
+++ b/src/bin/eolian/main.c
@@ -17,18 +17,21 @@
17static Eina_Strbuf * 17static Eina_Strbuf *
18_include_guard_enclose(const char *fname, const char *suffix, Eina_Strbuf *fbody) 18_include_guard_enclose(const char *fname, const char *suffix, Eina_Strbuf *fbody)
19{ 19{
20 if (!fbody || !eina_strbuf_string_get(fbody))
21 return fbody;
22
23 if (!suffix)
24 suffix = "";
25
20 char incname[255]; 26 char incname[255];
21 if (!fbody || !eina_strbuf_string_get(fbody)) return fbody;
22 memset(incname, 0, sizeof(incname)); 27 memset(incname, 0, sizeof(incname));
23 strncpy (incname, fname, sizeof(incname) - 1); 28 strncpy (incname, fname, sizeof(incname) - 1);
24 char *p = incname; 29 char *p = incname;
25 eina_str_toupper(&p); 30 eina_str_toupper(&p);
26 31
27 Eina_Strbuf *incguard = eina_strbuf_new(); 32 Eina_Strbuf *incguard = eina_strbuf_new();
28 eina_strbuf_append_printf(incguard, 33 eina_strbuf_append_printf(incguard, "#ifndef _%s_%s\n#define _%s_%s\n\n",
29 "#ifndef _%s_%s\n#define _%s_%s\n\n", 34 incname, suffix, incname, suffix);
30 incname, suffix?suffix:"",
31 incname, suffix?suffix:"");
32 eina_strbuf_replace_all(incguard, ".", "_"); 35 eina_strbuf_replace_all(incguard, ".", "_");
33 eina_strbuf_append(incguard, eina_strbuf_string_get(fbody)); 36 eina_strbuf_append(incguard, eina_strbuf_string_get(fbody));
34 eina_strbuf_append(incguard, "\n#endif\n"); 37 eina_strbuf_append(incguard, "\n#endif\n");
@@ -39,12 +42,12 @@ _include_guard_enclose(const char *fname, const char *suffix, Eina_Strbuf *fbody
39static const char * 42static const char *
40_filename_get(const char *path) 43_filename_get(const char *path)
41{ 44{
42 char *result = NULL; 45 if (!path)
43 46 return NULL;
44 if (!path) return NULL; 47 const char *ret = strrchr(path, '/');
45 if ((result = strrchr(path, '/'))) result++; 48 if (!ret)
46 else result = (char *)path; 49 return path;
47 return result; 50 return ret + 1;
48} 51}
49 52
50static Eina_Bool 53static Eina_Bool
@@ -109,143 +112,139 @@ _write_file(const char *filename, const Eina_Strbuf *buffer, Eina_Bool append)
109} 112}
110 113
111static Eina_Bool 114static Eina_Bool
112_generate_header_file(const char *filename, const char *eo_filename, Eina_Bool legacy) 115_generate_header(const char *outf, const char *inf, Eina_Bool legacy)
113{ 116{
114 Eina_Bool ret = EINA_FALSE; 117 Eina_Strbuf *buf = eina_strbuf_new();
115
116 Eina_Strbuf *buffer = eina_strbuf_new();
117 118
118 if (!types_header_generate(eo_filename, buffer, EINA_TRUE, legacy)) 119 if (!types_header_generate(inf, buf, EINA_TRUE, legacy))
119 { 120 {
120 fprintf(stderr, "eolian: could not generate types of '%s'\n", eo_filename); 121 fprintf(stderr, "eolian: could not generate types of '%s'\n", inf);
121 goto end; 122 eina_strbuf_free(buf);
122 } 123 return EINA_FALSE;
123 else
124 {
125 buffer = _include_guard_enclose(eo_filename, "TYPES", buffer);
126 } 124 }
127 125
126 buf = _include_guard_enclose(inf, "TYPES", buf);
127
128 Eina_Strbuf *ctbuf = eina_strbuf_new(); 128 Eina_Strbuf *ctbuf = eina_strbuf_new();
129 if (types_class_typedef_generate(eo_filename, ctbuf)) 129 if (types_class_typedef_generate(inf, ctbuf))
130 { 130 {
131 ctbuf = _include_guard_enclose(eo_filename, "CLASS_TYPE", ctbuf); 131 ctbuf = _include_guard_enclose(inf, "CLASS_TYPE", ctbuf);
132 eina_strbuf_append_char(ctbuf, '\n'); 132 eina_strbuf_append_char(ctbuf, '\n');
133 eina_strbuf_prepend(buffer, eina_strbuf_string_get(ctbuf)); 133 eina_strbuf_prepend(buf, eina_strbuf_string_get(ctbuf));
134 } 134 }
135 eina_strbuf_free(ctbuf); 135 eina_strbuf_free(ctbuf);
136 136
137 const Eolian_Class *class = eolian_class_get_by_file(eo_filename); 137 const Eolian_Class *cl = eolian_class_get_by_file(inf);
138 if (class) 138 if (cl)
139 { 139 {
140 Eina_Bool gret = legacy ? legacy_header_generate(class, buffer) 140 Eina_Bool gret = legacy ? legacy_header_generate(cl, buf)
141 : eo_header_generate(class, buffer); 141 : eo_header_generate(cl, buf);
142 if (!gret) 142 if (!gret)
143 { 143 {
144 fprintf(stderr, "eolian: could not generate header for '%s'\n", 144 fprintf(stderr, "eolian: could not generate header for '%s'\n",
145 eolian_class_name_get(class)); 145 eolian_class_name_get(cl));
146 goto end; 146 eina_strbuf_free(buf);
147 return EINA_FALSE;
147 } 148 }
148 } 149 }
149 150
150 if (class || !legacy) 151 if (cl || !legacy)
151 { 152 {
152 buffer = _include_guard_enclose(_filename_get(filename), NULL, buffer); 153 buf = _include_guard_enclose(_filename_get(outf), NULL, buf);
153 if (_write_file(filename, buffer, EINA_FALSE)) 154 if (_write_file(outf, buf, EINA_FALSE))
154 ret = EINA_TRUE; 155 {
156 eina_strbuf_free(buf);
157 return EINA_TRUE;
158 }
155 } 159 }
156end:
157 eina_strbuf_free(buffer);
158 160
159 return ret; 161 eina_strbuf_free(buf);
162 return EINA_FALSE;
160} 163}
161 164
162static Eina_Bool 165static Eina_Bool
163_generate_stub_header_file(const char *filename, const char *eo_filename) 166_generate_stub_header(const char *outf, const char *inf)
164{ 167{
165 Eina_Bool ret = EINA_FALSE; 168 Eina_Strbuf *buf = eina_strbuf_new();
166
167 Eina_Strbuf *buffer = eina_strbuf_new();
168 169
169 if (!types_header_generate(eo_filename, buffer, EINA_FALSE, EINA_FALSE)) 170 if (!types_header_generate(inf, buf, EINA_FALSE, EINA_FALSE))
170 { 171 {
171 fprintf(stderr, "eolian: could not generate types of '%s'\n", eo_filename); 172 fprintf(stderr, "eolian: could not generate types of '%s'\n", inf);
172 goto end; 173 eina_strbuf_free(buf);
174 return EINA_FALSE;
173 } 175 }
174 176
175 Eina_Strbuf *ctbuf = eina_strbuf_new(); 177 Eina_Strbuf *ctbuf = eina_strbuf_new();
176 if (types_class_typedef_generate(eo_filename, ctbuf)) 178 if (types_class_typedef_generate(inf, ctbuf))
177 { 179 {
178 eina_strbuf_append_char(ctbuf, '\n'); 180 eina_strbuf_append_char(ctbuf, '\n');
179 eina_strbuf_prepend(buffer, eina_strbuf_string_get(ctbuf)); 181 eina_strbuf_prepend(buf, eina_strbuf_string_get(ctbuf));
180 } 182 }
181 eina_strbuf_free(ctbuf); 183 eina_strbuf_free(ctbuf);
182 184
183 buffer = _include_guard_enclose(_filename_get(filename), "STUBS", buffer); 185 buf = _include_guard_enclose(_filename_get(outf), "STUBS", buf);
184 if (_write_file(filename, buffer, EINA_FALSE))
185 ret = EINA_TRUE;
186end:
187 eina_strbuf_free(buffer);
188 186
187 Eina_Bool ret = _write_file(outf, buf, EINA_FALSE);
188 eina_strbuf_free(buf);
189 return ret; 189 return ret;
190} 190}
191 191
192static Eina_Bool 192static Eina_Bool
193_generate_c_file(const char *filename, const char *eo_filename, Eina_Bool legacy_support) 193_generate_c(const char *outf, const char *inf, Eina_Bool legacy)
194{ 194{
195 Eina_Bool ret = EINA_FALSE; 195 Eina_Strbuf *eobuf = eina_strbuf_new(),
196 *lgbuf = eina_strbuf_new();
196 197
197 Eina_Strbuf *eo_buf = eina_strbuf_new(); 198 const Eolian_Class *cl = eolian_class_get_by_file(inf);
198 Eina_Strbuf *legacy_buf = eina_strbuf_new(); 199 if (cl)
199
200 const Eolian_Class *class = eolian_class_get_by_file(eo_filename);
201 if (class)
202 { 200 {
203 if (!eo_source_generate(class, eo_buf)) 201 if (!eo_source_generate(cl, eobuf))
204 { 202 {
205 fprintf(stderr, "eolian: could not generate source for '%s'\n", 203 fprintf(stderr, "eolian: could not generate source for '%s'\n",
206 eolian_class_name_get(class)); 204 eolian_class_name_get(cl));
207 goto end; 205 eina_strbuf_free(eobuf);
206 eina_strbuf_free(lgbuf);
207 return EINA_FALSE;
208 } 208 }
209 209
210 if (legacy_support) 210 if (legacy && !legacy_source_generate(cl, lgbuf))
211 if (!legacy_source_generate(class, legacy_buf)) 211 {
212 { 212 fprintf(stderr, "eolian: could not generate source for '%s'\n",
213 fprintf(stderr, "eolian: could not generate source for '%s'\n", 213 eolian_class_name_get(cl));
214 eolian_class_name_get(class)); 214 eina_strbuf_free(eobuf);
215 goto end; 215 eina_strbuf_free(lgbuf);
216 } 216 return EINA_FALSE;
217 }
217 } 218 }
218 219
219 if (_write_file(filename, eo_buf, EINA_FALSE) && 220 Eina_Bool ret = _write_file(outf, eobuf, EINA_FALSE) &&
220 _write_file(filename, legacy_buf, EINA_TRUE)) 221 _write_file(outf, lgbuf, EINA_TRUE);
221 ret = EINA_TRUE; 222 eina_strbuf_free(eobuf);
222end: 223 eina_strbuf_free(lgbuf);
223 eina_strbuf_free(legacy_buf);
224 eina_strbuf_free(eo_buf);
225 return ret; 224 return ret;
226} 225}
227 226
228static Eina_Bool 227static Eina_Bool
229_generate_impl_c_file(const char *filename, const char *eo_filename) 228_generate_impl(const char *outf, const char *inf)
230{ 229{
231 const Eolian_Class *class = eolian_class_get_by_file(eo_filename); 230 const Eolian_Class *cl = eolian_class_get_by_file(inf);
232 if (!class) 231 if (!cl)
233 return EINA_FALSE; 232 return EINA_FALSE;
234 233
235 Eina_Strbuf *buffer = NULL; 234 Eina_Strbuf *buf = NULL;
236 if (!_read_file(filename, &buffer)) 235 if (!_read_file(outf, &buf))
237 return EINA_FALSE; 236 return EINA_FALSE;
238 237
239 if (!impl_source_generate(class, buffer)) 238 if (!impl_source_generate(cl, buf))
240 { 239 {
241 fprintf(stderr, "eolian: could not generate source for '%s'\n", 240 fprintf(stderr, "eolian: could not generate source for '%s'\n",
242 eolian_class_name_get(class)); 241 eolian_class_name_get(cl));
243 eina_strbuf_free(buffer); 242 eina_strbuf_free(buf);
244 return EINA_FALSE; 243 return EINA_FALSE;
245 } 244 }
246 245
247 Eina_Bool ret = _write_file(filename, buffer, EINA_FALSE); 246 Eina_Bool ret = _write_file(outf, buf, EINA_FALSE);
248 eina_strbuf_free(buffer); 247 eina_strbuf_free(buf);
249 return ret; 248 return ret;
250} 249}
251 250
@@ -362,19 +361,19 @@ main(int argc, char **argv)
362 { 361 {
363 case GEN_H: 362 case GEN_H:
364 INF("Generating header file %s\n", outf); 363 INF("Generating header file %s\n", outf);
365 ret = !_generate_header_file(outf, eobn, do_legacy); 364 ret = !_generate_header(outf, eobn, do_legacy);
366 break; 365 break;
367 case GEN_H_STUB: 366 case GEN_H_STUB:
368 INF("Generating stub header file %s\n", outf); 367 INF("Generating stub header file %s\n", outf);
369 ret = !_generate_stub_header_file(outf, eobn); 368 ret = !_generate_stub_header(outf, eobn);
370 break; 369 break;
371 case GEN_C: 370 case GEN_C:
372 INF("Generating source file %s\n", outf); 371 INF("Generating source file %s\n", outf);
373 ret = !_generate_c_file(outf, eobn, do_legacy); 372 ret = !_generate_c(outf, eobn, do_legacy);
374 break; 373 break;
375 case GEN_C_IMPL: 374 case GEN_C_IMPL:
376 INF("Generating user source file %s\n", outf); 375 INF("Generating user source file %s\n", outf);
377 ret = !_generate_impl_c_file(outf, eobn); 376 ret = !_generate_impl(outf, eobn);
378 break; 377 break;
379 default: 378 default:
380 ERR("Wrong generation option\n"); 379 ERR("Wrong generation option\n");