aboutsummaryrefslogtreecommitdiff
path: root/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test.c')
-rw-r--r--test.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/test.c b/test.c
new file mode 100644
index 0000000..fb71a58
--- /dev/null
+++ b/test.c
@@ -0,0 +1,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);
+}