new tool functions

This commit is contained in:
ac-stef
2015-02-08 17:39:15 +01:00
parent af70d5c069
commit 348f640507
2 changed files with 25 additions and 0 deletions
+13
View File
@@ -422,6 +422,19 @@ const char *hiddenpwd(const char *pwd, int showchars)
for(int i = (int)strlen(text) - 1; i >= sc; i--) text[i] = '*';
return text;
}
int getlistindex(const char *key, const char *list[], bool acceptnumeric, int deflt)
{
int max = 0;
while(list[max][0]) if(!strcasecmp(key, list[max])) return max; else max++;
if(acceptnumeric && isdigit(key[0]))
{
int i = (int)strtol(key, NULL, 0);
if(i >= 0 && i < max) return i;
}
return deflt;
}
//////////////// geometry utils ////////////////
static inline float det2x2(float a, float b, float c, float d) { return a*d - b*c; }
+12
View File
@@ -586,6 +586,16 @@ static inline bool htcmp(const char *x, const char *y)
return !strcmp(x, y);
}
static inline uint hthash(const uchar *key)
{
return *((uint *)key);
}
static inline bool htcmp(const uchar *x, const uchar *y) // assume "uchar *" points to 32byte public keys
{
return !memcmp(x, y, 32);
}
static inline uint hthash(int key)
{
return key;
@@ -832,6 +842,7 @@ inline char *newstring(const char *s) { return newstring(s, strlen(s))
inline char *newstringbuf() { return newstring(MAXSTRLEN-1); }
inline char *newstringbuf(const char *s) { return newstring(s, MAXSTRLEN-1); }
inline void delstring(const char *s) { delete[] (char *)s; }
#define DELSTRING(s) if(s) { delstring(s); s = NULL; }
#ifndef STANDALONE
inline const char *_gettext(const char *msgid)
@@ -976,6 +987,7 @@ extern int cmpiprange(const struct iprange *a, const struct iprange *b);
extern int cmpipmatch(const struct iprange *a, const struct iprange *b);
extern int cvecprintf(vector<char> &v, const char *s, ...);
extern const char *hiddenpwd(const char *pwd, int showchars = 0);
extern int getlistindex(const char *key, const char *list[], bool acceptnumeric = true, int deflt = -1);
#if defined(WIN32) && !defined(_DEBUG) && !defined(__GNUC__)
extern void stackdumper(unsigned int type, EXCEPTION_POINTERS *ep);