summaryrefslogtreecommitdiff
path: root/appl/cmd/irtest.b
blob: 3d0260c7251ed8b525a32625240e8613bd870719 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
implement Irtest;

include "sys.m";
	sys: Sys;
include "draw.m";
include "ir.m";
	ir: Ir;

Irtest: module
{
	init:	fn(nil: ref Draw->Context, argv: list of string);
};

stderr: ref Sys->FD;

init(nil: ref Draw->Context, nil: list of string)
{
	x := chan of int;
	p := chan of int;

	sys = load Sys Sys->PATH;
	stderr = sys->fildes(2);

	ir = load Ir Ir->PATH;
	if(ir == nil)
		ir = load Ir Ir->SIMPATH;
	if(ir == nil) {
		sys->fprint(stderr, "load ir: %r\n");
		return;
	}

	if(ir->init(x,p) != 0) {
		sys->fprint(stderr, "Ir->init: %r\n");
		return;
	}
	<-p;

	names := array[] of {
		"Zero",
		"One",
		"Two",
		"Three",
		"Four",
		"Five",
		"Six",
		"Seven",
		"Eight",
		"Nine",
		"ChanUP",
		"ChanDN",
		"VolUP",
		"VolDN",
		"FF",
		"Rew",
		"Up",
		"Dn",
		"Select",
		"Power",
	};

	while((c := <-x) != Ir->EOF){
		c = ir->translate(c);
		if(c == ir->Error)
			sys->print("Error\n");
		else if(c >= len names)
			sys->print("unknown %d\n", c);
		else
			sys->print("%s\n", names[c]);
	}	
}