2016-11-16 15:07:10 +01:00
|
|
|
/* -*- 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)
|
|
|
|
{
|
2017-09-25 16:52:58 -04:00
|
|
|
g_autofree char *escaped = NULL;
|
|
|
|
g_autofree gchar *pretty = NULL;
|
2016-11-16 15:07:10 +01:00
|
|
|
int i;
|
|
|
|
static const ReplaceStrings rs[] = {
|
|
|
|
{ "Mesa DRI ", ""},
|
2022-12-02 10:25:29 +01:00
|
|
|
{ "Mesa Intel", "Intel"},
|
2022-01-29 08:09:46 +01:00
|
|
|
{ "[(]R[)]", "\302\256"},
|
|
|
|
{ "[(](tm|TM)[)]", "\342\204\242"},
|
2022-01-29 11:10:04 +01:00
|
|
|
{ "(ATI|EPYC|AMD FX|Radeon|Ryzen|Threadripper|GeForce RTX) ", "\\1\342\204\242 "},
|
2022-01-29 08:06:49 +01:00
|
|
|
{ "Gallium \\d+\\.\\d+ on (.*)", "\\1"},
|
2022-01-29 10:29:15 +01:00
|
|
|
{ " CPU| Processor| \\S+-Core| @ \\d+\\.\\d+GHz", ""},
|
2022-01-29 10:58:55 +01:00
|
|
|
{ " x86|/MMX|/SSE2|/PCIe", ""},
|
2022-01-29 08:25:21 +01:00
|
|
|
{ " [(][^)]*(DRM|MESA|LLVM)[^)]*[)]?", ""},
|
2016-11-16 15:07:10 +01:00
|
|
|
{ "Graphics Controller", "Graphics"},
|
2022-01-29 10:56:33 +01:00
|
|
|
{ ".*llvmpipe.*", "Software Rendering"},
|
2016-11-16 15:07:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
if (*info == '\0')
|
|
|
|
return NULL;
|
|
|
|
|
2017-09-25 16:52:58 -04:00
|
|
|
escaped = g_markup_escape_text (info, -1);
|
|
|
|
pretty = g_strdup (g_strstrip (escaped));
|
2016-11-16 15:07:10 +01:00
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (rs); i++)
|
|
|
|
{
|
2017-09-25 16:52:58 -04:00
|
|
|
g_autoptr(GError) error = NULL;
|
|
|
|
g_autoptr(GRegex) re = NULL;
|
|
|
|
g_autofree gchar *new = NULL;
|
2016-11-16 15:07:10 +01:00
|
|
|
|
|
|
|
re = g_regex_new (rs[i].regex, 0, 0, &error);
|
|
|
|
if (re == NULL)
|
|
|
|
{
|
|
|
|
g_warning ("Error building regex: %s", error->message);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-11-16 16:40:08 +01:00
|
|
|
new = g_regex_replace (re,
|
|
|
|
pretty,
|
|
|
|
-1,
|
|
|
|
0,
|
|
|
|
rs[i].replacement,
|
|
|
|
0,
|
|
|
|
&error);
|
2016-11-16 15:07:10 +01:00
|
|
|
|
|
|
|
if (error != NULL)
|
|
|
|
{
|
|
|
|
g_warning ("Error replacing %s: %s", rs[i].regex, error->message);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (pretty);
|
2017-09-25 16:52:58 -04:00
|
|
|
pretty = g_steal_pointer (&new);
|
2016-11-16 15:07:10 +01:00
|
|
|
}
|
|
|
|
|
2017-09-25 16:52:58 -04:00
|
|
|
return g_steal_pointer (&pretty);
|
2016-11-16 15:07:10 +01:00
|
|
|
}
|
|
|
|
|
2016-11-16 16:10:52 +01:00
|
|
|
static char *
|
|
|
|
remove_duplicate_whitespace (const char *old)
|
|
|
|
{
|
2017-09-25 16:52:58 -04:00
|
|
|
g_autofree gchar *new = NULL;
|
|
|
|
g_autoptr(GRegex) re = NULL;
|
|
|
|
g_autoptr(GError) error = NULL;
|
2016-11-16 16:10:52 +01:00
|
|
|
|
2016-12-05 10:15:12 +01:00
|
|
|
if (old == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2016-11-16 16:10:52 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-09-25 16:52:58 -04:00
|
|
|
return g_steal_pointer (&new);
|
2016-11-16 16:10:52 +01:00
|
|
|
}
|
|
|
|
|
2016-11-16 15:07:10 +01:00
|
|
|
char *
|
|
|
|
info_cleanup (const char *input)
|
|
|
|
{
|
2019-10-03 10:55:28 +13:00
|
|
|
g_autofree char *pretty = NULL;
|
2016-11-16 16:10:52 +01:00
|
|
|
|
|
|
|
pretty = prettify_info (input);
|
2017-09-25 16:52:58 -04:00
|
|
|
return remove_duplicate_whitespace (pretty);
|
2016-11-16 15:07:10 +01:00
|
|
|
}
|