summaryrefslogtreecommitdiff
path: root/src/deck_io.adb
diff options
context:
space:
mode:
Diffstat (limited to 'src/deck_io.adb')
-rw-r--r--src/deck_io.adb93
1 files changed, 46 insertions, 47 deletions
diff --git a/src/deck_io.adb b/src/deck_io.adb
index 5207fe7..4c87164 100644
--- a/src/deck_io.adb
+++ b/src/deck_io.adb
@@ -8,6 +8,7 @@ with
Ada.Strings.Maps,
Ada.Text_IO,
CSV,
+ Datatypes,
FMD,
GNAT.Regpat,
GNATCOLL.JSON,
@@ -15,7 +16,7 @@ with
use
- Ada.Text_IO;
+ Datatypes;
package body Deck_IO is
@@ -25,6 +26,7 @@ package body Deck_IO is
package FD renames Ada.Directories;
package Strfix renames Ada.Strings.Fixed;
package Strmap renames Ada.Strings.Maps;
+ package TIO renames Ada.Text_IO;
package Pat renames GNAT.Regpat;
package JS renames GNATCOLL.JSON;
@@ -48,7 +50,7 @@ package body Deck_IO is
end To_Unbounded_String;
function To_Unbounded_String
- (Item : in Field)
+ (Item : in Datatypes.Field)
return SU.Unbounded_String is
begin
return SU.Unbounded_String (Item);
@@ -71,12 +73,12 @@ package body Deck_IO is
function Generate_Temp_Name
return String
is
- Handle : File_Type;
+ Handle : TIO.File_Type;
Filename : SU.Unbounded_String;
begin
- Create (File => Handle);
- Filename := +Name (Handle);
- Close (Handle);
+ TIO.Create (File => Handle);
+ Filename := +TIO.Name (Handle);
+ TIO.Close (Handle);
return -Filename;
end Generate_Temp_Name;
@@ -84,8 +86,8 @@ package body Deck_IO is
function Matches
- (Models : in Model_Maps.Map;
- Notes : in Note_Vectors.Vector)
+ (Models : in Model_Map;
+ Notes : in Note_Vector)
return Boolean
is
use type Ada.Containers.Count_Type;
@@ -105,28 +107,30 @@ package body Deck_IO is
procedure Read_Media_Map
(Filename : in String;
- Media_Map : out Media_Maps.Map)
+ Media : out Media_Map)
is
Temp : String := Generate_Temp_Name;
- Input_Handle : File_Type;
+ Input_Handle : TIO.File_Type;
Raw_Data : SU.Unbounded_String;
JSON_Data : JS.JSON_Value;
procedure Map_Iteration
(Name : in JS.UTF8_String;
- Value : in JS.JSON_Value) is
+ Value : in JS.JSON_Value)
+ is
+ Val : SU.Unbounded_String := JS.Get (Value);
begin
- Media_Map.Insert (Media_ID (+Name), JS.Get (Value));
+ Media.Insert (Media_ID (+Name), Media_Name (Val));
end Map_Iteration;
begin
UnZip.Extract (Filename, "media", Temp);
- Open (Input_Handle, In_File, Temp);
- while not End_Of_File (Input_Handle) loop
- SU.Append (Raw_Data, Get_Line (Input_Handle) & Latin.LF);
+ TIO.Open (Input_Handle, TIO.In_File, Temp);
+ while not TIO.End_Of_File (Input_Handle) loop
+ SU.Append (Raw_Data, TIO.Get_Line (Input_Handle) & Latin.LF);
end loop;
- Close (Input_Handle);
+ TIO.Close (Input_Handle);
FD.Delete_File (Temp);
JSON_Data := JS.Read (-Raw_Data);
@@ -174,7 +178,7 @@ package body Deck_IO is
procedure Extract_Field_IDs
(Value : in JS.JSON_Array;
- FIDs : out Field_ID_Vectors.Vector)
+ FIDs : out Field_ID_Vector)
is
Index : Positive;
Item : JS.JSON_Value;
@@ -199,7 +203,7 @@ package body Deck_IO is
procedure Regex_Fields
(Raw_Data : in JS.UTF8_String;
- FIDs : out Field_ID_Vectors.Vector)
+ FIDs : out Field_ID_Vector)
is
use type Pat.Match_Location;
Matches : Pat.Match_Array (0 .. 1);
@@ -225,7 +229,7 @@ package body Deck_IO is
procedure Extract_Templates
(Value : in JS.JSON_Array;
- TMPLs : out Template_Vectors.Vector)
+ TMPLs : out Template_Vector)
is
Index : Positive;
Item : JS.JSON_Value;
@@ -247,7 +251,7 @@ package body Deck_IO is
procedure Extract_Model
(Name : in JS.UTF8_String;
Value : in JS.JSON_Value;
- Models : in out Model_Maps.Map)
+ Models : in out Model_Map)
is
Current_Model : Model;
begin
@@ -259,7 +263,7 @@ package body Deck_IO is
procedure Query_Models
(Deck : in out Deck_Handle;
- Models : out Model_Maps.Map)
+ Models : out Model_Map)
is
Statement : SQLite3.SQLite3_Statement;
Raw_Data : SU.Unbounded_String;
@@ -284,7 +288,7 @@ package body Deck_IO is
procedure Tokenize_Fields
(Raw_Data : in SU.Unbounded_String;
- Fields : out Field_Vectors.Vector)
+ Fields : out Field_Vector)
is
Charset : Strmap.Character_Set := Strmap.To_Set (Latin.US);
Position : Positive := 1;
@@ -293,9 +297,10 @@ package body Deck_IO is
while Next /= 0 and Position <= SU.Length (Raw_Data) loop
Next := SU.Index (Raw_Data, Charset, Position);
if Position <= Next then
- Fields.Append (Field (SU.Unbounded_Slice (Raw_Data, Position, Next - 1)));
+ Fields.Append (Datatypes.Field (SU.Unbounded_Slice
+ (Raw_Data, Position, Next - 1)));
else
- Fields.Append (Field (SU.Unbounded_Slice
+ Fields.Append (Datatypes.Field (SU.Unbounded_Slice
(Raw_Data, Position, SU.Length (Raw_Data))));
end if;
Position := Next + 1;
@@ -305,7 +310,7 @@ package body Deck_IO is
procedure Query_Notes
(Deck : in out Deck_Handle;
- Notes : out Note_Vectors.Vector)
+ Notes : out Note_Vector)
is
use type SQLite3.Status_Code;
Statement : SQLite3.SQLite3_Statement;
@@ -349,17 +354,15 @@ package body Deck_IO is
procedure Write_CSV
(Directory : in String;
Basename : in String;
- Models : in Model_Maps.Map;
- Notes : in Note_Vectors.Vector;
+ Models : in Model_Map;
+ Notes : in Note_Vector;
Overwrite : in Boolean := False)
is
package My_CSV is new CSV;
- procedure Put_Header is new My_CSV.Put_Row (Field_Ordinal, Field_ID, Field_ID_Vectors);
- procedure Put_Row is new My_CSV.Put_Row (Field_Ordinal, Field, Field_Vectors);
Counter : Positive := 1;
Outname : SU.Unbounded_String;
- File_Handle : File_Type;
+ File_Handle : TIO.File_Type;
Row_Size : Positive;
begin
for C in Models.Iterate loop
@@ -371,15 +374,15 @@ package body Deck_IO is
FD.Delete_File (-Outname);
end if;
end if;
- Create (File_Handle, Out_File, -Outname);
+ TIO.Create (File_Handle, TIO.Out_File, -Outname);
Row_Size := Positive (Model_Maps.Element (C).Fields.Length);
- Put_Header (File_Handle, Model_Maps.Element (C).Fields, Row_Size);
+ My_CSV.Put_Header (File_Handle, Model_Maps.Element (C).Fields);
for N of Notes loop
if N.Model = Model_Maps.Key (C) then
- Put_Row (File_Handle, N.Fields, Row_Size);
+ My_CSV.Put_Row (File_Handle, N.Fields, Row_Size);
end if;
end loop;
- Close (File_Handle);
+ TIO.Close (File_Handle);
Counter := Counter + 1;
end loop;
end Write_CSV;
@@ -390,18 +393,14 @@ package body Deck_IO is
procedure Write_FMD
(Directory : in String;
Basename : in String;
- Models : in Model_Maps.Map;
- Notes : in Note_Vectors.Vector;
- Media : in Media_Maps.Map;
+ Models : in Model_Map;
+ Notes : in Note_Vector;
+ Media : in Media_Map;
Overwrite : in Boolean := False)
is
- procedure Put_Fields is new FMD.Put_Fields (Field_Ordinal, Field_ID, Field_ID_Vectors);
- procedure Put_Pack is new FMD.Put_Pack (Field_Ordinal, Field_ID, Field_ID_Vectors);
- procedure Put_Entry is new FMD.Put_Entry (Field_Ordinal, Field, Field_Vectors);
-
Counter : Positive := 1;
Outname : SU.Unbounded_String;
- File_Handle : File_Type;
+ File_Handle : TIO.File_Type;
Entry_Size : Positive;
begin
for C in Models.Iterate loop
@@ -413,24 +412,24 @@ package body Deck_IO is
FD.Delete_File (-Outname);
end if;
end if;
- Create (File_Handle, Out_File, -Outname);
+ TIO.Create (File_Handle, TIO.Out_File, -Outname);
Entry_Size := Positive (Model_Maps.Element (C).Fields.Length);
FMD.Put_Header (File_Handle);
- Put_Fields (File_Handle, Model_Maps.Element (C).Fields);
+ FMD.Put_Fields (File_Handle, Model_Maps.Element (C).Fields);
FMD.Start_Pack_Section (File_Handle);
for Tmpl of Model_Maps.Element (C).Templates loop
- Put_Pack (File_Handle, Tmpl.Question, Tmpl.Answer);
+ FMD.Put_Pack (File_Handle, Tmpl.Question, Tmpl.Answer);
end loop;
FMD.End_Pack_Section (File_Handle);
FMD.Start_Entry_Section (File_Handle);
for N of Notes loop
if N.Model = Model_Maps.Key (C) then
- Put_Entry (File_Handle, N.Fields, Entry_Size);
+ FMD.Put_Entry (File_Handle, N.Fields, Entry_Size);
end if;
end loop;
FMD.End_Entry_Section (File_Handle);
FMD.Put_Footer (File_Handle);
- Close (File_Handle);
+ TIO.Close (File_Handle);
Counter := Counter + 1;
end loop;
end Write_FMD;