billiob pushed a commit to branch master.

commit 1f069a2fbec973a4c55aa578a58b9802e63db1ca
Author: Boris Faure <[email protected]>
Date:   Thu Jun 6 22:51:32 2013 +0200

    cleanup and fix _termio_link_find();
---
 src/bin/termiolink.c | 95 +++++++++++++++++++++++++---------------------------
 1 file changed, 45 insertions(+), 50 deletions(-)

diff --git a/src/bin/termiolink.c b/src/bin/termiolink.c
index 90c999d..97c9461 100644
--- a/src/bin/termiolink.c
+++ b/src/bin/termiolink.c
@@ -102,7 +102,7 @@ _termio_link_find(Evas_Object *obj, int cx, int cy,
    char endmatch = 0;
    int x1, x2, y1, y2, w = 0, h = 0, sc;
    size_t len;
-   Eina_Bool goback = EINA_TRUE, goforward = EINA_TRUE, extend = EINA_FALSE;
+   Eina_Bool goback = EINA_TRUE, goforward = EINA_FALSE, escaped = EINA_FALSE;
 
    x1 = x2 = cx;
    y1 = y2 = cy;
@@ -118,72 +118,76 @@ _termio_link_find(Evas_Object *obj, int cx, int cy,
              if (link_is_protocol(s))
                {
                   goback = EINA_FALSE;
+                  goforward = EINA_TRUE;
+
+                  /* Check if the previous char is a delimiter */
                   coord_back(&x1, &y1, w, h);
                   free(s);
                   s = termio_selection_get(obj, x1, y1 - sc, x2, y2 - sc,
                                            &len);
                   if (!s) break;
-                  if (s[0] == '"') endmatch = '"';
-                  else if (s[0] == '\'') endmatch = '\'';
-                  else if (s[0] == '<') endmatch = '>';
+                  switch (s[0])
+                    {
+                     case '"': endmatch = '"'; break;
+                     case '\'': endmatch = '\''; break;
+                     case '`': endmatch = '\''; break;
+                     case '<': endmatch = '>'; break;
+                     case '[': endmatch = ']'; break;
+                     case '{': endmatch = '}'; break;
+                     case '(': endmatch = ')'; break;
+                    }
                   coord_forward(&x1, &y1, w, h);
+
                   free(s);
                   s = termio_selection_get(obj, x1, y1 - sc, x2, y2 - sc,
                                            &len);
                   if (!s) break;
                }
-             else if ((isspace(s[0])) ||
-                      (s[0] == '"') ||
-                      (s[0] == '`') ||
-                      (s[0] == '\'') ||
-                      (s[0] == '<') ||
-                      (s[0] == '='))
+             else
                {
-                  if (s[0] == '"') endmatch = '"';
-                  else if (s[0] == '\'') endmatch = '\'';
-                  else if (s[0] == '`') endmatch = '\'';
-                  else if (s[0] == '<') endmatch = '>';
-                  if ((casestartswith((s + 1), "www.")) ||
-                      (casestartswith((s + 1), "ftp.")) ||
-                      (_is_file(s + 1)))
+                  switch (s[0])
                     {
-                       goback = EINA_FALSE;
-                       coord_forward(&x1, &y1, w, h);
+                     case '"': endmatch = '"'; break;
+                     case '\'': endmatch = '\''; break;
+                     case '`': endmatch = '\''; break;
+                     case '<': endmatch = '>'; break;
+                     case '[': endmatch = ']'; break;
+                     case '{': endmatch = '}'; break;
+                     case '(': endmatch = ')'; break;
                     }
-                  else
+                  if ((endmatch) || (isspace(s[0])))
                     {
                        goback = EINA_FALSE;
                        coord_forward(&x1, &y1, w, h);
+                       goforward = EINA_TRUE;
+                       free(s);
+                       s = termio_selection_get(obj, x1, y1 - sc, x2, y2 - sc,
+                                                &len);
+                       if (!s) break;
                     }
                }
           }
-        if (goforward)
+        if ((goforward) && (len >= 1))
           {
-             if (len > 1)
+             char end = s[len - 1];
+
+             if (((endmatch) && (end == endmatch)) ||
+                 ((!endmatch) && (!escaped) && (isspace(end))))
                {
-                  if (((endmatch) && (s[len - 1] == endmatch)) ||
-                      ((!endmatch) &&
-                          ((isspace(s[len - 1])) || (s[len - 1] == '>'))
-                      ))
-                    {
-                       goforward = EINA_FALSE;
-                       coord_back(&x2, &y2, w, h);
-                    }
+                  goforward = EINA_FALSE;
+                  coord_back(&x2, &y2, w, h);
+                  endmatch = 0;
                }
+             escaped = (end == '\\');
           }
-        
-        if (goforward)
+        if ((goback) && (!coord_back(&x1, &y1, w, h)))
           {
-             if (!coord_forward(&x2, &y2, w, h)) goforward = EINA_FALSE;
-          }
-        if (goback)
-          {
-             if (!coord_back(&x1, &y1, w, h)) goback = EINA_FALSE;
+             goback = EINA_FALSE;
+             goforward = EINA_TRUE;
           }
-        if ((!extend) && (!goback))
+        if ((goforward) && (!coord_forward(&x2, &y2, w, h)))
           {
-             goforward = EINA_TRUE;
-             extend = EINA_TRUE;
+             goforward = EINA_FALSE;
           }
         if ((!goback) && (!goforward))
           {
@@ -196,16 +200,7 @@ _termio_link_find(Evas_Object *obj, int cx, int cy,
      }
    if (s)
      {
-        while (len > 1)
-          {
-             if (isspace(s[len - 1]))
-               {
-                  s[len - 1] = 0;
-                  len--;
-               }
-             else break;
-          }
-        if ((!isspace(s[0])) && (len > 1))
+        if ((len > 1) && (!endmatch))
           {
              Eina_Bool is_file = _is_file(s);
              if (is_file ||

-- 

------------------------------------------------------------------------------
How ServiceNow helps IT people transform IT departments:
1. A cloud service to automate IT design, transition and operations
2. Dashboards that offer high-level views of enterprise services
3. A single system of record for all IT processes
http://p.sf.net/sfu/servicenow-d2d-j

Reply via email to