2012-07-13 02:12:01 -07:00
|
|
|
#include "private.h"
|
|
|
|
#include <Elementary.h>
|
|
|
|
#include "termio.h"
|
2012-10-09 08:11:09 -07:00
|
|
|
#include "utils.h"
|
2012-07-13 02:12:01 -07:00
|
|
|
|
|
|
|
static Eina_Bool
|
2013-08-27 06:36:50 -07:00
|
|
|
coord_back(int *x, int *y, int w, int h EINA_UNUSED)
|
2012-07-13 02:12:01 -07:00
|
|
|
{
|
|
|
|
(*x)--;
|
|
|
|
if ((*x) < 0)
|
|
|
|
{
|
|
|
|
if ((*y) <= 0)
|
|
|
|
{
|
|
|
|
(*x)++;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
(*x) = w - 1;
|
|
|
|
(*y)--;
|
|
|
|
}
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
coord_forward(int *x, int *y, int w, int h)
|
|
|
|
{
|
|
|
|
(*x)++;
|
|
|
|
if ((*x) >= w)
|
|
|
|
{
|
|
|
|
if ((*y) >= (h - 1))
|
|
|
|
{
|
|
|
|
(*x)--;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
(*x) = 0;
|
|
|
|
(*y)++;
|
|
|
|
}
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2012-10-09 10:09:26 -07:00
|
|
|
static char *
|
|
|
|
_cwd_path_get(const Evas_Object *obj, const char *relpath)
|
|
|
|
{
|
2012-10-09 10:32:29 -07:00
|
|
|
char cwdpath[PATH_MAX], tmppath[PATH_MAX];
|
2012-10-09 10:09:26 -07:00
|
|
|
|
2012-10-09 10:32:29 -07:00
|
|
|
if (!termio_cwd_get(obj, cwdpath, sizeof(cwdpath)))
|
|
|
|
return NULL;
|
2012-10-09 10:09:26 -07:00
|
|
|
|
|
|
|
eina_str_join(tmppath, sizeof(tmppath), '/', cwdpath, relpath);
|
|
|
|
return strdup(tmppath);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2013-08-27 06:36:50 -07:00
|
|
|
_home_path_get(const Evas_Object *obj EINA_UNUSED, const char *relpath)
|
2012-10-09 10:09:26 -07:00
|
|
|
{
|
2012-10-09 10:20:27 -07:00
|
|
|
char tmppath[PATH_MAX], homepath[PATH_MAX];
|
|
|
|
|
|
|
|
if (!homedir_get(homepath, sizeof(homepath)))
|
|
|
|
return NULL;
|
2012-10-09 10:09:26 -07:00
|
|
|
|
2012-10-09 10:20:27 -07:00
|
|
|
eina_str_join(tmppath, sizeof(tmppath), '/', homepath, relpath);
|
2012-10-09 10:09:26 -07:00
|
|
|
return strdup(tmppath);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
_local_path_get(const Evas_Object *obj, const char *relpath)
|
|
|
|
{
|
|
|
|
if (relpath[0] == '/')
|
|
|
|
return strdup(relpath);
|
|
|
|
else if (eina_str_has_prefix(relpath, "~/"))
|
|
|
|
return _home_path_get(obj, relpath + 2);
|
|
|
|
else
|
|
|
|
return _cwd_path_get(obj, relpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_is_file(const char *str)
|
|
|
|
{
|
|
|
|
switch (str[0])
|
|
|
|
{
|
|
|
|
case '/':
|
2012-12-24 17:15:56 -08:00
|
|
|
return EINA_TRUE;
|
2012-10-09 10:09:26 -07:00
|
|
|
case '~':
|
2012-12-24 17:15:56 -08:00
|
|
|
if (str[1] == '/')
|
|
|
|
return EINA_TRUE;
|
|
|
|
return EINA_FALSE;
|
2012-10-09 10:09:26 -07:00
|
|
|
case '.':
|
2012-12-24 17:15:56 -08:00
|
|
|
if (str[1] == '/')
|
|
|
|
return EINA_TRUE;
|
|
|
|
else if ((str[1] == '.') && (str[2] == '/'))
|
|
|
|
return EINA_TRUE;
|
|
|
|
return EINA_FALSE;
|
2012-10-09 10:09:26 -07:00
|
|
|
default:
|
2012-12-24 17:15:56 -08:00
|
|
|
return EINA_FALSE;
|
2012-10-09 10:09:26 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-13 02:12:01 -07:00
|
|
|
char *
|
2013-05-20 08:39:25 -07:00
|
|
|
_termio_link_find(Evas_Object *obj, int cx, int cy,
|
|
|
|
int *x1r, int *y1r, int *x2r, int *y2r)
|
2012-07-13 02:12:01 -07:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
char endmatch = 0;
|
2013-05-20 08:39:25 -07:00
|
|
|
int x1, x2, y1, y2, w = 0, h = 0, sc;
|
2014-06-30 12:48:55 -07:00
|
|
|
size_t len, prev_len = 0;
|
2013-06-06 13:51:32 -07:00
|
|
|
Eina_Bool goback = EINA_TRUE, goforward = EINA_FALSE, escaped = EINA_FALSE;
|
2013-05-20 08:39:25 -07:00
|
|
|
|
2012-07-13 02:12:01 -07:00
|
|
|
x1 = x2 = cx;
|
|
|
|
y1 = y2 = cy;
|
|
|
|
termio_size_get(obj, &w, &h);
|
|
|
|
if ((w <= 0) || (h <= 0)) return NULL;
|
2013-06-04 14:08:05 -07:00
|
|
|
sc = termio_scroll_get(obj);
|
2012-07-13 02:12:01 -07:00
|
|
|
for (;;)
|
|
|
|
{
|
2014-06-30 12:48:55 -07:00
|
|
|
prev_len = len;
|
2013-05-20 08:39:25 -07:00
|
|
|
s = termio_selection_get(obj, x1, y1 - sc, x2, y2 - sc, &len);
|
2012-07-13 02:12:01 -07:00
|
|
|
if (!s) break;
|
|
|
|
if (goback)
|
|
|
|
{
|
2012-10-09 08:11:09 -07:00
|
|
|
if (link_is_protocol(s))
|
2012-07-13 02:12:01 -07:00
|
|
|
{
|
|
|
|
goback = EINA_FALSE;
|
2013-06-06 13:51:32 -07:00
|
|
|
goforward = EINA_TRUE;
|
|
|
|
|
|
|
|
/* Check if the previous char is a delimiter */
|
2012-07-13 02:12:01 -07:00
|
|
|
coord_back(&x1, &y1, w, h);
|
|
|
|
free(s);
|
2014-06-30 12:48:55 -07:00
|
|
|
prev_len = len;
|
2013-05-20 08:39:25 -07:00
|
|
|
s = termio_selection_get(obj, x1, y1 - sc, x2, y2 - sc,
|
|
|
|
&len);
|
2012-07-13 02:12:01 -07:00
|
|
|
if (!s) break;
|
2013-06-06 13:51:32 -07:00
|
|
|
switch (s[0])
|
|
|
|
{
|
|
|
|
case '"': endmatch = '"'; break;
|
|
|
|
case '\'': endmatch = '\''; break;
|
2014-04-17 12:58:43 -07:00
|
|
|
case '`': endmatch = '`'; break;
|
2013-06-06 13:51:32 -07:00
|
|
|
case '<': endmatch = '>'; break;
|
|
|
|
case '[': endmatch = ']'; break;
|
|
|
|
case '{': endmatch = '}'; break;
|
|
|
|
case '(': endmatch = ')'; break;
|
|
|
|
}
|
2012-07-13 02:12:01 -07:00
|
|
|
coord_forward(&x1, &y1, w, h);
|
2013-06-06 13:51:32 -07:00
|
|
|
|
2012-07-13 02:12:01 -07:00
|
|
|
free(s);
|
2014-06-30 12:48:55 -07:00
|
|
|
prev_len = len;
|
2013-05-20 08:39:25 -07:00
|
|
|
s = termio_selection_get(obj, x1, y1 - sc, x2, y2 - sc,
|
|
|
|
&len);
|
2012-07-13 02:12:01 -07:00
|
|
|
if (!s) break;
|
|
|
|
}
|
2013-06-06 13:51:32 -07:00
|
|
|
else
|
2012-07-13 02:12:01 -07:00
|
|
|
{
|
2013-06-06 13:51:32 -07:00
|
|
|
switch (s[0])
|
2012-07-13 02:12:01 -07:00
|
|
|
{
|
2013-06-06 13:51:32 -07:00
|
|
|
case '"': endmatch = '"'; break;
|
|
|
|
case '\'': endmatch = '\''; break;
|
2014-04-17 12:58:43 -07:00
|
|
|
case '`': endmatch = '`'; break;
|
2013-06-06 13:51:32 -07:00
|
|
|
case '<': endmatch = '>'; break;
|
|
|
|
case '[': endmatch = ']'; break;
|
|
|
|
case '{': endmatch = '}'; break;
|
|
|
|
case '(': endmatch = ')'; break;
|
2012-07-13 02:12:01 -07:00
|
|
|
}
|
2013-06-06 13:51:32 -07:00
|
|
|
if ((endmatch) || (isspace(s[0])))
|
2012-07-13 02:12:01 -07:00
|
|
|
{
|
|
|
|
goback = EINA_FALSE;
|
|
|
|
coord_forward(&x1, &y1, w, h);
|
2013-06-06 13:51:32 -07:00
|
|
|
goforward = EINA_TRUE;
|
|
|
|
free(s);
|
|
|
|
s = termio_selection_get(obj, x1, y1 - sc, x2, y2 - sc,
|
|
|
|
&len);
|
|
|
|
if (!s) break;
|
2012-07-13 02:12:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-06 13:51:32 -07:00
|
|
|
if ((goforward) && (len >= 1))
|
2012-07-13 02:12:01 -07:00
|
|
|
{
|
2013-06-06 13:51:32 -07:00
|
|
|
char end = s[len - 1];
|
2014-06-30 12:48:55 -07:00
|
|
|
if (len - prev_len == 2 && len >= 2)
|
|
|
|
end = s[len - 2];
|
2013-06-06 13:51:32 -07:00
|
|
|
|
2013-06-15 09:15:24 -07:00
|
|
|
if ((end == endmatch) ||
|
|
|
|
((!escaped) && (isspace(end)) &&
|
|
|
|
((end != '\n') || (end != '\r'))))
|
2012-07-13 02:12:01 -07:00
|
|
|
{
|
2013-06-06 13:51:32 -07:00
|
|
|
goforward = EINA_FALSE;
|
|
|
|
coord_back(&x2, &y2, w, h);
|
|
|
|
endmatch = 0;
|
2012-07-13 02:12:01 -07:00
|
|
|
}
|
2013-06-06 13:51:32 -07:00
|
|
|
escaped = (end == '\\');
|
2012-07-13 02:12:01 -07:00
|
|
|
}
|
2013-06-06 13:51:32 -07:00
|
|
|
if ((goback) && (!coord_back(&x1, &y1, w, h)))
|
2012-07-13 02:12:01 -07:00
|
|
|
{
|
2013-06-06 13:51:32 -07:00
|
|
|
goback = EINA_FALSE;
|
|
|
|
goforward = EINA_TRUE;
|
2012-07-13 02:12:01 -07:00
|
|
|
}
|
2013-06-06 13:51:32 -07:00
|
|
|
if ((goforward) && (!coord_forward(&x2, &y2, w, h)))
|
2012-07-13 02:12:01 -07:00
|
|
|
{
|
2013-06-06 13:51:32 -07:00
|
|
|
goforward = EINA_FALSE;
|
2012-07-13 02:12:01 -07:00
|
|
|
}
|
|
|
|
if ((!goback) && (!goforward))
|
|
|
|
{
|
|
|
|
free(s);
|
2013-05-20 08:39:25 -07:00
|
|
|
s = termio_selection_get(obj, x1, y1 - sc, x2, y2 - sc, &len);
|
2012-07-13 02:12:01 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(s);
|
|
|
|
s = NULL;
|
|
|
|
}
|
|
|
|
if (s)
|
|
|
|
{
|
2013-06-06 13:51:32 -07:00
|
|
|
if ((len > 1) && (!endmatch))
|
2012-07-13 02:12:01 -07:00
|
|
|
{
|
2012-10-09 10:09:26 -07:00
|
|
|
Eina_Bool is_file = _is_file(s);
|
2013-06-15 14:37:10 -07:00
|
|
|
|
2012-10-09 10:09:26 -07:00
|
|
|
if (is_file ||
|
|
|
|
link_is_email(s) ||
|
2013-06-15 14:37:10 -07:00
|
|
|
link_is_url(s))
|
2012-07-13 02:12:01 -07:00
|
|
|
{
|
|
|
|
if (x1r) *x1r = x1;
|
|
|
|
if (y1r) *y1r = y1;
|
|
|
|
if (x2r) *x2r = x2;
|
|
|
|
if (y2r) *y2r = y2;
|
2012-10-09 10:09:26 -07:00
|
|
|
|
|
|
|
if (is_file && (s[0] != '/'))
|
|
|
|
{
|
|
|
|
char *ret = _local_path_get(obj, s);
|
|
|
|
free(s);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-13 02:12:01 -07:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(s);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|