X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=nssm.cpp;h=7eef69de8d4ca69df0c8c6fa47cc028e5b6c4e57;hb=c62455090e89f70865658c318d6e2ad491bc3647;hp=f412579aa9a463e4339dbac1b1761c15daf7aafb;hpb=167b3e74003ed8f2b61bda7037f31447c488c29b;p=nssm.git diff --git a/nssm.cpp b/nssm.cpp index f412579..7eef69d 100644 --- a/nssm.cpp +++ b/nssm.cpp @@ -1,53 +1,187 @@ #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, TCHAR **bogus) { + if (! string) return 1; + + *number = _tcstoul(string, bogus, 0); + if (**bogus) return 2; + + return 0; +} + +int str_number(const TCHAR *string, unsigned long *number) { + TCHAR *bogus; + return str_number(string, number, &bogus); +} + +/* 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