diff options
author | Kurtis Rader <krader@skepticism.us> | 2016-05-03 15:18:24 -0700 |
---|---|---|
committer | Kurtis Rader <krader@skepticism.us> | 2016-05-03 16:09:45 -0700 |
commit | 5c8763be0e68bbdec3fdd1edb5754f4c421098e1 (patch) | |
tree | 8b9a5068fa2f87d0a97c61df1336cd083c6b1504 /src/util.cpp | |
parent | ee44879d4d6ae28968885823db5f0ce13e5a6dec (diff) |
restyle remaining modules to match project style
For this change I decided to bundle the remaining modules that need to be
resytyled because only two were large enough to warrant doing on their own.
Reduces lint errors from 225 to 162 (-28%). Line count from 3073 to 2465 (-20%).
Another step in resolving issue #2902.
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 80 |
1 files changed, 30 insertions, 50 deletions
diff --git a/src/util.cpp b/src/util.cpp index 9d084af6..316bac68 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,39 +1,32 @@ -/** \file util.c - Generic utilities library. - - Contains datastructures such as automatically growing array lists, priority queues, etc. -*/ +// Generic utilities library. +// +// Contains data structures such as automatically growing array lists, priority queues, etc. +#include <errno.h> #include <stdlib.h> +#include <sys/time.h> +#include <sys/types.h> #include <wchar.h> #include <wctype.h> -#include <sys/types.h> -#include <errno.h> -#include <sys/time.h> +#include "common.h" #include "fallback.h" // IWYU pragma: keep #include "util.h" -#include "common.h" #include "wutil.h" // IWYU pragma: keep -int wcsfilecmp(const wchar_t *a, const wchar_t *b) -{ +int wcsfilecmp(const wchar_t *a, const wchar_t *b) { CHECK(a, 0); CHECK(b, 0); - if (*a==0) - { - if (*b==0) - return 0; + if (*a == 0) { + if (*b == 0) return 0; return -1; } - if (*b==0) - { + if (*b == 0) { return 1; } - long secondary_diff=0; - if (iswdigit(*a) && iswdigit(*b)) - { + long secondary_diff = 0; + if (iswdigit(*a) && iswdigit(*b)) { wchar_t *aend, *bend; long al; long bl; @@ -43,53 +36,40 @@ int wcsfilecmp(const wchar_t *a, const wchar_t *b) al = wcstol(a, &aend, 10); bl = wcstol(b, &bend, 10); - if (errno) - { - /* - Huuuuuuuuge numbers - fall back to regular string comparison - */ + if (errno) { + // Huge numbers - fall back to regular string comparison. return wcscmp(a, b); } diff = al - bl; - if (diff) - return diff > 0 ? 2 : -2; + if (diff) return diff > 0 ? 2 : -2; - secondary_diff = (aend-a) - (bend-b); + secondary_diff = (aend - a) - (bend - b); - a=aend-1; - b=bend-1; - } - else - { + a = aend - 1; + b = bend - 1; + } else { int diff = towlower(*a) - towlower(*b); - if (diff != 0) - return (diff>0)?2:-2; + if (diff != 0) return (diff > 0) ? 2 : -2; - secondary_diff = *a-*b; + secondary_diff = *a - *b; } - int res = wcsfilecmp(a+1, b+1); + int res = wcsfilecmp(a + 1, b + 1); - if (abs(res) < 2) - { - /* - No primary difference in rest of string. - Use secondary difference on this element if found. - */ - if (secondary_diff) - { - return secondary_diff > 0 ? 1 :-1; + if (abs(res) < 2) { + // No primary difference in rest of string. Use secondary difference on this element if + // found. + if (secondary_diff) { + return secondary_diff > 0 ? 1 : -1; } } return res; } -long long get_time() -{ +long long get_time() { struct timeval time_struct; gettimeofday(&time_struct, 0); - return 1000000ll*time_struct.tv_sec+time_struct.tv_usec; + return 1000000ll * time_struct.tv_sec + time_struct.tv_usec; } - |