2 Copyright (C) 1995 Miguel de Icaza, Janne Kukonlehto
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #include <stdlib.h> /* For free() */
23 #if (!defined(__IBMC__) && !defined(__IBMCPP__)) && !defined(OS2_NT)
29 #include "util.h" /* For xmalloc() */
34 #include "key.h" /* XCTRL and ALT macros */
40 typedef void (*fnptr
)(void);
42 typedef struct Fkey_Table_List
{
44 struct Fkey_Table_List
*next
;
48 static Fkey_Table_List
*fkey_table_list
= NULL
;
50 /* Width of output is always seven characters */
51 void sprint_bytesize (char *buffer
, int size
, int scale
)
53 char scales
[] = " kMGT";
56 while (size
> 9999 && scale
< sizeof (scales
)){
57 size
= (size
+ 512) / 1024;
62 sprintf (buffer
, "%4d %cb", size
, scales
[scale
]);
64 sprintf (buffer
, "%4d b ", size
);
67 void print_bytesize (int size
, int scale
)
71 sprint_bytesize (buffer
, size
, scale
);
75 /* Return values: 0 = not a fkey, other = was a fkey */
76 int check_fkeys (int c
)
117 if (fkey_table_list
->actions
[fkey
]){
118 fkey_table_list
->actions
[fkey
] ();
125 /* Return values: 0 = not a movement key, 1 = was a movement key */
126 int check_movement_keys (int c
, int additional
, int page_size
, void *data
,
127 movefn backfn
, movefn forfn
, movefn topfn
,
143 (*backfn
)(data
, page_size
-1);
148 (*forfn
)(data
, page_size
-1);
157 (*bottomfn
)(data
, 0);
166 (*backfn
)(data
, page_size
-1);
169 (*forfn
)(data
, page_size
-1);
172 (*backfn
)(data
, page_size
/ 2);
175 (*forfn
)(data
, page_size
/ 2);
181 (*bottomfn
)(data
, 0);
187 void mc_raw_mode (void)
192 void mc_noraw_mode (void)
197 /* Classification routines */
198 int is_abort_char (int c
)
200 return (c
== XCTRL('c') || c
== XCTRL('g') || c
== ESC_CHAR
||
204 int is_quit_char (int c
)
206 return (c
== XCTRL('g') || (c
== ESC_CHAR
) || (c
== KEY_F(10)));
209 /* This table is a mapping between names and the constants we use
210 * We use this to allow users to define alternate definitions for
211 * certain keys that may be missing from the terminal database
213 key_code_name_t key_name_conv_tab
[] = {
214 /* KEY_F(0) is not here, since we are mapping it to f10, so there is no reason
215 to define f0 as well. Also, it makes Learn keys a bunch of problems :( */
216 { KEY_F(1), "f1", N_("Function key 1") },
217 { KEY_F(2), "f2", N_("Function key 2") },
218 { KEY_F(3), "f3", N_("Function key 3") },
219 { KEY_F(4), "f4", N_("Function key 4") },
220 { KEY_F(5), "f5", N_("Function key 5") },
221 { KEY_F(6), "f6", N_("Function key 6") },
222 { KEY_F(7), "f7", N_("Function key 7") },
223 { KEY_F(8), "f8", N_("Function key 8") },
224 { KEY_F(9), "f9", N_("Function key 9") },
225 { KEY_F(10), "f10", N_("Function key 10") },
226 { KEY_F(11), "f11", N_("Function key 11") },
227 { KEY_F(12), "f12", N_("Function key 12") },
228 { KEY_F(13), "f13", N_("Function key 13") },
229 { KEY_F(14), "f14", N_("Function key 14") },
230 { KEY_F(15), "f15", N_("Function key 15") },
231 { KEY_F(16), "f16", N_("Function key 16") },
232 { KEY_F(17), "f17", N_("Function key 17") },
233 { KEY_F(18), "f18", N_("Function key 18") },
234 { KEY_F(19), "f19", N_("Function key 19") },
235 { KEY_F(20), "f20", N_("Function key 20") },
236 { KEY_BACKSPACE
, "bs", N_("Backspace key") },
237 { KEY_END
, "end", N_("End key") },
238 { KEY_UP
, "up", N_("Up arrow key") },
239 { KEY_DOWN
, "down", N_("Down arrow key") },
240 { KEY_LEFT
, "left", N_("Left arrow key") },
241 { KEY_RIGHT
, "right", N_("Right arrow key") },
242 { KEY_HOME
, "home", N_("Home key") },
243 { KEY_NPAGE
, "pgdn", N_("Page Down key") },
244 { KEY_PPAGE
, "pgup", N_("Page Up key") },
245 { KEY_IC
, "insert", N_("Insert key") },
246 { KEY_DC
, "delete", N_("Delete key") },
247 { ALT('\t'), "complete", N_("Completion/M-tab") },
248 { KEY_KP_ADD
, "kpplus", N_("+ on keypad") },
249 { KEY_KP_SUBTRACT
,"kpminus", N_("- on keypad") },
250 { KEY_KP_MULTIPLY
,"kpasterix", N_("* on keypad") },
251 /* From here on, these won't be shown in Learn keys (no space) */
252 { KEY_LEFT
, "kpleft", N_("Left arrow keypad") },
253 { KEY_RIGHT
, "kpright", N_("Right arrow keypad") },
254 { KEY_UP
, "kpup", N_("Up arrow keypad") },
255 { KEY_DOWN
, "kpdown", N_("Down arrow keypad") },
256 { KEY_HOME
, "kphome", N_("Home on keypad") },
257 { KEY_END
, "kpend", N_("End on keypad") },
258 { KEY_NPAGE
, "kpnpage", N_("Page Down keypad") },
259 { KEY_PPAGE
, "kpppage", N_("Page Up keypad") },
260 { KEY_IC
, "kpinsert", N_("Insert on keypad") },
261 { KEY_DC
, "kpdelete", N_("Delete on keypad") },
262 { (int) '\n', "kpenter", N_("Enter on keypad") },
263 { (int) '/', "kpslash", N_("Slash on keypad") },
264 { (int) '#', "kpnumlock", N_("NumLock on keypad") },
268 /* Return the code associated with the symbolic name keyname */
269 int lookup_key (char *keyname
)
273 for (i
= 0; key_name_conv_tab
[i
].code
; i
++){
274 if (strcasecmp (key_name_conv_tab
[i
].name
, keyname
))
276 return key_name_conv_tab
[i
].code
;