about summary refs log tree commit diff stats
path: root/src/tools
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2023-01-19 11:05:42 +0100
committerGitHub <noreply@github.com>2023-01-19 11:05:42 +0100
commit494512c25cabc2271b4132f19ad38fb8edee1afa (patch)
treee7131bb283b4731cbe0e1c595bfd7b3faa349c77 /src/tools
parent78496d6226cb6f00ba3b14db479497ab3cfc8160 (diff)
parent99ffaf0a008cabbc0855b0d3b818ce9a2ad6bd62 (diff)
downloadprofani-tty-494512c25cabc2271b4132f19ad38fb8edee1afa.tar.gz
Merge pull request #1780 from profanity-im/minor-improvements
Minor improvements
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/autocomplete.c49
-rw-r--r--src/tools/editor.c2
2 files changed, 10 insertions, 41 deletions
diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c
index 9450b98f..2f1acc1f 100644
--- a/src/tools/autocomplete.c
+++ b/src/tools/autocomplete.c
@@ -367,34 +367,20 @@ char*
 autocomplete_param_no_with_func(const char* const input, char* command, int arg_number, autocomplete_func func, gboolean previous, void* context)
 {
     if (strncmp(input, command, strlen(command)) == 0) {
-        GString* result_str = NULL;
-
         // count tokens properly
         int num_tokens = count_tokens(input);
 
         // if correct number of tokens, then candidate for autocompletion of last param
         if (num_tokens == arg_number) {
-            gchar* start_str = get_start(input, arg_number);
-            gchar* comp_str = g_strdup(&input[strlen(start_str)]);
+            auto_gchar gchar* start_str = get_start(input, arg_number);
+            auto_gchar gchar* comp_str = g_strdup(&input[strlen(start_str)]);
 
             // autocomplete param
             if (comp_str) {
-                char* found = func(comp_str, previous, context);
+                auto_gchar gchar* found = func(comp_str, previous, context);
                 if (found) {
-                    result_str = g_string_new("");
-                    g_string_append(result_str, start_str);
-                    g_string_append(result_str, found);
-
-                    free(start_str);
-                    free(comp_str);
-
-                    char* result = result_str->str;
-                    g_string_free(result_str, FALSE);
-
-                    return result;
+                    return g_strdup_printf("%s%s", start_str, found);
                 }
-            } else {
-                free(start_str);
             }
         }
     }
@@ -418,14 +404,12 @@ autocomplete_remove_older_than_max_reverse(Autocomplete ac, int maxsize)
 static gchar*
 _search(Autocomplete ac, GList* curr, gboolean quote, search_direction direction)
 {
-    gchar* search_str_ascii = g_str_to_ascii(ac->search_str, NULL);
-    gchar* search_str_lower = g_ascii_strdown(search_str_ascii, -1);
-    g_free(search_str_ascii);
+    auto_gchar gchar* search_str_ascii = g_str_to_ascii(ac->search_str, NULL);
+    auto_gchar gchar* search_str_lower = g_ascii_strdown(search_str_ascii, -1);
 
     while (curr) {
-        gchar* curr_ascii = g_str_to_ascii(curr->data, NULL);
-        gchar* curr_lower = g_ascii_strdown(curr_ascii, -1);
-        g_free(curr_ascii);
+        auto_gchar gchar* curr_ascii = g_str_to_ascii(curr->data, NULL);
+        auto_gchar gchar* curr_lower = g_ascii_strdown(curr_ascii, -1);
 
         // match found
         if (strncmp(curr_lower, search_str_lower, strlen(search_str_lower)) == 0) {
@@ -435,27 +419,13 @@ _search(Autocomplete ac, GList* curr, gboolean quote, search_direction direction
 
             // if contains space, quote before returning
             if (quote && g_strrstr(curr->data, " ")) {
-                GString* quoted = g_string_new("\"");
-                g_string_append(quoted, curr->data);
-                g_string_append(quoted, "\"");
-
-                gchar* result = quoted->str;
-                g_string_free(quoted, FALSE);
-
-                g_free(search_str_lower);
-                g_free(curr_lower);
-                return result;
-
+                return g_strdup_printf("\"%s\"", (gchar*)curr->data);
                 // otherwise just return the string
             } else {
-                g_free(search_str_lower);
-                g_free(curr_lower);
                 return strdup(curr->data);
             }
         }
 
-        g_free(curr_lower);
-
         if (direction == PREVIOUS) {
             curr = g_list_previous(curr);
         } else {
@@ -463,6 +433,5 @@ _search(Autocomplete ac, GList* curr, gboolean quote, search_direction direction
         }
     }
 
-    g_free(search_str_lower);
     return NULL;
 }
diff --git a/src/tools/editor.c b/src/tools/editor.c
index 4ac88a95..350fb5b1 100644
--- a/src/tools/editor.c
+++ b/src/tools/editor.c
@@ -56,7 +56,7 @@ get_message_from_editor(gchar* message, gchar** returned_message)
 
     gchar* filename = NULL;
     GError* glib_error = NULL;
-    char* jid = connection_get_barejid();
+    auto_char char* jid = connection_get_barejid();
     if (jid) {
         filename = files_file_in_account_data_path(DIR_EDITOR, jid, "compose.md");
     } else {
nincsnevem662@gmail.com> 2022-12-11 16:09:36 +0100 committer bptato <nincsnevem662@gmail.com> 2022-12-11 16:09:36 +0100 Add caption-side' href='/ahoang/chawan/commit/res/ua.css?id=7dae490a675df89031a56950f7b496c112a156c9'>7dae490a ^
8a1611e1 ^
bc1aceb8 ^
fb017f27 ^

bc1aceb8 ^

fb017f27 ^

8a1611e1 ^


bc1aceb8 ^
fb017f27 ^
152f8908 ^
bc1aceb8 ^

8a1611e1 ^
bc1aceb8 ^
fb017f27 ^
152f8908 ^
fb017f27 ^




152f8908 ^
fb017f27 ^




152f8908 ^
fb017f27 ^

c065b4c3 ^
fb017f27 ^


c065b4c3 ^
fb017f27 ^


c065b4c3 ^
fb017f27 ^
bf3b8804 ^

8af10b8b ^



eb2e57c9 ^




94a10242 ^
34b02351 ^
94a10242 ^
5ed6ccd8 ^
f4805eb8 ^











9b95435a ^
148d6ce5 ^

9b95435a ^


5ed6ccd8 ^
148d6ce5 ^

5ed6ccd8 ^


a413a311 ^
148d6ce5 ^

a413a311 ^

1a9acf70 ^
8bbff1f7 ^
5ed6ccd8 ^
60b58351 ^
1a9acf70 ^
60b58351 ^

e1194507 ^







72e171f6 ^


47b0c8df ^
72e171f6 ^



69f184a1 ^
72e171f6 ^








7707d87c ^





6a5cc238 ^
7707d87c ^












5c19adf2 ^
24fc8e94 ^



4511c956 ^



24fc8e94 ^

152f8908 ^
8bc1392c ^
24fc8e94 ^



152f8908 ^
8bc1392c ^
24fc8e94 ^

8bc1392c ^
24fc8e94 ^


8bc1392c ^


24fc8e94 ^

4511c956 ^

24fc8e94 ^

4511c956 ^

8bc1392c ^

4511c956 ^

24fc8e94 ^

5c19adf2 ^
d4e20ebe ^
5c19adf2 ^
051d22b1 ^



f92e3023 ^







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307