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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const FTSIZE: i32 = 5000;
const RSVUNT: i32 = 2;
const SCRUNT: i32 = 1;
const UTSIZE: i32 = ((20 + SCRUNT) + RSVUNT);
const READ: i32 = 1;
const WRITE: i32 = 2;
const SCRTCH: i32 = 3;
const NEW: i32 = 4;
const NUMAMH: i32 = 4;
const BIGI3E: i32 = 1;
const LTLI3E: i32 = 2;
const VAXGFL: i32 = 3;
const VAXDFL: i32 = 4;
const NUMBFF: i32 = 4;
const STRSIZ: i32 = 8;
const STRLEN: i32 = ((STRSIZ + 1) * NUMBFF);
const DAF: i32 = 1;
const DAS: i32 = 2;
const NUMARC: i32 = 2;
const RECL: i32 = 1024;
const FILEN: i32 = 255;
const CBFSIZ: i32 = 1024;
fn ZZICHR(CARG: &[u8]) -> i32 {
let CARG = &CARG[..1 as usize];
(intrinsics::ICHAR(CARG)
- (intrinsics::MAX0(&[-1, intrinsics::MIN0(&[0, intrinsics::ICHAR(CARG)])]) * 256))
}
//$Procedure ZZDDHIVF ( Private --- DDH Identify VAX DAF File Format )
pub fn ZZDDHIVF(NSUM: &[u8], BFF: &mut i32, FOUND: &mut bool) {
let mut LEADER: i32 = 0;
let mut TRAILR: i32 = 0;
//
// Local Variables
//
//
// Statement Functions
//
//
// Statement Function Definitions
//
// This function controls the conversion of characters to integers.
// Some versions of the g77 implement ICHAR with a signed integer.
// This function computes the value of ICHAR that this code requires
// on any version of g77 for x86 Linux.
//
//
// Before diving right into the code that examines the bit patterns
// stored in NSUM, review exactly what checks require completion and
// why they function.
//
// When this module is invoked, we already know that the DAF from
// which NSUM was extracted is little endian, and that it is not
// a LTL-IEEE file. This leaves us with one of 3 sources for
// NSUM:
//
// (a) A VAX D-Floating file
// (b) A VAX G-Floating file
// (c) A damaged file
//
// In the case of (c) the algorithm outlined below is not guaranteed
// to produce correct results. If the case is either (a) or (b),
// then the routine will correctly determine the source binary file
// format. Here's why:
//
// NSUM is the third double precision number from the first
// descriptor record of a non-empty DAF file. This number is
// an integral valued DP bounded between 1 and 125 inclusive.
//
// An examination of a binary file created with the following
// code fragment:
//
// INCLUDE 'zzddhman.inc'
//
// DOUBLE PRECISION DPDATA ( 125 )
// INTEGER I
// INTEGER LUN
// .
// .
// .
// CALL GETLUN( LUN )
//
// DO I = 1, 125
// DPDATA (I) = DBLE (I)
// END DO
//
// OPEN ( UNIT = LUN,
// . FILE = FNAME,
// . STATUS = 'NEW',
// . ACCESS = 'DIRECT',
// . RECL = RECL )
//
// WRITE ( UNIT = LUN, REC = 1 ) ( DPDATA(I), I = 1, 125 )
//
// END
//
// This source file was compiled on a VMS VAX system both with
// G-Floating and D-Floating options, and executed to produce
// the binary file of interest. The bit patterns for each of
// the 125 entries were compared using the UNIX command 'od'.
//
// This comparison yielded the fact that these two sets of 125
// bit patterns did not intersect, and all that remained was to
// uncover an efficient means of identifying which set a
// particular member belonged to.
//
// The following was observed:
//
// With the exception of the first entry representing the
// number 1.0D0 in the D-Floating case, all entries
// appeared as: (hexadecimal byte dump from 'od' output)
//
// 0041 0000 0000 0000
// 4041 0000 0000 0000
// 8041 0000 0000 0000
// .
// .
// .
// f643 0000 0000 0000
// f843 0000 0000 0000
// fa43 0000 0000 0000
//
// While the G-Floating case:
//
// 1040 0000 0000 0000
// 2040 0000 0000 0000
// 2840 0000 0000 0000
// .
// .
// .
// 7e40 00c0 0000 0000
// 7f40 0000 0000 0000
// 7f40 0040 0000 0000
//
// The important thing to note is that the fourth entry in
// G-Floating bit patterns is always '0', and in the
// D-Floating case (with the exception of the first entry)
// is always non-zero. The first entry in the D-Floating
// table is:
//
// 8040 0000 0000 0000
//
// It also happens to be the case that the leading value
// of all G-Floating cases are numbers less than 8.
// Constructing a series of tests around these observations
// will produce correct results. When the input file meets
// the restrictions non-empty and correct.
//
// So now all that remains is to lay out the specifics of the test.
// First extract the leading 4 bits from NSUM(1:1) and the trailing
// four bits from NSUM(2:2). Then enter this IF/ELSE IF block:
//
// If the value of the leading 4 bits from NSUM(1:1) is 8 and
// the trailing 4 bits from NSUM(2:2) are 0, then the file is
// of the D-Floating binary format.
//
// Else if the value of the trailing 4 bits of NSUM(2:2) is
// non-zero, then the file is also of the D-Floating binary
// format.
//
// Else if the value of the leading 4 bits of NSUM(1:1) is
// strictly less than 8 and the trailing bits of NSUM(2:2)
// are 0, then the file is of the G-Floating binary format.
//
// Else the file is not of VAX type.
//
// This routine could be reimplemented to examine all 8 bytes of
// each double precision number and compare it to two tables of
// values. In the interest of simplicity the preceding option
// was selected.
//
//
//
// Convert the first and second characters in NSUM to integers.
//
LEADER = ZZICHR(fstr::substr(NSUM, 1..=1));
TRAILR = ZZICHR(fstr::substr(NSUM, 2..=2));
//
// Shift the trailing 4 bits off LEADER.
//
LEADER = (LEADER / 16);
//
// Subtract the leading bits off TRAILR.
//
TRAILR = (TRAILR - (16 * (TRAILR / 16)));
//
// Now determine what file we are looking at.
//
if ((LEADER == 8) && (TRAILR == 0)) {
*FOUND = true;
*BFF = VAXDFL;
} else if (TRAILR != 0) {
*FOUND = true;
*BFF = VAXDFL;
} else if ((LEADER < 8) && (TRAILR == 0)) {
*FOUND = true;
*BFF = VAXGFL;
} else {
*FOUND = false;
}
}