文件管理系统源代码
知识库管理系统php源代码

知识库管理系统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;}。
Linux 内核2.4版源代码分析大全

4.4.4 如何使传统管理方式依然有效
4.4.5 内核实现综述
4.4.6 核心结构与变量
4.4.7 devfs节点注册函数
4.4.8 编写采用devfs的设备驱动程序
4,5 块设备的请求队列
4.5.1 相关结构及请求队列的初始化
4.6.1 构造ioctl命令字
4.6.2 ioctl的实现过程
4.6.3 ioctl的上层处理函数
4.6.4 ioctl的底层处理函数
4.7 I/O端口的资源分配与操作
4.7.1 I/O端口概述
4.7.2 Linux系统中的I/O空间分配
4.7.3 端口操作函数
4.9.4 设备的使用
4.9.5 驱动程序编写实例
4.10 块设备驱动程序的实现
4.10.1 设备功能
4.10.2 编写块设备的函数接口fops
4.10.3 设备接口注册与初始化
第5章 Linux系统初始化
5.1 系统引导
1,13 系统调用
1.13.1 与系统调用有关的数据结构和
函数
1.13.2 进程的系统调用命令是如何转换为
INT0x80中断请求的
1.13.3 系统调用功能模块的初始化
1.13.4 Linux内部是如何分别为各种系统
调用服务的
4.1.2 与外设的数据交流方
4.1.3 字符设备与块设备
4.1.4 主设备号和次设备号
4.1.5 本章内容分配
4.2 设备文件
4.2.1 基本设备文件的设备访问流程
4.2.2 设备驱动程序接口
4.2.3 块设备文件接口
图书馆管理系统文档(含源代码)免费

程序设计综合训练<图书馆管理系统>设计报告院系:材料科学与工程学院专业班级:材料成型一班*名:***学号: ***********指导老师:肖老师一、程序功能简介图书排序功能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是一种开放源代码的操作系统,它可以在各种计算机硬件设备和移动设备上运行。
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操作系统及其特点,掌握了基础的命令行终端和图形界面操作技能,掌握了安装软件和进行网络设置的方法以及权限管理。
Linux系统文件和目录管理

选项参数: -num:在匹配行找到后,将显示匹配行和匹配行前后num行的内容。 -A num:在匹配行找到后,将显示匹配行和匹配行后num行的内容。 -B num:在匹配行找到后,将显示匹配行和匹配行前num行的内容。 -n:在找到匹配的输出行前面加上该行在输入文件中的行数。 -s:对于不存在或者不可读的文件不输出错误信息。 文件列表:所要查询的文件和文件列表。 例:在tty.txt文件中查找每一个提到“Linux*b”的地方。
$ grep Linux\*b tty.txt
1.4 操作文件和目录
1. cp命令 功能:cp(copy)命令可以将文件或目录复制到其他目录中,就如
同DOS下的copy命令一样,功能非常强大。在使用cp命令时,需要 指定源文件名与目标文件名或目标目录即可。 格式:cp[选项]源文件 目标文件 选项参数: -f:在复制过程中删除已经存在的目标文件。 -i:在复制过程中删除已经存在的目标文件时给出提示信息。 -r:递归复制所有目录,将所有的非目录内容当作文件一样复制。 -u:源文件比目标文件新或目标文件不存在则复制。 -R:递归复制整个目录。
例1:输出当前目录下名称中有“lib”文件或目录的详细信息。
# ls –l *lib* 显示结果为 drwxr-xr-x 130 root root 69632 3月 10 14:07
lib drwxr-xr-x 13 root root 4096 3月 4 20:28
libexec 这个结果提供了许多细节信息。 1)第一列为文件模式。文件模式中第一位代表文件类型,其余九位
$ cat /etc/redhat-release
1.3 搜索文件内容
搜索文件内容可以使用grep命令 功能:grep命令用于在文件中查找指定的字串。 格式:grep[选项]文件列表 说明:grep除了可以查找固定的字符串,还可以使用较为复杂的匹
北邮操作系统进程管理实验报告及源代码

进程管理实验报告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)实验题目和要求:修改已经编写的程序, 将每个进程输出一个字符改为每个进程输出一句话, 再观察程序执行时屏幕上出现的现象, 并分析原因。
源代码管理工具-SVN使用手册大全(客户端)

目录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”中建立一个子文件夹(子文件夹为空文件夹),子文件夹的名称可以根据本公司配置库路径下的对应文件夹名称进行定义。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
文件管理系统一、实验目的通过设计一个多用户文件系统,了解操作系统中文件的组织与管理,熟悉文件管理所用的数据结构,加深对文件系统内部功能实现过程的理解。
二、实验内容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");}}}}。