use super::*;
use f2rust_std::*;
pub fn M2GETC(
NAME: &[u8],
STRING: &[u8],
FOUND: &mut bool,
WORD: &mut [u8],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut B: i32 = 0;
let mut E: i32 = 0;
let mut F: i32 = 0;
let mut L: i32 = 0;
let mut P: i32 = 0;
let mut W: i32 = 0;
M2VGET(NAME, 1, FOUND, &mut B, &mut E, ctx)?;
if !*FOUND {
return Ok(());
}
P = (B - 1);
F = (E + 1);
L = intrinsics::LEN(STRING);
W = intrinsics::LEN(WORD);
if (P > 0) {
if fstr::ne(fstr::substr(STRING, P..=P), b" ") {
spicelib::CHKIN(b"M2GETC", ctx)?;
spicelib::SETMSG(
b"The input string has been modified since it passed syntax validation in META/2. ",
ctx,
);
spicelib::SIGERR(b"META/2(CORRUPTEDINPUTSTRING)", ctx)?;
spicelib::CHKOUT(b"M2GETC", ctx)?;
return Ok(());
}
}
if (F < L) {
if fstr::ne(fstr::substr(STRING, F..=F), b" ") {
spicelib::CHKIN(b"M2GETC", ctx)?;
spicelib::SETMSG(
b"The input string has been modified since it passed syntax validation in META/2. ",
ctx,
);
spicelib::SIGERR(b"META/2(CORRUPTEDINPUTSTRING)", ctx)?;
spicelib::CHKOUT(b"M2GETC", ctx)?;
return Ok(());
}
}
if (fstr::eq(fstr::substr(STRING, B..=B), b" ") || fstr::eq(fstr::substr(STRING, E..=E), b" "))
{
spicelib::CHKIN(b"M2GETC", ctx)?;
spicelib::SETMSG(
b"The input string has been modified since it passed syntax validation in META/2. ",
ctx,
);
spicelib::SIGERR(b"META/2(CORRUPTEDINPUTSTRING)", ctx)?;
spicelib::CHKOUT(b"M2GETC", ctx)?;
return Ok(());
}
if (W < ((E - B) + 1)) {
spicelib::CHKIN(b"M2GETC", ctx)?;
spicelib::SETMSG(
b"There is not sufficient space in the output string to hold the requested word. ",
ctx,
);
spicelib::SIGERR(b"META/2(INSUFFICIENTSPACE)", ctx)?;
spicelib::CHKOUT(b"M2GETC", ctx)?;
return Ok(());
}
fstr::assign(WORD, fstr::substr(STRING, B..=E));
Ok(())
}