Commit 354333f9 by Alan Mishchenko

Changing command 'history' to have simpler interface.

parent e86e4b66
...@@ -344,50 +344,33 @@ int CmdCommandHistory( Abc_Frame_t * pAbc, int argc, char **argv ) ...@@ -344,50 +344,33 @@ int CmdCommandHistory( Abc_Frame_t * pAbc, int argc, char **argv )
{ {
char * pName; char * pName;
int i, c; int i, c;
int nPrints = 25; int nPrints = 20;
int iRepeat = -1;
Extra_UtilGetoptReset(); Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "Nh" ) ) != EOF ) while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != 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 > globalUtilOptind + 1 ) if ( argc > globalUtilOptind + 1 )
if ( argc >= globalUtilOptind + 1 )
goto usage; goto usage;
// get the number from the command line // get the number from the command line
// if ( argc == globalUtilOptind + 1 ) if ( argc == globalUtilOptind + 1 )
// iRepeat = atoi(argv[globalUtilOptind]); nPrints = atoi(argv[globalUtilOptind]);
// print the commands // print the commands
if ( iRepeat >= 0 && iRepeat < Vec_PtrSize(pAbc->aHistory) )
fprintf( pAbc->Out, "%s", (char *)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) ) 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 ); fprintf( pAbc->Out, "%2d : %s\n", Vec_PtrSize(pAbc->aHistory)-i, pName );
return 0; return 0;
usage: usage:
fprintf( pAbc->Err, "usage: history [-N <num>] [-h]\n" ); fprintf( pAbc->Err, "usage: history [-h] <num>\n" );
fprintf( pAbc->Err, " lists the last commands entered on the command line\n" ); fprintf( pAbc->Err, "\t 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, "\t-h : print the command usage\n" );
fprintf( pAbc->Err, " -h : print the command usage\n" ); fprintf( pAbc->Err, "\t<num> : the maximum number of entries to show [default = %d]\n", nPrints );
// fprintf( pAbc->Err, " <this> : the history entry to repeat to the command line\n" );
return ( 1 ); return ( 1 );
} }
......
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