void pstringbuffer::pcat(const pstring &s) { const std::size_t slen = s.blen(); const std::size_t nl = m_len + slen + 1; resize(nl); std::copy(s.c_str(), s.c_str() + slen, m_ptr + m_len); m_len += slen; m_ptr[m_len] = 0; }
pofilestream::pofilestream(const pstring &fname) : postream(0), m_file(fopen(fname.c_str(), "wb")), m_pos(0), m_actually_close(true), m_filename(fname) { if (m_file == nullptr) throw file_open_e(m_filename); init(); }
void netlist_tool_t::vlog(const plib::plog_level &l, const pstring &ls) const { pstring err = plib::pfmt("{}: {}\n")(l.name())(ls.c_str()); // FIXME: ... m_app.pout("{}", err); if (l == plib::plog_level::FATAL) throw netlist::nl_exception(err); }
input_t(const netlist::setup_t &setup, const pstring &line) { char buf[400]; double t; int e = sscanf(line.c_str(), "%lf,%[^,],%lf", &t, buf, &m_value); if (e != 3) throw netlist::nl_exception(plib::pfmt("error {1} scanning line {2}\n")(e)(line)); m_time = netlist::netlist_time::from_double(t); m_param = setup.find_param(pstring(buf, pstring::UTF8), true); }
input_t(const netlist::setup_t &setup, const pstring &line) : m_value(0.0) { std::array<char, 400> buf; // NOLINT(cppcoreguidelines-pro-type-member-init) double t; // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) int e = sscanf(line.c_str(), "%lf,%[^,],%lf", &t, buf.data(), &m_value); if (e != 3) throw netlist::nl_exception(plib::pfmt("error {1} scanning line {2}\n")(e)(line)); m_time = netlist::netlist_time::from_double(t); m_param = setup.find_param(pstring(buf.data()), true); }
void vlog(const plib::plog_level &l, const pstring &ls) const override { switch (l) { case plib::plog_level::DEBUG: break; case plib::plog_level::VERBOSE: break; case plib::plog_level::INFO: osd_printf_verbose("netlist INFO: %s\n", ls.c_str()); break; case plib::plog_level::WARNING: osd_printf_warning("netlist WARNING: %s\n", ls.c_str()); break; case plib::plog_level::ERROR: osd_printf_error("netlist ERROR: %s\n", ls.c_str()); break; case plib::plog_level::FATAL: throw emu_fatalerror(1, "netlist FATAL: %s\n", ls.c_str()); } }
double nl_convert_base_t::get_sp_unit(const pstring &unit) { int i = 0; while (pstring(m_units[i].m_unit, pstring::UTF8) != "-") { if (pstring(m_units[i].m_unit, pstring::UTF8) == unit) return m_units[i].m_mult; i++; } fprintf(stderr, "Unit %s unknown\n", unit.c_str()); return 0.0; }
void netlist_tool_callbacks_t::vlog(const plib::plog_level &l, const pstring &ls) const { pstring err = plib::pfmt("{}: {}\n")(l.name())(ls.c_str()); if (l == plib::plog_level::WARNING) m_app.m_warnings++; if (l == plib::plog_level::ERROR) m_app.m_errors++; if (l == plib::plog_level::FATAL) { m_app.m_errors++; throw netlist::nl_exception(err); } else m_app.pout("{}", err); }
void AgentProgram::save(const pstring& filename) { // standard ascii: ofstream file(filename.c_str()); file << "Destination selection: "; switch (m_sel_type) { case SEL_STANDARD: file << "Standard" << endl; break; case SEL_LENGTH: file << "Gibsonian Length" << endl; break; case SEL_OPTIC_FLOW: file << "Gibsonian Optic Flow" << endl; break; case SEL_COMPARATIVE_LENGTH: file << "Gibsonian Comparative Length" << endl; break; case SEL_COMPARATIVE_OPTIC_FLOW: file << "Gibsonian Comparative Optic Flow" << endl; break; default: file << "Unknown" << endl; } file << "Steps: " << m_steps << endl; file << "Bins: " << ((m_vbin == -1) ? 32 : m_vbin * 2 + 1) << endl; /* file << "Ahead bins: " << m_vahead * 2 + 1 << endl; file << "Ahead threshold: " << m_ahead_threshold << endl; file << "Feeler threshold: " << m_feeler_threshold << endl; file << "Feeler probability: " << m_feeler_probability << endl; */ file << "Rule order: " << m_rule_order[0] << " " << m_rule_order[1] << " " << m_rule_order[2] << " " << m_rule_order[3] << endl; for (int i = 0; i < 4; i++) { file << "Rule " << i << " (Bin -" << 1 + (i * 2) << "/+" << 1 + (i * 2) << ")" << endl; file << "Threshold: " << m_rule_threshold[i] << endl; file << "Turn Probability: " << m_rule_probability[i] << endl; } file << "Fitness: " << m_fitness << endl; }
bool AgentProgram::open(const pstring& filename) { // standard ascii: ifstream file(filename.c_str()); pstring line; file >> line; if (!line.empty()) { line.makelower(); if (!compare(line,"destination selection:",22)) { return false; } else { pstring method = line.substr(22); method.ltrim(); if (!method.empty()) { if (method == "standard") { m_sel_type = SEL_STANDARD; } else if (method == "gibsonian length") { m_sel_type = SEL_LENGTH; } else if (method == "gibsonian optic flow") { m_sel_type = SEL_OPTIC_FLOW; } else if (method == "gibsonian comparative length") { m_sel_type = SEL_COMPARATIVE_LENGTH; } else if (method == "gibsonian comparative optic flow") { m_sel_type = SEL_COMPARATIVE_OPTIC_FLOW; } file >> line; } else { return false; } }
void vlog(const plib::plog_level &l, const pstring &ls) const override { switch (l) { case plib::plog_level::DEBUG: m_parent.logerror("netlist DEBUG: %s\n", ls.c_str()); break; case plib::plog_level::VERBOSE: m_parent.logerror("netlist VERBOSE: %s\n", ls.c_str()); break; case plib::plog_level::INFO: m_parent.logerror("netlist INFO: %s\n", ls.c_str()); break; case plib::plog_level::WARNING: m_parent.logerror("netlist WARNING: %s\n", ls.c_str()); break; case plib::plog_level::ERROR: m_parent.logerror("netlist ERROR: %s\n", ls.c_str()); break; case plib::plog_level::FATAL: throw emu_fatalerror(1, "netlist FATAL: %s\n", ls.c_str()); } }
void nl_convert_rinf_t::tokenizer::verror(const pstring &msg, int line_num, const pstring &line) { m_convert.out("{} (line {}): {}\n", msg.c_str(), line_num, line.c_str()); }
void nl_convert_spice_t::process_line(const pstring &line) { if (line != "") { //printf("// %s\n", line.c_str()); std::vector<pstring> tt(plib::psplit(line, " ", true)); double val = 0.0; switch (tt[0].at(0)) { case ';': out("// {}\n", line.substr(1)); break; case '*': out("// {}\n", line.substr(1).c_str()); break; case '.': if (tt[0] == ".SUBCKT") { m_subckt = tt[1] + "_"; out("NETLIST_START({})\n", tt[1]); for (std::size_t i=2; i<tt.size(); i++) add_ext_alias(tt[i]); } else if (tt[0] == ".ENDS") { dump_nl(); out("NETLIST_END()\n"); m_subckt = ""; } else if (tt[0] == ".MODEL") { out("NET_MODEL(\"{} {}\")\n", m_subckt + tt[1], rem(tt,2)); } else out("// {}\n", line.c_str()); break; case 'Q': { /* check for fourth terminal ... should be numeric net * including "0" or start with "N" (ltspice) */ pstring model; pstring pins ="CBE"; bool err; auto nval = plib::pstonum_ne<long, true>(tt[4], err); plib::unused_var(nval); if ((!err || plib::startsWith(tt[4], "N")) && tt.size() > 5) model = tt[5]; else model = tt[4]; std::vector<pstring> m(plib::psplit(model,"{")); if (m.size() == 2) { if (m[1].length() != 4) plib::perrlogger("error with model desc {}\n", model); pins = plib::left(m[1], 3); } add_device("QBJT_EB", tt[0], m_subckt + m[0]); add_term(tt[1], tt[0] + "." + pins.at(0)); add_term(tt[2], tt[0] + "." + pins.at(1)); add_term(tt[3], tt[0] + "." + pins.at(2)); } break; case 'R': if (plib::startsWith(tt[0], "RV")) { val = get_sp_val(tt[4]); add_device("POT", tt[0], val); add_term(tt[1], tt[0] + ".1"); add_term(tt[2], tt[0] + ".2"); add_term(tt[3], tt[0] + ".3"); } else { val = get_sp_val(tt[3]); add_device("RES", tt[0], val); add_term(tt[1], tt[0] + ".1"); add_term(tt[2], tt[0] + ".2"); } break; case 'C': val = get_sp_val(tt[3]); add_device("CAP", tt[0], val); add_term(tt[1], tt[0] + ".1"); add_term(tt[2], tt[0] + ".2"); break; case 'B': // arbitrary behavioural current source - needs manual work afterwords add_device("CS", tt[0], "/*" + rem(tt, 3) + "*/"); add_term(tt[1], tt[0] + ".P"); add_term(tt[2], tt[0] + ".N"); break; case 'E': add_device("VCVS", tt[0]); add_term(tt[1], tt[0] + ".OP"); add_term(tt[2], tt[0] + ".ON"); add_term(tt[3], tt[0] + ".IP"); add_term(tt[4], tt[0] + ".IN"); out("PARAM({}, {})\n", tt[0] + ".G", tt[5]); break; case 'V': // just simple Voltage sources .... if (tt[2] == "0") { val = get_sp_val(tt[3]); add_device("ANALOG_INPUT", tt[0], val); add_term(tt[1], tt[0] + ".Q"); //add_term(tt[2], tt[0] + ".2"); } else plib::perrlogger("Voltage Source {} not connected to GND\n", tt[0]); break; #if 0 // This is wrong ... Need to use something else for inputs! case 'I': // Input pin special notation { val = get_sp_val(tt[2]); add_device("ANALOG_INPUT", tt[0], val); add_term(tt[1], tt[0] + ".Q"); } break; #else case 'I': { val = get_sp_val(tt[3]); add_device("CS", tt[0], val); add_term(tt[1], tt[0] + ".1"); add_term(tt[2], tt[0] + ".2"); } break; #endif case 'D': add_device("DIODE", tt[0], tt[3]); /* FIXME ==> does Kicad use different notation from LTSPICE */ add_term(tt[1], tt[0] + ".K"); add_term(tt[2], tt[0] + ".A"); break; case 'U': case 'X': { // FIXME: specific code for KICAD exports // last element is component type // FIXME: Parameter pstring xname = plib::replace_all(tt[0], pstring("."), pstring("_")); pstring tname = "TTL_" + tt[tt.size()-1] + "_DIP"; add_device(tname, xname); for (std::size_t i=1; i < tt.size() - 1; i++) { pstring term = plib::pfmt("{1}.{2}")(xname)(i); add_term(tt[i], term); } break; } default: out("// IGNORED {}: {}\n", tt[0].c_str(), line.c_str()); } } }
void pstringbuffer::pcopy(const pstring &from) { std::size_t nl = from.blen() + 1; resize(nl); std::copy(from.c_str(), from.c_str() + nl, m_ptr); }
void nl_convert_spice_t::process_line(const pstring &line) { if (line != "") { std::vector<pstring> tt(plib::psplit(line, " ", true)); double val = 0.0; switch (tt[0].at(0)) { case ';': out("// {}\n", line.substr(1)); break; case '*': out("// {}\n", line.substr(1).c_str()); break; case '.': if (tt[0].equals(".SUBCKT")) { out("NETLIST_START({})\n", tt[1].c_str()); for (std::size_t i=2; i<tt.size(); i++) add_ext_alias(tt[i]); } else if (tt[0].equals(".ENDS")) { dump_nl(); out("NETLIST_END()\n"); } else out("// {}\n", line.c_str()); break; case 'Q': { bool cerr = false; /* check for fourth terminal ... should be numeric net * including "0" or start with "N" (ltspice) */ ATTR_UNUSED long nval(tt[4].as_long(&cerr)); pstring model; pstring pins ="CBE"; if ((!cerr || tt[4].startsWith("N")) && tt.size() > 5) model = tt[5]; else model = tt[4]; std::vector<pstring> m(plib::psplit(model,"{")); if (m.size() == 2) { if (m[1].length() != 4) fprintf(stderr, "error with model desc %s\n", model.c_str()); pins = m[1].left(3); } add_device("QBJT_EB", tt[0], m[0]); add_term(tt[1], tt[0] + "." + pins.at(0)); add_term(tt[2], tt[0] + "." + pins.at(1)); add_term(tt[3], tt[0] + "." + pins.at(2)); } break; case 'R': if (tt[0].startsWith("RV")) { val = get_sp_val(tt[4]); add_device("POT", tt[0], val); add_term(tt[1], tt[0] + ".1"); add_term(tt[2], tt[0] + ".2"); add_term(tt[3], tt[0] + ".3"); } else { val = get_sp_val(tt[3]); add_device("RES", tt[0], val); add_term(tt[1], tt[0] + ".1"); add_term(tt[2], tt[0] + ".2"); } break; case 'C': val = get_sp_val(tt[3]); add_device("CAP", tt[0], val); add_term(tt[1], tt[0] + ".1"); add_term(tt[2], tt[0] + ".2"); break; case 'V': // just simple Voltage sources .... if (tt[2].equals("0")) { val = get_sp_val(tt[3]); add_device("ANALOG_INPUT", tt[0], val); add_term(tt[1], tt[0] + ".Q"); //add_term(tt[2], tt[0] + ".2"); } else fprintf(stderr, "Voltage Source %s not connected to GND\n", tt[0].c_str()); break; case 'I': // Input pin special notation { val = get_sp_val(tt[2]); add_device("ANALOG_INPUT", tt[0], val); add_term(tt[1], tt[0] + ".Q"); } break; case 'D': add_device("DIODE", tt[0], tt[3]); /* FIXME ==> does Kicad use different notation from LTSPICE */ add_term(tt[1], tt[0] + ".K"); add_term(tt[2], tt[0] + ".A"); break; case 'U': case 'X': { // FIXME: specific code for KICAD exports // last element is component type // FIXME: Parameter pstring xname = tt[0].replace_all(".", "_"); pstring tname = "TTL_" + tt[tt.size()-1] + "_DIP"; add_device(tname, xname); for (std::size_t i=1; i < tt.size() - 1; i++) { pstring term = plib::pfmt("{1}.{2}")(xname)(i); add_term(tt[i], term); } break; } default: out("// IGNORED {}: {}\n", tt[0].c_str(), line.c_str()); } } }