annotate examples/calculator/main.c @ 121:76ba6fd61c7d

More bug of insert sort. elms[i] is over wrote by elms[i-1]. Save it to a local variable at start of loop iteration for elms[i].
author Thinker K.F. Li <thinker@branda.to>
date Sun, 14 Sep 2008 23:40:57 +0800
parents 565b55508c8d
children 17e97e92b76e
rev   line source
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <stdio.h>
108
565b55508c8d More dox
Thinker K.F. Li <thinker@branda.to>
parents: 94
diff changeset
2 #include <mb/mb.h>
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include "calculator_scr.h"
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
5 typedef struct _calc_data calc_data_t;
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
6 struct _calc_data {
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 X_MB_runtime_t *rt;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 calculator_scr_t *code;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 };
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 static struct {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 int c;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 int off;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 } tgt_list[] = {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 { 0, OFFSET(calculator_scr_t, but_0) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 { 1, OFFSET(calculator_scr_t, but_1) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17 { 2, OFFSET(calculator_scr_t, but_2) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 { 3, OFFSET(calculator_scr_t, but_3) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 { 4, OFFSET(calculator_scr_t, but_4) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 { 5, OFFSET(calculator_scr_t, but_5) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 { 6, OFFSET(calculator_scr_t, but_6) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 { 7, OFFSET(calculator_scr_t, but_7) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 { 8, OFFSET(calculator_scr_t, but_8) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 { 9, OFFSET(calculator_scr_t, but_9) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 { '+', OFFSET(calculator_scr_t, but_add) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 { '-', OFFSET(calculator_scr_t, but_minus) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 { '*', OFFSET(calculator_scr_t, but_mul) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 { '/', OFFSET(calculator_scr_t, but_div) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 { '=', OFFSET(calculator_scr_t, but_eq) },
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30 { 'c', OFFSET(calculator_scr_t, but_clr) }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 };
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 static int real_compute(int op, int v1, int v2) {
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
34 int r = v1;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 switch(op) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 case '+':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 r = v1 + v2;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 case '-':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 r = v1 - v2;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43 case '*':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 r = v1 * v2;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 case '/':
93
Thinker K.F. Li <thinker@branda.to>
parents: 92
diff changeset
47 r = v1;
89
90428161fc61 Prevent divide by zero error
Thinker K.F. Li <thinker@branda.to>
parents: 88
diff changeset
48 if(v2)
93
Thinker K.F. Li <thinker@branda.to>
parents: 92
diff changeset
49 r /= v2;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 break;
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
51 case 'n':
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
52 r = v2;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
53 break;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
54 case 'N':
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
55 break;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
58 return r;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
61 static void show_text(calc_data_t *calc_data, int num, int saved, int op,
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
62 const char *suffix) {
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
63 char buf[20];
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
65 sprintf(buf, "%d%s", num, suffix);
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
66 sh_text_set_text(calc_data->code->screen_text, buf);
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
67 rdman_shape_changed(calc_data->rt->rdman, calc_data->code->screen_text);
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
68
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
69 if(op == 'n')
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
70 sprintf(buf, "None");
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
71 else
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
72 sprintf(buf, "%d%c", saved, op);
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
73 sh_text_set_text(calc_data->code->saved_text, buf);
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
74 rdman_shape_changed(calc_data->rt->rdman, calc_data->code->saved_text);
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
77 static void compute(calc_data_t *calc_data, coord_t *tgt) {
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78 int i;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79 coord_t **coord_p;
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
80 static int valid_num = 0;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
81 static int factor = 1;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
82 static int num = 0;
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
83 static int op = 'n';
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
84 static int saved = 0;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
85 char buf[2] = " ";
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
86
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
87 for(i = 0; i < 16; i++) {
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
88 coord_p = (coord_t **)((void *)calc_data->code + tgt_list[i].off);
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
89 if(*coord_p == (void *)tgt)
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
90 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
91 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 if(i >= 16) return;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94 if(i < 10) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
95 num = num * 10 + i;
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
96 show_text(calc_data, num * factor, saved, op, "");
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
97 valid_num = 1;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
98 } else {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
99 switch(tgt_list[i].c) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
100 case 'c':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
101 saved = num = 0;
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
102 factor = 1;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
103 valid_num = 0;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
104 op = 'n';
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
105 show_text(calc_data, 0, saved, op, "");
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
106 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
107
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
108 case '-':
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
109 if(!valid_num) {
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
110 factor *= -1;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
111 valid_num = 1;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
112 break;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
113 }
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
114 case '+':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
115 case '*':
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
116 case '/':
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
117 saved = real_compute(op, saved, num * factor);
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
118 buf[0] = tgt_list[i].c;
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
119 show_text(calc_data, saved, saved, 'n', buf);
90
bd29780bf266 Reduce redundant code
Thinker K.F. Li <thinker@branda.to>
parents: 89
diff changeset
120 op = tgt_list[i].c;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
121 num = 0;
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
122 factor = 1;
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
123 valid_num = 0;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
124 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
125
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
126 case '=':
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
127 saved = real_compute(op, saved, num * factor);
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
128 show_text(calc_data, saved, 0, 'n', "");
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
129 num = 0;
92
3f619ae03678 Improve calcuator example program.
Thinker K.F. Li <thinker@branda.to>
parents: 90
diff changeset
130 op = 'N';
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
131 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
132 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
133 }
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
134 rdman_redraw_changed(calc_data->rt->rdman);
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
135 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
136
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
137 static void buttons_handler(event_t *evt, void *arg) {
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
138 calc_data_t *calc_data = (calc_data_t *)arg;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
139
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
140 switch(evt->type) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
141 case EVT_MOUSE_BUT_PRESS:
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
142 compute(calc_data, (coord_t *)evt->cur_tgt);
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
143 break;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
144 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
145 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
146
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
147 static void setup_observers(calc_data_t *calc_data) {
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
148 calculator_scr_t *calculator_scr;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
149 ob_factory_t *factory;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
150 subject_t *subject;
90
bd29780bf266 Reduce redundant code
Thinker K.F. Li <thinker@branda.to>
parents: 89
diff changeset
151 coord_t *coord;
bd29780bf266 Reduce redundant code
Thinker K.F. Li <thinker@branda.to>
parents: 89
diff changeset
152 int off;
bd29780bf266 Reduce redundant code
Thinker K.F. Li <thinker@branda.to>
parents: 89
diff changeset
153 int i;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
154
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
155 calculator_scr = calc_data->code;
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
156 factory = rdman_get_ob_factory(calc_data->rt->rdman);
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
157
90
bd29780bf266 Reduce redundant code
Thinker K.F. Li <thinker@branda.to>
parents: 89
diff changeset
158 for(i = 0; i < 16; i++) {
bd29780bf266 Reduce redundant code
Thinker K.F. Li <thinker@branda.to>
parents: 89
diff changeset
159 off = tgt_list[i].off;
93
Thinker K.F. Li <thinker@branda.to>
parents: 92
diff changeset
160 coord = OFF2TYPE(calculator_scr, off, coord_t *);
90
bd29780bf266 Reduce redundant code
Thinker K.F. Li <thinker@branda.to>
parents: 89
diff changeset
161 subject = coord_get_mouse_event(coord);
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
162 subject_add_observer(factory, subject, buttons_handler, calc_data);
90
bd29780bf266 Reduce redundant code
Thinker K.F. Li <thinker@branda.to>
parents: 89
diff changeset
163 }
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
164 }
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
165
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
166 int main(int argc, char * const argv[]) {
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
167 X_MB_runtime_t rt;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
168 calculator_scr_t *calculator_scr;
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
169 calc_data_t calc_data;
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
170 int r;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
171
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
172 r = X_MB_init(":0.0", 300, 400, &rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
173
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
174 calculator_scr = calculator_scr_new(rt.rdman);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
175
94
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
176 calc_data.rt = &rt;
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
177 calc_data.code = calculator_scr;
Thinker K.F. Li <thinker@branda.to>
parents: 93
diff changeset
178 setup_observers(&calc_data);
88
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
179
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
180 X_MB_handle_connection(&rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
181
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
182 calculator_scr_free(calculator_scr);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
183 X_MB_destroy(&rt);
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
184
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
185 return 0;
dd813dcc232c New example, calculator.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
186 }