int counter_service_impl::apply_checkpoint(learn_state& state, chkpt_apply_mode mode) { if (mode == CHKPT_LEARN) { recover(state.files[0], state.to_decree_included); ddebug("counter_service_impl learn checkpoint succeed, last_committed_decree = %" PRId64 "", last_committed_decree()); return ERR_OK; } else { dassert(CHKPT_COPY == mode, "invalid mode %d", (int)mode); dassert(state.to_decree_included > _last_durable_decree, "checkpoint's decree is smaller than current"); char name[256]; sprintf(name, "%s/checkpoint.%" PRId64, data_dir().c_str(), state.to_decree_included ); std::string lname(name); if (!utils::filesystem::rename_path(state.files[0], lname)) { derror("counter_service_impl copy checkpoint failed, rename path failed"); return ERR_CHECKPOINT_FAILED; } else { _last_durable_decree = state.to_decree_included; ddebug("counter_service_impl copy checkpoint succeed, last_durable_decree = %" PRId64 "", _last_durable_decree.load()); return ERR_OK; } } }
::dsn::error_code simple_kv_service_impl::apply_checkpoint(int64_t commit, const dsn_app_learn_state& state, dsn_chkpt_apply_mode mode) { if (mode == DSN_CHKPT_LEARN) { recover(state.files[0], state.to_decree_included); return ERR_OK; } else { dassert(DSN_CHKPT_COPY == mode, "invalid mode %d", (int)mode); dassert(state.to_decree_included > last_durable_decree(), "checkpoint's decree is smaller than current"); char name[256]; sprintf(name, "%s/checkpoint.%" PRId64, data_dir(), state.to_decree_included ); std::string lname(name); if (!utils::filesystem::rename_path(state.files[0], lname)) return ERR_CHECKPOINT_FAILED; else { set_last_durable_decree(state.to_decree_included); return ERR_OK; } } }
FunctionRef FunctionRef::create( TypeRef returnType, Visibility visibility, const QByteArray &name, const QVector<TypeRef> &argTypes, const QVector<QByteArray> &argNames, bool firstArgIsReturnValuePointer, ModuleRef & parent, llvm::LLVMContext* ctx ) { llvm::Type *lt = returnType.rawPtr(); std::vector<llvm::Type*> largTypes(argTypes.size()); for (int i=0; i<argTypes.size(); ++i) { llvm::Type *at = (llvm::Type*) argTypes[i].rawPtr(); largTypes[i] = at; } llvm::FunctionType * lft = largTypes.empty() ? llvm::FunctionType::get(lt, false) : llvm::FunctionType::get(lt, largTypes, false) ; llvm::GlobalValue::LinkageTypes link = VS_Extern==visibility ? llvm::GlobalValue::ExternalLinkage : llvm::GlobalValue::PrivateLinkage ; std::string lname(name.constData(), name.size()); llvm::Module *lm = (llvm::Module*) parent.rawPtr(); llvm::Function *lf = llvm::Function::Create( lft, link, lname, lm ); lf->addFnAttr(llvm::Attribute::NoUnwind); lf->addFnAttr(llvm::Attribute::UWTable); typedef llvm::Function::ArgumentListType::iterator AIt; int argNumber = 0; for (AIt it=lf->getArgumentList().begin(); argNumber<argNames.size() ; ++argNumber, ++it) { const std::string argName(argNames[argNumber].constData()); it->setName(argName); } if (firstArgIsReturnValuePointer) { llvm::Argument & firstArg = lf->getArgumentList().front(); llvm::AttrBuilder abuilder; abuilder.addAttribute(llvm::Attribute::StructRet); abuilder.addAttribute(llvm::Attribute::NoAlias); firstArg.addAttr(llvm::AttributeSet::get(*ctx, 0, abuilder)); firstArg.addAttr(llvm::AttributeSet::get(*ctx, 1, abuilder)); } FunctionRef result; result.d = (lf); return result; }
//////////////////////////////////////////////////////////////////////// // namespace resolution void RDFContentSinkImpl::RegisterNamespaces(const PRUnichar **aAttributes) { nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(mDataSource); if (!sink) { return; } NS_NAMED_LITERAL_STRING(xmlns, "http://www.w3.org/2000/xmlns/"); for (; *aAttributes; aAttributes += 2) { // check the namespace const PRUnichar* attr = aAttributes[0]; const PRUnichar* xmlnsP = xmlns.BeginReading(); while (*attr == *xmlnsP) { ++attr; ++xmlnsP; } if (*attr != 0xFFFF || xmlnsP != xmlns.EndReading()) { continue; } // get the localname (or "xmlns" for the default namespace) const PRUnichar* endLocal = ++attr; while (*endLocal && *endLocal != 0xFFFF) { ++endLocal; } nsDependentSubstring lname(attr, endLocal); nsCOMPtr<nsIAtom> preferred = do_GetAtom(lname); if (preferred == kXMLNSAtom) { preferred = nsnull; } sink->AddNameSpace(preferred, nsDependentString(aAttributes[1])); } }
void MSSM_spectrum_plotter::write_spectrum(const TSpectrum& spectrum, std::ofstream& filestr) const { for (std::size_t s = 0; s < spectrum.size(); ++s) { if (!filestr.good()) { ERROR("MSSM_spectrum_plotter::write_spectrum: " "file stream is corrupted"); break; } const std::string& name = spectrum[s].name; const std::string& latex_name = spectrum[s].latex_name; const std::valarray<double>& masses = spectrum[s].masses; const std::size_t multiplicity = masses.size(); filestr << std::left << "# " << name << '\n'; for (std::size_t i = 0; i < multiplicity; ++i) { std::string lname("$" + latex_name + "$"); std::stringstream lname_with_index; lname_with_index << "$" << latex_name; if (multiplicity > 1) lname_with_index << "_{" << (i+1) << "}"; lname_with_index << "$"; filestr << std::left << std::setw(width) << s << std::left << std::setw(width) << masses[i] << std::left << std::setw(width) << name << std::left << std::setw(2*width) << lname << std::left << std::setw(2*width) << lname_with_index.str() << '\n'; } } }
const char* Response::getheader( const char* name ) const { std::string lname( name ); std::transform( lname.begin(), lname.end(), lname.begin(), ::tolower ); std::map< std::string, std::string >::const_iterator it = m_Headers.find( lname ); if( it == m_Headers.end() ) return 0; else return it->second.c_str(); }
QString ProfilePlotView::alarmLabel(const std::string & name) { std::string lname(name); std::transform(lname.begin(), lname.end(), lname.begin(), tolower); if (lname == "ascent") return tr("Ascent Rate"); if (lname == "bookmark") return tr("Bookmark"); std::string name2(name); std::replace(name2.begin(), name2.end(), '_', ' '); return QString::fromStdString(boost::locale::to_title(name2)); }
void Opt2::EatArgv(const char *optspec, const char *long_alias) { // some flags bool require_order = false; if (*optspec == '+') { require_order = true; optspec++; } if (*optspec == '-') ythrow yexception() << "Flag '-' can not be used in Opt2's optspec"; // step 1 - parse optspec for (const char *s = optspec; *s; s++) { if (SpecsMap[(ui8)*s]) ythrow yexception() << "Symbol '" << *s << "' is met twice in Opt2's optspec"; if (*s == '?' || *s == '-') ythrow yexception() << "Opt2: Symbol '" << *s << "' can not be used in optspec because it is reserved"; Specs.push_back(Opt2Param()); SpecsMap[(ui8)*s] = (ui8)Specs.size(); // actual index + 1 Specs.back().opt = *s; if (s[1] == ':') { Specs.back().HasArg = true; if (s[2] == ':') ythrow yexception() << "Opt2 does not accept optional parameters (e.g. \"a::\") in optspec"; s++; } } // long_alias has a form "long-name1=A,long-name2=B", etc. // This implementation is limited to aliasing a single long option // with single short option (extend it if you really need). THashMap<const char*, char> long2short; long2short["help"] = '?'; long_alias = long_alias? long_alias : ""; alias_copy = long_alias; for (char *s = alias_copy.begin(); s && *s;) { char *eq = strchr(s, '='); char *comma = strchr(s, ','); if (comma) *comma = 0; if (!eq || (comma && comma < eq)) ythrow yexception() << "Opt2, long_alias: '=' is expected after " << s; *eq++ = 0; if (!*eq || eq[1]) ythrow yexception() << "Opt2, long_alias: single letter must be assigned to " << s; if (!SpecsMap[(ui8)*eq]) ythrow yexception() << "Opt2, long_alias: trying to assign unknown option '" << *eq << "' to " << s; Opt2Param &p = Specs[SpecsMap[(ui8)*eq] - 1]; // If several long options aliased to some letter, only last one is shown in usage p.LongOptName = s; if (long2short.find(s) != long2short.end()) ythrow yexception() << "Opt2, long_alias: " << s << " specified twice"; long2short[s] = *eq; s = comma? comma + 1 : nullptr; } if (Argc < 1) { HasErrors = true; return; } // step 2 - parse argv int ind = 1; for (; ind != Argc; ind++) { if (*Argv[ind] != '-') { if (require_order) // everything now goes to Pos break; Pos.push_back(Argv[ind]); continue; } const char *s = Argv[ind] + 1; if (*s == '-') { if (!*++s) { // `--' terminates the list of options ind++; break; } // long option always spans one argv (--switch or --option-name=value) const char *eq = strchr(s, '='); TString lname(s, eq ? (size_t)(eq - s) : (size_t)strlen(s)); THashMap<const char*, char>::iterator i = long2short.find(~lname); if (i == long2short.end()) { UnknownLongOption = strdup(~lname); // free'd in AutoUsage() HasErrors = true; return; } if (i->second == '?') { UnknownOption = '?'; HasErrors = true; continue; } Opt2Param &p = Specs[SpecsMap[(ui8)i->second] - 1]; p.IsFound = true; if (p.HasArg && !eq) { HasErrors = true; OptionMissingArg = p.opt; // short option, indeed return; } if (!p.HasArg && eq) { HasErrors = true; OptionWrongArg = p.opt; // short option, indeed return; } if (eq) p.ActualValue.push_back(eq + 1); continue; } for (; *s; s++) { if (!SpecsMap[(ui8)*s]) { UnknownOption = *s; HasErrors = true; if (*s == '?') continue; return; } Opt2Param &p = Specs[SpecsMap[(ui8)*s] - 1]; p.IsFound = true; if (p.HasArg) { if (s[1]) p.ActualValue.push_back(s + 1); else { ind++; if (ind == Argc) { HasErrors = true; OptionMissingArg = *s; p.IsFound = false; return; } p.ActualValue.push_back(Argv[ind]); } break; } } } for (; ind != Argc; ind++) Pos.push_back(Argv[ind]); }
//--------------------------------------------------------------------------- bool TVPSelectFile(iTJSDispatch2 *params) { // show open dialog box // NOTE: currently this only shows ANSI version of file open dialog. tTJSVariant val; char * filter = NULL; char * filename = NULL; AnsiString initialdir; AnsiString title; AnsiString defaultext; BOOL result; try { // prepare OPENFILENAME structure OPENFILENAME ofn; memset(&ofn, 0, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = TVPGetModalWindowOwnerHandle(); ofn.hInstance = NULL; // set application window position to current window position // get filter ofn.lpstrFilter = NULL; if(TJS_SUCCEEDED(params->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("filter"), 0, &val, params))) { std::vector<AnsiString> filterlist; if(val.Type() != tvtObject) { TVPPushFilterPair(filterlist, ttstr(val).AsAnsiString()); } else { iTJSDispatch2 * array = val.AsObjectNoAddRef(); tjs_int count; tTJSVariant tmp; if(TJS_SUCCEEDED(array->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("count"), 0, &tmp, array))) count = tmp; else count = 0; for(tjs_int i = 0; i < count; i++) { if(TJS_SUCCEEDED(array->PropGetByNum(TJS_MEMBERMUSTEXIST, i, &tmp, array))) { TVPPushFilterPair(filterlist, ttstr(tmp).AsAnsiString()); } } } // create filter buffer tjs_int bufsize = 2; for(std::vector<AnsiString>::iterator i = filterlist.begin(); i != filterlist.end(); i++) { bufsize += i->Length() + 1; } filter = new char[bufsize]; char *p = filter; for(std::vector<AnsiString>::iterator i = filterlist.begin(); i != filterlist.end(); i++) { strcpy(p, i->c_str()); p += i->Length() + 1; } *(p++) = 0; *(p++) = 0; ofn.lpstrFilter = filter; } ofn.lpstrCustomFilter = NULL; ofn.nMaxCustFilter = 0; if(TJS_SUCCEEDED(params->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("filterIndex"), 0, &val, params))) ofn.nFilterIndex = (tjs_int)val; else ofn.nFilterIndex = 0; // filenames filename = new char [MAX_PATH + 1]; filename[0] = 0; if(TJS_SUCCEEDED(params->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("name"), 0, &val, params))) { ttstr lname(val); if(!lname.IsEmpty()) { lname = TVPNormalizeStorageName(lname); TVPGetLocalName(lname); AnsiString name = lname.AsAnsiString(); strncpy(filename, name.c_str(), MAX_PATH); filename[MAX_PATH] = 0; } } ofn.lpstrFile = filename; ofn.nMaxFile = MAX_PATH + 1; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; // initial dir ofn.lpstrInitialDir = NULL; if(TJS_SUCCEEDED(params->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("initialDir"), 0, &val, params))) { ttstr lname(val); if(!lname.IsEmpty()) { lname = TVPNormalizeStorageName(lname); TVPGetLocalName(lname); initialdir = lname.AsAnsiString(); ofn.lpstrInitialDir = initialdir.c_str(); } } // title if(TJS_SUCCEEDED(params->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("title"), 0, &val, params))) { title = ttstr(val).AsAnsiString(); ofn.lpstrTitle = title.c_str(); } else { ofn.lpstrTitle = NULL; } // flags bool issave = false; if(TJS_SUCCEEDED(params->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("save"), 0, &val, params))) issave = val.operator bool(); ofn.Flags = OFN_ENABLEHOOK|OFN_EXPLORER|OFN_NOCHANGEDIR| OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_ENABLESIZING; if(!issave) ofn.Flags |= OFN_FILEMUSTEXIST; else ofn.Flags |= OFN_OVERWRITEPROMPT; // default extension if(TJS_SUCCEEDED(params->PropGet(TJS_MEMBERMUSTEXIST, TJS_W("defaultExt"), 0, &val, params))) { defaultext = ttstr(val).AsAnsiString(); ofn.lpstrDefExt = defaultext.c_str(); } else { ofn.lpstrDefExt = NULL; } // hook proc ofn.lpfnHook = TVPOFNHookProc; // show dialog box if(!issave) result = GetOpenFileName(&ofn); else result = GetSaveFileName(&ofn); if(!result && CommDlgExtendedError() == CDERR_STRUCTSIZE) { // for old windows // set lStructSize to old Windows' structure size ofn.lStructSize = TVP_OLD_OFN_STRUCT_SIZE; if(!issave) result = GetOpenFileName(&ofn); else result = GetSaveFileName(&ofn); } if(result) { // returns some informations // filter index val = (tjs_int)ofn.nFilterIndex; params->PropSet(TJS_MEMBERENSURE, TJS_W("filterIndex"), 0, &val, params); // file name val = TVPNormalizeStorageName(ttstr(filename)); params->PropSet(TJS_MEMBERENSURE, TJS_W("name"), 0, &val, params); } } catch(...) { if(filter) delete [] filter; if(filename) delete [] filename; throw; } delete [] filter; delete [] filename; return (bool)result; }
//------------------------------------------------- // load a game name and offset into an // indexed array //------------------------------------------------- int datfile_manager::index_datafile(dataindex &index, int &swcount) { std::string readbuf, name; size_t t_hist = TAG_HISTORY_R.size(); size_t t_story = TAG_STORY_R.size(); size_t t_sysinfo = TAG_SYSINFO_R.size(); size_t t_info = TAG_INFO.size(); size_t t_bio = TAG_BIO.size(); char rbuf[64 * 1024]; while (fgets(rbuf, 64 * 1024, fp) != nullptr) { readbuf = chartrimcarriage(rbuf); if (m_history_rev.empty() && readbuf.compare(0, t_hist, TAG_HISTORY_R) == 0) { size_t found = readbuf.find(" ", t_hist + 1); m_history_rev = readbuf.substr(t_hist + 1, found - t_hist); } else if (m_sysinfo_rev.empty() && readbuf.compare(0, t_sysinfo, TAG_SYSINFO_R) == 0) { size_t found = readbuf.find(".", t_sysinfo + 1); m_sysinfo_rev = readbuf.substr(t_sysinfo + 1, found - t_sysinfo); } else if (m_story_rev.empty() && readbuf.compare(0, t_story, TAG_STORY_R) == 0) m_story_rev = readbuf.substr(t_story + 1); // TAG_INFO identifies the driver else if (readbuf.compare(0, t_info, TAG_INFO) == 0) { int curpoint = t_info + 1; int ends = readbuf.size(); while (curpoint < ends) { // search for comma size_t found = readbuf.find(",", curpoint); // found it if (found != std::string::npos) { // copy data and validate driver name = readbuf.substr(curpoint, found - curpoint); // validate driver int game_index = driver_list::find(name.c_str()); if (game_index != -1) index.emplace(&driver_list::driver(game_index), ftell(fp)); // update current point curpoint = ++found; } // if comma not found, copy data while until reach the end of string else if (curpoint < ends) { name = readbuf.substr(curpoint); int game_index = driver_list::find(name.c_str()); if (game_index != -1) index.emplace(&driver_list::driver(game_index), ftell(fp)); // update current point curpoint = ends; } } } // search for software info else if (!readbuf.empty() && readbuf[0] == DATAFILE_TAG[0]) { fgets(rbuf, 64 * 1024, fp); std::string readbuf_2(chartrimcarriage(rbuf)); // TAG_BIO identifies software list if (readbuf_2.compare(0, t_bio, TAG_BIO) == 0) { size_t eq_sign = readbuf.find("="); std::string s_list(readbuf.substr(1, eq_sign - 1)); std::string s_roms(readbuf.substr(eq_sign + 1)); int ends = s_list.size(); int curpoint = 0; while (curpoint < ends) { size_t found = s_list.find(",", curpoint); // found it if (found != std::string::npos) { name = s_list.substr(curpoint, found - curpoint); curpoint = ++found; } else { name = s_list; curpoint = ends; } // search for a software list in the index, if not found then allocates std::string lname(name); int cpoint = 0; int cends = s_roms.size(); while (cpoint < cends) { // search for comma size_t found = s_roms.find(",", cpoint); // found it if (found != std::string::npos) { // copy data name = s_roms.substr(cpoint, found - cpoint); // add a SoftwareItem m_swindex[lname].emplace(name, ftell(fp)); // update current point cpoint = ++found; swcount++; } else { // if reach the end, bail out if (s_roms[cpoint] == '\r' || s_roms[cpoint] == '\n') break; // copy data name = s_roms.substr(cpoint); // add a SoftwareItem m_swindex[lname].emplace(name, ftell(fp)); // update current point cpoint = cends; swcount++; } } } } } } return index.size(); }
static void create_locale (std::string std_src, std::string std_cmap, std::string outdir, std::string std_locale, bool force_output, bool use_ucs, bool no_position, bool link_aliases) { // extract the names of the locale and of the codeset std::string lname (std_src); std::string cname (std_cmap); if (lname.rfind(_RWSTD_PATH_SEP) != std::string::npos) lname = lname.substr(lname.rfind(_RWSTD_PATH_SEP) + 1, lname.size()); if (cname.rfind(_RWSTD_PATH_SEP) != std::string::npos) cname = cname.substr(cname.rfind(_RWSTD_PATH_SEP) + 1, cname.size()); if (lname.find('.') != std::string::npos) lname = lname.substr(0, lname.find('.')); if (cname.find('.') != std::string::npos) cname = cname.substr(0, cname.find('.')); // the vector of corresponding C locales StringVector C_locales; #ifndef _MSC_VER get_same_encoding_C_locale (lname, cname, C_locales); #endif // _MSC_VER // C library locale using same encoding std::string enc_C_locale; #ifdef _RWSTD_NO_ISO_10646_WCHAR_T // the encoding C locale enc_C_locale = get_C_encoding_locale (cname); // platforms with locale dependant wchar_t encodings need the current // C locale to be set. If there is no C locale with the same name // or that uses the same encoding as the locale we are creating // issue warning if (enc_C_locale.empty ()) { issue_diag (W_COMPAT, false, 0, "no compatible locale found\n"); } else std::setlocale (LC_ALL, enc_C_locale.c_str ()); #endif // _RWSTD_NO_ISO_10646_WCHAR_T // if no charmap is present assume ISO-8859-1 if (std_cmap.empty ()) std_cmap = "ISO-8859-1"; // retrieve UTF-8 encoding aliases std::string utf8_cname("UTF-8"); StringVector utf8_aliases; get_cname_aliases (utf8_cname, utf8_aliases); // is it a UTF-8 encoded locale? bool is_utf8 = false; StringVector::iterator pos = utf8_aliases.begin(); for (; pos != utf8_aliases.end (); pos++) if (ci_compare (cname, *pos) == 0) { is_utf8 = true; break; } // retrieve the charmap/codeset object Charmap* charmap_p = 0; std::vector <Charmap*>::iterator charmaps_it = charmaps.begin(); for (; charmaps_it != charmaps.end(); charmaps_it++){ if ((*charmaps_it)->get_full_charmap_name() == std_cmap) { charmap_p = *charmaps_it; break; } } // if none found, create one and parse the corresponding file if (0 == charmap_p) { issue_diag (I_STAGE, false, 0, "processing character set description file %s\n", std_cmap.c_str ()); charmap_p = new Charmap (enc_C_locale.c_str (), std_cmap.c_str (), is_utf8, true, true, use_ucs); charmaps.push_back (charmap_p); } // parse the source definition files bool def_error = false; issue_diag (I_STAGE, false, 0, "processing locale definition file %s\n", std_src.c_str ()); Def def (std_src.c_str (), (outdir + std_locale).c_str (), *charmap_p, no_position); try { // try to parse the input files def.process_input (); } catch (...) { def_error = true; } // create the locale directory std::string locale_dir (outdir + std_locale); makedir (locale_dir.c_str ()); if (def_error) { // write out the codecvt database and exit if parsing failed def.write_codecvt (locale_dir); throw loc_exception ("abort."); } // no output when it hasn't been forced and warnings were present if (!force_output && def.warnings_occurred_) { std::cerr << "Warnings occurred - No output produced\n"; return; } // and write out the locale categories data issue_diag (I_STAGE, false, 0, "generating LC_CTYPE database\n"); def.write_ctype (locale_dir); issue_diag (I_STAGE, false, 0, "generating codeset database\n"); def.write_codecvt (locale_dir); issue_diag (I_STAGE, false, 0, "generating LC_MONETARY database\n"); def.write_monetary (locale_dir); issue_diag (I_STAGE, false, 0, "generating LC_NUMERIC database\n"); def.write_numeric (locale_dir); issue_diag (I_STAGE, false, 0, "generating LC_TIME database\n"); def.write_time (locale_dir); issue_diag (I_STAGE, false, 0, "generating LC_COLLATE database\n"); def.write_collate (locale_dir); #ifndef _MSC_VER issue_diag (I_STAGE, false, 0, "generating LC_MESSAGES database\n"); def.write_messages (locale_dir); #endif // _MSC_VER // no C library locales equivalents if (C_locales.empty ()) return; #if !defined (_MSC_VER) if (link_aliases == false) return; // some corresponding C lib locale names where found for this name StringVector::iterator it = C_locales.begin (); for (; it != C_locales.end (); it++) { // check if the name actually exists if (*it == std_locale) continue; // set a symlink with the name of the C lib locale // pointing to our locale database create_symlink (outdir, std_locale, *it); } #endif // _MSC_VER }