00001
00021 #include "mainInt.h"
00022 #include "cmdInt.h"
00023 #include "abc.h"
00024
00028
00032
00044 void Cmd_CommandAdd( Abc_Frame_t * pAbc, char * sGroup, char * sName, void * pFunc, int fChanges )
00045 {
00046 char * key, * value;
00047 Abc_Command * pCommand;
00048 int fStatus;
00049
00050 key = sName;
00051 if ( st_delete( pAbc->tCommands, &key, &value ) )
00052 {
00053
00054 fprintf( pAbc->Err, "Cmd warning: redefining '%s'\n", sName );
00055 CmdCommandFree( (Abc_Command *)value );
00056 }
00057
00058
00059 pCommand = ALLOC( Abc_Command, 1 );
00060 pCommand->sName = Extra_UtilStrsav( sName );
00061 pCommand->sGroup = Extra_UtilStrsav( sGroup );
00062 pCommand->pFunc = pFunc;
00063 pCommand->fChange = fChanges;
00064 fStatus = st_insert( pAbc->tCommands, sName, (char *)pCommand );
00065 assert( !fStatus );
00066 }
00067
00079 int Cmd_CommandExecute( Abc_Frame_t * pAbc, char * sCommand )
00080 {
00081 int fStatus = 0, argc, loop;
00082 char * sCommandNext, **argv;
00083
00084 if ( !pAbc->fAutoexac )
00085 Cmd_HistoryAddCommand(pAbc, sCommand);
00086 sCommandNext = sCommand;
00087 do
00088 {
00089 sCommandNext = CmdSplitLine( pAbc, sCommandNext, &argc, &argv );
00090 loop = 0;
00091 fStatus = CmdApplyAlias( pAbc, &argc, &argv, &loop );
00092 if ( fStatus == 0 )
00093 fStatus = CmdCommandDispatch( pAbc, argc, argv );
00094 CmdFreeArgv( argc, argv );
00095 }
00096 while ( fStatus == 0 && *sCommandNext != '\0' );
00097 return fStatus;
00098 }
00099
00103
00104