X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=nssm.cpp;h=43faa4143278f7d1d5a8c11d8cf540f345027892;hb=4b7c8eec508cc90d80355fad5df80163a181ddcb;hp=08b94320089fed2f3111081abd6dfc48e6a820e0;hpb=4440946eccf1cb14e16f8d29c54fb4acecbd44ff;p=nssm.git diff --git a/nssm.cpp b/nssm.cpp index 08b9432..43faa41 100644 --- a/nssm.cpp +++ b/nssm.cpp @@ -1,54 +1,144 @@ #include "nssm.h" -/* String function */ -int str_equiv(const char *a, const char *b) { - int i; - for (i = 0; ; i++) { - if (tolower(b[i]) != tolower(a[i])) return 0; - if (! a[i]) return 1; - } +extern unsigned long tls_index; +extern bool is_admin; +extern imports_t imports; + +/* Are two strings case-insensitively equivalent? */ +int str_equiv(const TCHAR *a, const TCHAR *b) { + size_t len = _tcslen(a); + if (_tcslen(b) != len) return 0; + if (_tcsnicmp(a, b, len)) return 0; + return 1; +} + +/* Convert a string to a number. */ +int str_number(const TCHAR *string, unsigned long *number) { + if (! string) return 1; + + TCHAR *bogus; + *number = _tcstoul(string, &bogus, 0); + if (*bogus) return 2; + + return 0; +} + +/* Remove basename of a path. */ +void strip_basename(TCHAR *buffer) { + size_t len = _tcslen(buffer); + size_t i; + for (i = len; i && buffer[i] != _T('\\') && buffer[i] != _T('/'); i--); + /* X:\ is OK. */ + if (i && buffer[i - 1] == _T(':')) i++; + buffer[i] = _T('\0'); } /* How to use me correctly */ int usage(int ret) { - fprintf(stderr, "NSSM: The non-sucking service manager\n"); - fprintf(stderr, "Version %s, %s\n", NSSM_VERSION, NSSM_DATE); - fprintf(stderr, "Usage: nssm