mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Multiplication instead of pow calls and minor style changes.
This commit is contained in:
parent
28b7bd1ec2
commit
69986f1bd1
@ -346,8 +346,8 @@ static union option_info config_options_info[] = {
|
||||
|
||||
INIT_OPT_STRING("document.browse.links", N_("Specify link label key"),
|
||||
"label_key", 0, "0123456789",
|
||||
N_("Default is 0123456789, which is standard numeric labeling."
|
||||
"Ascii based strings like gfdsahjkl;trewqyuiopvcxznm can also"
|
||||
N_("Default is 0123456789, which is standard numeric labeling. "
|
||||
"Ascii based strings like gfdsahjkl;trewqyuiopvcxznm can also "
|
||||
"be used.")),
|
||||
|
||||
INIT_OPT_BOOL("document.browse.links", N_("Missing fragment reporting"),
|
||||
|
@ -1509,14 +1509,16 @@ static int
|
||||
dec2qwerty(int num, char *link_sym, const char *key)
|
||||
{
|
||||
int base = strlen(key);
|
||||
int newlen = 1;
|
||||
int newlen, i, pow;
|
||||
|
||||
while (pow(base, newlen) < num) ++newlen;
|
||||
if (base < 2) return 0;
|
||||
|
||||
for (newlen = 1, pow = base; pow <= num; ++newlen, pow *= base);
|
||||
|
||||
link_sym[newlen] = '\0';
|
||||
for (int i=1; i<=newlen; ++i) {
|
||||
for (i = 1; i <= newlen; ++i) {
|
||||
int key_index = num % base;
|
||||
link_sym[newlen-i] = key[key_index];
|
||||
link_sym[newlen - i] = key[key_index];
|
||||
num /= base;
|
||||
}
|
||||
return newlen;
|
||||
@ -1531,11 +1533,13 @@ qwerty2dec(const char *link_sym, const char *key)
|
||||
int z = 0;
|
||||
int base = strlen(key);
|
||||
int symlen = strlen(link_sym);
|
||||
int i;
|
||||
int pow;
|
||||
|
||||
for (int i=0; i<symlen; ++i) {
|
||||
int j=0;
|
||||
while (key[j] != link_sym[symlen-1-i]) ++j;
|
||||
z += j*pow(base,i);
|
||||
for (i = 0, pow = 1; i < symlen; ++i, pow *= base) {
|
||||
int j = 0;
|
||||
while (key[j] != link_sym[symlen - 1 - i]) ++j;
|
||||
z += j * pow;
|
||||
}
|
||||
return z;
|
||||
}
|
||||
@ -1556,7 +1560,7 @@ put_link_number(struct html_context *html_context)
|
||||
format.form = NULL;
|
||||
|
||||
s[slen++] = '[';
|
||||
slen += dec2qwerty(part->link_num, s+1, symkey);
|
||||
slen += dec2qwerty(part->link_num, s + 1, symkey);
|
||||
s[slen++] = ']';
|
||||
s[slen] = '\0';
|
||||
|
||||
|
@ -44,12 +44,6 @@
|
||||
#include "viewer/text/search.h"
|
||||
#include "viewer/text/view.h"
|
||||
|
||||
static void
|
||||
link_dialog_action(struct session *ses)
|
||||
{
|
||||
open_link_dialog(ses);
|
||||
}
|
||||
|
||||
static void
|
||||
goto_url_action(struct session *ses,
|
||||
unsigned char *(*get_url)(struct session *, unsigned char *, size_t))
|
||||
@ -283,7 +277,7 @@ do_action(struct session *ses, enum main_action action_id, int verbose)
|
||||
break;
|
||||
|
||||
case ACT_MAIN_LINK_DIALOG:
|
||||
link_dialog_action(ses);
|
||||
open_link_dialog(ses);
|
||||
break;
|
||||
|
||||
case ACT_MAIN_LINK_DOWNLOAD:
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "dialogs/status.h"
|
||||
#include "document/document.h"
|
||||
#include "document/forms.h"
|
||||
#include "document/html/renderer.h"
|
||||
#include "document/options.h"
|
||||
#include "document/view.h"
|
||||
#include "ecmascript/ecmascript.h"
|
||||
@ -1219,15 +1220,16 @@ goto_link_number(struct session *ses, unsigned char *num)
|
||||
void
|
||||
goto_link_symbol(struct session *ses, unsigned char *sym)
|
||||
{
|
||||
char *symkey = get_opt_str("document_browse.links.label_key", ses);
|
||||
char *symkey = get_opt_str("document.browse.links.label_key", ses);
|
||||
struct document_view *doc_view;
|
||||
int num;
|
||||
|
||||
assert(ses && sym);
|
||||
if_assert_failed return;
|
||||
doc_view = current_frame(ses);
|
||||
assert(doc_view);
|
||||
if_assert_failed return;
|
||||
int num = qwerty2dec(sym, symkey);
|
||||
num = qwerty2dec(sym, symkey);
|
||||
goto_link_number_do(ses, doc_view, num - 1);
|
||||
}
|
||||
|
||||
|
@ -95,6 +95,8 @@ enum frame_event_status save_formatted_dlg(struct session *ses, struct document_
|
||||
enum frame_event_status view_image(struct session *ses, struct document_view *doc_view, int xxxx);
|
||||
enum frame_event_status download_link(struct session *ses, struct document_view *doc_view, action_id_T action_id);
|
||||
|
||||
void open_link_dialog(struct session *ses);
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user