aboutsummaryrefslogtreecommitdiff
path: root/test.c
blob: fb71a585558ee2cd97741ab0d40616b2c350d6d5 (plain)
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
#include <u.h>
#include <libc.h>
#include "roman.h"

void
usage(void)
{
	fprint(2, "usage: %s [ -dr ] number\n", argv0);
	exits("usage");
}

void
main(int argc, char *argv[])
{
	int decimal;
	char *roman, buf[512];

	decimal = -1;
	roman = nil;

	ARGBEGIN{
	case 'd':
		roman = EARGF(usage());
		break;
	case 'r':
		decimal = strtol(EARGF(usage()), nil, 10);
		break;
	}ARGEND;
	if(argc != 0)
		usage();

	if(decimal >= 0){
		if(dectoroman(decimal, buf, sizeof buf) < 0)
			sysfatal("dectoroman: %r");
		print("%s\n", buf);
	}else if(roman != nil){
		if((decimal = romantodec(roman)) < 0)
			sysfatal("romantodec: %r");
		print("%d\n", decimal);
	}else
		usage();

	exits(nil);
}