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 | ---------------------------------------------------------------- {{{ ----------
--: Copyright © 2020 … 2023 Martin Krischik «krischik@users.sourceforge.net»
-------------------------------------------------------------------------------
--: This library is free software; you can redistribute it and/or modify it
--: under the terms of the GNU Library General Public License as published by
--: the Free Software Foundation; either version 2 of the License, or (at your
--: option) any later version.
--:
--: This library is distributed in the hope that it will be useful, but WITHOUT
--: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
--: FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
--: License for more details.
--:
--: You should have received a copy of the GNU Library General Public License
--: along with this library; if not, write to the Free Software Foundation,
--: Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
---------------------------------------------------------------- }}} ----------
pragma License (Modified_Gpl);
pragma Ada_2022;
with Ada.Text_IO;
with Ada.Wide_Text_IO;
with Ada.Strings.UTF_Encoding;
with Ada.Strings.UTF_Encoding.Wide_Strings;
with AdaCL.Trace;
package body HP41CX_Tools.Vector_IO is
use type AdaCL.Trace.Parameter_Vectors.Vector;
function Read_File (File_Name : in String) return HP41CX_Tools.String_Vectors.Vector is
pragma Debug (AdaCL.Trace.Entering (AdaCL.Trace.Parameter & File_Name'Image));
package IO renames Ada.Text_IO;
Retval : HP41CX_Tools.String_Vectors.Vector;
File : IO.File_Type;
begin
IO.Open
(File,
IO.In_File,
File_Name,
Form => "Encoding=UTF8,Text_Translation=U8TEXT,WCEM=8");
while not IO.End_Of_File (File) loop
Retval.Append (IO.Get_Line (File));
end loop;
IO.Close (File);
pragma Debug (AdaCL.Trace.Exiting (Out_Parameter => Retval'Image));
return Retval;
end Read_File;
function Read_File (File_Name : in String) return HP41CX_Tools.Wide_String_Vectors.Vector is
pragma Debug (AdaCL.Trace.Entering (AdaCL.Trace.Parameter & File_Name'Image));
package IO renames Ada.Text_IO;
package Encoding renames Ada.Strings.UTF_Encoding;
Retval : HP41CX_Tools.Wide_String_Vectors.Vector;
File : IO.File_Type;
begin
IO.Open (File, IO.In_File, File_Name);
while not IO.End_Of_File (File) loop
declare
UTF_8_Line : constant Encoding.UTF_8_String := IO.Get_Line (File);
Line : constant Wide_String := Encoding.Wide_Strings.Decode (UTF_8_Line);
begin
Retval.Append (Line);
end;
end loop;
IO.Close (File);
pragma Debug (AdaCL.Trace.Exiting (Out_Parameter => Retval'Image));
return Retval;
end Read_File;
procedure Write_File (File_Name : in String; Text : in String_Vectors.Vector) is
pragma Debug (AdaCL.Trace.Entering (AdaCL.Trace.Parameter & File_Name'Image));
package IO renames Ada.Text_IO;
File : IO.File_Type;
begin
IO.Create
(File,
IO.Out_File,
File_Name,
Form => "Encoding=UTF8,Text_Translation=U8TEXT,WCEM=8");
for Line in Text.Iterate loop
IO.Put_Line (File, Text (Line));
end loop;
IO.Close (File);
pragma Debug (AdaCL.Trace.Exiting);
return;
end Write_File;
procedure Write_File (File_Name : in String; Text : in Wide_String_Vectors.Vector) is
pragma Debug (AdaCL.Trace.Entering (AdaCL.Trace.Parameter & File_Name'Image));
package IO renames Ada.Wide_Text_IO;
File : IO.File_Type;
begin
IO.Create (File, IO.Out_File, File_Name);
for Line in Text.Iterate loop
IO.Put_Line (File, Text (Line));
end loop;
IO.Close (File);
pragma Debug (AdaCL.Trace.Exiting);
return;
end Write_File;
end HP41CX_Tools.Vector_IO;
---------------------------------------------------------------- {{{ ----------
--: vim: set textwidth=0 nowrap tabstop=8 shiftwidth=3 softtabstop=3 expandtab :
--: vim: set filetype=ada fileencoding=utf-8 fileformat=unix foldmethod=expr :
--: vim: set spell spelllang=en_gb :
|