Skip to content

Commit 6e2972f

Browse files
committed
UI: added text editing
1 parent d79eca0 commit 6e2972f

32 files changed

+3814
-358
lines changed

configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ function buildSDL() {
240240
BUILD_SUBDIRS="src/common src/platform/sdl"
241241
AC_SUBST(BUILD_SUBDIRS)
242242
(cd ide/android/assets && xxd -i main.bas > ../../../src/platform/sdl/main_bas.h)
243+
(cd documentation && g++ -o build_kwp build_kwp.cpp && ./build_kwp > ../src/ui/kwp.h)
243244
}
244245

245246
function buildTizen() {
@@ -277,6 +278,8 @@ function buildAndroid() {
277278

278279
TEST_DIR="src/platform/android"
279280
AC_SUBST(TEST_DIR)
281+
282+
(cd documentation && g++ -o build_kwp build_kwp.cpp && ./build_kwp > ../src/ui/kwp.h)
280283
}
281284

282285
function buildConsole() {

documentation/build_kwp.cpp

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
/**
2+
* builds the kwp.cxx (keyword tables)
3+
*/
4+
#include <stdio.h>
5+
#include <string.h>
6+
#include <ctype.h>
7+
#include <stdlib.h>
8+
#include <unistd.h>
9+
#include "../src/ui/strlib.h"
10+
11+
#define code_t int
12+
#define fcode_t int
13+
#define pcode_t int
14+
15+
struct keyword_s {
16+
char name[16];
17+
code_t code;
18+
};
19+
20+
struct opr_keyword_s {
21+
char name[16];
22+
code_t code;
23+
code_t opr;
24+
};
25+
26+
struct func_keyword_s {
27+
char name[16];
28+
fcode_t fcode;
29+
};
30+
31+
struct proc_keyword_s {
32+
char name[16];
33+
pcode_t pcode;
34+
};
35+
36+
struct spopr_keyword_s {
37+
char name[16];
38+
code_t code;
39+
};
40+
41+
42+
#include "../src/common/kw.h"
43+
#include "../src/languages/keywords.en.c"
44+
45+
struct HelpItem {
46+
char package[20];
47+
char keyword[20];
48+
char id[20];
49+
char signature[128];
50+
char help[1024];
51+
};
52+
53+
int compareHelpItem(const void *p1, const void *p2) {
54+
HelpItem **i1 = (HelpItem **)p1;
55+
HelpItem **i2 = (HelpItem **)p2;
56+
int result = strcasecmp((*i1)->package, (*i2)->package);
57+
if (result == 0) {
58+
result = strcasecmp((*i1)->keyword, (*i2)->keyword);
59+
}
60+
return result;
61+
}
62+
63+
bool isKeyword(const char *keyword) {
64+
bool result = false;
65+
66+
for (int i = 0; !result && keyword_table[i].name[0] != '\0'; i++) {
67+
if (strcasecmp(keyword_table[i].name, keyword) == 0) {
68+
result = true;
69+
}
70+
}
71+
72+
for (int i = 0; !result && proc_table[i].name[0] != '\0'; i++) {
73+
if (strcasecmp(proc_table[i].name, keyword) == 0) {
74+
result = true;
75+
}
76+
}
77+
78+
for (int i = 0; !result && func_table[i].name[0] != '\0'; i++) {
79+
if (strcasecmp(func_table[i].name, keyword) == 0) {
80+
result = true;
81+
}
82+
}
83+
return result;
84+
}
85+
86+
void logMissing(strlib::List<HelpItem *> *helpItems) {
87+
for (int i = 0; keyword_table[i].name[0] != '\0'; i++) {
88+
bool found = false;
89+
List_each(HelpItem *, it, *helpItems) {
90+
HelpItem *next = (*it);
91+
if (strcasecmp(keyword_table[i].name, next->keyword) == 0) {
92+
found = true;
93+
break;
94+
}
95+
}
96+
if (!found && keyword_table[i].name[0] != '$') {
97+
fprintf(stderr, "Missing KEYWORD doc: %s\n", keyword_table[i].name);
98+
}
99+
}
100+
for (int i = 0; proc_table[i].name[0] != '\0'; i++) {
101+
bool found = false;
102+
List_each(HelpItem *, it, *helpItems) {
103+
HelpItem *next = (*it);
104+
if (strcasecmp(proc_table[i].name, next->keyword) == 0) {
105+
found = true;
106+
break;
107+
}
108+
}
109+
if (!found) {
110+
fprintf(stderr, "Missing PROC doc: %s\n", proc_table[i].name);
111+
}
112+
}
113+
for (int i = 0; func_table[i].name[0] != '\0'; i++) {
114+
bool found = false;
115+
List_each(HelpItem *, it, *helpItems) {
116+
HelpItem *next = (*it);
117+
if (strcasecmp(func_table[i].name, next->keyword) == 0) {
118+
found = true;
119+
break;
120+
}
121+
}
122+
if (!found) {
123+
fprintf(stderr, "Missing FUNC doc: %s\n", func_table[i].name);
124+
}
125+
}
126+
}
127+
128+
bool readHelpReference(strlib::List<HelpItem *> *helpItems) {
129+
FILE *fp = fopen("sbasic_ref.csv", "r");
130+
if (!fp) {
131+
fprintf(stderr, "Failed to open sbasic_ref.csv");
132+
return false;
133+
}
134+
135+
char lineBuffer[2048];
136+
while (1) {
137+
if (fgets(lineBuffer, sizeof(lineBuffer), fp) == NULL) {
138+
break;
139+
}
140+
HelpItem *item = new HelpItem();
141+
int len = strlen(lineBuffer);
142+
int currentCol = 0;
143+
int start = 0;
144+
bool quoted = false;
145+
146+
for (int i = 0; i < len; i++) {
147+
if (lineBuffer[i] == '\"' && lineBuffer[i + 1] == '\"') {
148+
// change CSV escape to C escape "" -> \"
149+
lineBuffer[i] = '\\';
150+
i += 1;
151+
} else if (lineBuffer[i] == '\"') {
152+
quoted = !quoted;
153+
} else if (!quoted && (i + 1 == len || lineBuffer[i] == ',')) {
154+
int fieldLen = i - start;
155+
if (lineBuffer[start] == '\"') {
156+
start += 1;
157+
fieldLen -= 2;
158+
}
159+
switch (currentCol) {
160+
case 0:
161+
// package
162+
strncpy(item->package, lineBuffer + start, fieldLen);
163+
item->package[fieldLen] = '\0';
164+
break;
165+
case 1:
166+
// type
167+
break;
168+
case 2:
169+
// keyword
170+
strncpy(item->keyword, lineBuffer + start, fieldLen);
171+
item->keyword[fieldLen] = '\0';
172+
break;
173+
case 3:
174+
// nodeID
175+
strncpy(item->id, lineBuffer + start, fieldLen);
176+
item->id[fieldLen] = '\0';
177+
break;
178+
case 4:
179+
// signature
180+
strncpy(item->signature, lineBuffer + start, fieldLen);
181+
item->signature[fieldLen] = '\0';
182+
break;
183+
case 5:
184+
// text
185+
strncpy(item->help, lineBuffer + start, fieldLen);
186+
item->help[fieldLen] = '\0';
187+
break;
188+
}
189+
currentCol++;
190+
start = i + 1;
191+
}
192+
}
193+
if (isKeyword(item->keyword)) {
194+
helpItems->add(item);
195+
} else {
196+
fprintf(stderr, "OBSOLETE %s\n", item->keyword);
197+
}
198+
}
199+
fclose(fp);
200+
helpItems->sort(compareHelpItem);
201+
logMissing(helpItems);
202+
return true;
203+
}
204+
205+
int main(int argc, char *argv[]) {
206+
strlib::List<HelpItem *> helpItems;
207+
if (!readHelpReference(&helpItems)) {
208+
exit(1);
209+
}
210+
211+
fprintf(stdout, "/* automagicaly generated file */\n");
212+
fprintf(stdout, "struct KEYWORD_HELP {\n");
213+
fprintf(stdout, " const char *package;\n");
214+
fprintf(stdout, " const char *keyword;\n");
215+
fprintf(stdout, " const char *signature;\n");
216+
fprintf(stdout, " const char *help;\n");
217+
fprintf(stdout, "} keyword_help[] = {\n");
218+
List_each(HelpItem *, it, helpItems) {
219+
HelpItem *item = (*it);
220+
fprintf(stdout, "{\"%s\",\"%s\",\"%s\",\"%s\"},\n", item->package,
221+
item->keyword, item->signature, item->help);
222+
}
223+
fprintf(stdout, "};\n");
224+
fprintf(stdout, "const int keyword_help_len = %d;\n", helpItems.size());
225+
return 0;
226+
}

documentation/sbasic_ref.csv

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Console,command,BUTTON,523,"BUTTON x, y, w, h, variable, caption [,type]","Creat
2424
Console,command,CLS,524,"CLS ","Clears the screen."
2525
Console,command,DOFORM,525,"DOFORM FLAG|VAR","Runs the form created with the BUTTON and TEXT commands. Must be called from within a loop to keep the form active. Pass a control variable to receive the value of the selected or clicked form control. Pass 0 to close the form."
2626
Console,command,HTML,526,"HTML, [title,] [x,y,w,h]","Display HTML text."
27-
Console,command,INPUT,527,"INPUT [prompt,|;] var[, var [, ...]]","Reads from "keyboard" text and stores it to a variable."
27+
Console,command,INPUT,527,"INPUT [prompt,|;] var[, var [, ...]]","Reads from ""keyboard"" text and stores it to a variable."
2828
Console,command,LINEINPUT,528,"LINEINPUT [#fileN] var","Reads a whole text line from file or console."
2929
Console,command,LINPUT,529,"LINPUT [#fileN] var","Reads a whole text line from file or console."
3030
Console,command,LOCATE,530,"LOCATE y, x","Moves the console cursor to the specified position. x,y are in character cells."
@@ -69,10 +69,10 @@ Data,statement,ERASE,571,"ERASE var[, var[, ... var]]","Deallocates the memory u
6969
Data,statement,RESTORE,572,"RESTORE label","Specifies the position of the next data to be read."
7070
Date,command,DATEDMY,573,"DATEDMY dmy| julian_date, BYREF d, BYREF m, BYREF y","Returns the day, month and the year as integers."
7171
Date,command,TIMEHMS,574,"TIMEHMS hms| timer, BYREF h, BYREF m, BYREF s","Converts a time-value to hours, minutes and seconds integer values."
72-
Date,function,DATE,575,"DATE","Returns the current date as string "DD/MM/YYYY"."
72+
Date,function,DATE,575,"DATE","Returns the current date as string ""DD/MM/YYYY""."
7373
Date,function,DATEFMT,576,"DATEFMT (format, dmy| (d,m,y)| julian_date)","Returns formated date string."
7474
Date,function,JULIAN,577,"JULIAN (dmy| (d,m,y))","Returns the Julian date. (dates must be greater than 1/1/100 AD)."
75-
Date,function,TIME,578,"TIME","Returns the current time as string "HH:MM:SS"."
75+
Date,function,TIME,578,"TIME","Returns the current time as string ""HH:MM:SS""."
7676
Date,function,WEEKDAY,579,"WEEKDAY (dmy| (d,m,y)| julian_date)","Returns the day of the week (0 = Sunday)."
7777
File,command,ACCESS,580,"ACCESS (file)","Returns the access rights of the file."
7878
Data,command,APPEND,581,"APPEND a, val [, val [, ...]]","Inserts the values at the end of the specified array."
@@ -82,14 +82,14 @@ File,command,BSAVE,584,"BSAVE filename, address, length","Copies a specified por
8282
File,command,CHDIR,585,"CHDIR dir","Changes the current working directory. Not supported on PalmOS version."
8383
File,command,CHMOD,586,"CHMOD file, mode","Change permissions of a file. See also ACCESS."
8484
File,command,CLOSE,587,"CLOSE #fileN","Close a file or device."
85-
File,command,COPY,588,"COPY "file", "newfile"","Makes a copy of specified file to the 'newfile'."
85+
File,command,COPY,588,"COPY ""file"", ""newfile""","Makes a copy of specified file to the 'newfile'."
8686
File,command,DIRWALK,589,"DIRWALK directory [, wildcards] [USE ...]","Walk through the specified directories. The user-defined function must returns zero to stop the process."
8787
File,command,INPUT,590,"INPUT #fileN; var1 [,delim] [, var2 [,delim]] ...","Reads data from file."
88-
File,command,KILL,591,"KILL "file"","Deletes the specified file."
88+
File,command,KILL,591,"KILL ""file""","Deletes the specified file."
8989
File,command,LOCK,592,"LOCK","Lock a record or an area (not yet implemented)."
9090
File,command,MKDIR,593,"MKDIR dir","Create a directory. Not supported on PalmOS version."
9191
File,command,OPEN,594,"OPEN file [FOR {INPUT|OUTPUT|APPEND}] AS #fileN","Makes a file or device available for sequential input, sequential output."
92-
File,command,RENAME,595,"RENAME "file", "newname"","Renames the specified file."
92+
File,command,RENAME,595,"RENAME ""file"", ""newname""","Renames the specified file."
9393
File,command,RMDIR,596,"RMDIR dir","Removes a directory. Not supported on PalmOS version."
9494
File,command,SEEK,597,"SEEK #fileN; pos","Sets file position for the next read/write."
9595
File,command,TLOAD,598,"TLOAD file, BYREF var [, type]","Loads a text file into array variable. Each text-line is an array element. type 0 = load into array (default), 1 = load into string."
@@ -109,7 +109,7 @@ Graphics,command,ARC,611,"ARC [STEP] x,y,r,astart,aend [,aspect [,color]] [COLOR
109109
Graphics,command,CHART,612,"CHART LINECHART|BARCHART, array() [, style [, x1, y1, x2, y2]]","Draws a chart of array values in the rectangular area x1,y1,x2,y2. Styles: 0 = simple, 1 = with-marks, 2 = with ruler, 3 = with marks and ruler."
110110
Graphics,command,CIRCLE,613,"CIRCLE [STEP] x,y,r [,aspect [, color]] [COLOR color] [FILLED]","Draws a circle (or an ellipse if the aspect is specified)."
111111
Graphics,command,COLOR,614,"COLOR foreground-color [, background-color]","Specifies the foreground and background colors."
112-
Graphics,command,DRAW,615,"DRAW "commands"","Draw lines as specified by the given directional commands. "
112+
Graphics,command,DRAW,615,"DRAW ""commands""","Draw lines as specified by the given directional commands. "
113113
Graphics,command,DRAWPOLY,616,"DRAWPOLY array [,x-origin,y-origin [, scalef [, color]]] [COLOR color] [FILLED]","Draws a polyline. "
114114
Graphics,command,IMAGE,617,"IMAGE #handle, index, x, y [,sx,sy [,w,h]]","Display a graphical image."
115115
Graphics,command,LINE,618,"LINE [STEP] x,y [,|STEP x2,y2] [, color| COLOR color]","Draws a line."
@@ -118,7 +118,7 @@ Graphics,command,PLOT,620,"PLOT xmin, xmax USE f(x)","Graph of f(x)."
118118
Graphics,command,PSET,621,"PSET [STEP] x,y [, color| COLOR color]","Draw a pixel."
119119
Graphics,command,RECT,622,"RECT [STEP] x,y [,|STEP x2,y2] [, color| COLOR color] [FILLED]","Draws a rectangular parallelogram."
120120
Graphics,command,VIEW,623,"VIEW [x1,y1,x2,y2 [,color [,border-color]]]","Defines a viewport. The viewport defined by VIEW is disabled by a VIEW command with no parameters."
121-
Graphics,command,WINDOW,624,"WINDOW [x1,y1,x2,y2]","The WINDOW command allows you to redefine the corners of the display screen as a pair of "world" coordinates."
121+
Graphics,command,WINDOW,624,"WINDOW [x1,y1,x2,y2]","The WINDOW command allows you to redefine the corners of the display screen as a pair of ""world"" coordinates."
122122
Graphics,function,IMAGEH,625,"IMAGEH #handle, index","Returns the height of the image in pixels."
123123
Graphics,function,IMAGEW,626,"IMAGEW #handle, index","Returns the width of the image in pixels."
124124
Graphics,function,PEN,627,"PEN (0..14)","Returns the PEN/MOUSE data."
@@ -129,18 +129,18 @@ Graphics,function,TEXTHEIGHT,631,"TEXTHEIGHT (s)","Returns the text height of st
129129
Graphics,function,TEXTWIDTH,632,"TEXTWIDTH (s)","Returns the text width of string s in pixels. See TXTW."
130130
Graphics,function,TXTH,633,"TXTH (s)","Returns the text height of string s in pixels. See TEXTHEIGHT."
131131
Graphics,function,TXTW,634,"TXTW (s)","Returns the text width of string s in pixels. See TEXTWIDTH."
132-
Graphics,function,XPOS,635,"XPOS","Returns the current X position of the cursor in "characters"."
133-
Graphics,function,YPOS,636,"YPOS","Returns the current Y position of the cursor in "characters"."
132+
Graphics,function,XPOS,635,"XPOS","Returns the current X position of the cursor in ""characters""."
133+
Graphics,function,YPOS,636,"YPOS","Returns the current Y position of the cursor in ""characters""."
134134
Language,command,CALL,637,"CALL (fp)","Invoke a sub or func by address pointer."
135-
Language,function,IFF,638,"IFF expr","Inline version of IF. eg, animal = "cat": fur = IFF( animal = "cat", "yes", "no"): ? fur"
135+
Language,function,IFF,638,"IFF expr","Inline version of IF. eg, animal = ""cat"": fur = IFF( animal = ""cat"", ""yes"", ""no""): ? fur"
136136
Language,keyword,BYREF,639,"BYREF","Sub/func argument declaration. Changes to the variable will be passed back to the caller. Equivalent syntax to the @ character."
137137
Language,keyword,CASE,640,"CASE expr","Branch condition for a SELECT statement."
138138
Language,keyword,DEF,641,"DEF name[(par1[,...])] = expression","Defines a single line function. eg, DEF MySin(x) = SIN(x): ? MySin(pi/2)"
139139
Language,keyword,DO,642,"DO","FOR f IN files("*.txt") DO PRINT f"
140-
Language,keyword,ELIF,643,"ELIF","foo = 2: if foo==1: ? "one": ELIF foo==2: ? "two": fi"
141-
Language,keyword,ELSE,644,"ELSE","foo = 2: if foo==1: ? "one": ELSE: ? "not one": fi"
142-
Language,keyword,ELSEIF,645,"ELSEIF","foo = 2: if foo==1: ? "one": ELSEIF foo==2: ? "two": fi"
143-
Language,keyword,ENDIF,646,"ENDIF","foo = 1: if foo==1: ? "one": ENDIF"
140+
Language,keyword,ELIF,643,"ELIF","foo = 2: if foo==1: ? ""one"": ELIF foo==2: ? ""two"": fi"
141+
Language,keyword,ELSE,644,"ELSE","foo = 2: if foo==1: ? ""one"": ELSE: ? ""not one"": fi"
142+
Language,keyword,ELSEIF,645,"ELSEIF","foo = 2: if foo==1: ? ""one"": ELSEIF foo==2: ? ""two"": fi"
143+
Language,keyword,ENDIF,646,"ENDIF","foo = 1: if foo==1: ? ""one"": ENDIF"
144144
Language,keyword,EXEC,647,"EXEC file","Transfers control to another operating system program."
145145
Language,keyword,EXIT,648,"EXIT [FOR|LOOP|SUB|FUNC]","Exits a multi line function definition, a loop, or a subprogram. By default (if no parameter is specified) exits from last command block (loop, for-loop or routine)."
146146
Language,keyword,EXPORT,649,"EXPORT thing","Export a SUB, FUNC or variable from a UNIT to be used by the unit consumer."
@@ -152,7 +152,7 @@ Language,keyword,NEXT,654,"NEXT","See FOR."
152152
Language,keyword,SELECT,655,"SELECT CASE expr","Perform multiple tests on the expression. Offers a more concise syntax to writing successive IF tests."
153153
Language,keyword,STOP,656,"STOP [error]","Terminates execution of a program, closes all files opened by the program, and returns control to the operating system."
154154
Language,keyword,SUB,657,"SUB foo (a, b)","Declare a sub procedure. Sub's do not return a value but can return argument values when declared as BYREF."
155-
Language,keyword,THEN,658,"THEN","foo = 1: if foo==1 THEN: ? "one": fi"
155+
Language,keyword,THEN,658,"THEN","foo = 1: if foo==1 THEN: ? ""one"": fi"
156156
Language,keyword,UNIT,659,"UNIT name","Units are a set of procedures, functions and/or variables that can be used by another program or unit."
157157
Language,keyword,UNTIL,660,"UNTIL","a = 0: repeat: a++: ? a: UNTIL a = 10"
158158
Language,keyword,USE,661,"USE","Used with various commands for passing a user-defined expression. eg SPLIT s," ",v USE TRIM(x). Trim each element of v."
@@ -290,7 +290,7 @@ System,command,STKDUMP,812,"STKDUMP","Display internal execution stack."
290290
System,command,TROFF,813,"TROFF","See TRON."
291291
System,command,TRON,814,"TRON","When trace mechanism is ON, displays each line number as the program is executed."
292292
System,function,ENV,815,"ENV expr","See ENVIRON."
293-
System,function,ENVIRON,816,"ENVIRON expr","Returns the value of a specified entry in the current environment table. If the parameter is empty ("") then returns an array of the environment variables (in var=value form)."
293+
System,function,ENVIRON,816,"ENVIRON expr","Returns the value of a specified entry in the current environment table. If the parameter is empty ("""") then returns an array of the environment variables (in var=value form)."
294294
System,function,PROGLINE,817,"PROGLINE","Returns the current program line number."
295295
System,function,RUN,818,"RUN cmdstr","Loads a secondary copy of system's shell and, executes an program, or an shell command."
296296
System,function,TICKS,819,"TICKS","Returns the system-ticks. The tick value is depended on operating system."

src/common/keymap.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern "C" {
2525
#define SB_KEY_TAB 9
2626
#define SB_KEY_ENTER 13
2727
#define SB_KEY_SPACE 32
28+
#define SB_KEY_ESCAPE 27
2829

2930
// first 16 - common with handhelds any extra key will be there
3031
#define SB_KEY_PGUP 0xFF01
@@ -50,9 +51,10 @@ extern "C" {
5051
#define SB_KEY_SF(x) (0xFFE0+(x))
5152

5253
// Control & Alt keys (parameter = capital character)
53-
#define SB_KEY_CTRL(c) (0xF100 + (c))
54-
#define SB_KEY_ALT(c) (0xF200 + (c))
55-
#define SB_KEY_CTRL_ALT(c) (0xF400 + (c))
54+
#define SB_KEY_CTRL(c) (0xF1000000 + (c))
55+
#define SB_KEY_ALT(c) (0xF2000000 + (c))
56+
#define SB_KEY_CTRL_ALT(c) (0xF4000000 + (c))
57+
#define SB_KEY_SHIFT(c) (0xF8000000 + (c))
5658

5759
// keypad
5860
#define SB_KEY_KP_DIV 0xFFDA

0 commit comments

Comments
 (0)