Index: tools/smaz.adb ================================================================== --- tools/smaz.adb +++ tools/smaz.adb @@ -52,10 +52,11 @@ Dictionary_Input, Decode, Encode, Output_Hash, Help, + Sx_Dict_Output, Stat_Output, No_Stat_Output, Word_List_Input, Sx_Output, No_Sx_Output); @@ -66,10 +67,11 @@ type Callback is new Getopt.Handlers.Callback with record Display_Help : Boolean := False; Need_Dictionary : Boolean := False; Stat_Output : Boolean := False; Sx_Output : Boolean := False; + Sx_Dict_Output : Boolean := False; Action : Actions.Enum := Actions.Nothing; Ada_Dictionary : Ada.Strings.Unbounded.Unbounded_String; Hash_Package : Ada.Strings.Unbounded.Unbounded_String; Dict_Source : Dict_Sources.Enum := Dict_Sources.S_Expression; end record; @@ -158,10 +160,14 @@ when Options.Dictionary_Input => Handler.Dict_Source := Dict_Sources.S_Expression; when Options.Word_List_Input => Handler.Dict_Source := Dict_Sources.Word_List; + + when Options.Sx_Dict_Output => + Handler.Need_Dictionary := True; + Handler.Sx_Dict_Output := True; end case; end Option; function Getopt_Config return Getopt.Configuration is @@ -173,10 +179,11 @@ 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 ("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 ("stats", 's', No_Argument, Stat_Output); R.Add_Option ("no-stats", 'S', No_Argument, No_Stat_Output); R.Add_Option ("word-list", 'w', No_Argument, Word_List_Input); R.Add_Option ("s-expr", 'x', No_Argument, Sx_Output); R.Add_Option ("no-s-expr", 'X', No_Argument, No_Sx_Output); @@ -299,10 +306,15 @@ when Options.Word_List_Input => New_Line (Output); Put_Line (Output, Indent & Indent & "Compute dictionary from word list in input S-expression"); + + when Options.Sx_Dict_Output => + New_Line (Output); + Put_Line (Output, Indent & Indent + & "Output the dictionary as a S-expression"); end case; end loop; end Print_Help; function To_Dictionary @@ -321,11 +333,11 @@ for S of Input loop Natools.Smaz.Tools.Add_Substrings (Counter, S, 1, 3); end loop; return Natools.Smaz.Tools.To_Dictionary - (Natools.Smaz.Tools.Most_Common_Words (Counter, 254), + (Natools.Smaz.Tools.Simple_Dictionary (Counter, 254), True); end; end case; end To_Dictionary; @@ -392,10 +404,19 @@ end if; if Hash_Package'Length > 0 then Natools.Smaz.Tools.GNAT.Build_Perfect_Hash (Input_List, Hash_Package); end if; + + if Handler.Sx_Dict_Output then + Sx_Output.Open_List; + for I in Dictionary.Offsets'Range loop + Sx_Output.Append_String + (Natools.Smaz.Dict_Entry (Dictionary, I)); + end loop; + Sx_Output.Close_List; + end if; case Handler.Action is when Actions.Nothing => null; when Actions.Decode =>