From 81c249ddeb7d6d245b2dcc5c785eb7c04d6ff093 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Sat, 13 May 2006 15:20:15 +0000 Subject: [PATCH] handle spaces in eap filenames when editing, and proeprly escape things, add gneric escaper, and reduce file path of icon files nicely. SVN revision: 22587 --- TODO | 1 - src/bin/e_apps.c | 36 ++++++++++++++++-------------------- src/bin/e_utils.c | 32 ++++++++++++++++++++++++++++++++ src/bin/e_utils.h | 3 ++- 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/TODO b/TODO index 9dcac9a51..4ecf8a184 100644 --- a/TODO +++ b/TODO @@ -8,7 +8,6 @@ Some of the things (in very short form) that need to be done to E17... BUGS / FIXES ------------------------------------------------------------------------------- -* BUG: eap editor doesn't handle spaces in file paths for the .eap * BUG: ghost windows happen if windows close when on another desktop or if windows are very short-lived * BUG: k3b has minimization issues when burning cds (it tries to unminimize diff --git a/src/bin/e_apps.c b/src/bin/e_apps.c index 8e15f2026..e4219eb98 100644 --- a/src/bin/e_apps.c +++ b/src/bin/e_apps.c @@ -1419,7 +1419,7 @@ e_app_icon_add(Evas *evas, E_App *a) static int _e_app_new_save(E_App *a) { - static char tmpn[1024]; + static char tmpn[4096]; int fd = 0, ret = 0; char cmd[2048]; char ipart[512]; @@ -1446,20 +1446,13 @@ _e_app_new_save(E_App *a) } i = 0; - if (a->image) { start = strchr(a->image, '/'); - end = strrchr(a->image ,'/'); + end = strrchr(a->image, '/'); - if (start == end) - { - imgdir = strdup("/");; - } - else if ((!start) || (!end)) - { - imgdir = strdup(""); - } + if (start == end) imgdir = strdup("/"); + else if ((!start) || (!end)) imgdir = strdup(""); else { imgdir = malloc((end - start + 1)); @@ -1473,24 +1466,27 @@ _e_app_new_save(E_App *a) if (imgdir) { - snprintf(ipart, sizeof(ipart), "-id %s", imgdir); + snprintf(ipart, sizeof(ipart), "-id %s", + e_util_filename_escape(imgdir)); free(imgdir); } - else ipart[0] = '\0'; + else ipart[0] = 0; if (a->image) { - if (a->width <= 0) - a->width = EAP_MIN_WIDTH; - if (a->height <= 0) - a->height = EAP_MIN_HEIGHT; - fprintf(out, EAP_EDC_TMPL, a->image, a->width, a->height, a->image); + if (a->width <= 0) a->width = EAP_MIN_WIDTH; + if (a->height <= 0) a->height = EAP_MIN_HEIGHT; + fprintf(out, EAP_EDC_TMPL, + e_util_filename_escape(ecore_file_get_file(a->image)), + a->width, a->height, + e_util_filename_escape(ecore_file_get_file(a->image))); } else fprintf(out, EAP_EDC_TMPL_EMPTY); fclose(out); - snprintf(cmd, sizeof(cmd), "edje_cc -v %s %s %s", ipart, tmpn, a->path); + snprintf(cmd, sizeof(cmd), "edje_cc -v %s %s %s", ipart, tmpn, + e_util_filename_escape(a->path)); ret = system(cmd); if (ret < 0) @@ -1500,7 +1496,7 @@ _e_app_new_save(E_App *a) return 0; } - unlink(tmpn); + ecore_file_unlink(tmpn); return 1; } diff --git a/src/bin/e_utils.c b/src/bin/e_utils.c index d933985a3..a7134ccea 100644 --- a/src/bin/e_utils.c +++ b/src/bin/e_utils.c @@ -527,6 +527,38 @@ e_util_dialog_internal(const char *title, const char *txt) e_dialog_show(dia); } +EAPI const char * +e_util_filename_escape(const char *filename) +{ + char *p, *q; + static char buf[4096]; + + p = filename; + q = buf; + while (*p) + { + if ((q - buf) > 4090) return NULL; + if ( + (*p == ' ') || (*p == '\t') || (*p == '\n') || + (*p == '\\') || (*p == '\'') || (*p == '\"') || + (*p == ';') || (*p == '!') || (*p == '#') || + (*p == '$') || (*p == '%') || (*p == '&') || + (*p == '*') || (*p == '(') || (*p == ')') || + (*p == '[') || (*p == ']') || (*p == '{') || + (*p == '}') || (*p == '|') || (*p == '<') || + (*p == '>') || (*p == '?') + ) + { + *q = '\\'; + q++; + } + *q = *p; + q++; + p++; + } + return buf; +} + /* local subsystem functions */ static void _e_util_container_fake_mouse_up_cb(void *data) diff --git a/src/bin/e_utils.h b/src/bin/e_utils.h index 705c82dd8..4506729a5 100644 --- a/src/bin/e_utils.h +++ b/src/bin/e_utils.h @@ -39,6 +39,7 @@ EAPI E_Border *e_util_desk_border_above(E_Border *bd); EAPI E_Border *e_util_desk_border_below(E_Border *bd); EAPI int e_util_edje_collection_exists(const char *file, const char *coll); EAPI void e_util_dialog_internal(const char *title, const char *txt); - +EAPI const char *e_util_filename_escape(const char *filename); + #endif #endif