--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/fileio.c Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,226 @@
+/*
+ * XXX: assume all files are text files
+ */
+
+#include "misc.h"
+#include "fileio.h"
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <sys/stat.h>
+
+io_result_t IOResult;
+int FileMode;
+
+static void init(File f) {
+ f->fp = NULL;
+ f->eof = 0;
+ f->mode = NULL;
+ f->record_len = 0;
+}
+
+void fpcrtl_assign__vars(File *f, string255 name) {
+ FIX_STRING(name);
+ *f = (File) malloc(sizeof(file_wrapper_t));
+ strcpy((*f)->file_name, name.str);
+ init(*f);
+}
+
+void fpcrtl_reset1(File f) {
+ f->fp = fopen(f->file_name, "r");
+ if (!f->fp) {
+ IOResult = IO_ERROR_DUMMY;
+ printf("Failed to open %s\n", f->file_name);
+ return;
+ } else {
+#ifdef FPCRTL_DEBUG
+ printf("Opened %s\n", f->file_name);
+#endif
+ }
+ IOResult = IO_NO_ERROR;
+ f->mode = "r";
+}
+
+void fpcrtl_reset2(File f, int l) {
+ f->eof = 0;
+ f->fp = fopen(f->file_name, "rb");
+ if (!f->fp) {
+ IOResult = IO_ERROR_DUMMY;
+ printf("Failed to open %s\n", f->file_name);
+ return;
+ }
+ IOResult = IO_NO_ERROR;
+ f->mode = "rb";
+ f->record_len = l;
+}
+
+void __attribute__((overloadable)) fpcrtl_rewrite(File f) {
+ f->fp = fopen(f->file_name, "w+");
+ if (!f->fp) {
+ IOResult = IO_ERROR_DUMMY;
+ return;
+ }
+ IOResult = IO_NO_ERROR;
+ f->mode = "w+";
+}
+
+void __attribute__((overloadable)) fpcrtl_rewrite(File f, Integer l) {
+ IOResult = IO_NO_ERROR;
+ fpcrtl_rewrite(f);
+ if (f->fp) {
+ f->record_len = l;
+ }
+}
+
+void fpcrtl_close(File f) {
+ IOResult = IO_NO_ERROR;
+ fclose(f->fp);
+ free(f);
+}
+
+boolean fpcrtl_eof(File f) {
+ IOResult = IO_NO_ERROR;
+ if (f->eof || f->fp == NULL || feof(f->fp)) {
+ return true;
+ } else {
+ return false;
+ }
+}
+
+void __attribute__((overloadable)) fpcrtl_readLn(File f) {
+ IOResult = IO_NO_ERROR;
+ char line[256];
+ if (fgets(line, sizeof(line), f->fp) == NULL) {
+ f->eof = 1;
+ }
+ if (feof(f->fp)) {
+ f->eof = 1;
+ }
+}
+
+void __attribute__((overloadable)) fpcrtl_readLn__vars(File f, Integer *i) {
+ string255 s;
+
+ if (feof(f->fp)) {
+ f->eof = 1;
+ return;
+ }
+
+ fpcrtl_readLn__vars(f, &s);
+
+ *i = atoi(s.str);
+}
+
+void __attribute__((overloadable)) fpcrtl_readLn__vars(File f, LongWord *i) {
+ string255 s;
+
+ if (feof(f->fp)) {
+ f->eof = 1;
+ return;
+ }
+
+ fpcrtl_readLn__vars(f, &s);
+
+ *i = atoi(s.str);
+}
+
+void __attribute__((overloadable)) fpcrtl_readLn__vars(File f, string255 *s) {
+
+ if (fgets(s->str, 255, f->fp) == NULL) {
+
+ s->len = 0;
+ s->str[0] = 0;
+
+ f->eof = 1;
+ return;
+ }
+
+ if (feof(f->fp)) {
+ s->len = 0;
+ f->eof = 1;
+ return;
+ }
+
+ IOResult = IO_NO_ERROR;
+
+ s->len = strlen(s->str);
+ if ((s->len > 0) && (s->str[s->len - 1] == '\n')) {
+ s->str[s->len - 1] = 0;
+ s->len--;
+ }
+}
+
+void __attribute__((overloadable)) fpcrtl_write(File f, string255 s) {
+ FIX_STRING(s);
+ fprintf(f->fp, "%s", s.str);
+}
+
+void __attribute__((overloadable)) fpcrtl_write(FILE *f, string255 s) {
+ FIX_STRING(s);
+ fprintf(f, "%s", s.str);
+}
+
+void __attribute__((overloadable)) fpcrtl_writeLn(File f, string255 s) {
+ FIX_STRING(s);
+ fprintf(f->fp, "%s\n", s.str);
+}
+
+void __attribute__((overloadable)) fpcrtl_writeLn(FILE *f, string255 s) {
+ FIX_STRING(s);
+ fprintf(f, "%s\n", s.str);
+}
+
+void fpcrtl_blockRead__vars(File f, void *buf, Integer count, Integer *result) {
+ assert(f->record_len > 0);
+ *result = fread(buf, f->record_len, count, f->fp);
+}
+
+/*
+ * XXX: dummy blockWrite
+ */
+void fpcrtl_blockWrite__vars(File f, const void *buf, Integer count,
+ Integer *result) {
+ assert(0);
+}
+
+bool fpcrtl_directoryExists(string255 dir) {
+
+ struct stat st;
+ FIX_STRING(dir);
+
+ IOResult = IO_NO_ERROR;
+
+#ifdef FPCRTL_DEBUG
+ printf("Warning: directoryExists is called. This may not work when compiled to js.\n");
+#endif
+
+ if (stat(dir.str, &st) == 0) {
+ return true;
+ }
+
+ return false;
+}
+
+bool fpcrtl_fileExists(string255 filename) {
+
+ FIX_STRING(filename);
+
+ IOResult = IO_NO_ERROR;
+
+ FILE *fp = fopen(filename.str, "r");
+ if (fp) {
+ fclose(fp);
+ return true;
+ }
+ return false;
+}
+
+void __attribute__((overloadable)) fpcrtl_flush(Text f) {
+ printf("flush not implemented\n");
+ assert(0);
+}
+
+void __attribute__((overloadable)) fpcrtl_flush(FILE *f) {
+ fflush(f);
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/fileio.h Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,78 @@
+#ifndef FILEIO_H_
+#define FILEIO_H_
+
+#include <stdio.h>
+#include "types.h"
+#include "misc.h"
+
+extern int FileMode;
+
+typedef enum{
+ IO_NO_ERROR = 0,
+ IO_ERROR_DUMMY = 1
+}io_result_t;
+
+extern io_result_t IOResult;
+
+typedef struct{
+ FILE *fp;
+ const char* mode;
+ char file_name[256];
+ int eof;
+ int record_len;
+}file_wrapper_t;
+
+typedef file_wrapper_t* File;
+typedef File Text;
+typedef Text TextFile;
+
+void __attribute__((overloadable)) fpcrtl_readLn(File f);
+#define fpcrtl_readLn1(f) fpcrtl_readLn(f)
+
+void __attribute__((overloadable)) fpcrtl_readLn__vars(File f, Integer *i);
+void __attribute__((overloadable)) fpcrtl_readLn__vars(File f, LongWord *i);
+void __attribute__((overloadable)) fpcrtl_readLn__vars(File f, string255 *s);
+#define fpcrtl_readLn2(f, t) fpcrtl_readLn__vars(f, &(t))
+
+#define fpcrtl_readLn(...) macro_dispatcher(fpcrtl_readLn, __VA_ARGS__)(__VA_ARGS__)
+
+
+void fpcrtl_blockRead__vars(File f, void *buf, Integer count, Integer *result);
+#define fpcrtl_blockRead(f, buf, count, result) fpcrtl_blockRead__vars(f, &(buf), count, &(result))
+#define fpcrtl_BlockRead fpcrtl_blockRead
+
+#define fpcrtl_assign(f, name) fpcrtl_assign__vars(&f, name)
+void fpcrtl_assign__vars(File *f, string255 name);
+
+boolean fpcrtl_eof(File f);
+
+void fpcrtl_reset1(File f);
+void fpcrtl_reset2(File f, Integer l);
+#define fpcrtl_reset1(f) fpcrtl_reset1(f)
+#define fpcrtl_reset2(f, l) fpcrtl_reset2(f, l)
+#define fpcrtl_reset(...) macro_dispatcher(fpcrtl_reset, __VA_ARGS__)(__VA_ARGS__)
+
+void fpcrtl_close(File f);
+
+void __attribute__((overloadable)) fpcrtl_rewrite(File f);
+void __attribute__((overloadable)) fpcrtl_rewrite(File f, Integer l);
+
+void __attribute__((overloadable)) fpcrtl_flush(Text f);
+void __attribute__((overloadable)) fpcrtl_flush(FILE *f);
+
+void __attribute__((overloadable)) fpcrtl_write(File f, string255 s);
+void __attribute__((overloadable)) fpcrtl_write(FILE *f, string255 s);
+void __attribute__((overloadable)) fpcrtl_writeLn(File f, string255 s);
+void __attribute__((overloadable)) fpcrtl_writeLn(FILE *f, string255 s);
+
+void fpcrtl_blockWrite__vars(File f, const void *buf, Integer count, Integer *result);
+#define fpcrtl_blockWrite(f, buf, count, result) fpcrtl_blockWrite__vars(f, &(buf), count, &(result))
+#define fpcrtl_BlockWrite fpcrtl_blockWrite
+
+bool fpcrtl_directoryExists(string255 dir);
+#define fpcrtl_DirectoryExists fpcrtl_directoryExists
+
+bool fpcrtl_fileExists(string255 filename);
+#define fpcrtl_FileExists fpcrtl_fileExists
+
+#endif /* FILEIO_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/fpcrtl.h Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,189 @@
+#ifndef _FPCRTL_H_
+#define _FPCRTL_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "system.h"
+#include "misc.h"
+#include "sysutils.h"
+#include "fileio.h"
+#include "pmath.h"
+
+#ifndef EMSCRIPTEN
+#include "GL/glew.h"
+#endif
+
+#define fpcrtl_memcpy memcpy
+
+#define luapas_lua_gettop lua_gettop
+#define luapas_lua_close lua_close
+#define luapas_lua_createtable lua_createtable
+#define luapas_lua_error lua_error
+#define luapas_lua_gc lua_gc
+#define luapas_lua_getfield lua_getfield
+#define luapas_lua_objlen lua_objlen
+#define luapas_lua_call lua_call
+#define luapas_lua_pcall lua_pcall
+#define luapas_lua_pushboolean lua_pushboolean
+#define luapas_lua_pushcclosure lua_pushcclosure
+#define luapas_lua_pushinteger lua_pushinteger
+#define luapas_lua_pushnil lua_pushnil
+#define luapas_lua_pushnumber lua_pushnumber
+#define luapas_lua_pushlstring lua_pushlstring
+#define luapas_lua_pushstring lua_pushstring
+#define luapas_lua_pushvalue lua_pushvalue
+#define luapas_lua_rawgeti lua_rawgeti
+#define luapas_lua_setfield lua_setfield
+#define luapas_lua_settop lua_settop
+#define luapas_lua_toboolean lua_toboolean
+#define luapas_lua_tointeger lua_tointeger
+#define luapas_lua_tolstring lua_tolstring
+#define luapas_lua_tonumber lua_tonumber
+#define luapas_lua_type lua_type
+#define luapas_lua_typename lua_typename
+#define luapas_luaL_argerror luaL_argerror
+#define luapas_luaL_checkinteger luaL_checkinteger
+#define luapas_luaL_checklstring luaL_checklstring
+#define luapas_luaL_loadfile luaL_loadfile
+#define luapas_luaL_loadstring luaL_loadstring
+#define luapas_luaL_newstate luaL_newstate
+#define luapas_luaL_optinteger luaL_optinteger
+#define luapas_luaL_optlstring luaL_optlstring
+#define luapas_luaL_prepbuffer luaL_prepbuffer
+#define luapas_luaL_ref luaL_ref
+#define luapas_luaL_unref luaL_unref
+#define luapas_luaopen_base luaopen_base
+#define luapas_luaopen_math luaopen_math
+#define luapas_luaopen_string luaopen_string
+#define luapas_luaopen_table luaopen_table
+
+#define sdlh_IMG_Load IMG_Load
+
+#ifndef EMSCRIPTEN
+#define sdlh_Mix_AllocateChannels Mix_AllocateChannels
+#define sdlh_Mix_CloseAudio Mix_CloseAudio
+#define sdlh_Mix_FadeInChannelTimed Mix_FadeInChannelTimed
+#define sdlh_Mix_FadeInMusic Mix_FadeInMusic
+#define sdlh_Mix_FadeOutChannel Mix_FadeOutChannel
+#define sdlh_Mix_FreeChunk Mix_FreeChunk
+#define sdlh_Mix_FreeMusic Mix_FreeMusic
+#define sdlh_Mix_HaltChannel Mix_HaltChannel
+#define sdlh_Mix_HaltMusic Mix_HaltMusic
+#define sdlh_Mix_LoadMUS Mix_LoadMUS
+#define sdlh_Mix_LoadWAV_RW Mix_LoadWAV_RW
+#define sdlh_Mix_OpenAudio Mix_OpenAudio
+#define sdlh_Mix_PauseMusic Mix_PauseMusic
+#define sdlh_Mix_PlayChannelTimed Mix_PlayChannelTimed
+#define sdlh_Mix_Playing Mix_Playing
+#define sdlh_Mix_ResumeMusic Mix_ResumeMusic
+#define sdlh_Mix_Volume Mix_Volume
+#define sdlh_Mix_VolumeMusic Mix_VolumeMusic
+#else
+#define sdlh_Mix_AllocateChannels stub_Mix_AllocateChannels
+#define sdlh_Mix_CloseAudio stub_Mix_CloseAudio
+#define sdlh_Mix_FadeInChannelTimed stub_Mix_FadeInChannelTimed
+#define sdlh_Mix_FadeInMusic stub_Mix_FadeInMusic
+#define sdlh_Mix_FadeOutChannel stub_Mix_FadeOutChannel
+#define sdlh_Mix_FreeChunk stub_Mix_FreeChunk
+#define sdlh_Mix_FreeMusic stub_Mix_FreeMusic
+#define sdlh_Mix_HaltChannel stub_Mix_HaltChannel
+#define sdlh_Mix_HaltMusic stub_Mix_HaltMusic
+#define sdlh_Mix_LoadMUS stub_Mix_LoadMUS
+#define sdlh_Mix_LoadWAV_RW stub_Mix_LoadWAV_RW
+#define sdlh_Mix_OpenAudio stub_Mix_OpenAudio
+#define sdlh_Mix_PauseMusic stub_Mix_PauseMusic
+#define sdlh_Mix_PlayChannelTimed stub_Mix_PlayChannelTimed
+#define sdlh_Mix_Playing stub_Mix_Playing
+#define sdlh_Mix_ResumeMusic stub_Mix_ResumeMusic
+#define sdlh_Mix_Volume stub_Mix_Volume
+#define sdlh_Mix_VolumeMusic stub_Mix_VolumeMusic
+#endif
+
+#define sdlh_SDL_ConvertSurface SDL_ConvertSurface
+#define sdlh_SDL_CreateRGBSurface SDL_CreateRGBSurface
+#define sdlh_SDL_CreateThread SDL_CreateThread
+#define sdlh_SDL_Delay SDL_Delay
+#define sdlh_SDL_EnableKeyRepeat SDL_EnableKeyRepeat
+#define sdlh_SDL_EnableUNICODE SDL_EnableUNICODE
+#define sdlh_SDL_FillRect SDL_FillRect
+#define sdlh_SDL_FreeSurface SDL_FreeSurface
+#define sdlh_SDL_GetError SDL_GetError
+#define sdlh_SDL_GetKeyName SDL_GetKeyName
+#define sdlh_SDL_GetKeyState SDL_GetKeyState
+#define sdlh_SDL_GetMouseState SDL_GetMouseState
+#define sdlh_SDL_GetRGBA SDL_GetRGBA
+#define sdlh_SDL_GetTicks SDL_GetTicks
+#define sdlh_SDL_GL_SetAttribute SDL_GL_SetAttribute
+#define sdlh_SDL_GL_SwapBuffers SDL_GL_SwapBuffers
+#define sdlh_SDL_Init SDL_Init
+#define sdlh_SDL_InitSubSystem SDL_InitSubSystem
+#define sdlh_SDL_JoystickClose SDL_JoystickClose
+#define sdlh_SDL_JoystickEventState SDL_JoystickEventState
+#define sdlh_SDL_JoystickName SDL_JoystickName
+#define sdlh_SDL_JoystickNumAxes SDL_JoystickNumAxes
+#define sdlh_SDL_JoystickNumButtons SDL_JoystickNumButtons
+#define sdlh_SDL_JoystickNumHats SDL_JoystickNumHats
+#define sdlh_SDL_JoystickOpen SDL_JoystickOpen
+#define sdlh_SDL_LockSurface SDL_LockSurface
+#define sdlh_SDL_MapRGB SDL_MapRGB
+#define sdlh_SDL_MapRGBA SDL_MapRGBA
+#define sdlh_SDL_NumJoysticks SDL_NumJoysticks
+#define sdlh_SDL_PeepEvents SDL_PeepEvents
+#define sdlh_SDL_PumpEvents SDL_PumpEvents
+#define sdlh_SDL_Quit SDL_Quit
+#define sdlh_SDL_RWFromFile SDL_RWFromFile
+#define sdlh_SDL_SetColorKey SDL_SetColorKey
+#define sdlh_SDL_SetVideoMode SDL_SetVideoMode
+#ifndef EMSCRIPTEN
+#define sdlh_SDL_ShowCursor SDL_ShowCursor
+#else
+#define sdlh_SDL_ShowCursor SDL_ShowCursor_patch
+#endif
+#define sdlh_SDL_UnlockSurface SDL_UnlockSurface
+#define sdlh_SDL_UpperBlit SDL_UpperBlit
+#define sdlh_SDL_VideoDriverName SDL_VideoDriverName
+#define sdlh_SDL_WarpMouse SDL_WarpMouse
+#define sdlh_SDL_WM_SetCaption SDL_WM_SetCaption
+#define sdlh_SDL_WM_SetIcon SDL_WM_SetIcon
+#define sdlh_SDLNet_AddSocket SDLNet_AddSocket
+#define sdlh_SDLNet_AllocSocketSet SDLNet_AllocSocketSet
+#define sdlh_SDLNet_CheckSockets SDLNet_CheckSockets
+#define sdlh_SDLNet_FreeSocketSet SDLNet_FreeSocketSet
+#define sdlh_SDLNet_Init SDLNet_Init
+#define sdlh_SDLNet_Quit SDLNet_Quit
+#define sdlh_SDLNet_ResolveHost SDLNet_ResolveHost
+#define sdlh_SDLNet_TCP_Close SDLNet_TCP_Close
+#define sdlh_SDLNet_TCP_Open SDLNet_TCP_Open
+#define sdlh_SDLNet_TCP_Recv SDLNet_TCP_Recv
+#define sdlh_SDLNet_TCP_Send SDLNet_TCP_Send
+#define sdlh_TTF_Init TTF_Init
+#define sdlh_TTF_OpenFont TTF_OpenFont
+#define sdlh_TTF_Quit TTF_Quit
+#define sdlh_TTF_RenderUTF8_Blended TTF_RenderUTF8_Blended
+#define sdlh_TTF_RenderUTF8_Solid TTF_RenderUTF8_Solid
+#define sdlh_TTF_SetFontStyle TTF_SetFontStyle
+#define sdlh_TTF_SizeUTF8 TTF_SizeUTF8
+
+#define _strconcat fpcrtl_strconcat
+#define _strappend fpcrtl_strappend
+#define _strprepend fpcrtl_strprepend
+#define _strcompare fpcrtl_strcompare
+#define _strncompare fpcrtl_strncompare
+#define _strcomparec fpcrtl_strcomparec
+#define _chrconcat fpcrtl_chrconcat
+#define _pchar fpcrtl_pchar
+
+// hooks are implemented in javascript
+void start_hook(void);
+void mainloop_hook(void);
+void clear_filelist_hook(void);
+void add_file_hook(const char* ptr);
+void idb_loader_hook();
+void showcursor_hook();
+void hidecursor_hook();
+void drawworld_init_hook();
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/misc.c Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,168 @@
+#include "misc.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <assert.h>
+
+char strbuf[512];
+
+void fpcrtl_assert(int i)
+{
+ if(!i){
+ assert(0);
+ }
+}
+
+// EFFECTS: return the nearest integer of the given number
+int fpcrtl_round(double number)
+{
+ return (number >= 0) ? (int)(number + 0.5) : (int)(number - 0.5);
+}
+
+void fpcrtl_printf(const char* format, ...)
+{
+#ifdef FPCRTL_DEBUG
+ va_list args;
+ va_start (args, format);
+ vprintf (format, args);
+ va_end (args);
+#endif
+}
+
+//
+//void fpcrtl_check_string(string255 str)
+//{
+//#ifdef FPCRTL_DEBUG
+// int len = strlen(str.str);
+// if(len != str.len){
+// printf("String %s internal inconsistency error. Length should be %d but actually is %d.\n", str.str, len, str.len);
+// }
+// //assert(len == str.len);
+//#endif
+//}
+
+string255 fpcrtl_strconcat(string255 str1, string255 str2)
+{
+ //printf("str1 = %d, %d\n", str1.len, strlen(str1.str));
+ //printf("str2 = %d, %d\n", str2.len, strlen(str2.str));
+
+#ifdef FPCRTL_DEBUG
+ if(str1.len + (int)(str2.len) > 255){
+ printf("String overflow\n");
+ printf("str1(%d): %s\nstr2(%d): %s\n", str1.len, str1.str, str2.len, str2.str);
+ printf("String will be truncated.\n");
+
+ strbuf[0] = 0;
+ strcpy(strbuf, str1.str);
+ strcat(strbuf, str2.str);
+ memcpy(str1.str, strbuf, 255);
+ str1.str[254] = 0;
+
+ return str1;
+ }
+#endif
+
+ memcpy(&(str1.str[str1.len]), str2.str, str2.len);
+ str1.str[str1.len + str2.len] = 0;
+ str1.len += str2.len;
+
+ return str1;
+}
+
+string255 fpcrtl_strappend(string255 s, char c)
+{
+ s.str[s.len] = c;
+ s.str[s.len + 1] = 0;
+ s.len ++;
+
+ return s;
+}
+
+string255 fpcrtl_strprepend(char c, string255 s)
+{
+ FIX_STRING(s);
+
+ memmove(s.str + 1, s.str, s.len + 1); // also move '/0'
+ s.str[0] = c;
+ s.len++;
+
+ return s;
+}
+
+string255 fpcrtl_chrconcat(char a, char b)
+{
+ string255 result;
+
+ result.len = 2;
+ result.str[0] = a;
+ result.str[1] = b;
+ result.str[2] = 0;
+
+ return result;
+}
+
+bool fpcrtl_strcompare(string255 str1, string255 str2)
+{
+ //printf("str1 = %d, %d\n", str1.len, strlen(str1.str));
+ //printf("str2 = %d, %d\n", str2.len, strlen(str2.str));
+ FIX_STRING(str1);
+ FIX_STRING(str2);
+
+ if(strcmp(str1.str, str2.str) == 0){
+ return true;
+ }
+
+ return false;
+}
+
+bool fpcrtl_strcomparec(string255 a, char b)
+{
+ FIX_STRING(a);
+
+ if(a.len == 1 && a.str[0] == b){
+ return true;
+ }
+
+ return false;
+}
+
+bool fpcrtl_strncompare(string255 a, string255 b)
+{
+ return !fpcrtl_strcompare(a, b);
+}
+
+//char* fpcrtl_pchar(string255 s)
+//{
+// return s.str;
+//}
+
+string255 fpcrtl_pchar2str(char *s)
+{
+ string255 result;
+ int t = strlen(s);
+
+ if(t > 255){
+ printf("pchar2str, length > 255\n");
+ assert(0);
+ }
+
+ result.len = t;
+ memcpy(result.str, s, t);
+ result.str[t] = 0;
+
+ return result;
+}
+
+string255 fpcrtl_make_string(const char* s) {
+ string255 result;
+ strcpy(result.str, s);
+ result.len = strlen(s);
+ return result;
+}
+
+#ifdef EMSCRIPTEN
+GLenum glewInit()
+{
+ return GLEW_OK;
+}
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/misc.h Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,58 @@
+#ifndef _FPCRTL_MISC_H_
+#define _FPCRTL_MISC_H_
+
+#include "pas2c.h"
+#include <assert.h>
+#include <stdbool.h>
+
+#ifdef EMSCRIPTEN
+#include <GL/gl.h>
+#else
+#include <GL/glew.h>
+#endif
+
+#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL(__VA_ARGS__, 5,4,3,2,1)
+#define VA_NUM_ARGS_IMPL(_1,_2,_3,_4,_5,N,...) N
+
+#define macro_dispatcher(func, ...) macro_dispatcher_(func, VA_NUM_ARGS(__VA_ARGS__))
+#define macro_dispatcher_(func, nargs) macro_dispatcher__(func, nargs)
+#define macro_dispatcher__(func, nargs) func ## nargs
+
+#define FPCRTL_DEBUG
+
+#define FIX_STRING(s) (s.str[s.len] = 0)
+
+//#define fpcrtl_check_string(s) do{ if(strlen((s).str) != (s).len){ \
+// printf("String %s internal inconsistency error. Length should be %d but actually is %d.\n", (s).str, strlen((s).str), (s).len); \
+// assert(0);\
+// }}while(0)
+
+void fpcrtl_assert(int);
+void fpcrtl_print_trace (void);
+
+int fpcrtl_round(double number);
+void fpcrtl_printf(const char* format, ...);
+
+string255 fpcrtl_make_string(const char* s);
+
+string255 fpcrtl_strconcat(string255 str1, string255 str2);
+string255 fpcrtl_strappend(string255 s, char c);
+string255 fpcrtl_strprepend(char c, string255 s);
+string255 fpcrtl_chrconcat(char a, char b);
+
+// return true if str1 == str2
+bool fpcrtl_strcompare(string255 str1, string255 str2);
+bool fpcrtl_strcomparec(string255 a, char b);
+bool fpcrtl_strncompare(string255 a, string255 b);
+
+#define fpcrtl__pchar(s) ((s).str)
+string255 fpcrtl_pchar2str(char *s);
+
+#define fpcrtl_TypeInfo sizeof // dummy
+
+#ifdef EMSCRIPTEN
+#define GLEW_OK 1
+GLenum glewInit();
+#endif
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/pmath.c Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,50 @@
+#include "pmath.h"
+#include <math.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+/*
+ * power raises base to the power power.
+ * This is equivalent to exp(power*ln(base)). Therefore base should be non-negative.
+ */
+float fpcrtl_power(float base, float exponent)
+{
+ return exp(exponent * log(base));
+}
+
+/* Currently the games only uses sign of an integer */
+int fpcrtl_signi(int x)
+{
+ if(x > 0){
+ return 1;
+ }
+ else if(x < 0){
+ return -1;
+ }
+ else{
+ return 0;
+ }
+}
+
+float fpcrtl_csc(float x)
+{
+ return 1 / sin(x);
+}
+
+float __attribute__((overloadable)) fpcrtl_abs(float x)
+{
+ return fabs(x);
+}
+double __attribute__((overloadable)) fpcrtl_abs(double x)
+{
+ return fabs(x);
+}
+int __attribute__((overloadable)) fpcrtl_abs(int x)
+{
+ return abs(x);
+}
+
+int64_t __attribute__((overloadable)) fpcrtl_abs(int64_t x)
+{
+ return x < 0 ? -x : x;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/pmath.h Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,23 @@
+#ifndef PMATH_H_
+#define PMATH_H_
+
+#include <stdint.h>
+
+#define fpcrtl_min(a, b) ((a) < (b) ? (a) : (b))
+#define fpcrtl_max(a, b) ((a) > (b) ? (a) : (b))
+
+float fpcrtl_power(float base, float exponent);
+
+/* Currently the games only uses sign of an integer */
+int fpcrtl_signi(int x);
+
+float fpcrtl_csc(float x);
+
+#define fpcrtl_arctan2(y, x) atan2(y, x)
+
+float __attribute__((overloadable)) fpcrtl_abs(float x);
+double __attribute__((overloadable)) fpcrtl_abs(double x);
+int __attribute__((overloadable)) fpcrtl_abs(int x);
+int64_t __attribute__((overloadable)) fpcrtl_abs(int64_t x);
+
+#endif /* PMATH_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/system.c Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,275 @@
+#include "system.h"
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <math.h>
+
+int paramCount;
+string255 params[MAX_PARAMS];
+
+double pi = M_PI;
+
+string255 fpcrtl_copy(string255 s, Integer index, Integer count) {
+ string255 result = STRINIT("");
+
+ if (count < 1) {
+ return result;
+ }
+
+ if (index < 1) {
+ index = 1;
+ }
+
+ if (index > s.len) {
+ return result;
+ }
+
+ if (index + count > s.len + 1) {
+ count = s.len + 1 - index;
+ }
+
+ memcpy(result.str, s.str + index - 1, count);
+
+ result.str[count] = 0;
+ result.len = count;
+
+ return result;
+}
+
+void fpcrtl_delete__vars(string255 *s, SizeInt index, SizeInt count) {
+ // number of chars to be move
+ int num_move;
+ int new_length;
+
+ string255 temp = *s;
+
+ if (index < 1) {
+ // in fpc, if index < 1, the string won't be modified
+ return;
+ }
+
+ if(index > s->len){
+ return;
+ }
+
+ if (count > s->len - index + 1) {
+ s->str[index - 1] = 0;
+ s->len = index - 1;
+ return;
+ }
+
+ num_move = s->len - index + 1 - count;
+ new_length = s->len - count;
+
+ memmove(s->str + index - 1, temp.str + index - 1 + count, num_move);
+ s->str[new_length] = 0;
+
+ s->len = new_length;
+
+}
+
+string255 fpcrtl_floatToStr(double n) {
+ string255 t;
+ sprintf(t.str, "%f", n);
+ t.len = strlen(t.str);
+
+ return t;
+}
+
+void fpcrtl_move__vars(void *src, void *dst, SizeInt count) {
+ memmove(dst, src, count);
+}
+
+Integer __attribute__((overloadable)) fpcrtl_pos(Char c, string255 str) {
+ string255 t;
+ t.len = 1;
+ t.str[0] = c;
+ t.str[1] = 0;
+ return fpcrtl_pos(t, str);
+}
+
+Integer __attribute__((overloadable)) fpcrtl_pos(string255 substr, string255 str) {
+
+ char* p;
+
+ FIX_STRING(substr);
+ FIX_STRING(str);
+
+ if (str.len == 0) {
+ return 0;
+ }
+
+ if (substr.len == 0) {
+ return 0;
+ }
+
+ str.str[str.len] = 0;
+ substr.str[substr.len] = 0;
+
+ p = strstr(str.str, substr.str);
+
+ if (p == NULL) {
+ return 0;
+ }
+
+ return strlen(str.str) - strlen(p) + 1;
+}
+
+Integer fpcrtl_length(string255 s) {
+ return s.len;
+}
+
+string255 fpcrtl_lowerCase(string255 s) {
+ int i;
+
+ for (i = 0; i < s.len; i++) {
+ if (s.str[i] >= 'A' && s.str[i] <= 'Z') {
+ s.str[i] += 'a' - 'A';
+ }
+ }
+
+ return s;
+}
+
+void fpcrtl_fillChar__vars(void *x, SizeInt count, Byte value) {
+ memset(x, value, count);
+}
+
+void fpcrtl_new__vars(void **p, int size) {
+ *p = malloc(size);
+}
+
+Integer fpcrtl_trunc(extended n) {
+ return (int) n;
+}
+
+LongInt str_to_int(char *src)
+{
+ int i;
+ int len = strlen(src);
+ char *end;
+ for(i = 0; i < len; i++)
+ {
+ if(src[i] == '$'){
+ // hex
+ return strtol(src + i + 1, &end, 16);
+ }
+ }
+
+ // decimal
+ return atoi(src);
+}
+void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, LongInt *a,
+ LongInt *c) {
+ *c = 0; // no error
+ FIX_STRING(s);
+ *a = str_to_int(s.str);
+}
+
+void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, Byte *a,
+ LongInt *c) {
+ *c = 0; // no error
+ FIX_STRING(s);
+ *a = str_to_int(s.str);
+}
+
+void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, LongWord *a,
+ LongInt *c) {
+ *c = 0; // no error
+ FIX_STRING(s);
+ *a = str_to_int(s.str);
+}
+
+LongInt fpcrtl_random(LongInt l) {
+ return (LongInt) (rand() / (double) RAND_MAX * l);
+}
+
+void __attribute__((overloadable)) fpcrtl_str__vars(float x, string255 *s) {
+ sprintf(s->str, "%f", x);
+ s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(double x, string255 *s) {
+ sprintf(s->str, "%f", x);
+ s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(uint8_t x, string255 *s) {
+ sprintf(s->str, "%u", x);
+ s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(int8_t x, string255 *s) {
+ sprintf(s->str, "%d", x);
+ s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(uint16_t x, string255 *s) {
+ sprintf(s->str, "%u", x);
+ s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(int16_t x, string255 *s) {
+ sprintf(s->str, "%d", x);
+ s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(uint32_t x, string255 *s) {
+ sprintf(s->str, "%u", x);
+ s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(int32_t x, string255 *s) {
+ sprintf(s->str, "%d", x);
+ s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(uint64_t x, string255 *s) {
+ sprintf(s->str, "%llu", x);
+ s->len = strlen(s->str);
+}
+void __attribute__((overloadable)) fpcrtl_str__vars(int64_t x, string255 *s) {
+ sprintf(s->str, "%lld", x);
+ s->len = strlen(s->str);
+}
+
+/*
+ * XXX No protection currently!
+ */
+void fpcrtl_interlockedIncrement__vars(int *i) {
+ (*i)++;
+}
+
+void fpcrtl_interlockedDecrement__vars(int *i) {
+ (*i)--;
+}
+
+/*
+ * This function should be called when entering main
+ */
+void fpcrtl_init(int argc, char** argv) {
+ int i;
+ paramCount = argc;
+
+ printf("ARGC = %d\n", paramCount);
+
+ for (i = 0; i < argc; i++) {
+ if (strlen(argv[i]) > 255) {
+ assert(0);
+ }
+ strcpy(params[i].str, argv[i]);
+ params[i].len = strlen(params[i].str);
+ }
+
+}
+
+int fpcrtl_paramCount() {
+ return paramCount - 1; // ignore the first one
+}
+
+string255 fpcrtl_paramStr(int i) {
+ return params[i];
+}
+
+int fpcrtl_UTF8ToUnicode(PWideChar dest, PChar src, SizeInt maxLen) {
+ //return swprintf(dest, maxLen, L"%hs", "src"); //doesn't work in emscripten
+ return 0;
+}
+
+uint32_t __attribute__((overloadable)) fpcrtl_lo(uint64_t i) {
+ return (i & 0xFFFFFFFF);
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/system.h Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,170 @@
+#ifndef SYSTEM_H_
+#define SYSTEM_H_
+
+#include <time.h>
+#include <math.h>
+#include "types.h"
+#include "misc.h"
+
+extern double pi;
+
+typedef TDate* PDate;
+
+// dimension info for dynamic arrays
+typedef struct {
+ int dim;
+ int a[4]; // at most 4
+} fpcrtl_dimension_t;
+
+/*
+ * Copy returns a string which is a copy if the Count characters in S, starting at position Index.
+ * If Count is larger than the length of the string S, the result is truncated.
+ * If Index is larger than the length of the string S, then an empty string is returned.
+ * Index is 1-based.
+ */
+string255 fpcrtl_copy(string255 s, Integer Index, Integer Count);
+
+/*
+ * Delete removes Count characters from string S, starting at position Index.
+ * All characters after the deleted characters are shifted Count positions to the left,
+ * and the length of the string is adjusted.
+ */
+#define fpcrtl_delete(s, index, count) fpcrtl_delete__vars(&(s), index, count)
+void fpcrtl_delete__vars(string255 *s, SizeInt index, SizeInt count);
+
+string255 fpcrtl_floatToStr(double n);
+
+/*
+ * Move data from one location in memory to another
+ */
+void fpcrtl_move__vars(void *src, void *dst, SizeInt count);
+#define fpcrtl_move(src, dst, count) fpcrtl_move__vars(&(src), &(dst), count);
+#define fpcrtl_Move fpcrtl_move
+
+Integer __attribute__((overloadable)) fpcrtl_pos(Char c, string255 str);
+Integer __attribute__((overloadable)) fpcrtl_pos(string255 substr, string255 str);
+
+Integer fpcrtl_length(string255 s);
+#define fpcrtl_Length fpcrtl_length
+
+#define fpcrtl_sqr(x) ((x) * (x))
+
+#define fpcrtl_odd(x) ((x) % 2 != 0 ? true : false)
+
+#define fpcrtl_StrLen strlen
+
+#define SizeOf sizeof
+
+string255 fpcrtl_lowerCase(string255 s);
+#define fpcrtl_LowerCase fpcrtl_lowerCase
+
+void fpcrtl_fillChar__vars(void *x, SizeInt count, Byte value);
+#define fpcrtl_fillChar(x, count, value) fpcrtl_fillChar__vars(&(x), count, value)
+#define fpcrtl_FillChar fpcrtl_fillChar
+
+void fpcrtl_new__vars(void **p, int size);
+#define fpcrtl_new(a) fpcrtl_new__vars((void **)&(a), sizeof(*(a)))
+
+#define fpcrtl_dispose free
+
+#define fpcrtl_freeMem(p, size) free(p)
+#define fpcrtl_FreeMem(p, size) free(p)
+
+#define fpcrtl_getMem(size) malloc(size)
+#define fpcrtl_GetMem fpcrtl_getMem
+
+#define fpcrtl_assigned(p) ((p) != NULL)
+#define fpcrtl_Assigned fpcrtl_assigned
+
+Integer fpcrtl_trunc(extended n);
+
+#define fpcrtl_val(s, a, c) fpcrtl_val__vars(s, &(a), &(c))
+void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, LongInt *a, LongInt *c);
+void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, Byte *a, LongInt *c);
+void __attribute__((overloadable)) fpcrtl_val__vars(string255 s, LongWord *a, LongInt *c);
+
+#define fpcrtl_randomize() srand(time(NULL))
+
+/*
+ * Random returns a random number larger or equal to 0 and strictly less than L
+ */
+LongInt fpcrtl_random(LongInt l);
+
+string255 fpcrtl_paramStr(LongInt);
+#define fpcrtl_ParamStr fpcrtl_paramStr
+
+/*
+ * Str returns a string which represents the value of X. X can be any numerical type.
+ */
+#define fpcrtl_str(x, s) fpcrtl_str__vars(x, &(s))
+void __attribute__((overloadable)) fpcrtl_str__vars(float x, string255 *s);
+void __attribute__((overloadable)) fpcrtl_str__vars(double x, string255 *s);
+void __attribute__((overloadable)) fpcrtl_str__vars(uint8_t x, string255 *s);
+void __attribute__((overloadable)) fpcrtl_str__vars(int8_t x, string255 *s);
+void __attribute__((overloadable)) fpcrtl_str__vars(uint16_t x, string255 *s);
+void __attribute__((overloadable)) fpcrtl_str__vars(int16_t x, string255 *s);
+void __attribute__((overloadable)) fpcrtl_str__vars(uint32_t x, string255 *s);
+void __attribute__((overloadable)) fpcrtl_str__vars(int32_t x, string255 *s);
+void __attribute__((overloadable)) fpcrtl_str__vars(uint64_t x, string255 *s);
+void __attribute__((overloadable)) fpcrtl_str__vars(int64_t x, string255 *s);
+
+void fpcrtl_interlockedIncrement__vars(int *i);
+void fpcrtl_interlockedDecrement__vars(int *i);
+
+#define fpcrtl_interlockedIncrement(i) fpcrtl_interlockedIncrement__vars(&(i))
+#define fpcrtl_interlockedDecrement(i) fpcrtl_interlockedDecrement__vars(&(i))
+
+#define fpcrtl_InterlockedIncrement fpcrtl_interlockedIncrement
+#define fpcrtl_InterlockedDecrement fpcrtl_interlockedDecrement
+
+void fpcrtl_init(int argc, char** argv);
+
+int fpcrtl_paramCount();
+#define fpcrtl_ParamCount fpcrtl_paramCount
+
+string255 fpcrtl_paramStr(int i);
+#define fpcrtl_ParamStr fpcrtl_paramStr
+
+int fpcrtl_UTF8ToUnicode(PWideChar dest, PChar src, SizeInt maxLen);
+
+#define fpcrtl_halt(t) assert(0)
+
+#define fpcrtl_Load_GL_VERSION_2_0() 1
+
+uint32_t __attribute__((overloadable)) fpcrtl_lo(uint64_t);
+#define fpcrtl_Lo fpcrtl_lo
+
+#define __SET_LENGTH2(arr, d, b) do{\
+ d.dim = 1;\
+ arr = realloc(arr, b * sizeof(typeof(*arr)));\
+ d.a[0] = b;\
+ }while(0)
+
+#define SET_LENGTH2(arr, b) __SET_LENGTH2(arr, arr##_dimension_info, (b))
+
+#define __SET_LENGTH3(arr, d, b, c) do{\
+ d.dim = 2;\
+ for (int i = 0; i < d.a[0]; i++) {\
+ arr[i] = realloc(arr[i], c * sizeof(typeof(**arr)));\
+ }\
+ if (d.a[0] > b) {\
+ for (int i = b; i < d.a[0]; i++) {\
+ free(arr[i]);\
+ }\
+ arr = realloc(arr, b * sizeof(typeof(*arr)));\
+ } else if (d.a[0] < b) {\
+ arr = realloc(arr, b * sizeof(typeof(*arr)));\
+ for (int i = d.a[0]; i < b; i++) {\
+ arr[i] = malloc(c * sizeof(typeof(**arr)));\
+ memset(arr[i], 0, c * sizeof(typeof(**arr)));\
+ }\
+ }\
+ d.a[0] = b;\
+ d.a[1] = c;\
+ }while(0)
+
+#define SET_LENGTH3(arr, b, c) __SET_LENGTH3(arr, arr##_dimension_info, (b), (c))
+
+#define fpcrtl_SetLength(...) macro_dispatcher(SET_LENGTH, __VA_ARGS__)(__VA_ARGS__)
+
+#endif /* SYSTEM_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/sysutils.c Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,176 @@
+#include "sysutils.h"
+#include "system.h"
+#include "misc.h"
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+TDateTime fpcrtl_date()
+{
+ const int num_days_between_1900_1980 = 29220;
+
+ struct tm ref_date;
+ struct tm cur_date;
+ time_t local_time;
+ time_t ref_time, cur_time;
+
+ double timeDiff;
+ double day_time_frac; //fraction that represents the time in one day
+ int num_seconds;
+ int numDays;
+
+ // unix epoch doesn't work, choose Jan 1st 1980 instead
+ ref_date.tm_year = 80;
+ ref_date.tm_mon = 0;
+ ref_date.tm_mday = 1;
+ ref_date.tm_hour = 0;
+ ref_date.tm_min = 0;
+ ref_date.tm_sec = 0;
+ ref_date.tm_isdst = 0;
+ ref_date.tm_wday = 0; // ignored
+ ref_date.tm_yday = 0; // ignored
+
+ local_time = time(NULL);
+ cur_date = *localtime(&local_time);
+
+ cur_date.tm_hour = 0;
+ cur_date.tm_min = 0;
+ cur_date.tm_sec = 0;
+
+ ref_time = mktime(&ref_date);
+ cur_time = mktime(&cur_date);
+
+ timeDiff = difftime(cur_time, ref_time);
+ numDays = fpcrtl_round(timeDiff / 3600 / 24) + num_days_between_1900_1980 + 1;
+
+ fpcrtl_printf("[date] tim diff: %f\n", timeDiff);
+ fpcrtl_printf("[date] num days between 1980 and today: %d\n", fpcrtl_round(timeDiff/3600/24));
+ fpcrtl_printf("[date] current date: %s\n", asctime(&cur_date));
+ fpcrtl_printf("[date] reference date: %s\n", asctime(&ref_date));
+ fpcrtl_printf("[date] num days: %d\n", numDays);
+
+ return numDays;
+}
+
+TDateTime fpcrtl_time()
+{
+ struct tm cur_date;
+ time_t local_time;
+ time_t cur_time;
+
+ double day_time_frac; //fraction that represents the time in one day
+ int num_seconds;
+
+ local_time = time(NULL);
+ cur_date = *localtime(&local_time);
+
+ num_seconds = cur_date.tm_hour * 3600 + cur_date.tm_min * 60 + cur_date.tm_sec;
+ day_time_frac = num_seconds / 3600.0 / 24.0;
+
+ fpcrtl_printf("%f\n", day_time_frac);
+
+ return day_time_frac;
+}
+
+TDateTime fpcrtl_now()
+{
+ return fpcrtl_date() + fpcrtl_time();
+}
+
+/*
+ * XXX: dummy
+ */
+string255 fpcrtl_formatDateTime(string255 FormatStr, TDateTime DateTime)
+{
+ string255 result = STRINIT("2012 01-01");
+ return result;
+}
+
+string255 fpcrtl_trim(string255 s)
+{
+ int left, right;
+
+ if(s.len == 0){
+ return s;
+ }
+
+ for(left = 0; left < s.len; left++)
+ {
+ if(s.str[left] != ' '){
+ break;
+ }
+ }
+
+ for(right = s.len - 1; right >= 0; right--)
+ {
+ if(s.str[right] != ' '){
+ break;
+ }
+ }
+
+ if(left > right){
+ s.len = 0;
+ s.str[0] = 0;
+ return s;
+ }
+
+ s.len = right - left + 1;
+ memmove(s.str, s.str + left, s.len);
+
+ s.str[s.len] = 0;
+
+ return s;
+}
+
+Integer fpcrtl_strToInt(string255 s)
+{
+ s.str[s.len] = 0;
+ return atoi(s.str);
+}
+
+//function ExtractFileName(const FileName: string): string;
+//var
+// i : longint;
+// EndSep : Set of Char;
+//begin
+// I := Length(FileName);
+// EndSep:=AllowDirectorySeparators+AllowDriveSeparators;
+// while (I > 0) and not (FileName[I] in EndSep) do
+// Dec(I);
+// Result := Copy(FileName, I + 1, MaxInt);
+//end;
+
+string255 fpcrtl_extractFileName(string255 f)
+{
+ const char sep[] = {'\\', '/', ':'};
+ LongInt i,j;
+
+ i = f.len - 1;
+ while(i >= 0){
+ for(j = 0; j < sizeof(sep); j++){
+ if(f.str[i] == sep[j]){
+ goto FPCRTL_EXTRACTFILENAME_END;
+ }
+ }
+ i--;
+ }
+FPCRTL_EXTRACTFILENAME_END:
+ return fpcrtl_copy(f, i + 2, 256);
+}
+
+string255 fpcrtl_strPas(PChar p)
+{
+ string255 s;
+ int l = strlen(p);
+
+ if(l > 255){
+ printf("strPas: source string length > 255\n");
+ assert(0);
+ }
+
+ s.len = l;
+ strcpy(s.str, p);
+
+ return s;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/sysutils.h Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,41 @@
+#ifndef _FPCRTL_SYSUTILS_H_
+#define _FPCRTL_SYSUTILS_H_
+
+#include "types.h"
+
+// EFFECTS: return the current date time in pascal notation
+// http://www.merlyn.demon.co.uk/del-prgg.htm#TDT
+TDateTime fpcrtl_now();
+#define now fpcrtl_now
+#define Now fpcrtl_now
+
+// EFFECTS: return the current time
+// http://www.merlyn.demon.co.uk/del-prgg.htm#TDT
+TDateTime fpcrtl_time();
+
+
+// EFFECTS: return the current date
+// http://www.merlyn.demon.co.uk/del-prgg.htm#TDT
+TDateTime fpcrtl_date();
+#define date fpcrtl_date
+#define Date fpcrtl_date
+
+// EFFECTS: Trim strips blank characters (spaces) at the beginning and end of S
+// and returns the resulting string. Only #32 characters are stripped.
+// If the string contains only spaces, an empty string is returned.
+string255 fpcrtl_trim(string255 s);
+#define trim fpcrtl_trim
+#define Trim fpcrtl_trim
+
+Integer fpcrtl_strToInt(string255 s);
+#define StrToInt fpcrtl_strToInt
+#define strToInt fpcrtl_strToInt
+
+string255 fpcrtl_extractFileName(string255 f);
+#define fpcrtl_ExtractFileName fpcrtl_extractFileName
+
+string255 fpcrtl_strPas(PChar);
+#define fpcrtl_StrPas fpcrtl_strPas
+
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/tests/check_check.c Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,23 @@
+#include <check.h>
+#include <stdlib.h>
+#include "check_check.h"
+
+int main(void)
+{
+ int number_failed;
+
+ Suite *s1 = system_suite();
+ Suite *s2 = misc_suite();
+ Suite *s3 = sysutils_suite();
+ Suite *s4 = fileio_suite();
+
+ SRunner *sr = srunner_create(s1);
+ srunner_add_suite(sr, s2);
+ srunner_add_suite(sr, s3);
+ srunner_add_suite(sr, s4);
+
+ srunner_run_all(sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed(sr);
+ srunner_free(sr);
+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/tests/check_check.h Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,9 @@
+#ifndef _CHECK_CHECK_H_
+#define _CHECK_CHECK_H_
+
+Suite *system_suite();
+Suite *misc_suite();
+Suite *sysutils_suite();
+Suite *fileio_suite();
+
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/tests/check_fileio.c Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,103 @@
+#include <check.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "check_check.h"
+#include "../src/fpcrtl.h"
+
+typedef struct __TResourceList
+{
+ Integer count;
+ string255 files[500 + 1];
+} TResourceList;
+
+string255 t = STRINIT("test");
+string255 Pathz[1] =
+{ STRINIT("../../") };
+int ptCurrTheme = 0;
+string255 cThemeCFGFilename = STRINIT("theme.cfg");
+const string255 __str79 = STRINIT("object");
+string255 c1 = STRINIT("=");
+string255 c2 = STRINIT("\x2c");
+string255 c3 = STRINIT("\x2f");
+
+static string255 make_string(const char* str)
+{
+ string255 s;
+ s.len = strlen(str);
+ memcpy(s.str, str, s.len + 1);
+ return s;
+}
+
+TResourceList readThemeCfg_0()
+{
+ TResourceList readthemecfg_result;
+ string255 s;
+ string255 key;
+ TextFile f;
+ Integer i;
+ TResourceList res;
+
+ s = _strconcat(_strappend(Pathz[ptCurrTheme], '\x2f'), cThemeCFGFilename);
+ //umisc_log(s);
+
+ fpcrtl_assign(f, s);
+
+ FileMode = 0;
+ fpcrtl_reset(f);
+
+ res.count = 0;
+ while (!(fpcrtl_eof(f)))
+ {
+ fpcrtl_readLnS(f, s);
+ if ((fpcrtl_Length(s)) == (0))
+ {
+ continue;
+ }
+ if ((s.s[1]) == ('\x3b'))
+ {
+ continue;
+ }
+ i = fpcrtl_pos('\x3d', s);
+ key = fpcrtl_trim(fpcrtl_copy(s, 1, i - 1));
+ fpcrtl_delete(s, 1, i);
+ if (_strcompare(key, __str79))
+ {
+ i = fpcrtl_pos('\x2c', s);
+ res.files[res.count] = _strconcat(
+ _strappend(Pathz[ptCurrTheme], '\x2f'),
+ fpcrtl_trim(fpcrtl_copy(s, 1, i - 1)));
+ ++res.count;
+ //umisc_log(fpcrtl_trim(fpcrtl_copy(s, 1, i - 1)));
+ }
+ }
+ fpcrtl_close(f);
+ readthemecfg_result = res;
+ return readthemecfg_result;
+}
+
+START_TEST(test_readthemecfg)
+ {
+ int i;
+ TResourceList result;
+
+ printf("-----Entering test readthemecfg-----\n");
+ result = readThemeCfg_0();
+ for (i = 0; i < result.count; i++)
+ {
+ printf("%s\n", result.files[i].str);
+ }
+ printf("-----Leaving test readthemecfg-----\n");
+ }END_TEST
+
+Suite* fileio_suite(void)
+{
+ Suite *s = suite_create("fileio");
+
+ TCase *tc_core = tcase_create("Core");
+
+ tcase_add_test(tc_core, test_readthemecfg);
+
+ suite_add_tcase(s, tc_core);
+
+ return s;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/tests/check_misc.c Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,88 @@
+#include <check.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "check_check.h"
+#include "../src/misc.h"
+
+static string255 make_string(const char* str)
+{
+ string255 s;
+ s.len = strlen(str);
+ memcpy(s.str, str, s.len + 1);
+ return s;
+}
+
+START_TEST(test_strconcat)
+{
+ string255 t;
+ t = fpcrtl_strconcat(make_string(""), make_string(""));
+ fail_if(strcmp(t.str, ""), "strconcat(\"\", \"\")");
+
+ t = fpcrtl_strconcat(make_string(""), make_string("a"));
+ fail_if(strcmp(t.str, "a"), "strconcat(\"\", \"a\")");
+
+ t = fpcrtl_strconcat(make_string("a"), make_string(""));
+ fail_if(strcmp(t.str, "a"), "strconcat(\"a\", \"\")");
+
+ t = fpcrtl_strconcat(make_string("ab"), make_string(""));
+ fail_if(strcmp(t.str, "ab"), "strconcat(\"ab\", \"\")");
+
+ t = fpcrtl_strconcat(make_string("ab"), make_string("cd"));
+ fail_if(strcmp(t.str, "abcd"), "strconcat(\"ab\", \"cd\")");
+}
+END_TEST
+
+START_TEST (test_strappend)
+{
+ string255 t;
+
+ t = fpcrtl_strappend(make_string(""), 'c');
+ fail_if(strcmp(t.str, "c"), "strappend(\"\", 'c')");
+
+ t = fpcrtl_strappend(make_string("ab"), 'c');
+ fail_if(strcmp(t.str, "abc"), "strappend(\"ab\", 'c')");
+}
+END_TEST
+
+START_TEST (test_strprepend)
+{
+ string255 t;
+
+ t = fpcrtl_strprepend('c', make_string(""));
+ fail_if(strcmp(t.str, "c"), "strprepend('c', \"\")");
+
+ t = fpcrtl_strprepend('c', make_string("ab"));
+ fail_if(strcmp(t.str, "cab"), "strprepend('c', \"ab\")");
+}
+END_TEST
+
+START_TEST (test_strcompare)
+{
+ fail_unless(fpcrtl_strcompare(make_string(""), make_string("")), "strcompare(\"\", \"\")");
+ fail_unless(fpcrtl_strcompare(make_string("a"), make_string("a")), "strcompare(\"a\", \"a\"");
+ fail_unless(!fpcrtl_strcompare(make_string("a"), make_string("b")), "strcompare(\"a\", \"b\")");
+ fail_unless(!fpcrtl_strcompare(make_string("a"), make_string("ab")), "strcompare(\"a\", \"ab\")");
+
+ fail_unless(fpcrtl_strcomparec(make_string(" "), ' '), "strcomparec(\" \", ' ')");
+ fail_unless(fpcrtl_strcomparec(make_string("a"), 'a'), "strcomparec(\"a\", 'a')");
+ fail_unless(!fpcrtl_strcomparec(make_string(" "), ' '), "strcomparec(\" \", ' '");
+ fail_unless(!fpcrtl_strcomparec(make_string(""), ' '), "strcomparec(\"\", ' ')");
+
+}
+END_TEST
+
+Suite* misc_suite(void)
+{
+ Suite *s = suite_create("misc");
+
+ TCase *tc_core = tcase_create("Core");
+
+ tcase_add_test(tc_core, test_strconcat);
+ tcase_add_test(tc_core, test_strappend);
+ tcase_add_test(tc_core, test_strprepend);
+ tcase_add_test(tc_core, test_strcompare);
+
+ suite_add_tcase(s, tc_core);
+
+ return s;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/tests/check_system.c Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,251 @@
+#include <check.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "check_check.h"
+#include "../src/system.h"
+
+void check_string(string255 str)
+{
+ fail_unless(strlen(str.str) == str.len, "String internal inconsistency error");
+}
+
+static string255 make_string(const char* str)
+{
+ string255 s;
+ s.len = strlen(str);
+ memcpy(s.str, str, s.len + 1);
+ return s;
+}
+
+START_TEST (test_copy)
+ {
+ string255 s = STRINIT("1234567");
+ string255 t;
+
+ t = fpcrtl_copy(s, 1, 1);
+ fail_if(strcmp(t.str, "1"), "Test copy fail 1");
+
+ t = fpcrtl_copy(s, 7, 1);
+ fail_if(strcmp(t.str, "7"), "Test copy fail 2");
+
+ t = fpcrtl_copy(s, 8, 1);
+ fail_if(t.len != 0, "Test copy fail 3");
+
+ t = fpcrtl_copy(s, 8, 100);
+ fail_if(t.len != 0, "Test copy fail 4");
+ check_string(t);
+
+ t = fpcrtl_copy(s, 0, 100);
+ fail_if(strcmp(t.str, "1234567"), "Test copy fail 5");
+
+ t = fpcrtl_copy(s, 0, 5);
+ fail_if(strcmp(t.str, "12345"), "Test copy fail 6");
+
+ t = fpcrtl_copy(s, 4, 100);
+ fail_if(strcmp(t.str, "4567"), "Test copy fail 7");
+
+ t = fpcrtl_copy(s, 4, 2);
+ fail_if(strcmp(t.str, "45"), "Test copy fail 8");
+ }END_TEST
+
+START_TEST (test_delete)
+ {
+ string255 s = STRINIT("1234567");
+ string255 s2 = STRINIT("1234567");
+ string255 s3 = STRINIT("1234567");
+
+ fpcrtl_delete(s, 0, 10);
+ fail_if(strcmp(s.str, "1234567"), "delete(\"1234567\", 0, 10)");
+ check_string(s);
+
+ fpcrtl_delete(s, 1, 1);
+ fail_if(strcmp(s.str, "234567"), "delete(\"1234567\", 1, 1)");
+ check_string(s);
+
+ fpcrtl_delete(s, 1, 100);
+ fail_if(strcmp(s.str, ""), "delete(\"234567\", 1, 100)");
+ check_string(s);
+
+ fpcrtl_delete(s2, 3, 2);
+ fail_if(strcmp(s2.str, "12567"), "delete(\"1234567\", 3, 2)");
+ check_string(s2);
+
+ fpcrtl_delete(s3, 3, 100);
+ fail_if(strcmp(s3.str, "12"), "delete(\"1234567\", 3, 100)");
+ check_string(s3);
+
+ }
+END_TEST
+
+START_TEST (test_FloatToStr)
+ {
+ double s = 1.2345;
+ string255 t = fpcrtl_floatToStr(s);
+ printf("-----Entering test floatToStr-----\n");
+ printf("FloatToStr(%f) = %s\n", s, t.str);
+ printf("-----Leaving test floatToStr-----\n");
+ }
+END_TEST
+
+START_TEST (test_random)
+ {
+ fpcrtl_randomize();
+ printf("-----Entering test random-----\n");
+ printf("random(5000) = %d\n", fpcrtl_random(5000));
+ printf("random(1) = %d\n", fpcrtl_random(1));
+ printf("random(2) = %d\n", fpcrtl_random(2));
+ printf("-----Leaving test random-----\n");
+
+ }
+END_TEST
+
+START_TEST (test_posS)
+ {
+ string255 substr1 = STRINIT("123");
+ string255 str1 = STRINIT("12345");
+
+ string255 substr2 = STRINIT("45");
+ string255 str2 = STRINIT("12345");
+
+ string255 substr3 = STRINIT("");
+ string255 str3 = STRINIT("12345");
+
+ string255 substr4 = STRINIT("123");
+ string255 str4 = STRINIT("");
+
+ string255 substr5 = STRINIT("123");
+ string255 str5 = STRINIT("456");
+
+ fail_unless(fpcrtl_posS(substr1, str1) == 1, "pos(123, 12345)");
+ fail_unless(fpcrtl_posS(substr2, str2) == 4, "pos(45, 12345)");
+ fail_unless(fpcrtl_posS(substr3, str3) == 0, "pos(, 12345)");
+ fail_unless(fpcrtl_posS(substr4, str4) == 0, "pos(123, )");
+ fail_unless(fpcrtl_posS(substr5, str5) == 0, "pos(123, 456)");
+ }
+END_TEST
+
+START_TEST (test_trunc)
+ {
+ fail_unless(fpcrtl_trunc(123.456) == 123, "trunc(123.456)");
+ fail_unless(fpcrtl_trunc(-123.456) == -123, "trunc(-123.456)");
+ fail_unless(fpcrtl_trunc(12.3456) == 12, "trunc(12.3456)");
+ fail_unless(fpcrtl_trunc(-12.3456) == -12, "trunc(-12.3456)");
+ }
+END_TEST
+
+START_TEST (test_odd)
+{
+ fail_unless(fpcrtl_odd(123) != 0, "odd(123)");
+ fail_unless(fpcrtl_odd(124) == 0, "odd(124)");
+ fail_unless(fpcrtl_odd(0) == 0, "odd(0)");
+ fail_unless(fpcrtl_odd(-1) != 0, "odd(-1)");
+ fail_unless(fpcrtl_odd(-2) == 0, "odd(-2)");
+}
+END_TEST
+
+START_TEST (test_sqr)
+{
+ fail_unless(fpcrtl_sqr(0) == 0, "sqr(0)");
+ fail_unless(fpcrtl_sqr(5) == 25, "sqr(5)");
+ fail_unless(fpcrtl_sqr(-5) == 25, "sqr(-5)");
+}
+END_TEST
+
+START_TEST (test_lowercase)
+{
+ string255 s1 = STRINIT("");
+ string255 s2 = STRINIT("a");
+ string255 s3 = STRINIT("abc");
+ string255 t;
+
+ t = fpcrtl_lowerCase(make_string(""));
+ fail_if(strcmp(t.str, s1.str), "lowerCase(\"\")");
+
+ t = fpcrtl_lowerCase(make_string("a"));
+ fail_if(strcmp(t.str, s2.str), "lowerCase(\"a\")");
+
+ t = fpcrtl_lowerCase(make_string("A"));
+ fail_if(strcmp(t.str, s2.str), "lowerCase(\"A\")");
+
+ t = fpcrtl_lowerCase(make_string("AbC"));
+ fail_if(strcmp(t.str, s3.str), "lowerCase(\"AbC\")");
+
+ t = fpcrtl_lowerCase(make_string("abc"));
+ fail_if(strcmp(t.str, s3.str), "lowerCase(\"abc\")");
+}
+END_TEST
+
+START_TEST (test_str)
+{
+ int8_t a1 = -8;
+ uint8_t a2 = 8;
+ int16_t a3 = -13;
+ uint16_t a4 = 13;
+ int32_t a5 = -19;
+ uint32_t a6 = 22;
+ int64_t a7 = -199999999999999;
+ uint64_t a8 = 200000000000000;
+
+ float a9 = 12345.6789;
+ double a10 = -9876.54321;
+
+ string255 s;
+
+ printf("-----Entering test str-----\n");
+
+ fpcrtl_str(a1, s);
+ printf("%d == %s\n", a1, s.str);
+
+ fpcrtl_str(a2, s);
+ printf("%u == %s\n", a2, s.str);
+
+ fpcrtl_str(a3, s);
+ printf("%d == %s\n", a3, s.str);
+
+ fpcrtl_str(a4, s);
+ printf("%u == %s\n", a4, s.str);
+
+ fpcrtl_str(a5, s);
+ printf("%d == %s\n", a5, s.str);
+
+ fpcrtl_str(a6, s);
+ printf("%u == %s\n", a6, s.str);
+
+ fpcrtl_str(a7, s);
+ printf("%lld == %s\n", a7, s.str);
+
+ fpcrtl_str(a8, s);
+ printf("%llu == %s\n", a8, s.str);
+
+ fpcrtl_str(a9, s);
+ printf("%f == %s\n", a9, s.str);
+
+ fpcrtl_str(a10, s);
+ printf("%f == %s\n", a10, s.str);
+
+ printf("-----Leaving test str------\n");
+}
+END_TEST
+
+Suite* system_suite(void)
+{
+ Suite *s = suite_create("system");
+
+ TCase *tc_core = tcase_create("Core");
+
+ tcase_add_test(tc_core, test_copy);
+ tcase_add_test(tc_core, test_FloatToStr);
+ tcase_add_test(tc_core, test_random);
+ tcase_add_test(tc_core, test_posS);
+ tcase_add_test(tc_core, test_trunc);
+ tcase_add_test(tc_core, test_delete);
+ tcase_add_test(tc_core, test_odd);
+ tcase_add_test(tc_core, test_sqr);
+ tcase_add_test(tc_core, test_lowercase);
+ tcase_add_test(tc_core, test_str);
+
+ suite_add_tcase(s, tc_core);
+
+ return s;
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/tests/check_sysutils.c Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,80 @@
+#include <check.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "check_check.h"
+#include "../src/sysutils.h"
+
+static string255 make_string(const char* str)
+{
+ string255 s;
+ s.len = strlen(str);
+ memcpy(s.str, str, s.len + 1);
+ return s;
+}
+
+static int is_string_equal(string255 s1, string255 s2)
+{
+ return (s1.len == s2.len) && (strcmp(s1.str, s2.str) == 0);
+}
+
+START_TEST (test_trim)
+{
+ string255 t;
+
+ t = fpcrtl_trim(make_string(""));
+ fail_if(strcmp(t.str, ""), "trim(\"\")");
+
+ t = fpcrtl_trim(make_string("ab"));
+ fail_if(strcmp(t.str, "ab"), "trim(\"ab\")");
+
+ t = fpcrtl_trim(make_string(" "));
+ fail_if(strcmp(t.str, ""), "trim(\" \")");
+
+ t = fpcrtl_trim(make_string(" "));
+ fail_if(strcmp(t.str, ""), "trim(\" \")");
+
+ t = fpcrtl_trim(make_string(" ab"));
+ fail_if(strcmp(t.str, "ab"), "trim(\" ab\")");
+
+ t = fpcrtl_trim(make_string("ab "));
+ fail_if(strcmp(t.str, "ab"), "trim(\"ab \")");
+
+ t = fpcrtl_trim(make_string(" ab "));
+ fail_if(strcmp(t.str, "ab"), "trim(\" ab \")");
+
+}
+END_TEST
+
+START_TEST (test_strToInt)
+{
+ fail_unless(fpcrtl_strToInt(make_string("123")) == 123, "strToInt(\"123\")");
+ fail_unless(fpcrtl_strToInt(make_string("0")) == 0, "strToInt(\"0\")");
+ fail_unless(fpcrtl_strToInt(make_string("-123")) == -123, "strToInt(\"-123\")");
+}
+END_TEST
+
+START_TEST (test_extractFileName)
+{
+ fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("abc")), make_string("abc")), "extractFileName(\"abc\")");
+ fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("a:abc")), make_string("abc")), "extractFileName(\"a:abc\")");
+ fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("/abc")), make_string("abc")), "extractFileName(\"/abc\")");
+ fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("\\abc")), make_string("abc")), "extractFileName(\"\\abc\")");
+ fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("/usr/bin/abc")), make_string("abc")), "extractFileName(\"/usr/bin/abc\")");
+ fail_unless(is_string_equal(fpcrtl_extractFileName(make_string("c:\\def\\abc")), make_string("abc")), "extractFileName(\"c:\\def\\abc\")");
+}
+END_TEST
+
+Suite* sysutils_suite(void)
+{
+ Suite *s = suite_create("sysutils");
+
+ TCase *tc_core = tcase_create("Core");
+
+ tcase_add_test(tc_core, test_trim);
+ tcase_add_test(tc_core, test_strToInt);
+ tcase_add_test(tc_core, test_extractFileName);
+
+ suite_add_tcase(s, tc_core);
+
+ return s;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/tests/fileio_test.c Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,59 @@
+
+#include "pas2c.h"
+
+#include "fpcrtl.h"
+
+char Pathz[1][128] = {"./"};
+int ptCurrTheme = 0;
+cThemeCFGFilename = "theme.cfg";
+const string255 __str79 = STRINIT("object");
+
+typedef struct __TResourceList {
+ Integer count;
+ string255 files[500 + 1];
+} TResourceList;
+
+TResourceList readThemeCfg_0()
+{
+ TResourceList readthemecfg_result;
+ string255 s;
+ string255 key;
+ TextFile f;
+ Integer i;
+ TResourceList result;
+ s = _strconcat(_strappend(Pathz[ptCurrTheme], '\x2f'), cThemeCFGFilename);
+
+ assign(f, s);
+ FileMode = 0;
+ reset(f);
+ result.count = 0;
+ while(!eof(f))
+ {
+ readLnS(f, s);
+ if((Length(s)) == (0))
+ {
+ continue;
+ }
+ if((s.s[1]) == ('\x3b'))
+ {
+ continue;
+ }
+ i = pos('\x3d', s);
+ key = trim(copy(s, 1, i - 1));
+ delete(s, 1, i);
+ if(_strcompare(key, __str79))
+ {
+ i = pos('\x2c', s);
+ result.files[result.count] = _strconcat(_strappend(Pathz[ptCurrTheme], '\x2f'), trim(copy(s, 1, i - 1)));
+ ++result.count;
+ }
+ }
+ close(f);
+ readthemecfg_result = result;
+ return readthemecfg_result;
+};
+
+int main(int argc, char** argv)
+{
+ readThemeCfg_0();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/tests/main.c Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,84 @@
+
+//#include <stdio.h>
+//#include "fpcrtl.h"
+//#include "fileio.h"
+//
+//string255 t = STRINIT("test");
+//string255 Pathz[1] = {STRINIT(".")};
+////int ptCurrTheme = 0;
+//string255 cThemeCFGFilename = STRINIT("theme.cfg");
+//const string255 __str79 = STRINIT("object");
+//string255 c1 = STRINIT("=");
+//string255 c2 = STRINIT("\x2c");
+//string255 c3 = STRINIT("\x2f");
+//
+//typedef struct __TResourceList {
+// Integer count;
+// string255 files[500 + 1];
+//} TResourceList;
+//
+//TResourceList readThemeCfg_0()
+//{
+// TResourceList readthemecfg_result;
+// string255 s;
+// string255 key;
+// TextFile f;
+// Integer i;
+// TResourceList result;
+//
+// int t = 0;
+//
+// s = _strconcat(_strappend(Pathz[ptCurrTheme], '\x2f'), cThemeCFGFilename);
+//
+// assign(&f, s);
+//
+// reset(&f);
+//
+// if(f.fp == NULL){
+// readthemecfg_result.count = 0;
+// return readthemecfg_result;
+// }
+//
+// result.count = 0;
+// while(!eof(&f))
+// {
+// readLnS(&f, &s);
+//
+// if((Length(s)) == (0))
+// {
+// continue;
+// }
+// if((s.s[1]) == ('\x3b'))
+// {
+// continue;
+// }
+//
+// i = pos(c1, s);
+//
+// key = fpcrtl_trim(fpcrtl_copy(s, 1, i - 1));
+//
+// fpcrtl_delete(&s, 1, i);
+//
+// if(_strcompare(key, __str79))
+// {
+// i = pos(c2, s);
+// result.files[result.count] = _strconcat(_strappend(Pathz[ptCurrTheme], '\x2f'), trim(copy(s, 1, i - 1)));
+// ++result.count;
+// }
+// }
+//
+// close(&f);
+// readthemecfg_result = result;
+// return readthemecfg_result;
+//}
+//
+int main(int argc, char** argv)
+{
+ int i;
+
+// TResourceList result = readThemeCfg_0();
+// for(i = 0; i < result.count; i++){
+// printf("%s\n", result.files[i].str);
+// }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/project_files/hwc/rtl/types.h Wed Nov 07 18:04:27 2012 +0000
@@ -0,0 +1,39 @@
+#ifndef _TYPES_H_
+#define _TYPES_H_
+
+#include "pas2c.h"
+
+/*
+ * Not very useful currently
+ */
+
+typedef double TDate;
+typedef double TTime;
+typedef double TDateTime;
+typedef string255 TMonthNameArray[13];
+typedef string255 TWeekNameArray[8];
+
+typedef struct {
+ Byte CurrencyFormat;
+ Byte NegCurrFormat;
+ Char ThousandSeparator;
+ Char DecimalSeparator;
+ Byte CurrencyDecimals;
+ Char DateSeparator;
+ Char TimeSeparator;
+ Char ListSeparator;
+ string255 CurrencyString;
+ string255 ShortDateFormat;
+ string255 LongDateFormat;
+ string255 TimeAMString;
+ string255 TimePMString;
+ string255 ShortTimeFormat;
+ string255 LongTimeFormat;
+ TMonthNameArray ShortMonthNames;
+ TMonthNameArray LongMonthNames;
+ TWeekNameArray ShortDayNames;
+ TWeekNameArray LongDayNames;
+ Word TwoDigitYearCenturyWindow;
+}TFormatSettings;
+
+#endif