Index: tools/smaz.adb ================================================================== --- tools/smaz.adb +++ tools/smaz.adb @@ -19,10 +19,11 @@ ------------------------------------------------------------------------------ with Ada.Characters.Latin_1; with Ada.Command_Line; with Ada.Streams; +with Ada.Strings.Fixed; with Ada.Strings.Unbounded; with Ada.Text_IO.Text_Streams; with Natools.Getopt_Long; with Natools.S_Expressions.Parsers; with Natools.S_Expressions.Printers; @@ -35,11 +36,12 @@ package Actions is type Enum is (Nothing, Decode, - Encode); + Encode, + Evaluate); end Actions; package Dict_Sources is type Enum is (S_Expression, @@ -50,10 +52,11 @@ type Id is (Output_Ada_Dict, Dictionary_Input, Decode, Encode, + Evaluate, Output_Hash, Help, Sx_Dict_Output, Min_Sub_Size, Max_Sub_Size, @@ -133,10 +136,14 @@ when Options.Encode => Handler.Need_Dictionary := True; Handler.Action := Actions.Encode; + when Options.Evaluate => + Handler.Need_Dictionary := True; + Handler.Action := Actions.Evaluate; + when Options.No_Stat_Output => Handler.Stat_Output := False; when Options.No_Sx_Output => Handler.Sx_Output := False; @@ -192,10 +199,11 @@ begin R.Add_Option ("ada-dict", 'A', Optional_Argument, Output_Ada_Dict); R.Add_Option ("decode", 'd', No_Argument, Decode); R.Add_Option ("dict", 'D', No_Argument, Dictionary_Input); R.Add_Option ("encode", 'e', No_Argument, Encode); + R.Add_Option ("evaluate", 'E', No_Argument, Evaluate); R.Add_Option ("help", 'h', No_Argument, Help); R.Add_Option ("hash-pkg", 'H', Required_Argument, Output_Hash); R.Add_Option ("sx-dict", 'L', No_Argument, Sx_Dict_Output); R.Add_Option ("min-substring", 'm', Required_Argument, Min_Sub_Size); R.Add_Option ("max-substring", 'M', Required_Argument, Max_Sub_Size); @@ -344,10 +352,15 @@ when Options.Max_Word_Size => New_Line (Output); Put_Line (Output, Indent & Indent & "Maximum word size when building a dictionary"); + + when Options.Evaluate => + New_Line (Output); + Put_Line (Output, Indent & Indent + & "Evaluate the dictionary on the input given corpus"); end case; end loop; end Print_Help; function To_Dictionary @@ -549,8 +562,40 @@ end loop; Print_Line (Original_Total, Output_Total, Base64_Total); end; end if; + + when Actions.Evaluate => + declare + Total_Size : Ada.Streams.Stream_Element_Count; + Counts : Natools.Smaz.Tools.Dictionary_Counts; + begin + Natools.Smaz.Tools.Evaluate_Dictionary + (Dictionary, Input_Data, Total_Size, Counts); + + if Handler.Sx_Output then + Sx_Output.Open_List; + Sx_Output.Append_String (Ada.Strings.Fixed.Trim + (Ada.Streams.Stream_Element_Count'Image (Total_Size), + Ada.Strings.Both)); + + for E in Dictionary.Offsets'Range loop + Sx_Output.Open_List; + Sx_Output.Append_Atom ((0 => E)); + Sx_Output.Append_String + (Natools.Smaz.Dict_Entry (Dictionary, E)); + Sx_Output.Append_String (Ada.Strings.Fixed.Trim + (Natools.Smaz.Tools.String_Count'Image (Counts (E)), + Ada.Strings.Both)); + Sx_Output.Close_List; + end loop; + Sx_Output.Close_List; + end if; + + if Handler.Stat_Output then + Ada.Text_IO.Put_Line ("Not implemented yet"); + end if; + end; end case; end Build_Dictionary; end Smaz;