diff options
author | 2016-12-23 14:48:09 +0100 | |
---|---|---|
committer | 2016-12-23 14:48:09 +0100 | |
commit | d0b0de1aec45c0f9b66c931efb9902874cb93728 (patch) | |
tree | 98a11fe89a65cc62fa8114a0b6c5312c21810ede /src/lib/netlist/plib/pfmtlog.cpp | |
parent | c0561727b406ed189039d81fac7c69fef4c79913 (diff) | |
parent | 63b7b9d521712404dc35156ef8d7e606440b4156 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'src/lib/netlist/plib/pfmtlog.cpp')
-rw-r--r-- | src/lib/netlist/plib/pfmtlog.cpp | 80 |
1 files changed, 29 insertions, 51 deletions
diff --git a/src/lib/netlist/plib/pfmtlog.cpp b/src/lib/netlist/plib/pfmtlog.cpp index d66b8f62520..770a53af49d 100644 --- a/src/lib/netlist/plib/pfmtlog.cpp +++ b/src/lib/netlist/plib/pfmtlog.cpp @@ -16,14 +16,15 @@ #include "pfmtlog.h" #include "palloc.h" +namespace plib { pfmt::pfmt(const pstring &fmt) : m_str(m_str_buf), m_allocated(0), m_arg(0) { - unsigned l = fmt.blen() + 1; + std::size_t l = fmt.blen() + 1; if (l>sizeof(m_str_buf)) { m_allocated = 2 * l; - m_str = palloc_array(char, 2 * l); + m_str = palloc_array<char>(2 * l); } memcpy(m_str, fmt.cstr(), l); } @@ -31,11 +32,11 @@ pfmt::pfmt(const pstring &fmt) pfmt::pfmt(const char *fmt) : m_str(m_str_buf), m_allocated(0), m_arg(0) { - unsigned l = strlen(fmt) + 1; + std::size_t l = strlen(fmt) + 1; if (l>sizeof(m_str_buf)) { m_allocated = 2 * l; - m_str = palloc_array(char, 2 * l); + m_str = palloc_array<char>(2 * l); } memcpy(m_str, fmt, l); } @@ -46,30 +47,6 @@ pfmt::~pfmt() pfree_array(m_str); } -#if 0 -void pformat::format_element(const char *f, const char *l, const char *fmt_spec, ...) -{ - va_list ap; - va_start(ap, fmt_spec); - char fmt[30] = "%"; - char search[10] = ""; - char buf[1024]; - strcat(fmt, f); - strcat(fmt, l); - strcat(fmt, fmt_spec); - int nl = vsprintf(buf, fmt, ap); - m_arg++; - int sl = sprintf(search, "%%%d", m_arg); - char *p = strstr(m_str, search); - if (p != NULL) - { - // Make room - memmove(p+nl, p+sl, strlen(p) + 1 - sl); - memcpy(p, buf, nl); - } - va_end(ap); -} -#else void pfmt::format_element(const char *f, const char *l, const char *fmt_spec, ...) { va_list ap; @@ -78,28 +55,28 @@ void pfmt::format_element(const char *f, const char *l, const char *fmt_spec, . char search[10] = ""; char buf[2048]; m_arg++; - int sl = sprintf(search, "{%d:", m_arg); + std::size_t sl = static_cast<std::size_t>(sprintf(search, "{%d:", m_arg)); char *p = strstr(m_str, search); - if (p == NULL) + if (p == nullptr) { - sl = sprintf(search, "{%d}", m_arg); + sl = static_cast<std::size_t>(sprintf(search, "{%d}", m_arg)); p = strstr(m_str, search); - if (p == NULL) + if (p == nullptr) { sl = 2; p = strstr(m_str, "{}"); } - if (p==NULL) + if (p==nullptr) { sl=1; p = strstr(m_str, "{"); - if (p != NULL) + if (p != nullptr) { char *p1 = strstr(p, "}"); - if (p1 != NULL) + if (p1 != nullptr) { - sl = p1 - p + 1; - strncat(fmt, p+1, p1 - p - 2); + sl = static_cast<std::size_t>(p1 - p + 1); + strncat(fmt, p+1, static_cast<std::size_t>(p1 - p - 2)); } else strcat(fmt, f); @@ -111,44 +88,44 @@ void pfmt::format_element(const char *f, const char *l, const char *fmt_spec, . else { char *p1 = strstr(p, "}"); - if (p1 != NULL) + if (p1 != nullptr) { - sl = p1 - p + 1; + sl = static_cast<std::size_t>(p1 - p + 1); if (m_arg>=10) - strncat(fmt, p+4, p1 - p - 4); + strncat(fmt, p+4, static_cast<std::size_t>(p1 - p - 4)); else - strncat(fmt, p+3, p1 - p - 3); + strncat(fmt, p+3, static_cast<std::size_t>(p1 - p - 3)); } else strcat(fmt, f); } strcat(fmt, l); char *pend = fmt + strlen(fmt) - 1; - if (strchr("fge", *fmt_spec) != NULL) + if (strchr("fge", *fmt_spec) != nullptr) { - if (strchr("fge", *pend) == NULL) + if (strchr("fge", *pend) == nullptr) strcat(fmt, fmt_spec); } - else if (strchr("duxo", *fmt_spec) != NULL) + else if (strchr("duxo", *fmt_spec) != nullptr) { - if (strchr("duxo", *pend) == NULL) + if (strchr("duxo", *pend) == nullptr) strcat(fmt, fmt_spec); } else strcat(fmt, fmt_spec); - int nl = vsprintf(buf, fmt, ap); - if (p != NULL) + std::size_t nl = static_cast<std::size_t>(vsprintf(buf, fmt, ap)); + if (p != nullptr) { // check room - unsigned new_size = (p - m_str) + nl + strlen(p) + 1 - sl; + std::size_t new_size = static_cast<std::size_t>(p - m_str) + nl + strlen(p) + 1 - sl; if (new_size > m_allocated) { - unsigned old_alloc = std::max(m_allocated, (unsigned) sizeof(m_str_buf)); + std::size_t old_alloc = std::max(m_allocated, sizeof(m_str_buf)); if (m_allocated < old_alloc) m_allocated = old_alloc; while (new_size > m_allocated) m_allocated *= 2; - char *np = palloc_array(char, m_allocated); + char *np = palloc_array<char>(m_allocated); memcpy(np, m_str, old_alloc); p = np + (p - m_str); if (m_str != m_str_buf) @@ -161,4 +138,5 @@ void pfmt::format_element(const char *f, const char *l, const char *fmt_spec, . } va_end(ap); } -#endif + +} |