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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Delete a file
///
/// Delete a file.
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// FILNAM I The name of a file to be deleted.
/// ```
///
/// # Detailed Input
///
/// ```text
/// FILNAM is the name of a file that is to be deleted. Upon
/// successful completion of this routine this file will
/// no longer exist. The file to be deleted must be closed
/// when this routine is called.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If the file name is blank, the error SPICE(BLANKFILENAME)
/// is signaled.
///
/// 2) If the inquire on the filename specified by FILNAM fails for
/// some reason, the error SPICE(INQUIREERROR) is signaled.
///
/// 3) If the file specified by FILNAM is already open, the error
/// SPICE(FILECURRENTLYOPEN) is signaled.
///
/// 4) If the file specified by FILNAM does not exist, the error
/// SPICE(NOSUCHFILE) is signaled.
///
/// 5) If the attempt to open the file specified by FILNAM fails,
/// the error SPICE(FILEOPENFAILED) is signaled.
///
/// 6) If the attempt to close the file with STATUS='DELETE' fails,
/// the error SPICE(FILEDELETEFAILED) is signaled.
/// ```
///
/// # Files
///
/// ```text
/// The file specified by FILNAM is opened and then closed by this
/// routine with STATUS = 'DELETE' to delete it. The file must be
/// closed for this routine to delete it.
/// ```
///
/// # Particulars
///
/// ```text
/// This subroutine is a support utility that deletes a file.
/// ```
///
/// # Examples
///
/// ```text
/// Suppose you wish to delete a file named 'delete.me' in the
/// current directory. The code fragment below would accomplish this.
///
/// FILE = 'delete.me'
/// CALL DELFIL ( FILE )
/// ```
///
/// # Restrictions
///
/// ```text
/// 1) The file to be deleted must be closed when this routine is
/// invoked.
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// K.R. Gehringer (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.0.1, 02-JUN-2021 (JDR)
///
/// Edited the header to comply with NAIF standard.
///
/// - SPICELIB Version 1.0.0, 20-DEC-1995 (KRG)
/// ```
pub fn delfil(ctx: &mut SpiceContext, filnam: &str) -> crate::Result<()> {
DELFIL(filnam.as_bytes(), ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure DELFIL ( Delete a file )
pub fn DELFIL(FILNAM: &[u8], ctx: &mut Context) -> f2rust_std::Result<()> {
let mut IOSTAT: i32 = 0;
let mut LUNIT: i32 = 0;
let mut EXISTS: bool = false;
let mut OPENED: bool = false;
//
// Spicelib Routines
//
//
// Local Variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(b"DELFIL", ctx)?;
}
//
// Check to see if the filename we got is blank. If it is, signal an
// error and return.
//
if fstr::eq(FILNAM, b" ") {
SETMSG(b"The file name is blank.", ctx);
SIGERR(b"SPICE(BLANKFILENAME)", ctx)?;
CHKOUT(b"DELFIL", 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),
exist: Some(&mut EXISTS),
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) {
SETMSG(b"INQUIRE statement failed for file \'#\'. IOSTAT = #.", ctx);
ERRCH(b"#", FILNAM, ctx);
ERRINT(b"#", IOSTAT, ctx);
SIGERR(b"SPICE(INQUIREFAILED)", ctx)?;
CHKOUT(b"DELFIL", ctx)?;
return Ok(());
}
//
// The file ought to exist if you're trying to delete it. If not,
// signal an error and return.
//
if !EXISTS {
SETMSG(b"The file \'#\' does not exist.", ctx);
ERRCH(b"#", FILNAM, ctx);
SIGERR(b"SPICE(NOSUCHFILE)", ctx)?;
CHKOUT(b"DELFIL", ctx)?;
return Ok(());
}
//
// The file that is to be deleted should not be in use, indicated by
// it being open, by anything when we try to delete it. If it is
// open, signal an error and return.
//
if OPENED {
SETMSG(
b"The file \'#\' is currently open and cannot be deleted.",
ctx,
);
ERRCH(b"#", FILNAM, ctx);
SIGERR(b"SPICE(FILECURRENTLYOPEN)", ctx)?;
CHKOUT(b"DELFIL", ctx)?;
return Ok(());
}
//
// Get an available logical unit and attempt to open the file.
//
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) {
SETMSG(b"Attempt to open the file \'#\' failed.", ctx);
ERRCH(b"#", FILNAM, ctx);
SIGERR(b"SPICE(FILEOPENFAILED)", ctx)?;
CHKOUT(b"DELFIL", 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)?;
}
SETMSG(b"Attempt to delete the file \'#\' failed.", ctx);
ERRCH(b"#", FILNAM, ctx);
SIGERR(b"SPICE(FILEDELETEFAILED)", ctx)?;
CHKOUT(b"DELFIL", ctx)?;
return Ok(());
}
CHKOUT(b"DELFIL", ctx)?;
Ok(())
}