diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-06-05 17:25:41 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-06-05 17:25:41 +0000 |
commit | d2717df5ef65c00bb43e1b775c7846af1625848a (patch) | |
tree | ab4a67b2036f74f5df14e8a99199ca49237097f2 /src/command_parse.cpp | |
parent | adf372651c4c2b8db07e9a29ed7c9d5132737ee8 (diff) |
InspIRCd: Now with even MORE leet.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@7240 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/command_parse.cpp')
-rw-r--r-- | src/command_parse.cpp | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 68b8b0bda..c7f89e03b 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -67,38 +67,42 @@ std::string InspIRCd::TimeString(time_t curtime) */ long InspIRCd::Duration(const char* str) { - char n_field[MAXBUF]; - const char* maxsize = n_field + MAXBUF; + unsigned char multiplier = 0; long total = 0; - char* field_ptr = n_field; - *n_field = 0; + long times = 1; + long subtotal = 0; /* Iterate each item in the string, looking for number or multiplier */ - for (const char* i = str; *i; i++) + for (const char* i = str + strlen(str) - 1; i >= str; --i) { /* Found a number, queue it onto the current number */ - if ((*i >= '0') && (*i <= '9') && (field_ptr < maxsize)) - *field_ptr++ = *i; + if ((*i >= '0') && (*i <= '9')) + { + subtotal = subtotal + ((*i - '0') * times); + times = times * 10; + } else { /* Found something thats not a number, find out how much * it multiplies the built up number by, multiply the total * and reset the built up number. */ - *field_ptr = 0; - field_ptr = n_field; - total += atoi(n_field) * duration_multi[(const unsigned char)*i]; - *n_field = 0; + if (subtotal) + total += subtotal * duration_multi[multiplier]; + + /* Next subtotal please */ + subtotal = 0; + multiplier = *i; + times = 1; } } - /* Any trailing values built up are treated as raw seconds */ - if (*n_field) + if (multiplier) { - *field_ptr = 0; - total += atoi(n_field); + total += subtotal * duration_multi[multiplier]; + subtotal = 0; } - - return total; + /* Any trailing values built up are treated as raw seconds */ + return total + subtotal; } /* LoopCall is used to call a command classes handler repeatedly based on the contents of a comma seperated list. |