ecs2vl.c 3.37 KB
#include "spikproc.h"

int Process_File();
extern char BaseFileName[], SymFileName[], SchmFileName[];
extern char ProgramName[];
int symbol_only;
unsigned long permission_mask = ALL_OK;
FILE *f;
char cname[64];
int n0;

int main( ac, av )
int ac;
char *av[];
{ 
    char str[256],str1[256],str2[256];
    int i,si;

    if(ac!=3)
	exit(1);
    if(!Initialize()) 
	exit(1);
    sprintf( ProgramName, "ecs2vl ( %s )", av[1] );
    sprintf(str,"%s",av[2]);
    f = fopen(str,"w");
    strcpy(str1,av[1]);
    for(si=-1,i=0;av[1][i];i++)
	if(str1[i]=='/')
	    si = i;
    if(si>=0)
    {
	str1[si]=0;
	chdir(str1);
	strcpy(str2,&str1[si+1]);
    }
    else
	strcpy(str2,str1);
    if(f)
    {
	fprintf(f,"DW %s\n",str2);
        Process_File(str2);
        fclose(f);
    }
}

Do_Pin( sp, pn, pin )
SP_PTR sp;
PN_PTR pn;
struct _pin *pin;
{
    char name[256],netname[256];
    char *pinname;
    NT_PTR nt;

    nt = NetContainingPin( sp );
    if(nt)
    {
	strcpy(netname,Get_NA(nt,NAME));
	if(netname[0]=='_')
	    netname[0]='~';
	fprintf(f," %s",netname);
    }
    else
	fprintf(f," ?");
    return(FALSE );
}

static int Do_Port( pn, pin )
WORD pn;
struct _pin *pin;
{ 
    char  name[256];

    hstrcpy( name, Get_PNA( pn, NAME ) );
    if(name[0]=='_')
	name[0]='~';
    if ( *Get_PNA( pn, PINUSE ) == 'O' )
	fprintf(f,"AP %s %d PINTYPE=OUT\n",cname,n0++,name);
    if ( *Get_PNA( pn, PINUSE ) == 'I' )
	fprintf(f,"AP %s %d PINTYPE=IN\n",cname,n0++,name);
    if ( *Get_PNA( pn, PINUSE ) == 'B' )
	fprintf(f,"AP %s %d PINTYPE=INOUT\n",cname,n0++,name);
    return(FALSE);
}

static int Do_Port1( pn, pin )
WORD pn;
struct _pin *pin;
{ 
    char  name[256];

    hstrcpy( name, Get_PNA( pn, NAME ) );
    if(name[0]=='_')
	name[0]='~';
    fprintf(f," %s",name);
    return(FALSE);
}

int Do_Component( st )
ST_PTR st;
{

   Activate_Symbol_Type( st );
   hstrcpy(cname,Get_DA(st,NAME));
   strlwr(cname);
   fprintf(f,"AS %s pinorder =",cname);
   ForEachSymbolPin(Do_Port1);
   fprintf(f,"\n");
   n0 = 1;
   ForEachSymbolPin(Do_Port);
   return( FALSE );
}

int Do_Instance( si, inst )
SI_PTR si;
struct _inst *inst;
{ 
    ST_PTR st;
    char instance_name[80];
    char module_name[256];
    int type;

    st = TypeOfInstance( si );

    hstrcpy( (char _huge *)module_name, Get_DA( st, NAME ) );
    strlwr( module_name );
    hstrcpy( (char _huge *)instance_name, Get_IA( si, NAME ) );
    fprintf(f,"I %s %s",instance_name,module_name);
    ForEachInstancePin(si,Do_Pin);
    fprintf(f," LABEL=%s`\n",instance_name);
    return(FALSE);
}

int Process_File( name )
char *name;
{ 
    int ok;
    char buff[256];
    int retn = FALSE;

    AddExt( name, "" );
    strcpy(SchmFileName,name );
    strcpy(SymFileName,name );
    strcpy(BaseFileName,FileInPath( SymFileName ) );
    Free_Memory();
    CTL_LeftParen = '[';
    CTL_RightParen = ']';
    ok = LoadSymbol(SymFileName);
    if (ok)
    { 
	if ( LoadSchematic( SchmFileName ) )
	{ 
	    symbol_only = FALSE;
	    if ( ok = LoadSymbolsUsed() );
	    else fprintf(stderr,"Unable to Load Symbols for %s.sch\n", name );
	}
	else symbol_only = TRUE;
    }
    else
	fprintf(stderr,"Can Not Read Symbol File %s.sym\n", name );


    if(ok)
    {
	ForEachSymbolType(Do_Component);
	fprintf(f,"G GND\n");
	fprintf(f,"G VCC\n");
	ForEachSymbolInstance(0,0x00,Do_Instance);
    }
    return( retn );
}

int ErrorMsg( string )
char *string;
{
   MajorError( string );
   return( 1 );
}