mac support fixes
This commit is contained in:
parent
4987c15ed7
commit
4ca51f7554
|
@ -3,317 +3,328 @@
|
||||||
/**********************************/
|
/**********************************/
|
||||||
|
|
||||||
/* read the generic netlist created by eeschema and convert it to a pads-pcb form
|
/* read the generic netlist created by eeschema and convert it to a pads-pcb form
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#ifdef __UNIX__
|
#if defined (__UNIX__) || defined (__APPLE__)
|
||||||
#define stricmp strcasecmp
|
#define stricmp strcasecmp
|
||||||
#define strnicmp strncasecmp
|
#define strnicmp strncasecmp
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Pads-pcb sample:
|
/* Pads-pcb sample:
|
||||||
*PADS-PCB*
|
*PADS-PCB*
|
||||||
*PART*
|
*PART*
|
||||||
C1 CHIP_D
|
* C1 CHIP_D
|
||||||
C2 C1206
|
* C2 C1206
|
||||||
C3 CHIP_B
|
* C3 CHIP_B
|
||||||
C4 CHIP_B
|
* C4 CHIP_B
|
||||||
D1 CHIP_B
|
* D1 CHIP_B
|
||||||
JP1 unknown
|
* JP1 unknown
|
||||||
|
*
|
||||||
*NET*
|
*NET*
|
||||||
*SIGNAL* N03791
|
*SIGNAL* N03791
|
||||||
C3.1 R1.1 JP2.7 U1.3
|
* C3.1 R1.1 JP2.7 U1.3
|
||||||
*SIGNAL* VCC
|
*SIGNAL* VCC
|
||||||
U2.14 Y1.8 JP5.2 U3.2 C1.1 U1.20 JP1.8 JP1.3
|
* U2.14 Y1.8 JP5.2 U3.2 C1.1 U1.20 JP1.8 JP1.3
|
||||||
C5.2 C6.1 C7.2 U1.7 Y1.7
|
* C5.2 C6.1 C7.2 U1.7 Y1.7
|
||||||
*SIGNAL* N01384
|
*SIGNAL* N01384
|
||||||
JP5.1 U1.1
|
* JP5.1 U1.1
|
||||||
*SIGNAL* N02594
|
*SIGNAL* N02594
|
||||||
*END*
|
*END*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/* Generic netlist sample:
|
/* Generic netlist sample:
|
||||||
$BeginNetlist
|
* $BeginNetlist
|
||||||
$BeginComponentList
|
* $BeginComponentList
|
||||||
|
*
|
||||||
$BeginComponent
|
* $BeginComponent
|
||||||
TimeStamp=32568D1E
|
* TimeStamp=32568D1E
|
||||||
Footprint=
|
* Footprint=
|
||||||
Reference=JP1
|
* Reference=JP1
|
||||||
Value=CONN_8X2
|
* Value=CONN_8X2
|
||||||
Libname=CONN_8X2
|
* Libname=CONN_8X2
|
||||||
$BeginPinList
|
* $BeginPinList
|
||||||
1=GND
|
* 1=GND
|
||||||
2=REF10_1
|
* 2=REF10_1
|
||||||
3=GND
|
* 3=GND
|
||||||
4=REF11_1
|
* 4=REF11_1
|
||||||
5=GND
|
* 5=GND
|
||||||
6=REF7_1
|
* 6=REF7_1
|
||||||
7=GND
|
* 7=GND
|
||||||
8=REF9_1
|
* 8=REF9_1
|
||||||
9=GND
|
* 9=GND
|
||||||
10=REF6_1
|
* 10=REF6_1
|
||||||
11=GND
|
* 11=GND
|
||||||
12=REF8_1
|
* 12=REF8_1
|
||||||
13=GND
|
* 13=GND
|
||||||
14=REF4_1
|
* 14=REF4_1
|
||||||
15=GND
|
* 15=GND
|
||||||
16=REF5_1
|
* 16=REF5_1
|
||||||
$EndPinList
|
* $EndPinList
|
||||||
$EndComponent
|
* $EndComponent
|
||||||
|
*
|
||||||
$BeginComponent
|
* $BeginComponent
|
||||||
TimeStamp=325679C1
|
* TimeStamp=325679C1
|
||||||
Footprint=
|
* Footprint=
|
||||||
Reference=RR1
|
* Reference=RR1
|
||||||
Value=9x1K
|
* Value=9x1K
|
||||||
Libref=RR9
|
* Libref=RR9
|
||||||
$BeginPinList
|
* $BeginPinList
|
||||||
1=VCC
|
* 1=VCC
|
||||||
2=REF5_1
|
* 2=REF5_1
|
||||||
3=REF4_1
|
* 3=REF4_1
|
||||||
4=REF8_1
|
* 4=REF8_1
|
||||||
5=REF6_1
|
* 5=REF6_1
|
||||||
6=REF9_1
|
* 6=REF9_1
|
||||||
7=REF7_1
|
* 7=REF7_1
|
||||||
8=REF11_1
|
* 8=REF11_1
|
||||||
9=REF10_1
|
* 9=REF10_1
|
||||||
10=?
|
* 10=?
|
||||||
$EndPinList
|
* $EndPinList
|
||||||
$EndComponent
|
* $EndComponent
|
||||||
$EndComponentList
|
* $EndComponentList
|
||||||
|
*
|
||||||
$BeginNets
|
* $BeginNets
|
||||||
Net 0 ""
|
* Net 0 ""
|
||||||
Net 1 "GND"
|
* Net 1 "GND"
|
||||||
BUS1 31
|
* BUS1 31
|
||||||
U3 19
|
* U3 19
|
||||||
U3 10
|
* U3 10
|
||||||
U3 1
|
* U3 1
|
||||||
Net 172 ""
|
* Net 172 ""
|
||||||
BUS1 32
|
* BUS1 32
|
||||||
Net 173 ""
|
* Net 173 ""
|
||||||
BUS1 30
|
* BUS1 30
|
||||||
$EndNets
|
* $EndNets
|
||||||
|
*
|
||||||
$EndNetlist
|
* $EndNetlist
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char * GetLine(FILE *File, char *Line, int *LineNum, int SizeLine);
|
|
||||||
int ReadAndWriteComponentDataSection(FILE * InFile, FILE * OutFile, int *LineNumber);
|
|
||||||
int ReadAndWriteNetsDataSection(FILE * InFile, FILE * OutFile, int * LineNumber);
|
|
||||||
|
|
||||||
|
char* GetLine( FILE* File, char* Line, int* LineNum, int SizeLine );
|
||||||
|
int ReadAndWriteComponentDataSection( FILE* InFile, FILE* OutFile, int* LineNumber );
|
||||||
|
int ReadAndWriteNetsDataSection( FILE* InFile, FILE* OutFile, int* LineNumber );
|
||||||
|
|
||||||
|
|
||||||
class ComponentDataClass
|
class ComponentDataClass
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
char m_Reference[256];
|
char m_Reference[256];
|
||||||
char m_Value[256];
|
char m_Value[256];
|
||||||
char m_Footprint[256];
|
char m_Footprint[256];
|
||||||
char m_LibRef[256];
|
char m_LibRef[256];
|
||||||
long m_TimeStamp;
|
long m_TimeStamp;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ComponentDataClass(void)
|
ComponentDataClass( void )
|
||||||
{
|
{
|
||||||
InitData();
|
InitData();
|
||||||
}
|
}
|
||||||
void InitData(void)
|
|
||||||
{
|
|
||||||
m_TimeStamp = 0;
|
void InitData( void )
|
||||||
m_Reference[0] = 0;
|
{
|
||||||
m_Value[0] = 0;
|
m_TimeStamp = 0;
|
||||||
m_Footprint[0] = 0;
|
m_Reference[0] = 0;
|
||||||
m_LibRef[0] = 0;
|
m_Value[0] = 0;
|
||||||
}
|
m_Footprint[0] = 0;
|
||||||
|
m_LibRef[0] = 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/********************************/
|
/********************************/
|
||||||
int main(int argc, char ** argv )
|
int main( int argc, char** argv )
|
||||||
/********************************/
|
/********************************/
|
||||||
{
|
{
|
||||||
char * InputfileName, * OutputFilename;
|
char* InputfileName, * OutputFilename;
|
||||||
FILE * InFile, * OutFile;
|
FILE* InFile, * OutFile;
|
||||||
int LineNumber;
|
int LineNumber;
|
||||||
char Line[1024];
|
char Line[1024];
|
||||||
|
|
||||||
if ( argc < 3 )
|
if( argc < 3 )
|
||||||
{
|
{
|
||||||
printf("\nUsage; netlist_form_pads-pcb infile outfile\n");
|
printf( "\nUsage; netlist_form_pads-pcb infile outfile\n" );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
InputfileName = argv[1];
|
InputfileName = argv[1];
|
||||||
OutputFilename = argv[2];
|
OutputFilename = argv[2];
|
||||||
|
|
||||||
if ( (InFile = fopen(InputfileName, "rt")) == NULL)
|
if( ( InFile = fopen( InputfileName, "rt" ) ) == NULL )
|
||||||
{
|
{
|
||||||
printf ( "Failed to open file %s", InputfileName);
|
printf( "Failed to open file %s", InputfileName );
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
if ( (OutFile = fopen(OutputFilename, "wt")) == NULL)
|
if( ( OutFile = fopen( OutputFilename, "wt" ) ) == NULL )
|
||||||
{
|
{
|
||||||
printf ( "Failed to create file %s", OutputFilename);
|
printf( "Failed to create file %s", OutputFilename );
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Write header: */
|
/* Write header: */
|
||||||
fprintf( OutFile, "*PADS-PCB*\n*PART*\n" );
|
fprintf( OutFile, "*PADS-PCB*\n*PART*\n" );
|
||||||
|
|
||||||
/* Read and write data lines */
|
/* Read and write data lines */
|
||||||
while( GetLine(InFile, Line, &LineNumber, sizeof(Line) ) )
|
while( GetLine( InFile, Line, &LineNumber, sizeof(Line) ) )
|
||||||
{
|
{
|
||||||
if ( stricmp(Line, "$BeginComponent") == 0 )
|
if( stricmp( Line, "$BeginComponent" ) == 0 )
|
||||||
{
|
{
|
||||||
ReadAndWriteComponentDataSection(InFile, OutFile, &LineNumber);
|
ReadAndWriteComponentDataSection( InFile, OutFile, &LineNumber );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( stricmp(Line, "$BeginNets") == 0 )
|
if( stricmp( Line, "$BeginNets" ) == 0 )
|
||||||
{
|
{
|
||||||
fprintf( OutFile, "\n*NET*\n" );
|
fprintf( OutFile, "\n*NET*\n" );
|
||||||
ReadAndWriteNetsDataSection(InFile, OutFile, &LineNumber);
|
ReadAndWriteNetsDataSection( InFile, OutFile, &LineNumber );
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fprintf( OutFile, "*END*\n" );
|
fprintf( OutFile, "*END*\n" );
|
||||||
|
|
||||||
fclose(InFile);
|
fclose( InFile );
|
||||||
fclose(OutFile);
|
fclose( OutFile );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
int ReadAndWriteComponentDataSection(FILE * InFile, FILE * OutFile, int *LineNumber)
|
int ReadAndWriteComponentDataSection( FILE* InFile, FILE* OutFile, int* LineNumber )
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
|
|
||||||
/* Read the Components Section from the Generic Netlist and create Components section in Pads-Pcb format
|
/* Read the Components Section from the Generic Netlist and create Components section in Pads-Pcb format
|
||||||
For the component section only reference and footprint are used.
|
* For the component section only reference and footprint are used.
|
||||||
Create lines like:
|
* Create lines like:
|
||||||
C1 CHIP_D
|
* C1 CHIP_D
|
||||||
C2 unknown
|
* C2 unknown
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
char Line[1024];
|
char Line[1024];
|
||||||
class ComponentDataClass ComponentData;
|
|
||||||
char * ident, *data;
|
|
||||||
|
|
||||||
while( GetLine(InFile, Line, LineNumber, sizeof(Line) ) )
|
class ComponentDataClass ComponentData;
|
||||||
{
|
char* ident, * data;
|
||||||
if ( stricmp(Line, "$BeginPinList") == 0 )
|
|
||||||
{
|
|
||||||
while( GetLine(InFile, Line, LineNumber, sizeof(Line) ) )
|
|
||||||
if ( stricmp(Line, "$EndPinList") == 0 ) break;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( stricmp(Line, "$EndComponent") == 0 ) // Create the output for the component:
|
while( GetLine( InFile, Line, LineNumber, sizeof(Line) ) )
|
||||||
{
|
{
|
||||||
/* Create the line like: C2 unknown */
|
if( stricmp( Line, "$BeginPinList" ) == 0 )
|
||||||
|
{
|
||||||
|
while( GetLine( InFile, Line, LineNumber, sizeof(Line) ) )
|
||||||
|
if( stricmp( Line, "$EndPinList" ) == 0 )
|
||||||
|
break;
|
||||||
|
|
||||||
fprintf(OutFile, "%s ", ComponentData.m_Reference );
|
continue;
|
||||||
fprintf(OutFile, "%s\n",
|
}
|
||||||
strlen(ComponentData.m_Footprint) ? ComponentData.m_Footprint : "unknown");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
ident = strtok(Line,"=\n\r");
|
|
||||||
data = strtok(NULL,"=\n\r");
|
|
||||||
if ( data == NULL ) continue;
|
|
||||||
if ( stricmp(Line, "TimeStamp") == 0 )
|
|
||||||
{
|
|
||||||
ComponentData.m_TimeStamp = atol(data);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ( stricmp(Line, "Footprint") == 0 )
|
|
||||||
{
|
|
||||||
strncpy(ComponentData.m_Footprint, data, 255);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ( stricmp(Line, "Reference") == 0 )
|
|
||||||
{
|
|
||||||
strncpy(ComponentData.m_Reference, data, 255);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ( stricmp(Line, "Value") == 0 )
|
|
||||||
{
|
|
||||||
strncpy(ComponentData.m_Value, data, 255);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ( stricmp(Line, "Libref") == 0 )
|
|
||||||
{
|
|
||||||
strncpy(ComponentData.m_LibRef, data, 255);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1;
|
if( stricmp( Line, "$EndComponent" ) == 0 ) // Create the output for the component:
|
||||||
|
{
|
||||||
|
/* Create the line like: C2 unknown */
|
||||||
|
|
||||||
|
fprintf( OutFile, "%s ", ComponentData.m_Reference );
|
||||||
|
fprintf( OutFile, "%s\n",
|
||||||
|
strlen( ComponentData.m_Footprint ) ? ComponentData.m_Footprint : "unknown" );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ident = strtok( Line, "=\n\r" );
|
||||||
|
data = strtok( NULL, "=\n\r" );
|
||||||
|
if( data == NULL )
|
||||||
|
continue;
|
||||||
|
if( stricmp( Line, "TimeStamp" ) == 0 )
|
||||||
|
{
|
||||||
|
ComponentData.m_TimeStamp = atol( data );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if( stricmp( Line, "Footprint" ) == 0 )
|
||||||
|
{
|
||||||
|
strncpy( ComponentData.m_Footprint, data, 255 );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if( stricmp( Line, "Reference" ) == 0 )
|
||||||
|
{
|
||||||
|
strncpy( ComponentData.m_Reference, data, 255 );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if( stricmp( Line, "Value" ) == 0 )
|
||||||
|
{
|
||||||
|
strncpy( ComponentData.m_Value, data, 255 );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if( stricmp( Line, "Libref" ) == 0 )
|
||||||
|
{
|
||||||
|
strncpy( ComponentData.m_LibRef, data, 255 );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
int ReadAndWriteNetsDataSection(FILE * InFile, FILE * OutFile, int *LineNumber)
|
int ReadAndWriteNetsDataSection( FILE* InFile, FILE* OutFile, int* LineNumber )
|
||||||
/****************************************************************/
|
/****************************************************************/
|
||||||
|
|
||||||
/* Read the Nets Section from the Generic Netlist and create Nets section in Pads-Pcb format
|
/* Read the Nets Section from the Generic Netlist and create Nets section in Pads-Pcb format
|
||||||
create info type:
|
* create info type:
|
||||||
*SIGNAL* N03791
|
*SIGNAL* N03791
|
||||||
C3.1 R1.1 JP2.7 U1.3
|
* C3.1 R1.1 JP2.7 U1.3
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
char Line[1024];
|
char Line[1024];
|
||||||
char * ident, *netnum, *netname, * pin;
|
char* ident, * netnum, * netname, * pin;
|
||||||
|
|
||||||
while( GetLine(InFile, Line, LineNumber, sizeof(Line) ) )
|
while( GetLine( InFile, Line, LineNumber, sizeof(Line) ) )
|
||||||
{
|
{
|
||||||
if ( stricmp(Line, "$EndNets") == 0 ) return 0;
|
if( stricmp( Line, "$EndNets" ) == 0 )
|
||||||
ident = strtok(Line," \n\r");
|
return 0;
|
||||||
if ( stricmp(ident, "Net") == 0 )
|
ident = strtok( Line, " \n\r" );
|
||||||
{
|
if( stricmp( ident, "Net" ) == 0 )
|
||||||
netnum = strtok(NULL," \n\r");
|
{
|
||||||
netname = strtok(NULL," \"\n\r");
|
netnum = strtok( NULL, " \n\r" );
|
||||||
if ( (netname == NULL) || strlen(netname) == 0 )
|
netname = strtok( NULL, " \"\n\r" );
|
||||||
{ // Create the line like: *SIGNAL* N03791
|
if( (netname == NULL) || strlen( netname ) == 0 )
|
||||||
int num = atoi(netnum);
|
{ // Create the line like: *SIGNAL* N03791
|
||||||
sprintf(Line, "N-%6.6d", num);
|
int num = atoi( netnum );
|
||||||
netname = Line;
|
sprintf( Line, "N-%6.6d", num );
|
||||||
}
|
netname = Line;
|
||||||
fprintf(OutFile, "*SIGNAL* %s\n", netname);
|
}
|
||||||
}
|
fprintf( OutFile, "*SIGNAL* %s\n", netname );
|
||||||
else
|
}
|
||||||
{ // Create the line like: C3.1 R1.1 JP2.7 U1.3
|
else
|
||||||
pin = strtok(NULL," \n\r");
|
{
|
||||||
fprintf(OutFile, " %s.%s\n", ident, pin);
|
// Create the line like: C3.1 R1.1 JP2.7 U1.3
|
||||||
}
|
pin = strtok( NULL, " \n\r" );
|
||||||
}
|
fprintf( OutFile, " %s.%s\n", ident, pin );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************/
|
/*****************************************************************/
|
||||||
char * GetLine(FILE *File, char *Line, int *LineNum, int SizeLine)
|
char* GetLine( FILE* File, char* Line, int* LineNum, int SizeLine )
|
||||||
/*****************************************************************/
|
/*****************************************************************/
|
||||||
|
|
||||||
/* Return a non empty line
|
/* Return a non empty line
|
||||||
increment *LineNum for each read line
|
* increment *LineNum for each read line
|
||||||
Comment lines (starting by '#') are skipped
|
* Comment lines (starting by '#') are skipped
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
do {
|
do {
|
||||||
if (fgets(Line, SizeLine, File) == NULL) return NULL;
|
if( fgets( Line, SizeLine, File ) == NULL )
|
||||||
if( LineNum ) *LineNum += 1;
|
return NULL;
|
||||||
} while (Line[0] == '#' || Line[0] == '\n' || Line[0] == '\r' ||
|
if( LineNum )
|
||||||
Line[0] == 0);
|
*LineNum += 1;
|
||||||
|
} while( Line[0] == '#' || Line[0] == '\n' || Line[0] == '\r'
|
||||||
|
|| Line[0] == 0 );
|
||||||
|
|
||||||
strtok(Line,"\n\r");
|
strtok( Line, "\n\r" );
|
||||||
return Line;
|
return Line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue