This repository has been archived by the owner on Apr 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
BMSPS_FIND_IN_FILE.c
85 lines (69 loc) · 1.81 KB
/
BMSPS_FIND_IN_FILE.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
/*
* BMSPS_FIND_IN_FILE.c
* Created on: 11-25-2011
* Author: JasonStein
* E-mail: JasonStein@live.cn
*
* ===== BlendMIUI Speed-Porting Software =====
*
* This is a 100% free software and you can add all kinds
* of functions you like to make it powerful and useful.
* However,it's intended for personal and/or educational
* use only.It may not be duplicated for monetary benefit
* or any other purpose without the permission of the developer.
*
*/
#include <stdio.h>
#include <conio.h>
#include <string.h>
int DFS_COMPARE(char *String,int Len,char *File,int i,int j)
{
if(i==Len)
{
if(String[i]==File[j]) return 1;
else return 0;
}
else if(String[i]!=File[j]) return 0;
else return DFS_COMPARE(String,Len,File,i+1,j+1);
}
int FIND_IN_FILE(char *String,char *PATH,char *Ver)
{
char File[500][500];
int Lines=0 , i=0 , j=0 ,flag=0 ;
int Length=strlen(String);
FILE *fread=fopen(PATH,"r");
while(fgets(File[Lines++],500,fread));
for( i=0 ; i<Lines ; i++ )
{
j=0;
while( File[i][j]!='\0' )
if(DFS_COMPARE(String,Length-1,File[i],0,j))
{ flag=1; break; }
else j++;
if(flag) break;
}
strcpy(Ver,File[i]);
fclose(fread);
if(flag) return 1;
else return 0;
}
int FIND_IN_FILE_CHECK(char *String,char *PATH)
{
char File[500][500]={"\0"};
int Lines=0 , i=0 , j=0 ,flag=0 ;
int Length=strlen(String);
FILE *fread=fopen(PATH,"r");
while(fgets(File[Lines++],500,fread));
for( i=0 ; i<Lines ; i++ )
{
j=0;
while( File[i][j]!='\0' )
if(DFS_COMPARE(String,Length-1,File[i],0,j))
{ flag=1; break; }
else j++;
if(flag) break;
}
fclose(fread);
if(flag) return 1;
else return 0;
}