diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2012-08-25 12:32:44 -0700 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2012-08-25 12:32:44 -0700 |
commit | 2a7a06b653f1165b2bdf48bb1de2779ae4cc0172 (patch) | |
tree | 0df95c6f428c725cfd72416b56c26bcc66013f9f | |
parent | 49c5799934a5ab4f4ca2143e0edb43823ed4b0dd (diff) | |
download | abc-2a7a06b653f1165b2bdf48bb1de2779ae4cc0172.tar.gz abc-2a7a06b653f1165b2bdf48bb1de2779ae4cc0172.tar.bz2 abc-2a7a06b653f1165b2bdf48bb1de2779ae4cc0172.zip |
Added recording history of used commands into file 'abc.history' (Windows only).
-rw-r--r-- | src/base/cmd/cmd.c | 2 | ||||
-rw-r--r-- | src/base/cmd/cmd.h | 2 | ||||
-rw-r--r-- | src/base/cmd/cmdHist.c | 13 |
3 files changed, 12 insertions, 5 deletions
diff --git a/src/base/cmd/cmd.c b/src/base/cmd/cmd.c index e594c65a..8c40e71e 100644 --- a/src/base/cmd/cmd.c +++ b/src/base/cmd/cmd.c @@ -125,7 +125,7 @@ void Cmd_End( Abc_Frame_t * pAbc ) st_generator * gen; char * pKey, * pValue; #if defined(WIN32) - Cmd_HistoryWrite( pAbc ); + Cmd_HistoryWrite( pAbc, ABC_INFINITY ); #endif // st_free_table( pAbc->tCommands, (void (*)()) 0, CmdCommandFree ); diff --git a/src/base/cmd/cmd.h b/src/base/cmd/cmd.h index 4cf85a5c..fc16581f 100644 --- a/src/base/cmd/cmd.h +++ b/src/base/cmd/cmd.h @@ -61,7 +61,7 @@ extern void Cmd_FlagUpdateValue( Abc_Frame_t * pAbc, const char * key, ch /*=== 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 ); +extern void Cmd_HistoryWrite( Abc_Frame_t * p, int Limit ); /*=== cmdLoad.c ========================================================*/ extern int CmdCommandLoad( Abc_Frame_t * pAbc, int argc, char ** argv ); diff --git a/src/base/cmd/cmdHist.c b/src/base/cmd/cmdHist.c index 7222d2c5..359646a6 100644 --- a/src/base/cmd/cmdHist.c +++ b/src/base/cmd/cmdHist.c @@ -47,6 +47,9 @@ ABC_NAMESPACE_IMPL_START ***********************************************************************/ void Cmd_HistoryAddCommand( Abc_Frame_t * p, const char * command ) { + int nLastLooked = 10; // defines how many entries back are looked + int nLastSaved = 100; // defines how many last entries are saved + char Buffer[ABC_MAX_STR]; int Len = strlen(command); strcpy( Buffer, command ); @@ -60,11 +63,14 @@ void Cmd_HistoryAddCommand( Abc_Frame_t * p, const char * command ) char * pStr; int i; // do not enter if the same command appears among the last five commands - Vec_PtrForEachEntryStart( char *, p->aHistory, pStr, i, Abc_MaxInt(0, Vec_PtrSize(p->aHistory)-5) ) + Vec_PtrForEachEntryStart( char *, p->aHistory, pStr, i, Abc_MaxInt(0, Vec_PtrSize(p->aHistory)-nLastLooked) ) if ( !strcmp(pStr, Buffer) ) break; if ( i == Vec_PtrSize(p->aHistory) ) + { Vec_PtrPush( p->aHistory, Extra_UtilStrsav(Buffer) ); + Cmd_HistoryWrite( p, nLastSaved ); + } } } @@ -111,7 +117,7 @@ void Cmd_HistoryRead( Abc_Frame_t * p ) SeeAlso [] ***********************************************************************/ -void Cmd_HistoryWrite( Abc_Frame_t * p ) +void Cmd_HistoryWrite( Abc_Frame_t * p, int Limit ) { FILE * pFile; char * pStr; @@ -122,7 +128,8 @@ void Cmd_HistoryWrite( Abc_Frame_t * p ) Abc_Print( 0, "Cannot open file \"abc.history\" for writing.\n" ); return; } - Vec_PtrForEachEntry( char *, p->aHistory, pStr, i ) + Limit = Abc_MaxInt( 0, Vec_PtrSize(p->aHistory)-Limit ); + Vec_PtrForEachEntryStart( char *, p->aHistory, pStr, i, Limit ) fprintf( pFile, "%s\n", pStr ); fclose( pFile ); } |