Don't confuse .OP with .OPTIONS.

Fixes https://gitlab.com/kicad/code/kicad/issues/13849
This commit is contained in:
Jeff Young 2023-02-13 13:33:04 +00:00
parent e6d45e27e8
commit d6bef19811
2 changed files with 59 additions and 47 deletions

View File

@ -364,49 +364,55 @@ void NETLIST_EXPORTER_SPICE::ReadDirectives( unsigned aNetlistOptions )
wxStringTokenizer tokenizer( text, wxT( "\r\n" ), wxTOKEN_STRTOK ); wxStringTokenizer tokenizer( text, wxT( "\r\n" ), wxTOKEN_STRTOK );
bool foundDirective = false; bool foundDirective = false;
auto isDirective =
[]( const wxString& line, const wxString& dir )
{
return line == dir || line.StartsWith( dir + wxS( " " ) );
};
while( tokenizer.HasMoreTokens() ) while( tokenizer.HasMoreTokens() )
{ {
wxString line = tokenizer.GetNextToken().Upper(); wxString line = tokenizer.GetNextToken().Upper();
if( line.StartsWith( wxT( "." ) ) ) if( line.StartsWith( wxT( "." ) ) )
{ {
if( line.StartsWith( wxT( ".AC" ) ) if( isDirective( line, wxS( ".AC" ) )
|| line.StartsWith( wxT( ".CONTROL" ) ) || isDirective( line, wxS( ".CONTROL" ) )
|| line.StartsWith( wxT( ".CSPARAM" ) ) || isDirective( line, wxS( ".CSPARAM" ) )
|| line.StartsWith( wxT( ".DISTO" ) ) || isDirective( line, wxS( ".DISTO" ) )
|| line.StartsWith( wxT( ".ELSE" ) ) || isDirective( line, wxS( ".ELSE" ) )
|| line.StartsWith( wxT( ".ELSEIF" ) ) || isDirective( line, wxS( ".ELSEIF" ) )
|| line.StartsWith( wxT( ".END" ) ) || isDirective( line, wxS( ".END" ) )
|| line.StartsWith( wxT( ".ENDC" ) ) || isDirective( line, wxS( ".ENDC" ) )
|| line.StartsWith( wxT( ".ENDIF" ) ) || isDirective( line, wxS( ".ENDIF" ) )
|| line.StartsWith( wxT( ".ENDS" ) ) || isDirective( line, wxS( ".ENDS" ) )
|| line.StartsWith( wxT( ".FOUR" ) ) || isDirective( line, wxS( ".FOUR" ) )
|| line.StartsWith( wxT( ".FUNC" ) ) || isDirective( line, wxS( ".FUNC" ) )
|| line.StartsWith( wxT( ".GLOBAL" ) ) || isDirective( line, wxS( ".GLOBAL" ) )
|| line.StartsWith( wxT( ".IC" ) ) || isDirective( line, wxS( ".IC" ) )
|| line.StartsWith( wxT( ".IF" ) ) || isDirective( line, wxS( ".IF" ) )
|| line.StartsWith( wxT( ".INCLUDE" ) ) || isDirective( line, wxS( ".INCLUDE" ) )
|| line.StartsWith( wxT( ".LIB" ) ) || isDirective( line, wxS( ".LIB" ) )
|| line.StartsWith( wxT( ".MEAS" ) ) || isDirective( line, wxS( ".MEAS" ) )
|| line.StartsWith( wxT( ".MODEL" ) ) || isDirective( line, wxS( ".MODEL" ) )
|| line.StartsWith( wxT( ".NODESET" ) ) || isDirective( line, wxS( ".NODESET" ) )
|| line.StartsWith( wxT( ".NOISE" ) ) || isDirective( line, wxS( ".NOISE" ) )
|| line.StartsWith( wxT( ".OP" ) ) || isDirective( line, wxS( ".OP" ) )
|| line.StartsWith( wxT( ".OPTIONS" ) ) || isDirective( line, wxS( ".OPTIONS" ) )
|| line.StartsWith( wxT( ".PARAM" ) ) || isDirective( line, wxS( ".PARAM" ) )
|| line.StartsWith( wxT( ".PLOT" ) ) || isDirective( line, wxS( ".PLOT" ) )
|| line.StartsWith( wxT( ".PRINT" ) ) || isDirective( line, wxS( ".PRINT" ) )
|| line.StartsWith( wxT( ".PROBE" ) ) || isDirective( line, wxS( ".PROBE" ) )
|| line.StartsWith( wxT( ".PZ" ) ) || isDirective( line, wxS( ".PZ" ) )
|| line.StartsWith( wxT( ".SAVE" ) ) || isDirective( line, wxS( ".SAVE" ) )
|| line.StartsWith( wxT( ".SENS" ) ) || isDirective( line, wxS( ".SENS" ) )
|| line.StartsWith( wxT( ".SP" ) ) || isDirective( line, wxS( ".SP" ) )
|| line.StartsWith( wxT( ".SUBCKT" ) ) || isDirective( line, wxS( ".SUBCKT" ) )
|| line.StartsWith( wxT( ".TEMP" ) ) || isDirective( line, wxS( ".TEMP" ) )
|| line.StartsWith( wxT( ".TF" ) ) || isDirective( line, wxS( ".TF" ) )
|| line.StartsWith( wxT( ".TITLE" ) ) || isDirective( line, wxS( ".TITLE" ) )
|| line.StartsWith( wxT( ".TRAN" ) ) || isDirective( line, wxS( ".TRAN" ) )
|| line.StartsWith( wxT( ".WIDTH" ) ) ) || isDirective( line, wxS( ".WIDTH" ) ) )
{ {
foundDirective = true; foundDirective = true;
break; break;
@ -621,6 +627,12 @@ void NETLIST_EXPORTER_SPICE::WriteDirectives( OUTPUTFORMATTER& aFormatter,
} }
} }
auto isSimCommand =
[]( const wxString& candidate, const wxString& dir )
{
return candidate == dir || candidate.StartsWith( dir + wxS( " " ) );
};
for( const wxString& directive : m_directives ) for( const wxString& directive : m_directives )
{ {
bool simCommand = false; bool simCommand = false;
@ -629,15 +641,15 @@ void NETLIST_EXPORTER_SPICE::WriteDirectives( OUTPUTFORMATTER& aFormatter,
{ {
wxString candidate = directive.Upper(); wxString candidate = directive.Upper();
simCommand = ( candidate.StartsWith( wxT( ".AC" ) ) simCommand = ( isSimCommand( candidate, wxS( ".AC" ) )
|| candidate.StartsWith( wxT( ".DC" ) ) || isSimCommand( candidate, wxS( ".DC" ) )
|| candidate.StartsWith( wxT( ".TRAN" ) ) || isSimCommand( candidate, wxS( ".TRAN" ) )
|| candidate.StartsWith( wxT( ".OP" ) ) || isSimCommand( candidate, wxS( ".OP" ) )
|| candidate.StartsWith( wxT( ".DISTO" ) ) || isSimCommand( candidate, wxS( ".DISTO" ) )
|| candidate.StartsWith( wxT( ".NOISE" ) ) || isSimCommand( candidate, wxS( ".NOISE" ) )
|| candidate.StartsWith( wxT( ".PZ" ) ) || isSimCommand( candidate, wxS( ".PZ" ) )
|| candidate.StartsWith( wxT( ".SENS" ) ) || isSimCommand( candidate, wxS( ".SENS" ) )
|| candidate.StartsWith( wxT( ".TF" ) ) ); || isSimCommand( candidate, wxS( ".TF" ) ) );
} }
if( !simCommand || ( aNetlistOptions & OPTION_SIM_COMMAND ) ) if( !simCommand || ( aNetlistOptions & OPTION_SIM_COMMAND ) )

View File

@ -132,7 +132,7 @@ public:
protected: protected:
void ReadDirectives( unsigned aNetlistOptions ); void ReadDirectives( unsigned aNetlistOptions );
virtual void WriteDirectives( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions ) const; virtual void WriteDirectives( OUTPUTFORMATTER& candidate, unsigned aNetlistOptions ) const;
virtual std::string GenerateItemPinNetName( const std::string& aNetName, virtual std::string GenerateItemPinNetName( const std::string& aNetName,
int& aNcCounter ) const; int& aNcCounter ) const;