From e545d6af3fc0927eaa89229b318e5b31ad44ee8f Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 22 Mar 2019 00:05:17 +0100 Subject: [PATCH] Refined solution for issue-245 by providing a better name mapping (checked with ngspice) --- src/db/db/dbNetlistSpiceWriter.cc | 15 ++++++++++++--- testdata/algo/nwriter9_au.txt | 4 ++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/db/db/dbNetlistSpiceWriter.cc b/src/db/db/dbNetlistSpiceWriter.cc index d12843ea3..9bde4c2d0 100644 --- a/src/db/db/dbNetlistSpiceWriter.cc +++ b/src/db/db/dbNetlistSpiceWriter.cc @@ -246,12 +246,21 @@ std::string NetlistSpiceWriter::net_to_string (const db::Net *net) const } else { + // Tested with ngspice: this tool likes in net names: . $ ! & \ # + : | (but not at beginning) + // It does not like: , ; + // We translate , to | for the net separator + std::string n = net->expanded_name (); std::string nn; - nn.reserve (n.size ()); + nn.reserve (n.size () + 1); + if (!isalnum (*n.c_str ())) { + nn += "\\"; + } for (const char *cp = n.c_str (); *cp; ++cp) { - if (isspace (*cp)) { - nn += tl::sprintf ("$x%02x", (unsigned char) *cp); + if (! isalnum (*cp) && strchr (".$!&\\#+:,", *cp) == 0) { + nn += tl::sprintf ("\\x%02x", (unsigned char) *cp); + } else if (*cp == ',') { + nn += "|"; } else { nn += *cp; } diff --git a/testdata/algo/nwriter9_au.txt b/testdata/algo/nwriter9_au.txt index 570272e40..831158d81 100644 --- a/testdata/algo/nwriter9_au.txt +++ b/testdata/algo/nwriter9_au.txt @@ -11,9 +11,9 @@ XSC1 n1 n2 C1 * cell C1 * pin p1 * pin p2 -.SUBCKT C1 N1 N$x202 +.SUBCKT C1 N1 N\x202 * device instance $1 0,0 XCLS XD_$1 N1 n3 XCLS PARAMS: U=-17 V=42 * device instance $2 0,0 XCLS -XD_$2 n3 N$x202 XCLS PARAMS: U=17 V=-42 +XD_$2 n3 N\x202 XCLS PARAMS: U=17 V=-42 .ENDS C1