Commit 6390ff4c authored by Julian Trischler's avatar Julian Trischler

Added AdaDoc and using current time if not given.

parent 87fbdc0f
......@@ -5,14 +5,21 @@
-- This software was written by Julian 'Lyse' Trischler on June 18th 2010 --
-- and is published under Do-What-The-Fuck-You-Want-To-Public-License. --
-- --
-- Version 0.8 (2010-06-18) --
-- Version 1.0 (2010-06-18) --
-- * Initial release --
-- --
-- Version 1.1 (2010-10-04) --
-- * Using current time when no command line time given --
----------------------------------------------------------------------------
with Ada.Text_IO;
with Ada.Command_Line;
with Ada.Exceptions;
with Ada.Calendar;
procedure Wie_Schbaed is
VERSION: constant String := "1.1";
RELEASE: constant String := "2010-10-04";
------------------------------------------------------------------------
-- @Type: Hour --
......@@ -22,7 +29,7 @@ procedure Wie_Schbaed is
-- @See: Second --
-- @See: Time --
------------------------------------------------------------------------
type Hour is new Integer range 0..23;
type Hour is new Integer range 0 .. 23;
------------------------------------------------------------------------
-- @Type: Minute --
......@@ -31,7 +38,7 @@ procedure Wie_Schbaed is
-- @See: Second --
-- @See: Time --
------------------------------------------------------------------------
type Minute is new Integer range 0..59;
type Minute is new Integer range 0 .. 59;
------------------------------------------------------------------------
-- @Type: Second --
......@@ -42,7 +49,7 @@ procedure Wie_Schbaed is
-- @See: Minute --
-- @See: Time --
------------------------------------------------------------------------
type Second is new Integer range 0..59;
type Second is new Integer range 0 .. 59;
------------------------------------------------------------------------
-- @Type: Time --
......@@ -105,6 +112,17 @@ procedure Wie_Schbaed is
& Format(Integer(T.S));
end Str;
------------------------------------------------------------------------
-- @Function: Str --
-- @Description: Converts the given hour into the written Swabian --
-- string representation. Hours from 0..11 and 12..23 --
-- are treated equally. So '12' and '0' both becomes --
-- 'zwölfe'. --
-- @Parameters: --
-- +H: The hour to convert into Swabian string representation --
-- @Return: Swabian string representation of the given hour --
-- @See: Special_Str --
------------------------------------------------------------------------
function Str(H: Hour) return String is
begin
case H is
......@@ -155,11 +173,33 @@ procedure Wie_Schbaed is
end case;
end;
------------------------------------------------------------------------
-- @Procedure: Test --
-- @Description: Prints the given time in standard ISO format and --
-- separated with an ASCII art double arrow the Swabian --
-- string representation. --
-- @Purpose: This procedure can be used for testing the library. But --
-- human checks are required, too. --
-- @Parameters: --
-- +T: The time to print out to StdOut. --
-- @Return: String representation of the given time in format --
-- 'HH:MM:SS => W', where 'H' is the hour, 'M' the minute, --
-- 'S' the second and 'W' the Swabian time string. --
-- @See: Str --
-- @See: Time_To_String --
------------------------------------------------------------------------
procedure Test(T: Time) is
begin
Ada.Text_IO.Put_Line(Str(T) & " => " & Time_To_String(T));
end Test;
------------------------------------------------------------------------
-- @Exception: Input_Error --
-- @Purpose: Raised whenever Time_From_String fails to convert a --
-- ISO formatted time string into a Time object. --
-- @See: Time_From_String --
-- @See: Time --
------------------------------------------------------------------------
Input_Error: exception;
-- Data'First must equal Pattern'First
......@@ -233,7 +273,17 @@ procedure Wie_Schbaed is
return T;
end Time_From_String;
procedure Put_Usage is
begin
Ada.Text_IO.Put_Line("wieschbaed - „Wie schbäd?“ - „Wie spät ist es?“ - „What time is it?“");
Ada.Text_IO.Put_Line("This program displays the given or current time in Swabian.");
Ada.Text_IO.Put_Line("Usage: " & Ada.Command_Line.Command_Name & " [ <TIME> | --help | --version ]");
Ada.Text_IO.Put_Line(" <TIME> in one of the following formats:");
Ada.Text_IO.Put_Line(" HH:MM:SS - HH:MM - HHMMSS - HHMM");
end Put_Usage;
T: Time;
Secs: Ada.Calendar.Day_Duration;
begin
-- try to read the command line argument, it should be in one
......@@ -249,6 +299,13 @@ begin
declare
Input: String := Ada.Command_Line.Argument(1);
begin
if Input = "--help" then
Put_Usage;
return;
elsif Input = "--version" then
Ada.Text_IO.Put_Line("wieschbaed Version " & VERSION & " (" & RELEASE & ")");
return;
end if;
-- input length must be correct; as mentioned above, the formats
-- used at the moment are 4, 5, 6 or 8 characters long
......@@ -285,21 +342,20 @@ begin
raise Input_Error with "Illegal time data length";
end case;
end;
--Test(T);
Ada.Text_IO.Put_Line(Time_To_String(T));
else
Ada.Text_IO.Put_Line("wieschbaed - „Wie schbäd?“ - „Wie spät ist es?“ - „What time is it?“");
Ada.Text_IO.Put_Line("This program displays the given time in Swabian.");
Ada.Text_IO.Put_Line("Usage: " & Ada.Command_Line.Command_Name & " <TIME>");
Ada.Text_IO.Put_Line(" <TIME> in one of the following formats:");
Ada.Text_IO.Put_Line(" HH:MM:SS - HH:MM - HHMMSS - HHMM");
Secs := Ada.Calendar.Seconds(Ada.Calendar.Clock);
T.H := Hour(Integer(Secs) / 60 / 60);
T.M := Minute(Integer(Integer(Secs) / 60) mod 60);
T.S := 0;
Ada.Text_IO.Put_Line(Time_To_String(T));
end if;
exception
when E: Input_Error =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
Ada.Exceptions.Exception_Message(E));
Put_Usage;
Ada.Command_Line.Set_Exit_Status(1);
when E: others =>
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
......
......@@ -15,14 +15,21 @@
<i><span style='color:#808080;'>-- This software was written by Julian 'Lyse' Trischler on June 18th 2010 --</span></i>
<i><span style='color:#808080;'>-- and is published under Do-What-The-Fuck-You-Want-To-Public-License. --</span></i>
<i><span style='color:#808080;'>-- --</span></i>
<i><span style='color:#808080;'>-- Version 0.8 (2010-06-18) --</span></i>
<i><span style='color:#808080;'>-- Version 1.0 (2010-06-18) --</span></i>
<i><span style='color:#808080;'>-- * Initial release --</span></i>
<i><span style='color:#808080;'>-- --</span></i>
<i><span style='color:#808080;'>-- Version 1.1 (2010-10-04) --</span></i>
<i><span style='color:#808080;'>-- * Using current time when no command line time given --</span></i>
<i><span style='color:#808080;'>----------------------------------------------------------------------------</span></i>
<b>with</b> Ada.Text_IO;
<b>with</b> Ada.Command_Line;
<b>with</b> Ada.Exceptions;
<b>with</b> Ada.Calendar;
<b>procedure</b> Wie_Schbaed <b>is</b>
VERSION: <b>constant</b> <span style='color:#800000;'>String</span> := <span style='color:#dd0000;'>&quot;1.1&quot;</span>;
RELEASE: <b>constant</b> <span style='color:#800000;'>String</span> := <span style='color:#dd0000;'>&quot;2010-10-04&quot;</span>;
<i><span style='color:#808080;'>------------------------------------------------------------------------</span></i>
<i><span style='color:#808080;'>-- @Type: Hour --</span></i>
......@@ -32,7 +39,7 @@
<i><span style='color:#808080;'>-- @See: Second --</span></i>
<i><span style='color:#808080;'>-- @See: Time --</span></i>
<i><span style='color:#808080;'>------------------------------------------------------------------------</span></i>
<b>type</b> Hour <b>is</b> <b>new</b> <span style='color:#800000;'>Integer</span> <b>range</b> <span style='color:#800080;'>0..23</span>;
<b>type</b> Hour <b>is</b> <b>new</b> <span style='color:#800000;'>Integer</span> <b>range</b> <span style='color:#0000ff;'>0</span> .. <span style='color:#0000ff;'>23</span>;
<i><span style='color:#808080;'>------------------------------------------------------------------------</span></i>
<i><span style='color:#808080;'>-- @Type: Minute --</span></i>
......@@ -41,7 +48,7 @@
<i><span style='color:#808080;'>-- @See: Second --</span></i>
<i><span style='color:#808080;'>-- @See: Time --</span></i>
<i><span style='color:#808080;'>------------------------------------------------------------------------</span></i>
<b>type</b> Minute <b>is</b> <b>new</b> <span style='color:#800000;'>Integer</span> <b>range</b> <span style='color:#800080;'>0..59</span>;
<b>type</b> Minute <b>is</b> <b>new</b> <span style='color:#800000;'>Integer</span> <b>range</b> <span style='color:#0000ff;'>0</span> .. <span style='color:#0000ff;'>59</span>;
<i><span style='color:#808080;'>------------------------------------------------------------------------</span></i>
<i><span style='color:#808080;'>-- @Type: Second --</span></i>
......@@ -52,7 +59,7 @@
<i><span style='color:#808080;'>-- @See: Minute --</span></i>
<i><span style='color:#808080;'>-- @See: Time --</span></i>
<i><span style='color:#808080;'>------------------------------------------------------------------------</span></i>
<b>type</b> Second <b>is</b> <b>new</b> <span style='color:#800000;'>Integer</span> <b>range</b> <span style='color:#800080;'>0..59</span>;
<b>type</b> Second <b>is</b> <b>new</b> <span style='color:#800000;'>Integer</span> <b>range</b> <span style='color:#0000ff;'>0</span> .. <span style='color:#0000ff;'>59</span>;
<i><span style='color:#808080;'>------------------------------------------------------------------------</span></i>
<i><span style='color:#808080;'>-- @Type: Time --</span></i>
......@@ -115,6 +122,17 @@
&amp; Format(<span style='color:#800000;'>Integer</span>(T.S));
<b>end</b> Str;
<i><span style='color:#808080;'>------------------------------------------------------------------------</span></i>
<i><span style='color:#808080;'>-- @Function: Str --</span></i>
<i><span style='color:#808080;'>-- @Description: Converts the given hour into the written Swabian --</span></i>
<i><span style='color:#808080;'>-- string representation. Hours from 0..11 and 12..23 --</span></i>
<i><span style='color:#808080;'>-- are treated equally. So '12' and '0' both becomes --</span></i>
<i><span style='color:#808080;'>-- 'zwölfe'. --</span></i>
<i><span style='color:#808080;'>-- @Parameters: --</span></i>
<i><span style='color:#808080;'>-- +H: The hour to convert into Swabian string representation --</span></i>
<i><span style='color:#808080;'>-- @Return: Swabian string representation of the given hour --</span></i>
<i><span style='color:#808080;'>-- @See: Special_Str --</span></i>
<i><span style='color:#808080;'>------------------------------------------------------------------------</span></i>
<b>function</b> Str(H: Hour) <b>return</b> <span style='color:#800000;'>String</span> <b>is</b>
<b>begin</b>
<b>case</b> H <b>is</b>
......@@ -165,11 +183,33 @@
<b>end case</b>;
<b>end</b>;
<i><span style='color:#808080;'>------------------------------------------------------------------------</span></i>
<i><span style='color:#808080;'>-- @Procedure: Test --</span></i>
<i><span style='color:#808080;'>-- @Description: Prints the given time in standard ISO format and --</span></i>
<i><span style='color:#808080;'>-- separated with an ASCII art double arrow the Swabian --</span></i>
<i><span style='color:#808080;'>-- string representation. --</span></i>
<i><span style='color:#808080;'>-- @Purpose: This procedure can be used for testing the library. But --</span></i>
<i><span style='color:#808080;'>-- human checks are required, too. --</span></i>
<i><span style='color:#808080;'>-- @Parameters: --</span></i>
<i><span style='color:#808080;'>-- +T: The time to print out to StdOut. --</span></i>
<i><span style='color:#808080;'>-- @Return: String representation of the given time in format --</span></i>
<i><span style='color:#808080;'>-- 'HH:MM:SS =&gt; W', where 'H' is the hour, 'M' the minute, --</span></i>
<i><span style='color:#808080;'>-- 'S' the second and 'W' the Swabian time string. --</span></i>
<i><span style='color:#808080;'>-- @See: Str --</span></i>
<i><span style='color:#808080;'>-- @See: Time_To_String --</span></i>
<i><span style='color:#808080;'>------------------------------------------------------------------------</span></i>
<b>procedure</b> Test(T: Time) <b>is</b>
<b>begin</b>
Ada.Text_IO.Put_Line(Str(T) &amp; <span style='color:#dd0000;'>&quot; =&gt; &quot;</span> &amp; Time_To_String(T));
<b>end</b> Test;
<i><span style='color:#808080;'>------------------------------------------------------------------------</span></i>
<i><span style='color:#808080;'>-- @Exception: Input_Error --</span></i>
<i><span style='color:#808080;'>-- @Purpose: Raised whenever Time_From_String fails to convert a --</span></i>
<i><span style='color:#808080;'>-- ISO formatted time string into a Time object. --</span></i>
<i><span style='color:#808080;'>-- @See: Time_From_String --</span></i>
<i><span style='color:#808080;'>-- @See: Time --</span></i>
<i><span style='color:#808080;'>------------------------------------------------------------------------</span></i>
Input_Error: <b>exception</b>;
<i><span style='color:#808080;'>-- Data'First must equal Pattern'First</span></i>
......@@ -243,7 +283,17 @@
<b>return</b> T;
<b>end</b> Time_From_String;
<b>procedure</b> Put_Usage <b>is</b>
<b>begin</b>
Ada.Text_IO.Put_Line(<span style='color:#dd0000;'>&quot;wieschbaed - „Wie schbäd?“ - „Wie spät ist es?“ - „What time is it?“&quot;</span>);
Ada.Text_IO.Put_Line(<span style='color:#dd0000;'>&quot;This program displays the given or current time in Swabian.&quot;</span>);
Ada.Text_IO.Put_Line(<span style='color:#dd0000;'>&quot;Usage: &quot;</span> &amp; Ada.Command_Line.Command_Name &amp; <span style='color:#dd0000;'>&quot; [ &lt;TIME&gt; | --help | --version ]&quot;</span>);
Ada.Text_IO.Put_Line(<span style='color:#dd0000;'>&quot; &lt;TIME&gt; in one of the following formats:&quot;</span>);
Ada.Text_IO.Put_Line(<span style='color:#dd0000;'>&quot; HH:MM:SS - HH:MM - HHMMSS - HHMM&quot;</span>);
<b>end</b> Put_Usage;
T: Time;
Secs: Ada.Calendar.Day_Duration;
<b>begin</b>
<i><span style='color:#808080;'>-- try to read the command line argument, it should be in one</span></i>
......@@ -259,6 +309,13 @@
<b>declare</b>
Input: <span style='color:#800000;'>String</span> := Ada.Command_Line.Argument(<span style='color:#0000ff;'>1</span>);
<b>begin</b>
<b>if</b> Input = <span style='color:#dd0000;'>&quot;--help&quot;</span> <b>then</b>
Put_Usage;
<b>return</b>;
<b>elsif</b> Input = <span style='color:#dd0000;'>&quot;--version&quot;</span> <b>then</b>
Ada.Text_IO.Put_Line(<span style='color:#dd0000;'>&quot;wieschbaed Version &quot;</span> &amp; VERSION &amp; <span style='color:#dd0000;'>&quot; (&quot;</span> &amp; RELEASE &amp; <span style='color:#dd0000;'>&quot;)&quot;</span>);
<b>return</b>;
<b>end if</b>;
<i><span style='color:#808080;'>-- input length must be correct; as mentioned above, the formats</span></i>
<i><span style='color:#808080;'>-- used at the moment are 4, 5, 6 or 8 characters long</span></i>
......@@ -295,21 +352,20 @@
<b>raise</b> Input_Error <b>with</b> <span style='color:#dd0000;'>&quot;Illegal time data length&quot;</span>;
<b>end case</b>;
<b>end</b>;
<i><span style='color:#808080;'>--Test(T);</span></i>
Ada.Text_IO.Put_Line(Time_To_String(T));
<b>else</b>
Ada.Text_IO.Put_Line(<span style='color:#dd0000;'>&quot;wieschbaed - „Wie schbäd?“ - „Wie spät ist es?“ - „What time is it?“&quot;</span>);
Ada.Text_IO.Put_Line(<span style='color:#dd0000;'>&quot;This program displays the given time in Swabian.&quot;</span>);
Ada.Text_IO.Put_Line(<span style='color:#dd0000;'>&quot;Usage: &quot;</span> &amp; Ada.Command_Line.Command_Name &amp; <span style='color:#dd0000;'>&quot; &lt;TIME&gt;&quot;</span>);
Ada.Text_IO.Put_Line(<span style='color:#dd0000;'>&quot; &lt;TIME&gt; in one of the following formats:&quot;</span>);
Ada.Text_IO.Put_Line(<span style='color:#dd0000;'>&quot; HH:MM:SS - HH:MM - HHMMSS - HHMM&quot;</span>);
Secs := Ada.Calendar.Seconds(Ada.Calendar.Clock);
T.H := Hour(<span style='color:#800000;'>Integer</span>(Secs) / <span style='color:#0000ff;'>60</span> / <span style='color:#0000ff;'>60</span>);
T.M := Minute(<span style='color:#800000;'>Integer</span>(<span style='color:#800000;'>Integer</span>(Secs) / <span style='color:#0000ff;'>60</span>) <b>mod</b> <span style='color:#0000ff;'>60</span>);
T.S := <span style='color:#0000ff;'>0</span>;
Ada.Text_IO.Put_Line(Time_To_String(T));
<b>end if</b>;
<b>exception</b>
<b>when</b> E: Input_Error =&gt;
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
Ada.Exceptions.Exception_Message(E));
Put_Usage;
Ada.Command_Line.Set_Exit_Status(<span style='color:#0000ff;'>1</span>);
<b>when</b> E: <b>others</b> =&gt;
Ada.Text_IO.Put_Line(Ada.Text_IO.Standard_Error,
......
#!/bin/bash
./wie_schbaed `date +%H:%M:%S`
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment