cursor: refactor xcursor_theme_inherits

Use early returns and breaks to avoid dealing with very long
indentation lines.

Signed-off-by: Simon Ser <contact@emersion.fr>
This commit is contained in:
Simon Ser 2022-04-21 11:53:24 +02:00
parent 963014459c
commit 245d30ecb8

View file

@ -755,9 +755,13 @@ xcursor_theme_inherits(const char *full)
return NULL; return NULL;
f = fopen(full, "r"); f = fopen(full, "r");
if (f) { if (!f)
return NULL;
while (fgets(line, sizeof(line), f)) { while (fgets(line, sizeof(line), f)) {
if (!strncmp(line, "Inherits", 8)) { if (strncmp(line, "Inherits", 8))
continue;
char *l = line + 8; char *l = line + 8;
char *r; char *r;
while (*l == ' ') while (*l == ' ')
@ -768,7 +772,9 @@ xcursor_theme_inherits(const char *full)
while (*l == ' ') while (*l == ' ')
l++; l++;
result = malloc(strlen(l) + 1); result = malloc(strlen(l) + 1);
if (result) { if (!result)
break;
r = result; r = result;
while (*l) { while (*l) {
while (xcursor_sep(*l) || xcursor_white(*l)) while (xcursor_sep(*l) || xcursor_white(*l))
@ -777,17 +783,15 @@ xcursor_theme_inherits(const char *full)
break; break;
if (r != result) if (r != result)
*r++ = ':'; *r++ = ':';
while (*l && !xcursor_white(*l) && while (*l && !xcursor_white(*l) && !xcursor_sep(*l))
!xcursor_sep(*l))
*r++ = *l++; *r++ = *l++;
} }
*r++ = '\0'; *r++ = '\0';
}
break; break;
} }
}
fclose(f); fclose(f);
}
return result; return result;
} }