use super::*;
use f2rust_std::*;
const FNMLEN: i32 = 255;
pub fn NEWFIL_1(PATTRN: &[u8], FILE: &mut [u8], ctx: &mut Context) -> f2rust_std::Result<()> {
let mut FNAME = [b' '; FNMLEN as usize];
let mut NAME = [b' '; FNMLEN as usize];
let mut THIS = [b' '; FNMLEN as usize];
let mut DONE: bool = false;
let mut NOMORE: bool = false;
if spicelib::RETURN(ctx) {
return Ok(());
} else {
spicelib::CHKIN(b"NEWFIL_1", ctx)?;
}
fstr::assign(&mut FNAME, b" ");
FSTSTR(PATTRN, &mut FNAME, ctx)?;
fstr::assign(&mut NAME, &FNAME);
NOMORE = false;
DONE = false;
while !DONE {
fstr::assign(&mut THIS, &NAME);
fstr::assign(&mut NAME, b" ");
NXTSTR(PATTRN, &THIS, &mut NAME);
DONE = fstr::eq(&NAME, &FNAME);
if !DONE {
if !spicelib::EXISTS(&NAME, ctx)? {
DONE = true;
}
} else {
NOMORE = true;
}
}
if NOMORE {
fstr::assign(FILE, b" ");
spicelib::SETMSG(b"It was not possible to create a file name using \'#\' as the pattern. All of the file names that can be generated from this pattern already exist.", ctx);
spicelib::ERRCH(b"#", PATTRN, ctx);
spicelib::SIGERR(b"SPICE(CANNOTMAKEFILE)", ctx)?;
spicelib::CHKOUT(b"NEWFIL_1", ctx)?;
return Ok(());
}
fstr::assign(FILE, &NAME);
spicelib::CHKOUT(b"NEWFIL_1", ctx)?;
Ok(())
}