Commit 4ca51f75 authored by dickelbeck's avatar dickelbeck
Browse files

mac support fixes

parent 4987c15e
Loading
Loading
Loading
Loading
+279 −268
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@
#include <string.h>
#include <ctype.h>

#ifdef __UNIX__
#if defined (__UNIX__) || defined (__APPLE__)
#define stricmp  strcasecmp
#define strnicmp strncasecmp
#endif
@@ -17,91 +17,91 @@
/* Pads-pcb sample:
 *PADS-PCB*
 *PART*
C1 CHIP_D
C2 C1206
C3 CHIP_B
C4 CHIP_B
D1 CHIP_B
JP1 unknown

 *  C1 CHIP_D
 *  C2 C1206
 *  C3 CHIP_B
 *  C4 CHIP_B
 *  D1 CHIP_B
 *  JP1 unknown
 * 
 *NET*
 *SIGNAL* N03791
C3.1 R1.1 JP2.7 U1.3
 *  C3.1 R1.1 JP2.7 U1.3
 *SIGNAL* VCC
 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
 *  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
 *SIGNAL* N01384
 JP5.1 U1.1
 *  JP5.1 U1.1
 *SIGNAL* N02594
 *END*
 */


/* Generic netlist sample:
$BeginNetlist
$BeginComponentList

$BeginComponent
TimeStamp=32568D1E
Footprint=
Reference=JP1
Value=CONN_8X2
Libname=CONN_8X2
$BeginPinList
1=GND
2=REF10_1
3=GND
4=REF11_1
5=GND
6=REF7_1
7=GND
8=REF9_1
9=GND
10=REF6_1
11=GND
12=REF8_1
13=GND
14=REF4_1
15=GND
16=REF5_1
$EndPinList
$EndComponent

$BeginComponent
TimeStamp=325679C1
Footprint=
Reference=RR1
Value=9x1K
Libref=RR9
$BeginPinList
1=VCC
2=REF5_1
3=REF4_1
4=REF8_1
5=REF6_1
6=REF9_1
7=REF7_1
8=REF11_1
9=REF10_1
10=?
$EndPinList
$EndComponent
$EndComponentList

$BeginNets
Net 0 ""
Net 1 "GND"
 BUS1 31
 U3 19
 U3 10
 U3 1
Net 172 ""
 BUS1 32
Net 173 ""
 BUS1 30
$EndNets

$EndNetlist
 *  $BeginNetlist
 *  $BeginComponentList
 * 
 *  $BeginComponent
 *  TimeStamp=32568D1E
 *  Footprint=
 *  Reference=JP1
 *  Value=CONN_8X2
 *  Libname=CONN_8X2
 *  $BeginPinList
 *  1=GND
 *  2=REF10_1
 *  3=GND
 *  4=REF11_1
 *  5=GND
 *  6=REF7_1
 *  7=GND
 *  8=REF9_1
 *  9=GND
 *  10=REF6_1
 *  11=GND
 *  12=REF8_1
 *  13=GND
 *  14=REF4_1
 *  15=GND
 *  16=REF5_1
 *  $EndPinList
 *  $EndComponent
 * 
 *  $BeginComponent
 *  TimeStamp=325679C1
 *  Footprint=
 *  Reference=RR1
 *  Value=9x1K
 *  Libref=RR9
 *  $BeginPinList
 *  1=VCC
 *  2=REF5_1
 *  3=REF4_1
 *  4=REF8_1
 *  5=REF6_1
 *  6=REF9_1
 *  7=REF7_1
 *  8=REF11_1
 *  9=REF10_1
 *  10=?
 *  $EndPinList
 *  $EndComponent
 *  $EndComponentList
 * 
 *  $BeginNets
 *  Net 0 ""
 *  Net 1 "GND"
 *  BUS1 31
 *  U3 19
 *  U3 10
 *  U3 1
 *  Net 172 ""
 *  BUS1 32
 *  Net 173 ""
 *  BUS1 30
 *  $EndNets
 * 
 *  $EndNetlist
 */

char*   GetLine( FILE* File, char* Line, int* LineNum, int SizeLine );
@@ -109,7 +109,6 @@ int ReadAndWriteComponentDataSection(FILE * InFile, FILE * OutFile, int *LineNum
int     ReadAndWriteNetsDataSection( FILE* InFile, FILE* OutFile, int* LineNumber );



class ComponentDataClass
{
public:
@@ -124,6 +123,8 @@ public:
    {
        InitData();
    }


    void InitData( void )
    {
        m_TimeStamp    = 0;
@@ -197,14 +198,16 @@ char Line[1024];
/****************************************************************/
int ReadAndWriteComponentDataSection( FILE* InFile, FILE* OutFile, int* LineNumber )
/****************************************************************/

/* 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.
	Create lines like:
	C1 CHIP_D
	C2 unknown
 *  For the component section only reference and footprint are used.
 *  Create lines like:
 *  C1 CHIP_D
 *  C2 unknown
 */
{
    char  Line[1024];

    class ComponentDataClass ComponentData;
    char* ident, * data;

@@ -213,7 +216,9 @@ char * ident, *data;
        if( stricmp( Line, "$BeginPinList" ) == 0 )
        {
            while( GetLine( InFile, Line, LineNumber, sizeof(Line) ) )
				if ( stricmp(Line, "$EndPinList") == 0 ) break;
                if( stricmp( Line, "$EndPinList" ) == 0 )
                    break;

            continue;
        }

@@ -228,7 +233,8 @@ char * ident, *data;
        }
        ident = strtok( Line, "=\n\r" );
        data  = strtok( NULL, "=\n\r" );
		if ( data == NULL ) continue;
        if( data == NULL )
            continue;
        if( stricmp( Line, "TimeStamp" ) == 0 )
        {
            ComponentData.m_TimeStamp = atol( data );
@@ -259,13 +265,15 @@ char * ident, *data;
    return 1;
}


/****************************************************************/
int ReadAndWriteNetsDataSection( FILE* InFile, FILE* OutFile, int* LineNumber )
/****************************************************************/

/* Read the Nets Section from the Generic Netlist and create Nets section in Pads-Pcb format
	create info type:
 *  create info type:
 *SIGNAL* N03791
	C3.1 R1.1 JP2.7 U1.3
 *  C3.1 R1.1 JP2.7 U1.3
 */
{
    char  Line[1024];
@@ -273,7 +281,8 @@ char * ident, *netnum, *netname, * pin;

    while( GetLine( InFile, Line, LineNumber, sizeof(Line) ) )
    {
		if ( stricmp(Line, "$EndNets") == 0 ) return 0;
        if( stricmp( Line, "$EndNets" ) == 0 )
            return 0;
        ident = strtok( Line, " \n\r" );
        if( stricmp( ident, "Net" ) == 0 )
        {
@@ -288,7 +297,8 @@ char * ident, *netnum, *netname, * pin;
            fprintf( OutFile, "*SIGNAL* %s\n", netname );
        }
        else
		{	// Create the line like:   C3.1 R1.1 JP2.7 U1.3
        {
            // Create the line like:   C3.1 R1.1 JP2.7 U1.3
            pin = strtok( NULL, " \n\r" );
            fprintf( OutFile, " %s.%s\n", ident, pin );
        }
@@ -301,19 +311,20 @@ char * ident, *netnum, *netname, * pin;
/*****************************************************************/
char* GetLine( FILE* File, char* Line, int* LineNum, int SizeLine )
/*****************************************************************/

/* Return a non empty line
	increment *LineNum for each read line
	Comment lines (starting by '#') are skipped
 *  increment *LineNum for each read line
 *  Comment lines (starting by '#') are skipped
 */
{
    do  {
		if (fgets(Line, SizeLine, File) == NULL) return NULL;
		if( LineNum ) *LineNum += 1;
		} while (Line[0] == '#' || Line[0] == '\n' ||  Line[0] == '\r' ||
				Line[0] == 0);
        if( fgets( Line, SizeLine, File ) == NULL )
            return NULL;
        if( LineNum )
            *LineNum += 1;
    } while( Line[0] == '#' || Line[0] == '\n' ||  Line[0] == '\r'
             || Line[0] == 0 );

    strtok( Line, "\n\r" );
    return Line;
}