From 872e542f4eca52ce2198ba3fc30a51bc5d672dae Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Wed, 14 Oct 2020 20:21:09 +0200 Subject: Rename StringUtils.[ch] to XUtils.[ch] --- Action.c | 2 +- AffinityPanel.c | 2 +- AvailableColumnsPanel.c | 2 +- AvailableMetersPanel.c | 2 +- BatteryMeter.c | 2 +- CPUMeter.c | 2 +- CRT.c | 2 +- ColorsPanel.c | 2 +- ColumnsPanel.c | 2 +- CommandScreen.c | 2 +- DiskIOMeter.c | 2 +- DisplayOptionsPanel.c | 2 +- EnvScreen.c | 2 +- FunctionBar.c | 2 +- Header.c | 2 +- IncSet.c | 3 +- InfoScreen.c | 2 +- ListItem.c | 2 +- LoadAverageMeter.c | 2 +- Makefile.am | 8 +- Meter.c | 2 +- OpenFilesScreen.c | 2 +- Panel.c | 2 +- Process.c | 2 +- ProcessList.c | 4 +- Settings.c | 6 +- SignalsPanel.c | 2 +- StringUtils.c | 179 -------------------------------------------- StringUtils.h | 45 ----------- TasksMeter.c | 2 +- TraceScreen.c | 2 +- UptimeMeter.c | 2 +- UsersTable.c | 2 +- XUtils.c | 179 ++++++++++++++++++++++++++++++++++++++++++++ XUtils.h | 45 +++++++++++ htop.c | 2 +- linux/Battery.c | 9 ++- linux/IOPriorityPanel.c | 2 +- linux/LinuxProcess.c | 3 +- linux/LinuxProcessList.c | 3 +- linux/Platform.c | 2 +- linux/PressureStallMeter.c | 2 +- zfs/ZfsCompressedArcMeter.c | 2 +- 43 files changed, 276 insertions(+), 272 deletions(-) delete mode 100644 StringUtils.c delete mode 100644 StringUtils.h create mode 100644 XUtils.c create mode 100644 XUtils.h diff --git a/Action.c b/Action.c index 6d7782ca..f53acf7b 100644 --- a/Action.c +++ b/Action.c @@ -19,9 +19,9 @@ in the source distribution for its full text. #include "Process.h" #include "ScreenManager.h" #include "SignalsPanel.h" -#include "StringUtils.h" #include "TraceScreen.h" #include "Platform.h" +#include "XUtils.h" #include #include diff --git a/AffinityPanel.c b/AffinityPanel.c index 0027d4a4..ab17b420 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -13,8 +13,8 @@ in the source distribution for its full text. #include #include "CRT.h" -#include "StringUtils.h" #include "Vector.h" +#include "XUtils.h" #ifdef HAVE_LIBHWLOC #include diff --git a/AvailableColumnsPanel.c b/AvailableColumnsPanel.c index a2a6aba6..32bb470e 100644 --- a/AvailableColumnsPanel.c +++ b/AvailableColumnsPanel.c @@ -15,7 +15,7 @@ in the source distribution for its full text. #include "ColumnsPanel.h" #include "Header.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" static const char* const AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL}; diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c index b90912bd..faa69a8f 100644 --- a/AvailableMetersPanel.c +++ b/AvailableMetersPanel.c @@ -12,7 +12,7 @@ in the source distribution for its full text. #include "Header.h" #include "ListItem.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include diff --git a/BatteryMeter.c b/BatteryMeter.c index 060b125c..22a63c7a 100644 --- a/BatteryMeter.c +++ b/BatteryMeter.c @@ -12,8 +12,8 @@ This meter written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). #include "Battery.h" #include "ProcessList.h" #include "CRT.h" -#include "StringUtils.h" #include "Platform.h" +#include "XUtils.h" #include #include diff --git a/CPUMeter.c b/CPUMeter.c index c3133a2c..7e70f454 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -10,7 +10,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Settings.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include diff --git a/CRT.c b/CRT.c index 06ce0451..2f9eb2b6 100644 --- a/CRT.c +++ b/CRT.c @@ -8,8 +8,8 @@ in the source distribution for its full text. #include "config.h" #include "CRT.h" -#include "StringUtils.h" #include "RichString.h" +#include "XUtils.h" #include #include diff --git a/ColorsPanel.c b/ColorsPanel.c index 45745a73..5b189ea3 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -9,7 +9,7 @@ in the source distribution for its full text. #include "CRT.h" #include "CheckItem.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include diff --git a/ColumnsPanel.c b/ColumnsPanel.c index e4fe4fc1..a0e9fd31 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -8,7 +8,7 @@ in the source distribution for its full text. #include "ColumnsPanel.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" #include "ListItem.h" #include "CRT.h" diff --git a/CommandScreen.c b/CommandScreen.c index 58ed8840..df039645 100644 --- a/CommandScreen.c +++ b/CommandScreen.c @@ -5,7 +5,7 @@ #include "IncSet.h" #include "ListItem.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include diff --git a/DiskIOMeter.c b/DiskIOMeter.c index 34b0f081..d882b433 100644 --- a/DiskIOMeter.c +++ b/DiskIOMeter.c @@ -11,7 +11,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" static const int DiskIOMeter_attributes[] = { diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index d6534887..d667ab7f 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -13,7 +13,7 @@ in the source distribution for its full text. #include "CheckItem.h" #include "CRT.h" -#include "StringUtils.h" +#include "XUtils.h" static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; diff --git a/EnvScreen.c b/EnvScreen.c index 1f107457..10060ec7 100644 --- a/EnvScreen.c +++ b/EnvScreen.c @@ -5,7 +5,7 @@ #include "IncSet.h" #include "ListItem.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include diff --git a/FunctionBar.c b/FunctionBar.c index 3e00b87e..4e9d30cd 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -8,8 +8,8 @@ in the source distribution for its full text. #include "FunctionBar.h" #include "CRT.h" #include "RichString.h" -#include "StringUtils.h" #include "XAlloc.h" +#include "XUtils.h" #include #include diff --git a/Header.c b/Header.c index e5a64db1..f5233370 100644 --- a/Header.c +++ b/Header.c @@ -8,8 +8,8 @@ in the source distribution for its full text. #include "Header.h" #include "CRT.h" -#include "StringUtils.h" #include "Platform.h" +#include "XUtils.h" #include #include diff --git a/IncSet.c b/IncSet.c index 9dda3ce1..3534f857 100644 --- a/IncSet.c +++ b/IncSet.c @@ -6,9 +6,10 @@ in the source distribution for its full text. */ #include "IncSet.h" -#include "StringUtils.h" #include "ListItem.h" #include "CRT.h" +#include "XUtils.h" + #include #include diff --git a/InfoScreen.c b/InfoScreen.c index ecde6d91..ed890f7d 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -6,7 +6,7 @@ #include "IncSet.h" #include "ListItem.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include diff --git a/ListItem.c b/ListItem.c index d9d36f89..c4479d73 100644 --- a/ListItem.c +++ b/ListItem.c @@ -8,8 +8,8 @@ in the source distribution for its full text. #include "ListItem.h" #include "CRT.h" -#include "StringUtils.h" #include "RichString.h" +#include "XUtils.h" #include #include diff --git a/LoadAverageMeter.c b/LoadAverageMeter.c index 507d3dc3..c52bffc1 100644 --- a/LoadAverageMeter.c +++ b/LoadAverageMeter.c @@ -9,7 +9,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" static const int LoadAverageMeter_attributes[] = { diff --git a/Makefile.am b/Makefile.am index 600f2afc..0c3b68c0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -56,14 +56,14 @@ myhtopsources = \ ScreenManager.c \ Settings.c \ SignalsPanel.c \ - StringUtils.c \ SwapMeter.c \ TasksMeter.c \ TraceScreen.c \ UptimeMeter.c \ UsersTable.c \ Vector.c \ - XAlloc.c + XAlloc.c \ + XUtils.c myhtopheaders = \ Action.h \ @@ -108,14 +108,14 @@ myhtopheaders = \ ScreenManager.h \ Settings.h \ SignalsPanel.h \ - StringUtils.h \ SwapMeter.h \ TasksMeter.h \ TraceScreen.h \ UptimeMeter.h \ UsersTable.h \ Vector.h \ - XAlloc.h + XAlloc.h \ + XUtils.h # Linux # ----- diff --git a/Meter.c b/Meter.c index 3edfb233..154a5a64 100644 --- a/Meter.c +++ b/Meter.c @@ -10,8 +10,8 @@ in the source distribution for its full text. #include "RichString.h" #include "Object.h" #include "CRT.h" -#include "StringUtils.h" #include "Settings.h" +#include "XUtils.h" #include #include diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index 1973cc45..8e099bbe 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -10,8 +10,8 @@ in the source distribution for its full text. #include "CRT.h" #include "ProcessList.h" #include "IncSet.h" -#include "StringUtils.h" #include "FunctionBar.h" +#include "XUtils.h" #include #include diff --git a/Panel.c b/Panel.c index 06a15c6b..76e45d6e 100644 --- a/Panel.c +++ b/Panel.c @@ -10,7 +10,7 @@ in the source distribution for its full text. #include "CRT.h" #include "RichString.h" #include "ListItem.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include diff --git a/Process.c b/Process.c index 43a4c47e..147caee6 100644 --- a/Process.c +++ b/Process.c @@ -12,9 +12,9 @@ in the source distribution for its full text. #include "config.h" #include "CRT.h" -#include "StringUtils.h" #include "RichString.h" #include "Platform.h" +#include "XUtils.h" #include #include diff --git a/ProcessList.c b/ProcessList.c index 1b364cfc..b7445431 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -6,10 +6,10 @@ in the source distribution for its full text. */ #include "ProcessList.h" -#include "Platform.h" #include "CRT.h" -#include "StringUtils.h" +#include "Platform.h" +#include "XUtils.h" #include #include diff --git a/Settings.c b/Settings.c index 7a90ec47..fd623ad8 100644 --- a/Settings.c +++ b/Settings.c @@ -6,11 +6,11 @@ in the source distribution for its full text. */ #include "Settings.h" -#include "Platform.h" -#include "StringUtils.h" -#include "Vector.h" #include "CRT.h" +#include "Platform.h" +#include "Vector.h" +#include "XUtils.h" #include #include diff --git a/SignalsPanel.c b/SignalsPanel.c index e15e6c8d..0ebe16d3 100644 --- a/SignalsPanel.c +++ b/SignalsPanel.c @@ -16,7 +16,7 @@ in the source distribution for its full text. #include "ListItem.h" #include "Platform.h" #include "RichString.h" -#include "StringUtils.h" +#include "XUtils.h" Panel* SignalsPanel_new() { diff --git a/StringUtils.c b/StringUtils.c deleted file mode 100644 index 4eb76968..00000000 --- a/StringUtils.c +++ /dev/null @@ -1,179 +0,0 @@ -/* -htop - StringUtils.c -(C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include "config.h" - -#include "StringUtils.h" - -#include -#include -#include -#include - -#include "XAlloc.h" - - -char* String_cat(const char* s1, const char* s2) { - int l1 = strlen(s1); - int l2 = strlen(s2); - char* out = xMalloc(l1 + l2 + 1); - memcpy(out, s1, l1); - memcpy(out+l1, s2, l2+1); - out[l1 + l2] = '\0'; - return out; -} - -char* String_trim(const char* in) { - while (in[0] == ' ' || in[0] == '\t' || in[0] == '\n') { - in++; - } - int len = strlen(in); - while (len > 0 && (in[len-1] == ' ' || in[len-1] == '\t' || in[len-1] == '\n')) { - len--; - } - char* out = xMalloc(len+1); - strncpy(out, in, len); - out[len] = '\0'; - return out; -} - -inline int String_eq(const char* s1, const char* s2) { - if (s1 == NULL || s2 == NULL) { - if (s1 == NULL && s2 == NULL) - return 1; - else - return 0; - } - return (strcmp(s1, s2) == 0); -} - -char** String_split(const char* s, char sep, int* n) { - *n = 0; - const int rate = 10; - char** out = xCalloc(rate, sizeof(char*)); - int ctr = 0; - int blocks = rate; - char* where; - while ((where = strchr(s, sep)) != NULL) { - int size = where - s; - char* token = xMalloc(size + 1); - strncpy(token, s, size); - token[size] = '\0'; - out[ctr] = token; - ctr++; - if (ctr == blocks) { - blocks += rate; - out = (char**) xRealloc(out, sizeof(char*) * blocks); - } - s += size + 1; - } - if (s[0] != '\0') { - out[ctr] = xStrdup(s); - ctr++; - } - out = xRealloc(out, sizeof(char*) * (ctr + 1)); - out[ctr] = NULL; - *n = ctr; - return out; -} - -void String_freeArray(char** s) { - if (!s) { - return; - } - for (int i = 0; s[i] != NULL; i++) { - free(s[i]); - } - free(s); -} - -char* String_getToken(const char* line, const unsigned short int numMatch) { - const unsigned short int len = strlen(line); - char inWord = 0; - unsigned short int count = 0; - char match[50]; - - unsigned short int foundCount = 0; - - for (unsigned short int i = 0; i < len; i++) { - char lastState = inWord; - inWord = line[i] == ' ' ? 0:1; - - if (lastState == 0 && inWord == 1) - count++; - - if(inWord == 1){ - if (count == numMatch && line[i] != ' ' && line[i] != '\0' && line[i] != '\n' && line[i] != (char)EOF) { - match[foundCount] = line[i]; - foundCount++; - } - } - } - - match[foundCount] = '\0'; - return xStrdup(match); -} - -char* String_readLine(FILE* fd) { - const int step = 1024; - int bufSize = step; - char* buffer = xMalloc(step + 1); - char* at = buffer; - for (;;) { - char* ok = fgets(at, step + 1, fd); - if (!ok) { - free(buffer); - return NULL; - } - char* newLine = strrchr(at, '\n'); - if (newLine) { - *newLine = '\0'; - return buffer; - } else { - if (feof(fd)) { - return buffer; - } - } - bufSize += step; - buffer = xRealloc(buffer, bufSize + 1); - at = buffer + bufSize - step; - } -} - -int xAsprintf(char** strp, const char* fmt, ...) { - va_list vl; - va_start(vl, fmt); - int r = vasprintf(strp, fmt, vl); - va_end(vl); - - if (r < 0 || !*strp) { - fail(); - } - - return r; -} - -int xSnprintf(char* buf, int len, const char* fmt, ...) { - va_list vl; - va_start(vl, fmt); - int n = vsnprintf(buf, len, fmt, vl); - va_end(vl); - - if (n < 0 || n >= len) { - fail(); - } - - return n; -} - -char* xStrdup(const char* str) { - char* data = strdup(str); - if (!data) { - fail(); - } - return data; -} diff --git a/StringUtils.h b/StringUtils.h deleted file mode 100644 index 5a1af9ad..00000000 --- a/StringUtils.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef HEADER_StringUtils -#define HEADER_StringUtils -/* -htop - StringUtils.h -(C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPLv2, see the COPYING file -in the source distribution for its full text. -*/ - -#include - -#include "Macros.h" - - -#define String_startsWith(s, match) (strncmp((s),(match),strlen(match)) == 0) -#define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL) - -/* - * String_startsWith gives better performance if strlen(match) can be computed - * at compile time (e.g. when they are immutable string literals). :) - */ - -char* String_cat(const char* s1, const char* s2); - -char* String_trim(const char* in); - -int String_eq(const char* s1, const char* s2); - -char** String_split(const char* s, char sep, int* n); - -void String_freeArray(char** s); - -char* String_getToken(const char* line, const unsigned short int numMatch); - -char* String_readLine(FILE* fd); - -ATTR_FORMAT(printf, 2, 3) -int xAsprintf(char **strp, const char* fmt, ...); - -ATTR_FORMAT(printf, 3, 4) -int xSnprintf(char *buf, int len, const char* fmt, ...); - -char* xStrdup(const char* str) ATTR_NONNULL; - -#endif diff --git a/TasksMeter.c b/TasksMeter.c index ef7e4964..a13766ed 100644 --- a/TasksMeter.c +++ b/TasksMeter.c @@ -9,7 +9,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" static const int TasksMeter_attributes[] = { diff --git a/TraceScreen.c b/TraceScreen.c index 2956b569..314efc93 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -11,8 +11,8 @@ in the source distribution for its full text. #include "ProcessList.h" #include "ListItem.h" #include "IncSet.h" -#include "StringUtils.h" #include "FunctionBar.h" +#include "XUtils.h" #include #include diff --git a/UptimeMeter.c b/UptimeMeter.c index c8e511f1..1011aa10 100644 --- a/UptimeMeter.c +++ b/UptimeMeter.c @@ -9,7 +9,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" static const int UptimeMeter_attributes[] = { diff --git a/UsersTable.c b/UsersTable.c index 208fc8d8..e37c9038 100644 --- a/UsersTable.c +++ b/UsersTable.c @@ -17,8 +17,8 @@ in the source distribution for its full text. #include #include -#include "StringUtils.h" #include "XAlloc.h" +#include "XUtils.h" UsersTable* UsersTable_new() { diff --git a/XUtils.c b/XUtils.c new file mode 100644 index 00000000..9228c5e8 --- /dev/null +++ b/XUtils.c @@ -0,0 +1,179 @@ +/* +htop - StringUtils.c +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPLv2, see the COPYING file +in the source distribution for its full text. +*/ + +#include "config.h" + +#include "XUtils.h" + +#include +#include +#include +#include + +#include "XAlloc.h" + + +char* String_cat(const char* s1, const char* s2) { + int l1 = strlen(s1); + int l2 = strlen(s2); + char* out = xMalloc(l1 + l2 + 1); + memcpy(out, s1, l1); + memcpy(out+l1, s2, l2+1); + out[l1 + l2] = '\0'; + return out; +} + +char* String_trim(const char* in) { + while (in[0] == ' ' || in[0] == '\t' || in[0] == '\n') { + in++; + } + int len = strlen(in); + while (len > 0 && (in[len-1] == ' ' || in[len-1] == '\t' || in[len-1] == '\n')) { + len--; + } + char* out = xMalloc(len+1); + strncpy(out, in, len); + out[len] = '\0'; + return out; +} + +inline int String_eq(const char* s1, const char* s2) { + if (s1 == NULL || s2 == NULL) { + if (s1 == NULL && s2 == NULL) + return 1; + else + return 0; + } + return (strcmp(s1, s2) == 0); +} + +char** String_split(const char* s, char sep, int* n) { + *n = 0; + const int rate = 10; + char** out = xCalloc(rate, sizeof(char*)); + int ctr = 0; + int blocks = rate; + char* where; + while ((where = strchr(s, sep)) != NULL) { + int size = where - s; + char* token = xMalloc(size + 1); + strncpy(token, s, size); + token[size] = '\0'; + out[ctr] = token; + ctr++; + if (ctr == blocks) { + blocks += rate; + out = (char**) xRealloc(out, sizeof(char*) * blocks); + } + s += size + 1; + } + if (s[0] != '\0') { + out[ctr] = xStrdup(s); + ctr++; + } + out = xRealloc(out, sizeof(char*) * (ctr + 1)); + out[ctr] = NULL; + *n = ctr; + return out; +} + +void String_freeArray(char** s) { + if (!s) { + return; + } + for (int i = 0; s[i] != NULL; i++) { + free(s[i]); + } + free(s); +} + +char* String_getToken(const char* line, const unsigned short int numMatch) { + const unsigned short int len = strlen(line); + char inWord = 0; + unsigned short int count = 0; + char match[50]; + + unsigned short int foundCount = 0; + + for (unsigned short int i = 0; i < len; i++) { + char lastState = inWord; + inWord = line[i] == ' ' ? 0:1; + + if (lastState == 0 && inWord == 1) + count++; + + if(inWord == 1){ + if (count == numMatch && line[i] != ' ' && line[i] != '\0' && line[i] != '\n' && line[i] != (char)EOF) { + match[foundCount] = line[i]; + foundCount++; + } + } + } + + match[foundCount] = '\0'; + return xStrdup(match); +} + +char* String_readLine(FILE* fd) { + const int step = 1024; + int bufSize = step; + char* buffer = xMalloc(step + 1); + char* at = buffer; + for (;;) { + char* ok = fgets(at, step + 1, fd); + if (!ok) { + free(buffer); + return NULL; + } + char* newLine = strrchr(at, '\n'); + if (newLine) { + *newLine = '\0'; + return buffer; + } else { + if (feof(fd)) { + return buffer; + } + } + bufSize += step; + buffer = xRealloc(buffer, bufSize + 1); + at = buffer + bufSize - step; + } +} + +int xAsprintf(char** strp, const char* fmt, ...) { + va_list vl; + va_start(vl, fmt); + int r = vasprintf(strp, fmt, vl); + va_end(vl); + + if (r < 0 || !*strp) { + fail(); + } + + return r; +} + +int xSnprintf(char* buf, int len, const char* fmt, ...) { + va_list vl; + va_start(vl, fmt); + int n = vsnprintf(buf, len, fmt, vl); + va_end(vl); + + if (n < 0 || n >= len) { + fail(); + } + + return n; +} + +char* xStrdup(const char* str) { + char* data = strdup(str); + if (!data) { + fail(); + } + return data; +} diff --git a/XUtils.h b/XUtils.h new file mode 100644 index 00000000..4880d1a1 --- /dev/null +++ b/XUtils.h @@ -0,0 +1,45 @@ +#ifndef HEADER_XUtils +#define HEADER_XUtils +/* +htop - StringUtils.h +(C) 2004-2011 Hisham H. Muhammad +Released under the GNU GPLv2, see the COPYING file +in the source distribution for its full text. +*/ + +#include + +#include "Macros.h" + + +#define String_startsWith(s, match) (strncmp((s),(match),strlen(match)) == 0) +#define String_contains_i(s1, s2) (strcasestr(s1, s2) != NULL) + +/* + * String_startsWith gives better performance if strlen(match) can be computed + * at compile time (e.g. when they are immutable string literals). :) + */ + +char* String_cat(const char* s1, const char* s2); + +char* String_trim(const char* in); + +int String_eq(const char* s1, const char* s2); + +char** String_split(const char* s, char sep, int* n); + +void String_freeArray(char** s); + +char* String_getToken(const char* line, const unsigned short int numMatch); + +char* String_readLine(FILE* fd); + +ATTR_FORMAT(printf, 2, 3) +int xAsprintf(char **strp, const char* fmt, ...); + +ATTR_FORMAT(printf, 3, 4) +int xSnprintf(char *buf, int len, const char* fmt, ...); + +char* xStrdup(const char* str) ATTR_NONNULL; + +#endif diff --git a/htop.c b/htop.c index 9ce966f7..39aeec1a 100644 --- a/htop.c +++ b/htop.c @@ -16,9 +16,9 @@ in the source distribution for its full text. #include "ProcessList.h" #include "ScreenManager.h" #include "Settings.h" -#include "StringUtils.h" #include "UsersTable.h" #include "Platform.h" +#include "XUtils.h" #include #include diff --git a/linux/Battery.c b/linux/Battery.c index 14fcc90b..faf4064c 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -7,11 +7,10 @@ in the source distribution for its full text. Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat.com). */ +#include "config.h" // IWYU pragma: keep + #include "Battery.h" -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif #include #include #include @@ -20,7 +19,9 @@ Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat #include #include #include -#include "StringUtils.h" + +#include "XUtils.h" + #define SYS_POWERSUPPLY_DIR "/sys/class/power_supply" diff --git a/linux/IOPriorityPanel.c b/linux/IOPriorityPanel.c index ce7f01e4..cc1b3916 100644 --- a/linux/IOPriorityPanel.c +++ b/linux/IOPriorityPanel.c @@ -7,7 +7,7 @@ in the source distribution for its full text. #include "IOPriorityPanel.h" -#include "StringUtils.h" +#include "XUtils.h" Panel* IOPriorityPanel_new(IOPriority currPrio) { diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 9e3c2f89..75900b5a 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -11,7 +11,7 @@ in the source distribution for its full text. #include "LinuxProcess.h" #include "CRT.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include @@ -20,6 +20,7 @@ in the source distribution for its full text. #include #include + /* semi-global */ long long btime; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 6dcc5e5a..57fab842 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -8,7 +8,8 @@ in the source distribution for its full text. #include "LinuxProcessList.h" #include "LinuxProcess.h" #include "CRT.h" -#include "StringUtils.h" +#include "XUtils.h" + #include #include #include diff --git a/linux/Platform.c b/linux/Platform.c index 6a3ffab2..feb6b6cf 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -30,7 +30,7 @@ in the source distribution for its full text. #include "zfs/ZfsCompressedArcMeter.h" #include "LinuxProcess.h" #include "SELinuxMeter.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include diff --git a/linux/PressureStallMeter.c b/linux/PressureStallMeter.c index 518e66c8..4733415f 100644 --- a/linux/PressureStallMeter.c +++ b/linux/PressureStallMeter.c @@ -12,7 +12,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" static const int PressureStallMeter_attributes[] = { diff --git a/zfs/ZfsCompressedArcMeter.c b/zfs/ZfsCompressedArcMeter.c index def88d02..0153fccb 100644 --- a/zfs/ZfsCompressedArcMeter.c +++ b/zfs/ZfsCompressedArcMeter.c @@ -10,7 +10,7 @@ in the source distribution for its full text. #include "CRT.h" #include "Platform.h" -#include "StringUtils.h" +#include "XUtils.h" #include #include -- cgit v1.2.3