This patch moves the commands out of the header file and into main.c
and makes the COMMANDSIZE a compile time calculated const value. This
makes it so we don't need to remember to update that value each time a
new command is added, reduces likelihood of merge conflicts when
adding new commands, and should make things a bit more flexible in the
future (user defined colon commands?).
Regards,
Morgan
From f76b0ec8fea3963dcebdc8ebdcfac9de28e9c7d2 Mon Sep 17 00:00:00 2001
From: Morgan Howe <[email protected]>
Date: Sat, 24 Jan 2015 09:35:02 +0800
Subject: [PATCH 1/2] Move the commands list to main.c to get rid of
COMMANDSIZE define.
The COMMANDSIZE define needed to be incremented in a separate file any
time new commands were added. This made it easy to make mistakes, but
more importantly, caused frequent merge conflicts. Since the commands
list did not really need to be in the header file, I moved this into
main.c and made COMMANDSIZE an extern calculated at compile time. Also
cleaned up the whitespace in the commands list.
---
config.h | 54 ------------------------------------------------------
main.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
utilities.c | 8 ++++----
vimprobable.h | 3 ---
4 files changed, 59 insertions(+), 61 deletions(-)
diff --git a/config.h b/config.h
index a28d642..9713a3f 100644
--- a/config.h
+++ b/config.h
@@ -127,60 +127,6 @@ static Searchengine searchengines[] = {
static char defaultsearch[MAX_SETTING_SIZE] = "d";
-/* command mapping */
-Command commands[COMMANDSIZE] = {
- /* command, function, argument */
- { "ba", navigate, {NavigationBack} },
- { "back", navigate, {NavigationBack} },
- { "clear", clear, {0} },
- { "ec", script, {Info} },
- { "echo", script, {Info} },
- { "echoe", script, {Error} },
- { "echoerr", script, {Error} },
- { "fw", navigate, {NavigationForward} },
- { "fo", navigate, {NavigationForward} },
- { "forward", navigate, {NavigationForward} },
- { "javascript", script, {Silent} },
- { "o", open_arg, {TargetCurrent} },
- { "open", open_arg, {TargetCurrent} },
- { "q", quit, {0} },
- { "quit", quit, {0} },
- { "re", navigate, {NavigationReload} },
- { "re!", navigate, {NavigationForceReload} },
- { "reload", navigate, {NavigationReload} },
- { "reload!", navigate, {NavigationForceReload} },
- { "qt", search_tag, {0} },
- { "st", navigate, {NavigationCancel} },
- { "stop", navigate, {NavigationCancel} },
- { "t", open_arg, {TargetNew} },
- { "tabopen", open_arg, {TargetNew} },
- { "print", print_frame, {0} },
- { "bma", bookmark, {0} },
- { "bookmark", bookmark, {0} },
- { "source", view_source, {0} },
- { "esource", edit_source, {0} },
- { "openeditor", open_editor, {0} },
- { "set", browser_settings, {0} },
- { "map", mappings, {0} },
- { "inspect", open_inspector, {0} },
- { "jumpleft", scroll, {ScrollJumpTo | DirectionLeft} },
- { "jumpright", scroll, {ScrollJumpTo | DirectionRight} },
- { "jumptop", scroll, {ScrollJumpTo | DirectionTop} },
- { "jumpbottom", scroll, {ScrollJumpTo | DirectionBottom} },
- { "pageup", scroll, {ScrollMove | DirectionTop | UnitPage} },
- { "pagedown", scroll, {ScrollMove | DirectionBottom | UnitPage} },
- { "navigationback", navigate, {NavigationBack} },
- { "navigationforward", navigate, {NavigationForward} },
- { "scrollleft", scroll, {ScrollMove | DirectionLeft | UnitLine} },
- { "scrollright", scroll, {ScrollMove | DirectionRight | UnitLine} },
- { "scrollup", scroll, {ScrollMove | DirectionTop | UnitLine} },
- { "scrolldown", scroll, {ScrollMove | DirectionBottom | UnitLine} },
- { "zi", zoom, {ZoomIn | ZoomText} },
- { "zo", zoom, {ZoomOut | ZoomText} },
- { "pgzi", zoom, {ZoomIn | ZoomFullContent} },
- { "pgzo", zoom, {ZoomOut | ZoomFullContent} },
-};
-
/* mouse bindings
you can use MOUSE_BUTTON_1 to MOUSE_BUTTON_5
*/
diff --git a/main.c b/main.c
index e13bae5..cec7273 100644
--- a/main.c
+++ b/main.c
@@ -141,6 +141,61 @@ static void update_cookie_jar(SoupCookieJar *jar, SoupCookie *old, SoupCookie *n
static void handle_response_headers(SoupMessage *soup_msg, gpointer unused);
#endif
+/* command mapping */
+Command commands[] = {
+ /* command, function, argument */
+ { "ba", navigate, {NavigationBack} },
+ { "back", navigate, {NavigationBack} },
+ { "bma", bookmark, {0} },
+ { "bookmark", bookmark, {0} },
+ { "clear", clear, {0} },
+ { "ec", script, {Info} },
+ { "echo", script, {Info} },
+ { "echoe", script, {Error} },
+ { "echoerr", script, {Error} },
+ { "esource", edit_source, {0} },
+ { "fo", navigate, {NavigationForward} },
+ { "forward", navigate, {NavigationForward} },
+ { "fw", navigate, {NavigationForward} },
+ { "inspect", open_inspector, {0} },
+ { "jumpleft", scroll, {ScrollJumpTo | DirectionLeft} },
+ { "jumpright", scroll, {ScrollJumpTo | DirectionRight} },
+ { "jumptop", scroll, {ScrollJumpTo | DirectionTop} },
+ { "jumpbottom", scroll, {ScrollJumpTo | DirectionBottom} },
+ { "javascript", script, {Silent} },
+ { "map", mappings, {0} },
+ { "navigationback", navigate, {NavigationBack} },
+ { "navigationforward", navigate, {NavigationForward} },
+ { "o", open_arg, {TargetCurrent} },
+ { "open", open_arg, {TargetCurrent} },
+ { "openeditor", open_editor, {0} },
+ { "pageup", scroll, {ScrollMove | DirectionTop | UnitPage} },
+ { "pagedown", scroll, {ScrollMove | DirectionBottom | UnitPage} },
+ { "pgzi", zoom, {ZoomIn | ZoomFullContent} },
+ { "pgzo", zoom, {ZoomOut | ZoomFullContent} },
+ { "print", print_frame, {0} },
+ { "q", quit, {0} },
+ { "qt", search_tag, {0} },
+ { "quit", quit, {0} },
+ { "re", navigate, {NavigationReload} },
+ { "re!", navigate, {NavigationForceReload} },
+ { "reload", navigate, {NavigationReload} },
+ { "reload!", navigate, {NavigationForceReload} },
+ { "scrollleft", scroll, {ScrollMove | DirectionLeft | UnitLine} },
+ { "scrollright", scroll, {ScrollMove | DirectionRight | UnitLine} },
+ { "scrollup", scroll, {ScrollMove | DirectionTop | UnitLine} },
+ { "scrolldown", scroll, {ScrollMove | DirectionBottom | UnitLine} },
+ { "set", browser_settings, {0} },
+ { "source", view_source, {0} },
+ { "st", navigate, {NavigationCancel} },
+ { "stop", navigate, {NavigationCancel} },
+ { "t", open_arg, {TargetNew} },
+ { "tabopen", open_arg, {TargetNew} },
+ { "zi", zoom, {ZoomIn | ZoomText} },
+ { "zo", zoom, {ZoomOut | ZoomText} },
+};
+
+const size_t COMMANDSIZE = LENGTH(commands);
Client client;
/* callbacks */
diff --git a/utilities.c b/utilities.c
index 40df239..72e2322 100644
--- a/utilities.c
+++ b/utilities.c
@@ -14,7 +14,8 @@
#include "utilities.h"
extern Client client;
-extern Command commands[COMMANDSIZE];
+extern Command commands[];
+extern const size_t COMMANDSIZE;
extern Key keys[];
extern gboolean complete_case_sensitive;
static GList *dynamic_searchengines = NULL, *dynamic_uri_handlers = NULL;
@@ -446,7 +447,7 @@ process_mapping(char *keystring, int maprecord, char *cmd) {
gboolean
process_map_line(char *line) {
- int listlen, i;
+ int i;
char *c, *cmd;
my_pair.line = line;
c = search_word(0);
@@ -462,8 +463,7 @@ process_map_line(char *line) {
c = search_word(1);
if (!strlen(my_pair.value))
return FALSE;
- listlen = LENGTH(commands);
- for (i = 0; i < listlen; i++) {
+ for (i = 0; i < COMMANDSIZE; i++) {
/* commands is fixed size */
if (commands[i].cmd == NULL)
break;
diff --git a/vimprobable.h b/vimprobable.h
index 5f6ee83..4410dc1 100644
--- a/vimprobable.h
+++ b/vimprobable.h
@@ -192,9 +192,6 @@ enum ConfigFileError {
#define HISTORY_STORAGE_FILENAME "%s/vimprobable/history", client.config.config_base
#define CLOSED_URL_FILENAME "%s/vimprobable/closed", client.config.config_base
-/* Command size */
-#define COMMANDSIZE 49
-
/* maximum size of internal string variable handled by :set
* if you set this to anything lower than 8, colour values
* will stop working */
--
2.2.2
------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
_______________________________________________
Vimprobable-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vimprobable-users