Skip to content

Commit

Permalink
Added UTF-8 support to RuntimeError and AppTitle
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjp600 committed Apr 29, 2020
1 parent 87945c6 commit 1db8be3
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 10 deletions.
8 changes: 7 additions & 1 deletion bbruntime_dll/bbruntime_dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ using namespace std;

#include "../bbruntime/bbruntime.h"

#include "../gxruntime/gxutf8.h"

class DummyDebugger : public Debugger{
public:
virtual void debugRun(){}
Expand All @@ -25,7 +27,7 @@ class DummyDebugger : public Debugger{
virtual void debugLeave(){}
virtual void debugLog( const char *msg ){}
virtual void debugMsg( const char *e,bool serious ){
if( serious ) MessageBox( 0,e,"Error!",MB_OK|MB_TOPMOST|MB_SETFOREGROUND );
if( serious ) MessageBoxW( 0,UTF8::convertToUtf16(e).c_str(),L"Error!",MB_OK|MB_TOPMOST|MB_SETFOREGROUND );
}
virtual void debugSys( void *msg ){}
};
Expand Down Expand Up @@ -110,8 +112,10 @@ void Runtime::execute( void (*pc)(),const char *args,Debugger *dbg ){

trackmem( true );

#ifndef _DEBUG
_se_translator_function old_trans=_set_se_translator( seTranslator );
_control87( _RC_NEAR|_PC_24|_EM_INVALID|_EM_ZERODIVIDE|_EM_OVERFLOW|_EM_UNDERFLOW|_EM_INEXACT|_EM_DENORMAL,0xfffff );
#endif

//strip spaces from ends of args...
string params=args;
Expand All @@ -130,8 +134,10 @@ void Runtime::execute( void (*pc)(),const char *args,Debugger *dbg ){
gxRuntime::closeRuntime( t );
}

#ifndef _DEBUG
_control87( _CW_DEFAULT,0xfffff );
_set_se_translator( old_trans );
#endif
}

void Runtime::asyncStop(){
Expand Down
1 change: 1 addition & 0 deletions blitz/blitz.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<SccLocalPath />
<ProjectGuid>{2023B196-BA03-41D1-A771-EC49D27E48AD}</ProjectGuid>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>blitz</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
Expand Down
5 changes: 4 additions & 1 deletion blitz/blitz.vcxproj.user
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerWorkingDirectory>$(TargetDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
9 changes: 9 additions & 0 deletions blitz/libs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,17 @@ static const char *linkUserLibs(){
const char *openLibs(){

char *p=getenv( "blitzpath" );
#ifndef _DEBUG
if( !p ) return "Can't find blitzpath environment variable";
home=string(p);
#else
{
char workingDir[128];
GetCurrentDirectory(128, workingDir);
home = workingDir; home+="\\\\..";
putenv( (string("blitzpath=")+home).c_str() );
}
#endif

linkerHMOD=LoadLibrary( (home+"/bin/linker.dll").c_str() );
if( !linkerHMOD ) return "Unable to open linker.dll";
Expand Down
18 changes: 17 additions & 1 deletion blitz/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ int _cdecl main( int argc,char *argv[] ){
}
}

ifstream debugFile; debugFile.open("debug.txt", ios_base::in);
if (debugFile.good())
{
char* tmpBuf = new char[1024];
debugFile.getline(tmpBuf, 1024);
in_file = tmpBuf;
out_file = "";
delete[] tmpBuf;
debugFile.close();
debug = true;
}

if( out_file.size() && !in_file.size() ) usageErr();

if( const char *er=openLibs() ) err( er );
Expand All @@ -194,7 +206,11 @@ int _cdecl main( int argc,char *argv[] ){
if( dumpkeys ) dumpKeys( true,true,dumphelp );
if( versinfo ) versInfo();

if( !in_file.size() ) return 0;
if( !in_file.size() ){
versInfo();
showHelp();
return 0;
}

if( in_file[0]=='\"' ){
if( in_file.size()<3 || in_file[in_file.size()-1]!='\"' ) usageErr();
Expand Down
5 changes: 5 additions & 0 deletions blitz3d.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "bbruntime_dll", "bbruntime_
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "blitz", "blitz\blitz.vcxproj", "{2023B196-BA03-41D1-A771-EC49D27E48AD}"
ProjectSection(ProjectDependencies) = postProject
{41785D5A-2FD3-43A2-9469-F5D9CF927E1D} = {41785D5A-2FD3-43A2-9469-F5D9CF927E1D}
{4963165F-BF83-42DF-8F0D-D09164F4D6C0} = {4963165F-BF83-42DF-8F0D-D09164F4D6C0}
{57C1D7A8-8B56-474A-94D9-06684015BB6B} = {57C1D7A8-8B56-474A-94D9-06684015BB6B}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "blitz3d", "blitz3d\blitz3d.vcxproj", "{60BB991F-8721-4A17-9F70-79D0EE5507FA}"
EndProject
Expand Down
5 changes: 5 additions & 0 deletions debugger/debugger.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@
<ClInclude Include="stdafx.h" />
<ClInclude Include="tabber.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\gxruntime\gxruntime.vcxproj">
<Project>{a124d746-4a3b-401d-ae99-6a838595bc8c}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
6 changes: 4 additions & 2 deletions debugger/mainframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "debuggerapp.h"
#include "prefs.h"

#include "../gxruntime/gxutf8.h"

#define WM_IDLEUPDATECMDUI 0x0363 // wParam == bDisableIfNoHandler

enum{
Expand Down Expand Up @@ -204,9 +206,9 @@ void MainFrame::debugLeave(){

void MainFrame::debugMsg( const char *msg,bool serious ){
if( serious ){
::MessageBox( 0,msg,"Runtime Error",MB_OK|MB_ICONWARNING|MB_TOPMOST|MB_SETFOREGROUND );
::MessageBoxW( 0,UTF8::convertToUtf16(msg).c_str(),L"Runtime Error",MB_OK|MB_ICONWARNING|MB_TOPMOST|MB_SETFOREGROUND );
}else{
::MessageBox( 0,msg,"Runtime Message",MB_OK|MB_ICONINFORMATION|MB_TOPMOST|MB_SETFOREGROUND );
::MessageBoxW( 0,UTF8::convertToUtf16(msg).c_str(),L"Runtime Message",MB_OK|MB_ICONINFORMATION|MB_TOPMOST|MB_SETFOREGROUND );
}
}

Expand Down
1 change: 0 additions & 1 deletion debugger/prefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
Prefs prefs;

void Prefs::open(){

homeDir=getenv( "blitzpath" );

AddFontResource( (homeDir+"/cfg/blitz.fon").c_str() );
Expand Down
6 changes: 4 additions & 2 deletions gxruntime/gxfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ int gxFont::charAdvance(int chr) {
renderAtlas(chr);
it = glyphData.find(chr);
}
return it->second.horizontalAdvance;
return it != glyphData.end() ? it->second.horizontalAdvance : 0;
}

int gxFont::stringWidth(const std::string& text) {
Expand All @@ -232,7 +232,9 @@ int gxFont::stringWidth(const std::string& text) {
it = glyphData.find(chr);
}

width += it->second.horizontalAdvance;
if (it != glyphData.end()) {
width += it->second.horizontalAdvance;
}
i+=codepointLen;
}

Expand Down
4 changes: 3 additions & 1 deletion gxruntime/gxruntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "gxruntime.h"
#include "zmouse.h"

#include "../gxruntime/gxutf8.h"

struct gxRuntime::GfxMode{
DDSURFACEDESC2 desc;
};
Expand Down Expand Up @@ -649,7 +651,7 @@ bool gxRuntime::execute( const string &cmd_line ){
void gxRuntime::setTitle( const string &t,const string &e ){
app_title=t;
app_close=e;
SetWindowText( hwnd,app_title.c_str() );
SetWindowTextW( hwnd,UTF8::convertToUtf16(app_title).c_str() );
}

//////////////////
Expand Down
10 changes: 10 additions & 0 deletions gxruntime/gxutf8.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "std.h"
#include "gxutf8.h"

int UTF8::measureCodepoint(char chr) {
Expand Down Expand Up @@ -82,4 +83,13 @@ std::string UTF8::substr(const std::string& str, int start, int length) {
return str.substr(bytesStart, bytesLength);
}

std::wstring UTF8::convertToUtf16(const std::string& str) {
std::wstring result = L"";

for (int i=0;i<str.size();) {
result.push_back(decodeCharacter(str.c_str(),i));
i+=measureCodepoint(str[i]);
}

return result;
}
3 changes: 2 additions & 1 deletion gxruntime/gxutf8.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef GXUTF8_H
#define GXUTF8_H

#include "std.h"
#include <string>

class UTF8 {
private:
Expand All @@ -13,6 +13,7 @@ class UTF8 {
static int length(const std::string& str);
static int find(const std::string& str, const std::string& sstr, int from);
static std::string substr(const std::string& str, int start, int length);
static std::wstring convertToUtf16(const std::string& str);
};

#endif

0 comments on commit 1db8be3

Please sign in to comment.