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"),
|
INIT_OPT_STRING("document.browse.links", N_("Specify link label key"),
|
||||||
"label_key", 0, "0123456789",
|
"label_key", 0, "0123456789",
|
||||||
N_("Default is 0123456789, which is standard numeric labeling."
|
N_("Default is 0123456789, which is standard numeric labeling. "
|
||||||
"Ascii based strings like gfdsahjkl;trewqyuiopvcxznm can also"
|
"Ascii based strings like gfdsahjkl;trewqyuiopvcxznm can also "
|
||||||
"be used.")),
|
"be used.")),
|
||||||
|
|
||||||
INIT_OPT_BOOL("document.browse.links", N_("Missing fragment reporting"),
|
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)
|
dec2qwerty(int num, char *link_sym, const char *key)
|
||||||
{
|
{
|
||||||
int base = strlen(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';
|
link_sym[newlen] = '\0';
|
||||||
for (int i=1; i<=newlen; ++i) {
|
for (i = 1; i <= newlen; ++i) {
|
||||||
int key_index = num % base;
|
int key_index = num % base;
|
||||||
link_sym[newlen-i] = key[key_index];
|
link_sym[newlen - i] = key[key_index];
|
||||||
num /= base;
|
num /= base;
|
||||||
}
|
}
|
||||||
return newlen;
|
return newlen;
|
||||||
@ -1531,11 +1533,13 @@ qwerty2dec(const char *link_sym, const char *key)
|
|||||||
int z = 0;
|
int z = 0;
|
||||||
int base = strlen(key);
|
int base = strlen(key);
|
||||||
int symlen = strlen(link_sym);
|
int symlen = strlen(link_sym);
|
||||||
|
int i;
|
||||||
|
int pow;
|
||||||
|
|
||||||
for (int i=0; i<symlen; ++i) {
|
for (i = 0, pow = 1; i < symlen; ++i, pow *= base) {
|
||||||
int j=0;
|
int j = 0;
|
||||||
while (key[j] != link_sym[symlen-1-i]) ++j;
|
while (key[j] != link_sym[symlen - 1 - i]) ++j;
|
||||||
z += j*pow(base,i);
|
z += j * pow;
|
||||||
}
|
}
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
@ -1556,7 +1560,7 @@ put_link_number(struct html_context *html_context)
|
|||||||
format.form = NULL;
|
format.form = NULL;
|
||||||
|
|
||||||
s[slen++] = '[';
|
s[slen++] = '[';
|
||||||
slen += dec2qwerty(part->link_num, s+1, symkey);
|
slen += dec2qwerty(part->link_num, s + 1, symkey);
|
||||||
s[slen++] = ']';
|
s[slen++] = ']';
|
||||||
s[slen] = '\0';
|
s[slen] = '\0';
|
||||||
|
|
||||||
|
@ -44,12 +44,6 @@
|
|||||||
#include "viewer/text/search.h"
|
#include "viewer/text/search.h"
|
||||||
#include "viewer/text/view.h"
|
#include "viewer/text/view.h"
|
||||||
|
|
||||||
static void
|
|
||||||
link_dialog_action(struct session *ses)
|
|
||||||
{
|
|
||||||
open_link_dialog(ses);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
goto_url_action(struct session *ses,
|
goto_url_action(struct session *ses,
|
||||||
unsigned char *(*get_url)(struct session *, unsigned char *, size_t))
|
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;
|
break;
|
||||||
|
|
||||||
case ACT_MAIN_LINK_DIALOG:
|
case ACT_MAIN_LINK_DIALOG:
|
||||||
link_dialog_action(ses);
|
open_link_dialog(ses);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ACT_MAIN_LINK_DOWNLOAD:
|
case ACT_MAIN_LINK_DOWNLOAD:
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "dialogs/status.h"
|
#include "dialogs/status.h"
|
||||||
#include "document/document.h"
|
#include "document/document.h"
|
||||||
#include "document/forms.h"
|
#include "document/forms.h"
|
||||||
|
#include "document/html/renderer.h"
|
||||||
#include "document/options.h"
|
#include "document/options.h"
|
||||||
#include "document/view.h"
|
#include "document/view.h"
|
||||||
#include "ecmascript/ecmascript.h"
|
#include "ecmascript/ecmascript.h"
|
||||||
@ -1219,15 +1220,16 @@ goto_link_number(struct session *ses, unsigned char *num)
|
|||||||
void
|
void
|
||||||
goto_link_symbol(struct session *ses, unsigned char *sym)
|
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;
|
struct document_view *doc_view;
|
||||||
|
int num;
|
||||||
|
|
||||||
assert(ses && sym);
|
assert(ses && sym);
|
||||||
if_assert_failed return;
|
if_assert_failed return;
|
||||||
doc_view = current_frame(ses);
|
doc_view = current_frame(ses);
|
||||||
assert(doc_view);
|
assert(doc_view);
|
||||||
if_assert_failed return;
|
if_assert_failed return;
|
||||||
int num = qwerty2dec(sym, symkey);
|
num = qwerty2dec(sym, symkey);
|
||||||
goto_link_number_do(ses, doc_view, num - 1);
|
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 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);
|
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
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user