-
Notifications
You must be signed in to change notification settings - Fork 5
/
save.hac
97 lines (85 loc) · 2.77 KB
/
save.hac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
-- Local backup Ada shell script for the HAC project.
--
-- This script works both with HAC (command: hac save.adb)
-- and a full Ada compiler like GNAT, and that on different
-- Operating Systems: Linux and Windows at least.
--
-- 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).
--
-- 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, files : VString;
zip_res : Integer;
sep : 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 & "/*.ad* " &
root & "/*.gpr " &
root & "/*.hac " &
root & "/lea.rc " &
root & "/lea.h " &
root & "/lea.rbj " &
root & "/build.cmd " &
root & "/*.txt " &
root & "/debug.pra " &
root & "/ico_bmp/*.ico " &
root & "/ico_bmp/*.bmp " &
root & "/ico_bmp/*.ppt ";
-- 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;