Package: bsdgames
Version: 2.17-1
Severity: wishlist
Tags: patch

A wrote a patch for atc a couple years ago. It changes the keys used for
direction in the RULES structs depending on a command line option. I
just cleaned it up a bit to work with 2.17 in hope that others can use
it.

Please forward this feature to upstream if you think they may want it.


-- System Information:
Debian Release: 3.1
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing')
Architecture: i386 (i686)
Kernel: Linux 2.4.27-1-686
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)

Versions of packages bsdgames depends on:
ii  libc6                       2.3.2.ds1-18 GNU C Library: Shared libraries an
ii  libgcc1                     1:3.4.2-2    GCC support library
ii  libncurses5                 5.4-4        Shared libraries for terminal hand
ii  libstdc++5                  1:3.3.4-13   The GNU Standard C++ Library v3
ii  wamerican [wordlist]        5-4          American English dictionary words 
ii  wbritish [wordlist]         5-4          British English dictionary words f
ii  wenglish                    5-4          American English dictionary words 

-- no debconf information
diff -ru bsdgames-2.17-1.orig/atc/atc.6.in bsdgames-2.17-1.mine/atc/atc.6.in
--- bsdgames-2.17-1.orig/atc/atc.6.in   2004-01-02 10:04:51.000000000 -0800
+++ bsdgames-2.17-1.mine/atc/atc.6.in   2005-05-24 13:06:48.000000000 -0700
@@ -45,6 +45,7 @@
 .Op Fl u?lstp
 .Op Fl gf Ar "game name"
 .Op Fl r Ar "random seed"
+.Op Fl k Ar "keyboard"
 .Sh DESCRIPTION
 .Nm
 lets you try your hand at the nerve wracking duties of the air traffic
@@ -81,6 +82,11 @@
 .It Fl f Ar game
 Same as
 .Fl g .
+.It Fl k Ar keyboard
+Select an alternate keyboard map for the direction keys. ``dvorak'' uses
+keys around ``o'' in dvorak layout and ``numpad'' uses the numbers
+found on the right of many keyboards. The default is ``qwerty'', described in
+.Sx INPUT .
 .It Fl r Ar seed
 Set the random seed.
 The purpose of this flag is questionable.
@@ -223,11 +229,14 @@
 .Em [0\-9]
 means any single digit, and
 .Aq Em dir
-refers to a direction, given by the keys around the `s' key: ``wedcxzaq''.
+refers to a direction, given by a square of keys on the keyboard, by
+default the keys around the `s' in a qwerty layout: ``wedcxzaq''. The
+.Fl k
+option may be used to select a different group of keys.
 In absolute references, `q' refers to North-West or 315 degrees, and `w'
 refers to North, or 0 degrees.
 In relative references, `q' refers to \-45 degrees or 45 degrees left, and `w'
-refers to 0 degrees, or no change in direction.
+refers to 0 degrees, or no change in direction. 
 .Pp
 All commands start with a plane letter.
 This indicates the recipient of the command.
@@ -280,7 +289,10 @@
 (not
 .Em to
 .Aq dir . )
-`w' (0 degrees) is no turn.
+With the default keyboard map (
+.Fl k 
+qwerty
+) `w' (0 degrees) is no turn.
 `e' is 45 degrees; `q' gives \-45 degrees counterclockwise, that is,
 45 degrees clockwise.
 .It "t- [ dir ]"
diff -ru bsdgames-2.17-1.orig/atc/def.h bsdgames-2.17-1.mine/atc/def.h
--- bsdgames-2.17-1.orig/atc/def.h      2003-12-16 18:47:37.000000000 -0800
+++ bsdgames-2.17-1.mine/atc/def.h      2005-05-21 05:45:36.000000000 -0700
@@ -60,6 +60,8 @@
 
 #define MAXDIR         8
 
+#define KEYBOARD_DIR_NUM 3
+
 #define D_LEFT         1
 #define D_RIGHT                2
 #define D_UP           3
diff -ru bsdgames-2.17-1.orig/atc/extern.c bsdgames-2.17-1.mine/atc/extern.c
--- bsdgames-2.17-1.orig/atc/extern.c   2003-12-16 18:47:37.000000000 -0800
+++ bsdgames-2.17-1.mine/atc/extern.c   2005-05-21 05:45:36.000000000 -0700
@@ -54,7 +54,7 @@
 
 char           GAMES[] =       "Game_List";
 
-int            clck, safe_planes, start_time, test_mode;
+int            clck, safe_planes, start_time, test_mode, keyboard_dir;
 
 const char     *file;
 
@@ -66,6 +66,18 @@
 
 struct termios tty_start, tty_new;
 
+const char keyboard_dir_maps[KEYBOARD_DIR_NUM][MAXDIR] = {
+       {'w','e','d','c','x','z','a','q' },
+       {',','.','e','j','q',';','a','\'' },
+       {'8','9','6','3','2','1','4','7' }
+};
+
+const char * keyboard_dir_names[KEYBOARD_DIR_NUM] = {
+       "qwerty",
+       "dvorak",
+       "numpad"
+};
+
 DISPLACEMENT   displacement[MAXDIR] = {
                {  0, -1 },
                {  1, -1 },
diff -ru bsdgames-2.17-1.orig/atc/extern.h bsdgames-2.17-1.mine/atc/extern.h
--- bsdgames-2.17-1.orig/atc/extern.h   2004-01-27 12:52:07.000000000 -0800
+++ bsdgames-2.17-1.mine/atc/extern.h   2005-05-24 12:49:10.000000000 -0700
@@ -46,7 +46,11 @@
 extern char            GAMES[];
 extern const char      *file;
 
-extern int             clck, safe_planes, start_time, test_mode;
+extern int             clck, safe_planes, start_time, test_mode, keyboard_dir;
+
+const char keyboard_dir_maps[KEYBOARD_DIR_NUM][MAXDIR];
+
+const char * keyboard_dir_names[KEYBOARD_DIR_NUM];
 
 extern FILE            *filein, *fileout;
 
@@ -84,6 +88,7 @@
 void           ioclrtoeol(int);
 void           ioerror(int, int, const char *);
 void           iomove(int);
+int            keyboard_dir_remap(const char *);
 int            list_games(void);
 int            log_score(int);
 void           log_score_quit(int) __attribute__((__noreturn__));
diff -ru bsdgames-2.17-1.orig/atc/input.c bsdgames-2.17-1.mine/atc/input.c
--- bsdgames-2.17-1.orig/atc/input.c    2005-02-15 22:24:50.000000000 -0800
+++ bsdgames-2.17-1.mine/atc/input.c    2005-05-24 12:49:26.000000000 -0700
@@ -657,19 +657,65 @@
 {
        int     dir;
 
-       dir = -1;
-       switch (ch) {
-       case 'w':       dir = 0;        break;
-       case 'e':       dir = 1;        break;
-       case 'd':       dir = 2;        break;
-       case 'c':       dir = 3;        break;
-       case 'x':       dir = 4;        break;
-       case 'z':       dir = 5;        break;
-       case 'a':       dir = 6;        break;
-       case 'q':       dir = 7;        break;
-       default:
-               fprintf(stderr, "bad character in dir_no\n");
-               break;
+       for( dir=0; dir<MAXDIR; ++dir ) {
+               if( ch == keyboard_dir_maps[keyboard_dir][dir] )
+                       return (dir);
        }
-       return (dir);
+
+       fprintf(stderr, "bad character in dir_no\n");
+       return (-1);
+}
+
+// Load the map for the selected keyboard_dir into passed state rules
+// Call once for each state that uses the direction keys. Do not call
+// more than once with the same state.
+void
+keyboard_dir_load(state)
+       STATE state;
+{
+       int rule = 0;
+       int key = 0;
+
+       // Find the first direction rule by looking for the default
+       // key binding
+       while( rule<state.num_rules && state.rule[rule].token!='w' )
+               ++rule;
+
+       // Copy the new key bindings
+       for( key=0; key<MAXDIR && rule<state.num_rules;  ) {
+               state.rule[rule].token = keyboard_dir_maps[keyboard_dir][key];
+               rule++;
+               key++;
+       }
+
 }
+
+// Pass the name of a keyboard_dir map. Returns 1 on success,
+// -1 on error.
+// Call once to rename the keybindings in the rules. Do not call
+// again in the same execution.
+int
+keyboard_dir_remap(name)
+       const char  *name;
+{
+       int i;
+
+       for( i=0; i<KEYBOARD_DIR_NUM; i++ ) {
+               if( strcmp(name, keyboard_dir_names[i]) == 0) {
+                       keyboard_dir = i;
+                       if( i > 0 ) {
+                               // If name is not the default then modify the 
RULE structs for states that use directions
+                               keyboard_dir_load(st[2]);
+                               keyboard_dir_load(st[6]);
+                       }
+                       return 1;
+               }
+       }
+
+       fprintf( stderr, "Bad key map name. Your choices are: " );
+       for( i=0; i<KEYBOARD_DIR_NUM; i++ ) {
+               fprintf( stderr, "%s%s",  keyboard_dir_names[i], 
i!=(KEYBOARD_DIR_NUM-1)? ", " : "\n" );
+       }
+       return -1;
+}
+
diff -ru bsdgames-2.17-1.orig/atc/main.c bsdgames-2.17-1.mine/atc/main.c
--- bsdgames-2.17-1.orig/atc/main.c     2003-12-16 18:47:37.000000000 -0800
+++ bsdgames-2.17-1.mine/atc/main.c     2005-05-24 12:33:18.000000000 -0700
@@ -70,6 +70,7 @@
        int                     f_printpath = 0;
        const char              *file = NULL;
        int                     ch;
+       const char    *keyboard_dir_name = NULL;
        struct sigaction        sa;
 #ifdef BSD
        struct itimerval        itv;
@@ -81,7 +82,7 @@
 
        start_time = seed = time(NULL);
 
-       while ((ch = getopt(ac, av, "ulstpg:f:r:")) != -1) {
+       while ((ch = getopt(ac, av, "ulstpg:f:r:k:")) != -1) {
                switch (ch) {
                case '?':
                case 'u':
@@ -105,6 +106,9 @@
                case 'g':
                        file = optarg;
                        break;
+               case 'k':
+                       keyboard_dir_name = optarg;
+                       break;
                }
        }
        if (optind < ac)
@@ -113,7 +117,7 @@
 
        if (f_usage)
                fprintf(stderr, 
-                   "Usage: %s -[u?lstp] [-[gf] game_name] [-r random seed]\n",
+                   "Usage: %s -[u?lstp] [-[gf] game_name] [-r random seed] [-k 
keyboard map]\n",
                        av[0]);
        if (f_showscore)
                log_score(1);
@@ -135,9 +139,17 @@
        else
                file = okay_game(file);
 
+       // Force use of default keyboard when reading game
+       keyboard_dir = 0;
        if (file == NULL || read_file(file) < 0)
                exit(1);
 
+       if (keyboard_dir_name == NULL)
+               keyboard_dir = 0;
+       else
+               if (keyboard_dir_remap(keyboard_dir_name) < 0)
+                       exit(1);
+
        init_gr();
        setup_screen(sp);
 

Reply via email to