cmdApi.c 3.23 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
void Cmd_CommandAdd( Abc_Frame_t * pAbc, const char * sGroup, const char * sName, Cmd_CommandFuncType pFunc, int fChanges )
Alan Mishchenko committed
48
{
49 50
    const char * key;
    char * value;
Alan Mishchenko committed
51 52 53 54
    Abc_Command * pCommand;
    int fStatus;

    key = sName;
55
    if ( st__delete( pAbc->tCommands, &key, &value ) ) 
Alan Mishchenko committed
56 57 58 59 60 61 62
    {
        // 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
63
    pCommand = ABC_ALLOC( Abc_Command, 1 );
Alan Mishchenko committed
64 65
    pCommand->sName   = Extra_UtilStrsav( sName );
    pCommand->sGroup  = Extra_UtilStrsav( sGroup );
Alan Mishchenko committed
66 67
    pCommand->pFunc   = pFunc;
    pCommand->fChange = fChanges;
68
    fStatus = st__insert( pAbc->tCommands, pCommand->sName, (char *)pCommand );
Alan Mishchenko committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82
    assert( !fStatus );  // the command should not be in the table
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
83
int Cmd_CommandExecute( Abc_Frame_t * pAbc, const char * sCommand )
Alan Mishchenko committed
84 85
{
    int fStatus = 0, argc, loop;
86 87
    const char * sCommandNext;
    char **argv;
Alan Mishchenko committed
88

89
    if ( !pAbc->fAutoexac && !pAbc->fSource ) 
Alan Mishchenko committed
90 91 92 93 94 95 96 97
        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
98
            fStatus = CmdCommandDispatch( pAbc, &argc, &argv );
Alan Mishchenko committed
99 100 101 102 103 104 105 106 107 108 109
           CmdFreeArgv( argc, argv );
    } 
    while ( fStatus == 0 && *sCommandNext != '\0' );
    return fStatus;
}

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


110 111
ABC_NAMESPACE_IMPL_END