move code about hyperlinks to termpty.c to avoid issues with tyfuzz
This commit is contained in:
parent
be2f531516
commit
dd8e9cedcc
|
@ -432,106 +432,3 @@ end:
|
|||
ty_sb_free(&sb);
|
||||
return s;
|
||||
}
|
||||
|
||||
/* 0 means error here */
|
||||
static uint16_t
|
||||
_find_empty_slot(const Termpty *ty)
|
||||
{
|
||||
int pos;
|
||||
int max_pos = HL_LINKS_MAX / 8;
|
||||
|
||||
for (pos = 0; pos < max_pos && ty->hl.bitmap[pos] == 0xff; pos++)
|
||||
{
|
||||
}
|
||||
|
||||
if (pos <= max_pos)
|
||||
{
|
||||
int bit;
|
||||
for (bit = 0; bit < 8; bit++)
|
||||
{
|
||||
if (!(ty->hl.bitmap[pos] & (1<<bit)))
|
||||
{
|
||||
return pos * 8 + bit;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
hl_bitmap_set_bit(Termpty *ty, uint16_t id)
|
||||
{
|
||||
uint8_t *pos = &ty->hl.bitmap[id / 8];
|
||||
uint8_t bit = 1 << (id % 8);
|
||||
|
||||
*pos |= bit;
|
||||
}
|
||||
|
||||
static void
|
||||
hl_bitmap_clear_bit(Termpty *ty, uint16_t id)
|
||||
{
|
||||
uint8_t *pos = &ty->hl.bitmap[id / 8];
|
||||
uint8_t bit = 1 << (id % 8);
|
||||
|
||||
*pos &= ~bit;
|
||||
}
|
||||
|
||||
Term_Link *
|
||||
term_link_new(Termpty *ty)
|
||||
{
|
||||
uint16_t id;
|
||||
Term_Link *link;
|
||||
|
||||
/* 1st/ Find empty slot in bitmap */
|
||||
id = _find_empty_slot(ty);
|
||||
if (!id)
|
||||
{
|
||||
ERR("hyper links: can't find empty slot");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* 2nd/ Do we need to realloc? */
|
||||
if (id >= ty->hl.size)
|
||||
{
|
||||
Term_Link *links;
|
||||
uint16_t old_size = ty->hl.size;
|
||||
|
||||
if (!ty->hl.size)
|
||||
ty->hl.size = 256;
|
||||
links = realloc(ty->hl.links,
|
||||
ty->hl.size * 2 * sizeof(Term_Link));
|
||||
if (!links)
|
||||
return NULL;
|
||||
ty->hl.size *= 2;
|
||||
ty->hl.links = links;
|
||||
memset(ty->hl.links + old_size,
|
||||
0,
|
||||
(ty->hl.size - old_size) * sizeof(Term_Link));
|
||||
}
|
||||
|
||||
link = ty->hl.links + id;
|
||||
link->key = NULL;
|
||||
link->url = NULL;
|
||||
link->refcount = 0;
|
||||
|
||||
/* Mark in bitmap */
|
||||
hl_bitmap_set_bit(ty, id);
|
||||
|
||||
return link;
|
||||
}
|
||||
|
||||
void
|
||||
term_link_free(Termpty *ty, Term_Link *link)
|
||||
{
|
||||
if (!link || !ty)
|
||||
return;
|
||||
uint16_t id = (link - ty->hl.links);
|
||||
|
||||
eina_stringshare_del(link->key);
|
||||
link->key = NULL;
|
||||
eina_stringshare_del(link->url);
|
||||
link->url = NULL;
|
||||
|
||||
/* Remove from bitmap */
|
||||
hl_bitmap_clear_bit(ty, id);
|
||||
}
|
||||
|
|
|
@ -1,23 +1,6 @@
|
|||
#ifndef _TERMIO_LINK_H__
|
||||
#define _TERMIO_LINK_H__ 1
|
||||
|
||||
#define HL_LINKS_MAX (1 << 16)
|
||||
|
||||
typedef struct _Termlink Term_Link;
|
||||
|
||||
struct _Termlink
|
||||
{
|
||||
const char *key;
|
||||
const char *url;
|
||||
unsigned int refcount;
|
||||
};
|
||||
|
||||
typedef struct _Termpty Termpty;
|
||||
|
||||
|
||||
char *termio_link_find(const Evas_Object *obj, int cx, int cy, int *x1r, int *y1r, int *x2r, int *y2r);
|
||||
|
||||
Term_Link * term_link_new(Termpty *ty);
|
||||
void term_link_free(Termpty *ty, Term_Link *link);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1727,3 +1727,106 @@ termpty_config_get(const Termpty *ty)
|
|||
{
|
||||
return termio_config_get(ty->obj);
|
||||
}
|
||||
|
||||
/* 0 means error here */
|
||||
static uint16_t
|
||||
_find_empty_slot(const Termpty *ty)
|
||||
{
|
||||
int pos;
|
||||
int max_pos = HL_LINKS_MAX / 8;
|
||||
|
||||
for (pos = 0; pos < max_pos && ty->hl.bitmap[pos] == 0xff; pos++)
|
||||
{
|
||||
}
|
||||
|
||||
if (pos <= max_pos)
|
||||
{
|
||||
int bit;
|
||||
for (bit = 0; bit < 8; bit++)
|
||||
{
|
||||
if (!(ty->hl.bitmap[pos] & (1<<bit)))
|
||||
{
|
||||
return pos * 8 + bit;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
hl_bitmap_set_bit(Termpty *ty, uint16_t id)
|
||||
{
|
||||
uint8_t *pos = &ty->hl.bitmap[id / 8];
|
||||
uint8_t bit = 1 << (id % 8);
|
||||
|
||||
*pos |= bit;
|
||||
}
|
||||
|
||||
static void
|
||||
hl_bitmap_clear_bit(Termpty *ty, uint16_t id)
|
||||
{
|
||||
uint8_t *pos = &ty->hl.bitmap[id / 8];
|
||||
uint8_t bit = 1 << (id % 8);
|
||||
|
||||
*pos &= ~bit;
|
||||
}
|
||||
|
||||
Term_Link *
|
||||
term_link_new(Termpty *ty)
|
||||
{
|
||||
uint16_t id;
|
||||
Term_Link *link;
|
||||
|
||||
/* 1st/ Find empty slot in bitmap */
|
||||
id = _find_empty_slot(ty);
|
||||
if (!id)
|
||||
{
|
||||
ERR("hyper links: can't find empty slot");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* 2nd/ Do we need to realloc? */
|
||||
if (id >= ty->hl.size)
|
||||
{
|
||||
Term_Link *links;
|
||||
uint16_t old_size = ty->hl.size;
|
||||
|
||||
if (!ty->hl.size)
|
||||
ty->hl.size = 256;
|
||||
links = realloc(ty->hl.links,
|
||||
ty->hl.size * 2 * sizeof(Term_Link));
|
||||
if (!links)
|
||||
return NULL;
|
||||
ty->hl.size *= 2;
|
||||
ty->hl.links = links;
|
||||
memset(ty->hl.links + old_size,
|
||||
0,
|
||||
(ty->hl.size - old_size) * sizeof(Term_Link));
|
||||
}
|
||||
|
||||
link = ty->hl.links + id;
|
||||
link->key = NULL;
|
||||
link->url = NULL;
|
||||
link->refcount = 0;
|
||||
|
||||
/* Mark in bitmap */
|
||||
hl_bitmap_set_bit(ty, id);
|
||||
|
||||
return link;
|
||||
}
|
||||
|
||||
void
|
||||
term_link_free(Termpty *ty, Term_Link *link)
|
||||
{
|
||||
if (!link || !ty)
|
||||
return;
|
||||
uint16_t id = (link - ty->hl.links);
|
||||
|
||||
eina_stringshare_del(link->key);
|
||||
link->key = NULL;
|
||||
eina_stringshare_del(link->url);
|
||||
link->url = NULL;
|
||||
|
||||
/* Remove from bitmap */
|
||||
hl_bitmap_clear_bit(ty, id);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "config.h"
|
||||
#include "media.h"
|
||||
#include "termiolink.h"
|
||||
|
||||
typedef struct _Termcell Termcell;
|
||||
typedef struct _Termatt Termatt;
|
||||
|
@ -11,6 +10,8 @@ typedef struct _Termsave Termsave;
|
|||
typedef struct _Termsavecomp Termsavecomp;
|
||||
typedef struct _Termblock Termblock;
|
||||
typedef struct _Termexp Termexp;
|
||||
typedef struct _Termpty Termpty;
|
||||
typedef struct _Termlink Term_Link;
|
||||
|
||||
#define COL_DEF 0
|
||||
#define COL_BLACK 1
|
||||
|
@ -44,6 +45,18 @@ typedef struct _Termexp Termexp;
|
|||
#define MOVIE_STATE_PAUSE 1
|
||||
#define MOVIE_STATE_STOP 2
|
||||
|
||||
#define HL_LINKS_MAX (1 << 16)
|
||||
|
||||
struct _Termlink
|
||||
{
|
||||
const char *key;
|
||||
const char *url;
|
||||
unsigned int refcount;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
struct _Termatt
|
||||
{
|
||||
unsigned char fg, bg;
|
||||
|
@ -282,6 +295,9 @@ Config *termpty_config_get(const Termpty *ty);
|
|||
void termpty_handle_buf(Termpty *ty, const Eina_Unicode *codepoints, int len);
|
||||
void termpty_handle_block_codepoint_overwrite_heavy(Termpty *ty, int oldc, int newc);
|
||||
|
||||
Term_Link * term_link_new(Termpty *ty);
|
||||
void term_link_free(Termpty *ty, Term_Link *link);
|
||||
|
||||
extern int _termpty_log_dom;
|
||||
|
||||
#define TERMPTY_SCREEN(Tpty, X, Y) \
|
||||
|
|
Loading…
Reference in New Issue