void findSplitCommon( std::string const & filename, uint64_t const low, uint64_t const high, int64_t middle = -1 ) { if ( middle < 0 ) middle = (high+low)/2; // uint64_t const p = n/2; uint64_t const n = high-low; uint64_t const m = high-middle; std::ifstream istrn(filename.c_str(),std::ios::binary); istrn.seekg(low); std::ifstream istrm(filename.c_str(),std::ios::binary); istrm.seekg(middle); // dynamically growing best prefix table ::libmaus::util::KMP::BestPrefix<std::istream> BP(istrm,m); // adapter for accessing pattern in BP ::libmaus::util::KMP::BestPrefix<std::istream>::BestPrefixXAdapter xadapter = BP.getXAdapter(); // call KMP adaption std::pair<uint64_t, uint64_t> Q = ::libmaus::util::KMP::PREFIX_SEARCH_INTERNAL_RESTRICTED(xadapter,m,BP,istrn,n,n-m); uint64_t const showlen = std::min(Q.second,static_cast<uint64_t>(20)); std::cerr << "low=" << low << " Q.second=" << Q.second << " Q.first=" << Q.first << " middle=" << middle << " m=" << m << " pref=" << std::string(BP.x.begin(),BP.x.begin()+showlen) << std::endl; }
static lib_map_t read_lib_map(const pstring &lm) { plib::pistringstream istrm(lm); plib::putf8_reader reader(istrm); lib_map_t m; pstring line; while (reader.readline(line)) { std::vector<pstring> split(plib::psplit(line, ",")); m[split[0].trim()] = { split[1].trim(), split[2].trim() }; } return m; }
int main() { // Initialize the library DwInitialize(); // Get a buffer of data from a text file DwString buffer = ""; DwString line; ifstream istrm("exampl01.txt"); while (DwTrue) { getline(istrm, line); if (istrm.eof()) { break; } buffer += line + DW_EOL; } istrm.close(); // Create a message BasicMessage msg; // Create MIME-Version and Message-id header fields msg.SetAutomaticFields(); // Set header fields msg.SetDate(time(NULL)); msg.SetTypeStr("Text"); msg.SetSubtypeStr("Plain"); msg.SetCteStr("7bit"); msg.SetFrom("Emily Postnews <*****@*****.**>"); msg.SetTo("verbose@noisy"); msg.SetCc("forgetful@myvax"); msg.SetBcc("*****@*****.**"); msg.SetSubject("Re: How long should my signature be?"); // Set body msg.SetBody(buffer); // Write it to a file ofstream ostrm("exampl01.out"); ostrm << msg.AsString(); return 0; }
void GenericHDBRepository::nodeToCIMObject(CIMBase& cimObj, const HDBNode& node) { if (node) { DataIStream istrm(node.getDataLen(), node.getData()); cimObj.readObject(istrm); } else { cimObj.setNull(); } }
void CommandOptions::readOptionsFile(void) { wxString str; // open the file wxFileInputStream istrm(L"launch.sh"); wxTextInputStream text(istrm, wxT("\x09"), wxConvUTF8 ); while(istrm.IsOk() && !istrm.Eof() ) { str = text.ReadLine(); // skip empty lines and comments if ((str.length() > 1) && (str[0]!='#')) { break; } } if (str.length() > 1) { storedCommandLine = str.ToStdWstring(); } else { storedCommandLine = optionsToCommandLine(); } }
void load_alchemy(const std::string& filename) { // Open an input file stream std::ifstream fin(filename.c_str()); assert(fin.good()); std::string line; size_t line_number = 0; // Read the first line which should be "variable:" assert(getline(fin,line,line_number++)); line = trim(line); assert(line == "variables:"); // Read all the variables and create a map from the variable name // (string) to the variable* prl variable pointer. typedef std::map<std::string, variable_type> var_map_type; typedef var_map_type::iterator var_map_iter_type; var_map_type var_map; size_t unique_var_id = 0; while(fin.good() && getline(fin, line, line_number++) && trim(line) != "factors:") { // Separate into name and size line = trim(line); assert(line.length() > 0); size_t namelen = line.find_last_of('\t'); size_t varsize = 2; // if their is a '\t' character then the variable size follows it if(namelen != std::string::npos) { std::stringstream istrm(trim(line.substr(namelen))); istrm >> varsize; } // Get the variable name std::string var_name = trim(line.substr(0, namelen)); // Create a new finite variable in the universe variable_type variable(unique_var_id++, varsize); // Store the variable in the local variable map var_map[var_name] = variable; _var_name.push_back(var_name); assert(_var_name.size() == unique_var_id); }
inline void deserialize_from_string(const std::string &s, T &t) { boost::iostreams::stream<boost::iostreams::array_source> istrm(s.c_str(), s.length()); iarchive iarc(istrm); iarc >> t; }
//FIXME: should accept a stream as well void nl_convert_eagle_t::convert(const pstring &contents) { pistringstream istrm(contents); eagle_tokenizer tok(*this, istrm); out("NETLIST_START(dummy)\n"); add_term("GND", "GND"); add_term("VCC", "VCC"); eagle_tokenizer::token_t token = tok.get_token(); while (true) { if (token.is_type(eagle_tokenizer::ENDOFFILE)) { dump_nl(); // FIXME: Parameter out("NETLIST_END()\n"); return; } else if (token.is(tok.m_tok_SEMICOLON)) { /* ignore empty statements */ token = tok.get_token(); } else if (token.is(tok.m_tok_ADD)) { pstring name = tok.get_string(); /* skip to semicolon */ do { token = tok.get_token(); } while (!token.is(tok.m_tok_SEMICOLON)); token = tok.get_token(); pstring sval = ""; if (token.is(tok.m_tok_VALUE)) { pstring vname = tok.get_string(); sval = tok.get_string(); tok.require_token(tok.m_tok_SEMICOLON); token = tok.get_token(); } switch (name.code_at(0)) { case 'Q': { add_device("QBJT", name, sval); } break; case 'R': { double val = get_sp_val(sval); add_device("RES", name, val); } break; case 'C': { double val = get_sp_val(sval); add_device("CAP", name, val); } break; case 'P': if (sval.ucase() == "HIGH") add_device("TTL_INPUT", name, 1); else if (sval.ucase() == "LOW") add_device("TTL_INPUT", name, 0); else add_device("ANALOG_INPUT", name, sval.as_double()); add_pin_alias(name, "1", "Q"); break; case 'D': /* Pin 1 = Anode, Pin 2 = Cathode */ add_device("DIODE", name, sval); add_pin_alias(name, "1", "A"); add_pin_alias(name, "2", "K"); break; case 'U': case 'X': { pstring tname = "TTL_" + sval + "_DIP"; add_device(tname, name); break; } default: tok.error("// IGNORED " + name); } } else if (token.is(tok.m_tok_SIGNAL)) { pstring netname = tok.get_string(); token = tok.get_token(); while (!token.is(tok.m_tok_SEMICOLON)) { /* fixme: should check for string */ pstring devname = token.str(); pstring pin = tok.get_string(); add_term(netname, devname + "." + pin); token = tok.get_token(); } } else { out("Unexpected {}\n", token.str().cstr()); return; } } }
int main(int argc, char * argv[]) { try { testBorderArray(); testSuccinctBorderArray(); ::libmaus::util::ArgInfo const arginfo(argc,argv); std::string const fn = arginfo.getRestArg<std::string>(0); // std::string const fn = "1"; uint64_t const n = ::libmaus::util::GetFileSize::getFileSize(fn); uint64_t const tpacks = 128; uint64_t const packsize = (n+tpacks-1)/tpacks; uint64_t const packs = (n + packsize-1)/packsize; #if 0 && defined(_OPENMP) #pragma omp parallel for #endif for ( uint64_t i = 0; i < packs; ++i ) { uint64_t const low = std::min(i * packsize,n); uint64_t const high = std::min(low+packsize,n); findSplitCommon(fn,low,high); } } catch(std::exception const & ex) { std::cerr << ex.what() << std::endl; return EXIT_FAILURE; } #if 0 std::string const fn = "X"; uint64_t const n = ::libmaus::util::GetFileSize::getFileSize(fn); uint64_t const p = n/2; uint64_t const m = n-p; std::ifstream istrn(fn.c_str(),std::ios::binary); std::ifstream istrm(fn.c_str(),std::ios::binary); istrm.seekg(p); ::libmaus::util::KMP::BestPrefix<std::istream> BP(istrm,m); ::libmaus::util::KMP::BestPrefix<std::istream>::BestPrefixXAdapter xadapter = BP.getXAdapter(); std::pair<uint64_t, uint64_t> Q = ::libmaus::util::KMP::PREFIX_SEARCH_INTERNAL_RESTRICTED( xadapter,m,BP, istrn,n, n-m ); uint64_t const printmax = 30; if ( Q.second <= printmax ) std::cerr << "pos " << Q.first << " len " << Q.second << " p=" << p << " m=" << m << " common prefix " << std::string(BP.x.begin(),BP.x.begin()+Q.second) << std::endl; else std::cerr << "pos " << Q.first << " len " << Q.second << " p=" << p << " m=" << m << " common length " << Q.second << std::endl; istrn.clear(); istrn.seekg(Q.first); istrm.clear(); istrm.seekg(p); for ( uint64_t i = 0; i < Q.second /* std::min(Q.second, static_cast<uint64_t>(20)) */; ++i ) { int const cn = istrn.get(); int const cm = istrm.get(); assert ( cn == cm ); //std::cerr.put(cn); //std::cerr.put(cm); } // std::cerr << std::endl; int const cn = istrn.get(); int const cm = istrm.get(); assert ( (cn < 0 && cm < 0) || (cn != cm) ); if ( Q.second+1 <= m ) { istrm.clear(); istrm.seekg(p); ::libmaus::autoarray::AutoArray<char> cs(Q.second+1); istrm.read(cs.begin(),cs.size()); std::string s(cs.begin(),cs.begin()+cs.size()); if ( Q.second <= printmax ) std::cerr << "extending common prefix by next character in pattern: " << s << std::endl; istrn.clear(); istrn.seekg(0); ::libmaus::autoarray::AutoArray<char> cc(n); istrn.read(cc.begin(),n); std::string t(cc.begin(),cc.begin()+cc.size()); size_t pos = 0; while ( pos != std::string::npos ) { pos = t.find(s,pos); if ( pos != std::string::npos ) { std::cerr << "found " << pos << std::endl; pos += 1; } } } return 0; testLazyFailureFunctionRandom("abaabaababaabab"); testLazyFailureFunctionRandom("alabar_a_la_alabarda"); #endif }
int main(int argc, const char * argv[]) { Object::init(); Parser p; Object *env=Object::nil; Object *o; FUN tests[]={test0,test1,test2,test3,test4,test5}; if(argc>=1){ bool argh=false; //for help bool argt=false;//for test string argf="";//for file bool arginfo=false; for(int i=1;i<argc;i++){ string arg=string(argv[i]); if(arg[0]=='-'){ //cout<<argv[i]<<endl; if(arg=="-t"){ // argt=string(argv[i]); argt=true; }else if(arg=="-info"){ arginfo=true; }else if(arg=="--test"){ if((i+1)<argc){ int num=atoi(argv[++i]); if(num>=0&&num<sizeof(tests)/sizeof(FUN)){ return tests[num](); } } }else if(arg=="-h"||arg=="--h"||arg=="--help"||arg=="-help"){ argh=true; } }else{ argf=string(argv[i]); // cout<<"argf:"<<argf<<endl; } } if(argh){ cout<<"" <<"Lisp++ v"<<LISP_VERSION<<endl <<" Created by evil on 9/7/14."<<endl <<" Copyright (c) 2014 evilbinary.org. All rights reserved."<<endl <<" [email protected]"<<endl; cout<<"Help info:"<<endl; cout<<" "<<argv[0]<<" (direct to run interactive mode.)"<<endl;; cout<<" "<<argv[0]<<" [file] (run lisp with file.)"<<endl;; return 0; } if(argf!=""){ string line; ifstream istrm(argf.c_str()); // print_state(istrm); if(istrm.fail()){ cout<<argf<<" file not exit."<<endl; return 0; } while(true){ Object *o; Object *ret; o=p.parse(istrm); //Memory::add_root(o); //Memory::add_root(env); // cout<<" @"<<o<<endl; if(istrm.peek()==EOF&&o==Object::eob){ break; } if(arginfo){ cout<<"#input:"<<o<<endl; } if(argt==true){ //cout<<"artg=========="<<endl; //ret=o->eval(o,env); ret=o->eval2(o,env); }else{ ret=o->eval(o,env); } if(arginfo){ cout<<"#result:"; } if(ret!=Object::none){ cout<<ret<<endl; } if(arginfo){ cout<<endl; } //delete ret; } istrm.close(); // } }else{ cout<<">"; char ch; string line; int match=0; while (true) { try { char ch; //std::getline(std::cin, line); while( (ch=cin.get())!=EOF&&ch!='\n'){ // cout<<"getchar:"<<ch<<endl; if(ch=='('){ match++; }else if(ch==')'){ match--; } line+=ch; } cin.clear(); if(line!="" &&match==0){ Object *o=p.parse(line); // cout<<"begin:"<<line<<endl; // cin.clear(); //cout<<"input=";o->dprint(); // Object *ret=o->eval(o,env); Object *ret=Object::nil; if(arginfo){ cout<<"#input:"<<o<<endl; } if(argt==true){ //cout<<"artg=========="<<endl; ret=o->eval2(o,env); }else{ ret=o->eval(o,env); } if(arginfo){ cout<<"#result:"; } if(ret!=Object::none){ //cout<<ret<<endl; std::cout << ret; cout<<endl; cout<< ">"; }else if(ret==Object::eob){ std::cout << ret; cout<<endl; cout<< ">"; }else{ std::cout << ">"; } if(arginfo){ cout<<endl; } // cout<<"dprint:"; // ret->dprint(); // ret->gc(); //delete ret; line=""; } } catch (std::exception &e) { std::cout << e.what() << std::endl; } } } return 0; }else{ } return 0; }
void EOPDataStore::loadIGSFile(std::string igsFile) throw(FileMissingException) { ifstream inpf(igsFile.c_str()); if(!inpf) { FileMissingException fme("Could not open IERS file " + igsFile); GPSTK_THROW(fme); } clear(); // first we skip the header section // skip the header //version 2 //EOP SOLUTION // MJD X Y UT1-UTC LOD Xsig Ysig UTsig LODsig Nr Nf Nt Xrt Yrt Xrtsig Yrtsig dpsi deps // 10**-6" .1us .1us/d 10**-6" .1us .1us/d 10**-6"/d 10**-6"/d 10**-6 string temp; getline(inpf,temp); getline(inpf,temp); getline(inpf,temp); getline(inpf,temp); bool ok (true); while(!inpf.eof() && inpf.good()) { string line; getline(inpf,line); StringUtils::stripTrailing(line,'\r'); if(inpf.eof()) break; // line length is actually 185 if(inpf.bad() || line.size() < 120) { ok = false; break; } istringstream istrm(line); double mjd(0.0),xp(0.0),yp(0.0),UT1mUTC(0.0),dPsi(0.0),dEps(0.0); istrm >> mjd >> xp >> yp >> UT1mUTC; for(int i=0;i<12;i++) istrm >> temp; istrm >> dPsi >> dEps; xp *= 1e-6; yp *= 1e-6; UT1mUTC *= 1e-7; dPsi *= 1e-6; dEps *= 1e-6; addEOPData(MJD(mjd,TimeSystem::UTC), EOPData(xp,yp,UT1mUTC,dPsi,dEps)); }; inpf.close(); if(!ok) { FileMissingException fme("IERS File " + igsFile + " is corrupted or wrong format"); GPSTK_THROW(fme); } }
void nl_convert_rinf_t::convert(const pstring &contents) { plib::pistringstream istrm(contents); plib::putf8_reader reader(istrm); tokenizer tok(*this, reader); auto lm = read_lib_map(s_lib_map); out("NETLIST_START(dummy)\n"); add_term("GND", "GND"); add_term("VCC", "VCC"); tokenizer::token_t token = tok.get_token(); while (true) { if (token.is_type(tokenizer::ENDOFFILE) || token.is(tok.m_tok_END)) { dump_nl(); // FIXME: Parameter out("NETLIST_END()\n"); return; } else if (token.is(tok.m_tok_HEA)) { /* seems to be start token - ignore */ token = tok.get_token(); } else if (token.is(tok.m_tok_APP)) { /* version string */ pstring app = tok.get_string(); out("// APP: {}\n", app); token = tok.get_token(); } else if (token.is(tok.m_tok_TIM)) { /* time */ out("// TIM:"); for (int i=0; i<6; i++) { long x = tok.get_number_long(); out(" {}", x); } out("\n"); token = tok.get_token(); } else if (token.is(tok.m_tok_TYP)) { pstring id(tok.get_identifier()); out("// TYP: {}\n", id); token = tok.get_token(); } else if (token.is(tok.m_tok_ADDC)) { std::unordered_map<pstring, pstring> attr; pstring id = tok.get_identifier(); pstring s1 = tok.get_string(); pstring s2 = tok.get_string(); token = tok.get_token(); while (token.is(tok.m_tok_ATTC)) { pstring tid = tok.get_identifier(); if (tid != id) { out("Error: found {} expected {} in {}\n", tid, id, token.str()); return; } pstring at = tok.get_string(); pstring val = tok.get_string(); attr[at] = val; token = tok.get_token(); } pstring sim = attr["Simulation"]; pstring val = attr["Value"]; pstring com = attr["Comment"]; if (val == "") val = com; if (sim == "CAP") { add_device("CAP", id, get_sp_val(val)); } else if (sim == "RESISTOR") { add_device("RES", id, get_sp_val(val)); } else { pstring lib = attr["Library Reference"]; auto f = lm.find(lib); if (f != lm.end()) add_device(f->second.dev, id); else add_device(lib, id); } } else if (token.is(tok.m_tok_NET)) { pstring dev = tok.get_identifier(); pstring pin = tok.get_identifier_or_number(); pstring net = tok.get_string(); add_term(net, dev + "." + pin); token = tok.get_token(); if (token.is(tok.m_tok_TER)) { token = tok.get_token(); while (token.is_type(plib::ptokenizer::IDENTIFIER)) { pin = tok.get_identifier_or_number(); add_term(net, token.str() + "." + pin); token = tok.get_token(); } } } #if 0 token = tok.get_token(); /* skip to semicolon */ do { token = tok.get_token(); } while (!token.is(tok.m_tok_SEMICOLON)); token = tok.get_token(); pstring sval = ""; if (token.is(tok.m_tok_VALUE)) { pstring vname = tok.get_string(); sval = tok.get_string(); tok.require_token(tok.m_tok_SEMICOLON); token = tok.get_token(); } switch (name.code_at(0)) { case 'Q': { add_device("QBJT", name, sval); } break; case 'R': { double val = get_sp_val(sval); add_device("RES", name, val); } break; case 'C': { double val = get_sp_val(sval); add_device("CAP", name, val); } break; case 'P': if (sval.ucase() == "HIGH") add_device("TTL_INPUT", name, 1); else if (sval.ucase() == "LOW") add_device("TTL_INPUT", name, 0); else add_device("ANALOG_INPUT", name, sval.as_double()); add_pin_alias(name, "1", "Q"); break; case 'D': /* Pin 1 = Anode, Pin 2 = Cathode */ add_device("DIODE", name, sval); add_pin_alias(name, "1", "A"); add_pin_alias(name, "2", "K"); break; case 'U': case 'X': { pstring tname = "TTL_" + sval + "_DIP"; add_device(tname, name); break; } default: tok.error("// IGNORED " + name); } } else if (token.is(tok.m_tok_SIGNAL))