1 /* $Id: func.c,v 1.27 2003/09/26 17:59:51 ukai Exp $ */
13 #include "functable.c"
15 #define KEYDATA_HASH_SIZE 16
16 static Hash_iv *keyData = NULL;
17 static char keymap_initialized = FALSE;
18 static struct stat sys_current_keymap_file;
19 static struct stat current_keymap_file;
22 setKeymap(char *p, int lineno, int verbose)
24 unsigned char *map = NULL;
30 if (c < 0) { /* error */
32 /* FIXME: gettextize? */
33 emsg = Sprintf("line %d: unknown key '%s'", lineno, s)->ptr;
35 /* FIXME: gettextize? */
36 emsg = Sprintf("defkey: unknown key '%s'", s)->ptr;
37 record_err_message(emsg);
39 disp_message_nsec(emsg, FALSE, 1, TRUE, FALSE);
46 /* FIXME: gettextize? */
47 emsg = Sprintf("line %d: invalid command '%s'", lineno, s)->ptr;
49 /* FIXME: gettextize? */
50 emsg = Sprintf("defkey: invalid command '%s'", s)->ptr;
51 record_err_message(emsg);
53 disp_message_nsec(emsg, FALSE, 1, TRUE, FALSE);
57 unsigned char **mmap = NULL;
58 int i, j, m = MULTI_KEY(c);
68 if (map[m & 0x7F] == FUNCNAME_multimap)
69 mmap = (unsigned char **)getKeyData(m);
71 map[m & 0x7F] = FUNCNAME_multimap;
73 mmap = New_N(unsigned char *, 4);
74 for (i = 0; i < 4; i++) {
75 mmap[i] = New_N(unsigned char, 128);
76 for (j = 0; j < 128; j++)
77 mmap[i][j] = FUNCNAME_nulcmd;
79 mmap[0][ESC_CODE] = FUNCNAME_escmap;
80 mmap[1]['['] = FUNCNAME_escbmap;
81 mmap[1]['O'] = FUNCNAME_escbmap;
84 keyData = newHash_iv(KEYDATA_HASH_SIZE);
85 putHash_iv(keyData, m, (void *)mmap);
109 keyData = newHash_iv(KEYDATA_HASH_SIZE);
110 putHash_iv(keyData, c, (void *)s);
112 else if (getKeyData(c))
113 putHash_iv(keyData, c, NULL);
117 interpret_keymap(FILE * kf, struct stat *current, int force)
125 wc_ces charset = SystemCharset;
128 extern int str_to_bool(char *value, int old);
130 if ((fd = fileno(kf)) < 0 || fstat(fd, &kstat) ||
132 kstat.st_mtime == current->st_mtime &&
133 kstat.st_dev == current->st_dev &&
134 kstat.st_ino == current->st_ino && kstat.st_size == current->st_size))
143 Strremovefirstspaces(line);
144 if (line->length == 0)
147 line = wc_Str_conv(line, charset, InnerCharset);
151 if (*s == '#') /* comment */
153 if (!strcmp(s, "keymap")) ;
155 else if (!strcmp(s, "charset") || !strcmp(s, "encoding")) {
158 charset = wc_guess_charset(s, charset);
162 else if (!strcmp(s, "verbose")) {
165 verbose = str_to_bool(s, verbose);
169 emsg = Sprintf("line %d: syntax error '%s'", lineno, s)->ptr;
170 record_err_message(emsg);
172 disp_message_nsec(emsg, FALSE, 1, TRUE, FALSE);
175 setKeymap(p, lineno, verbose);
180 initKeymap(int force)
184 if ((kf = fopen(confFile(KEYMAP_FILE), "rt")) != NULL) {
185 interpret_keymap(kf, &sys_current_keymap_file,
186 force || !keymap_initialized);
189 if ((kf = fopen(rcFile(keymap_file), "rt")) != NULL) {
190 interpret_keymap(kf, ¤t_keymap_file,
191 force || !keymap_initialized);
194 keymap_initialized = TRUE;
198 getFuncList(char *id)
200 return getHash_si(&functable, id, -1);
208 return (char *)getHash_iv(keyData, key, NULL);
215 int c, esc = 0, ctrl = 0;
217 if (s == NULL || *s == '\0')
220 if (strcasecmp(s, "UP") == 0) { /* ^[[A */
224 else if (strcasecmp(s, "DOWN") == 0) { /* ^[[B */
228 else if (strcasecmp(s, "RIGHT") == 0) { /* ^[[C */
232 else if (strcasecmp(s, "LEFT") == 0) { /* ^[[D */
237 if (strncasecmp(s, "ESC-", 4) == 0 || strncasecmp(s, "ESC ", 4) == 0) { /* ^[ */
241 else if (strncasecmp(s, "M-", 2) == 0 || strncasecmp(s, "\\E", 2) == 0) { /* ^[ */
245 else if (*s == ESC_CODE) { /* ^[ */
249 if (strncasecmp(s, "C-", 2) == 0) { /* ^, ^[^ */
253 else if (*s == '^' && *(s + 1)) { /* ^, ^[^ */
257 if (!esc && ctrl && *s == '[') { /* ^[ */
263 if (*s == '[' || *s == 'O') { /* ^[[, ^[O */
267 if (strncasecmp(s, "C-", 2) == 0) { /* ^[^, ^[[^ */
271 else if (*s == '^' && *(s + 1)) { /* ^[^, ^[[^ */
279 if (*s >= '@' && *s <= '_') /* ^@ .. ^_ */
280 return esc | (*s - '@');
281 else if (*s >= 'a' && *s <= 'z') /* ^a .. ^z */
282 return esc | (*s - 'a' + 1);
283 else if (*s == '?') /* ^? */
284 return esc | DEL_CODE;
289 if (esc == K_ESCB && IS_DIGIT(*s)) {
293 c = c * 10 + (int)(*s - '0');
303 if (strncasecmp(s, "SPC", 3) == 0) { /* ' ' */
307 else if (strncasecmp(s, "TAB", 3) == 0) { /* ^i */
311 else if (strncasecmp(s, "DEL", 3) == 0) { /* ^? */
313 return esc | DEL_CODE;
316 if (*s == '\\' && *(s + 1) != '\0') {
331 return esc | ESC_CODE;
341 if (IS_ASCII(*s)) /* Ascii */
355 if (*s == ' ' || *s == '-')
361 c = K_MULTI | (c << 16) | c2;
373 for (s = p; *p && !IS_SPACE(*p) && *p != ';'; p++) ;
375 return Strnew_charp_n(s, p - s)->ptr;
383 int in_q = 0, in_dq = 0, esc = 0;
390 if (*p != '\\' && *p != '\'') /* '..\\..', '..\'..' */
391 Strcat_char(tmp, '\\');
394 if (*p != '\\' && *p != '"') /* "..\\..", "..\".." */
395 Strcat_char(tmp, '\\');
398 if (*p != '\\' && *p != '\'' && /* ..\\.., ..\'.. */
399 *p != '"' && !IS_SPACE(*p)) /* ..\".., ..\.. */
400 Strcat_char(tmp, '\\');
402 Strcat_char(tmp, *p);
405 else if (*p == '\\') {
412 Strcat_char(tmp, *p);
418 Strcat_char(tmp, *p);
420 else if (*p == '\'') {
423 else if (*p == '"') {
426 else if (IS_SPACE(*p) || *p == ';') {
430 Strcat_char(tmp, *p);
438 static MouseAction default_mouse_action = {
442 {{movMs, NULL}, {backBf, NULL}, {menuMs, NULL}}, /* default */
443 {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}, /* anchor */
444 {{followA, NULL}, {NULL, NULL}, {NULL, NULL}}, /* active */
445 {{tabMs, NULL}, {closeTMs, NULL}, {NULL, NULL}}, /* tab */
446 {NULL, NULL, NULL}, /* menu */
447 {NULL, NULL, NULL} /* lastline */
449 static MouseActionMap default_lastline_action[6] = {
459 setMouseAction0(char **str, int *width, MouseActionMap ** map, char *p)
468 for (b = 0; b < 3; b++)
474 *width = get_strwidth(s);
475 if (*width >= LIMIT_MOUSE_MENU)
476 *width = LIMIT_MOUSE_MENU;
479 for (b = 0; b < 3; b++) {
482 map[b] = New_Reuse(MouseActionMap, map[b], *width);
483 for (x = w + 1; x < *width; x++) {
484 map[b][x].func = NULL;
485 map[b][x].data = NULL;
491 setMouseAction1(MouseActionMap ** map, int width, char *p)
497 *map = New_N(MouseActionMap, width);
498 for (x = 0; x < width; x++) {
499 (*map)[x].func = NULL;
500 (*map)[x].data = NULL;
505 if (!(IS_DIGIT(*s) && x >= 0 && x < width))
509 if (!(IS_DIGIT(*s) && x2 >= 0 && x2 < width))
516 for (; x <= x2; x++) {
517 (*map)[x].func = (f >= 0) ? w3mFuncList[f].func : NULL;
523 setMouseAction2(MouseActionMap * map, char *p)
533 map->func = (f >= 0) ? w3mFuncList[f].func : NULL;
538 interpret_mouse_action(FILE * mf)
547 Strremovefirstspaces(line);
548 if (line->length == 0)
550 p = conv_from_system(line->ptr);
552 if (*s == '#') /* comment */
554 if (!strcmp(s, "menu")) {
555 setMouseAction0(&mouse_action.menu_str, &mouse_action.menu_width,
556 mouse_action.menu_map, p);
559 else if (!strcmp(s, "lastline")) {
560 setMouseAction0(&mouse_action.lastline_str,
561 &mouse_action.lastline_width,
562 mouse_action.lastline_map, p);
565 if (strcmp(s, "button"))
566 continue; /* error */
569 if (!(b >= 0 && b <= 2))
570 continue; /* error */
576 if (!strcasecmp(s, "menu")) {
577 if (!mouse_action.menu_str)
579 setMouseAction1(&mouse_action.menu_map[b], mouse_action.menu_width,
582 else if (!strcasecmp(s, "lastline")) {
583 if (!mouse_action.lastline_str)
585 setMouseAction1(&mouse_action.lastline_map[b],
586 mouse_action.lastline_width, p);
588 else if (!strcasecmp(s, "default"))
589 setMouseAction2(&mouse_action.default_map[b], p);
590 else if (!strcasecmp(s, "anchor"))
591 setMouseAction2(&mouse_action.anchor_map[b], p);
592 else if (!strcasecmp(s, "active"))
593 setMouseAction2(&mouse_action.active_map[b], p);
594 else if (!strcasecmp(s, "tab"))
595 setMouseAction2(&mouse_action.tab_map[b], p);
600 initMouseAction(void)
604 bcopy((void *)&default_mouse_action, (void *)&mouse_action,
605 sizeof(default_mouse_action));
606 mouse_action.lastline_map[0] = New_N(MouseActionMap, 6);
607 bcopy((void *)&default_lastline_action,
608 (void *)mouse_action.lastline_map[0],
609 sizeof(default_lastline_action));
613 char **symbol = get_symbol(DisplayCharset, &w);
615 char **symbol = get_symbol();
617 mouse_action.lastline_str =
618 Strnew_charp(symbol[N_GRAPH_SYMBOL + 13])->ptr;
621 if ((mf = fopen(confFile(MOUSE_FILE), "rt")) != NULL) {
622 interpret_mouse_action(mf);
625 if ((mf = fopen(rcFile(MOUSE_FILE), "rt")) != NULL) {
626 interpret_mouse_action(mf);