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

📄 test.c.bak

📁 可以自动识别一个程序中调用的所有函数
💻 BAK
字号:

/* ***********函数分析识别程序*******************/
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include <stdlib.h>

#define MAX 20
void main();
//bool isReserved(char *);
bool isdivided(char);
bool isOperation(char );
char *key[]=
			{
			"main","auto","break","case","char","const",
			"continue","default","do","double",
			"else","enum","extern","float","for","goto",
			"if","int","long","register",
			"return","short","signed","sizeof","static",
			"struct","switch","typedef",
			"union","unsigned","void","volatile","while","False"
			};    


/*运算、限界符*/
const int limitLen=18;
const int dividLen=15;
char divid[dividLen]=
					{
					'!','+','-','&','~',
					'*','%','<','>','=','|',
					',',';','{','}',
					};
char limit[limitLen]={
				'[',']','!','+','-','&','~',
				'*','%','<','>','=','|',
				',',';','{','}','#'
			};
char *hanshu[80];

void main()
{
	FILE *input;
	FILE *output;
	char ch;
	int isreserv=0,isfuction=0;
	int isoperation=0;
	int count=0;
	int n=0;

	if((input=fopen("input.txt","r"))==NULL)
	{ 
		printf("file open in readonly mode,but an error generate!\n");
		exit(0);
	}
	
	if((output=fopen("output.txt","w"))==NULL)
	{
		printf("file open in new_create mode,but an error generate!\n");
		exit(0);
	}

	//printf("test");
	ch=fgetc(input);
	while(ch!=EOF)
	{
			
		while((ch==' '||ch=='\n'||ch=='\t'&&ch!=EOF))//消除空格、回车、制表符
			ch=fgetc(input);
		if(ch=='/')//消除注释
		{
			ch=fgetc(input);
			if(ch=='/')//消除//后一行的注释内容
			{
				ch=fgetc(input);
				while(ch!='\n')
					ch=fgetc(input);
				ch=fgetc(input);
			}
			else if(ch=='*')//消除/* */ 中
			{
				count=0;
				ch=fgetc(input);
				while(count!=2)
				{
					count=0;
					while(ch!='*')
						ch=fgetc(input);
					count++;
					ch=fgetc(input);
					if(ch=='/')
						count++;
					else ch=fgetc(input);
				}
			}
			else //是除号
			{
				ch=fgetc(input);
				int m=0;
				char array[MAX];
				array[m]='\0';
				while(ch!='\n'&&ch!=')'&&!isdivided(ch))
				{
					
					array[m]=ch;
					m++;
					ch=fgetc(input);
					if(ch=='(')
					{
						while(ch!=')')
						{	array[m]=ch;
						m++;
						ch=fgetc(input);
						array[m]=ch;
						m++;
						}
					}
				}
				array[m]='\0';
			//	isreserv=isReserved(array);
				int i=0;
				if(!isreserv)//不是保留关键字
				{
					int i=0;
					if(isalpha(array[i]))
					{
						i++;
						while(array[i]!='(')
							i++;
					}
					if(array[i]!='\0')
					{
						hanshu[n]=array;
						n++;
						fprintf(output,"%s\n",array);
						printf("%s=\n",array);
						for(i=0;i<m;i++)
							array[i]='\0';
					}
					else for(i=0;i<m;i++)
							array[i]='\0';
				}
				else for(i=0;i<m;i++)
						array[i]='\0';
			}		
		}
		else if(ch=='\"')//消除" " 之间的字符
		{
			ch=fgetc(input);
			while(ch!='\"')
				ch=fgetc(input);
			ch=fgetc(input);
		}
		else if(ch=='\'')
		{
			ch=fgetc(input);
			while(ch!='\'')
				ch=fgetc(input);
			ch=fgetc(input);
		}
		else if(isOperation(ch)==true)	//是运算符
		{
		while(isOperation(ch)==true)
		ch=fgetc(input);
		}
		else 
		{
			int m=0;
			char array[MAX];
			array[m]='\0';
			while(ch!='\n'&&ch!=')'&&!isdivided(ch))
			{
				
				array[m]=ch;
				m++;
				ch=fgetc(input);
				if(ch=='(')
				{
						array[m]=ch;
					while(ch!=')')
					{
						m++;
						ch=fgetc(input);
						array[m]=ch;
						m++;
					}
				}
			}
			ch=fgetc(input);
				array[m]='\0';
		
			int i=0;
		//	isreserv=isReserved(array);
			if(!isreserv)//不是保留关键字
			{	
			
			//	if(isFuction(array))
				int i=0;
				if(isalpha(array[i]))
				{
					i++;
					while(array[i]!='(')
						i++;
				}
				if(i<m)
				{

					hanshu[n]=array;
					n++;
					fprintf(output,"%s\n",array);
					printf("%s\n",array);
					for(i=0;i<m;i++)
						array[i]='\0';
				}
				else for(i=0;i<m;i++)
						array[i]='\0';
				
			}
		//	else 
			for(i=0;i<m;i++)
					array[i]='\0';
		}
	}
	int	j=0;
	while(j<n)
	{
		printf("%s\n",hanshu[j]);
	    j++;
	}
}
/*
bool isReserved(char *str)
{
	int i=0;
	while(strcmp(str,key[i]))
	{
		i++;
	}
	if(i<33) return true;
	else return false;
}
*/
bool isOperation(char ch)
{
	
	int i=0;
	while((i<18)&&(ch!=limit[i]))
		i++;
	
	if(i==18) return false;
	else return true;
	
	
}
bool isdivided(char ch)
{
	
	int i=0;
	while((i<15&&(ch!=divid[i])))
		i++;
	
	if(i==15) return false;
	else return true;
	
	
}

⌨️ 快捷键说明

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