Skip to content
46 changes: 46 additions & 0 deletions documentation/build_kwp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include "../src/ui/strlib.h"

#define code_t int
Expand Down Expand Up @@ -45,6 +46,7 @@ struct spopr_keyword_s {
struct HelpItem {
char package[20];
char keyword[20];
char type[20];
char id[20];
char signature[128];
char help[1024];
Expand Down Expand Up @@ -177,6 +179,8 @@ bool readHelpReference(strlib::List<HelpItem *> *helpItems) {
break;
case 1:
// type
strncpy(item->type, lineBuffer + start, fieldLen);
item->type[fieldLen] = '\0';
break;
case 2:
// keyword
Expand Down Expand Up @@ -215,6 +219,16 @@ bool readHelpReference(strlib::List<HelpItem *> *helpItems) {
return true;
}

uint32_t getHash(const char *key) {
uint32_t hash, i;
for (hash = i = 0; key[i] != '\0'; i++) {
hash += tolower(key[i]);
hash += (hash << 3);
hash ^= (hash >> 1);
}
return hash;
}

int main(int argc, char *argv[]) {
strlib::List<HelpItem *> helpItems;
if (!readHelpReference(&helpItems)) {
Expand All @@ -228,12 +242,44 @@ int main(int argc, char *argv[]) {
fprintf(stdout, " const char *signature;\n");
fprintf(stdout, " const char *help;\n");
fprintf(stdout, "} keyword_help[] = {\n");

int max_keyword_len = 0;
List_each(HelpItem *, it, helpItems) {
HelpItem *item = (*it);
fprintf(stdout, "{\"%s\",\"%s\",\"%s\",\"%s\"},\n", item->package,
item->keyword, item->signature, item->help);
int len = strlen(item->keyword);
if (len > max_keyword_len) {
max_keyword_len = len;
}
}
fprintf(stdout, "};\n");
fprintf(stdout, "const int keyword_help_len = %d;\n", helpItems.size());
fprintf(stdout, "const int keyword_max_len = %d;\n", max_keyword_len);

int count = 0;
fprintf(stdout, "const uint32_t keyword_hash_statement[] = {\n");
List_each(HelpItem *, it, helpItems) {
HelpItem *item = (*it);
if (strcasecmp(item->package, "Language") == 0) {
count++;
fprintf(stdout, " %uu,\n", getHash(item->keyword));
}
}
fprintf(stdout, "};\n");
fprintf(stdout, "const int keyword_hash_statement_len = %d;\n", count);

count = 0;
fprintf(stdout, "const uint32_t keyword_hash_command[] = {\n");
List_each(HelpItem *, it, helpItems) {
HelpItem *item = (*it);
if (strcasecmp(item->package, "Language") != 0) {
count++;
fprintf(stdout, " %uu,\n", getHash(item->keyword));
}
}
fprintf(stdout, "};\n");
fprintf(stdout, "const int keyword_hash_command_len = %d;\n", count);

return 0;
}
2 changes: 1 addition & 1 deletion src/platform/sdl/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const int shiftmap[][2] = {
{'8', '*'},
{'9', '('},
{'0', ')'},
{'-', '-'},
{'-', '_'},
{'=', '+'},
{'[', '{'},
{']', '}'},
Expand Down
7 changes: 6 additions & 1 deletion src/platform/sdl/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "ui/utils.h"
#include "common/smbas.h"

extern int g_themeId;

static const char *ENV_VARS[] = {
"APPDATA", "HOME", "TMP", "TEMP", "TMPDIR"
};
Expand Down Expand Up @@ -88,6 +90,7 @@ void restoreSettings(const char *configName, SDL_Rect &rect, int &fontScale) {
fontScale = nextInteger(fp, DEFAULT_SCALE);
opt_mute_audio = nextInteger(fp, 0);
opt_ide = nextInteger(fp, 0);
g_themeId = nextInteger(fp, 0);
fclose(fp);
} else {
rect.x = SDL_WINDOWPOS_UNDEFINED;
Expand All @@ -97,6 +100,7 @@ void restoreSettings(const char *configName, SDL_Rect &rect, int &fontScale) {
fontScale = DEFAULT_SCALE;
opt_mute_audio = 0;
opt_ide = IDE_NONE;
g_themeId = 0;
}
}

Expand All @@ -109,7 +113,8 @@ void saveSettings(const char *configName, SDL_Window *window, int fontScale) {
int x, y, w, h;
SDL_GetWindowPosition(window, &x, &y);
SDL_GetWindowSize(window, &w, &h);
fprintf(fp, "%d,%d,%d,%d,%d,%d,%d\n", x, y, w, h, fontScale, opt_mute_audio, opt_ide);
fprintf(fp, "%d,%d,%d,%d,%d,%d,%d,%d\n", x, y, w, h,
fontScale, opt_mute_audio, opt_ide, g_themeId);
fclose(fp);
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/ui/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,15 @@ void System::editSource(strlib::String &loadPath) {
fileName = loadPath;
}

const char *help = " Ctrl+h (C-h)=Help";
strlib::String dirtyFile;
dirtyFile.append(" * ");
dirtyFile.append(fileName);
dirtyFile.append(" C-h=Help");
dirtyFile.append(help);
strlib::String cleanFile;
cleanFile.append(" - ");
cleanFile.append(fileName);
cleanFile.append(" C-h=Help");
cleanFile.append(help);

int w = _output->getWidth();
int h = _output->getHeight();
Expand Down
Loading