Slightly better strategy to convert C strings to Pascal-style ones.

This commit is contained in:
DarwinNE 2020-01-16 00:11:56 +01:00
parent 9cf5c41ad7
commit 5f30a05a34
3 changed files with 19 additions and 7 deletions

View File

@ -12,7 +12,7 @@ int main()
std::string out = "\033]0;Hello world win\007Hello, \033[1mexternal world of \033[0m\033[3mtrue beauty and \033[4mgreatness\033[0m.\nEnter \"exit\" to quit.\n";
//std::string out = "Hello, \033[1mexternal world of \033[0m\033[3mtrue beauty and \033[4mgreatness\033[0m.\nEnter \"exit\" to quit.\n";
retro::Console::currentInstance->write(out.data(), out.size());
std::string in;
do
{

View File

@ -270,7 +270,7 @@ void Console::ProcessOSCseq(char c)
switch(sequenceStep)
{
case 1:
if(c!='0') // The only recognized sequence is OSC 0;
if(c!='0') // The only recognized sequence is OSC 0;
{
OSCseq=false;
sequenceStep=0;
@ -279,7 +279,7 @@ void Console::ProcessOSCseq(char c)
++sequenceStep;
break;
case 2:
if(c!=';') // The only recognized sequence is OSC 0;
if(c!=';') // The only recognized sequence is OSC 0;
{
OSCseq=false;
sequenceStep=0;
@ -333,7 +333,7 @@ void Console::ProcessEscSequence(char c)
{
OSCseq=true;
++sequenceStep;
}
}
else
{
isProcessingEscSequence=false;

View File

@ -24,6 +24,7 @@
#include "ConsoleWindow.h"
#include "Events.h"
#include <unordered_map>
#include <cstring>
using namespace retro;
@ -67,9 +68,20 @@ ConsoleWindow::~ConsoleWindow()
void ConsoleWindow::setWindowName(std::string newName)
{
newName=" "+newName; // Convert into Pascal string
newName[0]=newName.length();
SetWTitle(win, (ConstStringPtr)newName.c_str());
Str255 pname;
#if TARGET_API_MAC_CARBON
// Carbon has the new, sane version.
c2pstrcpy(pname,newName.c_str());
#else
// It is also availble in various glue code libraries and
// in some versions of InterfaceLib, but it's confusing.
// Using the inplace variant, c2pstr, isn't much better than
// doing things by hand:
strncpy((char *)&pname[1],newName.c_str(),255);
pname[0] = newName.length();
#endif
SetWTitle(win, pname);
}