cmdApi.c 3.58 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/**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 $]

***********************************************************************/

21 22
#include "base/abc/abc.h"
#include "base/main/mainInt.h"
Alan Mishchenko committed
23
#include "cmdInt.h"
24 25 26

ABC_NAMESPACE_IMPL_START

Alan Mishchenko committed
27 28 29 30 31 32

////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
33
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
34 35 36 37 38 39 40 41 42 43 44 45 46
////////////////////////////////////////////////////////////////////////

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
int Cmd_CommandIsDefined( Abc_Frame_t * pAbc, const char * sName )
{
    return st__is_member( pAbc->tCommands, sName );
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
63
void Cmd_CommandAdd( Abc_Frame_t * pAbc, const char * sGroup, const char * sName, Cmd_CommandFuncType pFunc, int fChanges )
Alan Mishchenko committed
64
{
65 66
    const char * key;
    char * value;
Alan Mishchenko committed
67 68 69 70
    Abc_Command * pCommand;
    int fStatus;

    key = sName;
71
    if ( st__delete( pAbc->tCommands, &key, &value ) ) 
Alan Mishchenko committed
72 73 74 75 76 77 78
    {
        // delete existing definition for this command 
        fprintf( pAbc->Err, "Cmd warning: redefining '%s'\n", sName );
        CmdCommandFree( (Abc_Command *)value );
    }

    // create the new command
Alan Mishchenko committed
79
    pCommand = ABC_ALLOC( Abc_Command, 1 );
Alan Mishchenko committed
80 81
    pCommand->sName   = Extra_UtilStrsav( sName );
    pCommand->sGroup  = Extra_UtilStrsav( sGroup );
Alan Mishchenko committed
82 83
    pCommand->pFunc   = pFunc;
    pCommand->fChange = fChanges;
84
    fStatus = st__insert( pAbc->tCommands, pCommand->sName, (char *)pCommand );
Alan Mishchenko committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98
    assert( !fStatus );  // the command should not be in the table
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
99
int Cmd_CommandExecute( Abc_Frame_t * pAbc, const char * sCommand )
Alan Mishchenko committed
100 101
{
    int fStatus = 0, argc, loop;
102 103
    const char * sCommandNext;
    char **argv;
Alan Mishchenko committed
104

105
    if ( !pAbc->fAutoexac && !pAbc->fSource ) 
Alan Mishchenko committed
106 107 108 109 110 111 112 113
        Cmd_HistoryAddCommand(pAbc, sCommand);
    sCommandNext = sCommand;
    do 
    {
           sCommandNext = CmdSplitLine( pAbc, sCommandNext, &argc, &argv );
        loop = 0;
        fStatus = CmdApplyAlias( pAbc, &argc, &argv, &loop );
        if ( fStatus == 0 ) 
Alan Mishchenko committed
114
            fStatus = CmdCommandDispatch( pAbc, &argc, &argv );
Alan Mishchenko committed
115 116 117 118 119 120 121 122 123 124 125
           CmdFreeArgv( argc, argv );
    } 
    while ( fStatus == 0 && *sCommandNext != '\0' );
    return fStatus;
}

////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


126 127
ABC_NAMESPACE_IMPL_END