mirror of https://github.com/YosysHQ/abc.git
Added recording history of used commands into file 'abc.history' (Windows only).
This commit is contained in:
parent
7e2b007762
commit
22d21a5c44
1
abc.rc
1
abc.rc
|
|
@ -24,6 +24,7 @@ set gnuplotunix gnuplot
|
|||
load_plugin C:\_projects\abc\_TEST\bip\bip_win.exe "BIP"
|
||||
|
||||
# standard aliases
|
||||
alias hi history
|
||||
alias b balance
|
||||
alias cg clockgate
|
||||
alias cl cleanup
|
||||
|
|
|
|||
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -86,11 +86,7 @@ int Cmd_CommandExecute( Abc_Frame_t * pAbc, const char * sCommand )
|
|||
const char * sCommandNext;
|
||||
char **argv;
|
||||
|
||||
if ( !pAbc->fAutoexac && !pAbc->fSource &&
|
||||
strncmp(sCommand,"set",3) &&
|
||||
strncmp(sCommand,"quit",4) &&
|
||||
strncmp(sCommand,"source",6) &&
|
||||
strncmp(sCommand,"history",7) )
|
||||
if ( !pAbc->fAutoexac && !pAbc->fSource )
|
||||
Cmd_HistoryAddCommand(pAbc, sCommand);
|
||||
sCommandNext = sCommand;
|
||||
do
|
||||
|
|
|
|||
|
|
@ -47,11 +47,25 @@ ABC_NAMESPACE_IMPL_START
|
|||
***********************************************************************/
|
||||
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 );
|
||||
if ( command[strlen(command)-1] != '\n' )
|
||||
strcat( Buffer, "\n" );
|
||||
Vec_PtrPush( p->aHistory, Extra_UtilStrsav(Buffer) );
|
||||
if ( Buffer[Len-1] == '\n' )
|
||||
Buffer[Len-1] = 0;
|
||||
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*************************************************************
|
||||
|
|
@ -67,7 +81,7 @@ void Cmd_HistoryAddCommand( Abc_Frame_t * p, const char * command )
|
|||
***********************************************************************/
|
||||
void Cmd_HistoryRead( Abc_Frame_t * p )
|
||||
{
|
||||
char Buffer[1000];
|
||||
char Buffer[ABC_MAX_STR];
|
||||
FILE * pFile;
|
||||
assert( Vec_PtrSize(p->aHistory) == 0 );
|
||||
pFile = fopen( "abc.history", "rb" );
|
||||
|
|
@ -76,8 +90,13 @@ void Cmd_HistoryRead( Abc_Frame_t * p )
|
|||
// Abc_Print( 0, "Cannot open file \"abc.history\" for reading.\n" );
|
||||
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) );
|
||||
}
|
||||
fclose( pFile );
|
||||
}
|
||||
|
||||
|
|
@ -95,7 +114,7 @@ void Cmd_HistoryRead( Abc_Frame_t * p )
|
|||
void Cmd_HistoryWrite( Abc_Frame_t * p )
|
||||
{
|
||||
FILE * pFile;
|
||||
char * pName;
|
||||
char * pStr;
|
||||
int i;
|
||||
pFile = fopen( "abc.history", "wb" );
|
||||
if ( pFile == NULL )
|
||||
|
|
@ -103,8 +122,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, pName, i )
|
||||
fputs( pName, pFile );
|
||||
Vec_PtrForEachEntry( char *, p->aHistory, pStr, i )
|
||||
fprintf( pFile, "%s\n", pStr );
|
||||
fclose( pFile );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ ABC_NAMESPACE_HEADER_START
|
|||
#define ABC_VERSION "UC Berkeley, ABC 1.01"
|
||||
|
||||
// the maximum length of an input line
|
||||
#define MAX_STR 32768
|
||||
#define ABC_MAX_STR (1<<15)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
/// STRUCTURE DEFINITIONS ///
|
||||
|
|
|
|||
Loading…
Reference in New Issue