-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBEAUTIFY.PAS
93 lines (90 loc) · 2.04 KB
/
BEAUTIFY.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
{ @author: Sylvain Maltais ([email protected])
@created: 2023
@website(https://www.gladir.com/corail)
@abstract(Target: Turbo Pascal 7, Free Pascal 3.2)
}
Program BEAUTIFY;
Var
SourceJSON: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('BEAUTIFY : Cette commande permet de rendre lisible le formatage ',
' d''un fichier de format JSON.');
WriteLn;
WriteLn('Syntaxe : BEAUTIFY nomdufichier.JSON');
WriteLn;
WriteLn(' nomdufichier Ce paramŠtre permet d''indiquer le nom du fichier JSON.');
End
Else
If ParamCount>0Then Begin
Spacing:=2;
{$I-}Assign(SourceJSON,ParamStr(1));
Reset(SourceJSON,1);{$I+}
If IOResult=0Then Begin
Ident:=0;
InString:=False;
LastChar:=#0;
While Not(EOF(SourceJSON))do Begin
BlockRead(SourceJSON,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;
WriteLn(' ':Ident*Spacing,'}');
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;
'[':Begin
WriteLn('[');
Inc(Ident);
Write(' ':Ident*Spacing);
End;
']':Begin
WriteLn(']');
If Ident>0 Then Dec(Ident);
Write(' ':Ident*Spacing);
End;
':':Write(': ');
',':Begin
WriteLn(',');
Write(' ':Ident*Spacing);
End;
#13:WriteLn;
#10:WriteLn;
Else Write(CurrChar);
End;
End;
LastChar:=CurrChar;
End;
Close(SourceJSON);
End;
End;
END.