⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib.c

📁 操作系统简单的登入程序
💻 C
字号:
#include <stdio.h>
#include "filesys.h"
#include <string.h>
#include <regex.h>
#define NMATCH 10

char* getinput(char chr)
{
	char* buff;
	char* pbuff;
	long ch,k=0,ff;
	char control[2];
	short cn=0;
	buff=(char*)malloc(BLOCKSIZE);
	bzero(buff,BLOCKSIZE);


	while(ch!=chr)
	{
		ch=getchar();

		if(ch==chr)
			continue;

		if((ch!=27)&&(cn==0))
		{
			if(ch!=8)

				*(buff+k++)=ch;
			else
			 if(k!=0)
				k--;
		}
		else
		{
			if(cn==0)
			{
				cn=3;
			}
			control[--cn]=ch;
			if(cn==0)
			{
				
				if((control[1]=='[')&&(control[0]=='D'))
				{
						if(k!=0)
							k--;
				}

				if((control[1]=='[')&&(control[0]=='C'))
				{
						
						if(k!=0)
						{
							if(*(buff+k)==0)
							{

							*(buff+k)=' ';

							}

							k++;
						}
				}

			 }
	
		 }

		if(k%BLOCKSIZE==0)
		{
			pbuff=(char*)malloc(BLOCKSIZE*(k/BLOCKSIZE+1));

			bzero(pbuff,BLOCKSIZE);

			strcpy(pbuff,buff);

			free(buff);

			buff=pbuff;
		}
	}




	return buff;

}
void convertout(int di_mode ,int count)
{
	int  one;

	one=di_mode%2;
					
	di_mode=di_mode/2;	

	--count;

	if(count!=0)
	{
		convertout(di_mode,count);				
	}

		if(one)
		printf("x");
		else
		printf("-");


}

void showdir()
{
unsigned int di_mode;
int i,j;
struct inode *pinode;

readdir2(currentuser);


for(i=0;i<(DIRNUM);i++)
{
		if(directory_2.direct[i].filetype!=DIEMPTY)		
		{
			//printf("%d",i);
			printf("%4d	",directory_2.direct[i].d_ino);

			printf("%-10s	",directory_2.direct[i].name);

			pinode=(struct inode*)posinode(directory_2.direct[i].d_ino);
			
			di_mode=pinode->di_mode;

			convertout(di_mode,9);

			if(directory_2.direct[i].filetype==DIFILE)
			{
				
				printf("<file>");

				printf("size:%-4d",pinode->di_size);

				printf("block chain:");

				for(j=0;j<pinode->di_size;j++)

					printf("%-3d",pinode->di_addr[j]);
				
				printf("\n");
			}

		else
			
			{
				printf("<dir>\n");
			
			}
			
		}
}


}


int strreg(char* input,char* regex,int count )
{
	regex_t preg;

	unsigned int len,errno;

	char errbuf[1024];

	regmatch_t pmatch[NMATCH];
	
	bzero(&preg,sizeof(regex_t));
	
	if(regcomp(&preg,regex,REG_ICASE|REG_EXTENDED|REG_NEWLINE)==0)
	{
		errno=regexec(&preg,input,NMATCH,pmatch,0);

		if(errno==REG_NOMATCH)
		{
			strcpy(command1,"command syntax error");
			
			regfree(&preg);	

			return 1;

		}
		else if( errno )
		{
			regerror (errno, &preg, errbuf, sizeof (errbuf)); 

			strcpy(command1,errbuf);
			
			regfree(&preg);	
			//free(stroper);count
			return 1;
		}
		if(count>=1)
		{
		 	len=(pmatch[3].rm_eo-pmatch[3].rm_so);

			memcpy(command1,input+pmatch[3].rm_so,len);
			
			command1[len]='\0';

		}
		if(count>=2)
		{

		 	len=(pmatch[5].rm_eo-pmatch[5].rm_so);

			memcpy(command2,input+pmatch[5].rm_so,len);
			
			command2[len]='\0';

		}
		
		if(count>=3)
		{
		 	len=(pmatch[7].rm_eo-pmatch[7].rm_so);

			memcpy(command3,input+pmatch[7].rm_so,len);
			
			command3[len]='\0';

		}

		regfree(&preg);	

		return 0;

	}
	else
	{
		regfree(&preg);	

		return 1;
	}

}


void pwd()
{

	
	printf("/%s/\n",directory_1.users[currentuser].u_uid);
}

int oct2dec(int oct)
{
	int i=0;

	int degree=1;


	while(oct!=0)
	{
		i+=degree*(oct%10);
		
		degree*=8;

		oct=oct/10;
          
	}

	return  i;
}
void updatesys()
{
	fd=fopen("filesystem","r+");

	fseek(fd,0,SEEK_SET);

	fwrite(super,sizeof(struct filesys),1,fd);

	fclose(fd);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -