abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cmdApi.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [cmdApi.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Command processing package.]
8 
9  Synopsis [External procedures of the command package.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: cmdApi.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "base/main/mainInt.h"
23 #include "cmdInt.h"
24 
26 
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// DECLARATIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// FUNCTION DEFINITIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 /**Function*************************************************************
37 
38  Synopsis []
39 
40  Description []
41 
42  SideEffects []
43 
44  SeeAlso []
45 
46 ***********************************************************************/
47 int Cmd_CommandIsDefined( Abc_Frame_t * pAbc, const char * sName )
48 {
49  return st__is_member( pAbc->tCommands, sName );
50 }
51 
52 /**Function*************************************************************
53 
54  Synopsis []
55 
56  Description []
57 
58  SideEffects []
59 
60  SeeAlso []
61 
62 ***********************************************************************/
63 void Cmd_CommandAdd( Abc_Frame_t * pAbc, const char * sGroup, const char * sName, Cmd_CommandFuncType pFunc, int fChanges )
64 {
65  const char * key;
66  char * value;
67  Abc_Command * pCommand;
68  int fStatus;
69 
70  key = sName;
71  if ( st__delete( pAbc->tCommands, &key, &value ) )
72  {
73  // delete existing definition for this command
74  fprintf( pAbc->Err, "Cmd warning: redefining '%s'\n", sName );
75  CmdCommandFree( (Abc_Command *)value );
76  }
77 
78  // create the new command
79  pCommand = ABC_ALLOC( Abc_Command, 1 );
80  pCommand->sName = Extra_UtilStrsav( sName );
81  pCommand->sGroup = Extra_UtilStrsav( sGroup );
82  pCommand->pFunc = pFunc;
83  pCommand->fChange = fChanges;
84  fStatus = st__insert( pAbc->tCommands, pCommand->sName, (char *)pCommand );
85  assert( !fStatus ); // the command should not be in the table
86 }
87 
88 /**Function*************************************************************
89 
90  Synopsis []
91 
92  Description []
93 
94  SideEffects []
95 
96  SeeAlso []
97 
98 ***********************************************************************/
99 int Cmd_CommandExecute( Abc_Frame_t * pAbc, const char * sCommand )
100 {
101  int fStatus = 0, argc, loop;
102  const char * sCommandNext;
103  char **argv;
104 
105  if ( !pAbc->fAutoexac && !pAbc->fSource )
106  Cmd_HistoryAddCommand(pAbc, sCommand);
107  sCommandNext = sCommand;
108  do
109  {
110  sCommandNext = CmdSplitLine( pAbc, sCommandNext, &argc, &argv );
111  loop = 0;
112  fStatus = CmdApplyAlias( pAbc, &argc, &argv, &loop );
113  if ( fStatus == 0 )
114  fStatus = CmdCommandDispatch( pAbc, &argc, &argv );
115  CmdFreeArgv( argc, argv );
116  }
117  while ( fStatus == 0 && *sCommandNext != '\0' );
118  return fStatus;
119 }
120 
121 ////////////////////////////////////////////////////////////////////////
122 /// END OF FILE ///
123 ////////////////////////////////////////////////////////////////////////
124 
125 
127 
ABC_NAMESPACE_IMPL_START int Cmd_CommandIsDefined(Abc_Frame_t *pAbc, const char *sName)
DECLARATIONS ///.
Definition: cmdApi.c:47
typedefABC_NAMESPACE_HEADER_START struct MvCommand Abc_Command
INCLUDES ///.
Definition: cmd.h:39
char ** argv
Definition: cmdInt.h:55
int argc
Definition: cmdInt.h:54
int CmdCommandDispatch(Abc_Frame_t *pAbc, int *argc, char ***argv)
Definition: cmdUtils.c:93
int st__delete(st__table *table, const char **keyp, char **value)
Definition: st.c:375
int st__insert(st__table *table, const char *key, char *value)
Definition: st.c:171
int Cmd_CommandExecute(Abc_Frame_t *pAbc, const char *sCommand)
Definition: cmdApi.c:99
const char * CmdSplitLine(Abc_Frame_t *pAbc, const char *sCommand, int *argc, char ***argv)
Definition: cmdUtils.c:181
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define st__is_member(table, key)
Definition: st.h:70
char * Extra_UtilStrsav(const char *s)
void Cmd_HistoryAddCommand(Abc_Frame_t *pAbc, const char *command)
DECLARATIONS ///.
Definition: cmdHist.c:48
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
void Cmd_CommandAdd(Abc_Frame_t *pAbc, const char *sGroup, const char *sName, Cmd_CommandFuncType pFunc, int fChanges)
Definition: cmdApi.c:63
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
void CmdFreeArgv(int argc, char **argv)
Definition: cmdUtils.c:485
int(* Cmd_CommandFuncType)(Abc_Frame_t *, int, char **)
Definition: cmd.h:54
void CmdCommandFree(Abc_Command *pCommand)
Definition: cmdUtils.c:535
char * sName
Definition: cmdInt.h:53
enum keys key
int value
#define assert(ex)
Definition: util_old.h:213
int CmdApplyAlias(Abc_Frame_t *pAbc, int *argc, char ***argv, int *loop)
Definition: cmdUtils.c:267