-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
save.hac
136 lines (117 loc) · 3.94 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
-- 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;