From a7c1795a6162181a39366e99a60ee65a342a66f8 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Fri, 5 Nov 2021 18:36:56 +1300 Subject: Added option to strip formatting from deck notes --- src/deck_convert.adb | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/src/deck_convert.adb b/src/deck_convert.adb index 3b15a2f..6154b1c 100644 --- a/src/deck_convert.adb +++ b/src/deck_convert.adb @@ -45,6 +45,41 @@ procedure Deck_Convert is renames SU.To_String; + procedure Strip_Formatting + (Notes : in out Deck_IO.Note_Vectors.Vector) + is + procedure Strip + (Text : in out Deck_IO.Note; + Item : in String) + is + Position : Natural; + begin + for F of Text.Fields loop + loop + Position := SU.Index + (Source => SU.Unbounded_String (F), + Pattern => Item, + Going => Ada.Strings.Forward, + Mapping => Charhand.To_Lower'Access); + exit when Position = 0; + SU.Delete (SU.Unbounded_String (F), Position, Position + Item'Length - 1); + end loop; + end loop; + end Strip; + + Formatting : array (Positive range <>) of SU.Unbounded_String := + (+"", +"", +"", +"", +"", +"", +"", +"", + +"", +"", +"", +"", +"", +"", + +"", +"", +"", +"", +"", +""); + begin + for N of Notes loop + for S of Formatting loop + Strip (N, -S); + end loop; + end loop; + end Strip_Formatting; + + Config : GCom.Command_Line_Configuration; @@ -54,6 +89,7 @@ procedure Deck_Convert is Verbose : aliased Boolean; Help : aliased Boolean; Overwrite : aliased Boolean; + Strip_Form : aliased Boolean; Format_Arg : aliased GStr.String_Access; Input_Arg : aliased GStr.String_Access; Output_Arg : aliased GStr.String_Access; @@ -91,7 +127,7 @@ begin GCom.Define_Switch (Config => Config, Output => Format_Arg'Access, Switch => "-t:", Long_Switch => "--type=", - Help => "format of output data, valid options are CSV or FMD, default is FMD"); + Help => "format of output data, options are CSV or FMD, default is FMD"); GCom.Define_Switch (Config => Config, Output => Input_Arg'Access, @@ -103,6 +139,11 @@ begin Switch => "-o:", Long_Switch => "--output=", Help => "base name to store output data"); + GCom.Define_Switch + (Config => Config, Output => Strip_Form'Access, + Switch => "-b", Long_Switch => "--bare", + Help => "strip formatting from deck notes"); + GCom.Set_Usage (Config => Config, @@ -200,6 +241,17 @@ begin New_Line (Standard_Error); end if; + if Strip_Form then + if Verbose then + Put (Standard_Error, "Stripping formatting from deck notes..."); + end if; + Strip_Formatting (Notes); + if Verbose then + Put_Line (Standard_Error, " Done"); + New_Line (Standard_Error); + end if; + end if; + declare Contain_Dir : String := FD.Containing_Directory (-Output_Name); Simple_Name : String := FD.Simple_Name (-Output_Name); -- cgit