📄 cmdutils.c
字号:
/**CFile**************************************************************** FileName [cmdUtils.c] PackageName [MVSIS 2.0: Multi-valued logic synthesis system.] Synopsis [Various utilities of the command package.] Author [MVSIS Group] Affiliation [UC Berkeley] Date [Ver. 1.0. Started - February 1, 2003.] Revision [$Id: cmdUtils.c,v 1.19 2003/05/27 23:14:12 alanmi Exp $]***********************************************************************/#include "mv.h"#include "mvInt.h"#include "cmdInt.h"#include <ctype.h> // proper declaration of isspace/////////////////////////////////////////////////////////////////////////// DECLARATIONS ///////////////////////////////////////////////////////////////////////////static int CmdCommandPrintCompare( Mv_Command ** ppC1, Mv_Command ** ppC2 );/////////////////////////////////////////////////////////////////////////// FUNCTION DEFITIONS ////////////////////////////////////////////////////////////////////////////**Function************************************************************* Synopsis [Executes one command.] Description [] SideEffects [] SeeAlso []***********************************************************************/int CmdCommandDispatch( Mv_Frame_t * pMvsis, int argc, char **argv ){ Ntk_Network_t * pNetCopy; int (*pFunc) ( Mv_Frame_t *, int, char ** ); Mv_Command * pCommand; char * value; int fError; int clk; if ( argc == 0 ) return 0; // get the command if ( !avl_lookup( pMvsis->tCommands, argv[0], (char **)&pCommand ) ) { // the command is not in the table fprintf( pMvsis->Err, "** cmd error: unknown command '%s'\n", argv[0] ); return 1; } // get the backup network if the command is going to change the network if ( pCommand->fChange ) { if ( pMvsis->pNetCur ) { pNetCopy = Ntk_NetworkDup( pMvsis->pNetCur, Ntk_NetworkReadMan(pMvsis->pNetCur) ); Mv_FrameSetCurrentNetwork( pMvsis, pNetCopy ); // swap the current network and the backup network // to prevent the effect of resetting the short names Mv_FrameSwapCurrentAndBackup( pMvsis ); } } // execute the command clk = util_cpu_time(); pFunc = ( int (*)( Mv_Frame_t *, int, char ** ) ) pCommand->pFunc; fError = (*pFunc)( pMvsis, argc, argv ); pMvsis->TimeCommand += (util_cpu_time() - clk);// if ( !fError && pCommand->fChange && pMvsis->pNetCur ) // {// Cmd_HistoryAddSnapshot(pMvsis, pMvsis->pNet);// } // automatic execution of arbitrary command after each command // usually this is a passive command ... if ( fError == 0 && !pMvsis->fAutoexac ) { if ( avl_lookup( pMvsis->tFlags, "autoexec", &value ) ) { pMvsis->fAutoexac = 1; fError = Cmd_CommandExecute( pMvsis, value ); pMvsis->fAutoexac = 0; } } return fError;}/**Function************************************************************* Synopsis [Splits the command line string into individual commands.] Description [] SideEffects [] SeeAlso []***********************************************************************/char * CmdSplitLine( Mv_Frame_t * pMvsis, char *sCommand, int *argc, char ***argv ){ register char *p, *start, c; register int i, j; register char *new_arg; array_t *argv_array; int single_quote, double_quote; argv_array = array_alloc( char *, 5 ); p = sCommand; for ( ;; ) { // skip leading white space while ( isspace( ( int ) *p ) ) { p++; } // skip until end of this token single_quote = double_quote = 0; for ( start = p; ( c = *p ) != '\0'; p++ ) { if ( c == ';' || c == '#' || isspace( ( int ) c ) ) { if ( !single_quote && !double_quote ) { break; } } if ( c == '\'' ) { single_quote = !single_quote; } if ( c == '"' ) { double_quote = !double_quote; } } if ( single_quote || double_quote ) { ( void ) fprintf( pMvsis->Err, "** cmd warning: ignoring unbalanced quote ...\n" ); } if ( start == p ) break; new_arg = ALLOC( char, p - start + 1 ); j = 0; for ( i = 0; i < p - start; i++ ) { c = start[i]; if ( ( c != '\'' ) && ( c != '\"' ) ) { new_arg[j++] = isspace( ( int ) c ) ? ' ' : start[i]; } } new_arg[j] = '\0'; array_insert_last( char *, argv_array, new_arg ); } *argc = array_n( argv_array ); *argv = array_data( char *, argv_array ); array_free( argv_array ); if ( *p == ';' ) { p++; } else if ( *p == '#' ) { for ( ; *p != 0; p++ ); // skip to end of line } return p;}/**Function************************************************************* Synopsis [Replaces parts of the command line string by aliases if given.] Description [] SideEffects [] SeeAlso []***********************************************************************/int CmdApplyAlias( Mv_Frame_t * pMvsis, int *argcp, char ***argvp, int *loop ){ int i, argc, stopit, added, offset, did_subst, subst, fError, newc, j; char *arg, **argv, **newv; Mv_Alias *alias; argc = *argcp; argv = *argvp; stopit = 0; for ( ; *loop < 20; ( *loop )++ ) { if ( argc == 0 ) return 0; if ( stopit != 0 || avl_lookup( pMvsis->tAliases, argv[0], ( char ** ) &alias ) == 0 ) { return 0; } if ( strcmp( argv[0], alias->argv[0] ) == 0 ) { stopit = 1; } FREE( argv[0] ); added = alias->argc - 1; /* shift all the arguments to the right */ if ( added != 0 ) { argv = REALLOC( char *, argv, argc + added ); for ( i = argc - 1; i >= 1; i-- ) { argv[i + added] = argv[i]; } for ( i = 1; i <= added; i++ ) { argv[i] = NIL( char ); } argc += added; } subst = 0; for ( i = 0, offset = 0; i < alias->argc; i++, offset++ ) { arg = CmdHistorySubstitution( pMvsis, alias->argv[i], &did_subst ); if ( arg == NIL( char ) ) { *argcp = argc; *argvp = argv; return ( 1 ); } if ( did_subst != 0 ) { subst = 1; } fError = 0; do { arg = CmdSplitLine( pMvsis, arg, &newc, &newv ); /* * If there's a complete `;' terminated command in `arg', * when split_line() returns arg[0] != '\0'. */ if ( arg[0] == '\0' ) { /* just a bunch of words */ break; } fError = CmdApplyAlias( pMvsis, &newc, &newv, loop ); if ( fError == 0 ) { fError = CmdCommandDispatch( pMvsis, newc, newv ); } CmdFreeArgv( newc, newv ); } while ( fError == 0 ); if ( fError != 0 ) { *argcp = argc; *argvp = argv; return ( 1 ); } added = newc - 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -