-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTXT2INC.PAS
66 lines (62 loc) · 1.61 KB
/
TXT2INC.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
{ @author: Sylvain Maltais (support@gladir.com)
@created: 2023
@website(https://www.gladir.com/dev-cools)
@abstract(Target: Turbo Pascal 7, Free Pascal 3.2)
}
Program TXT2INC;
Var
SourceASC,TargetPas:Text;
CurrLine:String;
Function StringToPascalString(Source:String):String;
Var
I:Integer;
ConvStr:String;
Begin
ConvStr:='';
For I:=1 to Length(Source)do Begin
If Source[I]=''''Then ConvStr:=ConvStr+'''';
ConvStr:=ConvStr+Source[I];
End;
StringToPascalString:=ConvStr;
End;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')or
(ParamStr(1)='/h')or(ParamStr(1)='/H')Then Begin
WriteLn('TXT2INC : Cette commande permet de convertir un ',
'texte en chaine de caractŠres entre guillemet ',
'pour Pascal.');
WriteLn;
WriteLn('Syntaxe : TXT2INC source target constname');
WriteLn;
End
Else
If ParamCount>0 Then Begin
Assign(SourceASC,ParamStr(1));
{$I-}Reset(SourceASC);{$I+}
If IoResult<>0Then Begin
WriteLn('Fichier ASCII introuvable !');
Halt;
End;
Assign(TargetPas,ParamStr(2));
{$I+}Rewrite(TargetPas); {$I+}
If IoResult<>0Then Begin
WriteLn('Impossible de cr‚er le fichier Pascal !');
Close(SourceASC);
Halt;
End;
WriteLn(TargetPas,'Const ',ParamStr(3),':String=');
While Not EOF(SourceASC)do Begin
ReadLn(SourceASC,CurrLine);
If CurrLine=''Then WriteLn(TargetPas,' LineEnding +')
Else
Begin
WriteLn(TargetPas,' ''',StringToPascalString(CurrLine),''' + LineEnding +');
End;
End;
WriteLn(TargetPas,''''';');
Close(TargetPas);
Close(SourceASC);
End
Else
WriteLn('ParamŠtre requis !');
END.