Make getting hyperlinks from ids useable throughtout the codebase

This commit is contained in:
Kovid Goyal 2020-09-22 09:25:16 +05:30
parent fdaf857885
commit 0d665495b8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 7 additions and 7 deletions

View File

@ -319,6 +319,7 @@ void play_canberra_sound(const char *which_sound, const char *event_id);
#endif
SPRITE_MAP_HANDLE alloc_sprite_map(unsigned int, unsigned int);
SPRITE_MAP_HANDLE free_sprite_map(SPRITE_MAP_HANDLE);
const char* get_hyperlink_for_id(const HYPERLINK_POOL_HANDLE, hyperlink_id_type id, bool only_url);
static inline void safe_close(int fd, const char* file UNUSED, const int line UNUSED) {
#if 0

View File

@ -137,11 +137,11 @@ get_id_for_hyperlink(Screen *screen, const char *id, const char *url) {
}
const char*
get_hyperlink_for_id(Screen *screen, hyperlink_id_type id) {
HyperLinkPool *pool = (HyperLinkPool*)screen->hyperlink_pool;
get_hyperlink_for_id(const HYPERLINK_POOL_HANDLE handle, hyperlink_id_type id, bool only_url) {
const HyperLinkPool *pool = (HyperLinkPool*)handle;
HyperLinkEntry *s, *tmp;
HASH_ITER(hh, pool->hyperlinks, s, tmp) {
if (s->id == id) return strstr(s->key, ":") + 1;
if (s->id == id) return only_url ? strstr(s->key, ":") + 1 : s->key;
}
return NULL;
}

View File

@ -15,4 +15,3 @@ hyperlink_id_type get_id_for_hyperlink(Screen*, const char*, const char*);
hyperlink_id_type remap_hyperlink_ids(Screen *self, hyperlink_id_type *map);
PyObject* screen_hyperlinks_as_list(Screen *screen);
void screen_garbage_collect_hyperlink_pool(Screen *screen);
const char* get_hyperlink_for_id(Screen *screen, hyperlink_id_type id);

View File

@ -1956,7 +1956,7 @@ screen_open_url(Screen *self) {
if (!self->url_ranges.count) return false;
hyperlink_id_type hid = hyperlink_id_for_range(self, self->url_ranges.items);
if (hid) {
const char *url = get_hyperlink_for_id(self, hid);
const char *url = get_hyperlink_for_id(self->hyperlink_pool, hid, true);
if (url) {
CALLBACK("open_url", "sH", url, hid);
return true;
@ -2014,7 +2014,7 @@ static PyObject*
hyperlink_for_id(Screen *self, PyObject *val) {
unsigned long id = PyLong_AsUnsignedLong(val);
if (id > HYPERLINK_MAX_NUMBER) { PyErr_SetString(PyExc_IndexError, "Out of bounds"); return NULL; }
return Py_BuildValue("s", get_hyperlink_for_id(self, id));
return Py_BuildValue("s", get_hyperlink_for_id(self->hyperlink_pool, id, true));
}
static PyObject*
@ -2768,7 +2768,7 @@ hyperlink_at(Screen *self, PyObject *args) {
if (!self->url_ranges.count) Py_RETURN_NONE;
hyperlink_id_type hid = hyperlink_id_for_range(self, self->url_ranges.items);
if (!hid) Py_RETURN_NONE;
const char *url = get_hyperlink_for_id(self, hid);
const char *url = get_hyperlink_for_id(self->hyperlink_pool, hid, true);
return Py_BuildValue("s", url);
}