乱入1
http://d.hatena.ne.jp/w_o/20050308#p1
単に私はこういうのが好きなだけですので本論は無視します。
Adaが63行。空白行は一行も無くてもそこそこ読める、それがPascal系。
with Ada.Text_IO; with Ada.IO_Exceptions; with Ada.Command_Line; with Ada.Calendar.Formatting; with Ada.Calendar.Time_Zones; with Ada.Directories; procedure w_o_Ada is Time_Zone : constant Ada.Calendar.Time_Zones.Time_Offset := 540; type Compare_Mode is (Newer, Older); Parse_Error : exception; use Ada.Text_IO; begin if Ada.Command_Line.Argument_Count < 1 then Put("usage:"); New_Line; else declare File_Name : String := Ada.Command_Line.Argument(1); Time_Stamp : Ada.Calendar.Time := Ada.Directories.Modification_Time(File_Name); File : File_Type; Mode : Compare_Mode; C : Character; function Read_Integer(Last : Character) return Natural is Result : Natural := 0; begin loop Get(File, C); exit when C = Last; if C in '0'..'9' then Result := Result * 10 + (Character'Pos(C) - Character'Pos('0')); else raise Parse_Error; end if; exit when End_Of_Line(File); end loop; return Result; end Read_Integer; File_Hour : Ada.Calendar.Formatting.Hour_Number := Ada.Calendar.Formatting.Hour(Time_Stamp, Time_Zone); File_Min : Ada.Calendar.Formatting.Minute_Number := Ada.Calendar.Formatting.Minute(Time_Stamp, Time_Zone); Hour : Ada.Calendar.Formatting.Hour_Number; Min : Ada.Calendar.Formatting.Minute_Number; begin Open(File, In_File, File_Name); Get(File, C); case C is when 'n' => Mode := Newer; when 'o' => Mode := Older; when others => raise Parse_Error; end case; Get(File, C); if C /= ',' then raise Parse_Error; end if; Hour := Read_Integer(':'); Min := Read_Integer(Character'Val(0)); Close(File); if (Mode = Newer) = (File_Hour * 60 + File_Min > Hour * 60 + Min) then Put("ok"); New_Line; else Put("ng"); New_Line; end if; end; end if; end w_o_Ada;
範囲チェックをやってないように見えるかもしれませんが、Adaの場合は部分範囲型まわりは自動でConstraint_Errorが投げられたりしますのでそれ任せ。
というよりこの規模なら標準ライブラリで決まる気がしました。Cの例でもいちいちパースせずにfscanfで…。
あとAda.Directories.Modification_Timeから辿っていってMinGWのCランタイムのタイムスタンプ取得関数が、時差を考慮してくれてない予感。