-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeader.c
124 lines (124 loc) · 2.21 KB
/
Header.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include"Pre.h"
extern char *s;
/* This Function find string "#include" in string if found return address
* if not found return NULL*/
char *Header(char *str)
{
char *p;
if(p=strstr(str,"#include"))
return p;
if(p=strstr(str,"# include"))
return p;
if(p=strstr(str,"# include"))
return p;
return NULL;
}
/* We try to open That Hederfile.
* If found than add that file.
* realloc memory and include that all file data
* */
char *Include(char *str)
{
int i=0,j=0,f=0,k=0,l=0;
char file[50]="/usr/include/";
char file1[100]="/usr/include/x86_64-linux-gnu/";
char file2[50]="/usr/include/linux/";
l=19;
j=13;
k=30;
if(str[i]=='#')
{
if((str[i+1]=='i')||(str[i+2]=='i')||(str[i+3]=='i'))
{
if((str[i+3]=='n')||(str[i+2]=='n')||(str[i+4]=='n'))
{
strCpy(str," ");
i=9;
f=1;
}
}
}
for(;str[i];i++)
{
/*if(str[i]=='#')
{
if((str[i+1]=='i')||(str[i+2]=='i'))
{
if((str[i+2]=='n')||(str[i+3]='n'))
{
strCpy(str+i," ");
i+=9;
f=1;
}
}
}*/
if(str[i]=='>')
{
str[i]=' ';
break;
}
if((str[i]!=32)&&(f)&&(str[i]!='<'))
{
file2[l++]=str[i];
file1[k++]=str[i];
file[j++]=str[i];
str[i]=' ';
}
if(str[i]=='<')
str[i]=' ';
}
file1[k]='\0';
file[j]='\0';
file2[l]='\0';
FILE *fp,*fp1;
long size;
if((fp=fopen(file,"r"))!=NULL)
{
printf("SUCESS :%s\n",file);
fseek(fp,0,2);
size=ftell(fp);
rewind(fp);
if((str=realloc(s,strlen(s)+size+1))!=NULL)
{
s=str;
memmove(str+size,str,strlen(str)+1);
fread(str,size,1,fp);
fclose(fp);
}
return str;
}
if((fp1=fopen(file1,"r"))!=NULL)
{
printf("SUCESS :%s\n",file1);
fseek(fp1,0,2);
size=ftell(fp1);
rewind(fp1);
if((str=realloc(s,strlen(s)+size+1))!=NULL)
{
s=str;
memmove(str+size,str,strlen(str)+1);
fread(str,size,1,fp1);
//printf("%s\n",str);
fclose(fp1);
}
return str;
}
if((fp1=fopen(file2,"r"))!=NULL)
{
printf("SUCESS :%s\n",file2);
fseek(fp1,0,2);
size=ftell(fp1);
rewind(fp1);
if((str=realloc(s,strlen(s)+size+1))!=NULL)
{
s=str;
memmove(str+size,str,strlen(str)+1);
fread(str,size,1,fp1);
//printf("%s\n",str);
fclose(fp1);
}
return str;
}
printf("Error: %s\n",file);
return str;
}