亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > C > 正文

基于C語言實(shí)現(xiàn)shell指令的詳解

2020-01-26 16:07:31
字體:
供稿:網(wǎng)友
源代碼來自于TI開發(fā)板
在ARM上實(shí)現(xiàn)shell命令解析

第一步:構(gòu)建命令實(shí)現(xiàn)函數(shù)和命令表
1,定義結(jié)構(gòu)體 和命令表
復(fù)制代碼 代碼如下:

typedef int (*pfnCmdLine)(int argc, char *argv[]);
//*****************************************************************************
//
//! Structure for an entry in the command list table.
//
//*****************************************************************************
typedef struct
{
    //
    //! A pointer to a string containing the name of the command.
    //
    const char *pcCmd;
    //
    //! A function pointer to the implementation of the command.
    //
    pfnCmdLine pfnCmd;
    //
    //! A pointer to a string of brief help text for the command.
    //
    const char *pcHelp;
}
tCmdLineEntry;
//*****************************************************************************
//
//! This is the command table that must be provided by the application.
//
//*****************************************************************************
extern tCmdLineEntry g_sCmdTable[];

2,編寫命令執(zhí)行函數(shù)  實(shí)現(xiàn)命令表
復(fù)制代碼 代碼如下:

int
Cmd_help(int argc, char *argv[])
{
    tCmdLineEntry *pEntry;
    //
    // Print some header text.
    //
    UARTprintf("/nAvailable commands/n");
    UARTprintf("------------------/n");
    //
    // Point at the beginning of the command table.
    //
    pEntry = &g_sCmdTable[0];
    //
    // Enter a loop to read each entry from the command table.  The
    // end of the table has been reached when the command name is NULL.
    //
    while(pEntry->pcCmd)
    {
        //
        // Print the command name and the brief description.
        //
        UARTprintf("%s%s/n", pEntry->pcCmd, pEntry->pcHelp);
        //
        // Advance to the next entry in the table.
        //
        pEntry++;
    }
    //
    // Return success.
    //
    return(0);
}

復(fù)制代碼 代碼如下:

int
Cmd_ls(int argc, char *argv[])
{
    unsigned long ulTotalSize;
    unsigned long ulFileCount;
    unsigned long ulDirCount;
    FRESULT fresult;
    FATFS *pFatFs;
    //
    // Open the current directory for access.
    //
    fresult = f_opendir(&g_sDirObject, g_cCwdBuf);
    //
    // Check for error and return if there is a problem.
    //
    if(fresult != FR_OK)
    {
        return(fresult);
    }
    ulTotalSize = 0;
    ulFileCount = 0;
    ulDirCount = 0;
    //
    // Give an extra blank line before the listing.
    //
    UARTprintf("/n");
    //
    // Enter loop to enumerate through all directory entries.
    //
    for(;;)
    {
        //
        // Read an entry from the directory.
        //
        fresult = f_readdir(&g_sDirObject, &g_sFileInfo);
        //
        // Check for error and return if there is a problem.
        //
        if(fresult != FR_OK)
        {
            return(fresult);
        }
        //
        // If the file name is blank, then this is the end of the
        // listing.
        //
        if(!g_sFileInfo.fname[0])
        {
            break;
        }
        //
        // If the attribue is directory, then increment the directory count.
        //
        if(g_sFileInfo.fattrib & AM_DIR)
        {
            ulDirCount++;
        }
        //
        // Otherwise, it is a file.  Increment the file count, and
        // add in the file size to the total.
        //
        else
        {
            ulFileCount++;
            ulTotalSize += g_sFileInfo.fsize;
        }
        //
        // Print the entry information on a single line with formatting
        // to show the attributes, date, time, size, and name.
        //
        UARTprintf("%c%c%c%c%c %u/%02u/%02u %02u:%02u %9u  %s/n",
                    (g_sFileInfo.fattrib & AM_DIR) ? 'D' : '-',
                    (g_sFileInfo.fattrib & AM_RDO) ? 'R' : '-',
                    (g_sFileInfo.fattrib & AM_HID) ? 'H' : '-',
                    (g_sFileInfo.fattrib & AM_SYS) ? 'S' : '-',
                    (g_sFileInfo.fattrib & AM_ARC) ? 'A' : '-',
                    (g_sFileInfo.fdate >> 9) + 1980,
                    (g_sFileInfo.fdate >> 5) & 15,
                     g_sFileInfo.fdate & 31,
                    (g_sFileInfo.ftime >> 11),
                    (g_sFileInfo.ftime >> 5) & 63,
                     g_sFileInfo.fsize,
                     g_sFileInfo.fname);
 // tcp_write(Rpcb,g_sFileInfo.fname,sizeof(g_sFileInfo.fname),0);
    }   // endfor
    //
    // Print summary lines showing the file, dir, and size totals.
    //
    UARTprintf("/n%4u File(s),%10u bytes total/n%4u Dir(s)",
                ulFileCount, ulTotalSize, ulDirCount);
    //
    // Get the free space.
    //
    fresult = f_getfree("/", &ulTotalSize, &pFatFs);
    //
    // Check for error and return if there is a problem.
    //
    if(fresult != FR_OK)
    {
        return(fresult);
    }
    //
    // Display the amount of free space that was calculated.
    //
    UARTprintf(", %10uK bytes free/n", ulTotalSize * pFatFs->sects_clust / 2);
    //
    // Made it to here, return with no errors.
    //
    return(0);
}

復(fù)制代碼 代碼如下:

tCmdLineEntry g_sCmdTable[] =
{
    { "help",   Cmd_help,      " : Display list of commands" },
    { "h",      Cmd_help,   "    : alias for help" },
    { "?",      Cmd_help,   "    : alias for help" },
    { "ls",     Cmd_ls,      "   : Display list of files" },
    { "chdir",  Cmd_cd,         ": Change directory" },
    { "cd",     Cmd_cd,      "   : alias for chdir" },
    { "pwd",    Cmd_pwd,      "  : Show current working directory" },
    { "cat",    Cmd_cat,      "  : Show contents of a text file" },
 { "rm",     CMD_Delete,   "  : Delete a file or a folder"    },
    { 0, 0, 0 }
};

第二步:編寫命令解析 執(zhí)行函數(shù)
復(fù)制代碼 代碼如下:

//*****************************************************************************
//
// cmdline.c - Functions to help with processing command lines.
//
// Copyright (c) 2007-2010 Texas Instruments Incorporated.  All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 6594 of the Stellaris Firmware Development Package.
//
//*****************************************************************************
//*****************************************************************************
//
//! /addtogroup cmdline_api
//! @{
//
//*****************************************************************************
#include <string.h>
#include "cmdline.h"
//*****************************************************************************
//
// Defines the maximum number of arguments that can be parsed.
//
//*****************************************************************************
#ifndef CMDLINE_MAX_ARGS
#define CMDLINE_MAX_ARGS        8
#endif
//*****************************************************************************
//
//! Process a command line string into arguments and execute the command.
//!
//! /param pcCmdLine points to a string that contains a command line that was
//! obtained by an application by some means.
//!
//! This function will take the supplied command line string and break it up
//! into individual arguments.  The first argument is treated as a command and
//! is searched for in the command table.  If the command is found, then the
//! command function is called and all of the command line arguments are passed
//! in the normal argc, argv form.
//!
//! The command table is contained in an array named <tt>g_sCmdTable</tt> which
//! must be provided by the application.
//!
//! /return Returns /b CMDLINE_BAD_CMD if the command is not found,
//! /b CMDLINE_TOO_MANY_ARGS if there are more arguments than can be parsed.
//! Otherwise it returns the code that was returned by the command function.
//
//*****************************************************************************
int
CmdLineProcess(char *pcCmdLine)
{
    static char *argv[CMDLINE_MAX_ARGS + 1];
    char *pcChar;
    int argc;
    int bFindArg = 1;
    tCmdLineEntry *pCmdEntry;
    //
    // Initialize the argument counter, and point to the beginning of the
    // command line string.
    //
    argc = 0;
    pcChar = pcCmdLine;
    //
    // Advance through the command line until a zero character is found.
    //
    while(*pcChar)
    {
        //
        // If there is a space, then replace it with a zero, and set the flag
        // to search for the next argument.
        //
        if(*pcChar == ' ')
        {
            *pcChar = 0;
            bFindArg = 1;
        }
        //
        // Otherwise it is not a space, so it must be a character that is part
        // of an argument.
        //
        else
        {
            //
            // If bFindArg is set, then that means we are looking for the start
            // of the next argument.
            //
            if(bFindArg)
            {
                //
                // As long as the maximum number of arguments has not been
                // reached, then save the pointer to the start of this new arg
                // in the argv array, and increment the count of args, argc.
                //
                if(argc < CMDLINE_MAX_ARGS)
                {
                    argv[argc] = pcChar;
                    argc++;
                    bFindArg = 0;
                }
                //
                // The maximum number of arguments has been reached so return
                // the error.
                //
                else
                {
                    return(CMDLINE_TOO_MANY_ARGS);
                }
            }
        }
        //
        // Advance to the next character in the command line.
        //
        pcChar++;
    }
    //
    // If one or more arguments was found, then process the command.
    //
    if(argc)
    {
        //
        // Start at the beginning of the command table, to look for a matching
        // command.
        //
        pCmdEntry = &g_sCmdTable[0];
        //
        // Search through the command table until a null command string is
        // found, which marks the end of the table.
        //
        while(pCmdEntry->pcCmd)
        {
            //
            // If this command entry command string matches argv[0], then call
            // the function for this command, passing the command line
            // arguments.
            //
            if(!strcmp(argv[0], pCmdEntry->pcCmd))
            {
                return(pCmdEntry->pfnCmd(argc, argv));
            }
            //
            // Not found, so advance to the next entry.
            //
            pCmdEntry++;
        }
    }
    //
    // Fall through to here means that no matching command was found, so return
    // an error.
    //
    return(CMDLINE_BAD_CMD);
}

第三步:收到命令 調(diào)用解析函數(shù)
接收可用串口 網(wǎng)口等
假如收到的嗎,命令為  ls -l
*cmd="ls -l";
CmdLineProcess(cmd);
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

日韩欧美专区在线| 国内精品国语自产拍在线观看| 成视频在线观看免费观看| 欧美激情手机在线视频| 亚洲av无码专区在线播放中文| 国模吧精品视频| 一道精品视频一区二区三区图片| 福利影院在线看| 不卡视频免费在线观看| 神马久久久久| 99久久99九九99九九九| 好吊妞这里只有精品| 欧美成人三级在线观看| 欧美日韩精品久久久| 爆操妹子视频在线观看| 天使と恶魔の榨精在线播放| 久久久久综合网| 日韩国产一区久久| www99avcom| 久久精品一区二区三| 牛牛影视一区二区三区免费看| 精品少妇av| 日本欧美韩国国产| 不卡中文字幕av| 99久久婷婷国产一区二区三区| 美洲天堂一区二卡三卡四卡视频| 九色porn蝌蚪| 久久国产免费观看| 潘金莲激情呻吟欲求不满视频| 久久mv成人精品亚洲动漫| 久久不见久久见国语| 国产91白丝在线播放| 成人av小说网| 黄页网站大全在线观看| 久久久久久国产精品mv| 伊人久久99| 九七影院97影院理论片久久| 99在线视频观看| 亚洲色图一区二区三区| 免费看毛片网站| 精品999久久久| 特黄一区二区三区| 国产剧情麻豆剧果冻传媒视频免费| 成人免费毛片嘿嘿连载视频…| 在线观看免费视频一区二区三区| 精品国产乱码一区二区三区| 蜜臀久久99精品久久久| 欧美高清视频一区二区三区在线观看| 国产综合图区| 亚洲精品久久久久久久久久| 国产91在线播放精品| 伊人久久综合97精品| 555夜色666亚洲国产免| 99精品一区二区三区| 最近最好的中文字幕2019免费| 在线观看av免费观看| 天天操天天摸天天舔| 一区二区三区 日韩| 精品视频一区二区三区四区五区| 一区二区三区韩国| 日本啊v在线| 奇米影视狠888| 九七伦理97伦理手机| 中文字幕电影在线观看| 成人av免费电影| 欧美一级二级三级乱码| 日本福利在线| 高清视频一区二区三区四区| 久久精品美女视频| 欧美黄色片视频| 欧美xxx网站| 日日躁夜夜躁人人揉av五月天| 菠萝蜜视频在线观看一区| 成人av免费电影网站| www黄色在线观看视频| 日韩精品一区二区三区视频在线观看| 欧美黑人性受xxxx精品| 成人性生交大片免费看中文| 精品美女视频| 波多野结衣视频一区| 国产一区欧美一区| 黄色小视频在线播放| 91在线精品视频| 牛牛电影国产一区二区| 视频在线99re| 激情五月开心婷婷| 午夜精品久久久久久久| 无码一区二区三区在线| 日韩欧美国产一区二区三区| 精品网站在线| 中文字幕在线免费看线人| 亚洲高清免费观看高清完整版在线观看| 成人在线网址| 国产综合内射日韩久| 91精品蜜臀在线一区尤物| 性折磨bdsm欧美激情另类| 91在线免费网站| 黄色一级片免费播放| 欧美色中文字幕| 久久人妻精品白浆国产| 五月天久久久| 免费在线毛片网站| 欧美扣逼视频| 精品偷拍各种wc美女嘘嘘| 天美星空大象mv在线观看视频| 国产一区二区视频播放| 日韩中文字幕视频在线| 美洲精品一卡2卡三卡4卡四卡| 天天操夜夜做| 登山的目的在线| 337p粉嫩色噜噜噜大肥臀| 欧洲精品一区二区三区久久| 综合干狼人综合首页| 日韩免费影院| 青青草原av| 国产一区视频在线| 91精品入口蜜桃| 一区二区三区四区乱视频| 亚洲精品一区二区三区蜜桃久| 极品粉嫩国产18尤物| 在线观看黄网站免费继续| 黑人中文字幕一区二区三区| 午夜男人视频在线观看| 国模大尺度一区二区三区| 日本a级片在线观看| 成人亚洲精品| h视频免费高清在线观看| 欧美日韩在线精品一区二区三区激情| 久久天天做天天爱综合色| 石原莉奈一区二区三区高清在线| 日日av拍夜夜添久久免费| 中文字幕视频一区二区在线有码| 国产精品1区二区.| 亚洲av鲁丝一区二区三区| 超碰91在线观看| av在线麻豆| 超碰日本道色综合久久综合| 欧美熟妇一区二区| 色婷婷精品久久二区二区蜜臂av| 国产精品久久久久久久久妇女| 欧美色大人视频| 欧美精品日韩综合在线| 国产又大又黄又粗的视频| xxxxx性欧美特大| 大奶一区二区三区| 日本在线xxx| 国产精品18久久久久久久久久| 91精品国产吴梦梦| 91日韩中文字幕| 7777精品伊人久久久大香线蕉经典版下载| 国产精品国产亚洲精品看不卡15| 欧美a级网站| 久久国际精品| 手机av在线不卡| 国产成人高清激情视频在线观看| 午夜电影福利网| 色噜噜久久综合伊人一本| 视频一区二区三区国产| 欧美aaa级片| 91网在线免费观看| 韩国三级日本三级少妇99| 日韩欧中文字幕| 国产久草在线| 久久婷婷五月综合色国产香蕉| 911久久香蕉国产线看观看| 欧美日韩色婷婷| 日韩精品中文字幕第1页| 国产国语刺激对白av不卡| 色婷婷精品久久二区二区密| 黄色一级片在线免费观看| 成年网址网站在线观看| 国产精品一区二区三区视频网站| 丝袜国产日韩另类美女| 日日干夜夜操s8| 欧美一区二区三区喷汁尤物| 亚洲欧美一二三区| 三级理论午夜在线观看| 亚洲精品成av人片天堂无码| 91另类视频| 热久久这里只有精品| 国产极品精品在线观看| 欧美h版在线观看| 中文在线中文资源| 99免费视频观看| 亚洲精品自拍动漫在线| 亚洲电影在线播放| 91看片淫黄大片一级| 红桃一区二区三区| 亚洲国产精品中文| 国产人妻777人伦精品hd| 日韩精品一区二区亚洲av| 亚洲乱码国产乱码精品精天堂| 特级西西444www大精品视频免费看| 青娱乐国产盛宴| 欧美精品生活片| 99久久久久国产精品| 韩国在线视频一区| 国产特级毛片| 狠狠躁天天躁日日躁欧美| 精品精品99| 日本在线视频中文有码| 天堂网在线.www天堂在线| 精品视频一区三区九区| 亚洲中文无码av在线| 天然素人一区二区视频| 亚洲性线免费观看视频成熟| 亚洲精品久久久蜜桃动漫| 你懂的网站在线播放| 欧美性生活一级| 新天天拍日日拍狠狠拍| 国产精品视频不卡| 理论片在线不卡免费观看| 亚洲日本在线看| av一级黄色片| 欧美一区二区视频在线观看2022| 影音先锋中文在线视频| 悠悠资源网久久精品| 潘金莲一级淫片aaaaa免费看| 亚洲成人精品在线播放| 99精品国产一区二区三区2021| 丰满人妻一区二区三区四区| 亚洲国产一区二区精品视频| 992tv在线成人免费观看| 久久这里只有精品23| 亚洲综合网站| 亚洲欧洲高清| 色婷婷av一区二区| 日韩欧美精品在线观看视频| 99久久久国产精品免费调教网站| 日韩国产高清影视| 久久久久亚洲av无码专区体验| 日韩一级成人av| 日韩成人在线电影| 国产精品va在线播放我和闺蜜| 伪装者在线观看完整版免费| 三级影片在线看| 欧美网站大全在线观看| 2021中文字幕在线| 欧美性三三影院| 视频二区在线播放| 国产野外作爱视频播放| 久久蜜桃资源一区二区老牛| 狠狠色综合一区二区| 色综合视频二区偷拍在线| 综合久久综合久久| 色悠久久久久综合欧美99| 欧洲国产伦久久久久久久| 日本高清成人免费播放| 欧美一级久久久| 91精品入口蜜桃| 在线a人片免费观看视频| 中文精品一区二区| 一色桃子久久精品亚洲| 国产xxxxx视频| www.男人天堂.com| 欧美特级限制片免费在线观看| 午夜在线观看视频18| 免费一区二区三区在在线视频| 欧美日韩国产精品成人| 大型av综合网站| 欧洲亚洲在线视频| 国产精品久久久久久影视| 欧美极品少妇xxxxⅹ裸体艺术| 热re久久精品国产99热| 国产娇喘精品一区二区三区图片| 91香蕉网站| 久久精品亚洲精品国产欧美kt∨| 黄色亚洲精品| 男人的天堂在线免费视频| 国产精品久久久久久久久久齐齐| 欧美日韩精品久久久免费观看| 欧美一区二区日韩一区二区| 欧美va天堂va视频va在线| www.日本精品| 精品无人区乱码1区2区3区在线| 日韩主播视频在线| 亚洲欧美自拍另类日韩| 亚洲老头同性xxxxx| 91亚洲精品久久久蜜桃借种| 狠狠色综合播放一区二区| 日本爱爱爱视频| 日本在线观看www| 精品国产一区二区三区四区精华| 中文字幕无乱码| 欧美视频网站| 少妇丰满尤物大尺度写真| 国产成人三级视频| 在线观看91| 日韩福利一区二区| 国产色产综合色产在线视频| 国产精品99精品无码视| 欧美女优在线观看| 综合亚洲深深色噜噜狠狠网站| 国产精品女同一区二区三区| 色偷偷亚洲男人天堂| 伊人影院综合在线| 国产大奶在线| 国产白袜脚足j棉袜在线观看| 欧美va亚洲va日韩∨a综合色| 69成人精品免费视频| 日韩中文综合网| 日韩精品中文字幕一区二区三区| 欧美一区二区三区在线观看免费| 人妻体体内射精一区二区| 亚洲成色最大综合在线| 一区二区免费av| 性欧美大战久久久久久久免费观看| 无套白嫩进入乌克兰美女| 色播亚洲视频在线观看| 欧美亚洲一区二区在线| f2c人成在线观看免费视频| 伊人一区二区三区| 午夜在线视频播放| 欧美特级黄色录像| 亚欧美无遮挡hd高清在线视频| 国产一区二区三区成人欧美日韩在线观看| www久久久com| 99精品视频在线免费播放| 大伊香蕉精品视频在线| 一级片视频免费观看| 欧美怡春院一区二区三区| 亚洲色图视频在线观看| 黄色a一级视频| 成人免费观看视频在线观看| 久久久久久九九九九| 免费成人在线观看| 欧美高清不卡在线| 你懂的网站在线播放|