void appE4SMT::processFile(const QString& _inputFile, const QString &_outFile) { TargomanDebug(4,"<<<<<<<<<<<<< " + _inputFile); QFile OutFile; QTextStream OutStream(&OutFile); bool SpellCorrected; switch(gConfigs::Mode.value()){ case enuAppMode::Validate: XMLReader::isValid(_inputFile); break; case enuAppMode::Text2IXML: OPEN_OUT_STREAM("ixml"); foreach (const QString& Line, this->retrieveFileItems(_inputFile)) OutStream<<TargomanTextProcessor::instance().text2IXML( Line, SpellCorrected, gConfigs::Language.value(), 0, false, (gConfigs::NoSpellcorrector.value() ? false : true) )<<"\n"; break; case enuAppMode::IXML2Text: OPEN_OUT_STREAM("txt"); foreach (const QString& Line, this->retrieveFileItems(_inputFile)) OutStream<<TargomanTextProcessor::instance().ixml2Text( Line)<<"\n"; break; case enuAppMode::Tokenize: OPEN_OUT_STREAM("tokenized"); foreach (const QString& Line, this->retrieveFileItems(_inputFile)) OutStream<<TargomanTextProcessor::instance().ixml2Text( TargomanTextProcessor::instance().text2IXML( Line, SpellCorrected, gConfigs::Language.value(), 0, false, (gConfigs::NoSpellcorrector.value() ? false : true) ))<<"\n"; break; case enuAppMode::Normalize: OPEN_OUT_STREAM("normalized"); foreach (const QString& Line, this->retrieveFileItems(_inputFile)) OutStream<<TargomanTextProcessor::instance().normalizeText( Line, SpellCorrected, gConfigs::Language.value())<<"\n"; break; default: throw exAppE4SMT("Invalid action selected for simple input"); } TargomanDebug(4,">>>>>>>>>>>>> " << OutFile.fileName() ); }
FileID createFile(llvm::StringRef Name, llvm::StringRef Content) { llvm::SmallString<1024> Path(TemporaryDirectory.str()); llvm::sys::path::append(Path, Name); std::string ErrorInfo; llvm::raw_fd_ostream OutStream(Path.c_str(), ErrorInfo, llvm::raw_fd_ostream::F_Binary); assert(ErrorInfo.empty()); OutStream << Content; OutStream.close(); const FileEntry *File = Context.Files.getFile(Path); assert(File != NULL); return Context.Sources.createFileID(File, SourceLocation(), SrcMgr::C_User); }
void Settings::Save(QString IFileName) { QDomDocument Document; QDomElement Root = Document.createElement(XML_ROOT_TAG); Document.appendChild(Root); for(int i=0; i<UserList.length(); ++i) Root.appendChild(UserList[i].ToXML(&Document)); QFile OutputFile(IFileName); OutputFile.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream OutStream(&OutputFile); OutStream << Document.toString(); OutputFile.close(); }
bool CFuzzyMembershipFunction::Save (const char* name) { std::filebuf FileBuffer; FileBuffer.open(name,std::ios::out | std::ios::binary); if (FileBuffer.is_open()) { std::ostream OutStream(&FileBuffer); bool Result = Write(OutStream); OutStream.flush(); FileBuffer.close(); return Result; } return false; }
BOOL TDrawDocument::Commit(BOOL force) { if (!IsDirty() && !force) return TRUE; TOutStream* os = OutStream(ofWrite); if (!os) return FALSE; *os << *ecg; delete os; SetDirty(FALSE); return TRUE; }
void SettingsManager::SaveFile() { QFile NewFile(FilePath); NewFile.open(QIODevice::WriteOnly); QTextStream OutStream(&NewFile); QStringList Keys = Map.keys(); foreach(const QString &Key, Map.keys()) { OutStream << Key << "," << Map[Key] << "\n"; } NewFile.close(); }
void SettingsManager::LoadFile() { QFileInfo CheckFile(FilePath); if (CheckFile.exists() && CheckFile.isFile()) { QFile ExistingFile(FilePath); ExistingFile.open(QIODevice::ReadOnly); QTextStream InStream(&ExistingFile); while(!InStream.atEnd()) { QStringList Line = InStream.readLine().split(","); Set(Line[0], Line[1]); } ExistingFile.close(); } else { QFile NewFile(FilePath); NewFile.open(QIODevice::WriteOnly); QTextStream OutStream(&NewFile); OutStream << "RememberPos,0\n" //remember where the window is pos + size << "Size,0;0\n" << "Pos,0;0\n" << "HideWin,0\n" << "LockPos,0\n" << "HideBar,0\n" << "AutoLoad,1\n" << "LinkHistory,10\n" << "HotkeyOpen,ctrl+shift+Right\n" << "HotkeyClose,ctrl+shift+Left\n" << "HotkeyAuto,ctrl+shift+Down\n"; NewFile.close(); LoadFile(); } }
FileID createFile(llvm::StringRef Name, llvm::StringRef Content) { SmallString<1024> Path; int FD; llvm::error_code EC = llvm::sys::fs::unique_file(Twine(Name) + "%%%%%%", FD, Path); assert(!EC); (void)EC; llvm::raw_fd_ostream OutStream(FD, true); OutStream << Content; OutStream.close(); const FileEntry *File = Context.Files.getFile(Path); assert(File != NULL); StringRef Found = TemporaryFiles.GetOrCreateValue(Name, Path.str()).second; assert(Found == Path); (void)Found; return Context.Sources.createFileID(File, SourceLocation(), SrcMgr::C_User); }
//Basic Init, create the font, backbuffer, etc WINDOW *curses_init(void) { // _windows = new WINDOW[20]; //initialize all of our variables lastchar=-1; inputdelay=-1; int fontsize = 16; std::string typeface; int map_fontwidth = 8; int map_fontheight = 16; int map_fontsize = 16; std::string map_typeface; int overmap_fontwidth = 8; int overmap_fontheight = 16; int overmap_fontsize = 16; std::string overmap_typeface; bool fontblending; std::ifstream jsonstream(FILENAMES["fontdata"].c_str(), std::ifstream::binary); if (jsonstream.good()) { JsonIn json(jsonstream); JsonObject config = json.get_object(); // fontsize, fontblending, map_* are ignored in wincurse. fontwidth = config.get_int("fontwidth", fontwidth); fontheight = config.get_int("fontheight", fontheight); typeface = config.get_string("typeface", typeface); jsonstream.close(); } else { // User fontdata is missed. Try to load legacy fontdata. // Get and save all values. With unused. std::ifstream InStream(FILENAMES["legacy_fontdata"].c_str(), std::ifstream::binary); if(InStream.good()) { JsonIn jIn(InStream); JsonObject config = jIn.get_object(); fontwidth = config.get_int("fontwidth", fontwidth); fontheight = config.get_int("fontheight", fontheight); fontsize = config.get_int("fontsize", fontsize); typeface = config.get_string("typeface", typeface); map_fontwidth = config.get_int("map_fontwidth", fontwidth); map_fontheight = config.get_int("map_fontheight", fontheight); map_fontsize = config.get_int("map_fontsize", fontsize); map_typeface = config.get_string("map_typeface", typeface); overmap_fontwidth = config.get_int("overmap_fontwidth", fontwidth); overmap_fontheight = config.get_int("overmap_fontheight", fontheight); overmap_fontsize = config.get_int("overmap_fontsize", fontsize); overmap_typeface = config.get_string("overmap_typeface", typeface); InStream.close(); // Save legacy as user fontdata. assure_dir_exist(FILENAMES["config_dir"]); std::ofstream OutStream(FILENAMES["fontdata"].c_str(), std::ofstream::binary); if(!OutStream.good()) { DebugLog( D_ERROR, DC_ALL ) << "Can't save user fontdata file.\n" << "Check permissions for: " << FILENAMES["fontdata"].c_str(); return NULL; } JsonOut jOut(OutStream, true); // pretty-print jOut.start_object(); jOut.member("fontblending", fontblending); jOut.member("fontwidth", fontwidth); jOut.member("fontheight", fontheight); jOut.member("fontsize", fontsize); jOut.member("typeface", typeface); jOut.member("map_fontwidth", map_fontwidth); jOut.member("map_fontheight", map_fontheight); jOut.member("map_fontsize", map_fontsize); jOut.member("map_typeface", map_typeface); jOut.member("overmap_fontwidth", overmap_fontwidth); jOut.member("overmap_fontheight", overmap_fontheight); jOut.member("overmap_fontsize", overmap_fontsize); jOut.member("overmap_typeface", overmap_typeface); jOut.end_object(); OutStream << "\n"; OutStream.close(); } else { DebugLog( D_ERROR, DC_ALL ) << "Can't load fontdata files.\n" << "Check permissions for:\n" << FILENAMES["legacy_fontdata"].c_str() << "\n" << FILENAMES["fontdata"].c_str() << "\n"; return NULL; } } halfwidth=fontwidth / 2; halfheight=fontheight / 2; WindowWidth= OPTIONS["TERMINAL_X"] * fontwidth; WindowHeight = OPTIONS["TERMINAL_Y"] * fontheight; WinCreate(); //Create the actual window, register it, etc timeBeginPeriod(1); // Set Sleep resolution to 1ms CheckMessages(); //Let the message queue handle setting up the window WindowDC = GetDC(WindowHandle); backbuffer = CreateCompatibleDC(WindowDC); BITMAPINFO bmi = BITMAPINFO(); bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = WindowWidth; bmi.bmiHeader.biHeight = -WindowHeight; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 8; bmi.bmiHeader.biCompression = BI_RGB; // Raw RGB bmi.bmiHeader.biSizeImage = WindowWidth * WindowHeight * 1; bmi.bmiHeader.biClrUsed = 16; // Colors in the palette bmi.bmiHeader.biClrImportant = 16; // Colors in the palette backbit = CreateDIBSection(0, &bmi, DIB_RGB_COLORS, (void**)&dcbits, NULL, 0); DeleteObject(SelectObject(backbuffer, backbit));//load the buffer into DC // Load private fonts if (SetCurrentDirectoryW(L"data\\font")){ WIN32_FIND_DATA findData; for (HANDLE findFont = FindFirstFileW(L".\\*", &findData); findFont != INVALID_HANDLE_VALUE; ) { if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)){ // Skip folders AddFontResourceExW(findData.cFileName, FR_PRIVATE,NULL); } if (!FindNextFile(findFont, &findData)){ FindClose(findFont); break; } } SetCurrentDirectoryW(L"..\\.."); } // Use desired font, if possible font = CreateFontW(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, PROOF_QUALITY, FF_MODERN, widen(typeface).c_str()); SetBkMode(backbuffer, TRANSPARENT);//Transparent font backgrounds SelectObject(backbuffer, font);//Load our font into the DC // WindowCount=0; init_colors(); mainwin = newwin(OPTIONS["TERMINAL_Y"],OPTIONS["TERMINAL_X"],0,0); return mainwin; //create the 'stdscr' window and return its ref }
int creeperFrame::GetWebdata(wxString host, wxString URLpath, const char* FileName, int ConvFlag) { wxHTTP *get = new wxHTTP; size_t buf; char *InData, *OutData; wxString res; wxStringOutputStream OutStream(&res); std::fstream file; //Error Code enum { ConnectFail = 10, ConvertFail, OpenFail }; //Connet to the host/path SetStatusText(_("Loading web page.")); if( !get->Connect(host) ) { get->Abort(); SetStatusText(_("Connect Fail! Abort.")); return ConnectFail; } wxInputStream *in = get->GetInputStream(URLpath); if( get->GetError() != wxPROTO_NOERR ) { /* 0 wxPROTO_NOERR No error. 1 wxPROTO_NETERR A generic network error occurred. 2 wxPROTO_PROTERR An error occurred during negotiation. 3 wxPROTO_CONNERR The client failed to connect the server. 4 wxPROTO_INVVAL Invalid value. 5 wxPROTO_NOHNDLR . 6 wxPROTO_NOFILE The remote file doesn't exist. 7 wxPROTO_ABRT Last action aborted. 8 wxPROTO_RCNCT An error occurred during reconnection. 9 wxPROTO_STREAM Someone tried to send a command during a transfer. */ switch( get->GetError() ) { default: break; case 1: SetStatusText(_("Network error.")); break; case 2: SetStatusText(_("Negotiation error.")); break; case 3: SetStatusText(_("Connect error.")); break; case 4: SetStatusText(_("Invalid value.")); break; case 5: SetStatusText(_("No Handler.")); break; case 6: SetStatusText(_("404 File Not Found.")); break; case 7: SetStatusText(_("Last action aborted.")); break; case 8: SetStatusText(_("Reconnect error.")); break; case 9: SetStatusText(_("Transfer error")); break; } return get->GetError(); } if(ConvFlag == 1) { //store response data in 'InData' buf = in->GetSize(); InData = new char[buf]; in->Read(InData, buf); OutData = new char[buf*2]; //Converting data from big5 to utf8, if needed if( !convert("UTF-8", "BIG5", InData, buf, OutData, buf*2) ) { SetStatusText(_("Converting Failed!")); return ConvertFail; } //wxMessageBox(wxString::FromUTF8(OutData)); //Store file in filesystem file.open(FileName, std::ios::in | std::ios::out | std::ios::trunc); if( !file.is_open() ) { SetStatusText(_("Open File Error!")); return OpenFail; } file.write(OutData, buf*2); file.close(); } else { in->Read(OutStream); //wxMessageBox(res); } SetStatusText(_("Fetch file sucessfully !")); return 0; }