diff options
Diffstat (limited to 'get_address.c')
-rw-r--r-- | get_address.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/get_address.c b/get_address.c new file mode 100644 index 0000000..cc503ad --- /dev/null +++ b/get_address.c @@ -0,0 +1,22 @@ +#include <stdio.h> + +int get_address(char *self, char *arg) { + unsigned int got; + + if(sscanf(arg, "0x%x", &got) != 1) + if(sscanf(arg, "$%x", &got) != 1) + if(sscanf(arg, "%d", &got) != 1) { + fprintf(stderr, "Invalid address '%s'\n", arg); + return -1; + } + + if(got >= 0x10000) { + if(self) fprintf(stderr, "%s: ", self); + fprintf(stderr, "Address '%s' not in range $0000-$FFFF\n", arg); + return -1; + } + + return (int)got; +} + + |