[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
lynx-dev keymap patches
From: |
John E. Davis |
Subject: |
lynx-dev keymap patches |
Date: |
Thu, 23 Apr 1998 14:09:15 -0400 |
Here are my keymap patches to lynx2.8.1dev6. The patches have no
effect if compiled with (n)curses. They only work with slang. I
incorporated the changes in such a way as to have little impact on the
current code: only two files were affected.
LYMain.c calls a function to initialize the keymaps. The changes to
LYStrings.c include small rearrangement of the mouse portion of the
code, and it includes a new file: sl-keymaps.c. Of course the files
should be merged but I chose to do it this way so that the developers
can clearly see what is going on.
The rest of this email consists of three parts:
1. A sample lynx-keymaps configuration file. This file only
required if one wants to modify the keymaps. If so, put this in
your home directory and call it .lynx-keymaps if using Unix, or
lynx.keymaps if using VMS.
2. The patches to LYMain.c and LYStrings.c
3. The include file: slkeymap.c
Enjoy.
--John
------- .lynx-keymaps -----------------------------------------------------
# This is a sample key sequence definition file.
# Lines that start with a '#' are comment lines. Blank lines are ignored.
# The 'setkey' function may be used in two ways:
#
# 1. setkey ESC-SEQUENCE KEYSYM
# 2. setkey ESC-SEQUENCE KEYSYM_NAME
#
# where KEYSYM is an integer. A keysym is essentually with the lynx.rc file
# calls a 'keystroke', but I think that keysym is a more appropriate name.
# The keysym integer and may be expressed in various ways:
#
# as a decimal integer: 97
# hexadecimal: 0x61
# Octal: 0141
# as an ASCII character: 'a'
#
# Some keysyms may be expressed symbolically as a keysym name using the
# second form. The currently recognized symbolic names are:
#
# UPARROW
# DNARROW
# RTARROW
# LTARROW
# PGDOWN
# PGUP
# HOME
# END
# F1
# DO_KEY
# FIND_KEY
# SELECT_KEY
# INSERT_KEY
# REMOVE_KEY
# DO_NOTHING
#
# It does not matter if your keyboard does not have some of the keys implied
# by the above names. The fact is that lynx uses these keys as an
# an intermediate representation.
#
# The ESC-SEQUENCE should be enclosed in double quotes. The '^' character
# is special and indicates a control character, e.g., ^K is Ctrl-K. An ESC
# character (ascii 27) may be represented as ^[. As an example, many
# terminals have arrow keys that emit 'ESC [ A' for the UP arrow. This may
# be represented as the escape sequence "^[[A". The default keymapping is
# given below:
#
setkey "\033[A" UPARROW
setkey "\033OA" UPARROW
setkey "\033[B" DNARROW
setkey "\033OB" DNARROW
setkey "\033[C" RTARROW
setkey "\033OC" RTARROW
setkey "\033[D" LTARROW
setkey "\033OD" LTARROW
setkey "\033[1~" FIND_KEY
setkey "\033[2~" INSERT_KEY
setkey "\033[3~" REMOVE_KEY
setkey "\033[4~" SELECT_KEY
setkey "\033[5~" PGUP
setkey "\033[6~" PGDOWN
setkey "\033[8~" END
setkey "\033[7~" HOME
setkey "\033[28~" F1
setkey "\033[29~" DO_KEY
#
# All other keys map to themselves, e.g,
#
setkey "a" 'a'
#
# Now suppose that your terminal produces different escape sequences for
# HOME and END. In particular, suppose that the home key produces
# 'ESC [ H' and that the end key produces 'ESC [ K'. Then these may be
# defined to map to lynx HOME and END keys via
#
setkey "^[[H" HOME
setkey "^[[K" END
#
# Similarly, we may map emacs-like sequences to these functions:
#
setkey "^[<" HOME
setkey "^[>" END
-------- Patches to LYMain.c and LYStrings.c --------------------------
--- lynx2-8/src/LYMain.c Sat Apr 18 18:29:08 1998
+++ lynx2.8.1dev.6/src/LYMain.c Thu Apr 23 02:20:12 1998
@@ -1170,6 +1170,14 @@
}
fclose(fp);
+#if defined (USE_SLANG)
+# define USE_SLANG_KEYMAPS 1
+#endif
+
+#if defined(USE_SLANG_KEYMAPS)
+ if (-1 == lynx_initialize_keymaps ())
+ exit (-1);
+#endif
/*
* Make sure we have the character sets declared.
* This will initialize the CHARTRANS handling. - KW
--- lynx2-8/src/LYStrings.c Wed Mar 25 08:58:54 1998
+++ lynx2.8.1dev.6/src/LYStrings.c Thu Apr 23 02:32:01 1998
@@ -296,6 +296,7 @@
*y = SLang_getkey () - 33;
return 0;
}
+
#endif
#if defined(USE_SLANG_MOUSE) || defined(NCURSES_MOUSE_VERSION)
@@ -315,12 +316,45 @@
}
#endif
+#if defined(USE_SLANG_MOUSE)
+PRIVATE int sl_read_mouse_event NOARGS
+{
+ int mouse_x, mouse_y, button;
+
+ mouse_link = -1;
+ if (-1 != sl_parse_mouse_event (&mouse_x, &mouse_y, &button))
+ {
+ if (button == 0) /* left */
+ return set_clicked_link (mouse_x, mouse_y);
+
+ if (button == 2) /* right */
+ {
+ /* Right button: go back to prev document.
+ * The problem is that we need to determine
+ * what to return to achieve this.
+ */
+ return map_function_to_key (LYK_PREV_DOC);
+ }
+ }
+ return -1;
+}
+#endif
+
PRIVATE BOOLEAN csi_is_csi = TRUE;
PUBLIC void ena_csi ARGS1(
BOOLEAN, flag)
{
csi_is_csi = flag;
}
+
+#if defined(USE_SLANG)
+# define USE_SLANG_KEYMAPS 1
+#endif
+
+#if defined(USE_SLANG_KEYMAPS)
+#include "sl-keymap.c"
+#else
+
/*
* LYgetch() translates some escape sequences and may fake noecho.
*/
@@ -444,23 +478,7 @@
#ifdef USE_SLANG_MOUSE
if ((c == 27) && (b == '['))
{
- int mouse_x, mouse_y, button;
-
- mouse_link = -1;
- c = -1;
- if (-1 != sl_parse_mouse_event (&mouse_x, &mouse_y, &button))
- {
- if (button == 0) /* left */
- c = set_clicked_link (mouse_x, mouse_y);
- else if (button == 2) /* right */
- {
- /* Right button: go back to prev document.
- * The problem is that we need to determine
- * what to return to achieve this.
- */
- c = map_function_to_key (LYK_PREV_DOC);
- }
- }
+ c = sl_read_mouse_event ();
}
else
#endif
@@ -708,6 +726,7 @@
}
}
+#endif /* NOT USE_SLANG_KEYMAPS */
/*
** Display the current value of the string and allow the user
---- The include file: sl-keymap.c ------------------------------
static SLKeyMap_List_Type *Keymap_List;
/* This value should be larger than anything in LYStrings.h */
#define MOUSE_KEYSYM 0x1000
typedef struct
{
char *name;
int keysym;
}
Keysym_String_List;
static Keysym_String_List Keysym_Strings [] =
{
{"UPARROW", UPARROW},
{"DNARROW", DNARROW},
{"RTARROW", RTARROW},
{"LTARROW", LTARROW},
{"PGDOWN", PGDOWN},
{"PGUP", PGUP},
{"HOME", HOME},
{"END", END},
{"F1", F1},
{"DO_KEY", DO_KEY},
{"FIND_KEY", FIND_KEY},
{"SELECT_KEY", SELECT_KEY},
{"INSERT_KEY", INSERT_KEY},
{"REMOVE_KEY", REMOVE_KEY},
{"DO_NOTHING", DO_NOTHING},
{NULL, -1}
};
static int map_string_to_keysym (char *str, int *keysym)
{
Keysym_String_List *k;
k = Keysym_Strings;
while (k->name != NULL)
{
if (0 == strcmp (k->name, str))
{
*keysym = k->keysym;
return 0;
}
k++;
}
fprintf (stderr, "Keysym %s is unknown\n", str);
*keysym = -1;
return -1;
}
/* The second argument may either be a string or and integer */
static int setkey_cmd (int argc, SLcmd_Cmd_Table_Type *table)
{
char *keyseq;
int keysym;
(void) argc;
keyseq = table->string_args [1];
switch (table->arg_type[2])
{
case SLANG_INT_TYPE:
keysym = table->int_args[2];
break;
case SLANG_STRING_TYPE:
if (-1 == map_string_to_keysym (table->string_args[2], &keysym))
return -1;
break;
default:
return -1;
}
return SLkm_define_keysym (keyseq, keysym, Keymap_List);
}
static int unsetkey_cmd (int argc, SLcmd_Cmd_Table_Type *table)
{
(void) argc;
SLang_undefine_key (table->string_args[1], Keymap_List);
if (SLang_Error) return -1;
return 0;
}
static SLcmd_Cmd_Type Keymap_Cmd_Table [] =
{
{setkey_cmd, "setkey", "SG"},
{unsetkey_cmd, "unsetkey", "S"},
{NULL}
};
static int read_keymap_file (void)
{
char line[1024];
FILE *fp;
char file[1024];
char *home;
char *keymap_file;
int ret;
SLcmd_Cmd_Table_Type tbl;
int linenum;
#ifdef VMS
keymap_file = "lynx.keymaps";
home = "SYS$LOGIN:";
#else
keymap_file = "/.lynx-keymaps";
home = getenv ("HOME");
if (home == NULL) home = "";
#endif
sprintf (file, "%s%s", home, keymap_file);
if (NULL == (fp = fopen (file, "r")))
return 0;
tbl.table = Keymap_Cmd_Table;
linenum = 0;
ret = 0;
while (NULL != fgets (line, sizeof (line), fp))
{
char *s = line;
linenum++;
while ((*s == ' ') || (*s == '\t') || (*s == '\n'))
s++;
if ((*s == 0) || (*s == '#'))
continue;
if (-1 == SLcmd_execute_string (s, &tbl))
{
ret = -1;
break;
}
}
fclose (fp);
if (ret == -1)
fprintf (stderr, "Error processing line %d of %s\n", linenum, file);
return ret;
}
int lynx_initialize_keymaps (void)
{
int i;
char keybuf[2];
if (NULL == (Keymap_List = SLang_create_keymap ("Lynx", NULL)))
return -1;
keybuf[1] = 0;
for (i = 1; i < 256; i++)
{
keybuf[0] = (char) i;
SLkm_define_keysym (keybuf, i, Keymap_List);
}
SLkm_define_keysym ("\033[A", UPARROW, Keymap_List);
SLkm_define_keysym ("\033OA", UPARROW, Keymap_List);
SLkm_define_keysym ("\033[B", DNARROW, Keymap_List);
SLkm_define_keysym ("\033OB", DNARROW, Keymap_List);
SLkm_define_keysym ("\033[C", RTARROW, Keymap_List);
SLkm_define_keysym ("\033OC", RTARROW, Keymap_List);
SLkm_define_keysym ("\033[D", LTARROW, Keymap_List);
SLkm_define_keysym ("\033OD", LTARROW, Keymap_List);
SLkm_define_keysym ("\033[1~", FIND_KEY, Keymap_List);
SLkm_define_keysym ("\033[2~", INSERT_KEY, Keymap_List);
SLkm_define_keysym ("\033[3~", REMOVE_KEY, Keymap_List);
SLkm_define_keysym ("\033[4~", SELECT_KEY, Keymap_List);
SLkm_define_keysym ("\033[5~", PGUP, Keymap_List);
SLkm_define_keysym ("\033[6~", PGDOWN, Keymap_List);
SLkm_define_keysym ("\033[8~", END, Keymap_List);
SLkm_define_keysym ("\033[7~", HOME, Keymap_List);
SLkm_define_keysym ("\033[28~", F1, Keymap_List);
SLkm_define_keysym ("\033[29~", DO_KEY, Keymap_List);
SLkm_define_keysym ("\033[M", MOUSE_KEYSYM, Keymap_List);
if (SLang_Error
|| (-1 == read_keymap_file ()))
SLang_exit_error ("Unable to initialize keymaps");
return 0;
}
int LYgetch (void)
{
SLang_Key_Type *key;
int keysym;
key = SLang_do_key (Keymap_List, (int (*)(void)) GetChar);
if ((key == NULL) || (key->type != SLKEY_F_KEYSYM))
return DO_NOTHING;
keysym = key->f.keysym;
#if defined (USE_SLANG_MOUSE)
if (keysym == MOUSE_KEYSYM)
return sl_read_mouse_event ();
#endif
if ((keysym > DO_NOTHING) || (keysym < 0))
return 0;
return keysym;
}
- lynx-dev keymap patches,
John E. Davis <=
- Re: lynx-dev keymap patches, John E. Davis, 1998/04/23
- Re: lynx-dev keymap patches, T.E.Dickey, 1998/04/23
- Re: lynx-dev keymap patches, T.E.Dickey, 1998/04/23
- Re: lynx-dev keymap patches, T.E.Dickey, 1998/04/23
- Re: lynx-dev keymap patches, John E. Davis, 1998/04/24