-
Notifications
You must be signed in to change notification settings - Fork 5
/
CB.PAS
82 lines (78 loc) · 1.78 KB
/
CB.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
{ @author: Sylvain Maltais ([email protected])
@created: 2024
@website(https://www.gladir.com/corail)
@abstract(Target: Turbo Pascal 7, Free Pascal 3.2)
}
Program CB;
Var
SourceC:File;
LastChar,CurrChar:Char;
Spacing,ReadedByte:Word;
Ident:Integer;
InString:Boolean;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')Then Begin
WriteLn('CB : Cette commande permet de rendre lisible le formatage ',
' d''un fichier de format C.');
WriteLn;
WriteLn('Syntaxe : CB nomdufichier.C');
WriteLn;
WriteLn(' nomdufichier Ce paramŠtre permet d''indiquer le nom du fichier C.');
End
Else
If ParamCount>0Then Begin
Spacing:=2;
{$I-}Assign(SourceC,ParamStr(1));
Reset(SourceC,1);{$I+}
If IOResult=0Then Begin
Ident:=0;
InString:=False;
LastChar:=#0;
While Not(EOF(SourceC))do Begin
BlockRead(SourceC,CurrChar,1,ReadedByte);
If(InString)Then Begin
If(LastChar='\')and(CurrChar='"')Then Begin
{ Ne rien faire }
End
Else
If CurrChar='"'Then InString:=False;
Write(CurrChar);
End
Else
Begin
If LastChar='}'Then Begin
If CurrChar<>','Then Begin
WriteLn;
If(Ident>0)Then WriteLn(' ':Ident*Spacing,'}')
Else WriteLn('}');
Write(' ':Ident*Spacing);
End
Else
Write('}');
End;
Case CurrChar of
'"':Begin
InString:=True;
Write('"');
End;
'{':Begin
WriteLn('{');
Inc(Ident);
Write(' ':Ident*Spacing);
End;
'}':Begin
If Ident>0 Then Dec(Ident);
End;
':':Write(': ');
#13:WriteLn;
#10:;
Else Write(CurrChar);
End;
End;
LastChar:=CurrChar;
End;
If LastChar='}'Then WriteLn('}');
Close(SourceC);
End;
End;
END.