summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2012-08-24 12:25:53 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2012-08-24 12:25:53 -0700
commit7e2b00776213f86f54b9aa601e8593951b9de7d0 (patch)
treebc8d5f545162d5abf1fab5b4d54d3ae922042b12 /src
parent4a9152d0e1af415b7890b9a501b989b6472dbac8 (diff)
downloadabc-7e2b00776213f86f54b9aa601e8593951b9de7d0.tar.gz
abc-7e2b00776213f86f54b9aa601e8593951b9de7d0.tar.bz2
abc-7e2b00776213f86f54b9aa601e8593951b9de7d0.zip
Added recording history of used commands into file 'abc.history' (Windows only).
Diffstat (limited to 'src')
-rw-r--r--src/base/cmd/cmd.c36
-rw-r--r--src/base/cmd/cmd.h2
-rw-r--r--src/base/cmd/cmdApi.c6
-rw-r--r--src/base/cmd/cmdHist.c54
-rw-r--r--src/base/main/mainInt.h1
-rw-r--r--src/base/main/mainUtils.c9
6 files changed, 80 insertions, 28 deletions
diff --git a/src/base/cmd/cmd.c b/src/base/cmd/cmd.c
index 320f194f..b20e9ee2 100644
--- a/src/base/cmd/cmd.c
+++ b/src/base/cmd/cmd.c
@@ -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:
diff --git a/src/base/cmd/cmd.h b/src/base/cmd/cmd.h
index f424f090..4cf85a5c 100644
--- a/src/base/cmd/cmd.h
+++ b/src/base/cmd/cmd.h
@@ -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 );
diff --git a/src/base/cmd/cmdApi.c b/src/base/cmd/cmdApi.c
index 6ae9342d..5b94f67e 100644
--- a/src/base/cmd/cmdApi.c
+++ b/src/base/cmd/cmdApi.c
@@ -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
diff --git a/src/base/cmd/cmdHist.c b/src/base/cmd/cmdHist.c
index ba467f76..49808ec5 100644
--- a/src/base/cmd/cmdHist.c
+++ b/src/base/cmd/cmdHist.c
@@ -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 ///
////////////////////////////////////////////////////////////////////////
diff --git a/src/base/main/mainInt.h b/src/base/main/mainInt.h
index 6ed12786..5c30f7c0 100644
--- a/src/base/main/mainInt.h
+++ b/src/base/main/mainInt.h
@@ -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
diff --git a/src/base/main/mainUtils.c b/src/base/main/mainUtils.c
index f0d602d3..b46ffaea 100644
--- a/src/base/main/mainUtils.c
+++ b/src/base/main/mainUtils.c
@@ -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********************************************************************