-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFINDRECI.PAS
150 lines (140 loc) · 3.29 KB
/
FINDRECI.PAS
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
{ @author: Sylvain Maltais (support@gladir.com)
@created: 2022
@website(https://www.gladir.com/alimbase)
@abstract(Target: Turbo Pascal 7, Free Pascal 3.2)
}
Program FindReci;
Uses Strings;
Const
FoodList:Array[0..20]of PChar=(
'Brochette aux boeufs',
'Brochette aux poulets',
'Brochette Slovaquie',
'Burger aux champignons',
'Club sandwitch',
'C“telette de porc',
'Croque-monsieur',
'Hot Chicken',
'Hot Dog',
'G‚n‚ral Tao',
'Pƒt‚ chinois',
'Pƒt‚ … la viande',
'Pizza',
'Poutine',
'Soupe … l''oignon',
'Sous-marin',
'Spaghetti',
'Spaghetti gratin‚',
'Steak/Fites',
'TourtiŠre','Tourtiere'
);
Var
LineNumber:LongInt;
Option:Set of (_Lines);
BeginWord,I,J:Integer;
FoundMultiWord:Boolean;
SourceFile:Text;
FileName,CurrLine,CurrWord:String;
Function StrToUpper(S:String):String;
Var
I:Byte;
Begin
For I:=1 to Length(S)do Begin
If S[I] in['a'..'z']Then S[I]:=Chr(Ord(S[I])-32);
End;
StrToUpper:=S;
End;
Function IsLetter(Chr:Char):Boolean;Begin
IsLetter:=Chr in ['A'..'Z','a'..'z','‚','ˆ','Š','…','ƒ','“','‡'];
End;
Procedure CompileWord;
Var
I:Integer;
Begin
For I:=Low(FoodList) to High(FoodList) do Begin
If StrToUpper(StrPas(FoodList[I]))=StrToUpper(CurrWord)Then Begin
If FileName<>''Then Begin
If(_Lines in Option)Then Begin
WriteLn('Avion trouve dans la ligne numero ',LineNumber,' :');
End;
End;
WriteLn(StrPas(FoodList[I]));
Exit;
End;
End;
End;
Procedure ParseLineDetectPlane;
Var
J:Integer;
Begin
CurrWord:='';
BeginWord:=1;
For I:=1 to Length(CurrLine)do Begin
If(IsLetter(CurrLine[I]))Then CurrWord:=CurrWord+CurrLine[I]
Else
Begin
FoundMultiWord:=False;
For J:=Low(FoodList) to High(FoodList) do Begin
If(StrLen(FoodList[J])>Length(CurrWord))and
(StrToUpper(StrPas(FoodList[J]))=
StrToUpper(Copy(CurrLine,BeginWord,StrLen(FoodList[J]))))Then Begin
FoundMultiWord:=True;
Break;
End;
End;
If(FoundMultiWord)Then Begin
CurrWord:=CurrWord+CurrLine[I]
End
Else
Begin
CompileWord;
CurrWord:='';
BeginWord:=I+1;
End;
End;
End;
CompileWord;
End;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')or
(ParamStr(1)='/h')or(ParamStr(1)='/H')Then Begin
WriteLn('FINDRECI : Cette commande permet de d‚tecter les recettes ',
'mentionn‚ dans un texte.');
WriteLn;
WriteLn('Syntaxe : FINDRECI "message"');
WriteLn(' FINDRECI /FILE:fichier [/LINES]');
WriteLn;
WriteLn(' /FILE: Ce parametre permet d''indiquer le fichier a analyser');
WriteLn(' /LINES Ce parametre permet d''afficher le numero de ligne');
End
Else
Begin
Option:=[];
LineNumber:=0;
FileName:='';
CurrLine:='';
For I:=1 to ParamCount do Begin
If StrToUpper(ParamStr(I))='/LINES'Then Include(Option,_Lines);
If StrToUpper(Copy(ParamStr(I),1,6))='/FILE:'Then Begin
FileName:=Copy(ParamStr(I),7,255);
End
Else
Begin
If CurrLine=''Then CurrLine:=ParamStr(I)
Else CurrLine:=CurrLine+' '+ParamStr(I);
End;
End;
If FileName<>''Then Begin
Assign(SourceFile,FileName);
Reset(SourceFile);
While Not EOF(SourceFile)do Begin
Inc(LineNumber);
ReadLn(SourceFile,CurrLine);
ParseLineDetectPlane;
End;
Close(SourceFile);
End
Else
ParseLineDetectPlane;
End;
END.