Version abc70930

This commit is contained in:
Alan Mishchenko
2007-09-30 08:01:00 -07:00
parent 7d7e60f2dc
commit e54d969161
811 changed files with 248706 additions and 18038 deletions
-1674
View File
File diff suppressed because it is too large Load Diff
-73
View File
@@ -1,73 +0,0 @@
/**CFile****************************************************************
FileName [cmd.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Command processing package.]
Synopsis [External declarations of the command package.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: cmd.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#ifndef __CMD_H__
#define __CMD_H__
#ifdef __cplusplus
extern "C" {
#endif
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// PARAMETERS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// STRUCTURE DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
typedef struct MvCommand Abc_Command; // one command
typedef struct MvAlias Abc_Alias; // one alias
////////////////////////////////////////////////////////////////////////
/// MACRO DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/*=== cmd.c ===========================================================*/
extern void Cmd_Init();
extern void Cmd_End();
/*=== cmdApi.c ========================================================*/
extern void Cmd_CommandAdd( Abc_Frame_t * pAbc, char * sGroup, char * sName, void * pFunc, int fChanges );
extern int Cmd_CommandExecute( Abc_Frame_t * pAbc, char * sCommand );
/*=== cmdFlag.c ========================================================*/
extern char * Cmd_FlagReadByName( Abc_Frame_t * pAbc, char * flag );
extern void Cmd_FlagDeleteByName( Abc_Frame_t * pAbc, char * key );
extern void Cmd_FlagUpdateValue( Abc_Frame_t * pAbc, char * key, char * value );
/*=== cmdHist.c ========================================================*/
extern void Cmd_HistoryAddCommand( Abc_Frame_t * pAbc, char * command );
#ifdef __cplusplus
}
#endif
#endif
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
-120
View File
@@ -1,120 +0,0 @@
/**CFile****************************************************************
FileName [cmdAlias.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Command processing package.]
Synopsis [Procedures dealing with aliases in the command package.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: cmdAlias.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "cmdInt.h"
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void CmdCommandAliasAdd( Abc_Frame_t * pAbc, char * sName, int argc, char ** argv )
{
Abc_Alias * pAlias;
int fStatus, i;
pAlias = ALLOC(Abc_Alias, 1);
pAlias->sName = Extra_UtilStrsav(sName);
pAlias->argc = argc;
pAlias->argv = ALLOC(char *, pAlias->argc);
for(i = 0; i < argc; i++)
pAlias->argv[i] = Extra_UtilStrsav(argv[i]);
fStatus = st_insert( pAbc->tAliases, pAlias->sName, (char *) pAlias );
assert(!fStatus);
}
/**Function********************************************************************
Synopsis [required]
Description [optional]
SideEffects [required]
SeeAlso [optional]
******************************************************************************/
void CmdCommandAliasPrint( Abc_Frame_t * pAbc, Abc_Alias * pAlias )
{
int i;
fprintf(pAbc->Out, "%-15s", pAlias->sName);
for(i = 0; i < pAlias->argc; i++)
fprintf( pAbc->Out, " %s", pAlias->argv[i] );
fprintf( pAbc->Out, "\n" );
}
/**Function********************************************************************
Synopsis [required]
Description [optional]
SideEffects [required]
SeeAlso [optional]
******************************************************************************/
char * CmdCommandAliasLookup( Abc_Frame_t * pAbc, char * sCommand )
{
Abc_Alias * pAlias;
char * value;
if (!st_lookup( pAbc->tAliases, sCommand, &value))
return sCommand;
pAlias = (Abc_Alias *) value;
return pAlias->argv[0];
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void CmdCommandAliasFree( Abc_Alias * pAlias )
{
CmdFreeArgv( pAlias->argc, pAlias->argv );
FREE(pAlias->sName);
FREE(pAlias);
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
-104
View File
@@ -1,104 +0,0 @@
/**CFile****************************************************************
FileName [cmdApi.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Command processing package.]
Synopsis [External procedures of the command package.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: cmdApi.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "mainInt.h"
#include "cmdInt.h"
#include "abc.h"
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Cmd_CommandAdd( Abc_Frame_t * pAbc, char * sGroup, char * sName, void * pFunc, int fChanges )
{
char * key, * value;
Abc_Command * pCommand;
int fStatus;
key = sName;
if ( st_delete( pAbc->tCommands, &key, &value ) )
{
// delete existing definition for this command
fprintf( pAbc->Err, "Cmd warning: redefining '%s'\n", sName );
CmdCommandFree( (Abc_Command *)value );
}
// create the new command
pCommand = ALLOC( Abc_Command, 1 );
pCommand->sName = Extra_UtilStrsav( sName );
pCommand->sGroup = Extra_UtilStrsav( sGroup );
pCommand->pFunc = pFunc;
pCommand->fChange = fChanges;
fStatus = st_insert( pAbc->tCommands, sName, (char *)pCommand );
assert( !fStatus ); // the command should not be in the table
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Cmd_CommandExecute( Abc_Frame_t * pAbc, char * sCommand )
{
int fStatus = 0, argc, loop;
char * sCommandNext, **argv;
if ( !pAbc->fAutoexac )
Cmd_HistoryAddCommand(pAbc, sCommand);
sCommandNext = sCommand;
do
{
sCommandNext = CmdSplitLine( pAbc, sCommandNext, &argc, &argv );
loop = 0;
fStatus = CmdApplyAlias( pAbc, &argc, &argv, &loop );
if ( fStatus == 0 )
fStatus = CmdCommandDispatch( pAbc, argc, argv );
CmdFreeArgv( argc, argv );
}
while ( fStatus == 0 && *sCommandNext != '\0' );
return fStatus;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
-104
View File
@@ -1,104 +0,0 @@
/**CFile****************************************************************
FileName [cmdFlag.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Command processing package.]
Synopsis [Procedures working with flags.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: cmdFlag.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "mainInt.h"
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function********************************************************************
Synopsis [Looks up value of flag in table of named values.]
Description [The command parser maintains a table of named values. These
are manipulated using the 'set' and 'unset' commands. The value of the
named flag is returned, or NULL is returned if the flag has not been set.]
SideEffects []
******************************************************************************/
char * Cmd_FlagReadByName( Abc_Frame_t * pAbc, char * flag )
{
char * value;
if ( st_lookup(pAbc->tFlags, flag, &value) )
return value;
return NULL;
}
/**Function********************************************************************
Synopsis [Updates a set value by calling instead of set command.]
Description [Updates a set value by calling instead of set command.]
SideEffects []
******************************************************************************/
void Cmd_FlagUpdateValue( Abc_Frame_t * pAbc, char * key, char * value )
{
char * oldValue, * newValue;
if ( !key )
return;
if ( value )
newValue = Extra_UtilStrsav(value);
else
newValue = Extra_UtilStrsav("");
// newValue = NULL;
if ( st_delete(pAbc->tFlags, &key, &oldValue) )
FREE(oldValue);
st_insert( pAbc->tFlags, key, newValue );
}
/**Function********************************************************************
Synopsis [Deletes a set value by calling instead of unset command.]
Description [Deletes a set value by calling instead of unset command.]
SideEffects []
******************************************************************************/
void Cmd_FlagDeleteByName( Abc_Frame_t * pAbc, char * key )
{
char *value;
if ( !key )
return;
if ( st_delete( pAbc->tFlags, &key, &value ) )
{
FREE(key);
FREE(value);
}
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
-55
View File
@@ -1,55 +0,0 @@
/**CFile****************************************************************
FileName [cmdHist.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Command processing package.]
Synopsis [Procedures working with history.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: cmdHist.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "mainInt.h"
#include "cmd.h"
#include "cmdInt.h"
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Cmd_HistoryAddCommand( Abc_Frame_t * p, char * command )
{
static char Buffer[MAX_STR];
strcpy( Buffer, command );
if ( command[strlen(command)-1] != '\n' )
strcat( Buffer, "\n" );
Vec_PtrPush( p->aHistory, Extra_UtilStrsav(Buffer) );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
-83
View File
@@ -1,83 +0,0 @@
/**CFile****************************************************************
FileName [cmdInt.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Command processing package.]
Synopsis [Internal declarations of the command package.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: cmdInt.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#ifndef __CMD_INT_H__
#define __CMD_INT_H__
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include "mainInt.h"
#include "cmd.h"
////////////////////////////////////////////////////////////////////////
/// PARAMETERS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// STRUCTURE DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
struct MvCommand
{
char * sName; // the command name
char * sGroup; // the group name
void * pFunc; // the function to execute the command
int fChange; // set to 1 to mark that the network is changed
};
struct MvAlias
{
char * sName; // the alias name
int argc; // the number of alias parts
char ** argv; // the alias parts
};
////////////////////////////////////////////////////////////////////////
/// MACRO DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/*=== cmdAlias.c =============-========================================*/
extern void CmdCommandAliasAdd( Abc_Frame_t * pAbc, char * sName, int argc, char ** argv );
extern void CmdCommandAliasPrint( Abc_Frame_t * pAbc, Abc_Alias * pAlias );
extern char * CmdCommandAliasLookup( Abc_Frame_t * pAbc, char * sCommand );
extern void CmdCommandAliasFree( Abc_Alias * p );
/*=== cmdUtils.c =======================================================*/
extern int CmdCommandDispatch( Abc_Frame_t * pAbc, int argc, char ** argv );
extern char * CmdSplitLine( Abc_Frame_t * pAbc, char * sCommand, int * argc, char *** argv );
extern int CmdApplyAlias( Abc_Frame_t * pAbc, int * argc, char *** argv, int * loop );
extern char * CmdHistorySubstitution( Abc_Frame_t * pAbc, char * line, int * changed );
extern FILE * CmdFileOpen( Abc_Frame_t * pAbc, char * sFileName, char * sMode, char ** pFileNameReal, int silent );
extern void CmdFreeArgv( int argc, char ** argv );
extern void CmdCommandFree( Abc_Command * pCommand );
extern void CmdCommandPrint( Abc_Frame_t * pAbc, bool fPrintAll );
extern void CmdPrintTable( st_table * tTable, int fAliases );
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
#endif
-649
View File
@@ -1,649 +0,0 @@
/**CFile****************************************************************
FileName [cmdUtils.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Command processing package.]
Synopsis [Various utilities of the command package.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: cmdUtils.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "mainInt.h"
#include "abc.h"
#include "cmdInt.h"
#include <ctype.h> // proper declaration of isspace
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
static int CmdCommandPrintCompare( Abc_Command ** ppC1, Abc_Command ** ppC2 );
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int cmdCheckShellEscape( Abc_Frame_t * pAbc, int argc, char ** argv)
{
if (argv[0][0] == '!')
{
const int size = 4096;
int i;
char buffer[4096];
strncpy (buffer, &argv[0][1], size);
for (i = 1; i < argc; ++i)
{
strncat (buffer, " ", size);
strncat (buffer, argv[i], size);
}
if (buffer[0] == 0)
strncpy (buffer, "/bin/sh", size);
system (buffer);
// NOTE: Since we reconstruct the cmdline by concatenating
// the parts, we lose information. So a command like
// `!ls "file name"` will be sent to the system as
// `ls file name` which is a BUG
return 1;
}
else
{
return 0;
}
}
/**Function*************************************************************
Synopsis [Executes one command.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int CmdCommandDispatch( Abc_Frame_t * pAbc, int argc, char **argv )
{
Abc_Ntk_t * pNetCopy;
int (*pFunc) ( Abc_Frame_t *, int, char ** );
Abc_Command * pCommand;
char * value;
int fError;
int clk;
if ( argc == 0 )
return 0;
if ( cmdCheckShellEscape( pAbc, argc, argv ) == 1 )
return 0;
// get the command
if ( !st_lookup( pAbc->tCommands, argv[0], (char **)&pCommand ) )
{ // the command is not in the table
fprintf( pAbc->Err, "** cmd error: unknown command '%s'\n", argv[0] );
return 1;
}
// get the backup network if the command is going to change the network
if ( pCommand->fChange )
{
if ( pAbc->pNtkCur && Abc_FrameIsFlagEnabled( "backup" ) )
{
pNetCopy = Abc_NtkDup( pAbc->pNtkCur );
Abc_FrameSetCurrentNetwork( pAbc, pNetCopy );
// swap the current network and the backup network
// to prevent the effect of resetting the short names
Abc_FrameSwapCurrentAndBackup( pAbc );
}
}
// execute the command
clk = Extra_CpuTime();
pFunc = (int (*)(Abc_Frame_t *, int, char **))pCommand->pFunc;
fError = (*pFunc)( pAbc, argc, argv );
pAbc->TimeCommand += (Extra_CpuTime() - clk);
// automatic execution of arbitrary command after each command
// usually this is a passive command ...
if ( fError == 0 && !pAbc->fAutoexac )
{
if ( st_lookup( pAbc->tFlags, "autoexec", &value ) )
{
pAbc->fAutoexac = 1;
fError = Cmd_CommandExecute( pAbc, value );
pAbc->fAutoexac = 0;
}
}
return fError;
}
/**Function*************************************************************
Synopsis [Splits the command line string into individual commands.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
char * CmdSplitLine( Abc_Frame_t * pAbc, char *sCommand, int *argc, char ***argv )
{
char *p, *start, c;
int i, j;
char *new_arg;
Vec_Ptr_t * vArgs;
int single_quote, double_quote;
vArgs = Vec_PtrAlloc( 10 );
p = sCommand;
for ( ;; )
{
// skip leading white space
while ( isspace( ( int ) *p ) )
{
p++;
}
// skip until end of this token
single_quote = double_quote = 0;
for ( start = p; ( c = *p ) != '\0'; p++ )
{
if ( c == ';' || c == '#' || isspace( ( int ) c ) )
{
if ( !single_quote && !double_quote )
{
break;
}
}
if ( c == '\'' )
{
single_quote = !single_quote;
}
if ( c == '"' )
{
double_quote = !double_quote;
}
}
if ( single_quote || double_quote )
{
( void ) fprintf( pAbc->Err, "** cmd warning: ignoring unbalanced quote ...\n" );
}
if ( start == p )
break;
new_arg = ALLOC( char, p - start + 1 );
j = 0;
for ( i = 0; i < p - start; i++ )
{
c = start[i];
if ( ( c != '\'' ) && ( c != '\"' ) )
{
new_arg[j++] = isspace( ( int ) c ) ? ' ' : start[i];
}
}
new_arg[j] = '\0';
Vec_PtrPush( vArgs, new_arg );
}
*argc = vArgs->nSize;
*argv = (char **)Vec_PtrReleaseArray( vArgs );
Vec_PtrFree( vArgs );
if ( *p == ';' )
{
p++;
}
else if ( *p == '#' )
{
for ( ; *p != 0; p++ ); // skip to end of line
}
return p;
}
/**Function*************************************************************
Synopsis [Replaces parts of the command line string by aliases if given.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int CmdApplyAlias( Abc_Frame_t * pAbc, int *argcp, char ***argvp, int *loop )
{
int i, argc, stopit, added, offset, did_subst, subst, fError, newc, j;
char *arg, **argv, **newv;
Abc_Alias *alias;
argc = *argcp;
argv = *argvp;
stopit = 0;
for ( ; *loop < 200; ( *loop )++ )
{
if ( argc == 0 )
return 0;
if ( stopit != 0 || st_lookup( pAbc->tAliases, argv[0], (char **) &alias ) == 0 )
{
return 0;
}
if ( strcmp( argv[0], alias->argv[0] ) == 0 )
{
stopit = 1;
}
FREE( argv[0] );
added = alias->argc - 1;
/* shift all the arguments to the right */
if ( added != 0 )
{
argv = REALLOC( char *, argv, argc + added );
for ( i = argc - 1; i >= 1; i-- )
{
argv[i + added] = argv[i];
}
for ( i = 1; i <= added; i++ )
{
argv[i] = NULL;
}
argc += added;
}
subst = 0;
for ( i = 0, offset = 0; i < alias->argc; i++, offset++ )
{
arg = CmdHistorySubstitution( pAbc, alias->argv[i], &did_subst );
if ( arg == NULL )
{
*argcp = argc;
*argvp = argv;
return ( 1 );
}
if ( did_subst != 0 )
{
subst = 1;
}
fError = 0;
do
{
arg = CmdSplitLine( pAbc, arg, &newc, &newv );
/*
* If there's a complete `;' terminated command in `arg',
* when split_line() returns arg[0] != '\0'.
*/
if ( arg[0] == '\0' )
{ /* just a bunch of words */
break;
}
fError = CmdApplyAlias( pAbc, &newc, &newv, loop );
if ( fError == 0 )
{
fError = CmdCommandDispatch( pAbc, newc, newv );
}
CmdFreeArgv( newc, newv );
}
while ( fError == 0 );
if ( fError != 0 )
{
*argcp = argc;
*argvp = argv;
return ( 1 );
}
added = newc - 1;
if ( added != 0 )
{
argv = REALLOC( char *, argv, argc + added );
for ( j = argc - 1; j > offset; j-- )
{
argv[j + added] = argv[j];
}
argc += added;
}
for ( j = 0; j <= added; j++ )
{
argv[j + offset] = newv[j];
}
FREE( newv );
offset += added;
}
if ( subst == 1 )
{
for ( i = offset; i < argc; i++ )
{
FREE( argv[i] );
}
argc = offset;
}
*argcp = argc;
*argvp = argv;
}
fprintf( pAbc->Err, "** cmd warning: alias loop\n" );
return 1;
}
/**Function*************************************************************
Synopsis [Performs history substitution (now, disabled).]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
char * CmdHistorySubstitution( Abc_Frame_t * pAbc, char *line, int *changed )
{
// as of today, no history substitution
*changed = 0;
return line;
}
/**Function*************************************************************
Synopsis [Opens the file with path (now, disabled).]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
FILE * CmdFileOpen( Abc_Frame_t * pAbc, char *sFileName, char *sMode, char **pFileNameReal, int silent )
{
char * sRealName, * sPathUsr, * sPathLib, * sPathAll;
FILE * pFile;
if (strcmp(sFileName, "-") == 0) {
if (strcmp(sMode, "w") == 0) {
sRealName = Extra_UtilStrsav( "stdout" );
pFile = stdout;
}
else {
sRealName = Extra_UtilStrsav( "stdin" );
pFile = stdin;
}
}
else {
sRealName = NULL;
if (strcmp(sMode, "r") == 0) {
/* combine both pathes if exist */
sPathUsr = Cmd_FlagReadByName(pAbc,"open_path");
sPathLib = Cmd_FlagReadByName(pAbc,"lib_path");
if ( sPathUsr == NULL && sPathLib == NULL ) {
sPathAll = NULL;
}
else if ( sPathUsr == NULL ) {
sPathAll = Extra_UtilStrsav( sPathLib );
}
else if ( sPathLib == NULL ) {
sPathAll = Extra_UtilStrsav( sPathUsr );
}
else {
sPathAll = ALLOC( char, strlen(sPathLib)+strlen(sPathUsr)+5 );
sprintf( sPathAll, "%s:%s",sPathUsr, sPathLib );
}
if ( sPathAll != NULL ) {
sRealName = Extra_UtilFileSearch(sFileName, sPathAll, "r");
FREE( sPathAll );
}
}
if (sRealName == NULL) {
sRealName = Extra_UtilTildeExpand(sFileName);
}
if ((pFile = fopen(sRealName, sMode)) == NULL) {
if (! silent) {
perror(sRealName);
}
}
}
if ( pFileNameReal )
*pFileNameReal = sRealName;
else
FREE(sRealName);
return pFile;
}
/**Function*************************************************************
Synopsis [Frees the previously allocated argv array.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void CmdFreeArgv( int argc, char **argv )
{
int i;
for ( i = 0; i < argc; i++ )
FREE( argv[i] );
FREE( argv );
}
/**Function*************************************************************
Synopsis [Frees the previously allocated command.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void CmdCommandFree( Abc_Command * pCommand )
{
free( pCommand->sGroup );
free( pCommand->sName );
free( pCommand );
}
/**Function*************************************************************
Synopsis [Prints commands alphabetically by group.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void CmdCommandPrint( Abc_Frame_t * pAbc, bool fPrintAll )
{
char *key, *value;
st_generator * gen;
Abc_Command ** ppCommands;
Abc_Command * pCommands;
int nCommands, i;
char * sGroupCur;
int LenghtMax, nColumns, iCom = 0;
// put all commands into one array
nCommands = st_count( pAbc->tCommands );
ppCommands = ALLOC( Abc_Command *, nCommands );
i = 0;
st_foreach_item( pAbc->tCommands, gen, &key, &value )
{
pCommands = (Abc_Command *)value;
if ( fPrintAll || pCommands->sName[0] != '_' )
ppCommands[i++] = pCommands;
}
nCommands = i;
// sort command by group and then by name, alphabetically
qsort( (void *)ppCommands, nCommands, sizeof(Abc_Command *),
(int (*)(const void *, const void *)) CmdCommandPrintCompare );
assert( CmdCommandPrintCompare( ppCommands, ppCommands + nCommands - 1 ) <= 0 );
// get the longest command name
LenghtMax = 0;
for ( i = 0; i < nCommands; i++ )
if ( LenghtMax < (int)strlen(ppCommands[i]->sName) )
LenghtMax = (int)strlen(ppCommands[i]->sName);
// get the number of columns
nColumns = 79 / (LenghtMax + 2);
// print the starting message
fprintf( pAbc->Out, " Welcome to ABC!" );
// print the command by group
sGroupCur = NULL;
for ( i = 0; i < nCommands; i++ )
if ( sGroupCur && strcmp( sGroupCur, ppCommands[i]->sGroup ) == 0 )
{ // this command belongs to the same group as the previous one
if ( iCom++ % nColumns == 0 )
fprintf( pAbc->Out, "\n" );
// print this command
fprintf( pAbc->Out, " %-*s", LenghtMax, ppCommands[i]->sName );
}
else
{ // this command starts the new group of commands
// start the new group
fprintf( pAbc->Out, "\n" );
fprintf( pAbc->Out, "\n" );
fprintf( pAbc->Out, "%s commands:\n", ppCommands[i]->sGroup );
// print this command
fprintf( pAbc->Out, " %-*s", LenghtMax, ppCommands[i]->sName );
// remember current command group
sGroupCur = ppCommands[i]->sGroup;
// reset the command counter
iCom = 1;
}
fprintf( pAbc->Out, "\n" );
FREE( ppCommands );
}
/**Function*************************************************************
Synopsis [Comparision function used for sorting commands.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int CmdCommandPrintCompare( Abc_Command ** ppC1, Abc_Command ** ppC2 )
{
Abc_Command * pC1 = *ppC1;
Abc_Command * pC2 = *ppC2;
int RetValue;
RetValue = strcmp( pC1->sGroup, pC2->sGroup );
if ( RetValue < 0 )
return -1;
if ( RetValue > 0 )
return 1;
// the command belong to the same group
// put commands with "_" at the end of the list
if ( pC1->sName[0] != '_' && pC2->sName[0] == '_' )
return -1;
if ( pC1->sName[0] == '_' && pC2->sName[0] != '_' )
return 1;
RetValue = strcmp( pC1->sName, pC2->sName );
if ( RetValue < 0 )
return -1;
if ( RetValue > 0 )
return 1;
// should not be two indentical commands
assert( 0 );
return 0;
}
/**Function*************************************************************
Synopsis [Comparision function used for sorting commands.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int CmdNamePrintCompare( char ** ppC1, char ** ppC2 )
{
return strcmp( *ppC1, *ppC2 );
}
/**Function*************************************************************
Synopsis [Comparision function used for sorting commands.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void CmdPrintTable( st_table * tTable, int fAliases )
{
st_generator * gen;
char ** ppNames;
char * key, * value;
int nNames, i;
// collect keys in the array
ppNames = ALLOC( char *, st_count(tTable) );
nNames = 0;
st_foreach_item( tTable, gen, &key, &value )
ppNames[nNames++] = key;
// sort array by name
qsort( (void *)ppNames, nNames, sizeof(char *),
(int (*)(const void *, const void *))CmdNamePrintCompare );
// print in this order
for ( i = 0; i < nNames; i++ )
{
st_lookup( tTable, ppNames[i], &value );
if ( fAliases )
CmdCommandAliasPrint( Abc_FrameGetGlobalFrame(), (Abc_Alias *)value );
else
fprintf( stdout, "%-15s %-15s\n", ppNames[i], value );
}
free( ppNames );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
-6
View File
@@ -1,6 +0,0 @@
SRC += src/base/cmd/cmd.c \
src/base/cmd/cmdAlias.c \
src/base/cmd/cmdApi.c \
src/base/cmd/cmdFlag.c \
src/base/cmd/cmdHist.c \
src/base/cmd/cmdUtils.c