-
Notifications
You must be signed in to change notification settings - Fork 0
/
FINDCITY.PAS
177 lines (168 loc) · 5.86 KB
/
FINDCITY.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
{ @author: Sylvain Maltais (support@gladir.com)
@created: 2022
@website(https://www.gladir.com/geo-commander)
@abstract(Target: Turbo Pascal, Free Pascal)
}
Program FindCity;
Uses Strings;
Const
CityList:Array[0..258]of PChar=(
'Abu Dhabi','Abuja','Accra','Achgabat','Adamstown','Addis-Abeba',
'Alger','Alma','Alofi','Amman','Amsterdam','Andorre-la-Vieille',
'Ankara','Antananarivo','Apia','Asmara','Astana','Asunci¢n',
'AthŠnes','Avarua','Bagdad','Bakou','Bamako','Bandar Seri Begawan',
'Bangkok','Bangui','Banjul','Basse-Terre','Basseterre','Belgrade',
'Belmopan','Berlin','Berne','Beyrouth','Bissau','Bichkek',
'Bogot ','Boston','Brasilia','Bratislava','Brazzaville',
'Bridgetown','Bruxelles','Bucarest','Budapest','Buenos Aires',
'Bujumbura','Canberra','Caracas','Castries','Cayenne',
'Charlotte Amalie','Chibougamau','Chisinau','Cockburn Town',
'Colombo','Conakry','Copenhague','Dacca','Dakar','Damas',
'Djibouti','Djouba','Dili','Dodoma','Doha','Douchanb‚',
'Douglas','Dublin','Erevan','Flying Fish Cove','Fort-de-France',
'Freetown','Funafuti','Gaborone','George Town','Georgetown',
'Gibraltar','Grytviken','Guatemala','Gustavia','Hag†t¤a',
'Hamilton','Hano‹','Harare','Helsinki','Hong Kong','Honiara',
'Islamabad','Jakarta','Jamestown','J‚rusalem','Kaboul',
'Kampala','Khartoum','Katmandou','Kiev','Kigali','Kingston',
'Kingstown','Kinshasa','Kowe‹t','Kralendijk','Kuala Lumpur',
'Laƒyoune','Laval','La Havane','La Tuque','La Valette',
'Le Caire','Libreville','Lilongwe','Lima','Lisbonne',
'Ljubljana','Lom‚','Londres','Longueuil','Longyearbyen',
'Los Angeles','Luanda','Lusaka','Luxembourg','Lyon','Macao',
'Madrid','Malabo','Mal‚','Mamoudzou','Monaco','Managua',
'Manama','Manille','Mariehamn','Majuro','Maputo','Marseille',
'Mascate','Maseru','Mata-Utu','Mbabane','Melekeok',
'Melekeok - Palau State Capital','Mexico','Minsk','Mogadiscio',
'Monrovia','Montevideo','Montreal','Montr‚al','Moroni','Moscou',
'Munich','Nairobi','Nassau','Nay Pyi Taw','Ndjamena','New Delhi',
'New York','Niamey','Nicosie','Nouakchott','Noum‚a',
'Nuku''alofa','Nuuk','Oranjestad','Oslo','Ottawa','Ouagadougou',
'Oulan-Bator','Pago Pago','Palikir','Panam ','Papeete',
'Paramaribo','Paris','P‚kin','Philipsburg','Phnom Penh','Plymouth',
'Podgorica','Port-au-Prince','Port-Cartier','Port-d''Espagne',
'Port-aux-Fran‡ais','Port-Louis','Port Moresby','Port Stanley',
'Port-Vila','Porto Novo','Prague','Pretoria','Praia','Pristina',
'Pyongyang','Qu‚bec','Quito','Rabat','Reykjav¡k','Riga',
'Rio de Janeiro','Riyad','Road Town','Rome','Roseau','Saint-Denis',
'Saint John''s','Saint-Georges','Saint Helier','Saint-Marin',
'Saint-Pierre','Saint-Pierre-Port','Saipan','Sanaa','San Francisco',
'San Juan','San Jos‚','San Salvador','Santo Domingo',
'Santiago du Chili','Sao Tom‚','Sarajevo','S‚oul','Sept-Iles',
'Singapour','Skopje','Sofia','Stockholm','Sucre','Suva','Tachkent',
'Tallinn','Taipei','Tarawa-Sud','Tbilissi','Tegucigalpa','T‚h‚ran',
'Thimphou','Tirana','Tokyo','T¢rshavn','Tripoli','Tunis','Vaduz',
'Varsovie','Vatican City','Victoria','Vienne','Vientiane','Vilnius',
'Washington','Wellington','West Island','Willemstad','Windhoek',
'Yamoussoukro','Yaound‚','Yaren','Zagreb'
);
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(CityList) to High(CityList) do Begin
If StrToUpper(StrPas(CityList[I]))=StrToUpper(CurrWord)Then Begin
If FileName<>''Then Begin
If(_Lines in Option)Then Begin
WriteLn('Ville trouve dans la ligne numero ',LineNumber,' :');
End;
End;
WriteLn(StrPas(CityList[I]));
Exit;
End;
End;
End;
Procedure ParseLineDetectCity;
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(CityList) to High(CityList) do Begin
If(StrLen(CityList[J])>Length(CurrWord))and
(StrToUpper(StrPas(CityList[J]))=
StrToUpper(Copy(CurrLine,BeginWord,StrLen(CityList[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('FINDCITY : Cette commande permet de detecter les villes ',
'mentionne dans un texte.');
WriteLn;
WriteLn('Syntaxe : FINDCITY "message"');
WriteLn(' FINCCITY /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);
ParseLineDetectCity;
End;
Close(SourceFile);
End
Else
ParseLineDetectCity;
End;
END.