void sax_parser<_Handler,_Config>::characters() { size_t first = m_pos; const char* p0 = m_char; for (; has_char(); next()) { if (cur_char() == '<') break; if (cur_char() == '&') { // Text span with one or more encoded characters. Parse using cell buffer. cell_buffer& buf = get_cell_buffer(); buf.reset(); buf.append(p0, m_pos-first); characters_with_encoded_char(buf); if (buf.empty()) m_handler.characters(pstring(), false); else m_handler.characters(pstring(buf.get(), buf.size()), true); return; } } if (m_pos > first) { size_t size = m_pos - first; pstring val(m_content + first, size); m_handler.characters(val, false); } }
void tool_app_t::mac_out(const pstring &s, const bool cont) { if (cont) { unsigned pos = 0; pstring r; for (const auto &x : s) { if (x == '\t') { auto pos_mod_4 = pos % opt_tabwidth(); auto tab_adj = opt_tabwidth() - pos_mod_4; r += plib::rpad(pstring(""), pstring(" "), tab_adj); pos += tab_adj; } else { r += x; pos++; } } pout("{1}\\\n", plib::rpad(r, pstring(" "), opt_linewidth()-1)); } else pout("{1}\n", s); }
IShapeMap *IGraphFile::importMap(const char *filename, const char *type, const char *newmapname) { // Note: 08-APR-2010 -- still have to add DXF and CAT (all to get automatic analysis working) IShapeMap *shapemap = NULL; MetaGraph *graph = ((IGraphOrganizer *)m_data)->m_graph; string type_str = string(type); if (!(type_str.compare("MIF") == 0 || type_str.compare("TXT") == 0 || type_str.compare("CSV") == 0)) { return NULL; } if (type_str.compare("TXT") == 0 || type_str.compare("CSV") == 0) { // these can be x,y points or x1,y1,x2,y2 lines // first line should be labels, creates a datamap ifstream file(filename); if (!file) { return NULL; } else { int mapref = graph->importTxt( file, pstring(newmapname), (type_str.compare("CSV")==0) ); if (mapref != -1) { // note, at this stage in development, you CANNOT go from the mapref directly here as the getIShapeMap has both shape graphs and data maps mixed together ShapeMap& basemap = graph->m_data_maps.getMap(mapref); shapemap = ((IGraphOrganizer *)m_data)->getIShapeMap(&basemap); } } } else if (type_str.compare("MIF") == 0) { pstring miffilename = pstring(filename) + ".mif"; pstring midfilename = pstring(filename) + ".mid"; ifstream miffile( miffilename.c_str() ); ifstream midfile( midfilename.c_str() ); if (miffile && midfile) { int mapref = graph->m_data_maps.addMap(pstring(newmapname),ShapeMap::DATAMAP); ShapeMap& mifmap = graph->m_data_maps.getMap(mapref); int ok = mifmap.loadMifMap(miffile,midfile); if (ok == MINFO_OK || ok == MINFO_MULTIPLE) { // multiple is just a warning // note, at this stage in development, you CANNOT go from the mapref directly here as the getIShapeMap has both shape graphs and data maps mixed together shapemap = ((IGraphOrganizer *)m_data)->getIShapeMap(&mifmap); } else { // error: undo! graph->m_data_maps.removeMap(mapref); } } } return shapemap; }
void addPrefix(char* startbuf, int n) { std::set<pstring>::iterator elem = pset.find(pstring(startbuf, n)); bool replace = elem != pset.end() && n < elem->n; if (replace) { pset.erase(elem); } if (replace || elem == pset.end()) { pset.insert(pstring(startbuf, n)); } }
pstring document::get_sheet_name(sheet_t sheet_pos) const { if (sheet_pos < 0) return pstring(); size_t pos = static_cast<size_t>(sheet_pos); if (pos >= mp_impl->m_sheets.size()) return pstring(); return mp_impl->m_sheets[pos].name; }
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; }
bool IAttributes::insertAttributeColumn(const char *attribute) { if (strcmp(attribute,"Ref Number") != 0) { AttributeTable *table = (AttributeTable *)m_data; int n = table->getColumnIndex(pstring(attribute)); if (n == -1 || !table->isColumnLocked(n)) { table->insertColumn(pstring(attribute)); return true; } } return false; }
double nl_convert_base_t::get_sp_unit(const pstring &unit) { int i = 0; while (pstring(m_units[i].m_unit) != "-") { if (pstring(m_units[i].m_unit) == unit) return m_units[i].m_mult; i++; } plib::perrlogger("Unit {} unknown\n", unit); return 0.0; }
const pstring nl_convert_base_t::get_nl_val(const double val) { { int i = 0; while (pstring(m_units[i].m_unit) != "-" ) { if (m_units[i].m_mult <= std::abs(val)) break; i++; } return plib::pfmt(pstring(m_units[i].m_func))(val / m_units[i].m_mult); } }
IGraphFile *newGraphFile() { IGraphFile *graphfile = NULL; MetaGraph *graph = new MetaGraph(); // REMINDER: fill in some more details here: pstring version = "Sala.dll version"; char tmpbuf[9]; pstring date = pstring(_strdate(tmpbuf)); graph->setProperties(pstring("Name"),pstring("Organisation"),pstring(date),pstring(version)); graphfile = new IGraphFile(); graphfile->setData(graph); // ensure the graph is labelled for deletion after use ((IGraphOrganizer *)graphfile->m_data)->setDeleteFlag(); return graphfile; }
opc_relations_context::opc_relations_context(session_context& session_cxt, const tokens &_tokens) : xml_context_base(session_cxt, _tokens) { // build content type cache. for (schema_t* p = SCH_all; *p; ++p) m_schema_cache.insert(pstring(*p)); }
void sax_parser<_Handler,_Config>::cdata() { size_t len = remains(); assert(len > 3); // Parse until we reach ']]>'. const char* p0 = m_char; size_t i = 0, match = 0; for (char c = cur_char(); i < len; ++i, c = next_char()) { if (c == ']') { // Be aware that we may encounter a series of more than two ']' // characters, in which case we'll only count the last two. if (match == 0) // First ']' ++match; else if (match == 1) // Second ']' ++match; } else if (c == '>' && match == 2) { // Found ']]>'. size_t cdata_len = i - 2; m_handler.characters(pstring(p0, cdata_len), false); next(); return; } else match = 0; } throw sax::malformed_xml_error("malformed CDATA section."); }
bool parser_base::value(pstring& str, bool decode) { char c = cur_char(); if (c != '"') throw malformed_xml_error("value must be quoted"); c = next_char_checked(); size_t first = m_pos; const char* p0 = m_char; for (; c != '"'; c = next_char_checked()) { if (decode && c == '&') { // This value contains one or more encoded characters. cell_buffer& buf = get_cell_buffer(); buf.reset(); buf.append(p0, m_pos-first); value_with_encoded_char(buf, str); return true; } } str = pstring(p0, m_pos-first); // Skip the closing quote. next(); return false; }
opc_content_types_context::opc_content_types_context(session_context& session_cxt, const tokens& _tokens) : xml_context_base(session_cxt, _tokens) { // build content type cache. for (const content_type_t* p = CT_all; *p; ++p) m_ct_cache.insert(pstring(*p)); }
pstring pstring::sprintf(const char *format, ...) { va_list ap; va_start(ap, format); pstring ret = pstring(format).vprintf(ap); va_end(ap); return ret; }
pstring pstring::vprintf(va_list args) const { // sprintf into the temporary buffer char tempbuf[4096]; vsprintf(tempbuf, cstr(), args); return pstring(tempbuf); }
// get an attribute from the attribute table for the current point: float IAttributes::getAttribute(int id, const char *attribute) { AttributeTable& table = *((AttributeTable *)m_data); int index = (m_analysis_type != DLL_VGA_ANALYSIS) ? id : table.getRowid(id); // vga needs to look up rowid, all others use rowid directly if (index == -1) { return -1.0f; } return table.getValue(index,pstring(attribute)); }
void tool_app_t::create_header() { netlist_tool_t nt(*this, "netlist"); nt.init(); nt.log().verbose.set_enabled(false); nt.log().warning.set_enabled(false); nt.setup().register_source(plib::make_unique_base<netlist::source_t, netlist::source_proc_t>(nt.setup(), "dummy", &netlist_dummy)); nt.setup().include("dummy"); pout("// license:GPL-2.0+\n"); pout("// copyright-holders:Couriersud\n"); pout("#ifndef NLD_DEVINC_H\n"); pout("#define NLD_DEVINC_H\n"); pout("\n"); pout("#include \"nl_setup.h\"\n"); pout("#ifndef __PLIB_PREPROCESSOR__\n"); pout("\n"); pout("/* ----------------------------------------------------------------------------\n"); pout(" * Netlist Macros\n"); pout(" * ---------------------------------------------------------------------------*/\n"); pout("\n"); pstring last_source(""); for (auto &e : nt.setup().factory()) { if (last_source != e->sourcefile()) { last_source = e->sourcefile(); pout("{1}\n", pstring("// ").rpad("-", 72)); pout("{1}{2}\n", pstring("// Source: "), e->sourcefile().replace_all("../", "")); pout("{1}\n", pstring("// ").rpad("-", 72)); } cmac(e.get()); } pout("#endif // __PLIB_PREPROCESSOR__\n"); pout("#endif\n"); nt.stop(); }
bool IAttributes::renameAttributeColumn(const char *oldname, const char *newname) { AttributeTable *table = (AttributeTable *)m_data; int n = table->getColumnIndex(pstring(oldname)); if (n != -1 && !table->isColumnLocked(n)) { table->renameColumn(n,newname); return true; } return false; }
bool IAttributes::isLockedAttributeColumn(const char *attribute) { AttributeTable *table = (AttributeTable *)m_data; int n = table->getColumnIndex(pstring(attribute)); if (n != -1 && !table->isColumnLocked(n)) { return table->isColumnLocked(n); } // n.b., this should really throw an exception: return false; }
static pstring catremainder(const pstring_list_t &elems, std::size_t start, pstring sep) { pstringbuffer ret = ""; for (std::size_t i=start; i<elems.size(); i++) { ret.cat(elems[i]); ret.cat(sep); } return pstring(ret.cstr()); }
pstring ptokenizer::currentline_str() { char buf[300]; int bufp = 0; const char *p = m_line_ptr; while (*p && *p != 10) buf[bufp++] = *p++; buf[bufp] = 0; return pstring(buf); }
// set an attribute in the attribute table for the current point: void IAttributes::incrAttribute(int id, const char *attribute) { AttributeTable& table = *((AttributeTable *)m_data); int index = (m_analysis_type != DLL_VGA_ANALYSIS) ? id : table.getRowid(id); // vga needs to look up rowid, all others use rowid directly if (index == -1) { return; } // nb., changeValue modifies tot value (but not reduce min/max) table.incrValue(index,pstring(attribute)); }
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); }
/* format a string into an ei_x_buff, except the version token */ static int eiformat(const char** fmt, union arg** args, ei_x_buff* x) { const char* p = *fmt; int res; ei_x_buff x2; while (isspace((int)*p)) ++p; switch (*p) { case '~': res = pformat(&p, args, x); break; case '[': res = ei_x_new(&x2); if (res >= 0) res = plist(&p, args, &x2, 0); if (res > 0) res = ei_x_encode_list_header(x, res); if (res >= 0) res = ei_x_append(x, &x2); ei_x_free(&x2); break; case '{': res = ei_x_new(&x2); if (res >= 0) res = ptuple(&p, args, &x2, 0); if (res >= 0) res = ei_x_encode_tuple_header(x, res); if (res >= 0) res = ei_x_append(x, &x2); ei_x_free(&x2); break; case '"': res = pstring(&p, x); break; case '\'': res = pquotedatom(&p, x); break; default: if (isdigit((int)*p)) res = pdigit(&p, x); else if ((*p == '-' || *p == '+') && isdigit((int)*(p+1))) res = pdigit(&p, x); else if (islower((int)*p)) res = patom(&p, x); else res = -1; break; /* Variables */ } *fmt = p; return res; }
tokens::tokens(const char** token_names, size_t token_name_count) : m_token_names(token_names), m_token_name_count(token_name_count) { for (size_t i = 0; i < m_token_name_count; ++i) { m_tokens.insert( token_map_type::value_type( pstring(m_token_names[i]), static_cast<xml_token_t>(i))); } }
pstring pstring::substr(unsigned int start, int count) const { int alen = len(); if (start >= alen) return pstring(); if (count <0 || start + count > alen) count = alen - start; pstring ret; ret.pcopy(cstr() + start, count); return ret; }
pstring netlist_parser::getname(char sep) { char buf[300]; char *p1 = buf; char c; while ((c=getc()) != sep) *p1++ = c; *p1 = 0; return pstring(buf); }
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); }
ATTR_COLD void ptokenizer::error(const char *format, ...) { va_list ap; va_start(ap, format); pstring errmsg1 = pstring(format).vprintf(ap); va_end(ap); verror(errmsg1, currentline_no(), currentline_str()); //throw error; }