文件管理系统源代码
- 格式:doc
- 大小:110.50 KB
- 文档页数:24
知识库管理系统php源代码#include<stdio.h>#include<string.h>#include<stdlib.h>#include<conio.h>#include<malloc.h>#include<time.h> /*所使用的头文件*/typedef struct /*时间结构体定义*/{int hour;int minute;}TIME;typedef struct worker /*结构体定义*/{char id[10];char name[10];TIME time[20];struct worker *next;}worker;int menu_select(); /*主菜单*/void welcome(); /*欢迎界面*/void createInfo(); /*新建职工信息*/void createRec(); /*录入考勤信息*/void listRec(); /*浏览当天考勤信息*/ void searchRec(); /*/查询考勤信息*/void saveRec(); /*保存所有信息*/void deleteRec(); /*删除考勤信息*/void modifyRec(); /*修改考勤信息*/void loadRec(); /*加载文件信息*/void resetPassword(); /*重设密码*/int fun(); /*判断输入选择是否正确*/worker *head=NULL; /*链表头指针head*/writeinfo_flag=0; /*信息保存标记*/char password[16]="888888"; /*初始密码*/struct tm *timeinfo;int main() /*主函数*/{char s[16];welcome(); /*欢迎界面*/loadRec(); /*加载文件信息*/printf("\n提示:\n\n"); /*进入系统密码管理*/printf("\t\t\t\n\n\n\n\n请输入密码,进去系统(密码不超过15个字符):"); scanf("%s",s);while(strcmp(password,s)!=0){printf("\n密码错误,请重新输入:");scanf("%s",s);}system("cls");for(;;) /*菜单循环*/{switch(menu_select()){case 0:system("cls");createInfo();break;case 1:system("cls");createRec();break;case 2:system("cls");listRec();break;case 3:system("cls");searchRec();break;case 4:system("cls");deleteRec();break;case 5:system("cls");modifyRec();break;case 6:system("cls");saveRec();break;case 7:system("cls");resetPassword();break;case 8:system("cls");if(writeinfo_flag==1)saveRec();return 0; default:{printf("\n 选择错误,请按回车键返回后,重新输入(0~8)!"); getchar();getchar();system("cls");break;}}}return 0;}/*选择菜单*/int menu_select(){worker *p=head;int c,k;time_t nowtime;time( &nowtime );timeinfo = localtime( &nowtime );printf("\t\t**************选择菜单**************\t");/*在菜单中显示当前时间*/if(timeinfo->tm_wday==0){printf("时间:星期天");printf(" %d:%d",timeinfo->tm_hour,timeinfo->tm_min);}elseprintf("时间:星期%d %d:%d",timeinfo->tm_wday,timeinfo->tm_hour,timeinfo->tm_min);printf("\n---------------------------------------------------------------------------");printf("\t\t\t0.新建职工信息\n");printf("\t\t1.录入考勤信息\n");printf("\t\t2.浏览考勤信息\n");printf("\t\t3.查询考勤信息\n");printf("\t\t4.删除考勤信息\n");printf("\t\t5.修改考勤信息\n");printf("\t\t6.保存所有信息\n");printf("\t\t7.重设密码\n");printf("\t\t8.退出(退出后信息会自动保存在磁盘中)\n\t\t(任何情况下按Ctrl+C退出程序)\n");printf("\n---------------------------------------------------------------------------");printf("\n\n 请输入您的选择(0~8):");scanf("%d",&c);if(timeinfo->tm_wday==0&&p!=NULL) /*每周周日所有考勤信息初始化*/ {for(k=0;k<20;k++){p->time[k].hour=88;p->time[k].minute=88;}}return c;}void loadRec() /*从磁盘导入信息*/{worker *rear,*p,*pre;FILE *fp,*key;int i,pos=0;key=fopen("key.txt","r");if(key!=NULL){fscanf(key,"%s",password);fclose(key);}fp=fopen("workerRec.txt","r");if(fp!=NULL){fseek(fp, 0, SEEK_END); /*指针移到文件末尾*/pos= ftell(fp);}if(fp==NULL||0 == pos) /*打开职工信息文件和密码文件*/{printf("\n\n\n\n\n\n\t\t提示:\n\n\t\t数据库中没有职工信息,文本为空或文件不存在!\n");printf("\n\t\t请按回车键进入主菜单新建职工信息^_^\n");getchar();system("cls"); /*清屏*/return;}fseek(fp, 0, SEEK_SET); /*指针移到文件开头*/while(!feof(fp)) /*fp不指向文件末尾*/{p=(worker*)malloc(sizeof(worker)); /*开辟一个新单元*/fscanf(fp,"%s%s",p->id,p->name);for(i=0;i<20;i++)fscanf(fp,"%d%d",&p->time[i].hour,&p->time[i].minute);if(head==NULL){head=p;pre=p;rear=p;}else{rear->next=p;pre=rear;rear=p;}}pre->next=NULL;fclose(fp); /*关闭文件*/ return;}。
程序设计综合训练<图书馆管理系统>设计报告院系:材料科学与工程学院专业班级:材料成型一班*名:***学号: ***********指导老师:肖老师一、程序功能简介图书排序功能1)按图书编号排序可以按图书编号的大小排序,显示到屏幕上。
(从小到大)2)按图书出版时间排序可以按图书出版时间的前后排序,显示到屏幕上。
(从近到远)3)按图书价格排序可以按图书价格的贵宜排序,显示到屏幕上。
(从便宜到贵)4)按图书书名排序可以按图书书名字符的大小排序,显示到屏幕上。
(从小到大)5)按图书作者名排序可以按图书作者名字符的大小排序,显示到屏幕上。
(从小到大)二、本人完成的主要工作图书排序功能(排序比较简单只要做出来一个,其他都和它雷同。
)三、设计方案1.设计分析;1)序功能简介:s2)各个功能流程图1、按图书编号排序2、按图书出版时间排序3、按图书价格排序4、按图书书名排序5、按图书作者名排序2. 操作方法简介; 1)主面板输入密码9进入系统。
输入排序的功能序号5是 输入y/n 进,输入n 的话返回到主菜单Y/n是(y)显示排序否(n )按Enter2)主菜单按4进入排序功能。
2)排序功能目录3)选择功能(比如3)按价格的大小排序3.实验结果(包括输入数据和输出结果)四、设计体会在期末课程设计中,我们所选择的是设计一个图书管理系统,这对我们来说是一次尝试与创新的过程,也可以说是一个挑战的过程,毕竟以前没有作过,缺少经验。
现在利用自己学到的知识设计并制作一个图书管理系统,这本身就是一个知识转化为生产力的过程,所以大家都很兴奋,不同程度的投入了很高的热情与努力。
在具体的设计与实施中,我们看到并感受到了一个管理系统从无到有的过程,对具体的设计步骤、思路、方法、技巧都有了进一步的了解,并感受深刻。
在设计中我们基本能按照规范的方法和步骤进行,首先对现有的系统进行调查,并查阅有关资料,最后确定设计方案,然后设计并制作,实施过程中我们深刻的认识到认真执行管理系统软件标准的重要性,我们由于对管理系统软件相关的标准和规范不太了解,缺少行为操作准则,所以在设计中手法比较生硬,主与次也没能很好把握住,这些方面通过这次我们都要加强了解。
1 源代码管理 (2)1.1 总那末 (2)1.2 源代码完整性保障 (2)1.3 源代码的授权访问 (3)1.4 代码版本管理 (3)1.5 源代码复制和传播 (5)1.6 系统测试验收流程 (6)系统初验 (6)试运行 (6)系统终验 (7)应用系统验收标准 (9)文档评审通过标准 (9)确认测试通过标准 (10)系统试运行通过标准 (10)1、为保障公司源代码和开辟文档安全不至于泄露,保证源代码的完整,明确源代码控制管理流程,特制定此管理方法。
2、本方法合用于所有涉及接触源代码的各部门各岗位。
所涉及部门都必须严格执行本管理方法。
3、源代码直接控制管理部门为技术开辟部。
4、本方法管理重点在于控制管理源代码的完整性,不被非授权获取,不被非授权复制和传播。
5、本方法所指源代码不仅限于公司开辟人员自行编写实现功能的程序代码,而且还包括相应的开辟设计文档及用于支撑整个系统运行所必须具备的第三方软件、控件和其它支撑库等文件。
1、所有软件的源代码文件及相应的开辟设计文档均必须及时参加到指定的源代码效劳器中的指定库中。
2、我们研发的产品软件运行所必须的第三方软件、控件和其它支撑库等文件也必须及时参加源代码效劳器中指定的库中。
3、软件开始编写或者调整代码之前,其相应的设计文档和代码必须先从相应的 SVN 库进行SVNUpdate 操作。
软件编码或者功能调整结束测试正确无误后,相应的源代码必须进行 SVNCommit 操作,在最终进行 SVNCommit 操作之前需要再进行 SVNUpdate 操作,查看是否有冲突产生,如果有冲突产生需要和冲突相关人一并解决冲突。
1、源代码效劳器对于共享的 SVN 库的访问建立操作系统级的,基于身份和口令的访问授权。
第十条在 SVN 库中设置用户,并为不同用户分配不同的,适合工作的最小访问权限。
要求连接 SVN 库时必须校验 SVN 中用户身份及其口令。
在SVN 库中要求区别对待不同用户的可访问权、可读权、可写权。
linux实训报告总结Linux是一种开放源代码的操作系统,它可以在各种计算机硬件设备和移动设备上运行。
Linux是以Unix为基础的操作系统,其内核是由Linus Torvalds于1991年创建的。
Linux以其稳定性、可靠性、安全性、免费和自由等优点受到了广泛的欢迎和应用。
本文将介绍Linux实训的相关内容,包括Linux的基础概念、Linux系统下的文件管理、安装软件、网络设置、权限管理等内容。
同时还将讲述在实际Linux应用场景中我们所遇到的问题和解决方案。
一、Linux的基础概念本次实训,我们首先学习了Linux的基础概念。
Linux的文件系统和Windows有很大的不同,因此我们需要了解Linux的目录结构,包括usr、etc、var等目录下存放的文件和文件夹以及它们的作用。
随后我们学习了如何使用命令行终端,包括常用的命令,如ls、cd、mkdir、rm、cp等。
这些命令是Linux系统管理和操作的基础。
二、Linux系统下的文件管理Linux系统中不仅有命令行终端管理文件,还有图形化界面管理文件。
我们学习了如何创建文件夹、复制、剪切和重命名文件等。
另外,我们还学习了如何查看文件的属性和权限。
这些技能对于系统管理和操作都非常有帮助。
三、安装软件Linux系统中有很多软件可以使用,包括开源软件和商业软件。
我们学习了使用命令行终端和软件包管理器来安装和卸载软件,如yum、rpm等。
同时还学习了从源代码编译安装软件的方法。
四、网络设置在Linux系统中,通过命令行终端可以进行网络设置。
我们学习了如何配置网络接口以及如何进行本地ping和远程ping其他主机。
五、权限管理在Linux系统中,有严格的文件和目录的访问控制机制。
我们学习了如何使用命令行终端进行用户和组的管理,如添加、删除用户或组,并设置各种权限。
这对于系统管理员来说是非常重要的技能。
总结:Linux在各个领域都得到了广泛的应用,这次实训让我们更加深入地了解了Linux操作系统及其特点,掌握了基础的命令行终端和图形界面操作技能,掌握了安装软件和进行网络设置的方法以及权限管理。
进程管理实验报告1. 实验目的:(1)加深对进程概念的理解, 明确进程和程序的区别;(2)进一步认识并发执行的实质;(3)分析进程争用资源的现象, 学习解决进程互斥的方法;(4)了解Linux系统中进程通信的基本原理。
2. 实验预备内容(1)阅读Linux的sched.h源码文件, 加深对进程管理概念的理解;(2)阅读Linux的fork()源码文件, 分析进程的创建过程。
3.环境说明本次实验使用的是win7下的VMWare workstation虚拟机, 安装了ubuntu系统在ubuntu系统下使用code::blocks IDE编写代码并执行程序的4.实验内容:1.进程的创建:(1)实验题目和要求:编写一段程序, 使用系统调用fork() 创建两个子进程。
当此程序运行时, 在系统中有一个父进程和两个子进程活动。
让每一个进程在屏幕上显示一个字符:父进程显示字符“a”, 子进程分别显示字符“b”和“c”。
试观察记录屏幕上的显示结果, 并分析原因。
(2)程序设计说明:参照书上的例子进行设计, 详见源代码(3)程序运行结果截图:(4)程序分析:a,b,c随机出现, 因为父进程与两个子进程之间并没有同步措施, 所以a,b,c随机打印出来, 也就是三个进程的活动次序是随机进行的, 不同的系统可能有不同的进程调度方式。
(5)源程序:#include<sys/types.h>#include<stdio.h>#include<unistd.h>int main(){pid_t pid1,pid2;if((pid1=fork())<0){printf("Fork Failed.\n");exit(-1);}else if((pid1=fork())==0)printf("b\n");else{if((pid2=fork())<0){printf("Fork Failed.\n");exit(-1);}else if((pid2=fork())==0)printf("c\n");else{wait(NULL);printf("a\n");exit(0);}}return 0;}2.进程的控制:要求一:(1)实验题目和要求:修改已经编写的程序, 将每个进程输出一个字符改为每个进程输出一句话, 再观察程序执行时屏幕上出现的现象, 并分析原因。
目录1.SVN客户端使用说明 (1)1.1.安装SVN客户端 (1)1.2.迁出配置库内容 (1)1.3.维护工作文件 (3)1.3.1.增加文件 (3)1.3.2.更新文件 (7)1.3.3.删除文件 (8)1.3.4.修改文件 (8)1.3.5.比较版本差异 (9)1.3.6.撤销更改 (12)1.3.7.锁定和解锁 (12)1.3.8.重命名文件 (12)1.3.9.获取历史文件 (13)1.3.10.检查冲突 (13)1.3.11.解决冲突 (14)1.3.12.忽略无需版本控制的文件 (15)1.3.13.去除SVN标志 (15)1.3.14.查看文件每行的修改信息 (16)1.3.15.重置访问路径 (17)1.3.16.本地路径转换 (17)1.4.浏览版本库 (17)1.5.建立标签 (17)1.6.建立分支 (17)1.7.清除用户名等信息 (18)1.8.统计信息 (19)1.9.SVN数据同步 (22)2.VISUAL STUDIO集成SVN (23)2.1.安装V ISUAL SVN (23)1. SVN客户端使用说明1.1. 安装SVN客户端安装SVN客户端(TortoiseSVN-1.8.7.25475-x64-svn-1.8.9.msi):双击安装包→Next→选中“I accept the terms in the license Agreement”→Next→Install→选中“Show Changelog”→Finish→点击“Yes”按钮重新启动电脑。
SVN客户端的存放位置为:注意:安装SVN客户端后需重启电脑,否则SVN客户端无法正常使用。
可以下载TortoiseSVN的中文语言包,根据向导运行语言包安装程序,重新启动程序后,即可看到中文菜单。
所有的TortoiseSVN命令都是通过windows资源管理器的右键菜单执行。
1.2. 迁出配置库内容1、在本地硬盘上建立一个文件夹“SVN”,并在文件夹“SVN”中建立一个子文件夹(子文件夹为空文件夹),子文件夹的名称可以根据本公司配置库路径下的对应文件夹名称进行定义。
徐家乐1521030实验三Linux⽂件系统及⽂件管理实验三1 实验名称:Linux⽂件系统及⽂件管理2 实验⽬的通过本实验了解Linux操作系统⽀持的多⽂件系统,并熟练掌握Linux⽂件管理⽅法,使实验者具备初步的Linux操作系统⽂件管理能⼒,包括:2.1 掌握磁盘管理能⼒2.2 掌握⽬录与⽂件管理能⼒2.3 掌握⽂件归档与压缩能⼒2.4 掌握RPM软件包管理能⼒3 实验环境3.1Windows XP下基于“VMware Workstation”虚拟机环境的Red Hat Enterprise Linux Server 5系统。
3.2将主机改为具有个⼈学号后3位特征的名称。
4实验要求、步骤及结果4.1掌握与磁盘管理相关的shell命令的使⽤。
【操作要求1】查看系统已挂载⽂件系统信息;截取/dev下某⼀挂载设备(/dev/sda2)的具体信息,解释其含义。
查看该挂载点(/)的详细信息;访问该挂载点(/);查看该挂载点(/)上⽂件的详细信息;返回个⼈⽤户主⽬录。
【操作步骤1-查看挂载信息】【截取挂载相关信息及注解】【操作步骤2-查看挂载点】【操作步骤3-访问】【操作步骤4-查看⽂件】【操作要求3】分页查看/etc⽬录中⽂件信息;将/etc⽬录中fstab⽂件复制到当前⽬录下;显⽰fstab 的内容;显⽰fstab的访问权限;增加同组⽤户对fstab⽂件写的权限。
【操作步骤1-查看/ect】【操作步骤2-复制⽂件】【操作步骤3-显⽰⽂件内容】【操作步骤4-显⽰⽂件权限】【截取访问权限-字母表⽰】【转换访问权限-数字表⽰】664【操作步骤5-修改⽂件权限】【截取访问权限-字母表⽰】【转换访问权限-数字表⽰】6644.2掌握⽬录与⽂件管理相关的shell命令的使⽤。
【操作要求1】⽤⼀条命令新建具有如下结构的⽬录树。
注意:⽂件名严格区分⼤⼩写。
【操作要求1】【操作要求2】将M2⽬录重命名为m2;查看m1⽬录的访问权限;减去其它⽤户对m1⽬录的执⾏权。
在此文中,我们将为您介绍20个Python3大型项目开发的源代码,以帮助您了解Python3的应用和实际项目开发。
以下是这20个Python3大型项目开发源代码的详细内容:1. 人脸识别系统- 该项目使用Python3编写,利用OpenCV和Dlib库实现人脸识别功能。
它可以识别图像和视频中的人脸,并进行特征提取和匹配。
2. 文件同步工具- 这个项目使用Python3编写,可以实现不同计算机之间的文件同步。
它可以检测文件的新增、删除和修改,并及时同步到其他设备。
3. 聊天机器人- 该项目利用Python3编写,使用自然语言处理技术和机器学习算法,实现了一个智能聊天机器人。
它可以回答一般性问题,处理用户输入的文本,并给出相应的回复。
4. 数据可视化工具- 这个项目采用Python3编写,利用Matplotlib和Seaborn库实现数据可视化功能。
它可以将数据以图表、图形等形式展现出来,方便用户分析和理解数据。
5. 网络爬虫- 该项目使用Python3编写,利用BeautifulSoup和Requests库实现网络爬虫功能。
它可以抓取网页数据,对数据进行处理和分析,用于各种网页数据的采集和整理。
6. 视频流分析系统- 这个项目利用Python3编写,借助FFmpeg和NumPy库实现对视频流的分析和处理。
它可以提取视频流中的特征,并进行目标识别和跟踪。
7. 在线投票系统- 该项目采用Python3编写,利用Django框架实现在线投票系统。
它可以处理用户投票请求,进行实时统计数据,并生成相应的数据报表。
8. 电流信箱客户端- 这个项目使用Python3编写,利用smtplib和poplib库实现电流信箱客户端功能。
它可以发送、接收和管理电流信箱,支持对邮件进行筛选、归档等操作。
9. 文档管理系统- 该项目利用Python3编写,使用Django框架实现文档管理系统。
它可以上传、下载和管理文档,支持文档的分类、版本管理等功能。
文件管理系统一、实验目的通过设计一个多用户文件系统,了解操作系统中文件的组织与管理,熟悉文件管理所用的数据结构,加深对文件系统内部功能实现过程的理解。
二、实验内容1.用C语言或C++语言设计一个最多包括N个用户的多用户文件系统,约定每个用户最多保存M个文件。
同时限制一个用户在进入系统后,最多打开L个文件。
2.系统应具备一定的健壮性。
即能够检查用户所输入命令的正确性,出错时显示出必要的信息。
另外,对文件需设置必要的保护措施。
3.文件目录结构采用两级目录结构:主文件目录和用户文件目录#include"io.h"#include"conio.h"#include"stdio.h"#include"stdlib.h"#include"malloc.h"#include"string.h"#include"ctype.h"#define N 30 /*用户数*/#define M 20 /*一个用户可保存M个文件*/#define L 5 /*用户只能一次打开L个文件*/typedef struct MFD /*主文件目录*/{char username[100];char password[100];FILE fp; /*文件指针*/}MFD;///////////typedef struct UFD /*用户文件目录*/{char filename[256];char protect; /*保护码*/int length; /*文件长度*/}UFD;//////////typedef struct OFD /*打开文件目录*/{char filename[256];char opencode; /*打开保护码*/int fp; /*读写指针*/}OFD;//////////typedef struct COMM /*命令串*/{char string[256]; /*命令*/struct COMM *next;/*后继指针*/}COMM;////////////MFD mainfd[N]; /*主文件目录数组*/UFD userfd[M]; /*用户文件目录数组*/OFD openfd[L]; /*打开文件目录数组*/////////COMM*command; /*命令串指针*/char username[10];int usernum,savenum,opennum;int workfile;void init();void init_ufd(char *username);/*初始化用户文件目录*/ void mesg(char *str); /*消息*/char *getpass(); /*设置口令函数声明*/ char *getuser(); /*设置用户函数声明*/ COMM *readcommand(); /*读命令串函数声明*/ void login(); /*用户登录*/void logout(); /*用户注销*/void setpass(); /*设置口令*/void create(); /*创建文件*/void mydelete(); /*删除文件*/void myread(); /*读文件*/void myopen(); /*打开文件*/void myclose(); /*关闭文件*/void mywrite(); /*写文件*/void help(); /*帮助*/void dir(); /*列文件目录*/void mycopy(); /*复制文件*/void myrename(); /*重命名文件名*//////////////void main(){init();for(;;){readcommand();if(strcmp(command->string,"create")==0)create();else if(strcmp(command->string,"delete")==0)mydelete();else if(strcmp(command->string,"open")==0)myopen();else if(strcmp(command->string,"close")==0)myclose();else if(strcmp(command->string,"read")==0)myread();else if(strcmp(command->string,"write")==0)mywrite();else if(strcmp(command->string,"copy")==0)mycopy();else if(strcmp(command->string,"rename")==0)myrename();else if(strcmp(command->string,"login")==0)login();else if(strcmp(command->string,"setpass")==0)setpass();else if(strcmp(command->string,"logout")==0)logout();else if(strcmp(command->string,"help")==0)help();else if(strcmp(command->string,"dir")==0)dir();else if(strcmp(command->string,"exit")==0)break;elsemesg("Bad command!");}}///////////////////void init(){FILE *fp;char tempname[20],temppass[20];int i=0;usernum=0;savenum=0;opennum=0;strcpy(username,"");if((fp=fopen("mainfile.txt","r"))!=NULL){while(!feof(fp)){strcpy(tempname,"");fgets(tempname,20,fp);if(strcmp(tempname,"")!=0){fgets(temppass,20,fp);tempname[strlen(tempname)-1]='\0';temppass[strlen(tempname)-1]='\0';strcpy(mainfd[usernum].username,tempname);strcpy(mainfd[usernum].password,tempname);usernum++;}}fclose(fp);}}///////////////////////void init_ufd(char *username)/*初始化用户文件目录*/{FILE *fp;char tempfile[100],tempprot;int templength;savenum=0;opennum=0;workfile=-1;if((fp=fopen(username,"w+"))!=NULL){while(!feof(fp)){strcpy(tempfile,"");fgets(tempfile,50,fp);if(strcmp(tempfile,"")!=0){fscanf(fp,"%c",&tempprot);fscanf(fp,"%d",&templength);tempfile[strlen(tempfile)-1]='\0';strcpy(userfd[savenum].filename,tempfile);userfd[savenum].protect=tempprot;userfd[savenum].length=templength;savenum++;fgets(tempfile,50,fp);}}}fclose(fp);}////////////////////void mesg(char *str){printf("\n %s\n",str);}////////////////////////////char *getuser(){char username[20];char temp;int i;username[0]='\0';for(i=0;i<10;){while(!kbhit());temp=getch();if(isalnum(temp)||temp=='_'||temp==13){username[i]=temp;if(username[i]==13){username[i]='\0';break;}putchar(temp);i++;username[i]='\0';}}return(username);}///////////////////char *getpass(){char password[20];char temp;int i;password[0]='\0';for(i=0;i<10;){while(!kbhit());temp=getch();if(isalnum(temp)||temp=='_'||temp==13){password[i]=temp;if(password[i]==13){password[i]='\0';break;}putchar('*');i++;password[i]='\0';}}return(password);}///////////////COMM *readcommand(){char temp[256];char line[256];int i,end;COMM *newp,*p;command=NULL;strcpy(line,"");while(strcmp(line,"")==0){printf("\nc:\\>");gets(line);}for(i=0;i<=strlen(line);i++){if(line[i]==' ')i++;end=0;while(line[i]!='\0'&&line[i]!=' '){temp[end]=line[i];end++;i++;}if(end>0){temp[end]='\0';newp=(COMM *)malloc(sizeof(COMM *));strcpy(newp->string,temp);newp->next=NULL;if(command==NULL)command=newp;else{p=command;while(p->next!=NULL)p=p->next;p->next=newp;}}}p=command;return(command);}/////////////////////////////void login() /*用户注册*/{FILE *fp;int i;char password[20],confirm[20],tempname[20];if(command->next==NULL){printf("\n User Name:");strcpy(tempname,getuser());}else if(command->next->next!=NULL){mesg("Too many parameters!");return;}elsestrcpy(tempname,command->next->string);for(i=0;i<usernum;i++)if(strcmp(mainfd[i].username,tempname)==0)break; /*从mainfd表中查找要注册的用户*/ if(i>=usernum) /*新用户*/{printf("\n new user account,enter your password twice!");printf("\n Password:");strcpy(password,getpass());/*输入口令且返回之*/printf("\n Password:");strcpy(confirm,getpass()); /*第二次输入口令*/if(strcmp(password,confirm)==0)/*用户数不能超过N*/{if(usernum>=N)mesg("Create new account false!number of user asscount limited.\n login fasle!");else{strcpy(mainfd[usernum].username,tempname);/*把新用户和口令填入mainfd中*/strcpy(mainfd[usernum].password,password);usernum++;strcpy(username,tempname);mesg("Create a new user!\n login success!");init_ufd(username); /*初始化用户文件目录*/fp=fopen("mainfile.txt","w+"); /*把新用户填入mainfile.txt文件中*/for(i=0;i<usernum;i++){fputs(mainfd[i].username,fp);fputs("\n",fp);fputs(mainfd[i].password,fp);fputs("\n",fp);}fclose(fp);}}else{mesg("Create new account false! Error password.");mesg("login false!");}}else{printf("\n Password:");strcpy(password,getpass());if(strcmp(mainfd[i].password,password)!=0)mesg("Login false! Error password.");else{mesg("Login success!");strcpy(username,tempname);init_ufd(username);}}}/////////////////////////void logout() /*用户注销*/{if(command->next!=NULL)mesg("Too many parameters!");else if(strcmp(username,"")==0)mesg("No user login!");else{strcpy(username,"");opennum=0;savenum=0;workfile=-1;mesg("User logout!");}}////////////////////void setpass() /*修改口令*/{int i=0;FILE *fp;char oldpass[20],newpass[20],confirm[20];if(strcmp(username,"")==0)mesg("No user login!");else{printf("\n Old password:");strcpy(oldpass,getpass());for(int i=0;i<usernum;i++){if(strcmp(mainfd[i].username,username)==0)break;}if(strcmp(mainfd[i].password,oldpass)!=0)mesg("Old password error!");else{printf("\n New password:");strcpy(newpass,getpass());printf("\n Confirm password:");strcpy(confirm,getpass());if(strcmp(newpass,confirm)!=0)mesg("Password not change! confirm different.");else{strcpy(mainfd[i].password,newpass);mesg(" Password change !");fp=fopen("mainfile.txt","w+");for(i=0;i<usernum;i++){fputs(mainfd[i].username,fp);fputs("\n",fp);fputs(mainfd[i].password,fp);fputs("\n",fp);}fclose(fp);}}}}////////////////void create(){int i=0;FILE *fp;if(strcmp(username,"")==0)mesg("No user lgoin!");else if(command->next==NULL)mesg("Too few parametets!");else if(command->next->next!=NULL)mesg("Too many parameters!");else{for(i=0;i<savenum;i++){if(strcmp(userfd[i].filename,command->next->string)==0)break;}if(i<savenum)mesg("Error! the file already existed!");else if(savenum>=M)mesg("Error! connot create file! number of files limited!");else{strcpy(userfd[savenum].filename,command->next->string);userfd[i].protect='r';userfd[i].length=rand();savenum++;mesg("Create file success!");fp=fopen(username,"w+");for(i=0;i<savenum;i++){fputs(userfd[i].filename,fp);fputs("\n",fp);fprintf(fp,"%c\n%d\n",userfd[i].protect,userfd[i].length);}fclose(fp);}}}/////////////////void mydelete() /*删除*/{int i=0;int tempsave=0;FILE *fp;if(strcmp(username,"")==0)mesg("No user lgoin!");else if(command->next==NULL)mesg("Too few parametets!");else if(command->next->next!=NULL)mesg("Too many parameters!");else{for(i=0;i<savenum;i++){if(strcmp(userfd[i].filename,command->next->string)==0)break;}if(i>=savenum)mesg("Error! the file not existed!");else{tempsave=i;for(i=0;i<opennum;i++){if(strcmp(command->next->string,openfd[i].filename)==0)break;}if(i>=opennum)mesg("File not open");////////////////////////////////////////////else{if(tempsave==savenum-1)savenum--;else{for(;tempsave<savenum-1;tempsave++){strcpy(userfd[tempsave].filename,userfd[tempsave+1].filename);userfd[tempsave].protect=userfd[tempsave+1].protect;userfd[tempsave].length=userfd[tempsave+1].length;}savenum--;}mesg("Delete file success!");fp=fopen(username,"w+");for(i=0;i<savenum;i++){fputs(userfd[i].filename,fp);fputs("\n",fp);fprintf(fp,"%c\n%d\n",userfd[i].protect,userfd[i].length);}fclose(fp);}}}}//////////////////void myread() /*读*/{int i=0;int tempsave=0;char tempfile[100];if(strcmp(username,"")==0)mesg("No user lgoin!");else if(command->next==NULL)mesg("Too few parametets!");else if(command->next->next!=NULL)mesg("Too many parameters!");elsestrcpy(tempfile,command->next->string);for(i=0;i<savenum;i++){if(strcmp(tempfile,userfd[i].filename)==0)break;}if(i>=savenum)mesg("File not existed!");else{tempsave=i;for(i=0;i<opennum;i++){if(strcmp(tempfile,openfd[i].filename)==0)break;}if(i>=opennum)mesg("File not opened");else{if(userfd[tempsave].length<1000)printf("\n The file size is %d KB",userfd[tempsave].length);else if(userfd[tempsave].length==1000)printf("\n The file size is 1000 KB");elseprintf("\n The file size is %d,%d KB",userfd[tempsave].length/1000,userfd[tempsave].length%1000);mesg("File read");}}}}/////////////////void myopen()/*打开*/{int i=0;int type=0;char tempcode;char tempfile[100];if(strcmp(username,"")==0)mesg("No user login!");else if(command->next==NULL)mesg("Too few parameters!");{strcpy(tempfile,"");tempcode='r';if(strcmp(command->next->string,"/r")==0){tempcode='r';type=1;}else if(strcmp(command->next->string,"/w")==0){tempcode='w';type=1;}else if(strcmp(command->next->string,"/d")==0){tempcode='d';type=1;}else if(command->next->string[0]=='/')mesg("Error! /r/w/d request!");else if(command->next->next!=NULL)mesg("Too many parameters!");elsestrcpy(tempfile,command->next->string);if(type==1){if(command->next->next!=NULL){if(command->next->next->next!=NULL)mesg("Too many parameters!");elsestrcpy(tempfile,command->next->next->string);}elsemesg("Too few parameters!");}if(strcmp(tempfile,"")){for(i=0;i<savenum;i++){if(strcmp(tempfile,userfd[i].filename)==0)break;}if(i>=savenum)mesg("File not existed!");else{for(i=0;i<opennum;i++){if(strcmp(tempfile,openfd[i].filename)==0)break;}if(i<opennum){mesg("File already opened!");if(openfd[i].opencode!=tempcode){openfd[i].opencode=tempcode;mesg("File permission changed!");}}else if(opennum>=L){mesg("Error! connot open file! number of opened files limited!");}else{strcpy(openfd[opennum].filename,tempfile);openfd[opennum].opencode=tempcode;workfile=opennum;opennum++;mesg("File open success!");}}}}}///////////////////////void myclose()/*关闭*/{int i=0;int tempsave=0;char tempfile[100];if(strcmp(username,"")==0)mesg("No user lgoin!");else if(command->next==NULL)mesg("Too few parametets!");else if(command->next->next!=NULL)mesg("Too many parameters!");else{strcpy(tempfile,command->next->string);for(i=0;i<savenum;i++){if(strcmp(tempfile,userfd[i].filename)==0)break;}if(i>=savenum)mesg("File not existed!");else{for(i=0;i<opennum;i++){if(strcmp(tempfile,openfd[i].filename)==0)break;}if(i>=opennum)mesg("File not opened");else{if(i==opennum-1)opennum--;else{for(;i<opennum-1;i++){strcpy(openfd[i].filename,openfd[i+1].filename);openfd[i].opencode=openfd[i+1].opencode;}opennum--;}mesg("Close file success!");}}}}/////////////////////////void mywrite()/*写*/{int i=0;int tempsave=0;char tempfile[100];if(strcmp(username,"")==0)mesg("No user lgoin!");else if(command->next==NULL)mesg("Too few parametets!");else if(command->next->next!=NULL)mesg("Too many parameters!");else{strcpy(tempfile,command->next->string);for(i=0;i<savenum;i++){if(strcmp(tempfile,userfd[i].filename)==0)break;}if(i>=savenum)mesg("File not existed!");else{tempsave=i;for(i=0;i<opennum;i++){if(strcmp(tempfile,openfd[i].filename)==0)break;}if(i>=opennum)mesg("File not opened");else{mesg("File write");int tt=rand();if(userfd[tempsave].length<=1000)printf("\n The file size from %d KB to %d KB",userfd[tempsave].length,userfd[tempsave].length+tt);/* else if(userfd[tempsave].lenght=1000)printf("\n The file size from 1000 KB");*/elseprintf("\n The file size form %d,%d KB to %d,%d KB",userfd[tempsave].length/1000,userfd[tempsave].length%1000,userfd[tempsave].length+tt/10 00,userfd[tempsave].length+tt%1000);userfd[tempsave].length=userfd[tempsave].length+tt;}}}}///////////////////void help()/*帮助*/{static char *cmd[]={"login","setpass","logout","create","open","read","write","close","delete","dir","help","exit","copy","rename"};static char *cmdhlp[]={"aommand format: login [<username>]","command format:setpass","command format:logout","command format:create <filename>","command format:open [/r/w/d] <filename>","command format:read <filename>","command format:write <filename>","command format:close <filename>","command format:delete <filename>","command format:dir [/u/o/f]","command format:help [<command>]","command format:exit","command format:copy <source filename> <destination filename>","command format:rename <old filename> <new filename>"};static char *detail[]={"explain:user login in the file system.","explain:modify the user password.","explain:user logout the file system.","explain:creat a new file.","explain:/r -- read only [deflaut]\n\t /w -- list opened files \n\t /d --read,modify and delete.","explain:read the file.","explain:modify the file.","explain:close the file.","explain:delete the file.","explain:/u -- list the user account\n\t /0 -- list opened files\n\t /f --list user file[deflaut].","explain:<command> -- list the command detail format and explain.\n\t [deflaut] list the command.","explain:exit from the file sysytem.","explain:copy from one file to another file.","explain:modify the file name."};int helpnum=14;int i=0;if(command->next==NULL){mesg(cmdhlp[10]);mesg(detail[10]);mesg("step 1: login");printf("\t if old user then login,if user not exist then create new user");mesg("step 2: open the file for read(/r),write(/w)or delete(/d)");printf("\t you can open one or more files.one command can open one file");mesg("step 3: read,write or delete some one file");printf("\t you can operate one of the opened files.one command can open one file");mesg("step 4: close the open file");printf("\t you can close one of the opened files.one command can open one file");mesg("step 5: user logout.close all the user opened files");printf("\n command list:");for(i=0;i<helpnum;i++){if(i%4==0)printf("\n");printf(" %-10s",cmd[i]);}}else if(command->next->next!=NULL)mesg("Too many parameters!");else{for(i=0;i<helpnum;i++){if(strcmp(command->next->string,cmd[i])==0)break;}if(i>=helpnum)mesg("the command not existed!");else{mesg(cmdhlp[i]);mesg(detail[i]);}}}//////////////////////void dir()/*列目录文件*/{int i=0;int type=0;char tempcode;if(strcmp(username,"")==0)mesg("No user login!");else{if(command->next==NULL){tempcode='f';}else{if(strcmp(command->next->string,"/u")==0){tempcode='u';}else if(strcmp(command->next->string,"/o")==0){tempcode='o';}else if(strcmp(command->next->string,"/f")==0){tempcode='f';}else if(command->next->string[0]=='/')mesg("Error! /u/o/f request!");else if(command->next->next!=NULL)mesg("Too many parameters!");}if('u'==tempcode){printf("list the user account\n");printf("usename\n");for(i=0;i<usernum;i++){printf("%s\n",mainfd[i].username);}}else if('f'==tempcode){printf("list opened files\n");printf("filename length protect\n");for(i=0;i<savenum;i++){printf("%s%s%d%s%s%c\n",userfd[i].filename," ",userfd[i].length,"KB"," ",userfd[i].protect);}}else if('o'==tempcode){printf("list user files\n");printf("filename opencode\n");for(i=0;i<opennum;i++){printf("%s%s%c\n",openfd[i].filename," ",openfd[i].opencode);}}}}/////////////////////////void mycopy()/*复制*/{char sourfile[256],destfile[256];int i=0,j=0,temp=0;FILE *fp;char tempchar;if(strcmp(username,"")==0)mesg("No user lgoin!");else if(command->next==NULL)mesg("Too few parametets!");else if(command->next->next==NULL)mesg("Too few parametets!");else if(command->next->next->next!=NULL)mesg("Too many parameters!");else{strcpy(sourfile,command->next->string);strcpy(destfile,command->next->next->string);for(i=0;i<savenum;i++){if(strcmp(sourfile,userfd[i].filename)==0)break;}temp=i;if(i>=savenum)printf("\n the source file not eixsted!");else{for(i=0;i<opennum;i++){if(strcmp(sourfile,openfd[i].filename)==0)break;}if(i>=opennum)printf("\n the source file not opened!");else{for(j=0;j<opennum;j++){if(strcmp(destfile,openfd[i].filename)==0)break;}if(j<opennum)mesg("Error! the destination file opened,you must close it first.");else{for(j=0;j<savenum;j++){if(strcmp(destfile,userfd[i].filename)==0)break;}if(j<savenum){mesg("Warning! the destination file exist!");printf("\n Are you sure to recover if ? [Y/N]");while(!kbhit());tempchar=getch();if(tempchar=='N'||tempchar=='n')mesg("Cancel! file not copy.");else if(tempchar=='Y'||tempchar=='y'){mesg("File copy success!file recovered!");userfd[j].length=userfd[i].length;userfd[j].protect=userfd[i].protect;fp=fopen(username,"w+");for(i=0;i<savenum;i++){fputs(userfd[i].filename,fp);fputs("\n",fp);fprintf(fp,"%C\n%d\n",userfd[i].protect,userfd[i].length);}fclose(fp);}}else if(savenum>=M)mesg("copy false! file total limited.");else{strcpy(userfd[savenum].filename,destfile);userfd[savenum].length=userfd[temp].length;userfd[savenum].protect=userfd[temp].protect;savenum++;fp=fopen(username,"w+");for(i=0;i<savenum;i++){fputs(userfd[i].filename,fp);fputs("\n",fp);fprintf(fp,"%c\n%d\n",userfd[i].protect,userfd[i].length);}fclose(fp);mesg("File copy success!");}}}}}}///////////////////////void myrename()/*文件重命名*/{char oldfile[256],newfile[256];int i=0,temp=0;if(strcmp(username,"")==0)mesg("No user lgoin!");else if(command->next==NULL)mesg("Too few parametets!");else if(command->next->next==NULL)mesg("Too few parametets!");else if(command->next->next->next!=NULL)mesg("Too many parameters!");else{strcpy(oldfile,command->next->string);strcpy(newfile,command->next->next->string);for(i=0;i<savenum;i++){if(strcmp(oldfile,userfd[i].filename)==0)break;}temp=i;if(temp>=savenum)printf("\n the source file not eixsted!");else if(temp!=i&&i<savenum){printf("\n newfile and the existing files is the same name, please re-naming!");}else{for(i=0;i<opennum;i++){if(strcmp(oldfile,openfd[i].filename)==0)break;}if(i>=opennum)printf("\n the source file not opened!");else if(strcmp(oldfile,newfile)==0){printf("Rename false! oldfile and newfile can not be the same.");}else{strcpy(openfd[i].filename,newfile);strcpy(userfd[temp].filename,newfile);mesg("Rename file success!\n");}}}}。