From ef7c78910c069362a15a51c9f917c1697bbf2f67 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Thu, 12 Dec 2019 12:34:56 +0100 Subject: [PATCH] tweaks: reshuffle a few lines, for brevity or speed or consistency Also, don't compare case-insensitively where it is not needed. --- src/global.c | 16 ++++++---------- src/rcfile.c | 7 +++---- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/global.c b/src/global.c index c0818f9f..1d23ccf4 100644 --- a/src/global.c +++ b/src/global.c @@ -489,7 +489,7 @@ int keycode_from_string(const char *keystring) if (strcasecmp(keystring, "^Space") == 0) return 0; #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__) - if (strcasecmp(keystring, "^H") == 0) + if (strcmp(keystring, "^H") == 0) return KEY_BACKSPACE; #endif if (keystring[1] == '/' && keystring[2] == '\0') @@ -499,10 +499,10 @@ int keycode_from_string(const char *keystring) else return -1; } else if (keystring[0] == 'M') { - if (strcasecmp(keystring, "M-Space") == 0) - return (int)' '; if (keystring[1] == '-' && keystring[3] == '\0') return tolower((unsigned char)keystring[2]); + if (strcasecmp(keystring, "M-Space") == 0) + return (int)' '; else return -1; } else if (keystring[0] == 'F') { @@ -510,9 +510,9 @@ int keycode_from_string(const char *keystring) if (fn < 1 || fn > 24) return -1; return KEY_F0 + fn; - } else if (!strcasecmp(keystring, "Ins")) + } else if (strcasecmp(keystring, "Ins") == 0) return KEY_IC; - else if (!strcasecmp(keystring, "Del")) + else if (strcasecmp(keystring, "Del") == 0) return KEY_DC; else return -1; @@ -523,11 +523,7 @@ void assign_keyinfo(keystruct *s, const char *keystring, const int keycode) { s->keystr = keystring; s->meta = (keystring[0] == 'M' && keycode == 0); - - if (keycode) - s->keycode = keycode; - else - s->keycode = keycode_from_string(keystring); + s->keycode = (keycode ? keycode : keycode_from_string(keystring)); } /* These two tags are used elsewhere too, so they are global. */ diff --git a/src/rcfile.c b/src/rcfile.c index 00922990..97993561 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -428,12 +428,11 @@ void parse_binding(char *ptr, bool dobind) keycopy[0] = toupper((unsigned char)keycopy[0]); keycopy[1] = toupper((unsigned char)keycopy[1]); if (keycopy[0] == 'M' && keycopy[1] == '-') { - if (keycopy[2] != '\0') - keycopy[2] = toupper((unsigned char)keycopy[2]); - else { + if (keycopy[2] == '\0') { jot_error(N_("Key name is too short")); goto free_things; - } + } else + keycopy[2] = toupper((unsigned char)keycopy[2]); } /* Allow the codes for Insert and Delete to be rebound, but apart