📄 cmdutils.c
字号:
if ( added != 0 ) { argv = REALLOC( char *, argv, argc + added ); for ( j = argc - 1; j > offset; j-- ) { argv[j + added] = argv[j]; } argc += added; } for ( j = 0; j <= added; j++ ) { argv[j + offset] = newv[j]; } FREE( newv ); offset += added; } if ( subst == 1 ) { for ( i = offset; i < argc; i++ ) { FREE( argv[i] ); } argc = offset; } *argcp = argc; *argvp = argv; } fprintf( pMvsis->Err, "** cmd warning: alias loop\n" ); return 1;}/**Function************************************************************* Synopsis [Performs history substitution (now, disabled).] Description [] SideEffects [] SeeAlso []***********************************************************************/char * CmdHistorySubstitution( Mv_Frame_t * pMvsis, char *line, int *changed ){ // as of today, no history substitution *changed = 0; return line;}/**Function************************************************************* Synopsis [Opens the file with path (now, disabled).] Description [] SideEffects [] SeeAlso []***********************************************************************/FILE * CmdFileOpen( Mv_Frame_t * pMvsis, char *sFileName, char *sMode, char **pFileNameReal, int silent ){ char * sRealName, * sPathUsr, * sPathLib, * sPathAll; FILE * pFile; if (strcmp(sFileName, "-") == 0) { if (strcmp(sMode, "w") == 0) { sRealName = util_strsav( "stdout" ); pFile = stdout; } else { sRealName = util_strsav( "stdin" ); pFile = stdin; } } else { sRealName = NULL; if (strcmp(sMode, "r") == 0) { /* combine both pathes if exist */ sPathUsr = Cmd_FlagReadByName(pMvsis,"open_path"); sPathLib = Cmd_FlagReadByName(pMvsis,"lib_path"); if ( sPathUsr == NULL && sPathLib == NULL ) { sPathAll = NULL; } else if ( sPathUsr == NULL ) { sPathAll = util_strsav( sPathLib ); } else if ( sPathLib == NULL ) { sPathAll = util_strsav( sPathUsr ); } else { sPathAll = ALLOC( char, strlen(sPathLib)+strlen(sPathUsr)+5 ); sprintf( sPathAll, "%s:%s",sPathUsr, sPathLib ); } if ( sPathAll != NIL(char) ) { sRealName = util_file_search(sFileName, sPathAll, "r"); FREE( sPathAll ); } } if (sRealName == NIL(char)) { sRealName = util_tilde_expand(sFileName); } if ((pFile = fopen(sRealName, sMode)) == NIL(FILE)) { if (! silent) { perror(sRealName); } } } if ( pFileNameReal ) *pFileNameReal = sRealName; else FREE(sRealName); return pFile;}/**Function************************************************************* Synopsis [Frees the previously allocated argv array.] Description [] SideEffects [] SeeAlso []***********************************************************************/void CmdFreeArgv( int argc, char **argv ){ int i; for ( i = 0; i < argc; i++ ) FREE( argv[i] ); FREE( argv );}/**Function************************************************************* Synopsis [Frees the previously allocated command.] Description [] SideEffects [] SeeAlso []***********************************************************************/void CmdCommandFree( Mv_Command * pCommand ){ free( pCommand->sGroup ); free( pCommand->sName ); free( pCommand );}/**Function************************************************************* Synopsis [Prints commands alphabetically by group.] Description [] SideEffects [] SeeAlso []***********************************************************************/void CmdCommandPrint( Mv_Frame_t * pMvsis, bool fPrintAll ){ char *key, *value; avl_generator *gen; Mv_Command ** ppCommands; Mv_Command * pCommands; int nCommands, i; char * sGroupCur; int LenghtMax, nColumns, iCom; // put all commands into one array nCommands = avl_count( pMvsis->tCommands ); ppCommands = ALLOC( Mv_Command *, nCommands ); i = 0; avl_foreach_item( pMvsis->tCommands, gen, AVL_FORWARD, &key, &value ) { pCommands = (Mv_Command *)value; if ( fPrintAll || pCommands->sName[0] != '_' ) ppCommands[i++] = pCommands; } nCommands = i; // sort command by group and then by name, alphabetically qsort( (void *)ppCommands, nCommands, sizeof(Mv_Command *), (int (*)(const void *, const void *)) CmdCommandPrintCompare ); assert( CmdCommandPrintCompare( ppCommands, ppCommands + nCommands - 1 ) <= 0 ); // get the longest command name LenghtMax = 0; for ( i = 0; i < nCommands; i++ ) if ( LenghtMax < (int)strlen(ppCommands[i]->sName) ) LenghtMax = (int)strlen(ppCommands[i]->sName); // get the number of columns nColumns = 79 / (LenghtMax + 1); // print the starting message fprintf( pMvsis->Out, " Welcome to MVSIS!" ); // print the command by group sGroupCur = NULL; for ( i = 0; i < nCommands; i++ ) if ( sGroupCur && strcmp( sGroupCur, ppCommands[i]->sGroup ) == 0 ) { // this command belongs to the same group as the previous one if ( iCom++ % nColumns == 0 ) fprintf( pMvsis->Out, "\n" ); // print this command fprintf( pMvsis->Out, " %-*s", LenghtMax, ppCommands[i]->sName ); } else { // this command starts the new group of commands // start the new group fprintf( pMvsis->Out, "\n" ); fprintf( pMvsis->Out, "\n" ); fprintf( pMvsis->Out, "%s commands:\n", ppCommands[i]->sGroup ); // print this command fprintf( pMvsis->Out, " %-*s", LenghtMax, ppCommands[i]->sName ); // remember current command group sGroupCur = ppCommands[i]->sGroup; // reset the command counter iCom = 1; } fprintf( pMvsis->Out, "\n" ); FREE( ppCommands );} /**Function************************************************************* Synopsis [Comparision function used for sorting commands.] Description [] SideEffects [] SeeAlso []***********************************************************************/int CmdCommandPrintCompare( Mv_Command ** ppC1, Mv_Command ** ppC2 ){ Mv_Command * pC1 = *ppC1; Mv_Command * pC2 = *ppC2; int RetValue; RetValue = strcmp( pC1->sGroup, pC2->sGroup ); if ( RetValue < 0 ) return -1; if ( RetValue > 0 ) return 1; // the command belong to the same group // put commands with "_" at the end of the list if ( pC1->sName[0] != '_' && pC2->sName[0] == '_' ) return -1; if ( pC1->sName[0] == '_' && pC2->sName[0] != '_' ) return 1; RetValue = strcmp( pC1->sName, pC2->sName ); if ( RetValue < 0 ) return -1; if ( RetValue > 0 ) return 1; // should not be two indentical commands assert( 0 ); return 0;}/////////////////////////////////////////////////////////////////////////// END OF FILE ///////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -