bool SUIManager::LoadFromString( SPString stringStream ) { SPString screensString = SPStringHelper::XMLExcludeFrom(stringStream, L"ScreenList"); stringStream = SPStringHelper::XMLRemoveFirst(stringStream, L"ScreenList"); while(screensString.size() > 0) { SPString screenString = SPStringHelper::XMLExcludeFrom(screensString, L"SUIScreen"); screensString = SPStringHelper::XMLRemoveFirst(screensString, L"SUIScreen"); SPString screenNameString = SPStringHelper::XMLExcludeFrom(screenString, L"Name"); SUIScreenPtr screen = new SUIScreen(); screen->SetName(screenNameString); AddScreen(screen); dispalyStack.push_back(screen); screen->LoadFromString(screenString); } dispalyStack.clear(); SPString displayStackString = SPStringHelper::XMLExcludeFrom(stringStream, L"DisplayStack"); stringStream = SPStringHelper::XMLRemoveFirst(stringStream, L"DisplayStack"); while(displayStackString.size() > 0) { SPString screenNameString = SPStringHelper::XMLExcludeFrom(displayStackString, L"ScreenName"); displayStackString = SPStringHelper::XMLRemoveFirst(displayStackString, L"ScreenName"); dispalyStack.push_front(GetScreen(screenNameString)); } return true; }
void SPPathHelper::MakeSurePathExist( SPString path ) { SPPointer<SPStringList> parts = SplitPath(path); SPString currentDir = (*parts)[0]; for (int i = 0; i < parts->size() - 1; i++) { CreateDirectory(currentDir.c_str(), NULL); currentDir = currentDir + L"\\" + (*parts)[i + 1]; } }
int SPString::rindex(const SPString & s, int offset) { if (offset == -1) offset = length() - s.length(); else offset = offset - s.length() + 1; if (offset > length() - s.length()) offset = length() - s.length(); for (int i = offset; i >= 0; i--) { if (strncmp(&pstr[i], s, s.length()) == 0) return i; } return -1; }
void SPWindow::SetTitle( SPString title ) { modificationLock.Lock(); SetWindowText(GetHWnd(), title.c_str()); this->title = title; modificationLock.Unlock(); }
bool SScriptManager::LoadFromString( SPString stringStream ) { SPString commandsString = SPStringHelper::XMLExcludeFrom(stringStream, L"Commands"); stringStream = SPStringHelper::XMLRemoveFirst(stringStream, L"Commands"); commands.clear(); while(commandsString.size() > 0) { SPString commandString = SPStringHelper::XMLExcludeFrom(commandsString, L"SSC"); commandsString = SPStringHelper::XMLRemoveFirst(commandsString, L"SSC"); SPString commandName = SPStringHelper::XMLExcludeFrom(commandString, L"CN"); SPString commandArgs = SPStringHelper::XMLExcludeFrom(commandString, L"Properties"); SPString commandFile = SPStringHelper::XMLExcludeFrom(commandString, L"FN"); int commandOrder = SPStringHelper::StringToInt(SPStringHelper::XMLExcludeFrom(commandString, L"OD")); SScriptCommand command(commandName, SScriptHelper::StringToVariables(commandArgs), commandFile, commandOrder); commands.push_back(command); } SPString innerVariablesString = SPStringHelper::XMLExcludeFrom(stringStream, L"InnerVariables"); stringStream = SPStringHelper::XMLRemoveFirst(stringStream, L"InnerVariables"); innerScript->SetVariableMap(SScriptHelper::StringToVariables(innerVariablesString)); SPString outerVariablesString = SPStringHelper::XMLExcludeFrom(stringStream, L"OuterVariables"); stringStream = SPStringHelper::XMLRemoveFirst(stringStream, L"OuterVariables"); script->SetVariableMap(SScriptHelper::StringToVariables(innerVariablesString)); SPString functionsString = SPStringHelper::XMLExcludeFrom(stringStream, L"Functions"); stringStream = SPStringHelper::XMLRemoveFirst(stringStream, L"Functions"); while(functionsString.size() > 0) { SPString functionString = SPStringHelper::XMLExcludeFrom(functionsString, L"F"); functionsString = SPStringHelper::XMLRemoveFirst(functionsString, L"F"); SPString functionName = SPStringHelper::XMLExcludeFrom(functionString, L"N"); SPString functionScript = SPStringHelper::XMLExcludeFrom(functionString, L"S"); AddUserDefinedFunction(functionName, new ScriptStringFunction(this, functionScript)); } return true; }
static void sp_string_read_content(SPObject *object) { SPString *string = SP_STRING(object); string->string.clear(); //XML Tree being used directly here while it shouldn't be. gchar const *xml_string = string->getRepr()->content(); // see algorithms described in svg 1.1 section 10.15 if (object->xml_space.value == SP_XML_SPACE_PRESERVE) { for ( ; *xml_string ; xml_string = g_utf8_next_char(xml_string) ) { gunichar c = g_utf8_get_char(xml_string); if ((c == 0xa) || (c == 0xd) || (c == '\t')) { c = ' '; } string->string += c; } } else { bool whitespace = false; for ( ; *xml_string ; xml_string = g_utf8_next_char(xml_string) ) { gunichar c = g_utf8_get_char(xml_string); if ((c == 0xa) || (c == 0xd)) { continue; } if ((c == ' ') || (c == '\t')) { whitespace = true; } else { if (whitespace && (!string->string.empty() || (object->getPrev() != NULL))) { string->string += ' '; } string->string += c; whitespace = false; } } if (whitespace && object->getRepr()->next() != NULL) { // can't use SPObject::getNext() when the SPObject tree is still being built string->string += ' '; } } object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); }
int SPString::index(const SPString & s, int offset) { if (offset < 0) offset = 0; for (int i = offset; i < length(); i++) { if (strncmp(&pstr[i], s, s.length()) == 0) return i; } return -1; }
bool SUIPictureManager::LoadFromString( SPString stringStream ) { SPString picturesString = SPStringHelper::XMLExcludeFrom(stringStream, L"Pictures"); stringStream = SPStringHelper::XMLRemoveFirst(stringStream, L"Pictures"); while(picturesString.size() > 0) { SPString pictureString = SPStringHelper::XMLExcludeFrom(picturesString, L"SUIPL"); picturesString = SPStringHelper::XMLRemoveFirst(picturesString, L"SUIPL"); SPString propertiesString = SPStringHelper::XMLExcludeFrom(pictureString, L"Properties"); pictureString = SPStringHelper::XMLRemoveFirst(pictureString, L"Properties"); VariableMap properties = SScriptHelper::StringToVariables(propertiesString); SScriptFunctionPtr buildPicture = new SSFPicture(); buildPicture->Function(properties, false); SPString mixImagesString = SPStringHelper::XMLExcludeFrom(pictureString, L"MPS"); pictureString = SPStringHelper::XMLRemoveFirst(pictureString, L"MPS"); SScriptFunctionPtr mixPicture = new SSFMixPicture(); while(mixImagesString.size() > 0) { SPString mixImageString = SPStringHelper::XMLExcludeFrom(mixImagesString, L"SUIMI"); mixImagesString = SPStringHelper::XMLRemoveFirst(mixImagesString, L"SUIMI"); VariableMap miProperties = SScriptHelper::StringToVariables(mixImageString); mixPicture->Function(miProperties, false); } } SPString currentPictureString = SPStringHelper::XMLExcludeFrom(stringStream, L"CurrentPictureName"); stringStream = SPStringHelper::XMLRemoveFirst(stringStream, L"CurrentPictureName"); currentPicture = GetPicture(currentPictureString); return true; }
bool SPInputManager::SetCursor( SPString path ) { SPFilePtr file = SPFileManager::GetSingleton().OpenFile(path); if (!file) { return false; } LONGLONG length = file->GetFileLength(); char* pData = new char[length]; file->Read(pData, length); wchar_t tname[10]; _wtmpnam_s(tname, 10); SPString name = SPString(tname);// + path.substr(path.find_last_of(L".") + 1); HANDLE newFile = CreateFile(name.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (newFile == INVALID_HANDLE_VALUE) { return false; } DWORD numOfByte; if(FALSE == WriteFile(newFile, pData, length, &numOfByte, NULL)) { delete [] pData; SPFileManager::GetSingleton().CloseFile(path); CloseHandle(newFile); DeleteFile(name.c_str()); return false; } CloseHandle(newFile); HCURSOR cursor = LoadCursorFromFile(name.c_str()); if (!cursor) { DWORD err = GetLastError(); delete [] pData; SPFileManager::GetSingleton().CloseFile(path); CloseHandle(newFile); DeleteFile(name.c_str()); return false; } SPWindow::GetSingleton().SetCursor(cursor); DeleteFile(name.c_str()); delete [] pData; SPFileManager::GetSingleton().CloseFile(path); //CloseHandle(newFile); return true; }
bool SScriptManager::ReadCommandsFromString( SPString stringStream ) { readCommands.Clear(); SPString readRommandsString = SPStringHelper::XMLExcludeFrom(stringStream, L"RC"); stringStream = SPStringHelper::XMLRemoveFirst(stringStream, L"RC"); while(readRommandsString.size() > 0) { SPString commandString = SPStringHelper::XMLExcludeFrom(readRommandsString, L"FR"); readRommandsString = SPStringHelper::XMLRemoveFirst(readRommandsString, L"FR"); SPString commandFileName = SPStringHelper::XMLExcludeFrom(commandString, L"FN"); SPString commandReadRegionsString = SPStringHelper::XMLExcludeFrom(commandString, L"RL"); if (commandFileName == L"") { continue; } RegionListPtr regionList = new RegionList(); while(commandReadRegionsString.size() > 0) { SPString regionString = SPStringHelper::XMLExcludeFrom(commandReadRegionsString, L"R"); commandReadRegionsString = SPStringHelper::XMLRemoveFirst(commandReadRegionsString, L"R"); int beginOrder = SPStringHelper::StringToInt(SPStringHelper::XMLExcludeFrom(regionString, L"B")); int endOrder = SPStringHelper::StringToInt(SPStringHelper::XMLExcludeFrom(regionString, L"E")); regionList->push_back(new Region(beginOrder,endOrder)); } readCommands.Set(commandFileName, regionList); } return true; }
bool SPFileHelper::CreatePath( SPString path ) { if (path.size() == 0 || path == L"/" || path == L"\\") { return true; } if(IsPathExists(path.c_str())) { return true; } if(!CreatePath(GetUpperPath(path))) { return false; } if( FALSE == CreateDirectory(path.c_str(), NULL)) { return false; } return true; }
SPString SPFileHelper::GetUpperPath( SPString path ) { SPString result1 = L""; SPString result2 = L""; if (path.find_last_of(L"\\") != wstring::npos) { result2 = path.substr(0, path.find_last_of(L"\\")); } if (path.find_last_of(L"/") != wstring::npos) { result1 = path.substr(0, path.find_last_of(L"/")); } return result1.size() > result2.size() ? result1 : result2; }
bool SPFont::Load( INT Height, UINT Width, UINT Weight, UINT MipLevels, BOOL Italic, DWORD CharSet, DWORD OutputPrecision, DWORD Quality, DWORD PitchAndFamily, SPString FontName ) { float rate = SPFontManager::GetSingleton().GetSizeRate(); if (FAILED(D3DXCreateFont( SPDevice::GetSingleton().GetD3DDevice(), Height * rate , Width * rate, Weight, MipLevels, Italic, CharSet, OutputPrecision, Quality, PitchAndFamily, FontName.c_str(), &font))) { return false; } //D3DXFONT_DESCA des; //Font->GetDescA(&des); width = Width; height = Height; weight = Weight; italic = Italic == TRUE; miplevel = MipLevels; name = FontName; return true; }
bool SPFileHelper::IsPathExists( SPString path ) { return TRUE == PathFileExists(path.c_str()); }
int main(int argc, char **argv) { char c, *infn; ifstream ini("\\win3\\win.ini"); ofstream fout("t.sty"); int ln= 0; SPString w; SPStringList l; SPStringList ttfonts; Assoc<SPString> repfnts("", ""); // saves font replacement names if(argc < 2) infn= "test.sty"; else infn= argv[1]; ifstream fin(infn); if(!ini){ cerr << "Can't open \\win3\\win.ini" << endl; exit(1); } if(!fin){ cerr << "Can't open " << infn << endl; exit(1); } if(!fout){ cerr << "Can't open t.sty for write" << endl; exit(1); } cout << "Reading in truetype fonts" << endl; while(ini >> w){ // find the [fonts] section if(w.m("\\[fonts\\]")) break; } // cout << buf << endl; if(!ini.good()){ // checks all file state cerr << "Couldn't find [fonts] section in win.ini" << endl; exit(1); } // make a list of truetype fonts Regexp r1("^([a-zA-Z ]+) \\(([a-zA-Z ]+)\\)="); Regexp r2("^TrueType$"); Regexp r3("\\[.*\\]"); while(ini >> w){ if(w.m(r3)) break; // found the start of another section if(w.m(r1, l) != 3) continue; // ignore this line // cout << "Font match:" << l[1] << ", " << l[2] << endl; if(l[2].m(r2)){ ttfonts.push(l[1]); } } cout << "ttfonts: " << endl << ttfonts << endl; ini.close(); cout << "Looking for non-truetype fonts" << endl; SPString s, fnt, newfnt; SPStringList sl; while(fin >> s){ ln++; // cout << "line " << ln << ": <" << s << ">" << endl; if(s.m("\\[fnt\\]")){ fout << s << endl; // write out [fnt] line // read next line which should have font in it if(!(fin >> s)){ cerr << "Error reading font line " << ln << endl; exit(1); } ln++; fnt= s.split("' '").join(" "); // This trims whitespace // cout << "font name: <" << fnt << ">" << endl; if(!ttfonts.grep("^" + fnt + "$", "i")){ // not a truetype font int pos= s.index(fnt); // get position in string of font if(pos < 0){ cerr << "Couldn't find <" << fnt << "> in string <" << s << "> line " << ln << endl; exit(1); } // See if we already know what to exchange it with if(repfnts.isin(fnt)) // just replace it s.substr(pos, strlen(fnt)) = repfnts(fnt); else{ // need to ask what the new font name will be do{ cout << "Replace font <" << fnt << "> with:"; cout.flush(); cin >> newfnt; if(!(sl=ttfonts.grep("^" + newfnt + "$", "i"))){ cerr << "<" << newfnt << "> is not a valid font" << endl; continue; } break; }while(1); s.substr(pos, strlen(fnt)) = sl[0]; // replace it repfnts(fnt) = sl[0]; // remember for next time } fout << s << endl; }else{
#include <iostream.h> #include <fstream.h> #include "splash.h" #include "tracer.h" #ifdef _Windows #include "../win/debugwin/debugstr.h" #define OUTSTREAM dout #else #define OUTSTREAM cout #endif ifstream fin; // Globals SPString curln, curclass; int bcnt; // current brace count /* * Reads in a line, and eliminates anything in between comments * or quotes. Also keeps count of the brace level */ int getline() { LTRACER("getline", 4) if(!(fin >> curln)) return 0; cout << curln << endl; LTRACE(2, curln) while(curln.m("\".*\"")){ // remove anything in quoted strings int o, c;
void SPString::build(SPDocument *doc, Inkscape::XML::Node *repr) { SPString* object = this; object->read_content(); SPObject::build(doc, repr); }
// // I know! This is not fast, but it works!! // int SPString::tr(const char *sl, const char *rl, const char *opts) { if (length() == 0 || strlen(sl) == 0) return 0; int cflg = strchr(opts, 'c') != NULL; // thanks Michael int dflg = strchr(opts, 'd') != NULL; int sflg = strchr(opts, 's') != NULL; int cnt = 0, flen = 0; unsigned int i; SPString t; unsigned char lstc = '\0', fr[256]; // build search array, which is a 256 byte array that stores the index+1 // in the search string for each character found, == 0 if not in search memset(fr, 0, 256); for (i = 0; i < strlen(sl); i++) { if (i && sl[i] == '-') { // got a range assert(i + 1 < strlen(sl) && lstc <= sl[i + 1]); // sanity check for (unsigned char c = lstc + 1; c <= sl[i + 1]; c++) { fr[c] = (unsigned char) ++flen; } i++; lstc = '\0'; } else { lstc = sl[i]; fr[sl[i]] = (unsigned char) ++flen; } } unsigned int rlen; // build replacement list if ((rlen = strlen(rl)) != 0) { for (i = 0; i < rlen; i++) { if (i && rl[i] == '-') { // got a range assert(i + 1 < rlen && t[t.length() - 1] <= rl[i + 1]); // sanity check for (char c = t[i - 1] + 1; c <= rl[i + 1]; c++) t += c; i++; } else t += rl[i]; } } // replacement string that is shorter uses last character for rest of // string // unless the delete option is in effect or it is empty while (!dflg && rlen && flen > t.length()) { t += t[t.length() - 1]; // duplicate last character } rlen = t.length(); // length of translation // string // do translation, and deletion if dflg (actually falls out of length of t) // also squeeze translated characters if sflg SPString tmp; // need this in case dflg, and string changes // size for (i = 0; i < (unsigned int) length(); i++) { unsigned int off; if (cflg) { // complement, ie if NOT in // f char rc = (!dflg && t.length() ? t[t.length() - 1] : '\0'); // always use last // character for // replacement if ((off = fr[(*this)[i]]) == 0) { // not in map cnt++; if (!dflg && (!sflg || tmp.length() == 0 || tmp[tmp.length() - 1] != rc)) tmp += rc; } else tmp += (*this)[i]; // just stays the same } else { // in fr so substitute with // t, if no equiv in t then // delete if ((off = fr[(*this)[i]]) > 0) { off--; cnt++; if (rlen == 0 && !dflg && (!sflg || tmp.length() == 0 || tmp[tmp.length() - 1] != (*this)[i])) tmp += (*this)[i]; // stays the same else if (off < rlen && (!sflg || tmp.length() == 0 || tmp[tmp.length() - 1] != t[off])) tmp += t[off]; // substitute } else tmp += (*this)[i]; // just stays the same } } *this = tmp; return cnt; }
bool SPXAudio::Load() { TCHAR Buffer[MAX_PATH]; GetSystemDirectory(Buffer, MAX_PATH); SPString path = SPString(Buffer) + L"\\XAudio2_7.dll"; if(PathFileExists( path.c_str()) == FALSE) { // Register xaudio SPLogHelper::WriteLog(L"[XAudio] Copying XAudio " + path ); CopyFile(L"XAudio2_7.dll", path.c_str(), TRUE); SPLogHelper::WriteLog("[XAudio] Registering XAudio ..." ); UINT result = WinExec("regsvr32.exe XAudio2_7.dll ", SW_HIDE); } //void* fnc = GetProcAddress(module, "XAudio2Create"); SPLogHelper::WriteLog("[XAudio] Initializing XAudio ..."); HRESULT hr = S_OK;//CoInitializeEx(NULL, COINIT_MULTITHREADED); if (FAILED(hr) && hr != -2147417850) { SPLogHelper::WriteLog("[XAudio] ERROR: Failed to initialize XAudio2!"); SPMessageHelper::Msg("Failed to initialize XAudio2!"); return false; } IXAudio2* pXAudio2; hr = CoCreateInstance((0 & XAUDIO2_DEBUG_ENGINE) ? __uuidof(XAudio2_Debug) : __uuidof(XAudio2), NULL, CLSCTX_INPROC_SERVER, __uuidof(IXAudio2), (void**)&pXAudio2); if (SUCCEEDED(hr)) { hr = pXAudio2->Initialize(0, XAUDIO2_DEFAULT_PROCESSOR); if (SUCCEEDED(hr)) { xAudio = pXAudio2; } else { pXAudio2->Release(); } } else { SPLogHelper::WriteLog("[XAudio] ERROR: Failed to create XAudio2! %d %d", __uuidof(IXAudio2), __uuidof(XAudio2_Debug)); } //hr = XAudio2Create( &xAudio, 0, XAUDIO2_DEFAULT_PROCESSOR ); if (FAILED(hr)) { SPLogHelper::WriteLog("[XAudio] ERROR: Failed to create XAudio2! %d %d", hr, GetLastError()); SPMessageHelper::Msg("Failed to create XAudio2!"); return false; } // Enumerate and select devices UINT32 deviceCount; xAudio->GetDeviceCount(&deviceCount); XAUDIO2_DEVICE_DETAILS deviceDetails; int preferredDevice = 0; for (unsigned int i = 0; i < deviceCount; i++) { xAudio->GetDeviceDetails(i,&deviceDetails); if (deviceDetails.OutputFormat.Format.nChannels > 2) { preferredDevice = i; break; } } // Create mastering voice device if ( FAILED(xAudio->CreateMasteringVoice( &masterVoice, XAUDIO2_DEFAULT_CHANNELS, XAUDIO2_DEFAULT_SAMPLERATE, 0, preferredDevice, NULL ) ) ) { SPLogHelper::WriteLog("[XAudio] WARNING: Failed to create Mastering Voice!"); //MessageBoxA(NULL, "Failed to create mastering voice!", NULL, NULL); Unload(); return false; } return true; }