📄 cmd.c
字号:
/**CFile**************************************************************** FileName [cmd.c] PackageName [MVSIS 2.0: Multi-valued logic synthesis system.] Synopsis [Commands defined in the command package.] Author [MVSIS Group] Affiliation [UC Berkeley] Date [Ver. 1.0. Started - February 1, 2003.] Revision [$Id: cmd.c,v 1.16 2003/05/27 23:14:10 alanmi Exp $]***********************************************************************/ #include "mv.h"#include "mvInt.h"#include "cmdInt.h"/////////////////////////////////////////////////////////////////////////// DECLARATIONS ///////////////////////////////////////////////////////////////////////////static int CmdCommandTime ( Mv_Frame_t * pMvsis, int argc, char ** argv );static int CmdCommandEcho ( Mv_Frame_t * pMvsis, int argc, char ** argv );static int CmdCommandQuit ( Mv_Frame_t * pMvsis, int argc, char ** argv );static int CmdCommandUsage ( Mv_Frame_t * pMvsis, int argc, char ** argv );static int CmdCommandWhich ( Mv_Frame_t * pMvsis, int argc, char ** argv );static int CmdCommandHistory ( Mv_Frame_t * pMvsis, int argc, char ** argv );static int CmdCommandAlias ( Mv_Frame_t * pMvsis, int argc, char ** argv );static int CmdCommandUnalias ( Mv_Frame_t * pMvsis, int argc, char ** argv );static int CmdCommandHelp ( Mv_Frame_t * pMvsis, int argc, char ** argv );static int CmdCommandSource ( Mv_Frame_t * pMvsis, int argc, char ** argv );static int CmdCommandSetVariable ( Mv_Frame_t * pMvsis, int argc, char ** argv );static int CmdCommandUnsetVariable ( Mv_Frame_t * pMvsis, int argc, char ** argv );static int CmdCommandUndo ( Mv_Frame_t * pMvsis, int argc, char ** argv );static int CmdCommandSnatch ( Mv_Frame_t * pMvsis, int argc, char ** argv );#ifdef WIN32static int CmdCommandLs ( Mv_Frame_t * pMvsis, int argc, char ** argv );#endif/////////////////////////////////////////////////////////////////////////// FUNCTION DEFITIONS ////////////////////////////////////////////////////////////////////////////**Function******************************************************************** Synopsis [Initializes the command package.] SideEffects [Commands are added to the command table.] SeeAlso [Cmd_End]******************************************************************************/void Cmd_Init( Mv_Frame_t * pMvsis ){ pMvsis->tCommands = avl_init_table(strcmp); pMvsis->tAliases = avl_init_table(strcmp); pMvsis->tFlags = avl_init_table(strcmp); pMvsis->aHistory = array_alloc( CmdHistory_t, 0 ); Cmd_CommandAdd( pMvsis, "Basic", "time", CmdCommandTime, 0); Cmd_CommandAdd( pMvsis, "Basic", "echo", CmdCommandEcho, 0); Cmd_CommandAdd( pMvsis, "Basic", "quit", CmdCommandQuit, 0); Cmd_CommandAdd( pMvsis, "Basic", "usage", CmdCommandUsage, 0);// Cmd_CommandAdd( pMvsis, "Basic", "which", CmdCommandWhich, 0); Cmd_CommandAdd( pMvsis, "Basic", "history", CmdCommandHistory, 0); Cmd_CommandAdd( pMvsis, "Basic", "alias", CmdCommandAlias, 0); Cmd_CommandAdd( pMvsis, "Basic", "unalias", CmdCommandUnalias, 0); Cmd_CommandAdd( pMvsis, "Basic", "help", CmdCommandHelp, 0); Cmd_CommandAdd( pMvsis, "Basic", "source", CmdCommandSource, 0); Cmd_CommandAdd( pMvsis, "Basic", "set", CmdCommandSetVariable, 0); Cmd_CommandAdd( pMvsis, "Basic", "unset", CmdCommandUnsetVariable, 0); Cmd_CommandAdd( pMvsis, "Basic", "undo", CmdCommandUndo, 0); Cmd_CommandAdd( pMvsis, "Basic", "snatch", CmdCommandSnatch, 0); #ifdef WIN32 Cmd_CommandAdd( pMvsis, "Basic", "ls", CmdCommandLs, 0 );#endif}/**Function******************************************************************** Synopsis [Ends the command package.] Description [Ends the command package. Tables are freed.] SideEffects [] SeeAlso []******************************************************************************/void Cmd_End( Mv_Frame_t * pMvsis ){ int i; avl_free_table( pMvsis->tCommands, (void (*)()) 0, CmdCommandFree ); avl_free_table( pMvsis->tAliases, (void (*)()) 0, CmdCommandAliasFree ); avl_free_table( pMvsis->tFlags, free, free ); for ( i = 0; i < array_n(pMvsis->aHistory); i++ ) { CmdHistory_t cmd = array_fetch(CmdHistory_t, pMvsis->aHistory, i); if (cmd.fCommand) FREE(cmd.data.string); } array_free( pMvsis->aHistory );}/**Function******************************************************************** Synopsis [] Description [] SideEffects [] SeeAlso []******************************************************************************/int CmdCommandTime( Mv_Frame_t * pMvsis, int argc, char **argv ){ static long last_time = 0; int c; util_getopt_reset(); while ( ( c = util_getopt( argc, argv, "h" ) ) != EOF ) { switch ( c ) { case 'h': goto usage; default: goto usage; } } if ( argc != util_optind ) { goto usage; } pMvsis->TimeTotal += pMvsis->TimeCommand; fprintf( pMvsis->Out, "elapse: %2.1f seconds, total: %2.1f seconds\n", pMvsis->TimeCommand / 1000.0, pMvsis->TimeTotal / 1000.0 ); pMvsis->TimeCommand = 0; return 0; usage: fprintf( pMvsis->Err, "usage: time [-h]\n" ); fprintf( pMvsis->Err, " -h \t\tprint the command usage\n" ); return 1;}/**Function******************************************************************** Synopsis [] Description [] SideEffects [] SeeAlso []******************************************************************************/int CmdCommandEcho( Mv_Frame_t * pMvsis, int argc, char **argv ){ int i; int c; util_getopt_reset(); while ( ( c = util_getopt( argc, argv, "h" ) ) != EOF ) { switch ( c ) { case 'h': goto usage; break; default: goto usage; } } for ( i = 1; i < argc; i++ ) fprintf( pMvsis->Out, "%s ", argv[i] ); fprintf( pMvsis->Out, "\n" ); return 0; usage: fprintf( pMvsis->Err, "usage: echo [-h] string \n" ); fprintf( pMvsis->Err, " -h \t\tprint the command usage\n" ); return ( 1 );}/**Function******************************************************************** Synopsis [] Description [] SideEffects [] SeeAlso []******************************************************************************/int CmdCommandQuit( Mv_Frame_t * pMvsis, int argc, char **argv ){ int c; util_getopt_reset(); while ( ( c = util_getopt( argc, argv, "hs" ) ) != EOF ) { switch ( c ) { case 'h': goto usage; break; case 's': return -2; break; default: goto usage; } } if ( argc != util_optind ) goto usage; return -1; usage: fprintf( pMvsis->Err, "usage: quit [-h] [-s]\n" ); fprintf( pMvsis->Err, " -h print the command usage\n" ); fprintf( pMvsis->Err, " -s frees all the memory before quitting\n" ); return 1;}/**Function******************************************************************** Synopsis [] Description [] SideEffects [] SeeAlso []******************************************************************************/int CmdCommandUsage( Mv_Frame_t * pMvsis, int argc, char **argv ){ int c; util_getopt_reset(); while ( ( c = util_getopt( argc, argv, "h" ) ) != EOF ) { switch ( c ) { case 'h': goto usage; break; default: goto usage; } } if ( argc != util_optind ) goto usage; util_print_cpu_stats( pMvsis->Out ); return 0; usage: fprintf( pMvsis->Err, "usage: usage [-h]\n" ); fprintf( pMvsis->Err, " -h \t\tprint the command usage\n" ); return 1;}/**Function******************************************************************** Synopsis [] Description [] SideEffects [] SeeAlso []******************************************************************************/int CmdCommandWhich( Mv_Frame_t * pMvsis, int argc, char **argv ){ return 0;}/**Function******************************************************************** Synopsis [] Description [] SideEffects [] SeeAlso []******************************************************************************/int CmdCommandHistory( Mv_Frame_t * pMvsis, int argc, char **argv ){ int i, num, lineno; int size; int c; num = 30; lineno = 1; util_getopt_reset(); while ( ( c = util_getopt( argc, argv, "hn" ) ) != EOF ) { switch ( c ) { case 'h': goto usage; break; case 'n': lineno = 0; break; default: goto usage; } } if ( argc > 3 ) goto usage; size = array_n( pMvsis->aHistory ); num = ( num < size ) ? num : size; for ( i = size - num; i < size; i++ ) { // TODO: move this into cmdHist.c CmdHistory_t cmd = array_fetch(CmdHistory_t, pMvsis->aHistory, i); if (cmd.fCommand) { // command in history fprintf( pMvsis->Out, "\t%s", cmd.data.string); } else if (cmd.fSnapshot) { // snapshot in history fprintf( pMvsis->Out, "%d ** ", cmd.id); Ntk_NetworkPrintStats(pMvsis->Out, cmd.data.snapshot, 0, 0, 1); } } return ( 0 ); usage: fprintf( pMvsis->Err, "usage: history [-hn] [num]\n" ); fprintf( pMvsis->Err, " -h \t\tprint the command usage\n" ); fprintf( pMvsis->Err, " -n \t\tsuppress line numbers\n"); fprintf( pMvsis->Err, " num \t\tprint the last num commands\n" ); return ( 1 );}/**Function******************************************************************** Synopsis [] Description [] SideEffects [] SeeAlso []******************************************************************************/int CmdCommandAlias( Mv_Frame_t * pMvsis, int argc, char **argv ){ char *key, *value; avl_generator *gen; int c; util_getopt_reset(); while ( ( c = util_getopt( argc, argv, "h" ) ) != EOF ) { switch ( c ) { case 'h': goto usage; break; default: goto usage; } } if ( argc == 1 ) { avl_foreach_item( pMvsis->tAliases, gen, AVL_FORWARD, &key, &value ) { CmdCommandAliasPrint( pMvsis, ( Mv_Alias * ) value ); } return 0; } else if ( argc == 2 ) { if ( avl_lookup( pMvsis->tAliases, argv[1], &value ) ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -