⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 help.c

📁 MIPS下的boottloader yamon 的源代码
💻 C
字号:

/************************************************************************
 *
 *  help.c
 *
 *  Help command for shell
 *
 *  help [-a | <command>]
 *
 *
 * ######################################################################
 *
 * Copyright (c) 1999-2000 MIPS Technologies, Inc. All rights reserved. 
 * 
 * Unpublished rights reserved under the Copyright Laws of the United States of 
 * America. 
 * 
 * This document contains information that is proprietary to MIPS Technologies, 
 * Inc. ("MIPS Technologies"). Any copying, modifying or use of this information 
 * (in whole or in part) which is not expressly permitted in writing by MIPS 
 * Technologies or a contractually-authorized third party is strictly 
 * prohibited. At a minimum, this information is protected under unfair 
 * competition laws and the expression of the information contained herein is 
 * protected under federal copyright laws. Violations thereof may result in 
 * criminal penalties and fines. 
 * MIPS Technologies or any contractually-authorized third party reserves the 
 * right to change the information contained in this document to improve 
 * function, design or otherwise. MIPS Technologies does not assume any 
 * liability arising out of the application or use of this information. Any 
 * license under patent rights or any other intellectual property rights owned 
 * by MIPS Technologies or third parties shall be conveyed by MIPS Technologies 
 * or any contractually-authorized third party in a separate license agreement 
 * between the parties. 
 * The information contained in this document constitutes one or more of the 
 * following: commercial computer software, commercial computer software 
 * documentation or other commercial items. If the user of this information, or 
 * any related documentation of any kind, including related technical data or 
 * manuals, is an agency, department, or other entity of the United States 
 * government ("Government"), the use, duplication, reproduction, release, 
 * modification, disclosure, or transfer of this information, or any related 
 * documentation of any kind, is restricted in accordance with Federal 
 * Acquisition Regulation 12.212 for civilian agencies and Defense Federal 
 * Acquisition Regulation Supplement 227.7202 for military agencies. The use of 
 * this information by the Government is further restricted in accordance with 
 * the terms of the license agreement(s) and/or applicable contract terms and 
 * conditions covering this information from MIPS Technologies or any 
 * contractually-authorized third party. 
 *
 ************************************************************************/


/************************************************************************
 *  Include files
 ************************************************************************/

#include <shell_api.h>
#include "shell.h"
#include <sysdefs.h>
#include <string.h>

/************************************************************************
 *  Definitions
 ************************************************************************/

/* Indentations */

#define HELP_SYNTAX	12
#define HELP_INDENT	4
#define HELP_OPTION	14


/************************************************************************
 *  Public variables
 ************************************************************************/

/************************************************************************
 *  Static variables
 ************************************************************************/

static t_cmd  **commands;
static UINT32 command_count;

/************************************************************************
 *  Static function prototypes
 ************************************************************************/

static MON_FUNC(help);

static void
print_help(
    t_cmd  *cmd );


/************************************************************************
 *  Implementation : Static functions
 ************************************************************************/

/************************************************************************
 *                          help
 ************************************************************************/
static MON_FUNC(help)
{
    t_cmd  *cmd;
    bool   ambivalent;
    bool   disp_all    = TRUE;
    bool   disp_secret = FALSE;
    UINT32 i;

    /* Get additional parameter, if any */

    if( argc > 2 )
        return SHELL_ERROR_SYNTAX;

    if( argc != 1 )
    {
        if( strcmp( argv[1], "-a" ) == 0 )
	{
	    disp_secret = TRUE;
	}
	else
	{
	    disp_all = FALSE;

            cmd = shell_lookup_cmd( argv[1], &ambivalent, NULL, 
				    commands, command_count );

	    if( cmd )
	    {
	        if( !ambivalent )    
		{
                    print_help( cmd );
		    SHELL_PUTC( '\n' );
		}
	        else
		    return SHELL_ERROR_AMBIVALENT;
            }
	    else
	    {
                if( *(argv[1]) == '-' )
		{
		    shell_error_data = argv[1];
		    return SHELL_ERROR_OPTION;
		}
		else
		    return SHELL_ERROR_NOT_FOUND;
	    }
        }
    }

    if( disp_all )
    {
        if(SHELL_PUTS( "\nAvailable commands :\n" )) 
	    return OK;
	      
	for( i=0; i<command_count; i++ )
	{
	  if( commands[i]->secret && !disp_secret )
	      continue;		 /* Secret command */
	   
	  if(SHELL_PUTC( '\n' )) 
	      return OK;
	  if(SHELL_PUTS( commands[i]->name )) 
	      return OK;
	  if(SHELL_PUTS_INDENT( commands[i]->syntax, HELP_SYNTAX )) 
	      return OK;
	}
        
        if(SHELL_PUTS( "\n\n" )) 
	    return OK;
    }

    return OK;
}

/* Shell command 'help' */

static t_cmd help_cmd =
{
    "help", 
    help, 
    "help [<command>]",

    "'help' with no parameter shows a list of all the available commands.\n"
    "To get more detailed help on a particular command, specify the\n"
    "command name as an argument to 'help'.\n"
    "\n"
    "When specifying a command as an argument to help, command completion\n"
    "will be performed if at least two characters of the command name have\n"
    "been specified.",

    NULL,
    0,
    FALSE
};


/************************************************************************
 *                          print_help
 ************************************************************************/
static void
print_help(
    t_cmd  *cmd )
{
    UINT32 indent;
    UINT32 i;

    if(SHELL_PUTS( "\nNAME\n" )) return;
    if(SHELL_PUTS_INDENT( cmd->name, HELP_INDENT )) return;

    if(SHELL_PUTS( "\n\nSYNOPSIS\n" )) return;
    if(SHELL_PUTS_INDENT( cmd->syntax, HELP_INDENT )) return;

    if(SHELL_PUTS( "\n\nDESCRIPTION\n" )) return;
    if(SHELL_PUTS_INDENT( cmd->descr, HELP_INDENT )) return;

    if(SHELL_PUTS( "\n\nOPTIONS" )) return;
    
    for( i=0; i<cmd->option_count; i++ )
    {
	if(SHELL_PUTC( '\n' )) return;

	indent = HELP_INDENT;
        
	if(SHELL_PUTC_INDENT( '-', indent )) return;
	indent++;
	
        if(SHELL_PUTS_INDENT( cmd->options[i].option, indent )) return;
	indent += strlen( cmd->options[i].option );

        if(SHELL_PUTS_INDENT( cmd->options[i].descr, 
		   	      MAX( HELP_OPTION, indent + 1 ) )) return;
    }

    if(SHELL_PUTC( '\n' )) return;
}


/************************************************************************
 *  Implementation : Public functions
 ************************************************************************/

/************************************************************************
 *
 *                          shell_help_init
 *  Description :
 *  -------------
 *
 *  Initialise command
 *
 *  Return values :
 *  ---------------
 *
 *  void
 *
 ************************************************************************/
t_cmd *
shell_help_init( 
    t_cmd  **cmd,
    UINT32 cmd_count )
{
    commands      = cmd;
    command_count = cmd_count;
    
    return &help_cmd;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -