-- Local backup Ada shell script. -- -- This HAC script detects saves the essential files of Zip-Ada -- into a Zip-ball. -- -- #!/usr/bin/env hac -- A "shebang" for Unix/Linux, such as "#!/usr/bin/env hac" can be -- added on the top line of this file. -- HAC will ignore it, but GNAT won't like it (that's normal). -- -- This is a HAC script *and* an Ada program. -- How to run it is your choice. -- -- Usage with the HAC command-line tool : -- -- hac save.hac -- -- The HAC (HAC Ada Compiler) command-line tool can be found @ -- https://hacadacompiler.sourceforge.io/ , -- https://github.com/zertovitch/hac -- This program works both with HAC (command: hac save.hac) -- and a full Ada compiler like GNAT, and that on different -- Operating Systems: Linux and Windows at least. -- -- The extension for the main procedure is a free choice. -- We choose ".hac" so we can associate the ".hac" files by -- default with hac.exe on Windows, for Explorer *and* command-line! -- Explorer: double-click / hit Return on "save.hac". -- Cmd / PowerShell: type "save.hac" and hit Return. with HAT; procedure Save is use HAT; function Nice_Date (with_intraday : Boolean) return VString is t1 : constant Time := Clock; day_secs, day_mins : Integer; just_day : VString; -- function Two_Digits (x : Integer) return VString is begin if x < 10 then return "0" & Image (x); else return Image (x); end if; end Two_Digits; -- begin day_secs := Integer (Seconds (t1)); day_mins := day_secs / 60; just_day := +"" & -- VString concatenation Year (t1) & '-' & Two_Digits (Month (t1)) & '-' & Two_Digits (Day (t1)); if with_intraday then return just_day & "--" & Two_Digits (day_mins / 60) & '-' & Two_Digits (day_mins mod 60) & '-' & Two_Digits (day_secs mod 60); else return just_day; end if; end Nice_Date; root, ada_sources, doc, tools, extras, scripts, files : VString; zip_res : Integer; sep : constant Character := Directory_Separator; begin Put_Line ("Save date: " & Nice_Date (True)); Put_Line ("Current directory: " & Current_Directory); Put_Line ("-----"); root := Tail_After_Match (Current_Directory, sep); Set_Directory (".."); files := root & "/*.gpr " & root & "/*.prj " & root & "/*.pra "; ada_sources := root & "/zip_lib/*.ad* " & root & "/test/*.ad* " & root & "/demo/*.ad* " & -- root & "/trained/*.ad* " & root & "/trained/*.gpr "; doc := root & "/doc/*.txt " & root & "/doc/za*.xls " & root & "/doc/za*.pdf "; tools := root & "/tools/*.ad* " & root & "/tools/rez*.cmd " & root & "/tools/verif.* " & root & "/tools/adactl*.cmd "; extras := root & "/extras/*.ad* " & root & "/extras/*.rc " & root & "/extras/*.rbj " & root & "/extras/*.ico " & root & "/extras/*.pl " & root & "/extras/w*.cmd "; scripts := root & "/*_za.cmd " & root & "/*.hac " & root & "/*.sh " & root & "/test/test*.cmd " & root & "/test/*.hac " & root & "/test/bench*.cmd " & root & "/test/prof.cmd "; files := files & ada_sources & doc & tools & extras & scripts; -- The ZipAda command-line tool can be built or downloaded -- from the project Zip-Ada @ -- https://unzip-ada.sourceforge.io/ , -- https://github.com/zertovitch/zip-ada -- or from ALIRE (Ada LIbrary REpository) @ https://alire.ada.dev/ -- Shell_Execute ("zipada -ep2 " & root & sep & root & '-' & Nice_Date (True) & "- " & files, zip_res); if zip_res = 0 then Put_Line ("Zip archive creation successful"); else Put_Line ("Zip archive creation failed"); end if; Set_Directory (root); Put ("Press Return "); Skip_Line; end Save;