Mercurial > pidgin.yaz
annotate finch/libgnt/gntkeys.c @ 23218:02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Tue, 27 May 2008 03:24:19 +0000 |
parents | 44b4e8bd759b |
children | 7b7af53e136a |
rev | line source |
---|---|
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
1 /** |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
3 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
6 * source distribution. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
7 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
11 * (at your option) any later version. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
12 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
16 * GNU General Public License for more details. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
17 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
19680
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18423
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
21 */ |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18000
diff
changeset
|
22 |
15818 | 23 #include "gntkeys.h" |
24 | |
25 #include <glib.h> | |
26 #include <stdlib.h> | |
27 #include <string.h> | |
28 | |
29 char *gnt_key_cup; | |
30 char *gnt_key_cdown; | |
31 char *gnt_key_cleft; | |
32 char *gnt_key_cright; | |
33 | |
34 static const char *term; | |
35 static GHashTable *specials; | |
36 | |
23218
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
37 void gnt_keys_refine(char *text) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
38 { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
39 if (*text == 27 && *(text + 1) == '[' && |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
40 (*(text + 2) >= 'A' && *(text + 2) <= 'D')) { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
41 /* Apparently this is necessary for urxvt and screen and xterm */ |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
42 if (strcmp(term, "screen") == 0 || strcmp(term, "rxvt-unicode") == 0 || |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
43 strcmp(term, "xterm") == 0) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
44 *(text + 1) = 'O'; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
45 } else if (*(unsigned char*)text == 195) { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
46 if (*(text + 2) == 0 && strcmp(term, "xterm") == 0) { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
47 *(text) = 27; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
48 *(text + 1) -= 64; /* Say wha? */ |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
49 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
50 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
51 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
52 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
53 const char *gnt_key_translate(const char *name) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
54 { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
55 return name ? g_hash_table_lookup(specials, name) : NULL; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
56 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
57 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
58 typedef struct { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
59 const char *name; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
60 const char *key; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
61 } gntkey; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
62 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
63 static void |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
64 get_key_name(gpointer key, gpointer value, gpointer data) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
65 { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
66 gntkey *k = data; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
67 if (k->name) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
68 return; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
69 if (g_utf8_collate(value, k->key) == 0) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
70 k->name = key; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
71 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
72 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
73 const char *gnt_key_lookup(const char *key) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
74 { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
75 gntkey k = {NULL, key}; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
76 g_hash_table_foreach(specials, get_key_name, &k); |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
77 return k.name; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
78 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
79 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
80 /** |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
81 * The key-bindings will be saved in a tree. When a keystroke happens, GNT will |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
82 * find the sequence that matches a binding and return the length. |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
83 * A sequence should not be a prefix of another sequence. If it is, then only |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
84 * the shortest one will be processed. If we want to change that, we will need |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
85 * to allow getting the k-th prefix that matches the input, and pay attention |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
86 * to the return value of gnt_wm_process_input in gntmain.c. |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
87 */ |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
88 #define SIZE 256 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
89 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
90 #define IS_END 1 << 0 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
91 struct _node |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
92 { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
93 struct _node *next[SIZE]; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
94 int ref; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
95 int flags; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
96 }; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
97 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
98 struct _node root; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
99 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
100 static void add_path(struct _node *node, const char *path) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
101 { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
102 struct _node *n = NULL; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
103 if (!path || !*path) { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
104 node->flags |= IS_END; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
105 return; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
106 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
107 while (*path && node->next[(unsigned char)*path]) { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
108 node = node->next[(unsigned char)*path]; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
109 node->ref++; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
110 path++; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
111 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
112 if (!*path) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
113 return; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
114 n = g_new0(struct _node, 1); |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
115 n->ref = 1; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
116 node->next[(unsigned char)*path++] = n; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
117 add_path(n, path); |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
118 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
119 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
120 void gnt_keys_add_combination(const char *path) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
121 { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
122 add_path(&root, path); |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
123 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
124 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
125 static void del_path(struct _node *node, const char *path) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
126 { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
127 struct _node *next = NULL; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
128 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
129 if (!*path) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
130 return; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
131 next = node->next[(unsigned char)*path]; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
132 if (!next) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
133 return; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
134 del_path(next, path + 1); |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
135 next->ref--; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
136 if (next->ref == 0) { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
137 node->next[(unsigned char)*path] = NULL; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
138 g_free(next); |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
139 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
140 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
141 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
142 void gnt_keys_del_combination(const char *path) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
143 { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
144 del_path(&root, path); |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
145 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
146 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
147 int gnt_keys_find_combination(const char *path) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
148 { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
149 int depth = 0; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
150 struct _node *n = &root; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
151 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
152 root.flags &= ~IS_END; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
153 while (*path && n->next[(unsigned char)*path] && !(n->flags & IS_END)) { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
154 if (!g_ascii_isspace(*path) && |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
155 !g_ascii_iscntrl(*path) && |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
156 !g_ascii_isgraph(*path)) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
157 return 0; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
158 n = n->next[(unsigned char)*path++]; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
159 depth++; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
160 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
161 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
162 if (!(n->flags & IS_END)) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
163 depth = 0; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
164 return depth; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
165 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
166 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
167 static void |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
168 print_path(struct _node *node, int depth) |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
169 { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
170 int i; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
171 for (i = 0; i < SIZE; i++) { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
172 if (node->next[i]) { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
173 g_printerr("%*c (%d:%d)\n", depth * 4, i, node->next[i]->ref, |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
174 node->next[i]->flags); |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
175 print_path(node->next[i], depth + 1); |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
176 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
177 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
178 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
179 |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
180 /* this is purely for debugging purposes. */ |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
181 void gnt_keys_print_combinations(void); |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
182 void gnt_keys_print_combinations() |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
183 { |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
184 g_printerr("--------\n"); |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
185 print_path(&root, 1); |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
186 g_printerr("--------\n"); |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
187 } |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
188 |
15818 | 189 void gnt_init_keys() |
190 { | |
191 const char *controls[] = {"", "c-", "ctrl-", "ctr-", "ctl-", NULL}; | |
192 const char *alts[] = {"", "alt-", "a-", "m-", "meta-", NULL}; | |
193 int c, a, ch; | |
194 char key[32]; | |
195 | |
23218
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
196 memset(&root, 0, sizeof(root)); |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
197 root.ref = 1; |
02b6569d99e9
We don't need named initialiers here since we're already doing an active initilization
Gary Kramlich <grim@reaperworld.com>
parents:
19680
diff
changeset
|
198 |
15818 | 199 if (term == NULL) { |
200 term = getenv("TERM"); | |
201 if (!term) | |
202 term = ""; /* Just in case */ | |
203 } | |
204 | |
205 if (strcmp(term, "xterm") == 0 || strcmp(term, "rxvt") == 0) { | |
206 gnt_key_cup = "\033" "[1;5A"; | |
207 gnt_key_cdown = "\033" "[1;5B"; | |
208 gnt_key_cright = "\033" "[1;5C"; | |
209 gnt_key_cleft = "\033" "[1;5D"; | |
210 } else if (strcmp(term, "screen") == 0 || strcmp(term, "rxvt-unicode") == 0) { | |
211 gnt_key_cup = "\033" "Oa"; | |
212 gnt_key_cdown = "\033" "Ob"; | |
213 gnt_key_cright = "\033" "Oc"; | |
214 gnt_key_cleft = "\033" "Od"; | |
215 } | |
216 | |
217 specials = g_hash_table_new(g_str_hash, g_str_equal); | |
218 | |
219 #define INSERT_KEY(k, code) do { \ | |
220 g_hash_table_insert(specials, g_strdup(k), g_strdup(code)); \ | |
221 gnt_keys_add_combination(code); \ | |
222 } while (0) | |
223 | |
224 INSERT_KEY("home", GNT_KEY_HOME); | |
225 INSERT_KEY("end", GNT_KEY_END); | |
226 INSERT_KEY("pageup", GNT_KEY_PGUP); | |
227 INSERT_KEY("pagedown", GNT_KEY_PGDOWN); | |
228 INSERT_KEY("insert", GNT_KEY_INS); | |
229 INSERT_KEY("delete", GNT_KEY_DEL); | |
18000
05d7fe2320a9
(16:39:44) rekkanoryo: i have a feature request
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
16044
diff
changeset
|
230 INSERT_KEY("back_tab", GNT_KEY_BACK_TAB); |
15818 | 231 |
232 INSERT_KEY("left", GNT_KEY_LEFT); | |
233 INSERT_KEY("right", GNT_KEY_RIGHT); | |
234 INSERT_KEY("up", GNT_KEY_UP); | |
235 INSERT_KEY("down", GNT_KEY_DOWN); | |
236 | |
237 INSERT_KEY("tab", "\t"); | |
238 INSERT_KEY("menu", GNT_KEY_POPUP); | |
239 | |
240 INSERT_KEY("f1", GNT_KEY_F1); | |
241 INSERT_KEY("f2", GNT_KEY_F2); | |
242 INSERT_KEY("f3", GNT_KEY_F3); | |
243 INSERT_KEY("f4", GNT_KEY_F4); | |
244 INSERT_KEY("f5", GNT_KEY_F5); | |
245 INSERT_KEY("f6", GNT_KEY_F6); | |
246 INSERT_KEY("f7", GNT_KEY_F7); | |
247 INSERT_KEY("f8", GNT_KEY_F8); | |
248 INSERT_KEY("f9", GNT_KEY_F9); | |
249 INSERT_KEY("f10", GNT_KEY_F10); | |
250 INSERT_KEY("f11", GNT_KEY_F11); | |
251 INSERT_KEY("f12", GNT_KEY_F12); | |
252 | |
253 #define REM_LENGTH (sizeof(key) - (cur - key)) | |
254 #define INSERT_COMB(k, code) do { \ | |
255 snprintf(key, sizeof(key), "%s%s%s", controls[c], alts[a], k); \ | |
256 INSERT_KEY(key, code); \ | |
257 } while (0); | |
258 | |
259 /* Lower-case alphabets */ | |
260 for (a = 0, c = 0; controls[c]; c++, a = 0) { | |
261 if (c) { | |
262 INSERT_COMB("up", gnt_key_cup); | |
263 INSERT_COMB("down", gnt_key_cdown); | |
264 INSERT_COMB("left", gnt_key_cleft); | |
265 INSERT_COMB("right", gnt_key_cright); | |
266 } | |
267 | |
268 for (a = 0; alts[a]; a++) { | |
269 for (ch = 0; ch < 26; ch++) { | |
270 char str[2] = {'a' + ch, 0}, code[4] = "\0\0\0\0"; | |
271 int ind = 0; | |
272 if (a) | |
273 code[ind++] = '\033'; | |
274 code[ind] = (c ? 1 : 'a') + ch; | |
275 INSERT_COMB(str, code); | |
276 } | |
277 } | |
278 } | |
279 c = 0; | |
280 for (a = 0; alts[a]; a++) { | |
281 /* Upper-case alphabets */ | |
282 for (ch = 0; ch < 26; ch++) { | |
283 char str[2] = {'A' + ch, 0}, code[] = {'\033', 'A' + ch, 0}; | |
284 INSERT_COMB(str, code); | |
285 } | |
286 /* Digits */ | |
287 for (ch = 0; ch < 10; ch++) { | |
288 char str[2] = {'0' + ch, 0}, code[] = {'\033', '0' + ch, 0}; | |
289 INSERT_COMB(str, code); | |
290 } | |
291 } | |
292 } | |
293 |