-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathReckon.c
189 lines (161 loc) · 4.88 KB
/
Reckon.c
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/**
*
* Copyright (c) 2010-2015 Voidware Ltd. All Rights Reserved.
*
* This file contains Original Code and/or Modifications of Original Code as
* defined in and that are subject to the Voidware Public Source Licence version
* 1.0 (the 'Licence'). You may not use this file except in compliance with the
* Licence or with expressly written permission from Voidware. Please obtain a
* copy of the Licence at http://www.voidware.com/legal/vpsl1.txt and read it
* before using this file.
*
* The Original Code and all software distributed under the Licence are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
* OR IMPLIED, AND VOIDWARE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING
* WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
*
* Please see the Licence for the specific language governing rights and
* limitations under the Licence.
*
*/
#include "fxlib.h"
#include "stdlib.h"
#include "stdio.h"
#include "defs.h"
#include "utils.h"
#include "common.h"
static int GetLine(char* buf, unsigned int size)
{
unsigned int k;
char* p = buf;
int i;
const KeyWord* kw;
char* q;
while (p - buf < size-1)
{
k = GetKeyNonblocking(1, 0); // block
if (k == KEY_CTRL_HELP || k == KEY_CTRL_F1)
{
displayInfo();
return -1;
}
if (k == KEY_CTRL_EXE) break;
if (k == KEY_CTRL_AC || k == KEY_CTRL_OPTN)
{
return k; // escape
}
// translate manually, since different for RPN.
if (k == KEY_CHAR_PMINUS) k = '-';
k = translateKey(k);
// check the key words expansion
kw = findExpandKey(k, 1); // ALG mode
if (kw)
{
const char* s = kw->keyword;
while (*s && p - buf < size-1)
{
*p = *s++;
printc(p);
++p;
}
k = 0;
}
if (k == KEY_CTRL_DEL)
{
// delete key
if (p > buf)
{
*--p = '\b';
printc(p);
if (p > buf && ESC_CHAR(p[-1]))
--p;
}
}
else if (k > 0)
{
q = p;
if (k > 0xff) // extended
*p++ = k >> 8;
*p++ = k;
printc(q);
}
}
*p = 0;
return 0;
}
extern void eval(const char* exp, char** const result);
extern void eval_init();
extern void eval_end();
extern void do_rpn();
//****************************************************************************
// AddIn_main (Sample program main function)
//
// param : isAppli : 1 = This application is launched by MAIN MENU.
// : 0 = This application is launched by a strip in eACT application.
//
// OptionNum : Strip number (0~3)
// (This parameter is only used when isAppli parameter is 0.)
//
// retval : 1 = No error / 0 = Error
//
//****************************************************************************
int AddIn_main(int isAppli, unsigned short OptionNum)
{
unsigned int key;
static char buf[64];
const char* res;
eval_init();
Bdisp_AllClr_DDVRAM();
AC();
print("Reckon " VERSION);
newline();
for (;;)
{
print("> ");
key = GetLine(buf, sizeof(buf));
if (!key)
{
eval(buf, &res);
newline();
print(res);
newline();
}
else
{
if (key == KEY_CTRL_OPTN)
{
do_rpn();
}
AC();
}
}
eval_end();
return 1;
}
//****************************************************************************
//************** ****************
//************** Notice! ****************
//************** ****************
//************** Please do not change the following source. ****************
//************** ****************
//****************************************************************************
#pragma section _BR_Size
unsigned long BR_Size;
#pragma section
#pragma section _TOP
//****************************************************************************
// InitializeSystem
//
// param : isAppli : 1 = Application / 0 = eActivity
// OptionNum : Option Number (only eActivity)
//
// retval : 1 = No error / 0 = Error
//
//****************************************************************************
int InitializeSystem(int isAppli, unsigned short OptionNum)
{
return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
}
#pragma section