2005-07-29 17:01:00 +02:00
|
|
|
/**CFile****************************************************************
|
|
|
|
|
|
|
|
|
|
FileName [mainUtils.c]
|
|
|
|
|
|
|
|
|
|
SystemName [ABC: Logic synthesis and verification system.]
|
|
|
|
|
|
|
|
|
|
PackageName [The main package.]
|
|
|
|
|
|
|
|
|
|
Synopsis [Miscellaneous utilities.]
|
2010-11-01 09:35:04 +01:00
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
Author [Alan Mishchenko]
|
|
|
|
|
|
|
|
|
|
Affiliation [UC Berkeley]
|
|
|
|
|
|
|
|
|
|
Date [Ver. 1.0. Started - June 20, 2005.]
|
|
|
|
|
|
|
|
|
|
Revision [$Id: mainUtils.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
2012-07-08 05:14:12 +02:00
|
|
|
#include "base/abc/abc.h"
|
2005-07-29 17:01:00 +02:00
|
|
|
#include "mainInt.h"
|
|
|
|
|
|
2012-10-04 22:03:04 +02:00
|
|
|
#if !defined(_WIN32) && !defined(AIX)
|
2012-10-07 03:28:25 +02:00
|
|
|
// comment out the following line if 'readline' is not available
|
|
|
|
|
#define ABC_USE_READ_LINE
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef ABC_USE_READ_LINE
|
2008-03-01 17:01:00 +01:00
|
|
|
#include <readline/readline.h>
|
2008-07-02 17:01:00 +02:00
|
|
|
#include <readline/history.h>
|
2008-01-31 05:01:00 +01:00
|
|
|
#endif
|
|
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
ABC_NAMESPACE_IMPL_START
|
|
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// DECLARATIONS ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2010-11-01 09:35:04 +01:00
|
|
|
|
|
|
|
|
static char * DateReadFromDateString( char * datestr );
|
2005-07-29 17:01:00 +02:00
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2008-01-31 05:01:00 +01:00
|
|
|
/// FUNCTION DEFINITIONS ///
|
2005-07-29 17:01:00 +02:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
char * Abc_UtilsGetVersion( Abc_Frame_t * pAbc )
|
|
|
|
|
{
|
|
|
|
|
static char Version[1000];
|
|
|
|
|
sprintf(Version, "%s (compiled %s %s)", ABC_VERSION, __DATE__, __TIME__);
|
|
|
|
|
return Version;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
char * Abc_UtilsGetUsersInput( Abc_Frame_t * pAbc )
|
|
|
|
|
{
|
2011-12-09 09:37:05 +01:00
|
|
|
static char Prompt[5000];
|
2005-07-29 17:01:00 +02:00
|
|
|
sprintf( Prompt, "abc %02d> ", pAbc->nSteps );
|
2012-10-07 03:28:25 +02:00
|
|
|
#ifdef ABC_USE_READ_LINE
|
2012-09-29 23:50:50 +02:00
|
|
|
{
|
|
|
|
|
static char * line = NULL;
|
2009-02-15 17:01:00 +01:00
|
|
|
if (line != NULL) ABC_FREE(line);
|
2008-01-31 05:01:00 +01:00
|
|
|
line = readline(Prompt);
|
|
|
|
|
if (line == NULL){ printf("***EOF***\n"); exit(0); }
|
|
|
|
|
add_history(line);
|
|
|
|
|
return line;
|
2012-09-29 23:50:50 +02:00
|
|
|
}
|
|
|
|
|
#else
|
2012-09-29 23:56:00 +02:00
|
|
|
{
|
|
|
|
|
char * pRetValue;
|
2012-09-29 23:50:50 +02:00
|
|
|
fprintf( pAbc->Out, "%s", Prompt );
|
2012-09-29 23:56:00 +02:00
|
|
|
pRetValue = fgets( Prompt, 5000, stdin );
|
2012-09-29 23:50:50 +02:00
|
|
|
return Prompt;
|
2012-09-29 23:56:00 +02:00
|
|
|
}
|
2008-01-31 05:01:00 +01:00
|
|
|
#endif
|
2005-07-29 17:01:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
void Abc_UtilsPrintHello( Abc_Frame_t * pAbc )
|
|
|
|
|
{
|
|
|
|
|
fprintf( pAbc->Out, "%s\n", pAbc->sVersion );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
void Abc_UtilsPrintUsage( Abc_Frame_t * pAbc, char * ProgName )
|
|
|
|
|
{
|
|
|
|
|
fprintf( pAbc->Err, "\n" );
|
|
|
|
|
fprintf( pAbc->Err,
|
2012-03-02 09:57:48 +01:00
|
|
|
"usage: %s [-c cmd] [-f script] [-h] [-o file] [-s] [-t type] [-T type] [-x] [-b] [file]\n",
|
2005-07-29 17:01:00 +02:00
|
|
|
ProgName);
|
|
|
|
|
fprintf( pAbc->Err, " -c cmd\texecute commands `cmd'\n");
|
|
|
|
|
fprintf( pAbc->Err, " -F script\texecute commands from a script file and echo commands\n");
|
|
|
|
|
fprintf( pAbc->Err, " -f script\texecute commands from a script file\n");
|
|
|
|
|
fprintf( pAbc->Err, " -h\t\tprint the command usage\n");
|
|
|
|
|
fprintf( pAbc->Err, " -o file\tspecify output filename to store the result\n");
|
|
|
|
|
fprintf( pAbc->Err, " -s\t\tdo not read any initialization file\n");
|
|
|
|
|
fprintf( pAbc->Err, " -t type\tspecify input type (blif_mv (default), blif_mvs, blif, or none)\n");
|
|
|
|
|
fprintf( pAbc->Err, " -T type\tspecify output type (blif_mv (default), blif_mvs, blif, or none)\n");
|
|
|
|
|
fprintf( pAbc->Err, " -x\t\tequivalent to '-t none -T none'\n");
|
2012-03-02 09:57:48 +01:00
|
|
|
fprintf( pAbc->Err, " -b\t\trunning in bridge mode\n");
|
2005-07-29 17:01:00 +02:00
|
|
|
fprintf( pAbc->Err, "\n" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
void Abc_UtilsSource( Abc_Frame_t * pAbc )
|
|
|
|
|
{
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
if ( Cmd_CommandExecute(pAbc, "source abc.rc") )
|
|
|
|
|
{
|
|
|
|
|
if ( Cmd_CommandExecute(pAbc, "source ..\\abc.rc") == 0 )
|
|
|
|
|
printf( "Loaded \"abc.rc\" from the parent directory.\n" );
|
|
|
|
|
else if ( Cmd_CommandExecute(pAbc, "source ..\\..\\abc.rc") == 0 )
|
|
|
|
|
printf( "Loaded \"abc.rc\" from the grandparent directory.\n" );
|
|
|
|
|
}
|
|
|
|
|
#else
|
2008-01-31 05:01:00 +01:00
|
|
|
|
|
|
|
|
#if 0
|
2005-07-29 17:01:00 +02:00
|
|
|
{
|
2008-01-31 05:01:00 +01:00
|
|
|
char * sPath1, * sPath2;
|
2005-07-29 17:01:00 +02:00
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
// If .rc is present in both the home and current directories, then read
|
|
|
|
|
// it from the home directory. Otherwise, read it from wherever it's located.
|
|
|
|
|
sPath1 = Extra_UtilFileSearch(".rc", "~/", "r");
|
|
|
|
|
sPath2 = Extra_UtilFileSearch(".rc", ".", "r");
|
2005-07-29 17:01:00 +02:00
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
if ( sPath1 && sPath2 ) {
|
|
|
|
|
/* ~/.rc == .rc : Source the file only once */
|
2005-07-29 17:01:00 +02:00
|
|
|
(void) Cmd_CommandExecute(pAbc, "source -s ~/.rc");
|
|
|
|
|
}
|
2008-01-31 05:01:00 +01:00
|
|
|
else {
|
|
|
|
|
if (sPath1) {
|
|
|
|
|
(void) Cmd_CommandExecute(pAbc, "source -s ~/.rc");
|
|
|
|
|
}
|
|
|
|
|
if (sPath2) {
|
|
|
|
|
(void) Cmd_CommandExecute(pAbc, "source -s .rc");
|
|
|
|
|
}
|
2005-07-29 17:01:00 +02:00
|
|
|
}
|
2009-02-15 17:01:00 +01:00
|
|
|
if ( sPath1 ) ABC_FREE(sPath1);
|
|
|
|
|
if ( sPath2 ) ABC_FREE(sPath2);
|
2008-01-30 17:01:00 +01:00
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
/* execute the abc script which can be open with the "open_path" */
|
|
|
|
|
Cmd_CommandExecute( pAbc, "source -s abc.rc" );
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
#ifdef ABC_PYTHON_EMBED
|
|
|
|
|
if ( getenv("ABC_PYTHON_ABC_RC") )
|
|
|
|
|
{
|
|
|
|
|
/* read script file from $ABC_PYTHON_ABC_RC */
|
|
|
|
|
|
|
|
|
|
char * sPath = getenv("ABC_PYTHON_ABC_RC");
|
|
|
|
|
|
|
|
|
|
if (sPath){
|
|
|
|
|
char * sCmd = ABC_ALLOC(char, strlen(sPath) + 50);
|
|
|
|
|
(void) sprintf(sCmd, "source -s %s", sPath);
|
|
|
|
|
(void) Cmd_CommandExecute(pAbc, sCmd);
|
|
|
|
|
ABC_FREE(sCmd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif /* #ifdef ABC_PYTHON_EMBED */
|
2012-08-24 21:25:53 +02:00
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
{
|
|
|
|
|
char * sPath1, * sPath2;
|
|
|
|
|
char * home;
|
|
|
|
|
|
|
|
|
|
// If .rc is present in both the home and current directories, then read
|
|
|
|
|
// it from the home directory. Otherwise, read it from wherever it's located.
|
|
|
|
|
home = getenv("HOME");
|
|
|
|
|
if (home){
|
2009-02-15 17:01:00 +01:00
|
|
|
char * sPath3 = ABC_ALLOC(char, strlen(home) + 2);
|
2008-01-31 05:01:00 +01:00
|
|
|
(void) sprintf(sPath3, "%s/", home);
|
|
|
|
|
sPath1 = Extra_UtilFileSearch(".abc.rc", sPath3, "r");
|
2009-02-15 17:01:00 +01:00
|
|
|
ABC_FREE(sPath3);
|
2008-01-31 05:01:00 +01:00
|
|
|
}else
|
|
|
|
|
sPath1 = NULL;
|
|
|
|
|
|
|
|
|
|
sPath2 = Extra_UtilFileSearch(".abc.rc", ".", "r");
|
|
|
|
|
|
|
|
|
|
if ( sPath1 && sPath2 ) {
|
|
|
|
|
/* ~/.rc == .rc : Source the file only once */
|
2009-02-15 17:01:00 +01:00
|
|
|
char *tmp_cmd = ABC_ALLOC(char, strlen(sPath1)+12);
|
2008-10-04 17:01:00 +02:00
|
|
|
(void) sprintf(tmp_cmd, "source -s %s", sPath1);
|
|
|
|
|
// (void) Cmd_CommandExecute(pAbc, "source -s ~/.abc.rc");
|
|
|
|
|
(void) Cmd_CommandExecute(pAbc, tmp_cmd);
|
2009-02-15 17:01:00 +01:00
|
|
|
ABC_FREE(tmp_cmd);
|
2008-01-31 05:01:00 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (sPath1) {
|
2009-02-15 17:01:00 +01:00
|
|
|
char *tmp_cmd = ABC_ALLOC(char, strlen(sPath1)+12);
|
2008-10-04 17:01:00 +02:00
|
|
|
(void) sprintf(tmp_cmd, "source -s %s", sPath1);
|
|
|
|
|
// (void) Cmd_CommandExecute(pAbc, "source -s ~/.abc.rc");
|
|
|
|
|
(void) Cmd_CommandExecute(pAbc, tmp_cmd);
|
2009-02-15 17:01:00 +01:00
|
|
|
ABC_FREE(tmp_cmd);
|
2008-01-31 05:01:00 +01:00
|
|
|
}
|
|
|
|
|
if (sPath2) {
|
2009-02-15 17:01:00 +01:00
|
|
|
char *tmp_cmd = ABC_ALLOC(char, strlen(sPath2)+12);
|
2008-10-04 17:01:00 +02:00
|
|
|
(void) sprintf(tmp_cmd, "source -s %s", sPath2);
|
|
|
|
|
// (void) Cmd_CommandExecute(pAbc, "source -s .abc.rc");
|
|
|
|
|
(void) Cmd_CommandExecute(pAbc, tmp_cmd);
|
2009-02-15 17:01:00 +01:00
|
|
|
ABC_FREE(tmp_cmd);
|
2008-01-31 05:01:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
2009-02-15 17:01:00 +01:00
|
|
|
if ( sPath1 ) ABC_FREE(sPath1);
|
|
|
|
|
if ( sPath2 ) ABC_FREE(sPath2);
|
2008-01-31 05:01:00 +01:00
|
|
|
|
|
|
|
|
/* execute the abc script which can be open with the "open_path" */
|
|
|
|
|
Cmd_CommandExecute( pAbc, "source -s abc.rc" );
|
2007-09-30 17:01:00 +02:00
|
|
|
}
|
2010-11-01 09:35:04 +01:00
|
|
|
|
2005-07-29 17:01:00 +02:00
|
|
|
#endif //WIN32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function********************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Returns the date in a brief format assuming its coming from
|
|
|
|
|
the program `date'.]
|
|
|
|
|
|
|
|
|
|
Description [optional]
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
******************************************************************************/
|
2010-11-01 09:35:04 +01:00
|
|
|
char * DateReadFromDateString( char * datestr )
|
2005-07-29 17:01:00 +02:00
|
|
|
{
|
|
|
|
|
static char result[25];
|
|
|
|
|
char day[10];
|
|
|
|
|
char month[10];
|
|
|
|
|
char zone[10];
|
|
|
|
|
char *at;
|
|
|
|
|
int date;
|
|
|
|
|
int hour;
|
|
|
|
|
int minute;
|
|
|
|
|
int second;
|
|
|
|
|
int year;
|
|
|
|
|
|
|
|
|
|
if (sscanf(datestr, "%s %s %2d %2d:%2d:%2d %s %4d",
|
|
|
|
|
day, month, &date, &hour, &minute, &second, zone, &year) == 8) {
|
|
|
|
|
if (hour >= 12) {
|
|
|
|
|
if (hour >= 13) hour -= 12;
|
|
|
|
|
at = "PM";
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (hour == 0) hour = 12;
|
|
|
|
|
at = "AM";
|
|
|
|
|
}
|
|
|
|
|
(void) sprintf(result, "%d-%3s-%02d at %d:%02d %s",
|
|
|
|
|
date, month, year % 100, hour, minute, at);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return datestr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// END OF FILE ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
ABC_NAMESPACE_IMPL_END
|
|
|
|
|
|