summaryrefslogtreecommitdiff
path: root/src/bin/main.c
diff options
context:
space:
mode:
authorYakov Goldberg <yakov.g@samsung.com>2014-07-23 16:01:25 +0300
committerYakov Goldberg <yakov.g@samsung.com>2014-07-23 16:02:00 +0300
commit36868bd0bbd37524ab592b89ad9f212245b9fb77 (patch)
treeb9cc97273f56790c7a617e593781cc7920933c44 /src/bin/main.c
parent973dfc2d3b0edea2e0e829c7bc86481e57714331 (diff)
main fix in file path resolving
Diffstat (limited to 'src/bin/main.c')
-rw-r--r--src/bin/main.c45
1 files changed, 35 insertions, 10 deletions
diff --git a/src/bin/main.c b/src/bin/main.c
index 86119c9..6bf0481 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -192,19 +192,43 @@ main(int argc, char **argv)
192 /* Filename must be the first argument after the options. */ 192 /* Filename must be the first argument after the options. */
193 else if (optind != argc) 193 else if (optind != argc)
194 { 194 {
195 filename = ecore_file_realpath(argv[optind]); 195 /* if file exists, everything is easy */
196 if (strlen(filename) == 0) 196 if (ecore_file_exists(argv[optind]))
197 { 197 {
198 free(filename); 198 filename = ecore_file_realpath(argv[optind]);
199 char *dir_path = ecore_file_realpath("."); 199 if (ecore_file_is_dir(filename))
200 filename = malloc(strlen(dir_path) + 1 + strlen(argv[optind]) + 1); /* path/file\0 */ 200 {
201 sprintf(filename, "%s/%s", dir_path, argv[optind]); 201 printf("File: \"%s\" is a directory\n", filename);
202 goto end;
203 }
202 } 204 }
203 205 /* but if not, and user can provide it as "./filename" "~/filename" or "filename",
204 if (ecore_file_is_dir(filename)) 206 * we need resolve path before last / */
207 else
205 { 208 {
206 ERR("File: \"%s\" is directory", filename); 209 char dd[PATH_MAX] = {'\0'};
207 goto end; 210 char ff[PATH_MAX] = {'\0'};
211 const char *p = strrchr(argv[optind], '/');
212 if (p)
213 {
214 strncpy(dd, argv[optind], p - argv[optind] + 1);
215 strcpy(ff, p + 1);
216 }
217 else
218 {
219 strcpy(dd, "./");
220 strcpy(ff, argv[optind]);
221 }
222 if (!ecore_file_exists(dd))
223 {
224 printf("Path can not exist: \"%s\"\n", argv[optind]);
225 goto end;
226 }
227 char *dd_realpath = ecore_file_realpath(dd);
228
229 filename = malloc(strlen(dd_realpath) + 1 + strlen(ff) + 1); /* path/file\0 */
230 sprintf(filename, "%s/%s", dd_realpath, ff);
231 free(dd_realpath);
208 } 232 }
209 } 233 }
210 else if (optind == argc) 234 else if (optind == argc)
@@ -213,6 +237,7 @@ main(int argc, char **argv)
213 goto end; 237 goto end;
214 } 238 }
215 239
240
216 if (!egui_init(PACKAGE_DATA_DIR"/config/func_names.json")) 241 if (!egui_init(PACKAGE_DATA_DIR"/config/func_names.json"))
217 { 242 {
218 EINA_LOG_ERR("Could not start egui"); 243 EINA_LOG_ERR("Could not start egui");