Mercurial > ~mikael > mcabber > hg
annotate mcabber/mcabber/compl.c @ 2074:e04b6dfbb054
Some whitespace cleanup
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 29 Sep 2013 11:07:06 +0200 |
parents | 0cb8ea02e472 |
children | 1bd9978ed5d0 |
rev | line source |
---|---|
94 | 1 /* |
2 * compl.c -- Completion system | |
393 | 3 * |
1729
e6e89b1d7831
Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents:
1685
diff
changeset
|
4 * Copyright (C) 2005-2010 Mikael Berthe <mikael@lilotux.net> |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
5 * Copyright (C) 2009-2012 Myhailo Danylenko <isbear@ukrpost.net> |
94 | 6 * |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or (at | |
10 * your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
20 * USA | |
21 */ | |
22 | |
23 /* Usage, basically: | |
24 * - new_completion(); // 1. Initialization | |
25 * - complete(); // 2. 1st completion | |
26 * - cancel_completion(); // 3a. 2nd completion / cancel previous | |
27 * - complete(); // 3b. 2nd completion / complete | |
28 * ... | |
29 * - done_completion(); // n. finished -- free allocated areas | |
30 * | |
31 */ | |
32 | |
33 #include <string.h> | |
34 | |
35 #include "compl.h" | |
1240
a54645448e00
Fix completion of strings with multibyte chars
Mikael Berthe <mikael@lilotux.net>
parents:
1228
diff
changeset
|
36 #include "utf8.h" |
225 | 37 #include "roster.h" |
757
ae23c8826efb
Improve completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
38 #include "events.h" |
1926
c1f9a4d47e05
Add option 'completion_ignore_case'
Mikael Berthe <mikael@lilotux.net>
parents:
1923
diff
changeset
|
39 #include "settings.h" |
1922
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
40 #include "logprint.h" |
94 | 41 |
42 // Completion structure | |
43 typedef struct { | |
44 GSList *list; // list of matches | |
45 guint len_prefix; // length of text already typed by the user | |
46 guint len_compl; // length of the last completion | |
47 GSList *next; // pointer to next completion to try | |
48 } compl; | |
49 | |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
50 typedef GSList *(*compl_handler_t) (void); // XXX userdata? *dynlist? |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
51 |
94 | 52 // Category structure |
53 typedef struct { | |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
54 guint flags; |
94 | 55 GSList *words; |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
56 compl_handler_t dynamic; |
94 | 57 } category; |
58 | |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
59 #define COMPL_CAT_BUILTIN 0x01 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
60 #define COMPL_CAT_ACTIVE 0x02 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
61 #define COMPL_CAT_DYNAMIC 0x04 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
62 #define COMPL_CAT_REVERSE 0x10 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
63 #define COMPL_CAT_NOSORT 0x20 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
64 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
65 #define COMPL_CAT_USERFLAGS 0x30 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
66 |
94 | 67 static compl *InputCompl; |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
68 static category *Categories; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
69 static guint num_categories; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
70 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
71 // Dynamic completions callbacks |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
72 static GSList *compl_dyn_group (void) |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
73 { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
74 return compl_list(ROSTER_TYPE_GROUP); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
75 } |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
76 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
77 static GSList *compl_dyn_user (void) |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
78 { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
79 return compl_list(ROSTER_TYPE_USER); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
80 } |
94 | 81 |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
82 static GSList *compl_dyn_resource (void) |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
83 { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
84 return buddy_getresources_locale(NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
85 } |
1922
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
86 |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
87 static GSList *compl_dyn_events (void) |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
88 { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
89 GSList *compl = evs_geteventslist(); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
90 GSList *cel; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
91 for (cel = compl; cel; cel = cel->next) |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
92 cel->data = g_strdup(cel->data); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
93 compl = g_slist_append(compl, g_strdup("list")); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
94 return compl; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
95 } |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
96 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
97 static inline void register_builtin_cat(guint c, compl_handler_t dynamic) { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
98 Categories[c-1].flags = COMPL_CAT_BUILTIN | COMPL_CAT_ACTIVE; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
99 Categories[c-1].words = NULL; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
100 Categories[c-1].dynamic = dynamic; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
101 if (dynamic != NULL) { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
102 Categories[c-1].flags |= COMPL_CAT_DYNAMIC; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
103 } |
1922
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
104 } |
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
105 |
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
106 void compl_init_system(void) |
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
107 { |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
108 num_categories = COMPL_MAX_ID; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
109 #ifdef MODULES_ENABLE |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
110 num_categories = ((num_categories / 16) + 1) * 16; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
111 #endif |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
112 Categories = g_new0(category, num_categories); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
113 |
1922
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
114 // Builtin completion categories: |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
115 register_builtin_cat(COMPL_CMD, NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
116 register_builtin_cat(COMPL_JID, compl_dyn_user); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
117 register_builtin_cat(COMPL_URLJID, NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
118 register_builtin_cat(COMPL_NAME, NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
119 register_builtin_cat(COMPL_STATUS, NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
120 register_builtin_cat(COMPL_FILENAME, NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
121 register_builtin_cat(COMPL_ROSTER, NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
122 register_builtin_cat(COMPL_BUFFER, NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
123 register_builtin_cat(COMPL_GROUP, NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
124 register_builtin_cat(COMPL_GROUPNAME, compl_dyn_group); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
125 register_builtin_cat(COMPL_MULTILINE, NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
126 register_builtin_cat(COMPL_ROOM, NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
127 register_builtin_cat(COMPL_RESOURCE, compl_dyn_resource); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
128 register_builtin_cat(COMPL_AUTH, NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
129 register_builtin_cat(COMPL_REQUEST, NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
130 register_builtin_cat(COMPL_EVENTS, NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
131 register_builtin_cat(COMPL_EVENTSID, compl_dyn_events); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
132 register_builtin_cat(COMPL_PGP, NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
133 register_builtin_cat(COMPL_COLOR, NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
134 register_builtin_cat(COMPL_OTR, NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
135 register_builtin_cat(COMPL_OTRPOLICY, NULL); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
136 register_builtin_cat(COMPL_MODULE, NULL); |
1922
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
137 } |
1607 | 138 |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
139 #ifdef MODULES_ENABLE |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
140 // compl_new_category(flags) |
1607 | 141 // Reserves id for new completion category. |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
142 // Flags determine word sorting order. |
1607 | 143 // Returns 0, if no more categories can be allocated. |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
144 guint compl_new_category(guint flags) |
1607 | 145 { |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
146 guint i; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
147 for (i = 0; i < num_categories; i++) |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
148 if (!(Categories[i].flags & COMPL_CAT_ACTIVE)) |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
149 break; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
150 if (i >= num_categories ) { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
151 guint j; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
152 if (num_categories > G_MAXUINT - 16) { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
153 scr_log_print(LPRINT_LOGNORM, "Warning: Too many " |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
154 "completion categories!"); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
155 return 0; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
156 } |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
157 num_categories += 16; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
158 Categories = g_renew(category, Categories, num_categories); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
159 for (j = i+1; j < num_categories; j++) |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
160 Categories[j].flags = 0; |
1607 | 161 } |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
162 Categories[i].flags = COMPL_CAT_ACTIVE | (flags & COMPL_CAT_USERFLAGS); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
163 Categories[i].words = NULL; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
164 return i+1; |
1607 | 165 } |
166 | |
1828
8f7d7c05f275
Small coding style update
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
167 // compl_del_category(id) |
1607 | 168 // Frees reserved id for category. |
169 // Note, that for now it not validates its input, so, be careful | |
170 // and specify exactly what you get from compl_new_category. | |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
171 void compl_del_category(guint compl) |
1607 | 172 { |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
173 GSList *wel; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
174 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
175 if (!compl) { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
176 scr_log_print(LPRINT_DEBUG, "Error: compl_del_category() - " |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
177 "Invalid category (0)."); |
1922
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
178 return; |
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
179 } |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
180 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
181 compl--; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
182 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
183 if ((compl >= num_categories) || |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
184 (Categories[compl].flags & COMPL_CAT_BUILTIN)) { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
185 scr_log_print(LPRINT_DEBUG, "Error: compl_del_category() " |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
186 "Invalid category."); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
187 return; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
188 } |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
189 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
190 Categories[compl].flags = 0; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
191 for (wel = Categories[compl].words; wel; wel = g_slist_next (wel)) |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
192 g_free (wel -> data); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
193 g_slist_free (Categories[compl].words); |
1607 | 194 } |
195 #endif | |
196 | |
1756
e2c084204583
Add (optional) suffix after nick completion in Multi-User Chats
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
197 // new_completion(prefix, compl_cat, suffix) |
94 | 198 // . prefix = beginning of the word, typed by the user |
199 // . compl_cat = pointer to a completion category list (list of *char) | |
1756
e2c084204583
Add (optional) suffix after nick completion in Multi-User Chats
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
200 // . suffix = string to append to all completion possibilities (i.e. ":") |
894
f76b32ff2f14
done_completion(): free all allocated memory
Mikael Berthe <mikael@lilotux.net>
parents:
820
diff
changeset
|
201 // Set the InputCompl pointer to an allocated compl structure. |
f76b32ff2f14
done_completion(): free all allocated memory
Mikael Berthe <mikael@lilotux.net>
parents:
820
diff
changeset
|
202 // done_completion() must be called when finished. |
1228
9a68fe4515dc
Improve MUC nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
203 // Returns the number of possible completions. |
1756
e2c084204583
Add (optional) suffix after nick completion in Multi-User Chats
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
204 guint new_completion(const char *prefix, GSList *compl_cat, const gchar *suffix) |
94 | 205 { |
206 compl *c; | |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
207 guint ret_len = 0; |
94 | 208 GSList *sl_cat; |
1926
c1f9a4d47e05
Add option 'completion_ignore_case'
Mikael Berthe <mikael@lilotux.net>
parents:
1923
diff
changeset
|
209 gint (*cmp)(const char *s1, const char *s2, size_t n); |
735 | 210 size_t len = strlen(prefix); |
94 | 211 |
212 if (InputCompl) { // This should not happen, but hey... | |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
213 scr_log_print(LPRINT_DEBUG, "Warning: new_completion() - " |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
214 "Previous completion exists!"); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
215 done_completion(); |
94 | 216 } |
217 | |
1926
c1f9a4d47e05
Add option 'completion_ignore_case'
Mikael Berthe <mikael@lilotux.net>
parents:
1923
diff
changeset
|
218 if (settings_opt_get_int("completion_ignore_case")) |
c1f9a4d47e05
Add option 'completion_ignore_case'
Mikael Berthe <mikael@lilotux.net>
parents:
1923
diff
changeset
|
219 cmp = &strncasecmp; |
c1f9a4d47e05
Add option 'completion_ignore_case'
Mikael Berthe <mikael@lilotux.net>
parents:
1923
diff
changeset
|
220 else |
c1f9a4d47e05
Add option 'completion_ignore_case'
Mikael Berthe <mikael@lilotux.net>
parents:
1923
diff
changeset
|
221 cmp = &strncmp; |
c1f9a4d47e05
Add option 'completion_ignore_case'
Mikael Berthe <mikael@lilotux.net>
parents:
1923
diff
changeset
|
222 |
94 | 223 c = g_new0(compl, 1); |
224 // Build the list of matches | |
1228
9a68fe4515dc
Improve MUC nickname completion
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
225 for (sl_cat = compl_cat; sl_cat; sl_cat = g_slist_next(sl_cat)) { |
94 | 226 char *word = sl_cat->data; |
1926
c1f9a4d47e05
Add option 'completion_ignore_case'
Mikael Berthe <mikael@lilotux.net>
parents:
1923
diff
changeset
|
227 if (!cmp(prefix, word, len)) { |
1756
e2c084204583
Add (optional) suffix after nick completion in Multi-User Chats
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
228 if (strlen(word) != len) { |
e2c084204583
Add (optional) suffix after nick completion in Multi-User Chats
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
229 gchar *compval; |
e2c084204583
Add (optional) suffix after nick completion in Multi-User Chats
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
230 if (suffix) |
e2c084204583
Add (optional) suffix after nick completion in Multi-User Chats
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
231 compval = g_strdup_printf("%s%s", word+len, suffix); |
e2c084204583
Add (optional) suffix after nick completion in Multi-User Chats
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
232 else |
e2c084204583
Add (optional) suffix after nick completion in Multi-User Chats
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
233 compval = g_strdup(word+len); |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
234 // for a bit of efficiency, will reverse order afterwards |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
235 c->list = g_slist_prepend(c->list, compval); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
236 ret_len ++; |
1756
e2c084204583
Add (optional) suffix after nick completion in Multi-User Chats
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
237 } |
94 | 238 } |
239 } | |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
240 c->next = c->list = g_slist_reverse (c->list); |
94 | 241 InputCompl = c; |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
242 return ret_len; |
94 | 243 } |
244 | |
245 // done_completion(); | |
246 void done_completion(void) | |
247 { | |
894
f76b32ff2f14
done_completion(): free all allocated memory
Mikael Berthe <mikael@lilotux.net>
parents:
820
diff
changeset
|
248 GSList *clp; |
f76b32ff2f14
done_completion(): free all allocated memory
Mikael Berthe <mikael@lilotux.net>
parents:
820
diff
changeset
|
249 |
98 | 250 if (!InputCompl) return; |
251 | |
894
f76b32ff2f14
done_completion(): free all allocated memory
Mikael Berthe <mikael@lilotux.net>
parents:
820
diff
changeset
|
252 // Free the current completion list |
f76b32ff2f14
done_completion(): free all allocated memory
Mikael Berthe <mikael@lilotux.net>
parents:
820
diff
changeset
|
253 for (clp = InputCompl->list; clp; clp = g_slist_next(clp)) |
f76b32ff2f14
done_completion(): free all allocated memory
Mikael Berthe <mikael@lilotux.net>
parents:
820
diff
changeset
|
254 g_free(clp->data); |
94 | 255 g_slist_free(InputCompl->list); |
256 g_free(InputCompl); | |
257 InputCompl = NULL; | |
258 } | |
259 | |
260 // cancel_completion() | |
261 // Returns the number of chars to delete to cancel the completion | |
262 guint cancel_completion(void) | |
263 { | |
98 | 264 if (!InputCompl) return 0; |
94 | 265 return InputCompl->len_compl; |
266 } | |
267 | |
268 // Returns pointer to text to insert, NULL if no completion. | |
269 const char *complete() | |
270 { | |
271 compl* c = InputCompl; | |
272 char *r; | |
98 | 273 |
274 if (!InputCompl) return NULL; | |
275 | |
94 | 276 if (!c->next) { |
277 c->next = c->list; // back to the beginning | |
278 c->len_compl = 0; | |
279 return NULL; | |
280 } | |
281 r = (char*)c->next->data; | |
282 c->next = g_slist_next(c->next); | |
1240
a54645448e00
Fix completion of strings with multibyte chars
Mikael Berthe <mikael@lilotux.net>
parents:
1228
diff
changeset
|
283 if (!utf8_mode) { |
a54645448e00
Fix completion of strings with multibyte chars
Mikael Berthe <mikael@lilotux.net>
parents:
1228
diff
changeset
|
284 c->len_compl = strlen(r); |
a54645448e00
Fix completion of strings with multibyte chars
Mikael Berthe <mikael@lilotux.net>
parents:
1228
diff
changeset
|
285 } else { |
a54645448e00
Fix completion of strings with multibyte chars
Mikael Berthe <mikael@lilotux.net>
parents:
1228
diff
changeset
|
286 char *wc; |
a54645448e00
Fix completion of strings with multibyte chars
Mikael Berthe <mikael@lilotux.net>
parents:
1228
diff
changeset
|
287 c->len_compl = 0; |
a54645448e00
Fix completion of strings with multibyte chars
Mikael Berthe <mikael@lilotux.net>
parents:
1228
diff
changeset
|
288 for (wc = r; *wc; wc = next_char(wc)) |
1569
21c553e4bfb9
Fix completion with wide characters (e.g. Japanese characters)
Myhailo Danylenko <isbear@ukrpost.net>
parents:
1414
diff
changeset
|
289 c->len_compl++; |
1240
a54645448e00
Fix completion of strings with multibyte chars
Mikael Berthe <mikael@lilotux.net>
parents:
1228
diff
changeset
|
290 } |
94 | 291 return r; |
292 } | |
293 | |
294 | |
295 /* Categories functions */ | |
296 | |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
297 static gint compl_sort_forward(gconstpointer a, gconstpointer b) |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
298 { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
299 return g_ascii_strcasecmp((const gchar *)a, (const gchar *)b); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
300 } |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
301 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
302 static gint compl_sort_reverse(gconstpointer a, gconstpointer b) |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
303 { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
304 return -g_ascii_strcasecmp((const gchar *)a, (const gchar *)b); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
305 } |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
306 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
307 static gint compl_sort_append(gconstpointer a, gconstpointer b) |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
308 { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
309 return 1; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
310 } |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
311 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
312 static gint compl_sort_prepend(gconstpointer a, gconstpointer b) |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
313 { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
314 return -1; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
315 } |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
316 |
95 | 317 // compl_add_category_word(categ, command) |
318 // Adds a keyword as a possible completion in category categ. | |
1756
e2c084204583
Add (optional) suffix after nick completion in Multi-User Chats
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
319 void compl_add_category_word(guint categ, const gchar *word) |
94 | 320 { |
121 | 321 char *nword; |
1922
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
322 |
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
323 if (!categ) { |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
324 scr_log_print(LPRINT_DEBUG, "Error: compl_add_category_word() - " |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
325 "Invalid category (0)."); |
1922
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
326 return; |
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
327 } |
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
328 |
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
329 categ--; |
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
330 |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
331 if ((categ >= num_categories) || |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
332 !(Categories[categ].flags & COMPL_CAT_ACTIVE)) { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
333 scr_log_print(LPRINT_DEBUG, "Error: compl_add_category_word() - " |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
334 "Category does not exist."); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
335 return; |
94 | 336 } |
337 | |
121 | 338 // If word is not space-terminated, we add one trailing space |
339 for (nword = (char*)word; *nword; nword++) | |
340 ; | |
341 if (nword > word) nword--; | |
342 if (*nword != ' ') { // Add a space | |
1240
a54645448e00
Fix completion of strings with multibyte chars
Mikael Berthe <mikael@lilotux.net>
parents:
1228
diff
changeset
|
343 nword = g_strdup_printf("%s ", word); |
121 | 344 } else { // word is fine |
345 nword = g_strdup(word); | |
346 } | |
347 | |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
348 if (g_slist_find_custom(Categories[categ].words, nword, |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
349 (GCompareFunc)g_strcmp0) == NULL) { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
350 guint flags = Categories[categ].flags; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
351 GCompareFunc comparator = compl_sort_forward; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
352 if (flags & COMPL_CAT_NOSORT) { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
353 if (flags & COMPL_CAT_REVERSE) |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
354 comparator = compl_sort_prepend; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
355 else |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
356 comparator = compl_sort_append; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
357 } else if (flags & COMPL_CAT_REVERSE) |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
358 comparator = compl_sort_reverse; |
1850
8d7810f529db
Sort items in completion lists
alkino <nicolas.cornu@ensi-bourges.fr>
parents:
1828
diff
changeset
|
359 |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
360 Categories[categ].words = g_slist_insert_sorted |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
361 (Categories[categ].words, nword, comparator); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
362 } |
94 | 363 } |
364 | |
284
f879b17ecb8e
Add compl_del_category_word()
Mikael Berthe <mikael@lilotux.net>
parents:
225
diff
changeset
|
365 // compl_del_category_word(categ, command) |
f879b17ecb8e
Add compl_del_category_word()
Mikael Berthe <mikael@lilotux.net>
parents:
225
diff
changeset
|
366 // Removes a keyword from category categ in completion list. |
1756
e2c084204583
Add (optional) suffix after nick completion in Multi-User Chats
Mikael Berthe <mikael@lilotux.net>
parents:
1729
diff
changeset
|
367 void compl_del_category_word(guint categ, const gchar *word) |
284
f879b17ecb8e
Add compl_del_category_word()
Mikael Berthe <mikael@lilotux.net>
parents:
225
diff
changeset
|
368 { |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
369 GSList *wel; |
284
f879b17ecb8e
Add compl_del_category_word()
Mikael Berthe <mikael@lilotux.net>
parents:
225
diff
changeset
|
370 char *nword; |
1922
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
371 |
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
372 if (!categ) { |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
373 scr_log_print(LPRINT_DEBUG, "Error: compl_del_category_word() - " |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
374 "Invalid category (0)."); |
1922
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
375 return; |
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
376 } |
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
377 |
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
378 categ--; |
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
379 |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
380 if ((categ >= num_categories) || |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
381 !(Categories[categ].flags & COMPL_CAT_ACTIVE)) { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
382 scr_log_print(LPRINT_DEBUG, "Error: compl_del_category_word() - " |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
383 "Category does not exist."); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
384 return; |
284
f879b17ecb8e
Add compl_del_category_word()
Mikael Berthe <mikael@lilotux.net>
parents:
225
diff
changeset
|
385 } |
f879b17ecb8e
Add compl_del_category_word()
Mikael Berthe <mikael@lilotux.net>
parents:
225
diff
changeset
|
386 |
f879b17ecb8e
Add compl_del_category_word()
Mikael Berthe <mikael@lilotux.net>
parents:
225
diff
changeset
|
387 // If word is not space-terminated, we add one trailing space |
f879b17ecb8e
Add compl_del_category_word()
Mikael Berthe <mikael@lilotux.net>
parents:
225
diff
changeset
|
388 for (nword = (char*)word; *nword; nword++) |
f879b17ecb8e
Add compl_del_category_word()
Mikael Berthe <mikael@lilotux.net>
parents:
225
diff
changeset
|
389 ; |
f879b17ecb8e
Add compl_del_category_word()
Mikael Berthe <mikael@lilotux.net>
parents:
225
diff
changeset
|
390 if (nword > word) nword--; |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
391 if (*nword != ' ') // Add a space |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
392 word = nword = g_strdup_printf("%s ", word); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
393 else |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
394 nword = NULL; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
395 |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
396 for (wel = Categories[categ].words; wel; wel = g_slist_next (wel)) { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
397 if (!strcasecmp((char*)wel->data, word)) { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
398 g_free(wel->data); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
399 Categories[categ].words = g_slist_delete_link |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
400 (Categories[categ].words, wel); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
401 break; // Only remove first occurence |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
402 } |
284
f879b17ecb8e
Add compl_del_category_word()
Mikael Berthe <mikael@lilotux.net>
parents:
225
diff
changeset
|
403 } |
f879b17ecb8e
Add compl_del_category_word()
Mikael Berthe <mikael@lilotux.net>
parents:
225
diff
changeset
|
404 |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
405 g_free (nword); |
284
f879b17ecb8e
Add compl_del_category_word()
Mikael Berthe <mikael@lilotux.net>
parents:
225
diff
changeset
|
406 } |
f879b17ecb8e
Add compl_del_category_word()
Mikael Berthe <mikael@lilotux.net>
parents:
225
diff
changeset
|
407 |
95 | 408 // compl_get_category_list() |
1922
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
409 // Returns a slist of all words in the specified categorie. |
1076
b9698c89f46d
Fix memory leak in scr_handle_tab()
Mikael Berthe <mikael@lilotux.net>
parents:
894
diff
changeset
|
410 // Iff this function sets *dynlist to TRUE, then the caller must free the |
b9698c89f46d
Fix memory leak in scr_handle_tab()
Mikael Berthe <mikael@lilotux.net>
parents:
894
diff
changeset
|
411 // whole list after use. |
1922
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
412 GSList *compl_get_category_list(guint categ, guint *dynlist) |
94 | 413 { |
1922
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
414 if (!categ) { |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
415 scr_log_print(LPRINT_DEBUG, "Error: compl_get_category_list() - " |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
416 "Invalid category (0)."); |
1922
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
417 return NULL; |
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
418 } |
4ba68ad737bc
Increase the number of available categories for completions
Mikael Berthe <mikael@lilotux.net>
parents:
1852
diff
changeset
|
419 |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
420 categ --; |
94 | 421 |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
422 if ((categ > num_categories) || |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
423 !(Categories[categ].flags & COMPL_CAT_ACTIVE)) { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
424 scr_log_print(LPRINT_DEBUG, "Error: compl_get_category_list() - " |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
425 "Category does not exist."); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
426 return NULL; |
757
ae23c8826efb
Improve completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
427 } |
225 | 428 |
2042
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
429 if (Categories[categ].flags & COMPL_CAT_DYNAMIC) { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
430 *dynlist = TRUE; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
431 return (*Categories[categ].dynamic) (); |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
432 } else { |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
433 *dynlist = FALSE; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
434 return Categories[categ].words; |
0cb8ea02e472
Make completion sorting order configurable
Myhailo Danylenko <isbear@ukrpost.net>
parents:
2035
diff
changeset
|
435 } |
94 | 436 } |
437 | |
1811 | 438 /* vim: set expandtab cindent cinoptions=>2\:2(0 sw=2 ts=2: For Vim users... */ |