diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2010-11-01 01:35:04 -0700 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2010-11-01 01:35:04 -0700 |
commit | 6130e39b18b5f53902e4eab14f6d5cdde5219563 (patch) | |
tree | 0db0628479a1b750e9af1f66cb8379ebd0913d31 /src/base/cmd | |
parent | f0e77f6797c0504b0da25a56152b707d3357f386 (diff) | |
download | abc-6130e39b18b5f53902e4eab14f6d5cdde5219563.tar.gz abc-6130e39b18b5f53902e4eab14f6d5cdde5219563.tar.bz2 abc-6130e39b18b5f53902e4eab14f6d5cdde5219563.zip |
initial commit of public abc
Diffstat (limited to 'src/base/cmd')
-rw-r--r-- | src/base/cmd/cmd.c | 92 | ||||
-rw-r--r-- | src/base/cmd/cmd.h | 30 | ||||
-rw-r--r-- | src/base/cmd/cmdAlias.c | 6 | ||||
-rw-r--r-- | src/base/cmd/cmdApi.c | 19 | ||||
-rw-r--r-- | src/base/cmd/cmdFlag.c | 10 | ||||
-rw-r--r-- | src/base/cmd/cmdHist.c | 8 | ||||
-rw-r--r-- | src/base/cmd/cmdInt.h | 14 | ||||
-rw-r--r-- | src/base/cmd/cmdLoad.c | 226 | ||||
-rw-r--r-- | src/base/cmd/cmdPlugin.c | 629 | ||||
-rw-r--r-- | src/base/cmd/cmdUtils.c | 60 | ||||
-rw-r--r-- | src/base/cmd/module.make | 2 |
11 files changed, 1008 insertions, 88 deletions
diff --git a/src/base/cmd/cmd.c b/src/base/cmd/cmd.c index 398415ae..47b031bc 100644 --- a/src/base/cmd/cmd.c +++ b/src/base/cmd/cmd.c @@ -24,9 +24,11 @@ #include <unistd.h> #endif +#include "abc.h" #include "mainInt.h" #include "cmdInt.h" -#include "abc.h" + +ABC_NAMESPACE_IMPL_START //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// @@ -46,7 +48,7 @@ static int CmdCommandUnsetVariable ( Abc_Frame_t * pAbc, int argc, char ** argv static int CmdCommandUndo ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int CmdCommandRecall ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int CmdCommandEmpty ( Abc_Frame_t * pAbc, int argc, char ** argv ); -#ifdef WIN32 +#if defined(WIN32) && !defined(__cplusplus) static int CmdCommandLs ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int CmdCommandScrGen ( Abc_Frame_t * pAbc, int argc, char ** argv ); #endif @@ -55,6 +57,8 @@ static int CmdCommandSis ( Abc_Frame_t * pAbc, int argc, char ** argv static int CmdCommandMvsis ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int CmdCommandCapo ( Abc_Frame_t * pAbc, int argc, char ** argv ); +extern int Cmd_CommandAbcLoadPlugIn( Abc_Frame_t * pAbc, int argc, char ** argv ); + //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// @@ -75,28 +79,30 @@ void Cmd_Init( Abc_Frame_t * pAbc ) pAbc->tFlags = st_init_table(strcmp, st_strhash); pAbc->aHistory = Vec_PtrAlloc( 100 ); - Cmd_CommandAdd( pAbc, "Basic", "time", CmdCommandTime, 0); - Cmd_CommandAdd( pAbc, "Basic", "echo", CmdCommandEcho, 0); - Cmd_CommandAdd( pAbc, "Basic", "quit", CmdCommandQuit, 0); - Cmd_CommandAdd( pAbc, "Basic", "history", CmdCommandHistory, 0); - Cmd_CommandAdd( pAbc, "Basic", "alias", CmdCommandAlias, 0); - Cmd_CommandAdd( pAbc, "Basic", "unalias", CmdCommandUnalias, 0); - Cmd_CommandAdd( pAbc, "Basic", "help", CmdCommandHelp, 0); - Cmd_CommandAdd( pAbc, "Basic", "source", CmdCommandSource, 0); - Cmd_CommandAdd( pAbc, "Basic", "set", CmdCommandSetVariable, 0); - Cmd_CommandAdd( pAbc, "Basic", "unset", CmdCommandUnsetVariable, 0); - Cmd_CommandAdd( pAbc, "Basic", "undo", CmdCommandUndo, 0); - Cmd_CommandAdd( pAbc, "Basic", "recall", CmdCommandRecall, 0); - Cmd_CommandAdd( pAbc, "Basic", "empty", CmdCommandEmpty, 0); -#ifdef WIN32 - Cmd_CommandAdd( pAbc, "Basic", "ls", CmdCommandLs, 0 ); - Cmd_CommandAdd( pAbc, "Basic", "scrgen", CmdCommandScrGen, 0 ); + Cmd_CommandAdd( pAbc, "Basic", "time", CmdCommandTime, 0 ); + Cmd_CommandAdd( pAbc, "Basic", "echo", CmdCommandEcho, 0 ); + Cmd_CommandAdd( pAbc, "Basic", "quit", CmdCommandQuit, 0 ); + Cmd_CommandAdd( pAbc, "Basic", "history", CmdCommandHistory, 0 ); + Cmd_CommandAdd( pAbc, "Basic", "alias", CmdCommandAlias, 0 ); + Cmd_CommandAdd( pAbc, "Basic", "unalias", CmdCommandUnalias, 0 ); + Cmd_CommandAdd( pAbc, "Basic", "help", CmdCommandHelp, 0 ); + Cmd_CommandAdd( pAbc, "Basic", "source", CmdCommandSource, 0 ); + Cmd_CommandAdd( pAbc, "Basic", "set", CmdCommandSetVariable, 0 ); + Cmd_CommandAdd( pAbc, "Basic", "unset", CmdCommandUnsetVariable, 0 ); + Cmd_CommandAdd( pAbc, "Basic", "undo", CmdCommandUndo, 0 ); + Cmd_CommandAdd( pAbc, "Basic", "recall", CmdCommandRecall, 0 ); + Cmd_CommandAdd( pAbc, "Basic", "empty", CmdCommandEmpty, 0 ); +#if defined(WIN32) && !defined(__cplusplus) + Cmd_CommandAdd( pAbc, "Basic", "ls", CmdCommandLs, 0 ); + Cmd_CommandAdd( pAbc, "Basic", "scrgen", CmdCommandScrGen, 0 ); #endif - Cmd_CommandAdd( pAbc, "Basic", "version", CmdCommandVersion, 0); + Cmd_CommandAdd( pAbc, "Basic", "version", CmdCommandVersion, 0 ); + + Cmd_CommandAdd( pAbc, "Various", "sis", CmdCommandSis, 1 ); + Cmd_CommandAdd( pAbc, "Various", "mvsis", CmdCommandMvsis, 1 ); + Cmd_CommandAdd( pAbc, "Various", "capo", CmdCommandCapo, 0 ); - Cmd_CommandAdd( pAbc, "Various", "sis", CmdCommandSis, 1); - Cmd_CommandAdd( pAbc, "Various", "mvsis", CmdCommandMvsis, 1); - Cmd_CommandAdd( pAbc, "Various", "capo", CmdCommandCapo, 0); + Cmd_CommandAdd( pAbc, "Various", "load_plugin", Cmd_CommandAbcLoadPlugIn, 0 ); } /**Function******************************************************************** @@ -118,17 +124,17 @@ void Cmd_End( Abc_Frame_t * pAbc ) // st_free_table( pAbc->tCommands, (void (*)()) 0, CmdCommandFree ); // st_free_table( pAbc->tAliases, (void (*)()) 0, CmdCommandAliasFree ); -// st_free_table( pAbc->tFlags, ABC_FREE, ABC_FREE ); +// st_free_table( pAbc->tFlags, free, free ); - st_foreach_item( pAbc->tCommands, gen, (char **)&pKey, (char **)&pValue ) + st_foreach_item( pAbc->tCommands, gen, (const char **)&pKey, (char **)&pValue ) CmdCommandFree( (Abc_Command *)pValue ); st_free_table( pAbc->tCommands ); - st_foreach_item( pAbc->tAliases, gen, (char **)&pKey, (char **)&pValue ) + st_foreach_item( pAbc->tAliases, gen, (const char **)&pKey, (char **)&pValue ) CmdCommandAliasFree( (Abc_Alias *)pValue ); st_free_table( pAbc->tAliases ); - st_foreach_item( pAbc->tFlags, gen, (char **)&pKey, (char **)&pValue ) + st_foreach_item( pAbc->tFlags, gen, (const char **)&pKey, (char **)&pValue ) ABC_FREE( pKey ), ABC_FREE( pValue ); st_free_table( pAbc->tFlags ); @@ -374,7 +380,8 @@ usage: ******************************************************************************/ int CmdCommandAlias( Abc_Frame_t * pAbc, int argc, char **argv ) { - char *key, *value; + const char *key; + char *value; int c; Extra_UtilGetoptReset(); @@ -431,7 +438,8 @@ usage: int CmdCommandUnalias( Abc_Frame_t * pAbc, int argc, char **argv ) { int i; - char *key, *value; + const char *key; + char *value; int c; Extra_UtilGetoptReset(); @@ -481,7 +489,7 @@ int CmdCommandUnalias( Abc_Frame_t * pAbc, int argc, char **argv ) ******************************************************************************/ int CmdCommandHelp( Abc_Frame_t * pAbc, int argc, char **argv ) { - bool fPrintAll; + int fPrintAll; int c; fPrintAll = 0; @@ -714,7 +722,8 @@ int CmdCommandSource( Abc_Frame_t * pAbc, int argc, char **argv ) ******************************************************************************/ int CmdCommandSetVariable( Abc_Frame_t * pAbc, int argc, char **argv ) { - char *flag_value, *key, *value; + char *flag_value, *value; + const char* key; int c; Extra_UtilGetoptReset(); @@ -814,7 +823,8 @@ int CmdCommandSetVariable( Abc_Frame_t * pAbc, int argc, char **argv ) int CmdCommandUnsetVariable( Abc_Frame_t * pAbc, int argc, char **argv ) { int i; - char *key, *value; + const char *key; + char *value; int c; Extra_UtilGetoptReset(); @@ -1097,7 +1107,7 @@ usage: #endif -#ifdef WIN32 +#if defined(WIN32) && !defined(__cplusplus) #include <direct.h> // these structures are defined in <io.h> but are for some reason invisible @@ -1117,7 +1127,7 @@ extern int _findnext( long handle, struct _finddata_t *fileinfo ); extern int _findclose( long handle ); //extern char * _getcwd( char * buffer, int maxlen ); -extern int _chdir( const char *dirname ); +//extern int _chdir( const char *dirname ); /**Function************************************************************* @@ -1529,7 +1539,7 @@ int CmdCommandSis( Abc_Frame_t * pAbc, int argc, char **argv ) fprintf( pErr, "Cannot produce the intermediate network.\n" ); goto usage; } - Io_WriteBlif( pNetlist, "_sis_in.blif", 1 ); + Io_WriteBlif( pNetlist, "_sis_in.blif", 1, 0, 0 ); Abc_NtkDelete( pNetlist ); // create the file for sis @@ -1672,7 +1682,7 @@ int CmdCommandMvsis( Abc_Frame_t * pAbc, int argc, char **argv ) fprintf( pErr, "Cannot produce the intermediate network.\n" ); goto usage; } - Io_WriteBlif( pNetlist, "_mvsis_in.blif", 1 ); + Io_WriteBlif( pNetlist, "_mvsis_in.blif", 1, 0, 0 ); Abc_NtkDelete( pNetlist ); // create the file for MVSIS @@ -1767,10 +1777,10 @@ void Gia_ManGnuplotShow( char * pPlotFileName ) pAbc = Abc_FrameGetGlobalFrame(); // get the names from the plotting software - if ( Cmd_FlagReadByName(pAbc, "gnuplotwin") ) - pProgNameGnuplotWin = Cmd_FlagReadByName(pAbc, "gnuplotwin"); - if ( Cmd_FlagReadByName(pAbc, "gnuplotunix") ) - pProgNameGnuplotUnix = Cmd_FlagReadByName(pAbc, "gnuplotunix"); + if ( Cmd_FlagReadByName((Abc_Frame_t *)pAbc, "gnuplotwin") ) + pProgNameGnuplotWin = Cmd_FlagReadByName((Abc_Frame_t *)pAbc, "gnuplotwin"); + if ( Cmd_FlagReadByName((Abc_Frame_t *)pAbc, "gnuplotunix") ) + pProgNameGnuplotUnix = Cmd_FlagReadByName((Abc_Frame_t *)pAbc, "gnuplotunix"); // check if Gnuplot is available if ( (pFile = fopen( pProgNameGnuplotWin, "r" )) ) @@ -1887,7 +1897,7 @@ int CmdCommandCapo( Abc_Frame_t * pAbc, int argc, char **argv ) fprintf( pErr, "Cannot produce the intermediate network.\n" ); goto usage; } - Io_WriteBlif( pNetlist, "_capo_in.blif", 1 ); + Io_WriteBlif( pNetlist, "_capo_in.blif", 1, 0, 0 ); Abc_NtkDelete( pNetlist ); // create the file for Capo @@ -2011,3 +2021,5 @@ int CmdCommandVersion( Abc_Frame_t * pAbc, int argc, char **argv ) //////////////////////////////////////////////////////////////////////// +ABC_NAMESPACE_IMPL_END + diff --git a/src/base/cmd/cmd.h b/src/base/cmd/cmd.h index 61c7264b..787e52b9 100644 --- a/src/base/cmd/cmd.h +++ b/src/base/cmd/cmd.h @@ -21,18 +21,17 @@ #ifndef __CMD_H__ #define __CMD_H__ + //////////////////////////////////////////////////////////////////////// /// INCLUDES /// //////////////////////////////////////////////////////////////////////// +ABC_NAMESPACE_HEADER_START + //////////////////////////////////////////////////////////////////////// /// PARAMETERS /// //////////////////////////////////////////////////////////////////////// -#ifdef __cplusplus -extern "C" { -#endif - //////////////////////////////////////////////////////////////////////// /// STRUCTURE DEFINITIONS /// //////////////////////////////////////////////////////////////////////// @@ -49,21 +48,24 @@ typedef struct MvAlias Abc_Alias; // one alias //////////////////////////////////////////////////////////////////////// /*=== cmd.c ===========================================================*/ -extern void Cmd_Init(); -extern void Cmd_End(); +extern void Cmd_Init( Abc_Frame_t * pAbc ); +extern void Cmd_End( Abc_Frame_t * pAbc ); /*=== cmdApi.c ========================================================*/ -extern void Cmd_CommandAdd( Abc_Frame_t * pAbc, char * sGroup, char * sName, void * pFunc, int fChanges ); -extern ABC_DLL int Cmd_CommandExecute( Abc_Frame_t * pAbc, char * sCommand ); +typedef int (*Cmd_CommandFuncType)(Abc_Frame_t*, int, char**); +extern void Cmd_CommandAdd( Abc_Frame_t * pAbc, const char * sGroup, const char * sName, Cmd_CommandFuncType pFunc, int fChanges ); +extern ABC_DLL int Cmd_CommandExecute( Abc_Frame_t * pAbc, const char * sCommand ); /*=== cmdFlag.c ========================================================*/ extern char * Cmd_FlagReadByName( Abc_Frame_t * pAbc, char * flag ); -extern void Cmd_FlagDeleteByName( Abc_Frame_t * pAbc, char * key ); -extern void Cmd_FlagUpdateValue( Abc_Frame_t * pAbc, char * key, char * value ); +extern void Cmd_FlagDeleteByName( Abc_Frame_t * pAbc, const char * key ); +extern void Cmd_FlagUpdateValue( Abc_Frame_t * pAbc, const char * key, char * value ); /*=== cmdHist.c ========================================================*/ -extern void Cmd_HistoryAddCommand( Abc_Frame_t * pAbc, char * command ); +extern void Cmd_HistoryAddCommand( Abc_Frame_t * pAbc, const char * command ); + + + +ABC_NAMESPACE_HEADER_END + -#ifdef __cplusplus -} -#endif #endif diff --git a/src/base/cmd/cmdAlias.c b/src/base/cmd/cmdAlias.c index 20ee0694..6078927d 100644 --- a/src/base/cmd/cmdAlias.c +++ b/src/base/cmd/cmdAlias.c @@ -18,8 +18,12 @@ ***********************************************************************/ +#include "abc.h" #include "cmdInt.h" +ABC_NAMESPACE_IMPL_START + + //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// @@ -118,3 +122,5 @@ void CmdCommandAliasFree( Abc_Alias * pAlias ) //////////////////////////////////////////////////////////////////////// +ABC_NAMESPACE_IMPL_END + diff --git a/src/base/cmd/cmdApi.c b/src/base/cmd/cmdApi.c index ae1949a6..40c1dbf9 100644 --- a/src/base/cmd/cmdApi.c +++ b/src/base/cmd/cmdApi.c @@ -18,9 +18,12 @@ ***********************************************************************/ +#include "abc.h" #include "mainInt.h" #include "cmdInt.h" -#include "abc.h" + +ABC_NAMESPACE_IMPL_START + //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// @@ -41,9 +44,10 @@ SeeAlso [] ***********************************************************************/ -void Cmd_CommandAdd( Abc_Frame_t * pAbc, char * sGroup, char * sName, void * pFunc, int fChanges ) +void Cmd_CommandAdd( Abc_Frame_t * pAbc, const char * sGroup, const char * sName, Cmd_CommandFuncType pFunc, int fChanges ) { - char * key, * value; + const char * key; + char * value; Abc_Command * pCommand; int fStatus; @@ -61,7 +65,7 @@ void Cmd_CommandAdd( Abc_Frame_t * pAbc, char * sGroup, char * sName, void * pFu pCommand->sGroup = Extra_UtilStrsav( sGroup ); pCommand->pFunc = pFunc; pCommand->fChange = fChanges; - fStatus = st_insert( pAbc->tCommands, sName, (char *)pCommand ); + fStatus = st_insert( pAbc->tCommands, pCommand->sName, (char *)pCommand ); assert( !fStatus ); // the command should not be in the table } @@ -76,10 +80,11 @@ void Cmd_CommandAdd( Abc_Frame_t * pAbc, char * sGroup, char * sName, void * pFu SeeAlso [] ***********************************************************************/ -int Cmd_CommandExecute( Abc_Frame_t * pAbc, char * sCommand ) +int Cmd_CommandExecute( Abc_Frame_t * pAbc, const char * sCommand ) { int fStatus = 0, argc, loop; - char * sCommandNext, **argv; + const char * sCommandNext; + char **argv; if ( !pAbc->fAutoexac ) Cmd_HistoryAddCommand(pAbc, sCommand); @@ -102,3 +107,5 @@ int Cmd_CommandExecute( Abc_Frame_t * pAbc, char * sCommand ) //////////////////////////////////////////////////////////////////////// +ABC_NAMESPACE_IMPL_END + diff --git a/src/base/cmd/cmdFlag.c b/src/base/cmd/cmdFlag.c index d25861c0..a220042b 100644 --- a/src/base/cmd/cmdFlag.c +++ b/src/base/cmd/cmdFlag.c @@ -18,8 +18,12 @@ ***********************************************************************/ +#include "abc.h" #include "mainInt.h" +ABC_NAMESPACE_IMPL_START + + //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// @@ -58,7 +62,7 @@ char * Cmd_FlagReadByName( Abc_Frame_t * pAbc, char * flag ) SideEffects [] ******************************************************************************/ -void Cmd_FlagUpdateValue( Abc_Frame_t * pAbc, char * key, char * value ) +void Cmd_FlagUpdateValue( Abc_Frame_t * pAbc, const char * key, char * value ) { char * oldValue, * newValue; if ( !key ) @@ -83,7 +87,7 @@ void Cmd_FlagUpdateValue( Abc_Frame_t * pAbc, char * key, char * value ) SideEffects [] ******************************************************************************/ -void Cmd_FlagDeleteByName( Abc_Frame_t * pAbc, char * key ) +void Cmd_FlagDeleteByName( Abc_Frame_t * pAbc, const char * key ) { char *value; if ( !key ) @@ -102,3 +106,5 @@ void Cmd_FlagDeleteByName( Abc_Frame_t * pAbc, char * key ) //////////////////////////////////////////////////////////////////////// +ABC_NAMESPACE_IMPL_END + diff --git a/src/base/cmd/cmdHist.c b/src/base/cmd/cmdHist.c index fae9382d..a2f64027 100644 --- a/src/base/cmd/cmdHist.c +++ b/src/base/cmd/cmdHist.c @@ -18,10 +18,14 @@ ***********************************************************************/ +#include "abc.h" #include "mainInt.h" #include "cmd.h" #include "cmdInt.h" +ABC_NAMESPACE_IMPL_START + + //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// @@ -41,7 +45,7 @@ SeeAlso [] ***********************************************************************/ -void Cmd_HistoryAddCommand( Abc_Frame_t * p, char * command ) +void Cmd_HistoryAddCommand( Abc_Frame_t * p, const char * command ) { static char Buffer[MAX_STR]; strcpy( Buffer, command ); @@ -53,3 +57,5 @@ void Cmd_HistoryAddCommand( Abc_Frame_t * p, char * command ) //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// +ABC_NAMESPACE_IMPL_END + diff --git a/src/base/cmd/cmdInt.h b/src/base/cmd/cmdInt.h index 3a6a2803..0ea9b364 100644 --- a/src/base/cmd/cmdInt.h +++ b/src/base/cmd/cmdInt.h @@ -21,6 +21,7 @@ #ifndef __CMD_INT_H__ #define __CMD_INT_H__ + //////////////////////////////////////////////////////////////////////// /// INCLUDES /// //////////////////////////////////////////////////////////////////////// @@ -28,6 +29,9 @@ #include "mainInt.h" #include "cmd.h" +ABC_NAMESPACE_HEADER_START + + //////////////////////////////////////////////////////////////////////// /// PARAMETERS /// //////////////////////////////////////////////////////////////////////// @@ -40,7 +44,7 @@ struct MvCommand { char * sName; // the command name char * sGroup; // the group name - void * pFunc; // the function to execute the command + Cmd_CommandFuncType pFunc; // the function to execute the command int fChange; // set to 1 to mark that the network is changed }; @@ -66,19 +70,23 @@ extern char * CmdCommandAliasLookup( Abc_Frame_t * pAbc, char * sCommand ); extern void CmdCommandAliasFree( Abc_Alias * p ); /*=== cmdUtils.c =======================================================*/ extern int CmdCommandDispatch( Abc_Frame_t * pAbc, int * argc, char *** argv ); -extern char * CmdSplitLine( Abc_Frame_t * pAbc, char * sCommand, int * argc, char *** argv ); +extern const char * CmdSplitLine( Abc_Frame_t * pAbc, const char * sCommand, int * argc, char *** argv ); extern int CmdApplyAlias( Abc_Frame_t * pAbc, int * argc, char *** argv, int * loop ); extern char * CmdHistorySubstitution( Abc_Frame_t * pAbc, char * line, int * changed ); extern FILE * CmdFileOpen( Abc_Frame_t * pAbc, char * sFileName, char * sMode, char ** pFileNameReal, int silent ); extern void CmdFreeArgv( int argc, char ** argv ); extern char ** CmdAddToArgv( int argc, char ** argv ); extern void CmdCommandFree( Abc_Command * pCommand ); -extern void CmdCommandPrint( Abc_Frame_t * pAbc, bool fPrintAll ); +extern void CmdCommandPrint( Abc_Frame_t * pAbc, int fPrintAll ); extern void CmdPrintTable( st_table * tTable, int fAliases ); //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// + + +ABC_NAMESPACE_HEADER_END + #endif diff --git a/src/base/cmd/cmdLoad.c b/src/base/cmd/cmdLoad.c new file mode 100644 index 00000000..7a83385c --- /dev/null +++ b/src/base/cmd/cmdLoad.c @@ -0,0 +1,226 @@ +/**CFile**************************************************************** + + FileName [cmdApi.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Command processing package.] + + Synopsis [External procedures of the command package.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - June 20, 2005.] + + Revision [$Id: cmdApi.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "abc.h" +#include "mainInt.h" +#include "cmd.h" +#include "cmdInt.h" + +ABC_NAMESPACE_IMPL_START + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +static int CmdCommandLoad ( Abc_Frame_t * pAbc, int argc, char ** argv ); + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function******************************************************************** + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +******************************************************************************/ +int CmdCommandLoad( Abc_Frame_t * pAbc, int argc, char ** argv ) +{ + Vec_Str_t * vCommand; + FILE * pFile; + int i; + vCommand = Vec_StrAlloc( 100 ); + Vec_StrAppend( vCommand, "abccmd_" ); + Vec_StrAppend( vCommand, argv[0] ); + Vec_StrAppend( vCommand, ".exe" ); + Vec_StrPush( vCommand, 0 ); + // check if there is the binary + if ( (pFile = fopen( Vec_StrArray(vCommand), "r" )) == NULL ) + { + Abc_Print( -1, "Cannot run the binary \"%s\".\n\n", Vec_StrArray(vCommand) ); + return 1; + } + fclose( pFile ); + Vec_StrPop( vCommand ); + // add other arguments + for ( i = 1; i < argc; i++ ) + { + Vec_StrAppend( vCommand, " " ); + Vec_StrAppend( vCommand, argv[i] ); + } + Vec_StrPush( vCommand, 0 ); + // run the command line + if ( system( Vec_StrArray(vCommand) ) ) + { + Abc_Print( -1, "The following command has returned non-zero exit status:\n" ); + Abc_Print( -1, "\"%s\"\n", Vec_StrArray(vCommand) ); + return 1; + } + return 0; +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +#if defined(WIN32) && !defined(__cplusplus) + +#include <direct.h> + + +// these structures are defined in <io.h> but are for some reason invisible +typedef unsigned long _fsize_t; // Could be 64 bits for Win32 + +struct _finddata_t { + unsigned attrib; + time_t time_create; // -1 for FAT file systems + time_t time_access; // -1 for FAT file systems + time_t time_write; + _fsize_t size; + char name[260]; +}; + +extern long _findfirst( char *filespec, struct _finddata_t *fileinfo ); +extern int _findnext( long handle, struct _finddata_t *fileinfo ); +extern int _findclose( long handle ); + +//extern char * _getcwd( char * buffer, int maxlen ); +//extern int _chdir( const char *dirname ); + +/**Function************************************************************* + + Synopsis [Collect file names ending with .exe] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Vec_Ptr_t * CmdCollectFileNames() +{ + Vec_Ptr_t * vFileNames; + struct _finddata_t c_file; + long hFile; + if( (hFile = _findfirst( "*.exe", &c_file )) == -1L ) + { +// Abc_Print( 0, "No files with extention \"%s\" in the current directory.\n", "exe" ); + return NULL; + } + vFileNames = Vec_PtrAlloc( 100 ); + do { + Vec_PtrPush( vFileNames, Extra_UtilStrsav( c_file.name ) ); + } while( _findnext( hFile, &c_file ) == 0 ); + _findclose( hFile ); + return vFileNames; +} + +#else + +/**Function************************************************************* + + Synopsis [Collect file names ending with .exe] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Vec_Ptr_t * CmdCollectFileNames() +{ + return NULL; +} + +#endif + + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Load_Init( Abc_Frame_t * pAbc ) +{ + Vec_Ptr_t * vFileNames; + char * pName, * pStop; + int i; + vFileNames = CmdCollectFileNames(); + if ( vFileNames == NULL ) + return; + Vec_PtrForEachEntry( char *, vFileNames, pName, i ) + { + if ( strncmp( pName, "abccmd_", 7 ) ) + continue; + // get the command name +// pName[6] = '!'; + pStop = strstr( pName + 7, "." ); + if ( pStop ) + *pStop = 0; + // add the command + Cmd_CommandAdd( pAbc, "ZZ", pName+7, CmdCommandLoad, 0 ); +// printf( "Loaded command \"%s\"\n", pName+7 ); + } + Vec_PtrFreeFree( vFileNames ); +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Load_End( Abc_Frame_t * pAbc ) +{ +} + + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + +ABC_NAMESPACE_IMPL_END + diff --git a/src/base/cmd/cmdPlugin.c b/src/base/cmd/cmdPlugin.c new file mode 100644 index 00000000..be7a9245 --- /dev/null +++ b/src/base/cmd/cmdPlugin.c @@ -0,0 +1,629 @@ +/**CFile**************************************************************** + + FileName [cmdPlugin.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Command processing package.] + + Synopsis [Integrating external binary.] + + Author [Alan Mishchenko, Niklas Een] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - September 29, 2010.] + + Revision [$Id: cmdPlugin.c,v 1.00 2010/09/29 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#ifdef WIN32 +#include <io.h> +#include <process.h> +#else +#include <unistd.h> +#endif + +#include "abc.h" +#include "mainInt.h" +#include "cmd.h" +#include "cmdInt.h" + +ABC_NAMESPACE_IMPL_START + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +/* + +-------- Original Message -------- +Subject: ABC/ZZ integration +Date: Wed, 29 Sep 2010 00:34:32 -0700 +From: Niklas Een <niklas@een.se> +To: Alan Mishchenko <alanmi@EECS.Berkeley.EDU> + +Hi Alan, + +Since the interface is file-based, it is important that we generate +good, unique filenames (we may run multiple instances of ABC in the +same directory), so I have attached some portable code for doing that +(tmpFile.c). You can integrate it appropriately. + +This is how my interface is meant to work: + +(1) As part of your call to Bip, give it first argument "-abc". + This will alter Bip's behavior slightly. + +(2) To list the commands, call 'bip -list-commands'. + My commands begin with a comma (so that's my prefix). + +(3) All commands expect an input file and an output file. + The input file should be in AIGER format. + The output will be a text file. + Example: + bip -input=tmp.aig -output=tmp.out ,pdr -check -prop=5 + + So you just auto-generate the two temporary files (output file is + closed and left empty) and stitch the ABC command line at the end. + All you need to check for is if the ABC line begins with a comma. + +(4) The result written to the output file will contain a number + of object. Each object is on a separate line of the form: + + <object name>: <object data> + +That is: name, colon, space, data, newline. If you see a name you don't +recognize, just skip that line (so you will ignore future extensions by me). +I currently define the following objects: + + result: + counter-example: + proof-invariant: + bug-free-depth: + abstraction: + +"result:" is one of "proved", "failed", "undetermined" (=reached resource limit), "error" +(only used by the abstraction command, and only if resource limit was so tight that the +abstraction was still empty -- no abstraction is returned in this special case). + +"counter-example:" -- same format as before + +"proof-invariant:" contains an text-encoded single-output AIG. If you want +you can parse it and validate the invariant. + +"bug-free-depth:" the depth up to which the procedure has checked for counter-example. +Starts at -1 (not even the initial states have been verified). + +"abstraction:" -- same format as before + +(5) I propose that you add a command "load_plugin <path/binary>". That way Bob can put +Bip where ever he likes and just modify his abc_rc file. + +The intention is that ABC can read this file and act on it without knowing what +particular command was used. If there is an abstraction, you will always apply it. +If there is a "bug-free-depth" you will store that data somewhere so that Bob can query +it through the Python interface, and so on. If we need different actions for different +command, then we add a new object for the new action. + +// N. + +*/ + +extern int tmpFile(const char* prefix, const char* suffix, char** out_name); + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +char * Abc_GetBinaryName( Abc_Frame_t * pAbc, int argc, char ** argv ) +{ + char * pTemp; + int i; + Vec_PtrForEachEntry( char *, pAbc->vPlugInComBinPairs, pTemp, i ) + { + i++; + if ( strcmp( pTemp, argv[0] ) == 0 ) + return Vec_PtrEntry( pAbc->vPlugInComBinPairs, i ); + } + assert( 0 ); + return NULL; +} + +/**Function************************************************************* + + Synopsis [Read flop map.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Vec_Str_t * Abc_ManReadFile( char * pFileName ) +{ + FILE * pFile; + Vec_Str_t * vStr; + int c; + pFile = fopen( pFileName, "r" ); + if ( pFile == NULL ) + { + printf( "Cannot open file \"%s\".\n", pFileName ); + return NULL; + } + vStr = Vec_StrAlloc( 100 ); + while ( (c = fgetc(pFile)) != EOF ) + Vec_StrPush( vStr, (char)c ); + Vec_StrPush( vStr, '\0' ); + fclose( pFile ); + return vStr; +} + +/**Function************************************************************* + + Synopsis [Read flop map.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Vec_Int_t * Abc_ManReadBinary( char * pFileName, char * pToken ) +{ + Vec_Int_t * vMap = NULL; + Vec_Str_t * vStr; + char * pStr; + int i, Length; + vStr = Abc_ManReadFile( pFileName ); + if ( vStr == NULL ) + return NULL; + pStr = Vec_StrArray( vStr ); + pStr = strstr( pStr, pToken ); + if ( pStr != NULL ) + { + pStr += strlen( pToken ); + vMap = Vec_IntAlloc( 100 ); + Length = strlen( pStr ); + for ( i = 0; i < Length; i++ ) + { + if ( pStr[i] == '0' || pStr[i] == '?' ) + Vec_IntPush( vMap, 0 ); + else if ( pStr[i] == '1' ) + Vec_IntPush( vMap, 1 ); + if ( ('a' <= pStr[i] && pStr[i] <= 'z') || + ('A' <= pStr[i] && pStr[i] <= 'Z') ) + break; + } + } + Vec_StrFree( vStr ); + return vMap; +} + +/**Function************************************************************* + + Synopsis [Read flop map.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Abc_ManReadInteger( char * pFileName, char * pToken ) +{ + int Result = -1; + Vec_Str_t * vStr; + char * pStr; + vStr = Abc_ManReadFile( pFileName ); + if ( vStr == NULL ) + return -1; + pStr = Vec_StrArray( vStr ); + pStr = strstr( pStr, pToken ); + if ( pStr != NULL ) + Result = atoi( pStr + strlen(pToken) ); + Vec_StrFree( vStr ); + return Result; +} + +/**Function************************************************************* + + Synopsis [Read flop map.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Abc_ManReadStatus( char * pFileName, char * pToken ) +{ + int Result = -1; + Vec_Str_t * vStr; + char * pStr; + vStr = Abc_ManReadFile( pFileName ); + if ( vStr == NULL ) + return -1; + pStr = Vec_StrArray( vStr ); + pStr = strstr( pStr, pToken ); + if ( pStr != NULL ) + { + if ( strncmp(pStr+8, "proved", 6) == 0 ) + Result = 1; + else if ( strncmp(pStr+8, "failed", 6) == 0 ) + Result = 0; + } + Vec_StrFree( vStr ); + return Result; +} + +/**Function************************************************************* + + Synopsis [Work-around to insert 0s for PIs without fanout.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Vec_Int_t * Abc_ManExpandCex( Gia_Man_t * pGia, Vec_Int_t * vCex ) +{ + Vec_Int_t * vCexNew; + Gia_Obj_t * pObj; + int i, k; + + // start with register outputs + vCexNew = Vec_IntAlloc( Vec_IntSize(vCex) ); + Gia_ManForEachRo( pGia, pObj, i ) + Vec_IntPush( vCexNew, 0 ); + + ABC_FREE( pGia->pRefs ); + Gia_ManCreateRefs( pGia ); + k = Gia_ManRegNum( pGia ); + while ( 1 ) + { + Gia_ManForEachPi( pGia, pObj, i ) + { + if ( Gia_ObjRefs(pGia, pObj) == 0 ) + Vec_IntPush( vCexNew, 0 ); + else + { + if ( k == Vec_IntSize(vCex) ) + break; + Vec_IntPush( vCexNew, Vec_IntEntry(vCex, k++) ); + } + } + if ( k == Vec_IntSize(vCex) ) + break; + } + return vCexNew; +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Cmd_CommandAbcPlugIn( Abc_Frame_t * pAbc, int argc, char ** argv ) +{ + char * pFileIn, * pFileOut; + char * pFileNameBinary; + Vec_Str_t * vCommand; + Vec_Int_t * vCex; + FILE * pFile; + int i, fd, clk; + int fLeaveFiles; +/* + Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc); + if ( pNtk == NULL ) + { + Abc_Print( -1, "Current network does not exist\n" ); + return 1; + } + if ( !Abc_NtkIsStrash( pNtk) ) + { + Abc_Print( -1, "The current network is not an AIG. Cannot continue.\n" ); + return 1; + } +*/ + if ( pAbc->pGia == NULL ) + { + Abc_Print( -1, "Current AIG does not exist (try command &ps).\n" ); + return 1; + } + + // check if there is the binary + pFileNameBinary = Abc_GetBinaryName( pAbc, argc, argv ); + if ( (pFile = fopen( pFileNameBinary, "r" )) == NULL ) + { + Abc_Print( -1, "Cannot run the binary \"%s\".\n\n", pFileNameBinary ); + return 1; + } + fclose( pFile ); + + // create temp file + fd = tmpFile( "__abctmp_", ".aig", &pFileIn ); + if ( fd == -1 ) + { + Abc_Print( -1, "Cannot create a temporary file.\n" ); + return 1; + } +#ifdef WIN32 + _close( fd ); +#else + close( fd ); +#endif + + // create temp file + fd = tmpFile( "__abctmp_", ".out", &pFileOut ); + if ( fd == -1 ) + { + ABC_FREE( pFileIn ); + Abc_Print( -1, "Cannot create a temporary file.\n" ); + return 1; + } +#ifdef WIN32 + _close( fd ); +#else + close( fd ); +#endif + + + // write current network into a file +/* + { + extern Aig_Man_t * Abc_NtkToDar( Abc_Ntk_t * pNtk, int fExors, int fRegisters ); + Aig_Man_t * pAig; + pAig = Abc_NtkToDar( pNtk, 0, 1 ); + Ioa_WriteAiger( pAig, pFileIn, 0, 0 ); + Aig_ManStop( pAig ); + } +*/ + // check what to do with the files + fLeaveFiles = 0; + if ( strcmp( argv[argc-1], "!" ) == 0 ) + { + Abc_Print( 0, "Input file \"%s\" and output file \"%s\" are not deleted.\n", pFileIn, pFileOut ); + fLeaveFiles = 1; + argc--; + } + + // create input file + Gia_WriteAiger( pAbc->pGia, pFileIn, 0, 0 ); + + // create command line + vCommand = Vec_StrAlloc( 100 ); + Vec_StrAppend( vCommand, pFileNameBinary ); + // add input/output file + Vec_StrAppend( vCommand, " -abc" ); +// Vec_StrAppend( vCommand, " -input=C:/_projects/abc/_TEST/hwmcc/139442p0.aig" ); + Vec_StrAppend( vCommand, " -input=" ); + Vec_StrAppend( vCommand, pFileIn ); + Vec_StrAppend( vCommand, " -output=" ); + Vec_StrAppend( vCommand, pFileOut ); + // add other arguments + for ( i = 0; i < argc; i++ ) + { + Vec_StrAppend( vCommand, " " ); + Vec_StrAppend( vCommand, argv[i] ); + } + Vec_StrPush( vCommand, 0 ); + + // run the command line +//printf( "Running command line: %s\n", Vec_StrArray(vCommand) ); + + clk = clock(); + if ( system( Vec_StrArray(vCommand) ) ) + { + Abc_Print( -1, "The following command has returned non-zero exit status:\n" ); + Abc_Print( -1, "\"%s\"\n", Vec_StrArray(vCommand) ); + return 1; + } + clk = clock() - clk; + Vec_StrFree( vCommand ); + + // check if the output file exists + if ( (pFile = fopen( pFileOut, "r" )) == NULL ) + { + Abc_Print( -1, "There is no output file \"%s\".\n", pFileOut ); + return 1; + } + fclose( pFile ); + + // process the output + if ( Extra_FileSize(pFileOut) > 0 ) + { + // read program arguments + pAbc->Status = Abc_ManReadStatus( pFileOut, "result:" ); + pAbc->nFrames = Abc_ManReadInteger( pFileOut, "bug-free-depth:" ); + if ( pAbc->nFrames == -1 ) + printf( "Gia_ManCexAbstractionStartNew(): Cannot read the number of frames covered by BMC.\n" ); + pAbc->pGia->vFlopClasses = Abc_ManReadBinary( pFileOut, "abstraction:" ); + vCex = Abc_ManReadBinary( pFileOut, "counter-example:" ); + if ( vCex ) + { + int nFrames, nRemain; + + nFrames = (Vec_IntSize(vCex) - Gia_ManRegNum(pAbc->pGia)) / Gia_ManPiNum(pAbc->pGia); + nRemain = (Vec_IntSize(vCex) - Gia_ManRegNum(pAbc->pGia)) % Gia_ManPiNum(pAbc->pGia); + if ( nRemain != 0 ) + { + Vec_Int_t * vTemp; + Abc_Print( 1, "Adjusting counter-example by adding zeros for PIs without fanout.\n" ); + // expand the counter-example to include PIs without fanout + vCex = Abc_ManExpandCex( pAbc->pGia, vTemp = vCex ); + Vec_IntFree( vTemp ); + } + + nFrames = (Vec_IntSize(vCex) - Gia_ManRegNum(pAbc->pGia)) / Gia_ManPiNum(pAbc->pGia); + nRemain = (Vec_IntSize(vCex) - Gia_ManRegNum(pAbc->pGia)) % Gia_ManPiNum(pAbc->pGia); + if ( nRemain != 0 ) + Abc_Print( 1, "Counter example has a wrong length.\n" ); + else + { + extern int Gia_ManVerifyCounterExampleAllOuts( Gia_Man_t * pAig, Abc_Cex_t * p ); + + Abc_Print( 1, "Problem is satisfiable. Found counter-example in frame %d. ", nFrames-1 ); + Abc_PrintTime( 1, "Time", clk ); + ABC_FREE( pAbc->pCex ); + pAbc->pCex = Gia_ManDeriveCexFromArray( pAbc->pGia, vCex, 0, nFrames-1 ); + +// Gia_ManPrintCex( pAbc->pCex ); + +// if ( !Gia_ManVerifyCounterExample( pAbc->pGia, pAbc->pCex, 0 ) ) +// Abc_Print( 1, "Generated counter-example is INVALID.\n" ); + + // remporary work-around to detect the output number - October 18, 2010 + pAbc->pCex->iPo = Gia_ManVerifyCounterExampleAllOuts( pAbc->pGia, pAbc->pCex ); + if ( pAbc->pCex->iPo == -1 ) + { + Abc_Print( 1, "Generated counter-example is INVALID.\n" ); + ABC_FREE( pAbc->pCex ); + } + else + { + Abc_Print( 1, "Returned counter-example successfully verified in ABC.\n" ); + } + } + Vec_IntFreeP( &vCex ); + } + } + + + + // clean up + if ( !fLeaveFiles ) + { + remove( pFileIn ); + remove( pFileOut ); + } + ABC_FREE( pFileIn ); + ABC_FREE( pFileOut ); + return 0; +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Cmd_CommandAbcLoadPlugIn( Abc_Frame_t * pAbc, int argc, char ** argv ) +{ + FILE * pFile; + char pBuffer[1000]; + char * pCommandLine; + char * pTempFile; + char * pStrDirBin, * pStrSection; + int fd, RetValue; + + if ( argc != 3 ) + { + Abc_Print( -1, "Wrong number of arguments.\n" ); + goto usage; + } + // collect arguments + pStrDirBin = argv[argc-2]; + pStrSection = argv[argc-1]; + + // check if the file exists + if ( (pFile = fopen( pStrDirBin, "r" )) == NULL ) + { +// Abc_Print( -1, "Cannot run the binary \"%s\".\n", pStrDirBin ); +// goto usage; + return 0; + } + fclose( pFile ); + + // create temp file + fd = tmpFile( "__abctmp_", ".txt", &pTempFile ); + if ( fd == -1 ) + { + Abc_Print( -1, "Cannot create a temporary file.\n" ); + goto usage; + } +#ifdef WIN32 + _close( fd ); +#else + close( fd ); +#endif + + // get command list + pCommandLine = ABC_ALLOC( char, 100 + strlen(pStrDirBin) + strlen(pTempFile) ); +// sprintf( pCommandLine, "%s -abc -list-commands > %s", pStrDirBin, pTempFile ); + sprintf( pCommandLine, "%s -abc -list-commands > %s", pStrDirBin, pTempFile ); + RetValue = system( pCommandLine ); + if ( RetValue == -1 ) + { + Abc_Print( -1, "Command \"%s\" did not succeed.\n", pCommandLine ); + ABC_FREE( pCommandLine ); + ABC_FREE( pTempFile ); + goto usage; + } + ABC_FREE( pCommandLine ); + + // create commands + pFile = fopen( pTempFile, "r" ); + if ( pFile == NULL ) + { + Abc_Print( -1, "Cannot open file with the list of commands.\n" ); + ABC_FREE( pTempFile ); + goto usage; + } + while ( fgets( pBuffer, 1000, pFile ) != NULL ) + { + if ( pBuffer[strlen(pBuffer)-1] == '\n' ) + pBuffer[strlen(pBuffer)-1] = 0; + Cmd_CommandAdd( pAbc, pStrSection, pBuffer, Cmd_CommandAbcPlugIn, 1 ); +// plugin_commands.push(Pair(cmd_name, binary_name)); + Vec_PtrPush( pAbc->vPlugInComBinPairs, strdup(pBuffer) ); + Vec_PtrPush( pAbc->vPlugInComBinPairs, strdup(pStrDirBin) ); + printf( "Creating command %s with binary %s\n", pBuffer, pStrDirBin ); + } + fclose( pFile ); + remove( pTempFile ); + ABC_FREE( pTempFile ); + return 0; +usage: + Abc_Print( -2, "usage: load_plugin <plugin_dir\\binary_name> <section_name>\n" ); + Abc_Print( -2, "\t loads external binary as a plugin\n" ); + Abc_Print( -2, "\t-h : print the command usage\n"); + return 1; +} + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + +ABC_NAMESPACE_IMPL_END + diff --git a/src/base/cmd/cmdUtils.c b/src/base/cmd/cmdUtils.c index 1e4c7700..5fc663fc 100644 --- a/src/base/cmd/cmdUtils.c +++ b/src/base/cmd/cmdUtils.c @@ -18,10 +18,13 @@ ***********************************************************************/ -#include "mainInt.h" #include "abc.h" +#include "mainInt.h" #include "cmdInt.h" -#include <ctype.h> // proper declaration of isspace +#include <ctype.h> + +ABC_NAMESPACE_IMPL_START + // proper declaration of isspace //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// @@ -107,17 +110,24 @@ int CmdCommandDispatch( Abc_Frame_t * pAbc, int * pargc, char *** pargv ) // get the command if ( !st_lookup( pAbc->tCommands, argv[0], (char **)&pCommand ) ) { // the command is not in the table -// fprintf( pAbc->Err, "** cmd error: unknown command '%s'\n", argv[0] ); -// return 1; - // add command 'read' assuming that this is the file name - argv2 = CmdAddToArgv( argc, argv ); - CmdFreeArgv( argc, argv ); - argc = argc+1; - argv = argv2; - *pargc = argc; - *pargv = argv; - if ( !st_lookup( pAbc->tCommands, argv[0], (char **)&pCommand ) ) - assert( 0 ); + // if there is only one word with an extension, assume this is file to be read + if ( argc == 1 && strstr( argv[0], "." ) ) + { + // add command 'read' assuming that this is the file name + argv2 = CmdAddToArgv( argc, argv ); + CmdFreeArgv( argc, argv ); + argc = argc+1; + argv = argv2; + *pargc = argc; + *pargv = argv; + if ( !st_lookup( pAbc->tCommands, argv[0], (char **)&pCommand ) ) + assert( 0 ); + } + else + { + fprintf( pAbc->Err, "** cmd error: unknown command '%s'\n", argv[0] ); + return 1; + } } // get the backup network if the command is going to change the network @@ -164,9 +174,10 @@ int CmdCommandDispatch( Abc_Frame_t * pAbc, int * pargc, char *** pargv ) SeeAlso [] ***********************************************************************/ -char * CmdSplitLine( Abc_Frame_t * pAbc, char *sCommand, int *argc, char ***argv ) +const char * CmdSplitLine( Abc_Frame_t * pAbc, const char *sCommand, int *argc, char ***argv ) { - char *p, *start, c; + const char *p, *start; + char c; int i, j; char *new_arg; Vec_Ptr_t * vArgs; @@ -252,7 +263,8 @@ char * CmdSplitLine( Abc_Frame_t * pAbc, char *sCommand, int *argc, char ***argv int CmdApplyAlias( Abc_Frame_t * pAbc, int *argcp, char ***argvp, int *loop ) { int i, argc, stopit, added, offset, did_subst, subst, fError, newc, j; - char *arg, **argv, **newv; + const char *arg; + char **argv, **newv; Abc_Alias *alias; argc = *argcp; @@ -519,9 +531,10 @@ void CmdCommandFree( Abc_Command * pCommand ) SeeAlso [] ***********************************************************************/ -void CmdCommandPrint( Abc_Frame_t * pAbc, bool fPrintAll ) +void CmdCommandPrint( Abc_Frame_t * pAbc, int fPrintAll ) { - char *key, *value; + const char *key; + char *value; st_generator * gen; Abc_Command ** ppCommands; Abc_Command * pCommands; @@ -555,7 +568,7 @@ void CmdCommandPrint( Abc_Frame_t * pAbc, bool fPrintAll ) nColumns = 79 / (LenghtMax + 2); // print the starting message - fprintf( pAbc->Out, " Welcome to ABC!" ); + fprintf( pAbc->Out, " Welcome to ABC compiled on %s %s!", __DATE__, __TIME__ ); // print the command by group sGroupCur = NULL; @@ -654,12 +667,13 @@ int CmdNamePrintCompare( char ** ppC1, char ** ppC2 ) void CmdPrintTable( st_table * tTable, int fAliases ) { st_generator * gen; - char ** ppNames; - char * key, * value; + const char ** ppNames; + const char * key; + char* value; int nNames, i; // collect keys in the array - ppNames = ABC_ALLOC( char *, st_count(tTable) ); + ppNames = ABC_ALLOC( const char *, st_count(tTable) ); nNames = 0; st_foreach_item( tTable, gen, &key, &value ) ppNames[nNames++] = key; @@ -683,3 +697,5 @@ void CmdPrintTable( st_table * tTable, int fAliases ) //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// +ABC_NAMESPACE_IMPL_END + diff --git a/src/base/cmd/module.make b/src/base/cmd/module.make index 1eca3f65..0277c760 100644 --- a/src/base/cmd/module.make +++ b/src/base/cmd/module.make @@ -3,4 +3,6 @@ SRC += src/base/cmd/cmd.c \ src/base/cmd/cmdApi.c \ src/base/cmd/cmdFlag.c \ src/base/cmd/cmdHist.c \ + src/base/cmd/cmdLoad.c \ + src/base/cmd/cmdPlugin.c \ src/base/cmd/cmdUtils.c |