diff options
author | Simon Ser <contact@emersion.fr> | 2022-04-21 11:53:24 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2022-05-23 08:59:05 +0000 |
commit | 245d30ecb8a5001ec698e2db1fd77c3661563da5 (patch) | |
tree | 1be8b4bf1364b3bf1326ddeb69491319cec515c5 /cursor | |
parent | 963014459c5eb54b1317c688f9e2dfbac44a672d (diff) | |
download | wayland-245d30ecb8a5001ec698e2db1fd77c3661563da5.tar.gz |
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>
Diffstat (limited to 'cursor')
-rw-r--r-- | cursor/xcursor.c | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/cursor/xcursor.c b/cursor/xcursor.c index 0a7dfec..5aab4ef 100644 --- a/cursor/xcursor.c +++ b/cursor/xcursor.c @@ -755,39 +755,43 @@ xcursor_theme_inherits(const char *full) return NULL; f = fopen(full, "r"); - if (f) { - while (fgets(line, sizeof(line), f)) { - if (!strncmp(line, "Inherits", 8)) { - char *l = line + 8; - char *r; - while (*l == ' ') - l++; - if (*l != '=') - continue; + if (!f) + return NULL; + + while (fgets(line, sizeof(line), f)) { + if (strncmp(line, "Inherits", 8)) + continue; + + char *l = line + 8; + char *r; + while (*l == ' ') + l++; + if (*l != '=') + continue; + l++; + while (*l == ' ') + l++; + result = malloc(strlen(l) + 1); + if (!result) + break; + + r = result; + while (*l) { + while (xcursor_sep(*l) || xcursor_white(*l)) l++; - while (*l == ' ') - l++; - result = malloc(strlen(l) + 1); - if (result) { - r = result; - while (*l) { - while (xcursor_sep(*l) || xcursor_white(*l)) - l++; - if (!*l) - break; - if (r != result) - *r++ = ':'; - while (*l && !xcursor_white(*l) && - !xcursor_sep(*l)) - *r++ = *l++; - } - *r++ = '\0'; - } + if (!*l) break; - } + if (r != result) + *r++ = ':'; + while (*l && !xcursor_white(*l) && !xcursor_sep(*l)) + *r++ = *l++; } - fclose(f); + *r++ = '\0'; + + break; } + + fclose(f); return result; } |