if (!ptrn) return;
data = (void*)((uintptr_t)ptrn-sizeof(struct memblock_t));
info = (struct memblock_t*)data;
-
+
util_debug("MEM", "released: % 8u (bytes) address 0x%08X @ %s:%u\n", info->byte, data, file, line);
mem_db += info->byte;
mem_dt++;
return util_strdup(s);
}
-/*
- * Remove newline from a string (if it exists). This is
- * done pointer wise instead of strlen(), and an array
- * access.
- */
-char *util_strrnl(const char *src) {
- char *cpy = NULL;
-
- if (src) {
- cpy = (char*)src;
- while (*cpy && *cpy != '\n')
- cpy++;
-
- *cpy = '\0';
- }
- return (char*)src;
-}
-
-/*
- * Removes any whitespace prefixed on a string by moving
- * skipping past it, and stroing the skip distance, so
- * the string can later be freed (if it was allocated)
- */
-char *util_strsws(const char *skip) {
- size_t size = 0;
- if (!skip)
- return NULL;
-
- while (*skip == ' ' || *skip == '\t')
- skip++,size++;
- return util_strdup(skip-size);
-}
-
/*
* Returns true if string is all uppercase, otherwise
* it returns false.
return true;
}
+bool util_strncmpexact(const char *src, const char *ned, size_t len) {
+ return (!strncmp(src, ned, len) && !src[len]);
+}
+
void util_debug(const char *area, const char *ms, ...) {
va_list va;
if (!opts_debug)
*pos = '\0';
return (ret = pos - *lineptr);
}
+
+size_t util_strtocmd(const char *in, char *out, size_t outsz) {
+ size_t sz = 1;
+ for (; *in && sz < outsz; ++in, ++out, ++sz) {
+ if (*in == '-')
+ *out = '_';
+ else if (isalpha(*in) && !isupper(*in))
+ *out = *in + 'A' - 'a';
+ else
+ *out = *in;
+ }
+ *out = 0;
+ return sz-1;
+}
+
+size_t util_strtononcmd(const char *in, char *out, size_t outsz) {
+ size_t sz = 1;
+ for (; *in && sz < outsz; ++in, ++out, ++sz) {
+ if (*in == '_')
+ *out = '-';
+ else if (isalpha(*in) && isupper(*in))
+ *out = *in + 'a' - 'A';
+ else
+ *out = *in;
+ }
+ *out = 0;
+ return sz-1;
+}