2 # Copyright (C) 2020 Free Software Foundation
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 fmt_name
= sys
.argv
[1]
21 templates
= sys
.argv
[2:]
45 syntax_file
= open('%s.sps' % fmt_name
, 'w')
46 syntax_file
.write('''\
47 DATA LIST NOTABLE FILE='%(fmt_name)s.input'/%(fmt_name)s 1-40 (%(fmt_name)s).
48 PRINT OUTFILE='%(fmt_name)s.output'/%(fmt_name)s (F16.2).
50 ''' % {'fmt_name': fmt_name
})
53 expout_file
= open('expout', 'w')
54 input_file
= open('%s.input' % fmt_name
, 'w')
56 def print_all_formats(d
, h
, m
, s
, template
, formatted
, expected
, sign
):
59 template
= template
[1:]
62 for new_sign
in ('', '-', '+'):
63 print_all_formats(d
, h
, m
, s
, template
,
64 formatted
+ new_sign
, expected
, new_sign
)
66 for f
in ('%d', '%02d'):
67 print_all_formats(0, h
, m
, s
, template
,
68 formatted
+ (f
% d
), expected
+ d
* 86400,
71 for f
in ('%d', '%02d'):
72 print_all_formats(0, 0, m
, s
, template
,
73 formatted
+ (f
% (h
+ d
* 24)),
74 expected
+ h
* 3600 + d
* 86400,
77 for f
in ('%d', '%02d'):
78 print_all_formats(0, 0, 0, s
, template
,
79 formatted
+ (f
% (m
+ h
* 60 + d
* 1440)),
80 expected
+ m
* 60 + h
* 3600 + d
* 86400,
83 for f
in ('%.0f', '%02.0f', '%.1f', '%.2f'):
84 ns
= s
+ m
* 60 + h
* 3600 + d
* 86400
86 print_all_formats(0, 0, 0, 0, template
,
87 formatted
+ formatted_s
,
88 expected
+ float(formatted_s
),
92 print_all_formats(d
, h
, m
, s
, template
, formatted
+ f
,
95 print_all_formats(d
, h
, m
, s
, template
, formatted
+ ' ',
100 # Write the formatted value to fmt_name.input.
101 input_file
.write('%s\n' % formatted
)
103 # Write the expected value to 'expout'.
104 if sign
== '-' and expected
> 0:
106 expected_s
= '%17.2f\n' % expected
107 expected_s
= expected_s
.replace(' 0.', ' .')
108 expout_file
.write(expected_s
)
111 for template
in templates
:
114 print_all_formats(d
, h
, m
, s
, template
, '', 0, '')