mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-25 11:40:06 +01:00
tools: record: drop quotes from os-release information
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
4d92ea116c
commit
d80bbcb028
3 changed files with 67 additions and 2 deletions
|
|
@ -312,3 +312,29 @@ error:
|
|||
free(result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strip any of the characters in what from the beginning and end of the
|
||||
* input string.
|
||||
*
|
||||
* @return a newly allocated string with none of "what" at the beginning or
|
||||
* end of string
|
||||
*/
|
||||
static inline char *
|
||||
strstrip(const char *input, const char *what)
|
||||
{
|
||||
char *str, *last;
|
||||
|
||||
str = safe_strdup(&input[strspn(input, what)]);
|
||||
|
||||
last = str;
|
||||
|
||||
for (char *c = str; *c != '\0'; c++) {
|
||||
if (!strchr(what, *c))
|
||||
last = c + 1;
|
||||
}
|
||||
|
||||
*last = '\0';
|
||||
|
||||
return str;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1033,6 +1033,44 @@ START_TEST(strjoin_test)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(strstrip_test)
|
||||
{
|
||||
struct strstrip_test {
|
||||
const char *string;
|
||||
const char *expected;
|
||||
const char *what;
|
||||
} tests[] = {
|
||||
{ "foo", "foo", "1234" },
|
||||
{ "\"bar\"", "bar", "\"" },
|
||||
{ "'bar'", "bar", "'" },
|
||||
{ "\"bar\"", "\"bar\"", "'" },
|
||||
{ "'bar'", "'bar'", "\"" },
|
||||
{ "\"bar\"", "bar", "\"" },
|
||||
{ "\"\"", "", "\"" },
|
||||
{ "\"foo\"bar\"", "foo\"bar", "\"" },
|
||||
{ "\"'foo\"bar\"", "foo\"bar", "\"'" },
|
||||
{ "abcfooabcbarbca", "fooabcbar", "abc" },
|
||||
{ "xxxxfoo", "foo", "x" },
|
||||
{ "fooyyyy", "foo", "y" },
|
||||
{ "xxxxfooyyyy", "foo", "xy" },
|
||||
{ "x xfooy y", " xfooy ", "xy" },
|
||||
{ " foo\n", "foo", " \n" },
|
||||
{ "", "", "abc" },
|
||||
{ "", "", "" },
|
||||
{ NULL , NULL, NULL }
|
||||
};
|
||||
struct strstrip_test *t = tests;
|
||||
|
||||
while (t->string) {
|
||||
char *str;
|
||||
str = strstrip(t->string, t->what);
|
||||
ck_assert_str_eq(str, t->expected);
|
||||
free(str);
|
||||
t++;
|
||||
}
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(list_test_insert)
|
||||
{
|
||||
struct list_test {
|
||||
|
|
@ -1138,6 +1176,7 @@ litest_utils_suite(void)
|
|||
tcase_add_test(tc, strsplit_test);
|
||||
tcase_add_test(tc, kvsplit_double_test);
|
||||
tcase_add_test(tc, strjoin_test);
|
||||
tcase_add_test(tc, strstrip_test);
|
||||
tcase_add_test(tc, time_conversion);
|
||||
|
||||
tcase_add_test(tc, list_test_insert);
|
||||
|
|
|
|||
|
|
@ -1447,9 +1447,9 @@ print_system_header(struct record_context *ctx)
|
|||
osrstr[strlen(osrstr) - 1] = '\0'; /* linebreak */
|
||||
|
||||
if (!distro && strneq(osrstr, "ID=", 3))
|
||||
distro = safe_strdup(&osrstr[3]);
|
||||
distro = strstrip(&osrstr[3], "\"'");
|
||||
else if (!version && strneq(osrstr, "VERSION_ID=", 11))
|
||||
version = safe_strdup(&osrstr[11]);
|
||||
version = strstrip(&osrstr[11], "\"'");
|
||||
|
||||
if (distro && version) {
|
||||
iprintf(ctx, "os: \"%s:%s\"\n", distro, version);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue