File: rax2.c

package info (click to toggle)
radare2 0.9.6-3.1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 17,496 kB
  • ctags: 45,959
  • sloc: ansic: 240,999; sh: 3,645; makefile: 2,520; python: 1,212; asm: 312; ruby: 214; awk: 209; perl: 188; lisp: 169; java: 23; xml: 17; php: 6
file content (44 lines) | stat: -rw-r--r-- 789 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* radare - LGPL - Copyright 2007-2012 pancake<nopcode.org> */

#include <r_userconf.h>
#include <r_util.h>

static int rax(const char *str) {
	ut64 n;
	if (*str=='q')
		return 0;
 	n = r_num_math(NULL, str);
	if (str[0]=='0'&&str[1]=='x')
		printf("%"PFMT64d"\n", n);
	else printf("0x%"PFMT64x"\n", n);
	return 1;
}

int main(int argc, char **argv)
{
	int i;
	char buf[1024];

	if (argc == 1) {
		while(!feof(stdin)) {
			fgets(buf, 1023, stdin);
			if (feof(stdin)) break;
			buf[strlen(buf)-1] = '\0';
			if (!rax(buf)) break;
		}
		return 0;
	}
	if (argv[1][0]=='-') {
		switch(argv[1][1]) {
		case 'h':
			printf("Usage: rax2 [-hV] [expression]\n");
			return 0;
		case 'V':
			printf("rax2 v"R2_VERSION"\n");
			return 0;
		}
	}
	for(i=1; i<argc; i++)
		rax( argv[i] );
	return 0;
}