From b2fe95c6d86114b2681763df845a2817ee0fe234 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 16 Jul 2014 01:26:56 -0500 Subject: make the os-release parser slightly less unreadable. --- src/service.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/service.c b/src/service.c index f8c375d..faff4d4 100644 --- a/src/service.c +++ b/src/service.c @@ -343,7 +343,7 @@ get_os_release (void) for (;;) { - char *p, *q; + char *in, *out; const char *val; GIOStatus status; @@ -357,29 +357,28 @@ get_os_release (void) continue; /* split into name=value */ - p = strchr(gstr->str, '='); - if (!p) + in = strchr(gstr->str, '='); + if (!in) continue; - *p++ = '\0'; + *in++ = '\0'; /* remove quotes and newline; un-escape */ - val = p; - q = p; - while (*p) + val = out = in; + while (*in) { - if ((*p == '\'') || (*p == '"') || (*p == '\n')) + if ((*in=='\'') || (*in=='"') || (*in=='\n')) /* skip chars */ { - ++p; + ++in; } else { - if ((*p=='\\') && !*++p) + if ((*in=='\\') && !*++in) /* handle an escaped char */ break; - *q++ = *p++; - } - *q = '\0'; /* zero terminate */ + *out++ = *in++; + } } + *out = '\0'; /* zero terminate */ g_hash_table_insert (hash, g_strdup(gstr->str), g_strdup(val)); } -- cgit v1.2.3