Commit 7e2b0077 by Alan Mishchenko

Added recording history of used commands into file 'abc.history' (Windows only).

parent 4a9152d0
......@@ -79,6 +79,9 @@ void Cmd_Init( Abc_Frame_t * pAbc )
pAbc->tAliases = st_init_table(strcmp, st_strhash);
pAbc->tFlags = st_init_table(strcmp, st_strhash);
pAbc->aHistory = Vec_PtrAlloc( 100 );
#if defined(WIN32)
Cmd_HistoryRead( pAbc );
#endif
Cmd_CommandAdd( pAbc, "Basic", "time", CmdCommandTime, 0 );
Cmd_CommandAdd( pAbc, "Basic", "echo", CmdCommandEcho, 0 );
......@@ -121,7 +124,9 @@ void Cmd_End( Abc_Frame_t * pAbc )
{
st_generator * gen;
char * pKey, * pValue;
int i;
#if defined(WIN32)
Cmd_HistoryWrite( pAbc );
#endif
// st_free_table( pAbc->tCommands, (void (*)()) 0, CmdCommandFree );
// st_free_table( pAbc->tAliases, (void (*)()) 0, CmdCommandAliasFree );
......@@ -139,9 +144,7 @@ void Cmd_End( Abc_Frame_t * pAbc )
ABC_FREE( pKey ), ABC_FREE( pValue );
st_free_table( pAbc->tFlags );
for ( i = 0; i < pAbc->aHistory->nSize; i++ )
ABC_FREE( pAbc->aHistory->pArray[i] );
Vec_PtrFree( pAbc->aHistory );
Vec_PtrFreeFree( pAbc->aHistory );
}
......@@ -333,9 +336,8 @@ int CmdCommandWhich( Abc_Frame_t * pAbc, int argc, char **argv )
******************************************************************************/
int CmdCommandHistory( Abc_Frame_t * pAbc, int argc, char **argv )
{
int i, c, num, size;
num = 20;
char * pName;
int i, c, num = 20;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
{
......@@ -349,15 +351,12 @@ int CmdCommandHistory( Abc_Frame_t * pAbc, int argc, char **argv )
}
if ( argc > 2 )
goto usage;
// get the number of commands to print
if ( argc == globalUtilOptind + 1 )
num = atoi(argv[globalUtilOptind]);
// print the commands
size = pAbc->aHistory->nSize;
num = ( num < size ) ? num : size;
for ( i = size - num; i < size; i++ )
fprintf( pAbc->Out, "%s", (char*)pAbc->aHistory->pArray[i] );
Vec_PtrForEachEntryStart( char *, pAbc->aHistory, pName, i, Abc_MaxInt(0, Vec_PtrSize(pAbc->aHistory)-num) )
fprintf( pAbc->Out, "%2d : %s", Vec_PtrSize(pAbc->aHistory)-i, pName );
return 0;
usage:
......@@ -587,6 +586,7 @@ int CmdCommandSource( Abc_Frame_t * pAbc, int argc, char **argv )
* lp_count initialized to -1, and hence, any file sourced by SIS (if -l or
* -t options on "source" were used in SIS) would actually be executed twice.
*/
pAbc->fSource = 1;
do
{
char * pFileName, * pTemp;
......@@ -603,6 +603,7 @@ int CmdCommandSource( Abc_Frame_t * pAbc, int argc, char **argv )
fp = CmdFileOpen( pAbc, pFileName, "r", &real_filename, silent );
if ( fp == NULL )
{
pAbc->fSource = 0;
ABC_FREE( real_filename );
return !silent; /* error return if not silent */
}
......@@ -626,9 +627,6 @@ int CmdCommandSource( Abc_Frame_t * pAbc, int argc, char **argv )
clearerr( fp );
/* read another command line */
// if (CmdFgetsFilec(line, MAX_STR, fp, prompt_string) == NULL) {
// Abc_UtilsPrintPrompt(prompt_string);
// fflush(stdout);
if ( fgets( line, MAX_STR, fp ) == NULL )
{
if ( interactive )
......@@ -667,7 +665,7 @@ int CmdCommandSource( Abc_Frame_t * pAbc, int argc, char **argv )
}
if ( command != line )
{
( void ) strcpy( line, command );
strcpy( line, command );
}
if ( interactive && *line != '\0' )
{
......@@ -675,7 +673,7 @@ int CmdCommandSource( Abc_Frame_t * pAbc, int argc, char **argv )
if ( pAbc->Hst != NULL )
{
fprintf( pAbc->Hst, "%s\n", line );
( void ) fflush( pAbc->Hst );
fflush( pAbc->Hst );
}
}
......@@ -692,13 +690,13 @@ int CmdCommandSource( Abc_Frame_t * pAbc, int argc, char **argv )
"** cmd error: aborting 'source %s'\n",
real_filename );
}
( void ) fclose( fp );
fclose( fp );
}
ABC_FREE( real_filename );
}
while ( ( status == 0 ) && ( lp_count <= 0 ) );
pAbc->fSource = 0;
return status;
usage:
......
......@@ -60,6 +60,8 @@ 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, const char * command );
extern void Cmd_HistoryRead( Abc_Frame_t * p );
extern void Cmd_HistoryWrite( Abc_Frame_t * p );
/*=== cmdLoad.c ========================================================*/
extern int CmdCommandLoad( Abc_Frame_t * pAbc, int argc, char ** argv );
......
......@@ -86,7 +86,11 @@ int Cmd_CommandExecute( Abc_Frame_t * pAbc, const char * sCommand )
const char * sCommandNext;
char **argv;
if ( !pAbc->fAutoexac )
if ( !pAbc->fAutoexac && !pAbc->fSource &&
strncmp(sCommand,"set",3) &&
strncmp(sCommand,"quit",4) &&
strncmp(sCommand,"source",6) &&
strncmp(sCommand,"history",7) )
Cmd_HistoryAddCommand(pAbc, sCommand);
sCommandNext = sCommand;
do
......
......@@ -54,6 +54,60 @@ void Cmd_HistoryAddCommand( Abc_Frame_t * p, const char * command )
Vec_PtrPush( p->aHistory, Extra_UtilStrsav(Buffer) );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Cmd_HistoryRead( Abc_Frame_t * p )
{
char Buffer[1000];
FILE * pFile;
assert( Vec_PtrSize(p->aHistory) == 0 );
pFile = fopen( "abc.history", "rb" );
if ( pFile == NULL )
{
// Abc_Print( 0, "Cannot open file \"abc.history\" for reading.\n" );
return;
}
while ( fgets( Buffer, 1000, pFile ) != NULL )
Vec_PtrPush( p->aHistory, Extra_UtilStrsav(Buffer) );
fclose( pFile );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Cmd_HistoryWrite( Abc_Frame_t * p )
{
FILE * pFile;
char * pName;
int i;
pFile = fopen( "abc.history", "wb" );
if ( pFile == NULL )
{
Abc_Print( 0, "Cannot open file \"abc.history\" for writing.\n" );
return;
}
Vec_PtrForEachEntry( char *, p->aHistory, pName, i )
fputs( pName, pFile );
fclose( pFile );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
......
......@@ -68,6 +68,7 @@ struct Abc_Frame_t_
Abc_Ntk_t * pNtkBestDelay; // the current network
Abc_Ntk_t * pNtkBestArea; // the current network
int nSteps; // the counter of different network processed
int fSource; // marks the source mode
int fAutoexac; // marks the autoexec mode
int fBatchMode; // batch mode flag
int fBridgeMode; // bridge mode flag
......
......@@ -203,6 +203,7 @@ void Abc_UtilsSource( Abc_Frame_t * pAbc )
}
else
#endif /* #ifdef ABC_PYTHON_EMBED */
{
char * sPath1, * sPath2;
char * home;
......@@ -252,14 +253,6 @@ void Abc_UtilsSource( Abc_Frame_t * pAbc )
}
#endif //WIN32
{
// reset command history
char * pName;
int i;
Vec_PtrForEachEntry( char *, pAbc->aHistory, pName, i )
ABC_FREE( pName );
pAbc->aHistory->nSize = 0;
}
}
/**Function********************************************************************
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment