aboutsummaryrefslogtreecommitdiff
path: root/get_address.c
blob: cc503ad717cdaf2c83ee536b239473ea4f6b9348 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;
}