summaryrefslogtreecommitdiff
path: root/console.c
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2005-05-06 22:06:40 +0000
committerDarkvater <Darkvater@openttd.org>2005-05-06 22:06:40 +0000
commit1a9c87bfe42d2a880a06e7a8593542e3cb1c362a (patch)
treec1ca915c8e8133c139e44feca8584f5ed4846486 /console.c
parent5e4080b5470a5cc619ec989c89055404f2c5515b (diff)
downloadopenttd-1a9c87bfe42d2a880a06e7a8593542e3cb1c362a.tar.xz
(svn r2277) - Codechange: change sscanf() into stroul() Which Does The Right Thing tm. Thanks tron
Diffstat (limited to 'console.c')
-rw-r--r--console.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/console.c b/console.c
index 778be52e1..45db0f982 100644
--- a/console.c
+++ b/console.c
@@ -448,17 +448,19 @@ void IConsoleError(const char* string)
*/
bool GetArgumentInteger(uint32 *value, const char *arg)
{
- int result = sscanf(arg, "%u", value);
+ char *endptr;
- /* Hexadecimal numbers start with 0x, so at least the first number has been parsed */
- if (result == 1 && arg[0] == '0' && (arg[1] == 'x' || arg[1] == 'X'))
- result = sscanf(arg, "%x", value);
-
- if (result == 0 && (strcmp(arg, "on") == 0 || strcmp(arg, "true") == 0 )) {*value = 1; result = 1;}
-
- if (result == 0 && (strcmp(arg, "off") == 0 || strcmp(arg, "false") == 0)) {*value = 0; result = 1;}
+ if (strcmp(arg, "on") == 0 || strcmp(arg, "true") == 0) {
+ *value = 1;
+ return true;
+ }
+ if (strcmp(arg, "off") == 0 || strcmp(arg, "false") == 0) {
+ *value = 0;
+ return true;
+ }
- return !!result;
+ *value = strtoul(arg, &endptr, 0);
+ return (arg == endptr) ? false : true;
}
/**