summaryrefslogtreecommitdiffstats
path: root/panels/info-overview/info-cleanup.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 14:36:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 14:36:24 +0000
commit9b6d8e63db85c30007b463e91f91a791969fa83f (patch)
tree0899af51d73c1bf986f73ae39a03c4436083018a /panels/info-overview/info-cleanup.c
parentInitial commit. (diff)
downloadgnome-control-center-upstream.tar.xz
gnome-control-center-upstream.zip
Adding upstream version 1:3.38.4.upstream/1%3.38.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'panels/info-overview/info-cleanup.c')
-rw-r--r--panels/info-overview/info-cleanup.c129
1 files changed, 129 insertions, 0 deletions
diff --git a/panels/info-overview/info-cleanup.c b/panels/info-overview/info-cleanup.c
new file mode 100644
index 0000000..5a73927
--- /dev/null
+++ b/panels/info-overview/info-cleanup.c
@@ -0,0 +1,129 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2010 Red Hat, Inc
+ * Copyright (C) 2008 William Jon McCann <jmccann@redhat.com>
+ *
+ * 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 program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <config.h>
+
+#include <glib.h>
+#include "info-cleanup.h"
+
+typedef struct
+{
+ char *regex;
+ char *replacement;
+} ReplaceStrings;
+
+static char *
+prettify_info (const char *info)
+{
+ g_autofree char *escaped = NULL;
+ g_autofree gchar *pretty = NULL;
+ int i;
+ static const ReplaceStrings rs[] = {
+ { "Mesa DRI ", ""},
+ { "Intel[(]R[)]", "Intel\302\256"},
+ { "Core[(]TM[)]", "Core\342\204\242"},
+ { "Atom[(]TM[)]", "Atom\342\204\242"},
+ { "Gallium .* on (AMD .*)", "\\1"},
+ { "(AMD .*) [(].*", "\\1"},
+ { "(AMD [A-Z])(.*)", "\\1\\L\\2\\E"},
+ { "AMD", "AMD\302\256"},
+ { "Graphics Controller", "Graphics"},
+ };
+
+ if (*info == '\0')
+ return NULL;
+
+ escaped = g_markup_escape_text (info, -1);
+ pretty = g_strdup (g_strstrip (escaped));
+
+ for (i = 0; i < G_N_ELEMENTS (rs); i++)
+ {
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GRegex) re = NULL;
+ g_autofree gchar *new = NULL;
+
+ re = g_regex_new (rs[i].regex, 0, 0, &error);
+ if (re == NULL)
+ {
+ g_warning ("Error building regex: %s", error->message);
+ continue;
+ }
+
+ new = g_regex_replace (re,
+ pretty,
+ -1,
+ 0,
+ rs[i].replacement,
+ 0,
+ &error);
+
+ if (error != NULL)
+ {
+ g_warning ("Error replacing %s: %s", rs[i].regex, error->message);
+ continue;
+ }
+
+ g_free (pretty);
+ pretty = g_steal_pointer (&new);
+ }
+
+ return g_steal_pointer (&pretty);
+}
+
+static char *
+remove_duplicate_whitespace (const char *old)
+{
+ g_autofree gchar *new = NULL;
+ g_autoptr(GRegex) re = NULL;
+ g_autoptr(GError) error = NULL;
+
+ if (old == NULL)
+ return NULL;
+
+ re = g_regex_new ("[ \t\n\r]+", G_REGEX_MULTILINE, 0, &error);
+ if (re == NULL)
+ {
+ g_warning ("Error building regex: %s", error->message);
+ return g_strdup (old);
+ }
+ new = g_regex_replace (re,
+ old,
+ -1,
+ 0,
+ " ",
+ 0,
+ &error);
+ if (new == NULL)
+ {
+ g_warning ("Error replacing string: %s", error->message);
+ return g_strdup (old);
+ }
+
+ return g_steal_pointer (&new);
+}
+
+char *
+info_cleanup (const char *input)
+{
+ g_autofree char *pretty = NULL;
+
+ pretty = prettify_info (input);
+ return remove_duplicate_whitespace (pretty);
+}