Code

Merge remote branches 'jn/cosmetics', 'jn/doxygen' and 'jn/renames'
[ncmpc.git] / src / command.c
index f323b12c457e189f5f6f99dad5ed85ab467a3a2f..0e7e5a2551b2f348088a6875a60ac77b79fabf17 100644 (file)
@@ -1,21 +1,21 @@
 /* ncmpc (Ncurses MPD Client)
  * (c) 2004-2010 The Music Player Daemon Project
  * Project homepage: http://musicpd.org
-
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
-
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
-
+ *
  * You should have received a copy of the GNU General Public License along
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
+ */
 
 #include "command.h"
 #include "config.h"
 #define DK(x)
 #endif
 
-#define BS KEY_BACKSPACE
-#define DEL KEY_DC
-#define UP KEY_UP
-#define DWN KEY_DOWN
+#define KEY_CTL(x) ((x) & 0x1f) /* KEY_CTL(A) == ^A == \1 */
+
+#define BS   KEY_BACKSPACE
+#define DEL  KEY_DC
+#define UP   KEY_UP
+#define DWN  KEY_DOWN
 #define LEFT KEY_LEFT
 #define RGHT KEY_RIGHT
 #define HOME KEY_HOME
-#define END KEY_END
+#define END  KEY_END
 #define PGDN KEY_NPAGE
 #define PGUP KEY_PPAGE
-#define TAB 0x09
+#define TAB  0x09
 #define STAB 0x161
-#define ESC 0x1B
-#define F1 KEY_F(1)
-#define F2 KEY_F(2)
-#define F3 KEY_F(3)
-#define F4 KEY_F(4)
-#define F5 KEY_F(5)
-#define F6 KEY_F(6)
-#define F7 KEY_F(7)
-#define F8 KEY_F(8)
-
+#define ESC  0x1B
+#define RET  '\r'
+#define F1   KEY_F(1)
+#define F2   KEY_F(2)
+#define F3   KEY_F(3)
+#define F4   KEY_F(4)
+#define F5   KEY_F(5)
+#define F6   KEY_F(6)
+#define F7   KEY_F(7)
+#define F8   KEY_F(8)
+#define C(x) KEY_CTL(x)
 
 static command_definition_t cmds[] = {
 #ifdef ENABLE_KEYDEF_SCREEN
        { {'K', 0, 0 }, 0, CMD_SCREEN_KEYDEF, "screen-keyedit",
          N_("Key configuration screen") },
 #endif
-       { { 'q', 'Q', 3 }, 0, CMD_QUIT, "quit",
+       { { 'q', 'Q', C('C') }, 0, CMD_QUIT, "quit",
          N_("Quit") },
 
        /* movement */
@@ -82,9 +85,9 @@ static command_definition_t cmds[] = {
          N_("Move cursor to the middle of screen") },
        { { 'L', 0, 0 }, 0, CMD_LIST_BOTTOM, "bottom",
          N_("Move cursor to the bottom of screen") },
-       { { HOME, 0x01, 0 }, 0, CMD_LIST_FIRST, "home",
+       { { HOME, C('A'), 0 }, 0, CMD_LIST_FIRST, "home",
          N_("Move cursor to the top of the list") },
-       { { END, 0x05, 0 }, 0, CMD_LIST_LAST, "end",
+       { { END, C('E'), 0 }, 0, CMD_LIST_LAST, "end",
          N_("Move cursor to the bottom of the list") },
        { { PGUP, 0, 0 }, 0, CMD_LIST_PREVIOUS_PAGE, "pgup",
          N_("Page up") },
@@ -92,9 +95,9 @@ static command_definition_t cmds[] = {
          N_("Page down") },
        { { 'v',  0, 0 }, 0, CMD_LIST_RANGE_SELECT, "range-select",
          N_("Range selection") },
-       { { 14,  0, 0 }, 0, CMD_LIST_SCROLL_DOWN_LINE, "scroll-down-line",
+       { { C('N'),  0, 0 }, 0, CMD_LIST_SCROLL_DOWN_LINE, "scroll-down-line",
          N_("Scroll up one line") },
-       { { 2,  0, 0 }, 0, CMD_LIST_SCROLL_UP_LINE, "scroll-up-line",
+       { { C('B'),  0, 0 }, 0, CMD_LIST_SCROLL_UP_LINE, "scroll-up-line",
          N_("Scroll down one line") },
        { { 'N',  0, 0 }, 0, CMD_LIST_SCROLL_DOWN_HALF, "scroll-down-half",
          N_("Scroll up half a screen") },
@@ -114,7 +117,7 @@ static command_definition_t cmds[] = {
 
 
        /* player commands */
-       { { 13, 0, 0 }, 0, CMD_PLAY, "play",
+       { { RET, 0, 0 }, 0, CMD_PLAY, "play",
          N_("Play/Enter directory") },
        { { 'P', 0, 0 }, 0, CMD_PAUSE,"pause",
          N_("Pause") },
@@ -154,7 +157,7 @@ static command_definition_t cmds[] = {
          N_("Toggle consume mode") },
        { { 'x', 0, 0 }, 0, CMD_CROSSFADE, "crossfade",
          N_("Toggle crossfade mode") },
-       { { 21, 0, 0 }, 0, CMD_DB_UPDATE, "db-update",
+       { { C('U'), 0, 0 }, 0, CMD_DB_UPDATE, "db-update",
          N_("Start a music database update") },
        { { 'S', 0, 0 }, 0, CMD_SAVE_PLAYLIST, "save",
          N_("Save playlist") },
@@ -170,11 +173,11 @@ static command_definition_t cmds[] = {
          N_("Locate song in browser") },
 
        /* lists */
-       { { 11, 0, 0 }, 0, CMD_LIST_MOVE_UP, "move-up",
+       { { C('K'), 0, 0 }, 0, CMD_LIST_MOVE_UP, "move-up",
          N_("Move item up") },
-       { { 10, 0, 0 }, 0, CMD_LIST_MOVE_DOWN, "move-down",
+       { { C('J'), 0, 0 }, 0, CMD_LIST_MOVE_DOWN, "move-down",
          N_("Move item down") },
-       { { 12, 0, 0 }, 0, CMD_SCREEN_UPDATE, "update",
+       { { C('L'), 0, 0 }, 0, CMD_SCREEN_UPDATE, "update",
          N_("Refresh screen") },
 
 
@@ -269,7 +272,7 @@ key2str(int key)
                return _("Undefined");
        case ' ':
                return _("Space");
-       case 13:
+       case RET:
                return _("Enter");
        case BS:
                return _("Backspace");
@@ -479,23 +482,20 @@ assign_keys(command_t command, int keys[MAX_COMMAND_KEYS])
 int
 check_key_bindings(command_definition_t *cp, char *buf, size_t bufsize)
 {
-       int i = 0;
+       int i;
        int retval = 0;
 
        if (cp == NULL)
                cp = cmds;
 
-       while (cp[i].name) {
+       for (i = 0; cp[i].name; i++)
                cp[i].flags &= ~COMMAND_KEY_CONFLICT;
-               i++;
-       }
 
-       i = 0;
-       while (cp[i].name) {
+       for (i = 0; cp[i].name; i++) {
                int j;
                command_t cmd;
 
-               for(j=0; j<MAX_COMMAND_KEYS; j++)
+               for(j=0; j<MAX_COMMAND_KEYS; j++) {
                        if (cp[i].keys[j] &&
                            (cmd = find_key_command(cp[i].keys[j],cp)) != cp[i].command) {
                                if (buf) {
@@ -516,8 +516,9 @@ check_key_bindings(command_definition_t *cp, char *buf, size_t bufsize)
                                set_key_flags(cp, cmd, COMMAND_KEY_CONFLICT);
                                retval = -1;
                        }
-               i++;
+               }
        }
+
        return retval;
 }