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
|
|
|
|
coord_back(int *x, int *y, int w, int h __UNUSED__)
|
|
|
|
{
|
|
|
|
(*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 *
|
|
|
|
_home_path_get(const Evas_Object *obj __UNUSED__, const char *relpath)
|
|
|
|
{
|
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 *
|
|
|
|
_termio_link_find(Evas_Object *obj, int cx, int cy, int *x1r, int *y1r, int *x2r, int *y2r)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
char endmatch = 0;
|
|
|
|
int x1, x2, y1, y2, len, w = 0, h = 0, sc;
|
|
|
|
Eina_Bool goback = EINA_TRUE, goforward = EINA_FALSE, extend = EINA_FALSE;
|
|
|
|
|
|
|
|
x1 = x2 = cx;
|
|
|
|
y1 = y2 = cy;
|
|
|
|
termio_size_get(obj, &w, &h);
|
|
|
|
sc = termio_scroll_get(obj);
|
|
|
|
if ((w <= 0) || (h <= 0)) return NULL;
|
|
|
|
if (!coord_back(&x1, &y1, w, h)) goback = EINA_FALSE;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
s = termio_selection_get(obj, x1, y1 - sc, x2, y2 - sc);
|
|
|
|
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;
|
|
|
|
coord_back(&x1, &y1, w, h);
|
|
|
|
free(s);
|
|
|
|
s = termio_selection_get(obj, x1, y1 - sc, x2, y2 - sc);
|
|
|
|
if (!s) break;
|
|
|
|
if (s[0] == '"') endmatch = '"';
|
|
|
|
else if (s[0] == '\'') endmatch = '\'';
|
|
|
|
else if (s[0] == '<') endmatch = '>';
|
|
|
|
coord_forward(&x1, &y1, w, h);
|
|
|
|
free(s);
|
|
|
|
s = termio_selection_get(obj, x1, y1 - sc, x2, y2 - sc);
|
|
|
|
if (!s) break;
|
|
|
|
}
|
|
|
|
else if ((isspace(s[0])) ||
|
|
|
|
(s[0] == '"') ||
|
2012-07-23 01:11:42 -07:00
|
|
|
(s[0] == '`') ||
|
2012-07-13 02:12:01 -07:00
|
|
|
(s[0] == '\'') ||
|
|
|
|
(s[0] == '<') ||
|
|
|
|
(s[0] == '='))
|
|
|
|
{
|
|
|
|
if (s[0] == '"') endmatch = '"';
|
|
|
|
else if (s[0] == '\'') endmatch = '\'';
|
2012-07-23 01:11:42 -07:00
|
|
|
else if (s[0] == '`') endmatch = '\'';
|
2012-07-13 02:12:01 -07:00
|
|
|
else if (s[0] == '<') endmatch = '>';
|
2012-10-09 08:14:24 -07:00
|
|
|
if ((casestartswith((s + 1), "www.")) ||
|
|
|
|
(casestartswith((s + 1), "ftp.")) ||
|
2012-10-09 10:09:26 -07:00
|
|
|
(_is_file(s + 1)))
|
2012-07-13 02:12:01 -07:00
|
|
|
{
|
|
|
|
goback = EINA_FALSE;
|
|
|
|
coord_forward(&x1, &y1, w, h);
|
|
|
|
}
|
|
|
|
else if (strchr((s + 2), '@'))
|
|
|
|
{
|
|
|
|
goback = EINA_FALSE;
|
|
|
|
coord_forward(&x1, &y1, w, h);
|
|
|
|
}
|
|
|
|
else if (s[0] == '=')
|
|
|
|
{
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free(s);
|
|
|
|
s = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (goforward)
|
|
|
|
{
|
|
|
|
len = strlen(s);
|
|
|
|
if (len > 1)
|
|
|
|
{
|
|
|
|
if (((endmatch) && (s[len - 1] == endmatch)) ||
|
|
|
|
((!endmatch) &&
|
|
|
|
((isspace(s[len - 1])) || (s[len - 1] == '>'))
|
|
|
|
))
|
|
|
|
{
|
|
|
|
goforward = EINA_FALSE;
|
|
|
|
coord_back(&x2, &y2, w, h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (goforward)
|
|
|
|
{
|
|
|
|
if (!coord_forward(&x2, &y2, w, h)) goforward = EINA_FALSE;
|
|
|
|
}
|
|
|
|
if (goback)
|
|
|
|
{
|
|
|
|
if (!coord_back(&x1, &y1, w, h)) goback = EINA_FALSE;
|
|
|
|
}
|
|
|
|
if ((!extend) && (!goback))
|
|
|
|
{
|
|
|
|
goforward = EINA_TRUE;
|
|
|
|
extend = EINA_TRUE;
|
|
|
|
}
|
|
|
|
if ((!goback) && (!goforward))
|
|
|
|
{
|
|
|
|
free(s);
|
|
|
|
s = termio_selection_get(obj, x1, y1 - sc, x2, y2 - sc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(s);
|
|
|
|
s = NULL;
|
|
|
|
}
|
|
|
|
if (s)
|
|
|
|
{
|
|
|
|
len = strlen(s);
|
|
|
|
while (len > 1)
|
|
|
|
{
|
|
|
|
if (isspace(s[len - 1]))
|
|
|
|
{
|
|
|
|
s[len - 1] = 0;
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
else break;
|
|
|
|
}
|
|
|
|
if ((!isspace(s[0])) && (len > 1))
|
|
|
|
{
|
2012-10-09 10:09:26 -07:00
|
|
|
Eina_Bool is_file = _is_file(s);
|
|
|
|
if (is_file ||
|
|
|
|
link_is_email(s) ||
|
|
|
|
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;
|
|
|
|
}
|