Commit 22d21a5c by Alan Mishchenko

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

parent 7e2b0077
...@@ -24,6 +24,7 @@ set gnuplotunix gnuplot ...@@ -24,6 +24,7 @@ set gnuplotunix gnuplot
load_plugin C:\_projects\abc\_TEST\bip\bip_win.exe "BIP" load_plugin C:\_projects\abc\_TEST\bip\bip_win.exe "BIP"
# standard aliases # standard aliases
alias hi history
alias b balance alias b balance
alias cg clockgate alias cg clockgate
alias cl cleanup alias cl cleanup
......
...@@ -337,33 +337,51 @@ int CmdCommandWhich( Abc_Frame_t * pAbc, int argc, char **argv ) ...@@ -337,33 +337,51 @@ int CmdCommandWhich( Abc_Frame_t * pAbc, int argc, char **argv )
int CmdCommandHistory( Abc_Frame_t * pAbc, int argc, char **argv ) int CmdCommandHistory( Abc_Frame_t * pAbc, int argc, char **argv )
{ {
char * pName; char * pName;
int i, c, num = 20; int i, c;
int nPrints = 10;
int iRepeat = -1;
Extra_UtilGetoptReset(); Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF ) while ( ( c = Extra_UtilGetopt( argc, argv, "Nh" ) ) != EOF )
{ {
switch ( c ) switch ( c )
{ {
case 'N':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
goto usage;
}
nPrints = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nPrints < 0 )
goto usage;
break;
case 'h': case 'h':
goto usage; goto usage;
default : default :
goto usage; goto usage;
} }
} }
if ( argc > 2 ) // if ( argc > globalUtilOptind + 1 )
if ( argc >= globalUtilOptind + 1 )
goto usage; goto usage;
// get the number of commands to print // get the number from the command line
if ( argc == globalUtilOptind + 1 ) // if ( argc == globalUtilOptind + 1 )
num = atoi(argv[globalUtilOptind]); // iRepeat = atoi(argv[globalUtilOptind]);
// print the commands // print the commands
Vec_PtrForEachEntryStart( char *, pAbc->aHistory, pName, i, Abc_MaxInt(0, Vec_PtrSize(pAbc->aHistory)-num) ) if ( iRepeat >= 0 && iRepeat < Vec_PtrSize(pAbc->aHistory) )
fprintf( pAbc->Out, "%2d : %s", Vec_PtrSize(pAbc->aHistory)-i, pName ); fprintf( pAbc->Out, "%s", Vec_PtrEntry(pAbc->aHistory, Vec_PtrSize(pAbc->aHistory)-1-iRepeat) );
else if ( nPrints > 0 )
Vec_PtrForEachEntryStart( char *, pAbc->aHistory, pName, i, Abc_MaxInt(0, Vec_PtrSize(pAbc->aHistory)-nPrints) )
fprintf( pAbc->Out, "%2d : %s\n", Vec_PtrSize(pAbc->aHistory)-i, pName );
return 0; return 0;
usage: usage:
fprintf( pAbc->Err, "usage: history [-h] <num>\n" ); fprintf( pAbc->Err, "usage: history [-N <num>] [-h]\n" );
fprintf( pAbc->Err, " prints the latest command entered on the command line\n" ); fprintf( pAbc->Err, " lists the last commands entered on the command line\n" );
fprintf( pAbc->Err, " -N num : the maximum number of entries to show [default = %d]\n", nPrints );
fprintf( pAbc->Err, " -h : print the command usage\n" ); fprintf( pAbc->Err, " -h : print the command usage\n" );
fprintf( pAbc->Err, "num : print the last num commands\n" ); // fprintf( pAbc->Err, " <this> : the history entry to repeat to the command line\n" );
return ( 1 ); return ( 1 );
} }
...@@ -541,7 +559,7 @@ int CmdCommandSource( Abc_Frame_t * pAbc, int argc, char **argv ) ...@@ -541,7 +559,7 @@ int CmdCommandSource( Abc_Frame_t * pAbc, int argc, char **argv )
int c, echo, prompt, silent, interactive, quit_count, lp_count; int c, echo, prompt, silent, interactive, quit_count, lp_count;
int status = 0; /* initialize so that lint doesn't complain */ int status = 0; /* initialize so that lint doesn't complain */
int lp_file_index, did_subst; int lp_file_index, did_subst;
char *prompt_string, *real_filename, line[MAX_STR], *command; char *prompt_string, *real_filename, line[ABC_MAX_STR], *command;
FILE *fp; FILE *fp;
interactive = silent = prompt = echo = 0; interactive = silent = prompt = echo = 0;
...@@ -627,7 +645,7 @@ int CmdCommandSource( Abc_Frame_t * pAbc, int argc, char **argv ) ...@@ -627,7 +645,7 @@ int CmdCommandSource( Abc_Frame_t * pAbc, int argc, char **argv )
clearerr( fp ); clearerr( fp );
/* read another command line */ /* read another command line */
if ( fgets( line, MAX_STR, fp ) == NULL ) if ( fgets( line, ABC_MAX_STR, fp ) == NULL )
{ {
if ( interactive ) if ( interactive )
{ {
......
...@@ -86,11 +86,7 @@ int Cmd_CommandExecute( Abc_Frame_t * pAbc, const char * sCommand ) ...@@ -86,11 +86,7 @@ int Cmd_CommandExecute( Abc_Frame_t * pAbc, const char * sCommand )
const char * sCommandNext; const char * sCommandNext;
char **argv; char **argv;
if ( !pAbc->fAutoexac && !pAbc->fSource && 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); Cmd_HistoryAddCommand(pAbc, sCommand);
sCommandNext = sCommand; sCommandNext = sCommand;
do do
......
...@@ -47,11 +47,25 @@ ABC_NAMESPACE_IMPL_START ...@@ -47,11 +47,25 @@ ABC_NAMESPACE_IMPL_START
***********************************************************************/ ***********************************************************************/
void Cmd_HistoryAddCommand( Abc_Frame_t * p, const char * command ) void Cmd_HistoryAddCommand( Abc_Frame_t * p, const char * command )
{ {
static char Buffer[MAX_STR]; char Buffer[ABC_MAX_STR];
int Len = strlen(command);
strcpy( Buffer, command ); strcpy( Buffer, command );
if ( command[strlen(command)-1] != '\n' ) if ( Buffer[Len-1] == '\n' )
strcat( Buffer, "\n" ); Buffer[Len-1] = 0;
Vec_PtrPush( p->aHistory, Extra_UtilStrsav(Buffer) ); if ( strncmp(Buffer,"set",3) &&
strncmp(Buffer,"quit",4) &&
strncmp(Buffer,"source",6) &&
strncmp(Buffer,"history",7) && strncmp(Buffer,"hi ", 3) && strcmp(Buffer,"hi") )
{
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) )
if ( !strcmp(pStr, Buffer) )
break;
if ( i == Vec_PtrSize(p->aHistory) )
Vec_PtrPush( p->aHistory, Extra_UtilStrsav(Buffer) );
}
} }
/**Function************************************************************* /**Function*************************************************************
...@@ -67,7 +81,7 @@ void Cmd_HistoryAddCommand( Abc_Frame_t * p, const char * command ) ...@@ -67,7 +81,7 @@ void Cmd_HistoryAddCommand( Abc_Frame_t * p, const char * command )
***********************************************************************/ ***********************************************************************/
void Cmd_HistoryRead( Abc_Frame_t * p ) void Cmd_HistoryRead( Abc_Frame_t * p )
{ {
char Buffer[1000]; char Buffer[ABC_MAX_STR];
FILE * pFile; FILE * pFile;
assert( Vec_PtrSize(p->aHistory) == 0 ); assert( Vec_PtrSize(p->aHistory) == 0 );
pFile = fopen( "abc.history", "rb" ); pFile = fopen( "abc.history", "rb" );
...@@ -76,8 +90,13 @@ void Cmd_HistoryRead( Abc_Frame_t * p ) ...@@ -76,8 +90,13 @@ void Cmd_HistoryRead( Abc_Frame_t * p )
// Abc_Print( 0, "Cannot open file \"abc.history\" for reading.\n" ); // Abc_Print( 0, "Cannot open file \"abc.history\" for reading.\n" );
return; return;
} }
while ( fgets( Buffer, 1000, pFile ) != NULL ) while ( fgets( Buffer, ABC_MAX_STR, pFile ) != NULL )
{
int Len = strlen(Buffer);
if ( Buffer[Len-1] == '\n' )
Buffer[Len-1] = 0;
Vec_PtrPush( p->aHistory, Extra_UtilStrsav(Buffer) ); Vec_PtrPush( p->aHistory, Extra_UtilStrsav(Buffer) );
}
fclose( pFile ); fclose( pFile );
} }
...@@ -95,7 +114,7 @@ void Cmd_HistoryRead( Abc_Frame_t * p ) ...@@ -95,7 +114,7 @@ void Cmd_HistoryRead( Abc_Frame_t * p )
void Cmd_HistoryWrite( Abc_Frame_t * p ) void Cmd_HistoryWrite( Abc_Frame_t * p )
{ {
FILE * pFile; FILE * pFile;
char * pName; char * pStr;
int i; int i;
pFile = fopen( "abc.history", "wb" ); pFile = fopen( "abc.history", "wb" );
if ( pFile == NULL ) if ( pFile == NULL )
...@@ -103,8 +122,8 @@ void Cmd_HistoryWrite( Abc_Frame_t * p ) ...@@ -103,8 +122,8 @@ void Cmd_HistoryWrite( Abc_Frame_t * p )
Abc_Print( 0, "Cannot open file \"abc.history\" for writing.\n" ); Abc_Print( 0, "Cannot open file \"abc.history\" for writing.\n" );
return; return;
} }
Vec_PtrForEachEntry( char *, p->aHistory, pName, i ) Vec_PtrForEachEntry( char *, p->aHistory, pStr, i )
fputs( pName, pFile ); fprintf( pFile, "%s\n", pStr );
fclose( pFile ); fclose( pFile );
} }
......
...@@ -48,7 +48,7 @@ ABC_NAMESPACE_HEADER_START ...@@ -48,7 +48,7 @@ ABC_NAMESPACE_HEADER_START
#define ABC_VERSION "UC Berkeley, ABC 1.01" #define ABC_VERSION "UC Berkeley, ABC 1.01"
// the maximum length of an input line // the maximum length of an input line
#define MAX_STR 32768 #define ABC_MAX_STR (1<<15)
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// STRUCTURE DEFINITIONS /// /// STRUCTURE DEFINITIONS ///
......
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