Skip to content

Commit

Permalink
Recognize the + continuation in SUBCKT header
Browse files Browse the repository at this point in the history
  • Loading branch information
ra3xdh committed Nov 18, 2024
1 parent 08b72b5 commit 871b51c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
19 changes: 17 additions & 2 deletions qucs/extsimkernels/spicecompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,29 @@ int spicecompat::getPins(const QString &file, const QString &compname, QStringLi
const QRegularExpression sep("\\s");

QTextStream stream(&content,QIODevice::ReadOnly);
bool header_start = false;
while (!stream.atEnd()) {
QString lin = stream.readLine();
auto start_comment = lin.indexOf(';');
if (start_comment != -1) {
lin = lin.left(start_comment);
}

if (subckt_header.match(lin).hasMatch()) {
if (header_start) {
// line continuation
if (lin.startsWith("+")) {
lin.remove(0,1);
QStringList pins = lin.split(QRegularExpression("[ \\t]"),Qt::SkipEmptyParts);
pin_names.append(pins);
} else {
// end of header
header_start = false;
break;
}
}

if (subckt_header.match(lin).hasMatch()) {
header_start = true;
QStringList lst2 = lin.split(sep,qucs::SkipEmptyParts);
QString name = lin.section(sep,1,1,QString::SectionSkipEmpty).toLower();
QString refname = compname.toLower();
Expand All @@ -300,13 +314,14 @@ int spicecompat::getPins(const QString &file, const QString &compname, QStringLi
lst2.removeFirst();
for (const auto &s1: lst2) {
QString pp = s1;
if (pp.toLower() == "params:") header_start = false;
if (!s1.contains('=') &&
(pp.toLower() != "params:")) {
pin_names.append(s1);
}
}
r = pin_names.count();
break;
//break;
}
}

Expand Down
18 changes: 18 additions & 0 deletions qucs/extsimkernels/spicelibcompdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ int SpiceLibCompDialog::parseLibFile(const QString &filename)
QTextStream ts(&f);

bool subcir_start = false;
bool header_start = false;
QString last_subcir;
QString subname;
QString subcir_body;
while (!ts.atEnd()) {
Expand All @@ -282,17 +284,33 @@ int SpiceLibCompDialog::parseLibFile(const QString &filename)
if (start_comment != -1) {
line = line.left(start_comment);
}

if (header_start) {
// line continuation
if (line.startsWith("+")) {
line.remove(0,1);
QStringList pins = line.split(QRegularExpression("[ \\t]"),Qt::SkipEmptyParts);
subcirPins[last_subcir].append(pins);
} else {
// end of header
header_start = false;
}
}

if (line.startsWith(".SUBCKT")) {
subcir_start = true;
header_start = true;
subcir_body.clear();
QStringList pin_names;
QStringList tokens = line.split(QRegularExpression("[ \\t]"),Qt::SkipEmptyParts);
if (tokens.count() > 3) {
subname = tokens.at(1);
last_subcir = subname;
} else continue;
tokens.removeFirst();
tokens.removeFirst();
for (const auto &s1: tokens) {
if (s1 == "PARAMS:") header_start = false;
if (!s1.contains('=') && (s1 != "PARAMS:")) {
pin_names.append(s1);
}
Expand Down

0 comments on commit 871b51c

Please sign in to comment.