-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBIN2CSP.PAS
61 lines (56 loc) · 1.5 KB
/
BIN2CSP.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
{ @author: Sylvain Maltais ([email protected])
@created: 2023
@website(https://www.gladir.com/corail)
@abstract(Target: Turbo Pascal 7, Free Pascal)
}
Program BIN2CSP;
Var
Source:File{$IFDEF FPC} of Byte{$ENDIF};
Target:Text;
Tampon:Array[0..0]of Byte;
ByteReaded:Integer;
Position:Byte;
Function ByteHex2Str(value:Byte):String;
Const
matrix:Array[0..15]of Char = ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
Begin
ByteHex2Str:=matrix[(value shr 4) and $0F]+matrix[value and $F];
End;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')Then Begin
WriteLn('BIN2CSP : Cette commande permet de convertir un fichier binaire en tableau de CSP (C Server Pages).');
WriteLn;
WriteLn('Syntaxe : BIN2CSP fichier fichier.csp');
End
Else
If ParamCount=2Then Begin
Assign(Source,ParamStr(1));
Reset(Source);
Assign(Target,ParamStr(2));
Rewrite(Target);
Position:=0;
WriteLn(Target,'<%');
WriteLn(Target,'const unsigned char samples[',FileSize(Source),'] = {');
Write(Target,' ');
While Not EOF(Source)do Begin
BlockRead(Source,Tampon,1,ByteReaded);
Write(Target,'0x',ByteHex2Str(Tampon[0]));
If Not EOF(Source)Then Begin
Write(Target,', ');
Inc(Position);
If Position=8Then BEgin
WriteLn(Target);
Write(Target,' ');
End;
Position:=Position and 7;
End;
End;
WriteLn(Target);
WriteLn(Target,'};');
WriteLn(Target,'%>');
Close(Target);
Close(Source);
End
Else
WriteLn('Parametre invalide !');
END.