Cleanup in elf.c with .bss section clean; adm command mounts cdrom instead of floppy...
[ZeXOS.git] / apps / zde / zcalc / main.c
blob45003804f9e5eecb404c92e49f2df607cb4f3c43
1 /*
2 * ZeX/OS
3 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <appcl.h>
22 int result;
23 int pos;
24 int mem;
25 char op;
27 void zcalc_draw ()
29 zgui_puts (10, 10, "ZCalc", 0);
31 char res[32];
32 sprintf (res, "= %d", result);
34 zgui_puts (10, 20, res, 0);
36 char btn[16];
38 btn[1] = zgui_button (10, 100, "1");
39 btn[2] = zgui_button (35, 100, "2");
40 btn[3] = zgui_button (60, 100, "3");
41 btn[12] = zgui_button (85, 100, "*");
43 btn[4] = zgui_button (10, 75, "4");
44 btn[5] = zgui_button (35, 75, "5");
45 btn[6] = zgui_button (60, 75, "6");
46 btn[13] = zgui_button (85, 75, "/");
48 btn[7] = zgui_button (10, 50, "7");
49 btn[8] = zgui_button (35, 50, "8");
50 btn[9] = zgui_button (60, 50, "9");
51 btn[15] = zgui_button (85, 50, "C");
53 btn[0] = zgui_button (10, 125, "0");
54 btn[10] = zgui_button (35, 125, "+");
55 btn[11] = zgui_button (60, 125, "-");
56 btn[14] = zgui_button (85, 125, "=");
58 int i;
59 for (i = 0; i < 10; i ++)
60 if (!btn[i]) {
61 result *= pos;
62 result += i;
63 pos = 10;
66 /* C */
67 if (!btn[15]) {
68 result = 0;
69 pos = 1;
70 mem = 0;
73 /* + */
74 if (!btn[10]) {
75 mem += result;
76 result = 0;
77 pos = 1;
78 op = '+';
81 /* - */
82 if (!btn[11]) {
83 if (mem)
84 mem -= result;
86 result = 0;
87 pos = 1;
88 op = '-';
91 /* * */
92 if (!btn[12]) {
93 if (mem)
94 mem *= result;
96 result = 0;
97 pos = 1;
98 op = '*';
101 /* / */
102 if (!btn[13]) {
103 if (mem)
104 mem /= result;
106 result = 0;
107 pos = 1;
108 op = '/';
111 /* = */
112 if (!btn[14]) {
113 switch (op) {
114 case '+':
115 mem += result;
116 result = mem;
117 break;
118 case '-':
119 mem -= result;
120 result = mem;
121 break;
122 case '*':
123 mem *= result;
124 result = mem;
125 break;
126 case '/':
127 mem /= result;
128 result = mem;
129 break;
132 mem = 0;
133 op = 0;
137 int main (int argc, char **argv)
139 int exit = 0;
141 result = 0;
142 pos = 1;
143 mem = 0;
144 op = 0;
146 if (zgui_init () == -1)
147 return -1;
149 zgui_resize (120, 200);
151 while (!exit) {
152 unsigned state = zgui_event ();
154 if (state & APPCL_STATE_REDRAW)
155 zcalc_draw ();
157 if (state & APPCL_STATE_EXIT)
158 exit = 1;
161 return zgui_exit ();