




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、计算机与信息学院操作系统课程设计报告专 业 班 级 计算机科学与技术08-5班 学生姓名及学号 邹纯纯 20082681 课程教学班号 任 课 教 师 刘晓平、李琳、田卫东 实验指导教师 李琳 实验地点 逸夫楼507 2010 2011 学年第 二 学期目录第1章 课程设计任务、要求、目的.3第2章 原理及算法描述.3第3章 开发环境.4第4章 重要算法和设计思路描述.4第5章 程序实现-数据结构.7第6章 程序实现-程序清单.8第7章 总结.24第8章 参考文献.24 第一章 课程设计任务、要求、目的1.1课程设计任务 本次课程设计的任务是在windows环境下实现兼容unix/linux操
2、作系统的命令接口,并实现一些指定的命令功能。1.2课程设计要求和目的 1、为windows操作系统建立一个兼容unix命令的命令接口; 2、实现命令包括ls,cat,cp,mv,md,rd,cd,sort,more,print,命令的内容 与详细格式请查阅unix命令手册;3、 可以字符形式接收命令,执行命令,然后显示命令执行结果。 第二章 原理及算法描述计算机的操作我们通常使用的是windows操作系统,在windows2000以上的版本中,我们只需在“搜索程序和文件”选项框中输入cmd命令进入windows操作系统中就可以达到实现系统相关功能的目的。同样在unix和linux操作平台中,也
3、可以实现相关命令以完成操作系统的相关操作。现在我们必须实现这样一种方法,即为windows操作系统建立一个兼容unix命令的命令接口。在主程序中新建一个windows_unix.exe文件,然后调用相关实现相关unix命令的函数实现命令功能。具体命令的实现主要通过系统的api函数调用与之功能相同或相似的dos命令,这样就可以实现在windows操作系统中虚拟地实现unix命令。 第三章 开发环境1、硬件环境:微型计算机。2、软件环境:windows 7 操作系统,语言环境为visual c+ 6.0。第4章 重要算法和设计思路描述1、 实验要实现的unix命令包括ls、cat、cp、mv、md
4、、rd、cd、sort、more、print等。2、 unix常用指令功能内容:(1) ls ls 的意义为 list,实现显示指定目录中的文件和子目录。如果你在下 ls 指令后面没有跟著任何的文件名或目录名,则会显示出当前目前目录中所有文件信息。(2) catcat指令实现指定目录中文件,打开文件并显示其中的内容的功能,当要打开的文件无效时会返回打开文件失败。(3) cp cp 是复制(copy) ,也就是将一个或多个文件复制成另一个文件或者是将其复制到另一个目录去,另外可以对要复制的目标文件进行重命名操作。(4) mv md drive:pathnmv 的意义为 move , 主要是实现将
5、文件从一个目录移到另一个目录。(5) mdmd实现在指定的目录或文件下创建目录。(6) rdrd实现删除当前指定的内容为空的目录,若当前目录不为空则无法进行删除目录操作。(7)cdcd指令实现显示当前目录的名称或将其更改。程序中我设定的是cd -s为显示当前目录,而cd .n,其中.为要父目录,即指定要切换到的目录。(8) sortsort指令实现对指定文件中的所有的行进行排序,并将结果标准输出。排序的算法可以是按升序或按降序进行排列。(9) moremore实现将指定超过一页的文件临时停留在屏幕,等按任何的一个键后才继续显示。(10) printprint指令实现对指定的文件连接当前计算机的
6、打印设备进行打印操作。 除了上述的实验要求的命令,为了便于操作和命令的使用查询,我另外设置了以下指令:help: 提供帮助信息。n命令 + -help: 提供命令的详细操作信息。nexit: 退出命令解释程序。n3、设计思路(1)void lsfunction(string *lsinput,int lscount)函数实现显示一个目录中的文件和子目录。如果失败返回显示“路径可能不存在!” 。(2)void catfunction(string *catinput,int catcount)函数实现打开文件并显示内容。如果失败返回显示“无法打开文件!”。(3)void cpfunction(s
7、tring *cpinput,int cpcount)函数实现复制文件和目录树。如果成功返回显示“复制成功”,否则显示“文件或目录可能不存在!” 。(4)void mvfunction(string *mvinput,int mvcount)函数实现将文件从一个目录移到另一个目录。如果成功返回显示“成功” ,否则显示“文件或目录可能不存在!” 。(5)void mdfunction(string *mdinput,int mdcount)实现在指定的目录或文件下创建目录。(6)void rdfunction(string *rdinput,int rdcount)函数实现删除空目录。如果成功返
8、回显示“删除目录成功” ,否则显示“文件夹可能不存在或文件夹不为空!” 。(7)void cdfunction(string *cdinput,int cdcount)函数实现显示当前目录的名称或将其更改。如果失败返回显示“路径可能不存在!” 。(8)void sortfunction(string *sortinput,int sortcount)指令实现对指定 文件中的所有的行进行排序,并将结果标准输出。排序的算法可以是按升序或按降序进行排列。(9)void morefunction(string *moreinput,int morecount)实现将指定超过一页的文件临时停留在屏幕,等
9、按任何的一个键后才继续显示。(10)void printfunction(string *printinput,int printcount)实现对指定的文件连接当前计算机的打印设备进行打印操作。(11)void helpfunction()函数实现提供windows命令的帮助信息。如果失败返回显示“命令语法不正确” 。(12)void exitfunction()函数实现退出命令解释程序。(13)void printpath()函数实现显示当前操作的目录路径。(14)在主函数int main()中通过输入具体的unix命令来判断进入何种函数实现相应的功能。此外在命令名后加入-help,可以调
10、出相应命令的使用说明。第5章 程序实现-数据结构程序开始输出当前版本信息用户输入命令字符判断进入何种命令操作函数 是exit指令 判断不是exit命令ls()cat()cp()mv()md()rd()cd()sort()more()print()退出程序第六章 程序实现-程序清单程序清单:#include windows.h#include fstream#include string#include iomanip#include iostreamusing namespace std;#define printheadhelp = tos课程设计操作系统接口:兼容unix/linux命令接
11、口n 要求:n 1、为windows操作系统建立一个兼容unix命令的命令接口;n 2、实现命令包括ls,cat,cp,mv,md,rd,cd,sort,more,print等命令的内容与详细格式请查阅 unix命令手册;n 3、可以字符形式接收命令,执行命令,然后显示命令执行结果;n=#define printhelp 有关每个命令的详细信息,请键入命令-help。n ls 显示指定目录中的文件和子目录。n cat 打开文件并显示内容。n cp 复制文件和目录树。n mv 将文件从一个目录移到另一个目录。n md 创建目录n rd 删除空目录。n cd 显示当前目录的名称或将其更改。n so
12、rt 对指定文件中的所有的行进行排序,并将结果标准输出。n more 超过一页的文件临时停留在屏幕,等按任何的一个键后才继续显示。n print 打印。n help 提供帮助信息。n 命令 + -help 提供命令的详细操作信息。n exit 退出命令解释程序。nn 有关工具的详细信息,请参阅联机帮助中的命令行参考。nn#define printlshelp显示目录中的文件和子目录列表。nls drive:pathfilename +?n drive:pathfilenamen 显示要列出的驱动器、目录或文件。n#define printcathelp 打开文件并显示内容。n cat driv
13、e:pathdirname1#define printcphelp复制文件和目录树。ncpsourcedestinationn source 指定要复制的文件。ndestination 指定新文件的位置或名称。n#defineprintmvhelp将文件从一个目录移到另一个目录。n移动:mv drive:pathdirname1 destinationn重命名:mv drive:pathdirname1 dirname2n#define printmdhelp 创建目录。nmd drive:pathn#define printrdhelp 删除目录。n rmdir /s /q drive:pa
14、thn rd /s /q drive:pathn#define printcdhelp 显示当前目录名或改变当前目录。ncd -s:显示drive:path +?ncd .n . 指定要改成父目录。n#define printsorthelp 对指定文件中的所有的行进行排序,并将结果标准输出。n sort sourcen source 指定要进行行排序的文件n#define printmorehelp 使超过一页的文件临时停留在屏幕,等按任何的一个键后才继续显示。n more sourcen source 指定要进行显示的文件n#define printprinthelp 将文件打印出来。n
15、print sourcen source 指定要进行打印的文件n/-1、lsvoid lshelpfunction()coutprintlshelpendl;void lsfunction(string *lsinput,int lscount)void printpath(void);if(1 = lscount)handlehandle;char fc50;filetime lpcreationtime,lplastaccesstime,lplastwritetime;systemtime stime;win32_find_data* fd = new win32_find_data();
16、if(!:getcurrentdirectory(50,fc)cout路径可能不存在!cfilename,generic_read,file_share_read | file_share_delete,null,open_existing,file_flag_backup_semantics, null); if(getfiletime(hdir, &lpcreationtime, &lplastaccesstime, &lplastwritetime) filetime ftime; filetimetolocalfiletime(&lplastwritetime, &ftime); /转
17、换成本地时间 filetimetosystemtime(&ftime, &stime); /转换成系统时间格式 coutsetfill(0);coutstime.wyear-setw(2)stime.wmonth-setw(2)stime.wday setw(2)stime.wminute:setw(2)stime.wmilliseconds;cout cfilenameendl;closehandle(hdir);while (findnextfile(handle, fd);findclose(handle);printpath();else if (lscount = 2)if (lsi
18、nput1 = ? )coutprintlshelpendl;elsehandlehandle;char fc50,fe50;filetime lpcreationtime,lplastaccesstime,lplastwritetime;systemtime stime;win32_find_data* fd = new win32_find_data();if (!:getcurrentdirectory(50,fc)cout路径可能不存在!endl;if (!setcurrentdirectory(lsinput1.c_str()cout路径可能不存在!endl;if (!:getcur
19、rentdirectory(50,fe)cout路径可能不存在!cfilename,generic_read,file_share_read | file_share_delete,null,open_existing,file_flag_backup_semantics, null); if(getfiletime(hdir, &lpcreationtime, &lplastaccesstime, &lplastwritetime) filetime ftime; filetimetolocalfiletime(&lplastwritetime, &ftime); / 转换成本地时间 fil
20、etimetosystemtime(&ftime, &stime); / 转换成系统时间格式 coutsetfill(0);coutstime.wyear-setw(2)stime.wmonth-setw(2)stime.wday setw(2)stime.wminute:setw(2)stime.wmilliseconds;cout cfilenameendl;closehandle(hdir);while (findnextfile(handle, fd);findclose(handle);if(!setcurrentdirectory(fc)cout路径可能不存在!endl;print
21、path();/-2、catvoid cathelpfunction()coutprintcathelpendl;/* /单独显示打开文件地址string catfunction()string file_name;coutfile_name;ifstream infile(file_name.c_str(),ios:in); /open file with the way of inputif (!infile)cout无法打开文件 file_name.c_str()!;char f2000;infile.getline(f,2000,eof);cout_endl;coutfendl;cou
22、t_endl;infile.close();return f;*/void catfunction(string *catinput,int catcount)void printpath(void);if (1 = catcount)cout命令语法不正确!endl;printpath();if (2 = catcount)ifstream infile(catinput1.c_str(),ios:in);if (!infile)cout无法打开文件 catinput1.c_str()!endl;goto l;char f2000;infile.getline(f,2000,null); /
23、eofcout_;coutfendl;cout_;l:infile.close();printpath();/-3、cpvoid cphelpfunction()coutprintcphelp cp 源文件路径 目的文件路径/另外在copy的过程可以进行重命名操作,即cpinput2.c_str()void printpath(void);if (1 = cpcount)cout命令语法不正确!endl;printpath();elseif (!copyfile(cpinput1.c_str(),cpinput2.c_str(),1)cout文件或目录可能不存在t!endl;printpath
24、();elsecout复制文件成功!endl;printpath();/-4、mvvoid mvhelpfunction()coutprintmvhelpendl;void mvfunction(string *mvinput,int mvcount)void printpath(void);if (1 = mvcount)cout命令语法不正确!endl;printpath();else if (mvcount = 3)if (0 = movefile(mvinput1.c_str(),mvinput2.c_str()cout移动失败,文件或目录可能不存在!endl;printpath();
25、elsecout移动文件成功!endl;printpath();/-5、mdvoid mdhelpfunction()coutprintmdhelpendl;void mdfunction(string *mdinput,int mdcount)void printpath(void);if (1 = mdcount)cout命令语法不正确!endl;printpath();elseif (0 = createdirectory(mdinput1.c_str(),null)cout路径不对或目录不存在!endl;printpath();elsecout创建目录成功!endl;printpath
26、();/-6、rdvoid rdhelpfunction()coutprintrdhelpendl;void rdfunction(string *rdinput,int rdcount)void printpath(void);if (1 = rdcount)cout命令语法不正确!endl;printpath();if (2 = rdcount)if (0 = removedirectory(rdinput1.c_str()cout路径不对或目录不存在!endl;printpath();elsecout删除空目录成功!endl;printpath();/-7、cdvoid cdhelpfu
27、nction()coutprintcdhelpendl;void cdfunction(string *cdinput,int cdcount)void printpath(void);void getpath(void);if (1 = cdcount)cout命令语法不正确!endl;printpath();if (2 = cdcount & cdinput1 = -s)cout当前目录的名称为: ; getpath(); /显示当前路径:调用api函数getcurrentdirectory()或直接调用函数printpath()coutendl;printpath();else if (
28、2 = cdcount & cdinput1 != -s) if (!setcurrentdirectory(cdinput1.c_str() /更改当前路径cout路径可能不存在!endl;printpath();/-8、sortvoid sorthelpfunction()coutprintsorthelpendl;void sortfunction(string *sortinput,int sortcount)void printpath(void);string buffer100; /line 100int i = 0;int number = 0;if (1 = sortcoun
29、t)cout命令语法不正确!endl;printpath();if (2 = sortcount)fstream infile(sortinput1.c_str();if (!infile)cout无法打开文件 sortinput1.c_str() !bufferi) i+;number = i;infile.close();string buffer_temp;int j = 0;int k = 0;/对指定文件中的所有的行进行排序bufferfor (j = 0; j number; j+)for (k = j; k number; k+)if (bufferk = bufferj)buf
30、fer_temp = bufferk;bufferk = bufferj;bufferj = buffer_temp;ofstream outfile(d:sortfile.txt); /将sort后的行内容写入新文件中if (!outfile)cout读入数据失败!endl;elsefor (i = 0; i number; i+)outfilebufferiendl;coutsort操作完毕,新文件为d:sortfile.txt!endl;outfile.close();printpath();/-9、morevoid morehelpfunction()coutprintmorehelp
31、endl;void morefunction(string *moreinput,int morecount)void printpath(void);string get5000;int i = 0;int count = 0;if (1 = morecount)cout命令语法不正确!endl;printpath();if (2 = morecount)fstream fin(moreinput1.c_str();if (!fin)cout无法打开文件 moreinput1.c_str() !geti) i+; count = i; if (0 != i)int dis = 0;l:for
32、 (i = dis; i = count/24; i+)for (int j = i*24; j i*24+24; j+)if (getj != 0)coutgetjendl;cout-第dis+1页-;dis+;while (1)/if (kbhit() /kbhit()不清空缓存,是非阻塞型的函数/控制文档使之停止继续显示/if (getchar() = !)/goto s;if (getchar() != 0)goto l;/s:/cout已经停止显示文件!endl;/-10、printvoid printhelpfunction()coutprintprinthelpendl;void
33、 printfunction(string *printinput,int printcount)void printpath(void);if (1 = printcount)cout命令语法不正确!endl;/coutprintinput0不是内部或外部命令,也不是可运行的程序或批处理文件。endl;printpath();if (2 = printcount)fstream infile(printinput1.c_str();if (!infile)cout打开文件printinput1.c_str()失败!endl;printpath();elsecout要打印的文件为printin
34、put1.c_str()endl;cout正在连接计算机打印机;for (int num = 0; num 6; num+)cout.;sleep(500); /0.5 smessagebox(null,打印之前必须选择打印机。n如果需要安装打印机,请双击“添加打印机”图标。,打印,mb_iconerror);coutendl;printpath();/-helpvoid helpfunction()/cout_;coutprinthelp;/cout_;/-exitvoid exitfunction()/*char x;coutx;if (y = x | y = x)exit(0);*/ex
35、it(0);/-print pathvoid printpath()char buffer50;getcurrentdirectory(50,buffer); /获取当前路径并输出coutbuffer;/-cd命令查询当前目录:get pathvoid getpath()char buffer150;getcurrentdirectory(50,buffer1);coutbuffer1;/=int main()/coutprintheadhelp;coutmicrosoft windows 版本 6.1.7600n;cout版本所有 2009 microsoft corporation。保留所
36、有权利。nendl;handle hfile; /创建文件句柄hfile = :createfile(windows_unix.exe,generic_read,file_share_read,null,open_always,file_attribute_normal,null); /创建文件,设定名称为windows_linux.exeprintpath();string *str = new string10; /声明字符串数组,用于接受用户输入的字符形式的命令char ch;int count = 0; /记录输入字符形式命令的个数int disc;while (1)int strco
37、unt = 0;disc = 0;for (int i = 0; i 10; i+)stri = ;ch = getchar(); /读入命令字符,进行分析while (ch != n)disc = 1;if (ch != )while (ch != n) & (ch != )strstrcount = strstrcount + ch;ch = getchar();strcount+;if (ch = n)goto disc;ch = getchar();if (disc = 0) /什么也不输入,则继续返回当前路径printpath();disc:if (str0 = ls-help)ls
38、helpfunction();printpath();else if (str0 = ls)lsfunction(str,strcount);else if (str0 = cat-help)cathelpfunction();printpath();else if (str0 = cat)catfunction(str,strcount);else if (str0 = cp-help)cphelpfunction();printpath();else if (str0 = cp) /cp copyfile()cpfunction(str,strcount);else if (str0 =
39、mv-help)mvhelpfunction();printpath();else if (str0 = mv) /mv movefile()mvfunction(str,strcount);else if (str0 = md-help)mdhelpfunction();printpath();else if (str0 = md) /md createdirectory()mdfunction(str,strcount);else if (str0 = rd-help)rdhelpfunction();printpath();else if (str0 = rd |str0 = rmdir
40、) /rmdir removedirectory()rdfunction(str,strcount);else if (str0 = cd-help)cdhelpfunction();printpath();else if (str0 = cd) /cd getcurrentdirectory();setcurrentdirectory()cdfunction(str,strcount);else if (str0 = sort-help)sorthelpfunction();printpath();else if (str0 = sort)sortfunction(str,strcount);e
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 抚州幼儿师范高等专科学校《数字逻辑设计》2023-2024学年第二学期期末试卷
- 儿童歌唱表演AI应用行业跨境出海项目商业计划书
- 体育健康与运动康复AI应用企业制定与实施新质生产力项目商业计划书
- 光伏一体化建筑施工规范企业制定与实施新质生产力项目商业计划书
- 非遗传承研学游企业制定与实施新质生产力项目商业计划书
- 企业大学AI应用企业制定与实施新质生产力项目商业计划书
- 线上线下同步促销行业深度调研及发展项目商业计划书
- 2024年五年级数学上册第九单元探索乐园第2课时密铺教案冀教版
- 《电能转化为化学能-电解》第二课时学案2
- 十五五护理服务事业发展规划
- 我们毕业啦毕业季通用模板课件
- 小升初数学复习八(平面图形)讲义课件
- 水处理间制度
- (完整版)基建建设工程流程图
- 公司金融课件(完整版)
- 《我做了一项小实验》教学设计公开课
- 公务员工资套改和运行案例
- 生物质能发电技术论文
- 哥尼斯堡七桥问题PPT课件
- 总包(消防)管理方案
- 1.2平面曲线的曲率ppt课件
评论
0/150
提交评论