diff options
author | Jed Barber <jjbarber@y7mail.com> | 2017-02-18 22:04:50 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2017-02-18 22:04:50 +1100 |
commit | eea66078d37c7b0f6115b97af222e4e91d61bbf0 (patch) | |
tree | c2ff99a34ee1c6a3969207353313f84c9cc110c1 | |
parent | be9b26ad909dfe973e3ef7756afae6a2b42a41d5 (diff) |
Slightly improved comments, code formatting
-rw-r--r-- | src/preferences.adb | 30 | ||||
-rw-r--r-- | src/simple_time.adb | 12 | ||||
-rw-r--r-- | src/stv.adb | 29 |
3 files changed, 34 insertions, 37 deletions
diff --git a/src/preferences.adb b/src/preferences.adb index 71c521f..7dd6c95 100644 --- a/src/preferences.adb +++ b/src/preferences.adb @@ -50,6 +50,8 @@ package body Preferences is + -- Looks at the raw ranking list above the line and the Above_Ballot and + -- turns it into a list of CandidateIDs in the order they were ranked. function Extract_Formal (Above_Input : in Above_Pref_Array; Formal_Prefs : out Preference_Array) @@ -81,6 +83,8 @@ package body Preferences is + -- Looks at the raw ranking list below the line and the Below_Ballot and + -- turns it into a list of CandidateIDs in the order they were ranked. function Extract_Formal (Below_Input : in Below_Pref_Array; Formal_Prefs : out Preference_Array) @@ -264,31 +268,23 @@ package body Preferences is begin This_In := SU.To_Unbounded_String (Input); - if not Parse_Above_Line (This_In, Above_Line, This_Remaining) then - return Empty_Array; - end if; - - if not Comma (This_Remaining, This_In) then - return Empty_Array; - end if; - - if not Parse_Below_Line (This_In, Below_Line, This_Remaining) then + if not Parse_Above_Line (This_In, Above_Line, This_Remaining) or else + not Comma (This_Remaining, This_In) or else + not Parse_Below_Line (This_In, Below_Line, This_Remaining) + then return Empty_Array; end if; Optional_Line_Ending (This_Remaining, This_In); - if SU.Length (This_In) > 0 then - return Empty_Array; - end if; - - if Extract_Formal (Below_Line, Result) or else - Extract_Formal (Above_Line, Result) + if SU.Length (This_In) > 0 or else + (not Extract_Formal (Below_Line, Result) and then + not Extract_Formal (Above_Line, Result)) then - return Result; - else return Empty_Array; end if; + + return Result; end Parse_Preferences; diff --git a/src/simple_time.adb b/src/simple_time.adb index 7b7abf9..6dab6bc 100644 --- a/src/simple_time.adb +++ b/src/simple_time.adb @@ -30,12 +30,12 @@ package body Simple_Time is Month_Str, Day_Str, Hour_Str, Minute_Str : String (1 .. 2); Second_Str : String (1 .. 12); begin - Move (Trim (Year_Number'Image (Year (Moment)), Left), Year_Str, Left, Right, '0'); - Move (Trim (Month_Number'Image (Month (Moment)), Left), Month_Str, Left, Right, '0'); - Move (Trim (Day_Number'Image (Day (Moment)), Left), Day_Str, Left, Right, '0'); - Move (Trim (Integer'Image (Hours), Left), Hour_Str, Left, Right, '0'); - Move (Trim (Integer'Image (Minutes), Left), Minute_Str, Left, Right, '0'); - Move (Trim (Duration'Image (Seconds), Left), Second_Str, Left, Right, '0'); + Move (Trim (Year_Number'Image (Year (Moment)), Left), Year_Str, Left, Right, '0'); + Move (Trim (Month_Number'Image (Month (Moment)), Left), Month_Str, Left, Right, '0'); + Move (Trim (Day_Number'Image (Day (Moment)), Left), Day_Str, Left, Right, '0'); + Move (Trim (Integer'Image (Hours), Left), Hour_Str, Left, Right, '0'); + Move (Trim (Integer'Image (Minutes), Left), Minute_Str, Left, Right, '0'); + Move (Trim (Duration'Image (Seconds), Left), Second_Str, Left, Right, '0'); return Year_Str & '-' & Month_Str & '-' & Day_Str & " " & Hour_Str & ':' & Minute_Str & ':' & Second_Str; end To_String; diff --git a/src/stv.adb b/src/stv.adb index 78a3052..0b07891 100644 --- a/src/stv.adb +++ b/src/stv.adb @@ -43,7 +43,8 @@ procedure STV is Further_Help : String := "Try ""stv --help"" for more information."; - -- I'm not fond of accesses to string accesses + -- I'm not fond of accesses to string accesses. + -- Would be nice if the GNAT.Strings package would use Unbounded_Strings instead. Verbose : aliased Boolean; Version : aliased Boolean; Help : aliased Boolean; @@ -82,8 +83,8 @@ begin Switch => "-V", Long_Switch => "--version", Help => "show version number"); - -- technically not required, but included so - -- it will show up in the help output + -- Technically not required, but included so + -- it will show up in the help output. GCom.Define_Switch (Config => Config, Output => Help'Access, Switch => "-h", Long_Switch => "--help", @@ -122,7 +123,7 @@ begin "required for normal operation." & ASCII.LF); - -- parse options + -- Parse options begin GCom.Getopt (Config); exception @@ -135,7 +136,7 @@ begin end; - -- version display functionality + -- Version display functionality if Version then Put_Line ("Australian STV Counter v0.2"); ACom.Set_Exit_Status (ACom.Failure); @@ -143,7 +144,7 @@ begin end if; - -- check candidate data option is valid + -- Check candidate data option is valid if Candidate_File.all = "" then Put_Line ("Candidate data file not provided." & ASCII.LF & Further_Help); ACom.Set_Exit_Status (ACom.Failure); @@ -161,7 +162,7 @@ begin end if; - -- check preference data option is valid + -- Check preference data option is valid if Preference_File.all = "" then Put_Line ("Preference data file not provided." & ASCII.LF & Further_Help); ACom.Set_Exit_Status (ACom.Failure); @@ -179,7 +180,7 @@ begin end if; - -- check output directory option is valid + -- Check output directory option is valid if Output_Dir.all = "" then Put_Line ("Output logging directory not provided." & ASCII.LF & Further_Help); ACom.Set_Exit_Status (ACom.Failure); @@ -192,7 +193,7 @@ begin end if; - -- check number to elect option is valid + -- Check number to elect option is valid if Number_To_Elect < 1 then Put_Line ("Number of candidates to be elected too low." & ASCII.LF & Further_Help); ACom.Set_Exit_Status (ACom.Failure); @@ -200,7 +201,7 @@ begin end if; - -- check state option is valid + -- Check state option is valid begin State := Candidates.State_Name'Value (State_String.all); exception @@ -211,7 +212,7 @@ begin end; - -- set up logging + -- Set up logging File.Create_Directory (Output_Dir.all); Start_Time := Simple_Time.Now; Main_Log := SU.To_Unbounded_String (Output_Dir.all & "/" & "log.txt"); @@ -224,7 +225,7 @@ begin end if; - -- read in candidate data, which is necessary for further setup + -- Read in candidate data, which is necessary for further setup if Verbose then Put_Line (Standard_Error, "Reading candidate data..."); end if; @@ -232,7 +233,7 @@ begin Candidates.Containers.Generate_Ballots (Candidate_Data, Above_Ballot, Below_Ballot); - -- set up and run the election singleton + -- Set up and run the election singleton declare package Given_Prefs is new Preferences (Pref_Size => Integer (Below_Ballot.Length), @@ -259,7 +260,7 @@ begin end; - -- finish up logging + -- Finish up logging Finish_Time := Simple_Time.Now; Log_Msg := SU.To_Unbounded_String ("Finished election count at " & Simple_Time.To_String (Finish_Time) & ASCII.LF & |