1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

Added support for label_key in references of dumps.

Added base parameter to dec2qwerty and qwerty2dec to avoid strlen calls
im dumps.
This commit is contained in:
Witold Filipczyk 2016-02-07 11:51:17 +01:00
parent 69986f1bd1
commit 4efea7e314
4 changed files with 20 additions and 12 deletions

View File

@ -1505,10 +1505,9 @@ put_chars_conv(struct html_context *html_context,
* represented by key. I the trivial case, key="0123456789". A more homerow
* friendly key="gfdsahjkl;trewqyuiopvcxznm". Returns the length of link_sym.
*/
static int
dec2qwerty(int num, char *link_sym, const char *key)
int
dec2qwerty(int num, unsigned char *link_sym, const unsigned char *key, int base)
{
int base = strlen(key);
int newlen, i, pow;
if (base < 2) return 0;
@ -1528,10 +1527,9 @@ dec2qwerty(int num, char *link_sym, const char *key)
* Returns the value of link_sym in decimal according to key.
*/
int
qwerty2dec(const char *link_sym, const char *key)
qwerty2dec(const unsigned char *link_sym, const unsigned char *key, int base)
{
int z = 0;
int base = strlen(key);
int symlen = strlen(link_sym);
int i;
int pow;
@ -1555,12 +1553,13 @@ put_link_number(struct html_context *html_context)
unsigned char *fi = format.image;
struct form_control *ff = format.form;
int slen = 0;
int base = strlen(symkey);
format.link = format.target = format.image = NULL;
format.form = NULL;
s[slen++] = '[';
slen += dec2qwerty(part->link_num, s + 1, symkey);
slen += dec2qwerty(part->link_num, s + 1, symkey, base);
s[slen++] = ']';
s[slen] = '\0';

View File

@ -68,5 +68,6 @@ void free_table_cache(void);
struct part *format_html_part(struct html_context *html_context, unsigned char *, unsigned char *, int, int, int, struct document *, int, int, unsigned char *, int);
int qwerty2dec(const char *link_sym, const char *key);
int dec2qwerty(int num, unsigned char *link_sym, const unsigned char *key, int base);
int qwerty2dec(const unsigned char *link_sym, const unsigned char *key, int base);
#endif

View File

@ -23,6 +23,7 @@
#include "cache/cache.h"
#include "config/options.h"
#include "document/document.h"
#include "document/html/renderer.h"
#include "document/options.h"
#include "document/renderer.h"
#include "document/view.h"
@ -326,9 +327,12 @@ dump_references(struct document *document, int fd, unsigned char buf[D_BUF])
{
if (document->nlinks
&& get_opt_bool("document.dump.references", NULL)) {
unsigned char key_sym[64] = {0};
int x;
unsigned char *header = "\nReferences\n\n Visible links\n";
const unsigned char *label_key = get_opt_str("document.browse.links.label_key", NULL);
int headlen = strlen(header);
int base = strlen(label_key);
if (hard_write(fd, header, headlen) != headlen)
return -1;
@ -341,12 +345,15 @@ dump_references(struct document *document, int fd, unsigned char buf[D_BUF])
if (!where) continue;
if (document->options.links_numbering) {
dec2qwerty(x + 1, key_sym, label_key, base);
if (link->title && *link->title)
snprintf(buf, D_BUF, "%4d. %s\n\t%s\n",
x + 1, link->title, where);
snprintf(buf, D_BUF, "%4s. %s\n\t%s\n",
key_sym, link->title, where);
else
snprintf(buf, D_BUF, "%4d. %s\n",
x + 1, where);
snprintf(buf, D_BUF, "%4s. %s\n",
key_sym, where);
} else {
if (link->title && *link->title)
snprintf(buf, D_BUF, " . %s\n\t%s\n",

View File

@ -1223,13 +1223,14 @@ goto_link_symbol(struct session *ses, unsigned char *sym)
char *symkey = get_opt_str("document.browse.links.label_key", ses);
struct document_view *doc_view;
int num;
int base = strlen(symkey);
assert(ses && sym);
if_assert_failed return;
doc_view = current_frame(ses);
assert(doc_view);
if_assert_failed return;
num = qwerty2dec(sym, symkey);
num = qwerty2dec(sym, symkey, base);
goto_link_number_do(ses, doc_view, num - 1);
}