Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old April 8, 2011, 11:58   #1
Max Stats
Swordsman
 
Join Date: Jun 2010
Posts: 324
Max Stats is on a distinguished road
Minor issue saving '\' in keymap in nightlies

I have encountered a very minor issue in the nightlies. I have a keymap for '^\', and when I save keymaps, the next time I load the game I receive an error that the line in the pref file with this keymap is too long. I assume that this is because the '\' character escapes the newline after it, and this messes everything up. I can fix it by editing the pref file and changing the trigger to '^\\'. This fixes it until the next time I save keymaps.

The fix seems to be writing two '\' characters anytime one is encountered in a keymap. I don't care too much, because once I get my keymaps set, I won't be saving them much anymore.
Max Stats is offline   Reply With Quote
Old April 8, 2011, 20:34   #2
myshkin
Angband Devteam member
 
Join Date: Apr 2007
Posts: 334
myshkin is on a distinguished road
Confirmed, and entered as bug 1389 on trac. Thanks for the report.
myshkin is offline   Reply With Quote
Old June 4, 2011, 20:21   #3
Max Stats
Swordsman
 
Join Date: Jun 2010
Posts: 324
Max Stats is on a distinguished road
For awhile, I thought that once I had my keymaps set, I wouldn't need to change them much, and this bug wouldn't be that annoying. Turns out, it is more annoying than I thought, as I still tweak my keymaps from time to time. In fact, it was annoying enough that I decided to take a swing at it and see if I could fix it on my copy. I think I have done it. Here is my patch:

Code:
diff --git a/src/keymap.c b/src/keymap.c
index 35a3304..d1a0818 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -174,12 +174,12 @@ void keymap_dump(ang_file *fff)
 		struct keypress key[2] = { { 0 }, { 0 } };
 
 		/* Encode the action */
-		keypress_to_text(buf, sizeof(buf), k->actions);
+		keypress_to_text(buf, sizeof(buf), k->actions, FALSE);
 		file_putf(fff, "A:%s\n", buf);
 
 		/* Convert the key into a string */
 		key[0] = k->key;
-		keypress_to_text(buf, sizeof(buf), key);
+		keypress_to_text(buf, sizeof(buf), key, TRUE);
 		file_putf(fff, "C:%d:%s\n", mode, buf);
 
 		file_putf(fff, "\n");
diff --git a/src/ui-event.c b/src/ui-event.c
index c9e9601..44412ef 100644
--- a/src/ui-event.c
+++ b/src/ui-event.c
@@ -221,7 +221,7 @@ void keypress_from_text(struct keypress *buf, size_t len, const char *str)
 /*
  * Convert a string of keypresses into their textual equivalent.
  */
-void keypress_to_text(char *buf, size_t len, const struct keypress *src)
+void keypress_to_text(char *buf, size_t len, const struct keypress *src, bool expand_backslash)
 {
 	size_t cur = 0;
 	size_t end = 0;
@@ -258,7 +258,13 @@ void keypress_to_text(char *buf, size_t len, const struct keypress *src)
 		} else {
 			switch (i) {
 				case '\a': strnfcat(buf, len, &end, "\a"); break;
-				case '\\': strnfcat(buf, len, &end, "\\"); break;
+				case '\\': {
+					if (expand_backslash)
+						   strnfcat(buf, len, &end, "\\\\");
+					else
+						   strnfcat(buf, len, &end, "\\");
+					break;
+				}
 				case '^': strnfcat(buf, len, &end, "\\^"); break;
 				case '[': strnfcat(buf, len, &end, "\\["); break;
 				default: {
diff --git a/src/ui-event.h b/src/ui-event.h
index 5becb8e..0942fe5 100644
--- a/src/ui-event.h
+++ b/src/ui-event.h
@@ -179,7 +179,7 @@ keycode_t keycode_find_code(const char *str, size_t len);
 const char *keycode_find_desc(keycode_t kc);
 
 /** Convert a string of keypresses into their textual representation */
-void keypress_to_text(char *buf, size_t len, const struct keypress *src);
+void keypress_to_text(char *buf, size_t len, const struct keypress *src, bool expand_backslash);
 
 /** Covert a textual representation of keypresses into actual keypresses */
 void keypress_from_text(struct keypress *buf, size_t len, const char *str);
diff --git a/src/ui-options.c b/src/ui-options.c
index ce5a849..7bc5e2a 100644
--- a/src/ui-options.c
+++ b/src/ui-options.c
@@ -367,7 +367,7 @@ static struct keypress keymap_get_trigger(void)
 	buf[0] = inkey();
 
 	/* Convert to ascii */
-	keypress_to_text(tmp, sizeof(tmp), buf);
+	keypress_to_text(tmp, sizeof(tmp), buf, FALSE);
 
 	/* Hack -- display the trigger */
 	Term_addstr(-1, TERM_WHITE, tmp);
@@ -420,7 +420,7 @@ static void ui_keymap_query(const char *title, int row)
 	else
 	{
 		/* Analyze the current action */
-		keypress_to_text(tmp, sizeof(tmp), act);
+		keypress_to_text(tmp, sizeof(tmp), act, FALSE);
 	
 		/* Display the current action */
 		prt("Found: ", 15, 0);
@@ -449,7 +449,7 @@ static void ui_keymap_create(const char *title, int row)
 	while (!done) {
 		struct keypress kp;
 
-		keypress_to_text(tmp, sizeof(tmp), keymap_buffer);
+		keypress_to_text(tmp, sizeof(tmp), keymap_buffer, FALSE);
 		c_prt(first ? TERM_YELLOW : TERM_WHITE,
 				format("Action: %s", tmp), 15, 0);
 
@@ -515,7 +515,7 @@ static void keymap_browse_hook(int oid, void *db, const region *loc)
 
 	/* Show current action */
 	prt("Current action (if any) shown below:", 13, 0);
-	keypress_to_text(tmp, sizeof(tmp), keymap_buffer);
+	keypress_to_text(tmp, sizeof(tmp), keymap_buffer, FALSE);
 	prt(tmp, 14, 0);
 }
Caveat: I poke around the code from time to time, but I am far from familiar with it, so a more elegant solution might be possible from someone more learned than I am. The gist of this is to add a flag to keypress_to_text that causes it to double the backslash character when it is TRUE. Everyone sets the flag to FALSE except keymap_dump, which sets it to true when outputting the "C:" lines.

I have tested this on my own pref files, which seem to work correctly, but I naturally can't guarantee that this won't introduce bugs of its own.
Max Stats is offline   Reply With Quote
Old June 4, 2011, 20:30   #4
Magnate
Angband Devteam member
 
Join Date: May 2007
Location: London, UK
Posts: 5,057
Magnate is on a distinguished road
Send a message via MSN to Magnate Send a message via Yahoo to Magnate
Quote:
Originally Posted by Max Stats View Post
For awhile, I thought that once I had my keymaps set, I wouldn't need to change them much, and this bug wouldn't be that annoying. Turns out, it is more annoying than I thought, as I still tweak my keymaps from time to time. In fact, it was annoying enough that I decided to take a swing at it and see if I could fix it on my copy. I think I have done it. Here is my patch:
Awesome - thank you. This looks fine at first glance, but the input layer is not my specialty so I will wait for one of the others to cast an eye over it before committing.
Magnate is offline   Reply With Quote
Old June 7, 2011, 10:21   #5
myshkin
Angband Devteam member
 
Join Date: Apr 2007
Posts: 334
myshkin is on a distinguished road
Quote:
Originally Posted by Max Stats View Post
Here is my patch:
Thanks! I have committed this change to staging, and it should be in a dev release shortly. Note that the keymap module does not actually map a bare '\', as that is needed for command escaping, but your change fixes behavior for keypresses like ^\.
myshkin is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Minor nightlies bugs Derakon Development 16 April 5, 2011 07:47
Can't use \r in keymap in latest nightly Max Stats Development 4 March 1, 2011 18:22
Keyboard basic keymap image fbas Vanilla 14 December 16, 2010 22:37
Minor squelch issue (3.1.2 v2)? piwakawaka Vanilla 2 March 12, 2010 08:16
new to rogue-like games, Q about saving ohnoitsphil Vanilla 4 February 22, 2008 15:37


All times are GMT +1. The time now is 14:52.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.