Skip to content

Instantly share code, notes, and snippets.

@deton
Created December 31, 2022 03:43
Show Gist options
  • Save deton/8607ef08521b25199e81f11b7bd2e8bd to your computer and use it in GitHub Desktop.
Save deton/8607ef08521b25199e81f11b7bd2e8bd to your computer and use it in GitHub Desktop.
Lynx patch to disable toolbar by lynx.cfg
diff --git a/LYMessages_en.h b/LYMessages_en.h
index 7014be6..ac64f9a 100644
--- a/LYMessages_en.h
+++ b/LYMessages_en.h
@@ -426,6 +426,7 @@
#define NO_EDITOR gettext("No editor is defined!")
#define PRINT_DISABLED gettext("The 'p'rint command is currently disabled.")
#define NO_TOOLBAR gettext("Document has no Toolbar links or Banner.")
+#define TOOLBAR_DISABLED gettext("Toolbar is currently disabled.")
#define CANNOT_OPEN_TRAV_FILE gettext("Unable to open traversal file.")
#define CANNOT_OPEN_TRAF_FILE gettext("Unable to open traversal found file.")
#define CANNOT_OPEN_REJ_FILE gettext("Unable to open reject file.")
diff --git a/src/HTML.c b/src/HTML.c
index 660106e..8f7115e 100644
--- a/src/HTML.c
+++ b/src/HTML.c
@@ -1397,6 +1397,13 @@ static int HTML_start_element(HTStructured * me, int element_number,
HTML_end_element(me, HTML_A, include);
}
+ if (no_toolbar) {
+ FREE(temp);
+ FREE(href);
+ FREE(title);
+ break;
+ }
+
/*
* Create anchors for the links that simulate a toolbar. - FM
*/
@@ -1683,7 +1690,8 @@ static int HTML_start_element(HTStructured * me, int element_number,
* Treat this as a toolbar if we don't have one yet, and we are in the
* first half of the first page. - FM
*/
- if ((!HText_hasToolbar(me->text) &&
+ if (!no_toolbar &&
+ (!HText_hasToolbar(me->text) &&
HText_getLines(me->text) < (display_lines / 2)) &&
(ID_A = HTAnchor_findChildAndLink(me->node_anchor, /* Parent */
LYToolbarName, /* Tag */
diff --git a/src/LYGlobalDefs.h b/src/LYGlobalDefs.h
index 8011c66..0a99ca8 100644
--- a/src/LYGlobalDefs.h
+++ b/src/LYGlobalDefs.h
@@ -388,7 +388,6 @@ extern "C" {
extern char *personal_mail_name;
extern char *homepage; /* startfile or command line argument */
extern char *editor; /* if non empty it enables edit mode with
-
* the editor that is named */
extern char *jumpfile;
extern char *bookmark_page;
@@ -406,6 +405,7 @@ extern "C" {
extern BOOLEAN no_margins;
extern BOOLEAN no_pause;
extern BOOLEAN no_title;
+ extern BOOLEAN no_toolbar;
extern BOOLEAN update_term_title;
extern BOOLEAN historical_comments;
extern BOOLEAN html5_charsets;
diff --git a/src/LYMain.c b/src/LYMain.c
index 0c4ea33..3ffc1e3 100644
--- a/src/LYMain.c
+++ b/src/LYMain.c
@@ -413,6 +413,7 @@ BOOLEAN no_list = FALSE;
BOOLEAN no_margins = FALSE;
BOOLEAN no_pause = FALSE;
BOOLEAN no_title = FALSE;
+BOOLEAN no_toolbar = FALSE;
BOOLEAN update_term_title = FALSE;
BOOLEAN no_url_redirection = FALSE; /* Don't follow URL redirections */
BOOLEAN pseudo_inline_alts = MAKE_PSEUDO_ALTS_FOR_INLINES;
diff --git a/src/LYMainLoop.c b/src/LYMainLoop.c
index 7a3df1c..73232fb 100644
--- a/src/LYMainLoop.c
+++ b/src/LYMainLoop.c
@@ -4754,7 +4754,10 @@ static void handle_LYK_TOOLBAR(BOOLEAN *try_internal,
if (!HText_hasToolbar(HTMainText)) {
if (*old_c != real_c) {
*old_c = real_c;
- HTUserMsg(NO_TOOLBAR);
+ if (no_toolbar)
+ HTUserMsg(TOOLBAR_DISABLED);
+ else
+ HTUserMsg(NO_TOOLBAR);
}
} else if (*old_c != real_c) {
*old_c = real_c;
diff --git a/src/LYReadCFG.c b/src/LYReadCFG.c
index 9523527..ba24f1f 100644
--- a/src/LYReadCFG.c
+++ b/src/LYReadCFG.c
@@ -1656,6 +1656,7 @@ static Config_Type Config_Table [] =
PARSE_SET(RC_NO_REFERER_HEADER, LYNoRefererHeader),
PARSE_SET(RC_NO_TABLE_CENTER, no_table_center),
PARSE_SET(RC_NO_TITLE, no_title),
+ PARSE_SET(RC_NO_TOOLBAR, no_toolbar),
PARSE_SET(RC_UPDATE_TERM_TITLE, update_term_title),
PARSE_FUN(RC_NONRESTARTING_SIGWINCH, nonrest_sigwinch_fun),
PARSE_FUN(RC_OUTGOING_MAIL_CHARSET, outgoing_mail_charset_fun),
diff --git a/src/LYrcFile.h b/src/LYrcFile.h
index bf9a54b..436566c 100644
--- a/src/LYrcFile.h
+++ b/src/LYrcFile.h
@@ -180,6 +180,7 @@
#define RC_NO_REFERER_HEADER "no_referer_header"
#define RC_NO_TABLE_CENTER "no_table_center"
#define RC_NO_TITLE "no_title"
+#define RC_NO_TOOLBAR "no_toolbar"
#define RC_NUMBER_FIELDS_ON_LEFT "number_fields_on_left"
#define RC_NUMBER_LINKS_ON_LEFT "number_links_on_left"
#define RC_OUTGOING_MAIL_CHARSET "outgoing_mail_charset"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment