开发的Shell程序支持以下命令:
1)cd ——将当前默认目录改变为。如果没有参数,则显示当前目录;如果目录不存在,会出现合适的错误信息提示。
2)clr——清屏
3)dir ——列出目录的内容
4)environ——列出所有的环境变量
5)echo ——在屏幕上显示并换行
6)help——显示用户手册,并使用more命令过滤
7)pause——停止Shell存在直到按下回车键
8)quit——退出Shell
9)其它的命令行输入被解释为程序调用,Shell创建并执行这个程序。
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 35328 2013-11-08 13:38 myshellDebugmyshell.exe
文件 397272 2013-11-08 13:38 myshellDebugmyshell.ilk
文件 543744 2013-11-08 13:38 myshellDebugmyshell.pdb
文件 1133 2013-11-08 01:04 myshellDebugshellhelp.txt
文件 33619968 2013-11-18 14:22 myshellipchmyshell-5903f905myshell-acfa900a.ipch
文件 586 2013-11-08 13:38 myshellmyshellDebugcl.command.1.tlog
文件 13706 2013-11-08 13:38 myshellmyshellDebugCL.read.1.tlog
文件 238 2013-11-08 13:38 myshellmyshellDebugCL.write.1.tlog
文件 2 2013-11-08 13:38 myshellmyshellDebuglink-cvtres.read.1.tlog
文件 2 2013-11-08 13:38 myshellmyshellDebuglink-cvtres.write.1.tlog
文件 2 2013-11-08 13:38 myshellmyshellDebuglink.20520-cvtres.read.1.tlog
文件 2 2013-11-08 13:38 myshellmyshellDebuglink.20520-cvtres.write.1.tlog
文件 2 2013-11-08 13:38 myshellmyshellDebuglink.20520.read.1.tlog
文件 2 2013-11-08 13:38 myshellmyshellDebuglink.20520.write.1.tlog
文件 2 2013-11-08 13:38 myshellmyshellDebuglink.8200-cvtres.read.1.tlog
文件 2 2013-11-08 13:38 myshellmyshellDebuglink.8200-cvtres.write.1.tlog
文件 2 2013-11-08 13:38 myshellmyshellDebuglink.8200.read.1.tlog
文件 2 2013-11-08 13:38 myshellmyshellDebuglink.8200.write.1.tlog
文件 2 2013-11-08 13:38 myshellmyshellDebuglink.8548-cvtres.read.1.tlog
文件 2 2013-11-08 13:38 myshellmyshellDebuglink.8548-cvtres.write.1.tlog
文件 2 2013-11-08 13:38 myshellmyshellDebuglink.8548.read.1.tlog
文件 2 2013-11-08 13:38 myshellmyshellDebuglink.8548.write.1.tlog
文件 1308 2013-11-08 13:38 myshellmyshellDebuglink.command.1.tlog
文件 2808 2013-11-08 13:38 myshellmyshellDebuglink.read.1.tlog
文件 548 2013-11-08 13:38 myshellmyshellDebuglink.write.1.tlog
文件 350 2013-11-08 13:38 myshellmyshellDebugmt.command.1.tlog
文件 250 2013-11-08 13:38 myshellmyshellDebugmt.read.1.tlog
文件 250 2013-11-08 13:38 myshellmyshellDebugmt.write.1.tlog
文件 3005 2013-11-07 23:51 myshellmyshellDebugmyshell.Build.CppClean.log
文件 406 2013-11-07 23:51 myshellmyshellDebugmyshell.exe.embed.manifest
............此处省略27个文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define PAGELEN 24
#define LINELEN 512
#define BUFSIZE MAX_PATH
char buf[BUFSIZE];
char path[BUFSIZE];
int main(int argc char *argv[])
{
void cd_cmd(char *dir);
void dir_cmd(char *dir);
void clr_cmd();
void environ_cmd();
void echo_cmd(char *comment);
void help_cmd();
int pause_cmd();
void quit_cmd();
void otherOpration(char *dir);
char c*input*arg[2];
char *other;
int inputlen=0is_bg=0ij=0k;
DWORD dwRet;
printf(“Oprating System Shell [版本 1.0]
版权所有 2013 YU YING ZUO。保留所有权利。
“);
char * str=“C:\Users\Administrator“;
strcpy(pathstr);
SetCurrentDirectoryA(path);
while(true)
{
for(i=0;i<2;i++)
arg[i]=NULL;
dwRet=GetCurrentDirectoryA(BUFSIZEpath);
if(dwRet==0)
{
//返回当前目录失败,输出出错信息
printf(“GetCurrentDirectory failed.
“);
}
else if(dwRet>BUFSIZE)
{
printf(“GetCurrentDirectory failed(buffer too small;need%d chars)
“dwRet);
}
else
printf(“
%s>“path);
/**********输入***********/
inputlen=0;
//过滤无用字符
while((c=getchar())==‘ ‘||c==‘
‘||c==‘ ‘||c==EOF)
if(c==‘
‘)
continue;
while(c!=‘
‘)
{
buf[inputlen++]=c;
c=getchar();
}
buf[inputlen++]=‘ ‘;
//将命令从缓存复制到input中
input=(char*)malloc(sizeof(char)*(inputlen));
other=(char*)malloc(sizeof(char)*(inputlen));
strcpy(inputbuf);
strcpy(otherbuf);
/**********解析指令***********/
for(i=0j=0k=0;i {
if(input[i]==‘ ‘||input[i]==‘ ‘)
{
if(j==0) //去掉多余空格
continue;
else
{
buf[j++]=‘ ‘;
arg[k]=(char*)malloc(sizeof(char)*j);
strcpy(arg[k++]buf);
j=0;
}
}
else
buf[j++]=input[i];
}
/**********处理命令***********/
//cd
if(strcmp(arg[0]“cd“)==0||strcmp(arg[0]“CD“)==0)
{
for(i=3j=0;i buf[j++]=input[i];
buf[j]=‘ ‘;
arg[1]=(char*)malloc(sizeof(char)*j);
strcpy(arg[1]buf);
if(arg[1]==NULL)
cd_cmd(path);
else
cd_cmd(arg[1]);
free(input);
continue;
}
//dir
else if(strcmp(arg[0]“dir“)==0||strcmp(arg[0]“DIR“)==0)
{
char* route;
if(arg[1]==NULL)
{
route=path;
dir_cmd(route);
}
else
dir_cmd(arg[1]);
free(input);
continue;
}
//clr清屏
else if(strcmp(arg[0]“clr“)==0||strcmp(arg[0]“CLR“)==0)
{
clr_cmd();
free(input);
continue;
}
//environ获取所有环境变量
else if(strcmp(arg[0]“environ“)==0||strcmp(arg[0]“ENVIRON“)==0)
{
environ_cmd();
free(input);
continue;
}
//echo 显示comment并换行
else if(strcmp(arg[0]“echo“)==0||strcmp(arg[0]“ECHO“)==0)
{
for(i=5j=0;i buf[j++]=input[i];
buf[j]=‘ ‘;
arg[1]=(char*)malloc(
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 35328 2013-11-08 13:38 myshellDebugmyshell.exe
文件 397272 2013-11-08 13:38 myshellDebugmyshell.ilk
文件 543744 2013-11-08 13:38 myshellDebugmyshell.pdb
文件 1133 2013-11-08 01:04 myshellDebugshellhelp.txt
文件 33619968 2013-11-18 14:22 myshellipchmyshell-5903f905myshell-acfa900a.ipch
文件 586 2013-11-08 13:38 myshellmyshellDebugcl.command.1.tlog
文件 13706 2013-11-08 13:38 myshellmyshellDebugCL.read.1.tlog
文件 238 2013-11-08 13:38 myshellmyshellDebugCL.write.1.tlog
文件 2 2013-11-08 13:38 myshellmyshellDebugli
文件 2 2013-11-08 13:38 myshellmyshellDebugli
文件 2 2013-11-08 13:38 myshellmyshellDebugli
文件 2 2013-11-08 13:38 myshellmyshellDebugli
文件 2 2013-11-08 13:38 myshellmyshellDebugli
文件 2 2013-11-08 13:38 myshellmyshellDebugli
文件 2 2013-11-08 13:38 myshellmyshellDebugli
文件 2 2013-11-08 13:38 myshellmyshellDebugli
文件 2 2013-11-08 13:38 myshellmyshellDebugli
文件 2 2013-11-08 13:38 myshellmyshellDebugli
文件 2 2013-11-08 13:38 myshellmyshellDebugli
文件 2 2013-11-08 13:38 myshellmyshellDebugli
文件 2 2013-11-08 13:38 myshellmyshellDebugli
文件 2 2013-11-08 13:38 myshellmyshellDebugli
文件 1308 2013-11-08 13:38 myshellmyshellDebugli
文件 2808 2013-11-08 13:38 myshellmyshellDebugli
文件 548 2013-11-08 13:38 myshellmyshellDebugli
文件 350 2013-11-08 13:38 myshellmyshellDebugmt.command.1.tlog
文件 250 2013-11-08 13:38 myshellmyshellDebugmt.read.1.tlog
文件 250 2013-11-08 13:38 myshellmyshellDebugmt.write.1.tlog
文件 3005 2013-11-07 23:51 myshellmyshellDebugmyshell.Build.CppClean.log
文件 406 2013-11-07 23:51 myshellmyshellDebugmyshell.exe.em
............此处省略27个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)