summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@samsung.com>2014-02-13 16:21:25 +0200
committerDaniel Zaoui <daniel.zaoui@samsung.com>2014-03-03 14:09:54 +0200
commit327202ef371814f6e61bae77d43990198edf1363 (patch)
treed5ac7b6fe25f0e87484f83e32b1d808542e40bd9 /src/bin
parentfabea6399c23fba336aa016d04f94fb24bf9c27d (diff)
Eolian/Generator: port options to getopt
Even if we want to remove the appending options, we still support them. We will remove them later.
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/eolian/main.c180
1 files changed, 69 insertions, 111 deletions
diff --git a/src/bin/eolian/main.c b/src/bin/eolian/main.c
index c47376de6e..08d0bae989 100644
--- a/src/bin/eolian/main.c
+++ b/src/bin/eolian/main.c
@@ -1,3 +1,5 @@
1#include <getopt.h>
2
1#include <Eina.h> 3#include <Eina.h>
2#include <Ecore_File.h> 4#include <Ecore_File.h>
3 5
@@ -146,7 +148,7 @@ end:
146int main(int argc, char **argv) 148int main(int argc, char **argv)
147{ 149{
148 eina_init(); 150 eina_init();
149 int i, ret = 0; 151 int ret = 0;
150 Eina_Bool help = EINA_FALSE, show = EINA_FALSE; 152 Eina_Bool help = EINA_FALSE, show = EINA_FALSE;
151 Eina_List *files = NULL, *itr; 153 Eina_List *files = NULL, *itr;
152 Eina_List *classes = NULL; 154 Eina_List *classes = NULL;
@@ -157,123 +159,79 @@ int main(int argc, char **argv)
157 Eina_Bool happend = EINA_FALSE; 159 Eina_Bool happend = EINA_FALSE;
158 Eina_Bool lappend = EINA_FALSE; 160 Eina_Bool lappend = EINA_FALSE;
159 161
160 for(i = 1; i < argc; i++) 162 static struct option long_options[] =
161 { 163 {
162 if (!strcmp(argv[i], "-eo1")) 164 /* These options set a flag. */
163 { 165 {"eo1", no_argument, &eo_version, 1},
164 eo_version = 1; 166 {"eo2", no_argument, &eo_version, 2},
165 continue; 167 {"verbose", no_argument, 0, 'V'},
166 } 168 {"help", no_argument, 0, 'h'},
167 if (!strcmp(argv[i], "-eo2")) 169 {"gh", required_argument, 0, 1},
168 { 170 {"gc", required_argument, 0, 2},
169 eo_version = 2; 171 {"ah", required_argument, 0, 3},
170 continue; 172 {"al", required_argument, 0, 4},
171 } 173 {"gle", required_argument, 0, 5},
172 if (!strcmp(argv[i], "-gh") && (i < (argc-1))) 174 {"include", required_argument, 0, 'I'},
173 { 175 {"class", required_argument, 0, 'c'},
174 h_filename = argv[i + 1]; 176 {0, 0, 0, 0}
175 continue; 177 };
176 } 178 int long_index =0, opt;
177 if (!strcmp(argv[i], "-gc") && (i < (argc-1))) 179 while ((opt = getopt_long(argc, argv,"Vho:I:c:", long_options, &long_index )) != -1)
178 { 180 {
179 c_filename = argv[i + 1]; 181 switch (opt) {
180 continue; 182 case 0: break;
181 } 183 case 1: h_filename = optarg; break;
182 if (!strcmp(argv[i], "-gl") && (i < (argc-1))) 184 case 2: c_filename = optarg; break;
183 { 185 case 3: h_filename = optarg; happend = EINA_TRUE; break;
184 leg_filename = argv[i + 1]; 186 case 4: leg_filename = optarg; lappend = EINA_TRUE; break;
185 continue; 187 case 5: eoleg_filename = optarg; break;
186 } 188 case 'V': show = EINA_TRUE; break;
187 if (!strcmp(argv[i], "-gle") && (i < (argc-1))) 189 case 'h': help = EINA_TRUE; break;
188 { 190 case 'I':
189 eoleg_filename = argv[i + 1]; 191 {
190 continue; 192 printf("%s\n", optarg);
191 } 193 char *dir = ecore_file_realpath(optarg);
192 if (!strcmp(argv[i], "-ah") && (i < (argc-1))) 194 if (strlen(dir) != 0)
193 { 195 {
194 h_filename = argv[i + 1]; 196 if (ecore_file_is_dir(dir))
195 happend = EINA_TRUE; 197 {
196 continue; 198 Eina_List *dir_files;
197 } 199 char *file;
198 if (!strcmp(argv[i], "-al") && (i < (argc-1))) 200 /* Get all files from directory. Not recursively!!!*/
199 { 201 dir_files = ecore_file_ls(dir);
200 leg_filename = argv[i + 1]; 202 EINA_LIST_FREE(dir_files, file)
201 lappend = EINA_TRUE; 203 {
202 continue; 204 char *filepath = malloc(strlen(dir) + 1 + strlen(file) + 1);
203 } 205 sprintf(filepath, "%s/%s", dir, file);
204 if (!strcmp(argv[i], "--class") && (i < (argc-1))) 206 if ((!ecore_file_is_dir(filepath)) && eina_str_has_suffix(filepath, EO_SUFFIX))
205 { 207 {
206 classes = eina_list_append(classes, argv[i + 1]); 208 /* Allocated string will be freed during deletion of "files" list. */
207 continue; 209 files = eina_list_append(files, strdup(filepath));
208 } 210 }
209 if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) 211 free(filepath);
210 { 212 free(file);
211 help = EINA_TRUE; 213 }
212 continue; 214 }
213 } 215 }
214 if (!strcmp(argv[i], "--show")) 216 free(dir);
215 { 217 break;
216 show = EINA_TRUE; 218 }
217 continue; 219 case 'c': classes = eina_list_append(classes, optarg); break;
218 } 220 default: help = EINA_TRUE;
219 /* Directory parameter found. */ 221 }
220 if ((!strcmp(argv[i], "-d") || !strcmp(argv[i], "--dir")) && (i < (argc-1)))
221 {
222 i++;
223 char *dir = ecore_file_realpath(argv[i]);
224 if (strlen(dir) != 0)
225 {
226 if (ecore_file_is_dir(dir))
227 {
228 Eina_List *dir_files;
229 char *file;
230 /* Get all files from directory. Not recursively!!!*/
231 dir_files = ecore_file_ls(dir);
232 EINA_LIST_FREE(dir_files, file)
233 {
234 char *filepath = malloc(strlen(dir) + 1 + strlen(file) + 1);
235 sprintf(filepath, "%s/%s", dir, file);
236 if ((!ecore_file_is_dir(filepath)) && eina_str_has_suffix(filepath, EO_SUFFIX))
237 {
238 /* Allocated string will be freed during deletion of "files" list. */
239 files = eina_list_append(files, strdup(filepath));
240 }
241 free(filepath);
242 free(file);
243 }
244 }
245 }
246 free(dir);
247 continue;
248 }
249 if ((!strcmp(argv[i], "-f") || !strcmp(argv[i], "--file")) && (i < (argc-1)))
250 {
251 i++;
252 char *realpath = ecore_file_realpath(argv[i]);
253 if (strlen(realpath) != 0)
254 {
255 if (!ecore_file_is_dir(realpath))
256 {
257 if (eina_str_has_suffix(realpath, EO_SUFFIX))
258 files = eina_list_append(files, strdup(realpath));
259 }
260 }
261 free(realpath);
262 continue;
263 }
264 } 222 }
265 223
266 if (eina_list_count(classes)) classname = eina_list_data_get(classes); 224 if (eina_list_count(classes)) classname = eina_list_data_get(classes);
267 225
268 if (!files || help || !classname) 226 if (!files || help || !classname)
269 { 227 {
270 printf("Usage: %s [-h/--help] [--show] [-d/--dir input_dir] [-f/--file input_file] [-gh|-gc|-ah] filename [--class] classname \n", argv[0]); 228 printf("Usage: %s [-h/--help] [-V/--verbose] [-I/--include input_dir] [--gh|--gc|--ah] filename [-c/--class] classname \n", argv[0]);
271 printf(" -eo1/-eo2 Set generator to eo1/eo2 mode. Must be specified\n"); 229 printf(" --eo1/--eo2 Set generator to eo1/eo2 mode. Must be specified\n");
272 printf(" -gh Generate c header file [.h] for eo class specified by classname\n"); 230 printf(" --gh Generate c header file [.h] for eo class specified by classname\n");
273 printf(" -gc Generate c source file [.c] for eo class specified by classname\n"); 231 printf(" --gc Generate c source file [.c] for eo class specified by classname\n");
274 printf(" -ah Append eo class definitions to an existing c header file [.h]\n"); 232 printf(" --ah Append eo class definitions to an existing c header file [.h]\n");
275 printf(" -al Append legacy function definitions to an existing c header file [.h]\n"); 233 printf(" --al Append legacy function definitions to an existing c header file [.h]\n");
276 printf(" -gle Generate eo and legacy file [.h]\n"); 234 printf(" --gle Generate eo and legacy file [.h]\n");
277 return 0; 235 return 0;
278 } 236 }
279 237