summaryrefslogtreecommitdiffstats
path: root/src/base/cmd/cmd.c
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2012-08-24 15:44:33 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2012-08-24 15:44:33 -0700
commit22d21a5c44a05e49c315bb0732cc0de100350e4a (patch)
tree5db529e04b2787346ae6cc36bc9cf89a85bea0df /src/base/cmd/cmd.c
parent7e2b00776213f86f54b9aa601e8593951b9de7d0 (diff)
downloadabc-22d21a5c44a05e49c315bb0732cc0de100350e4a.tar.gz
abc-22d21a5c44a05e49c315bb0732cc0de100350e4a.tar.bz2
abc-22d21a5c44a05e49c315bb0732cc0de100350e4a.zip
Added recording history of used commands into file 'abc.history' (Windows only).
Diffstat (limited to 'src/base/cmd/cmd.c')
-rw-r--r--src/base/cmd/cmd.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/src/base/cmd/cmd.c b/src/base/cmd/cmd.c
index b20e9ee2..161cd090 100644
--- a/src/base/cmd/cmd.c
+++ b/src/base/cmd/cmd.c
@@ -337,33 +337,51 @@ int CmdCommandWhich( Abc_Frame_t * pAbc, int argc, char **argv )
int CmdCommandHistory( Abc_Frame_t * pAbc, int argc, char **argv )
{
char * pName;
- int i, c, num = 20;
+ int i, c;
+ int nPrints = 10;
+ int iRepeat = -1;
Extra_UtilGetoptReset();
- while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF )
+ while ( ( c = Extra_UtilGetopt( argc, argv, "Nh" ) ) != EOF )
{
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':
goto usage;
default :
goto usage;
}
}
- if ( argc > 2 )
+// if ( argc > globalUtilOptind + 1 )
+ if ( argc >= globalUtilOptind + 1 )
goto usage;
- // get the number of commands to print
- if ( argc == globalUtilOptind + 1 )
- num = atoi(argv[globalUtilOptind]);
+ // get the number from the command line
+// if ( argc == globalUtilOptind + 1 )
+// iRepeat = atoi(argv[globalUtilOptind]);
// print the commands
- 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 );
+ if ( iRepeat >= 0 && iRepeat < Vec_PtrSize(pAbc->aHistory) )
+ 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;
usage:
- fprintf( pAbc->Err, "usage: history [-h] <num>\n" );
- fprintf( pAbc->Err, " prints the latest command entered on the command line\n" );
+ fprintf( pAbc->Err, "usage: history [-N <num>] [-h]\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, "num : print the last num commands\n" );
+// fprintf( pAbc->Err, " <this> : the history entry to repeat to the command line\n" );
return ( 1 );
}
@@ -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 status = 0; /* initialize so that lint doesn't complain */
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;
interactive = silent = prompt = echo = 0;
@@ -627,7 +645,7 @@ int CmdCommandSource( Abc_Frame_t * pAbc, int argc, char **argv )
clearerr( fp );
/* read another command line */
- if ( fgets( line, MAX_STR, fp ) == NULL )
+ if ( fgets( line, ABC_MAX_STR, fp ) == NULL )
{
if ( interactive )
{