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

首頁 > 編程 > C > 正文

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

2020-02-24 14:34:39
字體:
供稿:網(wǎng)友

下面武林技術(shù)頻道的小編就為大家?guī)硪黄獙崿F(xiàn)基于C語言的shell指令,小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考,一起跟隨小編過來看看吧。

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

復制代碼 代碼如下:

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ù)? 實現(xiàn)命令表

?

復制代碼 代碼如下:

?


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);
}

?

復制代碼 代碼如下:

?


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);
}

?

復制代碼 代碼如下:

?


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ù)

?

復制代碼 代碼如下:

?


//*****************************************************************************
//
// 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
#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 g_sCmdTable 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);

以上就是實現(xiàn)基于C語言的shell指令的全部內(nèi)容,如果大家想了解更多相關(guān)內(nèi)容,請持續(xù)關(guān)注本站,本站小編將在第一時間為大家?guī)砀玫慕?jīng)典內(nèi)容。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

欧美三级不卡| 日本精品一区二区三区在线播放| 欧美日韩精品是欧美日韩精品| 亚洲久久久久久久久久久| 日韩高清dvd碟片| 亚洲欧洲成视频免费观看| 亚洲一区二区中文字幕| 国产成人在线影院| 欧美一区91| 欧美孕妇与黑人孕交| 欧美综合一区二区三区| h视频在线观看免费网站| 亚洲视频在线观看视频| 国产极品视频在线观看| 91在线视频免费观看| 国产男女激情视频| 国产精品视频播放| 国产精品一区二区三区观看| 欧美二区三区| 日本高清不卡中文字幕| 狠狠入ady亚洲精品经典电影| 精品伦理一区二区| 欧美一级二级三级乱码| 欧美日本韩国一区二区三区视频| 国产网址在线观看| 亚洲人成电影在线观看网| 九色视频成人porny| 97精品人妻一区二区三区香蕉| 亚洲视频在线观看三级| 一级黄色电影片| 五月天激情综合网| 天干天干啦夜天干天2019| 欧美成人精品不卡视频在线观看| 国产精品av网站| 亚洲天天影视| 国产精品久免费的黄网站| 成年人午夜视频在线观看| 在线免费观看成人| 怡红院成永久免费人全部视频| 日韩美女一级视频| 久久久久成人精品无码| 国产99在线免费| 国产精品美女视频| 国产精品普通话对白| 国内国产区免费视频| www.xxx.国产| 亚洲柠檬福利资源导航| 7799精品视频| 国产日韩亚洲欧美精品| 美女又爽又黄免费| 国产一区视频网站| 免费在线观看av网址| 国产精品视频黄色| 五月婷婷欧美激情| 国产精品沙发午睡系列| 日韩有码一区| 涩涩视频在线观看免费| 男人的天堂视频在线| 国产精品69久久久久孕妇欧美| 99国产精品久久久久久久久久久| 波多野结衣av一区二区全免费观看| 超碰在线一区二区三区| 国产suv精品一区二区69| 欧美xoxoxo| 一区二区三区在线免费| 欧美一区二区三区免费观看视频| 91系列在线观看| 欧美三级韩国三级日本一级| 免费大片黄在线观看视频网站| 亚洲区免费影片| 国产欧美日本| 欧美高清激情视频| 日韩视频一区二区三区在线播放免费观看| 欧美一区永久视频免费观看| 中文字幕日韩精品久久| 日韩av一区二区在线播放| 亚洲天堂精品一区| 久久五月天小说| 成人午夜电影小说| 久久精品99久久香蕉国产色戒| 成人欧美一区二区三区在线湿哒哒| 日本a级片在线观看| 精品少妇人妻av一区二区三区| 天天噜夜夜操| 中文字幕日韩精品有码视频| 日韩av手机在线观看| 黄色小视频免费看| 加勒比一区二区三区在线| 国产一区二区不卡在线| 无码人妻aⅴ一区二区三区日本| 国产美女精品视频免费播放软件| 国产喷白浆一区二区三区| 久久久久资源| 日本中文在线观看| 色婷婷av一区二区三| 狠狠综合久久久综合| 香蕉av一区| 欧美精品中文字幕一区| 成人18视频免费69| 欧美中文在线观看| 91在线视频免费观看| 欧美成人日本| 天堂视频在线| 亚洲成人av一区二区三区| 性の欲びの女javhd| 欧美成人观看免费全部完小说| 久草免费在线观看视频| 亚洲视频免费一区| 欧美中日韩在线| 久久久久久久久久av| 中文字幕 91| 天海翼一区二区三区四区在线观看| 国产精品17p| 欧美成人国产精品高潮| 可以免费看的av毛片| 欧美久久久久久久久久久| 18av在线播放| 91产国在线观看动作片喷水| 中文字幕在线播放一区二区| 日韩在线视频网| 1024手机看片国产| 日本a级黄色| 欧美激情精品久久久久久黑人| 偷拍一区二区三区| 欧美日韩国内| 性感美女福利视频| 欧美一区二区激情| 久久综合久久久| 人人妻人人澡人人爽久久av| 国产又黄又猛又粗又爽| 五月天激情综合网| 国产精品91久久久久久| 欧美日韩一区二区三区视视频| 国产乱理伦片a级在线观看| 中文字幕无线码| 婷婷中文字幕一区| 国模冰冰炮一区二区| 久久中文字幕一区二区三区| 91精品国产综合久久男男| 亚洲青色在线| 久久99国产精品久久久久久久久| 免费xxxx性欧美18vr| 中文字幕亚洲欧美日韩2019| 欧美日韩午夜| 亚洲欧美日韩国产一区二区| 北条麻妃69av| 欧美日韩在线精品成人综合网| 欧美三级午夜理伦三级富婆| 国产精品久久久久久久久久久久久久| 国产卡一卡2卡三卡免费视频| 亚洲黄色一区| 精品国产91久久久久久久妲己| 婷婷亚洲图片| 九色综合日本| 九九热精品视频在线| 婷婷丁香综合网| 免费看一级毛片| 青青草国产精品视频| 影音先锋成人资源网站| 亚洲尤物av| 一级片免费在线观看| 亚洲精品在线视频免费| 亚洲国产一区二区三区在线播放| 国产日韩欧美一区二区东京热| 精品国产乱码久久久久久老虎| 曰本三级日本三级日本三级| 久久99亚洲热视| 国产成人精品免费看视频| 亚洲第一成人网站| 欧洲成人综合网| 欧美亚洲视频在线看网址| 日韩免费在线电影| 欧美tk—视频vk| 最新中文乱码字字幕在线| 露出调教综合另类| 免费一级片91| 日韩成人视屏| 在线观看一区二区三区四区| 伦伦影院午夜理论片| 高清无码视频直接看| 麻豆免费看一区二区三区| 久久久女人电视剧免费播放下载| 欧美日韩亚洲高清一区二区| 国产精品国产三级国产专播品爱网| 亚洲欧美日韩爽爽影院| 好吊妞视频一区二区三区| 亚洲欧洲在线观看av| 污视频在线观看网站| 两性午夜免费视频| 国产免费福利视频| 伊人精品视频在线观看| 欧美国产97人人爽人人喊| 视频免费在线看| 日本精品黄色| 91亚洲一区精品| 精品人妻一区二区三区潮喷在线| 图片区乱熟图片区亚洲| 性感美女一级片| 欧美电影《睫毛膏》| 99精品视频一区| 性欧美xxxx| 国产精品午夜av在线| 国产麻豆视频一区二区| youjizz.com在线观看| 国产香蕉97碰碰久久人人| 超碰在线最新网址| 91热精品视频| 久久久777精品电影网影网| 992tv成人免费影院| 中文字幕一区二区中文字幕| 中文字幕精品一区| 欧美一区二区三区久久| 日韩欧美成人午夜| 依人在线免费视频| 在线精品高清中文字幕| 99热最新在线| 午夜影院免费版| 日韩系列欧美系列| 欧美日韩亚洲一二三| 欧美人与性动交α欧美精品图片| 欧美一区二区三区成人久久片| 久久精品aⅴ无码中文字字幕重口| free性欧美16hd| 亚洲综合在线做性| 久久香蕉综合色一综合色88| 亚洲麻豆一区二区三区| 成人综合专区| 久久福利影视| 石原莉奈一区二区三区高清在线| 天天摸天天舔天天操| 日本久久电影网| 向日葵视频成人app网址| 中国黄色a级片| 欧美gay男男猛男无套| 91女主播在线观看| 蜜桃av鲁一鲁一鲁一鲁俄罗斯的| 精品一区二区在线免费观看| 免费在线a视频| 欧美牲交a欧美牲交| 国产欧美在线观看免费| 亚洲人成电影网站| 成人午夜免费在线视频| 台湾天天综合人成在线| 久久久久高潮毛片免费全部播放| 一本大道久久精品懂色aⅴ| 免费男女羞羞的视频网站中文字幕| av在线官网| 人妻丰满熟妇aⅴ无码| 国产精品日本欧美一区二区三区| 快射视频在线观看| 伊人成综合网伊人222| 日本jizzcom| 国产伦精品一区二区三区千人斩| 国产成人亚洲精品狼色在线| 日本超碰在线观看| 国产三区视频在线观看| 欧美成人午夜77777| av电影在线观看网站| heisi视频网在线观看| 亚洲视频在线观看| 日韩精品一区二区三区中文精品| 国产深喉视频一区二区| 国产欧美欧洲在线观看| 日韩精品亚洲元码| 日日碰狠狠添天天爽| 国产精品自拍三区| 久久久精品欧美丰满| 欧美黑吊大战白妞| 51国产成人精品午夜福中文下载| 盗摄女厕thunder| 久草手机视频在线观看| 亚洲色图第三页| 黄污视频在线观看| 99精品视频在线观看播放| 亚洲人视频在线| 97视频资源在线观看| 偷拍亚洲欧洲综合| 亚洲成人av一区二区| 国产ktv在线视频| 日本一区午夜艳熟免费| 精品一区二区三区五区六区| av噜噜在线观看| 国产精品高清一区二区三区| www.99视频| 欧美激情在线有限公司| 国产一二三四区在线| 深夜福利免费在线观看| 精品综合久久| 亚洲国产欧美不卡在线观看| 亚洲 欧美 综合 另类 中字| 成年人网站大全| 国内精品在线一区| 日本黄大片一区二区三区| 999在线免费视频| 日日夜夜精品免费| 92国产精品视频| 国产日韩精品久久| 亚洲在线视频一区| 精品在线视频免费观看| 一区二区三区四区影院| 成人免费观看毛片| 黄色毛片在线观看| 另类专区欧美蜜桃臀第一页| 亚洲免费高清视频| 国产一区二区三区在线视频| 99精品在线播放| 在线视频欧美性高潮| 日韩污视频在线观看| 精品乱子伦一区二区三区| chinesemodel无套啪啪| 精品国产免费人成电影在线观看四季| 中文字幕一区在线观看| 成人午夜精品一区二区三区| 国产乱色精品成人免费视频| 国产成人av影院| 亚洲深夜福利在线| 国产成人精品视频在线观看| 精品国产福利在线| 亚洲成人免费网站| 操操操干干干| 亚洲欧美日韩一区在线| 国产又粗又硬视频| 亚洲欧美日韩成人高清在线一区| 亚洲永久免费av| 夜久久久久久| 日韩精品无码一区二区三区久久久| 七七久久电影网| 国产一区二区三区三州|