aports/testing/apt-dater/fix-gnu-source-warning.patch

473 lines
12 KiB
Diff

Source: https://github.com/DE-IBH/apt-dater/pull/181.patch
--
From 4e820e5f885d6102a740553679ae188b3f5902bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20B=C3=BChler?= <source@stbuehler.de>
Date: Sat, 30 Sep 2023 14:28:26 +0200
Subject: [PATCH 1/5] fix _GNU_SOURCE redefinition warning
---
src/apt-dater.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/apt-dater.h b/src/apt-dater.h
index 7eda355..447c29d 100644
--- a/src/apt-dater.h
+++ b/src/apt-dater.h
@@ -25,7 +25,9 @@
#ifndef _APT_DATER_H
#define _APT_DATER_H
-#define _GNU_SOURCE
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
#include <assert.h>
#include <stdio.h>
From 1f65f0267bb3319e9513298409352cb9aef78819 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20B=C3=BChler?= <source@stbuehler.de>
Date: Mon, 2 Oct 2023 13:39:36 +0200
Subject: [PATCH 2/5] consistent include of config.h
---
src/apt-dater.h | 9 ++++-----
src/runcust.c | 8 ++++----
src/screen.h | 4 +++-
3 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/apt-dater.h b/src/apt-dater.h
index 447c29d..7de9d28 100644
--- a/src/apt-dater.h
+++ b/src/apt-dater.h
@@ -42,7 +42,10 @@
#include <glib/gstdio.h>
#include <gio/gio.h>
-#include "../config.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include "../include/adproto.h"
#ifdef HAVE_GETTEXT
@@ -60,10 +63,6 @@
#define BUF_MAX_LEN 256
#define PROG_NAME PACKAGE
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
#ifndef NDEBUG
typedef enum {
T_CFGFILE=1,
diff --git a/src/runcust.c b/src/runcust.c
index bc41e5f..70ecd6e 100644
--- a/src/runcust.c
+++ b/src/runcust.c
@@ -25,16 +25,16 @@
#include <glib.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#ifdef HAVE_NCURSES_H
#include <ncurses.h>
#else
#include <curses.h>
#endif
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
#ifdef FEAT_RUNCUST
#include "apt-dater.h"
diff --git a/src/screen.h b/src/screen.h
index 410d341..292acb9 100644
--- a/src/screen.h
+++ b/src/screen.h
@@ -25,7 +25,9 @@
#ifndef _SCREEN_H
#define _SCREEN_H
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
#ifndef FEAT_TMUX
From 28559dca8f26b112f246245f981b321c39be0cc8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20B=C3=BChler?= <source@stbuehler.de>
Date: Mon, 2 Oct 2023 15:07:43 +0200
Subject: [PATCH 3/5] fix runcust feature check in header
---
src/runcust.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/runcust.h b/src/runcust.h
index b82daf3..19cc712 100644
--- a/src/runcust.h
+++ b/src/runcust.h
@@ -29,7 +29,7 @@
# include "config.h"
#endif
-#ifndef FEAT_RUNCUST
+#ifdef FEAT_RUNCUST
#include "apt-dater.h"
From 1f72d30df6f179cefed6501ddc0022a547eface4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20B=C3=BChler?= <source@stbuehler.de>
Date: Sat, 30 Sep 2023 15:17:24 +0200
Subject: [PATCH 4/5] tmux: use g_spawn_check_wait_status instead of deprecated
g_spawn_check_exit_status with glib>=2.70
---
src/tmux.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/tmux.c b/src/tmux.c
index 8b939d7..f2a5c2c 100644
--- a/src/tmux.c
+++ b/src/tmux.c
@@ -120,7 +120,12 @@ tmux_get_sessions(HostNode *n) {
return FALSE;
}
+#if GLIB_CHECK_VERSION(2, 70, 0)
+ if(!g_spawn_check_wait_status(rc, &error)) {
+#else
+ /* deprecated name for g_spawn_check_wait_status: */
if(!g_spawn_check_exit_status(rc, &error)) {
+#endif
/* g_warning("error on list-sessions: %s", error->message);
g_clear_error (&error);*/
From 02c8c2fb96dfeb3d4c08deba84217c3b70f47859 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20B=C3=BChler?= <source@stbuehler.de>
Date: Sat, 30 Sep 2023 16:39:32 +0200
Subject: [PATCH 5/5] replace deprecated GCompletion with smaller local
implementation
---
po/POTFILES.in | 1 +
src/Makefile.am | 2 +
src/completion.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++
src/completion.h | 50 +++++++++++++++++++
src/ui.c | 31 ++++--------
5 files changed, 183 insertions(+), 23 deletions(-)
create mode 100644 src/completion.c
create mode 100644 src/completion.h
diff --git a/po/POTFILES.in b/po/POTFILES.in
index affacd0..7e6be98 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,6 +2,7 @@
./src/autoref.c
./src/clusters.c
./src/colors.c
+./src/completion.c
./src/env.c
./src/exec.c
./src/history.c
diff --git a/src/Makefile.am b/src/Makefile.am
index f79a6ca..ed6287b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,6 +12,8 @@ SHARED_SOURCES = \
apt-dater.h \
colors.c \
colors.h \
+ completion.c \
+ completion.h \
exec.c \
exec.h \
extern.h \
diff --git a/src/completion.c b/src/completion.c
new file mode 100644
index 0000000..35e78c7
--- /dev/null
+++ b/src/completion.c
@@ -0,0 +1,122 @@
+/* apt-dater - terminal-based remote package update manager
+ *
+ * Authors:
+ * 2023 (C) Stefan Bühler <source@stbuehler.de>
+ *
+ * License:
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this package; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "apt-dater.h"
+#include "completion.h"
+#include "ui.h"
+
+Completion *completion_init() {
+ Completion *cmpl = NULL;
+
+ cmpl = g_new0(Completion, 1);
+ return cmpl;
+}
+
+static void completion_reset(Completion *cmpl) {
+ g_list_free(cmpl->entries);
+ cmpl->entries = NULL;
+
+ g_free(cmpl->cached_prefix);
+ cmpl->cached_prefix = NULL;
+
+ g_list_free(cmpl->cached_entries);
+ cmpl->cached_entries = NULL;
+}
+
+void completion_set_entries(Completion *cmpl, GList *entries) {
+ completion_reset(cmpl);
+
+ cmpl->entries = g_list_copy(entries);
+}
+
+static gboolean prefix_match(const gchar *entry_name, const gchar *prefix, gsize prefix_len) {
+ return 0 == g_ascii_strncasecmp(entry_name, prefix, prefix_len);
+}
+
+static gboolean entry_match(GList *entry, const gchar *prefix, gsize prefix_len) {
+ gchar *entry_name;
+
+ entry_name = getStrFromDrawNode((DrawNode *) entry->data);
+ return prefix_match(entry_name, prefix, prefix_len);
+}
+
+GList *completion_search(Completion *cmpl, const gchar *prefix) {
+ GList *entry = NULL;
+ gsize prefix_len;
+
+ prefix_len = strlen(prefix);
+ if (0 == prefix_len) {
+ return cmpl->entries;
+ }
+
+ if (cmpl->cached_prefix) {
+ gsize cached_len = strlen(cmpl->cached_prefix);
+
+ if (cached_len <= prefix_len && prefix_match(prefix, cmpl->cached_prefix, cached_len)) {
+ if (cached_len == prefix_len) {
+ return cmpl->cached_entries;
+ }
+
+ for (entry = cmpl->cached_entries; entry; ) {
+ GList *next = g_list_next(entry);
+ if (!entry_match(entry, prefix, prefix_len)) {
+ cmpl->cached_entries = g_list_delete_link(cmpl->cached_entries, entry);
+ }
+ entry = next;
+ }
+
+ goto search_done;
+ }
+ }
+
+ /* no cache / cache prefix mismatch: */
+
+ g_list_free(cmpl->cached_entries);
+ cmpl->cached_entries = NULL;
+
+ for (entry = cmpl->entries; entry; entry = g_list_next(entry)) {
+ if (entry_match(entry, prefix, prefix_len)) {
+ cmpl->cached_entries = g_list_prepend(cmpl->cached_entries, entry->data);
+ }
+ }
+
+search_done:
+ /* Modified cache; remember prefix (unless result is empty)*/
+
+ if (cmpl->cached_prefix) {
+ g_free(cmpl->cached_prefix);
+ cmpl->cached_prefix = NULL;
+ }
+
+ if (cmpl->cached_entries) {
+ cmpl->cached_prefix = g_strdup(prefix);
+ }
+
+ return cmpl->cached_entries;
+}
+
+void completion_free(Completion *cmpl) {
+ if (!cmpl) return;
+
+ completion_reset(cmpl);
+
+ g_free(cmpl);
+}
diff --git a/src/completion.h b/src/completion.h
new file mode 100644
index 0000000..5244fd9
--- /dev/null
+++ b/src/completion.h
@@ -0,0 +1,50 @@
+/* apt-dater - terminal-based remote package update manager
+ *
+ * Authors:
+ * 2023 (C) Stefan Bühler <source@stbuehler.de>
+ *
+ * License:
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this package; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef _COMPLETION_H
+#define _COMPLETION_H
+
+#include <glib.h>
+
+/* Find entries in a GList that match a given prefix.
+ *
+ * Based on deprecated glib GCompletion
+ */
+
+typedef struct _completion {
+ GList *entries;
+
+ /* remember last prefix and the matched entries */
+ gchar* cached_prefix;
+ GList* cached_entries;
+} Completion;
+
+Completion *completion_init();
+
+/* entries: list of `DrawNode*` */
+void completion_set_entries(Completion *cmpl, GList *entries);
+
+/* returns non-owned list; returned list gets invalidated with any other completion_* call on this instance */
+GList *completion_search(Completion *cmpl, const gchar *prefix);
+
+void completion_free(Completion *cmpl);
+
+#endif /* _COMPLETION_H */
diff --git a/src/ui.c b/src/ui.c
index 2b71bcb..262ee3f 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -32,6 +32,7 @@
#include "apt-dater.h"
#include "ui.h"
#include "colors.h"
+#include "completion.h"
#include "ttymux.h"
#include "exec.h"
#include "stats.h"
@@ -75,7 +76,7 @@ gchar maintainer[48];
gchar filterexp[BUF_MAX_LEN];
#endif
gint sc_mask = 0;
-static GCompletion* dlCompl = NULL;
+static Completion* dlCompl = NULL;
#ifdef FEAT_TCLFILTER
static Tcl_Interp *tcl_interp = NULL;
@@ -397,20 +398,6 @@ static void setMenuEntries(gint mask) {
}
-static gchar *compDl(gpointer p)
-{
- gchar *ret = NULL;
-
- ret = getStrFromDrawNode((DrawNode *) p);
-
- return ret;
-}
-
-static gint strcompDl (const gchar *s1, const gchar *s2, gsize n)
-{
- return(g_ascii_strncasecmp(s1, s2, n));
-}
-
void freeDrawNode (DrawNode *n)
{
g_free(n);
@@ -1864,9 +1851,8 @@ void doUI (GList *hosts)
refreshDraw();
/* Create completion list. */
- dlCompl = g_completion_new(compDl);
- g_completion_add_items(dlCompl, drawlist);
- g_completion_set_compare(dlCompl, strcompDl);
+ dlCompl = completion_init();
+ completion_set_entries(dlCompl, drawlist);
const gchar *m = getenv("MAINTAINER");
if (m)
@@ -2499,8 +2485,7 @@ static void expandAllNodes(GList *hosts)
rebuildDrawList(hosts);
}
- g_completion_clear_items (dlCompl);
- g_completion_add_items (dlCompl, drawlist);
+ completion_set_entries(dlCompl, drawlist);
}
@@ -2558,7 +2543,7 @@ void searchEntry(GList *hosts) {
/* find completion matches */
if(strlen(s))
- matches = g_completion_complete(dlCompl, s, NULL);
+ matches = completion_search(dlCompl, s);
else
matches = NULL;
@@ -2568,7 +2553,7 @@ void searchEntry(GList *hosts) {
s[--pos] = 0;
if(pos>0)
- matches = g_completion_complete(dlCompl, s, NULL);
+ matches = completion_search(dlCompl, s);
}
/* print new search string */
else {
@@ -3738,7 +3723,7 @@ gboolean ctrlUI (GList *hosts)
#ifdef FEAT_TCLFILTER
if (!Tcl_InterpDeleted(tcl_interp)) Tcl_DeleteInterp(tcl_interp);
#endif
- if(dlCompl) g_completion_free (dlCompl);
+ if(dlCompl) completion_free (dlCompl);
ret = FALSE;
attrset(A_NORMAL);