tw_cli_misc_cmd.c
资源名称:cli.rar [点击查看]
上传用户:hujq123
上传日期:2016-04-10
资源大小:153k
文件大小:4k
源码类别:
Telnet服务器
开发平台:
Unix_Linux
- /*
- * Copyright (C) 2002 Koninklijke Philips Electronics N.V.,
- * All Rights Reserved.
- *
- * This source code and any compilation or derivative thereof is the
- * proprietary information of Koninklijke Philips Electronics N.V.
- * and is confidential in nature.
- * Under no circumstances is this software to be exposed to or placed
- * under an Open Source License of any type without the expressed
- * written permission of Koninklijke Philips Electronics N.V.
- *
- *###########################################################
- */
- /*!
- * file tw_cli_misc_cmd.c
- *
- * brief -
- *
- */
- /*-----------------------------------------------------------*
- *
- * %version: 3 %
- * instance: DS_6
- * %date_created: Fri Feb 21 08:04:38 2003 %
- *
- *###########################################################
- */
- /****************************************************************************
- *
- * Filename : tw_cli_misc_cmd.c
- * Purpose : Misc CLI command objects and functions not worthy enough to
- * have their own files.
- *
- *
- *****************************************************************************/
- #include <stdio.h>
- #include <stdarg.h>
- #include <string.h>
- #include <tw_cli.h>
- /**************** *** Definition of CLI Command Objects *** ***************/
- /*** 1st level CLI Command Option - "exit"
- ***/
- static int CliRcoProc_Exit(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliRco_Exit =
- {
- "exit",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "terminate current telnet session",
- NULL,
- CliRcoProc_Exit,
- NULL
- };
- /*** 1st level CLI Command Option - "history"
- ***/
- static int CliRcoProc_History(Cli_cmdSession_t *pSess, char *CmdStr, int Ptr);
- Cli_CmdStruct_t CliRco_History =
- {
- "history",
- ALL_ACCESS_MODE | ALL_PRODUCT_TYPE,
- NULL,
- "display historical commands",
- NULL,
- CliRcoProc_History,
- NULL
- };
- /*****************************************************************************
- * int CliRcoProc_Exit(Cli_cmdSession_t *pSess, char *cmdStr, int ptr)
- *
- * Description :
- * This is the command processing handler for
- * "logout"
- *
- * Arguments :
- * Standard prarameters.
- *
- * Returns :
- * 0 if OK, -1 if bad.
- *
- * History
- * who when why
- * KBL 7/7/99 created
- *
- *****************************************************************************/
- int CliRcoProc_Exit(Cli_cmdSession_t *pSess, char *cmdStr, int ptr)
- {
- return -1;
- }
- /*****************************************************************************
- * int CliCoProc_History(Cli_cmdSession_t *pSess, char *cmdStr, int ptr)
- *
- * Description :
- * This is the command processing handler for
- * "history"
- *
- * Arguments :
- * Standard prarameters.
- *
- * Returns :
- * 0 if OK, -1 if bad.
- *
- * History
- * who when why
- * KBL 7/7/99 created
- *
- *****************************************************************************/
- int CliRcoProc_History(Cli_cmdSession_t *pSess, char *cmdStr, int ptr)
- {
- int i, hptr;
- char *cmd;
- char numStr[16]; /* u32 is 10 digits, plus 2 CR/LF and 1 space after */
- for (i = CLI_ACCESS_HISTORY_DEPTH; i >= 1; i--)
- {
- hptr = (pSess->historyPtr + CLI_ACCESS_HISTORY_DEPTH - i )% CLI_ACCESS_HISTORY_DEPTH;
- if (pSess->historyNum[hptr] == 0)
- {
- /* history number start from 1, 0 means empty history */
- continue;
- }
- sprintf(numStr, "%10d ", pSess->historyNum[hptr]);
- cmd = pSess->historyBuf[hptr];
- if (Cli_Printf(pSess, numStr) < 0)
- {
- return -1;
- }
- if (Cli_Printf(pSess, cmd) < 0)
- {
- return -1;
- }
- Cli_Printf(pSess, "n") ;
- }
- return 0;
- }