| 1 | Source: https://github.com/DE-IBH/apt-dater/pull/181.patch
|
| 2 | --
|
| 3 | From 4e820e5f885d6102a740553679ae188b3f5902bf Mon Sep 17 00:00:00 2001
|
| 4 | From: =?UTF-8?q?Stefan=20B=C3=BChler?= <[email protected]>
|
| 5 | Date: Sat, 30 Sep 2023 14:28:26 +0200
|
| 6 | Subject: [PATCH 1/5] fix _GNU_SOURCE redefinition warning
|
| 7 |
|
| 8 | ---
|
| 9 | src/apt-dater.h | 4 +++-
|
| 10 | 1 file changed, 3 insertions(+), 1 deletion(-)
|
| 11 |
|
| 12 | diff --git a/src/apt-dater.h b/src/apt-dater.h
|
| 13 | index 7eda355..447c29d 100644
|
| 14 | |
| 15 | |
| 16 | @@ -25,7 +25,9 @@
|
| 17 | #ifndef _APT_DATER_H
|
| 18 | #define _APT_DATER_H
|
| 19 |
|
| 20 | -#define _GNU_SOURCE
|
| 21 | +#ifndef _GNU_SOURCE
|
| 22 | +# define _GNU_SOURCE
|
| 23 | +#endif
|
| 24 |
|
| 25 | #include <assert.h>
|
| 26 | #include <stdio.h>
|
| 27 |
|
| 28 | From 1f65f0267bb3319e9513298409352cb9aef78819 Mon Sep 17 00:00:00 2001
|
| 29 | From: =?UTF-8?q?Stefan=20B=C3=BChler?= <[email protected]>
|
| 30 | Date: Mon, 2 Oct 2023 13:39:36 +0200
|
| 31 | Subject: [PATCH 2/5] consistent include of config.h
|
| 32 |
|
| 33 | ---
|
| 34 | src/apt-dater.h | 9 ++++-----
|
| 35 | src/runcust.c | 8 ++++----
|
| 36 | src/screen.h | 4 +++-
|
| 37 | 3 files changed, 11 insertions(+), 10 deletions(-)
|
| 38 |
|
| 39 | diff --git a/src/apt-dater.h b/src/apt-dater.h
|
| 40 | index 447c29d..7de9d28 100644
|
| 41 | |
| 42 | |
| 43 | @@ -42,7 +42,10 @@
|
| 44 | #include <glib/gstdio.h>
|
| 45 | #include <gio/gio.h>
|
| 46 |
|
| 47 | -#include "../config.h"
|
| 48 | +#ifdef HAVE_CONFIG_H
|
| 49 | +# include "config.h"
|
| 50 | +#endif
|
| 51 | +
|
| 52 | #include "../include/adproto.h"
|
| 53 |
|
| 54 | #ifdef HAVE_GETTEXT
|
| 55 | @@ -60,10 +63,6 @@
|
| 56 | #define BUF_MAX_LEN 256
|
| 57 | #define PROG_NAME PACKAGE
|
| 58 |
|
| 59 | -#ifdef HAVE_CONFIG_H
|
| 60 | -# include "config.h"
|
| 61 | -#endif
|
| 62 | -
|
| 63 | #ifndef NDEBUG
|
| 64 | typedef enum {
|
| 65 | T_CFGFILE=1,
|
| 66 | diff --git a/src/runcust.c b/src/runcust.c
|
| 67 | index bc41e5f..70ecd6e 100644
|
| 68 | |
| 69 | |
| 70 | @@ -25,16 +25,16 @@
|
| 71 |
|
| 72 | #include <glib.h>
|
| 73 |
|
| 74 | +#ifdef HAVE_CONFIG_H
|
| 75 | +# include "config.h"
|
| 76 | +#endif
|
| 77 | +
|
| 78 | #ifdef HAVE_NCURSES_H
|
| 79 | #include <ncurses.h>
|
| 80 | #else
|
| 81 | #include <curses.h>
|
| 82 | #endif
|
| 83 |
|
| 84 | -#ifdef HAVE_CONFIG_H
|
| 85 | -# include "config.h"
|
| 86 | -#endif
|
| 87 | -
|
| 88 | #ifdef FEAT_RUNCUST
|
| 89 |
|
| 90 | #include "apt-dater.h"
|
| 91 | diff --git a/src/screen.h b/src/screen.h
|
| 92 | index 410d341..292acb9 100644
|
| 93 | |
| 94 | |
| 95 | @@ -25,7 +25,9 @@
|
| 96 | #ifndef _SCREEN_H
|
| 97 | #define _SCREEN_H
|
| 98 |
|
| 99 | -#include "config.h"
|
| 100 | +#ifdef HAVE_CONFIG_H
|
| 101 | +# include "config.h"
|
| 102 | +#endif
|
| 103 |
|
| 104 | #ifndef FEAT_TMUX
|
| 105 |
|
| 106 |
|
| 107 | From 28559dca8f26b112f246245f981b321c39be0cc8 Mon Sep 17 00:00:00 2001
|
| 108 | From: =?UTF-8?q?Stefan=20B=C3=BChler?= <[email protected]>
|
| 109 | Date: Mon, 2 Oct 2023 15:07:43 +0200
|
| 110 | Subject: [PATCH 3/5] fix runcust feature check in header
|
| 111 |
|
| 112 | ---
|
| 113 | src/runcust.h | 2 +-
|
| 114 | 1 file changed, 1 insertion(+), 1 deletion(-)
|
| 115 |
|
| 116 | diff --git a/src/runcust.h b/src/runcust.h
|
| 117 | index b82daf3..19cc712 100644
|
| 118 | |
| 119 | |
| 120 | @@ -29,7 +29,7 @@
|
| 121 | # include "config.h"
|
| 122 | #endif
|
| 123 |
|
| 124 | -#ifndef FEAT_RUNCUST
|
| 125 | +#ifdef FEAT_RUNCUST
|
| 126 |
|
| 127 | #include "apt-dater.h"
|
| 128 |
|
| 129 |
|
| 130 | From 1f72d30df6f179cefed6501ddc0022a547eface4 Mon Sep 17 00:00:00 2001
|
| 131 | From: =?UTF-8?q?Stefan=20B=C3=BChler?= <[email protected]>
|
| 132 | Date: Sat, 30 Sep 2023 15:17:24 +0200
|
| 133 | Subject: [PATCH 4/5] tmux: use g_spawn_check_wait_status instead of deprecated
|
| 134 | g_spawn_check_exit_status with glib>=2.70
|
| 135 |
|
| 136 | ---
|
| 137 | src/tmux.c | 5 +++++
|
| 138 | 1 file changed, 5 insertions(+)
|
| 139 |
|
| 140 | diff --git a/src/tmux.c b/src/tmux.c
|
| 141 | index 8b939d7..f2a5c2c 100644
|
| 142 | |
| 143 | |
| 144 | @@ -120,7 +120,12 @@ tmux_get_sessions(HostNode *n) {
|
| 145 | return FALSE;
|
| 146 | }
|
| 147 |
|
| 148 | +#if GLIB_CHECK_VERSION(2, 70, 0)
|
| 149 | + if(!g_spawn_check_wait_status(rc, &error)) {
|
| 150 | +#else
|
| 151 | + /* deprecated name for g_spawn_check_wait_status: */
|
| 152 | if(!g_spawn_check_exit_status(rc, &error)) {
|
| 153 | +#endif
|
| 154 | /* g_warning("error on list-sessions: %s", error->message);
|
| 155 | g_clear_error (&error);*/
|
| 156 |
|
| 157 |
|
| 158 | From 02c8c2fb96dfeb3d4c08deba84217c3b70f47859 Mon Sep 17 00:00:00 2001
|
| 159 | From: =?UTF-8?q?Stefan=20B=C3=BChler?= <[email protected]>
|
| 160 | Date: Sat, 30 Sep 2023 16:39:32 +0200
|
| 161 | Subject: [PATCH 5/5] replace deprecated GCompletion with smaller local
|
| 162 | implementation
|
| 163 |
|
| 164 | ---
|
| 165 | po/POTFILES.in | 1 +
|
| 166 | src/Makefile.am | 2 +
|
| 167 | src/completion.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++
|
| 168 | src/completion.h | 50 +++++++++++++++++++
|
| 169 | src/ui.c | 31 ++++--------
|
| 170 | 5 files changed, 183 insertions(+), 23 deletions(-)
|
| 171 | create mode 100644 src/completion.c
|
| 172 | create mode 100644 src/completion.h
|
| 173 |
|
| 174 | diff --git a/po/POTFILES.in b/po/POTFILES.in
|
| 175 | index affacd0..7e6be98 100644
|
| 176 | |
| 177 | |
| 178 | @@ -2,6 +2,7 @@
|
| 179 | ./src/autoref.c
|
| 180 | ./src/clusters.c
|
| 181 | ./src/colors.c
|
| 182 | +./src/completion.c
|
| 183 | ./src/env.c
|
| 184 | ./src/exec.c
|
| 185 | ./src/history.c
|
| 186 | diff --git a/src/Makefile.am b/src/Makefile.am
|
| 187 | index f79a6ca..ed6287b 100644
|
| 188 | |
| 189 | |
| 190 | @@ -12,6 +12,8 @@ SHARED_SOURCES = \
|
| 191 | apt-dater.h \
|
| 192 | colors.c \
|
| 193 | colors.h \
|
| 194 | + completion.c \
|
| 195 | + completion.h \
|
| 196 | exec.c \
|
| 197 | exec.h \
|
| 198 | extern.h \
|
| 199 | diff --git a/src/completion.c b/src/completion.c
|
| 200 | new file mode 100644
|
| 201 | index 0000000..35e78c7
|
| 202 | |
| 203 | |
| 204 | @@ -0,0 +1,122 @@
|
| 205 | +/* apt-dater - terminal-based remote package update manager
|
| 206 | + *
|
| 207 | + * Authors:
|
| 208 | + * 2023 (C) Stefan Bühler <[email protected]>
|
| 209 | + *
|
| 210 | + * License:
|
| 211 | + * This program is free software; you can redistribute it and/or modify
|
| 212 | + * it under the terms of the GNU General Public License as published by
|
| 213 | + * the Free Software Foundation; either version 2 of the License, or
|
| 214 | + * (at your option) any later version.
|
| 215 | + *
|
| 216 | + * This program is distributed in the hope that it will be useful,
|
| 217 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 218 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 219 | + * GNU General Public License for more details.
|
| 220 | + *
|
| 221 | + * You should have received a copy of the GNU General Public License
|
| 222 | + * along with this package; if not, write to the Free Software
|
| 223 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 224 | + */
|
| 225 | +
|
| 226 | +#include "apt-dater.h"
|
| 227 | +#include "completion.h"
|
| 228 | +#include "ui.h"
|
| 229 | +
|
| 230 | +Completion *completion_init() {
|
| 231 | + Completion *cmpl = NULL;
|
| 232 | +
|
| 233 | + cmpl = g_new0(Completion, 1);
|
| 234 | + return cmpl;
|
| 235 | +}
|
| 236 | +
|
| 237 | +static void completion_reset(Completion *cmpl) {
|
| 238 | + g_list_free(cmpl->entries);
|
| 239 | + cmpl->entries = NULL;
|
| 240 | +
|
| 241 | + g_free(cmpl->cached_prefix);
|
| 242 | + cmpl->cached_prefix = NULL;
|
| 243 | +
|
| 244 | + g_list_free(cmpl->cached_entries);
|
| 245 | + cmpl->cached_entries = NULL;
|
| 246 | +}
|
| 247 | +
|
| 248 | +void completion_set_entries(Completion *cmpl, GList *entries) {
|
| 249 | + completion_reset(cmpl);
|
| 250 | +
|
| 251 | + cmpl->entries = g_list_copy(entries);
|
| 252 | +}
|
| 253 | +
|
| 254 | +static gboolean prefix_match(const gchar *entry_name, const gchar *prefix, gsize prefix_len) {
|
| 255 | + return 0 == g_ascii_strncasecmp(entry_name, prefix, prefix_len);
|
| 256 | +}
|
| 257 | +
|
| 258 | +static gboolean entry_match(GList *entry, const gchar *prefix, gsize prefix_len) {
|
| 259 | + gchar *entry_name;
|
| 260 | +
|
| 261 | + entry_name = getStrFromDrawNode((DrawNode *) entry->data);
|
| 262 | + return prefix_match(entry_name, prefix, prefix_len);
|
| 263 | +}
|
| 264 | +
|
| 265 | +GList *completion_search(Completion *cmpl, const gchar *prefix) {
|
| 266 | + GList *entry = NULL;
|
| 267 | + gsize prefix_len;
|
| 268 | +
|
| 269 | + prefix_len = strlen(prefix);
|
| 270 | + if (0 == prefix_len) {
|
| 271 | + return cmpl->entries;
|
| 272 | + }
|
| 273 | +
|
| 274 | + if (cmpl->cached_prefix) {
|
| 275 | + gsize cached_len = strlen(cmpl->cached_prefix);
|
| 276 | +
|
| 277 | + if (cached_len <= prefix_len && prefix_match(prefix, cmpl->cached_prefix, cached_len)) {
|
| 278 | + if (cached_len == prefix_len) {
|
| 279 | + return cmpl->cached_entries;
|
| 280 | + }
|
| 281 | +
|
| 282 | + for (entry = cmpl->cached_entries; entry; ) {
|
| 283 | + GList *next = g_list_next(entry);
|
| 284 | + if (!entry_match(entry, prefix, prefix_len)) {
|
| 285 | + cmpl->cached_entries = g_list_delete_link(cmpl->cached_entries, entry);
|
| 286 | + }
|
| 287 | + entry = next;
|
| 288 | + }
|
| 289 | +
|
| 290 | + goto search_done;
|
| 291 | + }
|
| 292 | + }
|
| 293 | +
|
| 294 | + /* no cache / cache prefix mismatch: */
|
| 295 | +
|
| 296 | + g_list_free(cmpl->cached_entries);
|
| 297 | + cmpl->cached_entries = NULL;
|
| 298 | +
|
| 299 | + for (entry = cmpl->entries; entry; entry = g_list_next(entry)) {
|
| 300 | + if (entry_match(entry, prefix, prefix_len)) {
|
| 301 | + cmpl->cached_entries = g_list_prepend(cmpl->cached_entries, entry->data);
|
| 302 | + }
|
| 303 | + }
|
| 304 | +
|
| 305 | +search_done:
|
| 306 | + /* Modified cache; remember prefix (unless result is empty)*/
|
| 307 | +
|
| 308 | + if (cmpl->cached_prefix) {
|
| 309 | + g_free(cmpl->cached_prefix);
|
| 310 | + cmpl->cached_prefix = NULL;
|
| 311 | + }
|
| 312 | +
|
| 313 | + if (cmpl->cached_entries) {
|
| 314 | + cmpl->cached_prefix = g_strdup(prefix);
|
| 315 | + }
|
| 316 | +
|
| 317 | + return cmpl->cached_entries;
|
| 318 | +}
|
| 319 | +
|
| 320 | +void completion_free(Completion *cmpl) {
|
| 321 | + if (!cmpl) return;
|
| 322 | +
|
| 323 | + completion_reset(cmpl);
|
| 324 | +
|
| 325 | + g_free(cmpl);
|
| 326 | +}
|
| 327 | diff --git a/src/completion.h b/src/completion.h
|
| 328 | new file mode 100644
|
| 329 | index 0000000..5244fd9
|
| 330 | |
| 331 | |
| 332 | @@ -0,0 +1,50 @@
|
| 333 | +/* apt-dater - terminal-based remote package update manager
|
| 334 | + *
|
| 335 | + * Authors:
|
| 336 | + * 2023 (C) Stefan Bühler <[email protected]>
|
| 337 | + *
|
| 338 | + * License:
|
| 339 | + * This program is free software; you can redistribute it and/or modify
|
| 340 | + * it under the terms of the GNU General Public License as published by
|
| 341 | + * the Free Software Foundation; either version 2 of the License, or
|
| 342 | + * (at your option) any later version.
|
| 343 | + *
|
| 344 | + * This program is distributed in the hope that it will be useful,
|
| 345 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 346 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 347 | + * GNU General Public License for more details.
|
| 348 | + *
|
| 349 | + * You should have received a copy of the GNU General Public License
|
| 350 | + * along with this package; if not, write to the Free Software
|
| 351 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
| 352 | + */
|
| 353 | +
|
| 354 | +#ifndef _COMPLETION_H
|
| 355 | +#define _COMPLETION_H
|
| 356 | +
|
| 357 | +#include <glib.h>
|
| 358 | +
|
| 359 | +/* Find entries in a GList that match a given prefix.
|
| 360 | + *
|
| 361 | + * Based on deprecated glib GCompletion
|
| 362 | + */
|
| 363 | +
|
| 364 | +typedef struct _completion {
|
| 365 | + GList *entries;
|
| 366 | +
|
| 367 | + /* remember last prefix and the matched entries */
|
| 368 | + gchar* cached_prefix;
|
| 369 | + GList* cached_entries;
|
| 370 | +} Completion;
|
| 371 | +
|
| 372 | +Completion *completion_init();
|
| 373 | +
|
| 374 | +/* entries: list of `DrawNode*` */
|
| 375 | +void completion_set_entries(Completion *cmpl, GList *entries);
|
| 376 | +
|
| 377 | +/* returns non-owned list; returned list gets invalidated with any other completion_* call on this instance */
|
| 378 | +GList *completion_search(Completion *cmpl, const gchar *prefix);
|
| 379 | +
|
| 380 | +void completion_free(Completion *cmpl);
|
| 381 | +
|
| 382 | +#endif /* _COMPLETION_H */
|
| 383 | diff --git a/src/ui.c b/src/ui.c
|
| 384 | index 2b71bcb..262ee3f 100644
|
| 385 | |
| 386 | |
| 387 | @@ -32,6 +32,7 @@
|
| 388 | #include "apt-dater.h"
|
| 389 | #include "ui.h"
|
| 390 | #include "colors.h"
|
| 391 | +#include "completion.h"
|
| 392 | #include "ttymux.h"
|
| 393 | #include "exec.h"
|
| 394 | #include "stats.h"
|
| 395 | @@ -75,7 +76,7 @@ gchar maintainer[48];
|
| 396 | gchar filterexp[BUF_MAX_LEN];
|
| 397 | #endif
|
| 398 | gint sc_mask = 0;
|
| 399 | -static GCompletion* dlCompl = NULL;
|
| 400 | +static Completion* dlCompl = NULL;
|
| 401 |
|
| 402 | #ifdef FEAT_TCLFILTER
|
| 403 | static Tcl_Interp *tcl_interp = NULL;
|
| 404 | @@ -397,20 +398,6 @@ static void setMenuEntries(gint mask) {
|
| 405 | }
|
| 406 |
|
| 407 |
|
| 408 | -static gchar *compDl(gpointer p)
|
| 409 | -{
|
| 410 | - gchar *ret = NULL;
|
| 411 | -
|
| 412 | - ret = getStrFromDrawNode((DrawNode *) p);
|
| 413 | -
|
| 414 | - return ret;
|
| 415 | -}
|
| 416 | -
|
| 417 | -static gint strcompDl (const gchar *s1, const gchar *s2, gsize n)
|
| 418 | -{
|
| 419 | - return(g_ascii_strncasecmp(s1, s2, n));
|
| 420 | -}
|
| 421 | -
|
| 422 | void freeDrawNode (DrawNode *n)
|
| 423 | {
|
| 424 | g_free(n);
|
| 425 | @@ -1864,9 +1851,8 @@ void doUI (GList *hosts)
|
| 426 | refreshDraw();
|
| 427 |
|
| 428 | /* Create completion list. */
|
| 429 | - dlCompl = g_completion_new(compDl);
|
| 430 | - g_completion_add_items(dlCompl, drawlist);
|
| 431 | - g_completion_set_compare(dlCompl, strcompDl);
|
| 432 | + dlCompl = completion_init();
|
| 433 | + completion_set_entries(dlCompl, drawlist);
|
| 434 |
|
| 435 | const gchar *m = getenv("MAINTAINER");
|
| 436 | if (m)
|
| 437 | @@ -2499,8 +2485,7 @@ static void expandAllNodes(GList *hosts)
|
| 438 |
|
| 439 | rebuildDrawList(hosts);
|
| 440 | }
|
| 441 | - g_completion_clear_items (dlCompl);
|
| 442 | - g_completion_add_items (dlCompl, drawlist);
|
| 443 | + completion_set_entries(dlCompl, drawlist);
|
| 444 | }
|
| 445 |
|
| 446 |
|
| 447 | @@ -2558,7 +2543,7 @@ void searchEntry(GList *hosts) {
|
| 448 |
|
| 449 | /* find completion matches */
|
| 450 | if(strlen(s))
|
| 451 | - matches = g_completion_complete(dlCompl, s, NULL);
|
| 452 | + matches = completion_search(dlCompl, s);
|
| 453 | else
|
| 454 | matches = NULL;
|
| 455 |
|
| 456 | @@ -2568,7 +2553,7 @@ void searchEntry(GList *hosts) {
|
| 457 | s[--pos] = 0;
|
| 458 |
|
| 459 | if(pos>0)
|
| 460 | - matches = g_completion_complete(dlCompl, s, NULL);
|
| 461 | + matches = completion_search(dlCompl, s);
|
| 462 | }
|
| 463 | /* print new search string */
|
| 464 | else {
|
| 465 | @@ -3738,7 +3723,7 @@ gboolean ctrlUI (GList *hosts)
|
| 466 | #ifdef FEAT_TCLFILTER
|
| 467 | if (!Tcl_InterpDeleted(tcl_interp)) Tcl_DeleteInterp(tcl_interp);
|
| 468 | #endif
|
| 469 | - if(dlCompl) g_completion_free (dlCompl);
|
| 470 | + if(dlCompl) completion_free (dlCompl);
|
| 471 |
|
| 472 | ret = FALSE;
|
| 473 | attrset(A_NORMAL);
|