This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efm2.

View the commit online.

commit cc7448a6d74fb036bb85f87adfbd06bc4f2ab02a
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
AuthorDate: Sat Jun 21 10:29:59 2025 +0100

    move shared util funcs to esc.c for string stuff
---
 src/backends/default/open.c | 51 +--------------------------
 src/efm/efm.c               |  5 ++-
 src/efm/efm_dnd.c           |  6 ++--
 src/efm/efm_util.c          | 84 ++++-----------------------------------------
 src/efm/efm_util.h          |  4 +--
 src/efm/meson.build         |  1 +
 src/shared/esc.c            | 81 +++++++++++++++++++++++++++++++++++++++++++
 src/shared/esc.h            |  9 +++--
 8 files changed, 102 insertions(+), 139 deletions(-)

diff --git a/src/backends/default/open.c b/src/backends/default/open.c
index 27531e5..8ebe83f 100644
--- a/src/backends/default/open.c
+++ b/src/backends/default/open.c
@@ -687,55 +687,6 @@ _file_add_mod_meta_append(const char *path, const char *meta, const char *key,
   eina_stringshare_del(s);
 }
 
-static char *
-_env_var_resolve(const char *str)
-{
-  Eina_Strbuf *buf = eina_strbuf_new();
-  char        *s, *e, *tmp, save, *env = NULL, *strout = NULL;
-
-  if (!buf) return NULL;
-  tmp = strdup(str);
-  if (!tmp) goto err;
-  for (s = tmp; *s; s++)
-    {
-      if (!env)
-        {
-          if (*s == '$')
-            { // found start of an env var - 0 the $ and mark beginning
-              *s = 0;
-              env = s + 1;
-            }
-          else eina_strbuf_append_char(buf, *s);
-        }
-      else
-        {
-          if (!(((*s >= 'a') && (*s <= 'z')) || ((*s >= 'A') && (*s <= 'Z'))
-                || ((*s >= '0') && (*s <= '9')) || (*s == '_')))
-            { //  char is not a valid env var char (a-z, A-Z, _)
-              save = *s;
-              *s = 0;
-              e    = getenv(env);
-              if (e) eina_strbuf_append(buf, e);
-              eina_strbuf_append_char(buf, save);
-              env = NULL;
-            }
-        }
-    }
-  // handle $ENV at end
-  if (env)
-    {
-      e = getenv(env);
-      if (e) eina_strbuf_append(buf, e);
-    }
-
-  strout = eina_strbuf_string_steal(buf);
-err:
-  free(tmp);
-  eina_strbuf_free(buf);
-  return strout;
-}
-
-
 static void
 _file_add_mod_desktop_fields_append(Eina_Strbuf *strbuf, Efreet_Desktop *d,
                                     const char *key_prefix, const char *path,
@@ -803,7 +754,7 @@ _file_add_mod_desktop_fields_append(Eina_Strbuf *strbuf, Efreet_Desktop *d,
   s = _desktop_x_field(d, "X-Enlightenment-Type");
   if ((d->url) && (s) && (!strcmp(s, "Mount")))
     { // XXX:  resolve $ENV $VAR etc if X-Enlightenment-Type == Mount
-      char *res = _env_var_resolve(d->url);
+      char *res = env_var_resolve(d->url);
 
       if (res)
         {
diff --git a/src/efm/efm.c b/src/efm/efm.c
index cf1db6b..196fa55 100644
--- a/src/efm/efm.c
+++ b/src/efm/efm.c
@@ -15,8 +15,7 @@
 #include "efm_back_end.h"
 #include "efm_custom.h"
 #include "efm_private.h"
-#include "eina_types.h"
-#include "elm_table_eo.legacy.h"
+#include "esc.h"
 
 int _log_dom = -1;
 
@@ -123,7 +122,7 @@ _cb_sel_get(void *data, Evas_Object *_obj EINA_UNUSED, Elm_Selection_Data *ev)
             {
               if (**p)
                 {
-                  esc = _escape_parse(*p);
+                  esc = unescape(*p);
                   if (!esc) continue;
                   printf("XXX: PASTE FILE: [%s]\n", esc);
                 }
diff --git a/src/efm/efm_dnd.c b/src/efm/efm_dnd.c
index f6de12e..b6f9579 100644
--- a/src/efm/efm_dnd.c
+++ b/src/efm/efm_dnd.c
@@ -6,7 +6,7 @@
 #include "efm_util.h"
 #include "efm_dnd.h"
 #include "efm_private.h"
-#include "eina_strbuf.h"
+#include "esc.h"
 
 // utils for draga and drop handling
 static Eina_Bool
@@ -186,7 +186,7 @@ _dnd_drop_handle(Smart_Data *sd, char *urilist, Elm_Xdnd_Action act)
     {
       if (**p)
         {
-          esc = _escape_parse(*p);
+          esc = unescape(*p);
           if (!esc) continue;
           dropicons = _icons_path_find(esc);
           free(esc);
@@ -215,7 +215,7 @@ _dnd_drop_handle(Smart_Data *sd, char *urilist, Elm_Xdnd_Action act)
     {
       if (**p)
         {
-          esc = _escape_parse(*p);
+          esc = unescape(*p);
           if (!esc) continue;
           printf("XXX: DROP FILE: [%s]\n", esc);
           if ((sd->config.view_mode == EFM_VIEW_MODE_ICONS_CUSTOM)
diff --git a/src/efm/efm_util.c b/src/efm/efm_util.c
index b6d4f3e..876b43a 100644
--- a/src/efm/efm_util.c
+++ b/src/efm/efm_util.c
@@ -7,82 +7,10 @@
 #include "efm_back_end.h"
 #include "efm_private.h"
 #include "efm_structs.h"
-#include "eina_list.h"
-#include "eina_strbuf.h"
-#include "eina_types.h"
+#include "esc.h"
 #include "mimeapps.h"
 
 // util funcs for the efm view
-static inline int
-_xtov(char x)
-{
-  if ((x >= '0') && (x <= '9')) return x - '0';
-  if ((x >= 'a') && (x <= 'f')) return 10 + (x - 'a');
-  if ((x >= 'A') && (x <= 'F')) return 10 + (x - 'A');
-  return 0;
-}
-
-static unsigned int
-_xtoi(const char *str)
-{
-  unsigned int v = 0;
-  const char  *s;
-
-  for (s = str; *s; s++)
-    {
-      v <<= 4;
-      v += _xtov(*s);
-    }
-  return v;
-}
-
-char *
-_escape_parse(const char *str)
-{
-  char       *dest = malloc(strlen(str) + 1);
-  char       *d;
-  const char *s;
-
-  for (d = dest, s = str; *s; d++)
-    {
-      if ((s[0] == '%') && (!isspace(s[1])))
-        {
-          if ((s[1]) && (s[2]))
-            {
-              *d = (_xtov(s[1]) << 4) | (_xtov(s[2]));
-              s += 3;
-            }
-          else s++;
-        }
-      else
-        {
-          *d = s[0];
-          s++;
-        }
-    }
-  *d = 0;
-  return dest;
-}
-
-static void
-_strbuf_escape_append(Eina_Strbuf *strbuf, const char *str)
-{
-  const char  hex[] = "0123456789abcdef";
-  const char *s;
-
-  for (s = str; *s; s++)
-    {
-      if ((*s <= ',') || (*s == '%') || ((*s >= ':') && (*s <= '@'))
-          || ((*s >= '[') && (*s <= '`')) || (*s >= '{'))
-        {
-          eina_strbuf_append_char(strbuf, '%');
-          eina_strbuf_append_char(strbuf, hex[(*s >> 4) & 0xf]);
-          eina_strbuf_append_char(strbuf, hex[*s & 0xf]);
-        }
-      else eina_strbuf_append_char(strbuf, *s);
-    }
-}
-
 double
 _scale_get(Smart_Data *sd)
 {
@@ -140,8 +68,8 @@ _selected_icons_uri_strbuf_append(Smart_Data *sd, Eina_Strbuf *strbuf)
     {
       if (!icon->selected) continue; // skip icons not selected
       eina_strbuf_append(strbuf, "file://");
-      _strbuf_escape_append(strbuf, icon->sd->config.path);
-      _strbuf_escape_append(strbuf, icon->info.file);
+      strbuf_escape_append(strbuf, icon->sd->config.path);
+      strbuf_escape_append(strbuf, icon->info.file);
       eina_strbuf_append_char(strbuf, '\n');
       added = EINA_TRUE;
     }
@@ -842,7 +770,7 @@ _uri_list_cmd_strbuf_append(Eina_Strbuf *strbuf, const char *key,
         }
       else s2 = se + 1;
       *se  = '\0';
-      stmp = _escape_parse(s);
+      stmp = unescape(s);
       if (stmp) cmd_strbuf_append(strbuf, key, stmp);
       free(stmp);
       if (!s2) break;
@@ -869,7 +797,7 @@ _file_list_cmd_strbuf_append(Eina_Strbuf *strbuf, const char *key,
         }
       else s2 = se + 1;
       *se  = '\0';
-      stmp = _escape_parse(s);
+      stmp = unescape(s);
       if (stmp)
         {
           if (!strncmp(stmp, "file://", 7))
@@ -2313,7 +2241,7 @@ _icon_object_add(Icon *icon, Smart_Data *sd, Evas *e,
           s = cmd_key_find(icon->cmd, "mode");
           if (s)
             { // special mode info display obj
-              int mode = _xtoi(s);
+              int mode = xtoi(s);
 
               icon->o_list_detail_swallow[5] = o2
                 = elm_grid_add(sd->o_scroller);
diff --git a/src/efm/efm_util.h b/src/efm/efm_util.h
index dc068c3..4a18063 100644
--- a/src/efm/efm_util.h
+++ b/src/efm/efm_util.h
@@ -15,9 +15,7 @@ typedef enum
   EFM_FOCUS_DIR_PGUP
 } Efm_Focus_Dir;
 
-char          *_escape_parse(const char *str);
-Eina_Bool      _selected_icons_uri_strbuf_append(Smart_Data  *sd,
-                                                 Eina_Strbuf *strbuf);
+Eina_Bool      _selected_icons_uri_strbuf_append(Smart_Data *sd, Eina_Strbuf *strbuf);
 void           _detail_realized_items_resize(Smart_Data *sd);
 double         _scale_get(Smart_Data *sd);
 Eina_List     *_icons_path_find(const char *path);
diff --git a/src/efm/meson.build b/src/efm/meson.build
index 3c3bfc2..0bd7d95 100644
--- a/src/efm/meson.build
+++ b/src/efm/meson.build
@@ -6,6 +6,7 @@ inc = include_directories(
 )
 executable('efm', [
     '../shared/cmd.c',
+    '../shared/esc.c',
     '../shared/mimeapps.c',
     'efm.c',
     'sort.c',
diff --git a/src/shared/esc.c b/src/shared/esc.c
index eba589a..8698e7a 100644
--- a/src/shared/esc.c
+++ b/src/shared/esc.c
@@ -12,6 +12,20 @@ _xtov(char x)
   return 0;
 }
 
+unsigned int
+xtoi(const char *str)
+{
+  unsigned int v = 0;
+  const char  *s;
+
+  for (s = str; *s; s++)
+    {
+      v <<= 4;
+      v += _xtov(*s);
+    }
+  return v;
+}
+
 char *
 escape(const char *src_in)
 {
@@ -62,4 +76,71 @@ unescape(const char *src_in)
     }
   *d = 0;
   return dest;
+}
+
+void
+strbuf_escape_append(Eina_Strbuf *strbuf, const char *str)
+{
+  const char  hex[] = "0123456789abcdef";
+  const char *s;
+
+  for (s = str; *s; s++)
+    {
+      if ((*s <= ',') || (*s == '%') || ((*s >= ':') && (*s <= '@'))
+          || ((*s >= '[') && (*s <= '`')) || (*s >= '{'))
+        {
+          eina_strbuf_append_char(strbuf, '%');
+          eina_strbuf_append_char(strbuf, hex[(*s >> 4) & 0xf]);
+          eina_strbuf_append_char(strbuf, hex[*s & 0xf]);
+        }
+      else eina_strbuf_append_char(strbuf, *s);
+    }
+}
+
+char *
+env_var_resolve(const char *str)
+{
+  Eina_Strbuf *buf = eina_strbuf_new();
+  char        *s, *e, *tmp, save, *env = NULL, *strout = NULL;
+
+  if (!buf) return NULL;
+  tmp = strdup(str);
+  if (!tmp) goto err;
+  for (s = tmp; *s; s++)
+    {
+      if (!env)
+        {
+          if (*s == '$')
+            { // found start of an env var - 0 the $ and mark beginning
+              *s  = 0;
+              env = s + 1;
+            }
+          else eina_strbuf_append_char(buf, *s);
+        }
+      else
+        {
+          if (!(((*s >= 'a') && (*s <= 'z')) || ((*s >= 'A') && (*s <= 'Z'))
+                || ((*s >= '0') && (*s <= '9')) || (*s == '_')))
+            { //  char is not a valid env var char (a-z, A-Z, _)
+              save = *s;
+              *s   = 0;
+              e    = getenv(env);
+              if (e) eina_strbuf_append(buf, e);
+              eina_strbuf_append_char(buf, save);
+              env = NULL;
+            }
+        }
+    }
+  // handle $ENV at end
+  if (env)
+    {
+      e = getenv(env);
+      if (e) eina_strbuf_append(buf, e);
+    }
+
+  strout = eina_strbuf_string_steal(buf);
+err:
+  free(tmp);
+  eina_strbuf_free(buf);
+  return strout;
 }
\ No newline at end of file
diff --git a/src/shared/esc.h b/src/shared/esc.h
index a2effe7..392481b 100644
--- a/src/shared/esc.h
+++ b/src/shared/esc.h
@@ -1,7 +1,12 @@
 #ifndef ESC_H
 #define ESC_H 1
 
-char *escape(const char *src_in);
-char *unescape(const char *src_in);
+#include <Eina.h>
+
+unsigned int  xtoi(const char *str);
+char         *escape(const char *src_in);
+char         *unescape(const char *src_in);
+void          strbuf_escape_append(Eina_Strbuf *strbuf, const char *str);
+char         *env_var_resolve(const char *str);
 
 #endif
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to