-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCONVERT.PAS
143 lines (138 loc) · 4.11 KB
/
CONVERT.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
{ @author: Sylvain Maltais (support@gladir.com)
@created: 2023
@website(https://www.gladir.com/corail)
@abstract(Target: Turbo Pascal 7, Free Pascal 3.2)
}
Program CONVERT;
Var
FileInput:Text;
Ch:Char;
FirstChar:Boolean;
InString,InComment:boolean;
UpperCase:Set of Char;
I:Integer;
Mode:(_LowerCase,_UpperCase,_Capital);
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 LoCase(C:Char):Char;Begin
If C in['A'..'Z']Then LoCase:=Chr(Ord(C)+32)
Else LoCase:=C;
End;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')or
(ParamStr(1)='/h')or(ParamStr(1)='/H')Then Begin
WriteLn('CONVERT : Cette commande permet de convertir en ',
'minuscule, majuscule ou capitale un fichier ',
'de code source Pascal.');
WriteLn;
WriteLn('Syntaxe : CONVERT [/LOWER|/UPPER|/CAPITAL] nomdufichier.pas');
WriteLn;
WriteLn(' nomdufichier.pas Nom du fichier de code source Pascal.');
WriteLn(' /CAPITAL Convertie les mots en capitale.');
WriteLn(' /LOWER Force … convertir en minuscule. ',
'Valeur par d‚faut');
WriteLn(' /UPPER Force … convertir en majuscule.');
WriteLn;
End
Else
If ParamCount>0 Then Begin
Mode:=_LowerCase;
For I:=1 to ParamCount do Begin
If StrToUpper(ParamStr(I))='/LOWER'Then Mode:=_LowerCase Else
If StrToUpper(ParamStr(I))='/UPPER'Then Mode:=_UpperCase Else
If StrToUpper(ParamStr(I))='/CAPITAL'Then Mode:=_Capital;
End;
For I:=1 to ParamCount do If(StrToUpper(ParamStr(I))<>'/LOWER')and
(StrToUpper(ParamStr(I))<>'/UPPER')and
(StrToUpper(ParamStr(I))<>'/CAPITAL')Then Begin
{$I-}Assign(FileInput,ParamStr(I));
Reset(FileInput);{$I+}
If IoResult=0 Then Begin
InString:=False;
InComment:=False;
If(Mode=_Capital)Then Begin
FirstChar:=True;
While Not Eof(FileInput)do Begin
While not Eoln(FileInput) do Begin
Read(FileInput,Ch);
If(Ch = '''')and(Not InComment)Then InString:=Not InString;
If(Ch = '{')and(Not InString)Then InComment:=True;
If(Ch = '}')and(Not InString)Then InComment:=False;
If Not(InString)and Not(InComment)Then Begin
If Ch in['A'..'Z','a'..'z']Then Begin
If(FirstChar)Then Begin
Write(UpCase(Ch));
FirstChar:=False;
End
Else
Write(LoCase(Ch));
End
Else
Begin
FirstChar:=True;
Write(Ch);
End;
End
else
Write(Ch);
End;
Readln(FileInput);
WriteLn;
End;
End
Else
If(Mode=_UpperCase)Then Begin
UpperCase:=['a'..'z'];
While Not Eof(FileInput)do Begin
While not Eoln(FileInput) do Begin
Read(FileInput,ch);
If(Ch = '''')and(Not InComment)Then InString:=Not InString;
If(Ch = '{')and(Not InString)Then InComment:=True;
If(Ch = '}')and(Not InString)Then InComment:=False;
If Not(InString)and Not(InComment)Then Begin
If Ch in UpperCase Then Write(Chr(Ord(ch)-Ord('a')+Ord('A')))
Else Write(Ch);
End
else
Write(Ch);
End;
Readln(FileInput);
WriteLn;
End;
End
Else
Begin
UpperCase:=['A'..'Z'];
While Not Eof(FileInput)do Begin
While not Eoln(FileInput) do Begin
Read(FileInput,ch);
If(Ch = '''')and(Not InComment)Then InString:=Not InString;
If(Ch = '{')and(Not InString)Then InComment:=True;
If(Ch = '}')and(Not InString)Then InComment:=False;
If Not(InString)and Not(InComment)Then Begin
If Ch in UpperCase Then Write(Chr(Ord(ch)-Ord('A')+Ord('a')))
Else Write(Ch);
End
else
Write(Ch);
End;
Readln(FileInput);
WriteLn;
End;
End;
Close(FileInput);
End
Else
WriteLn('Impossible de lire le fichier : ',ParamStr(I));
End;
End
Else
WriteLn('ParamŠtre attendu !');
END.