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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
//$Procedure KILFIL ( Kill a file )
pub fn KILFIL(FILNAM: &[u8], ctx: &mut Context) -> f2rust_std::Result<()> {
let mut IOSTAT: i32 = 0;
let mut LUNIT: i32 = 0;
let mut OPENED: bool = false;
//
// Spicelib Routines
//
//
// Local Variables
//
//
// Standard SPICE error handling.
//
if spicelib::RETURN(ctx) {
return Ok(());
}
spicelib::CHKIN(b"KILFIL", ctx)?;
//
// Check to see if the filename we got is blank. If it is, signal an
// error and return.
//
if fstr::eq(FILNAM, b" ") {
spicelib::SETMSG(b"The file name is blank.", ctx);
spicelib::SIGERR(b"SPICE(BLANKFILENAME)", ctx)?;
spicelib::CHKOUT(b"KILFIL", ctx)?;
return Ok(());
}
//
// If the file doesn't exist, there's nothing to do.
//
if !spicelib::EXISTS(FILNAM, ctx)? {
spicelib::CHKOUT(b"KILFIL", ctx)?;
return Ok(());
}
//
// We inquire before we try opening anything to see if the file
// exists or is currently open.
//
{
use f2rust_std::io;
let specs = io::InquireSpecs {
file: Some(FILNAM),
opened: Some(&mut OPENED),
..Default::default()
};
IOSTAT = io::capture_iostat(|| ctx.inquire(specs))?;
}
//
// Not too likely, but if the INQUIRE statement fails signal an error
// and return.
//
if (IOSTAT != 0) {
spicelib::SETMSG(b"INQUIRE statement failed for file \'#\'. IOSTAT = #.", ctx);
spicelib::ERRCH(b"#", FILNAM, ctx);
spicelib::ERRINT(b"#", IOSTAT, ctx);
spicelib::SIGERR(b"SPICE(INQUIREFAILED)", ctx)?;
spicelib::CHKOUT(b"KILFIL", ctx)?;
return Ok(());
}
//
// The file is already open, we don't have to bother opening it
// We can just delete it.
//
if OPENED {
{
use f2rust_std::io;
let specs = io::InquireSpecs {
file: Some(FILNAM),
number: Some(&mut LUNIT),
..Default::default()
};
ctx.inquire(specs)?;
}
} else {
//
// Get an available logical unit and attempt to open the file.
//
spicelib::GETLUN(&mut LUNIT, ctx)?;
{
use f2rust_std::io;
let specs = io::OpenSpecs {
unit: Some(LUNIT),
file: Some(FILNAM),
status: Some(b"OLD"),
..Default::default()
};
IOSTAT = io::capture_iostat(|| ctx.open(specs))?;
}
//
// If we had trouble opening the file, signal an appropriate error
// and return.
//
if (IOSTAT != 0) {
spicelib::SETMSG(b"Attempt to open the file \'#\' failed.", ctx);
spicelib::ERRCH(b"#", FILNAM, ctx);
spicelib::SIGERR(b"SPICE(FILEOPENFAILED)", ctx)?;
spicelib::CHKOUT(b"KILFIL", ctx)?;
return Ok(());
}
}
//
// We opened the file successfully, so let's try to close it with
// STATUS = 'DELETE'. If this fails, attempt to just close the file,
// signal an error and return.
//
{
use f2rust_std::io;
let specs = io::CloseSpecs {
unit: Some(LUNIT),
status: Some(b"DELETE"),
..Default::default()
};
IOSTAT = io::capture_iostat(|| ctx.close(specs))?;
}
if (IOSTAT != 0) {
{
use f2rust_std::io;
let specs = io::CloseSpecs {
unit: Some(LUNIT),
..Default::default()
};
ctx.close(specs)?;
}
spicelib::SETMSG(b"Attempt to delete the file \'#\' failed.", ctx);
spicelib::ERRCH(b"#", FILNAM, ctx);
spicelib::SIGERR(b"SPICE(FILEDELETEFAILED)", ctx)?;
spicelib::CHKOUT(b"KILFIL", ctx)?;
return Ok(());
}
spicelib::CHKOUT(b"KILFIL", ctx)?;
Ok(())
}