操作系统课程设计报告 文件访问接口设计.doc_第1页
操作系统课程设计报告 文件访问接口设计.doc_第2页
操作系统课程设计报告 文件访问接口设计.doc_第3页
操作系统课程设计报告 文件访问接口设计.doc_第4页
操作系统课程设计报告 文件访问接口设计.doc_第5页
已阅读5页,还剩40页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

课程设计说明书 设计名称 操作系统课程设计操作系统课程设计 题 目 文件访问接口设计文件访问接口设计 学生姓名 陈小浪 专 业 计算机科学与技术 班 级 12 级 1 班 学 号 2012314118 指导教师 任朝晖 日 期 2014 年 9 月 15 日 佛山科学技术学院课程设计用纸 课程设计任务书 计算机科学与技术 专业 年级 班 一 一 设计题目设计题目 文件访问接口设计 二 二 主要内容主要内容 利用 C 语言设计 具体包括 1 基本文件内容输入 2 基本文件内容输出 3 创建文件 4 打开文件 5 关闭文件 6 文件缓冲区管理 7 文件句柄管理 8 读顺序文件 9 写顺序文件 10 读随机文件 11 写随机文件 12 文本文件操作验证程序 上述功能由两部分程序验证 中断驻留程序和验证程序 首先运行中断驻留程序 然后运行验证 程序得到预期结果 三 三 具体要求具体要求 本设计的目的是通过 BIOS 调用设计简单的文件访问接口 使学生掌握程序接口的设计方法 要求学生在熟悉比 BIOS DOS 操作系统的中断接口及程序接口的基础上 利用 C 语言设计简单的文 件访问接口 最后通过程序验证接口的正确性 四 四 进度安排进度安排 依照教学计划 课程设计时间为 2 周 1 要求讲解 资料查找 系统分析 概要设计 2 天 2 系统详细设计 功能设计 2 天 3 算法实现 编程调试 5 天 4 4 功能演示 资料整理 课程设计说明书编写 1 天 五 五 完成后应上交的材料完成后应上交的材料 课程设计说明书纸质文档 六 六 总评成绩总评成绩 指导教师指导教师 签名日期签名日期 年年 月月 日日 系系 主主 任任 审核日期审核日期 年年 月月 日日 佛山科学技术学院课程设计用纸 目 录 一 程序概述 1 1 1 完成的任务 1 1 2 解决的问题 1 二 概念原理 1 2 1 基本概念 1 2 2 基本原理 2 三 总体设计 2 3 1 实现方法 2 3 2 技术路线 2 四 详细设计 2 4 1 主要函数 2 4 2 引用函数 3 五 完成情况 3 六 使用说明 3 七 设计总结 4 7 1 系统特色 4 7 2 经验教训 5 7 3 实践感受 5 参考资料 6 附 录 7 佛山科学技术学院课程设计用纸 1 一 程序概述一 程序概述 1 11 1 完成的任务完成的任务 本设计要求编写一个简单的文件访问接口设计 利用 C 语言 DOS BIOS 中断调用进行设计 主要完 成要求中所提到的功能如 创建文件 删除文件 打开文件 关闭文件 基本文件内容输入 基本文件内 容输出 读顺序文件 写顺序文件 文本文件操作验证程序 文件缓冲区管理 的实现 1 21 2 解决的问题解决的问题 在设计过程主要遇到了以下的问题 一是关于中断的理解 二是在理解了中断的意义之 后 进行中断函数如 int86 int86x intdos intdos 等函数的调用不是很清晰 解决的过程 通过与同学讨论 在网上查阅了相关的书籍和学过的课本 如 C 高级实用 设计 以及 80 x86 汇编语言程序设计 之后 便有了比较清晰的思路 有关函数的调用参 数的设计 基本上是基于这些 结构体 WORDREGS BYTEREGS SREGS 联合体 REGS 文件属性 字节 以及汇编语言中 int 21H dos 系统功能调用中中断类型 主要是 21H 以及调用功能号 的查询和设置 下面主要介绍上述提及的几个结构体跟联合体 以字作为单位的寄存器所组合的结构体 Struct WORDREGS Unsigned int ax bx cx dx si di cflag flags 以字节作为单位的寄存器做组合的结构体 Struct BYTEREGS Unsigned char al ah bl bh cl ch dl dh 由上述两个结构体所组合的共用体 联合体 Union REGS Struct WORDREGS x Struct BYTEREGS h 由段寄存器组合的结构体 Struct SREGS Unsigned int es cs ss ds 二 二 概念原理概念原理 2 12 1 基本概念基本概念 中断中断 中断 顾名思义 是指当出现需要时 CPU 暂时停止当前程序的执行转而执行处理新情况的程序和 执行过程 即在程序运行过程中 系统出现了一个必须由 CPU 立即处理的情况 此时 CPU 暂时中止 程序的执行转而处理这个新的情况的过程就叫做中断 本课题中涉及的为 dos 中断跟 bios 中断 文件访问接口文件访问接口 所谓访问接口 实际上即为用户通过 dos 状态下的提示 键入相关命令后 作为访问相关文件操作 的中介 即类似一个中转站 而系统同时也需要在响应了用户键入的命令后执行预先编写好的相应程序 佛山科学技术学院课程设计用纸 2 并将程序的执行结果通过中介 即文件访问接口 输出给用户 而事实上在系统响应一次用户的命令时 系统进行了一次 IO 中断 中断驻留程序中断驻留程序 中断驻留程序 指的是当加载进内存的程序执行完毕后 依然能够保存产生的临时数据跟临时状态 而在下一次调用时继续执行 验证程序验证程序 本课题的验证程序 指的是 当用 dos bios 中断调用编写好相关用于文件访问的函数并执行之后 用 C 语言高级的函数如 fopen fprintf fgetc fclose 等函数来验证上述编写的访问函数是否可 行 本课题中用 fopen fclose 来验证用 dos 中断调用所编写的函数 CloseFile CreateFile 和 CloseFile 用 fgetc fprintf 等函数来验证用 dos 中断调用所编写的 WriteToFile 和 ReadFromFile 函数 除此之外 像 ftell fseek 等的验证是同样的道理 只需基于上述由 dos bios 中断调用所编写的函数 系统调用系统调用 系统调用 顾名思义 说的是操作系统提供给用户程序调用的一组 特殊 接口 用户程序可以通 过这组 特殊 接口来获得操作系统内核提供的服务 比如用户可以通过文件系统相关的调用请求系统 打开文件 关闭文件或读写文件 可以通过时钟相关的系统调用获得系统时间或设置定时器等 从逻辑上来说 系统调用可被看成是一个内核与用户空间程序交互的接口 它好比一个中间人 把 用户进程的请求传达给内核 待内核把请求处理完毕后再将处理结果送回给用户空间 2 22 2 基本基本原理原理 本课题的运行结果 首先是在运行开始时给定了 10 个选择开关 供用户选择 每当接收一次用户 的选择时 系统将进行一次的 IO 中断 之后执行相应的中断服务程序 在这里是指由 dos bios 中断调用 编写好的函数 调用结束时 将临时结果保存 并退出中断 继续响应用户的选择 直到用户选择了退 出 如下图所示 三 总体设计三 总体设计 3 13 1 实现方法实现方法 程序通过选择开关 switch case 将用 dos bios 调用编写的函数组合起来供用户做出 佛山科学技术学院课程设计用纸 3 选择 在对应处理用户的选择编写的函数中 主要的核心是 dos 功能中断调用函数的编写 其中包括中断类型号 中断功能调用号等的设置 以及响应用户选择后中断服务程序的编写 另外 可以通过参看当前工作目录下的文件信息或者通过 Validate 开头的相关函数进 行程序运行结果的验证 3 23 2 技术路线技术路线 整个程序的设计流程 围绕着 bios dos 功能中断调用这一主线 编写好相关文件操作函数 在响应 用户选择之后 对应执行相关的函数 四 详细设计四 详细设计 4 14 1 主要函数主要函数 Int OperOfSel 用于显示可供用户选择的功能 并提示用户作出相应的功能选择 Void CreateFile char filename 80 用于创建一个新的文件 根据用户输入的文件名进行文件的创建 如果文件创建失败 如 磁盘空间已满或者已经存在该文件 即创建失败 Int DeleteFile char filename 80 用于删除一个文件 如果删除成功 将返回文件代号 否则删除失败 可能是不存在该 文件 Int OpenFile char filename 80 用于打开一个文件 如果打开成功 则返回文件代号 否则打开失败 可能是不存在该 文件 Void CloseFile filename 80 用于关闭一个文件 Void WriteToFile filename 80 用于写顺序文件 基本文件内容的输入 以及文件缓冲区的管理 首先根据用户输入的文 件名打开一个文件 如果存在该文件 则打开成功 开始写入内容 此时继续接受用户输入 的内容 注意 输入直到用户键入回车键即表示输入完毕 此时将输入的内容根据文件缓冲 区管理规则将用户输入的内容进行存储至指定文件名的文件中 Void ReadFromFile filename 80 用于读顺序文件 基本文件内容的输出 以及文件缓冲区的管理 从指定的文件中读取 文件中的内容 并输出 Void ValidateOpenFile char filename 80 用于验证上述文件访问函数编写的正确性 用于验证创建文件 打开文件是否成功 Void ValidateReadFile char filename 80 用于验证上述文件访问函数编写的正确性 用于验证上述中 WriteToFile filename 80 以 及 ReadFromFile filename 80 函数 4 2 引用函数引用函数 Clrscr 用于清空屏幕的作用 五 完成情况五 完成情况 本程序完成了其中的 9 项 能够实现文件的创建 打开 关闭 基本文件内容的输入 输出 文件 缓冲区的管理 以及文本文件的验证程序 写顺序文件 读顺序文件 因为对文件句柄以及写 读随机 文件的理解不是很清晰 故而没有动手实践完成 另外 本程序在 dos 下进行演示 需要根据提示来进行 输入 不允许用户胡乱的输入 不然有可能程序处理不了 即本程序在某种程度上还不是很稳定 安全 佛山科学技术学院课程设计用纸 4 但从理论上的角度上讲 只要操作合理 那么本程序将可以实现对应的功能 六 使用说明六 使用说明 运行成功后进行首页 开始接受用户的选择 接着进行相应功能选项前面对应数字的输入 在这里以 1 5 6 10 为例 其他为同样的道理 1 为创建一个新的文件 表示 test txt 文件已经存在 故而创建失败 查看目录 果然已经存在了 test txt 故而提示创建失败 佛山科学技术学院课程设计用纸 5 再次执行 1 号功能选择 newfile txt 创建成功 查看目录下 果然创建了 newfile txt 佛山科学技术学院课程设计用纸 6 进行 10 号功能的选择 结果将出现清空屏幕的效果 佛山科学技术学院课程设计用纸 7 进行 5 号功能的选择 输入成功 提示输入了多少个字符 上述统计了一下 包括字符 为 63 个 在目录打开此文件 果然是写 入了这些内容 下面进行 6 号功能的演示 佛山科学技术学院课程设计用纸 8 上述的演示结果 正好符合了其中的要求 其他的功能演示也是同样的道理 七 设计总结七 设计总结 7 17 1 系统特色系统特色 在本系统中已初步实现一个可访问的文件接口 能够正常的解析命令并执行 在解析命令方面 采 用中断函数调用以及功能类型号选择设置的形式 达到直接与底层 打交道 的作用 效率高 7 27 2 经验教训经验教训 在编程过程中要多使用库函数中自带的内容 不必另外再去编写已有的功能 这样不仅能节省时间 也能提高程序的可靠性 要多了解库函数 可以阅读相应的帮助文件来获得有用的信息 遇到问题多与 老师同学讨论 可以帮助自己跳出思维定势 7 37 3 实践感受实践感受 每次的课程设计都是对我们所学知识的一个深化 在实践过程中能遇到许多的问题 遇到问题 分 析问题 解决问题 这样对知识的理解得到一个升华 实践过程中学到的都是印象非常深刻的 所以以 后要多参加这样的实践 认真对待每一次机会 本次的课程设计 其实从某种程度上来说 还是挺有难度的 因为 之前对于 C 语言的了解是通过 其高级函数的 如文件的访问中 正是通过其高级函数来访问的 刚开始还不知所措 网上的介绍也很 模糊 根本很难找到有关 dos 中断进行文件访问接口的相关设计 后来在于伙伴的讨论下 知道了 C 高 级实用设计这本书 从次书中受益匪浅 加上 80 x86 汇编语言程序设计 更是增长了自己对于汇编的见 识 从此更加肯定了汇编在底层操纵的作用 而且通过此次的课程设计 认识了讨论的重要性 我个人觉得编码正是如此 如果遇到了一个人难 以解决 那么最好是提出来与伙伴或者同学一同探讨 这不但能直到别人的向想法 更能让自己认识自 己的不足 更有甚者 能够增长自己的见识 佛山科学技术学院课程设计用纸 9 参考资料参考资料 1 计算机操作系统教程 第 2 版 张尧学 史美林 编著 清华大学出版社 2 操作系统实验指导 任爱华 李鹏 刘方毅 清华大学出版社 3 操作系统实验教程 核心技术与编程实例 顾宝根 王立松 顾喜梅 科学出版社 4 80 x86 汇编语言程序设计 沈美明 温冬婵编著 清华大学出版社 5 C 高级实用程序设计 王世元 编著 清华大学出版社 6 C 语言程序设计 谭浩强 编著 清华大学出版社 附录 源代码 include include include include include include The number of type of interrupt define INTER 0 x21 The size of filename define Num 80 the number of characters define CNum 9 Function Of Selection int OperOfSel clrscr printf n n n n Function Of Selection n printf n0 Exit n1 Create a new file n2 Delete a existing file printf n3 Open a existing file n4 Close an existing file printf n5 Input basic contents to existing file 佛山科学技术学院课程设计用纸 10 printf n6 Output basic contents from existing file printf n7 To validate the file is open or not printf n8 To validate the reading contents from file printf n9 To validate the writting contents to file printf n10 Clean the screen printf n n Function Of Selection n int sel printf n Input Your Selction scanf d return sel Create a new file void CreateFile char filename 80 union REGS inregs outregs struct SREGS segregs The function number of create file is 5B inregs h ah 0 x5B Set the segment address and effective address inregs x dx FP OFF filename segregs ds FP SEG filename Set the attribute of file inregs x cx 0 int86x INTER if outregs x ax 2 printf n Fail To Create New File n return if outregs x ax 80 佛山科学技术学院课程设计用纸 11 printf n Fail to create file s The file has benn existed n filename return printf n Create New File s Successfully The File s Attribute is d n filename outregs x cx printf The FileCode is d n outregs x ax Delete a exist file int DeleteFile char filename 80 union REGS inregs outregs struct SREGS segregs The function number of create file is 41 inregs h ah 0 x41 inregs x dx FP OFF filename segregs ds FP SEG filename intdosx int result outregs x ax return result Open an existing file int OpenFile char filename 80 union REGS inregs outregs struct SREGS segregs int result 佛山科学技术学院课程设计用纸 12 inregs h ah 0 x3D inregs x dx FP OFF filename segregs ds FP SEG filename Set the way to access file inregs h al 2 int86x INTER You Can Through CreateFile To Know The FileCode as test printf Successfully open file d n outregs x ax if 2 outregs x ax printf n Fail To Open The File s May not exist n filename else printf n Successfully Opening The File s The FileCode Is d n filename outregs x ax result outregs x ax return result Close The Existing File void CloseFile char filename 80 union REGS inregs outregs struct SREGS segregs 佛山科学技术学院课程设计用纸 13 int result int FileCode To Close The File We Should Open The File Firstly The File Should be exist inregs h ah 0 x3D inregs x dx FP OFF filename segregs ds FP SEG filename Set the way to access file inregs h al 2 int86x INTER You Can Through CreateFile To Know The FileCode as test printf Successfully open file d n outregs x ax if 2 outregs x ax printf n Fail To Open The File s May not exist n filename else printf n Successfully Opening The File s The FileCode Is d n filename outregs x ax result outregs x ax if 2 result printf n Open the file s Failly It may not exist n filename printf n Fail to close the file s It may not exist n filename else printf n Open the file s Successfully Now the file will be close n filename FileCode outregs x ax 佛山科学技术学院课程设计用纸 14 inregs h ah 0 x3E inregs x bx FileCode int rel intdos printf n Close File s Successfully rel d n filename rel Input Contents To Existing File void WriteToFile char filename 80 union REGS inregs outregs struct SREGS segregs int result int FileCode char WriteContents CNum inregs h ah 0 x3D inregs x dx FP OFF filename segregs ds FP SEG filename inregs h al 2 int86x INTER result outregs x ax if 2 result printf n Can not input contents to file s It may not exist n filename 佛山科学技术学院课程设计用纸 15 else printf n Open the file s Successfully Now the file will be close n filename Very Important Here To Abosrb The Enter KeyCode getchar printf n n Input The Writting Contents n gets WriteContents printf WriteContents s n WriteContents int CharNum 0 i 0 int i 0 while WriteContents i 0 CharNum i int count 0 printf CharNum d i d n CharNum i printf i d n i int temp 0 int sumChar 0 for int i 0 i CNum 1 i WriteContents i getchar WriteContents i if count 1 佛山科学技术学院课程设计用纸 16 WriteContents i temp i count 0 scanf c if WriteContents i n printf i d n i break if WriteContents i n end if i CNum 1 getchar printf Hello World n return FileCode result inregs h ah 0 x40 inregs x dx FP OFF WriteContents inregs x dx FP OFF WriteContents segregs ds FP SEG WriteContents inregs x bx FileCode inregs x cx i 佛山科学技术学院课程设计用纸 17 printf inregs x cx d n inregs x cx int86x INTER intdosx printf Now The Ax d n outregs x ax printf inregs x bx d n inregs x bx printf Hello World n temp WriteContents i count count 1 i 1 sumChar outregs x ax if i 8 end printf c WriteContents i end for circle char TempContents 8 for int k 0 k i k TempContents k WriteContents k printf n n the rest of the contents of file s are listed below n filename printf WriteContents s n WriteContents printf WriteContents 0 c WriteContents 1 c n WriteContents 0 WriteContents 1 for int j 0 j i j printf c WriteContents j 佛山科学技术学院课程设计用纸 18 printf n printf end for circle i d n i printf WriteContents s i d n WriteContents i printf i d n i for int j 0 j i j printf c WriteContents j printf n FileCode result inregs h ah 0 x40 inregs x dx FP OFF WriteContents segregs ds FP SEG WriteContents inregs x bx FileCode inregs x cx i printf inregs x cx d n inregs x cx int86x INTER intdosx sumChar outregs x ax printf n n The number of contents you have write to file are d n sumChar printf Now The Ax d n outregs x ax printf inregs x bx d n inregs x bx 佛山科学技术学院课程设计用纸 19 printf i d n i Read Contents From Existing File void ReadFromFile char filename 80 union REGS inregs outregs struct SREGS segregs int result char ReadContents CNum 1024 inregs h ah 0 x3D inregs x dx FP OFF filename segregs ds FP SEG filename inregs h al 2 intdosx result outregs x ax if 2 result printf n Can not read contents from file s The file may not exist n filename else printf n Now I ll Read Contents From File s n filename inregs x bx result inregs h ah 0 x3F 佛山科学技术学院课程设计用纸 20 printf d n inregs x bx inregs x dx FP OFF ReadContents segregs ds FP SEG ReadContents inregs x cx 1024 intdosx printf Real Number Of Read Characters in file s d n filename outregs x ax printf ReadContents s n ReadContents printf n The Contents Of File s Are Listed Below n filename for int i 0 i outregs x ax i printf c ReadContents i printf n for int i 0 i 1024 i printf c ReadContents i if ReadContents i 0 break int i 0 while ReadContents i NULL i printf i d n i 佛山科学技术学院课程设计用纸 21 for int j 0 j i 2 j printf c ReadContents j printf n validate function one open file after create one file you can validate the file is exist or not void ValidateOpenFile char filename 80 FILE fp fp fopen filename r if fp printf n Open file s Failly fail to validate open file function n filename return else printf n Open file s Successfully success to validate open file function n filename fclose fp validate function two read file after writting contents to one file you can 佛山科学技术学院课程设计用纸 22 validate the contents whether it has been written to it or not void ValidateReadFile char filename 80 FILE fp fp fopen filename r if fp printf n Can not read contents from file s It may not exist n filename return else int count 0 printf n Read contents from file s successfully The below are the contents n filename char ch while ch fgetc fp EOF count printf c ch while end printf n printf n The total number of contents of the file s are d n filename count else end fclose fp 佛山科学技术学院课程设计用纸 23 Main Function int main clrscr char CreateFileName Num char DeleteFileName Num char OpenFileName Num char CloseFileName Num char WrittingFileName Num char ReadingFileName Num char ValidateOpenFileName Num char ValidateReadFileName Num int sel printf Your Selection Is d n sel while sel 0 do sel OperOfSel switch sel case 0 printf Select 0 Exit n printf n Exit the system n exit 0 break case 1 printf Select 1 n printf n Selection Of Creating A NewFile n printf n Input the name of file to create scanf s CreateFileName CreateFile CreateFileName break 佛山科学技术学院课程设计用纸 24 case 2 printf Select 2 n printf n Selection Of Deleting A ExistingFile n printf n Input the name of existing file to delete scanf s DeleteFileName printf DeleteFileName is s DeleteFileName int RelOfDel DeleteFile DeleteFileName if 0 RelOfDel printf n The File s has been delete successfully n DeleteFileName else printf n Can not delete the file s It may not be exist n DeleteFileName break case 3 printf n The Selection Of Opening an Existing File n printf n Input the name of existing opening file scanf s OpenFileName printf nOpenFileName s n OpenFileName int RelOfOpenFile OpenFile OpenFileName if 2 RelOfOpenFile printf n Fail To Open The File s May not exist n OpenFileName else printf n Successfully Opening The File s The FileCode Is d n OpenFileName outregs x ax printf n Successfully Opening The File s n OpenFileName 佛山科学技术学院课程设计用纸 25 break case 4 printf n The Selection Of Closing an Existing File n printf n Input The Name Of Closing File scanf s CloseFileName printf The CloseFileName s n CloseFileName CloseFile CloseFileName break case 5 printf n The Selection Of Writting Basic Contents To File n printf Input The Name Of Writting File scanf s WrittingFileName printf WrittingFileName s n WrittingFileName WriteToFile WrittingFileName break case 6 printf n The Selection Of Reading Basic Contents From File n printf Input The Name Of Reading File scanf s ReadingFileName printf ReadingFileName s n ReadingFileName ReadFromFile ReadingFileName break printf n7 To validate the file is open or not printf n8 To validate the writting contents to file printf n9 To validate the reading contents from file case 7 佛山科学技术学院课程设计用纸 26 printf n The Selection Of validating the file is open or not n printf n Input the filename to validate the open file function scanf s ValidateOpenFileName ValidateOpenFile ValidateOpenFileName break case 8 printf n The Selection Of validating writting contents to file n break case 8 printf n The Selection Of validating reading contents from file n printf n Input the filename to validate the reading file function scanf s ValidateReadFileName ValidateReadFile ValidateReadFileName break case 10 clrscr break default printf n Input Illegal Please Re Input The Aboved Number n break while sel 0 return 0 佛山科学技术学院课程设计用纸 27 七 设计总结七 设计总结 7 17 1 系统特色系统特色 在本系统中已初步实现一个完整命令处理器的功能 能够正常的解析命令并执行 在解析命令方面 采用指针加数组的形式 既可以节约内存资源 又可以自动扩充命令参数 7 27 2 经验教训经验教训 在编程过程中要多使用库函数中自带的内容 不必另外再去编写已有的功能 这样不仅能节省时间 也能提高程序的可靠性 要多了解库函数 可以阅读相应的帮助文件来获得有用的信息 遇到问题多与 老师同学讨论 可以帮助自己跳出思维定势 7 37 3 实践感受实践感受 每次的课程设计都是对我们所学知识的一个深化 在实践过程中能遇到许多的问题 遇到问题 分 析问题 解决问题 这样对知识的理解得到一个升华 实践过程中学到的都是印象非常深刻的 所以以 后要多参加这样的实践 认真对待每一次机会 佛山科学技术学院课程设计用纸 28 参考资料参考资料 1 计算机操作系统教程 第 2 版 张尧学 史美林 编著 清华大学出版社 2 操作系统实验指导 任爱华 李鹏 刘方毅 清华大学出版社 3 操作系统实验教程 核心技术与编程实例 顾宝根 王立松 顾喜梅 科学出版社 4 C 编程思想 Bruck 著 侯捷译 机械工业出版社 5 C 语言程序中清除键盘缓冲区的方法 杨长虹 益阳职业技术学院学报 佛山科学技术学院课程设计用纸 29 附附 录录 include include include include include include include 定义全局变量 char root dir 3 char pre dir 255 char cmd line 255 char curuser 10 struct userinf char username 10 char userpass 10 函数申明 void init int login int getcmd void dir void cd void clear void newdir void deldir void del void copy void cut void account void help main init while 1 消息循环 switch getcmd case 0 help 佛山科学技术学院课程设计用纸 30 break case 1 dir break case 2 cd break case 3 newdir break case 4 deldir break case 5 del break case 6 copy break case 7 cut break case 8 account break void init 程序初始化 if login 0 exit 0 strcpy pre dir C 设定当前目录 clear 清屏 printf S Shell Above Windows XP Ver 1 0 n printf C Copyright 2007 stars 625 n n getchar 清空缓冲区 int login 程序登陆 char name 10 char pass 10 int logintime 3 佛山科学技术学院课程设计用纸 31 FILE fp struct userinf inf while logintime 0 登陆错误超过三次自动退出 printf Login scanf s name printf Password scanf s pass if fp fopen inf dll r NULL printf Can t open inf dll file n printf Press any key to exit getch exit 0 while fread if strcmp inf username name 0 if strcmp inf userpass pass 0 strcpy curuser inf username clear return 1 else printf Login error Press any key to relogin n getch clear else printf The user is not exist Press any key to relogin n getch clear logintime printf Login error above three times Press any key to exit getch return 0 佛山科学技术学院课程设计用纸 32 int getcmd 获得命令 int i 0 j 0 k 0 char buf 255 printf s pre dir 打印提示符 fgets buf 255 stdin cmd line j calloc 255 sizeof char while buf i n k else cmd line j 1 calloc 255 sizeof char k 0 j i c

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论