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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
pub const LBCELL: i32 = -5;
pub const LBCBUF: i32 = 0;
//$Procedure LBINS ( Line buffer, insert )
pub fn LBINS_1(
POS: i32,
LINE: &[u8],
PTRS: &mut [i32],
BUFFER: CharArrayMut,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut PTRS = DummyArrayMut::new(PTRS, LBCELL..);
let mut BUFFER = DummyCharArrayMut::new(BUFFER, None, LBCBUF..);
let mut MAXLN: i32 = 0;
let mut NLINE: i32 = 0;
let mut NCOM: i32 = 0;
let mut PCARD: i32 = 0;
let mut POSPTR: i32 = 0;
let mut F: i32 = 0;
let mut L: i32 = 0;
let mut LNLEN: i32 = 0;
let mut AVAIL: i32 = 0;
let mut PTR = StackArray::<i32, 2>::new(1..=2);
//
// SPICELIB functions
//
//
// Local variables
//
//
// Equivalences
//
//
// Standard error handling.
//
if spicelib::RETURN(ctx) {
return Ok(());
} else {
spicelib::CHKIN(b"LBINS_1", ctx)?;
}
//
// Recover all the essential control information.
//
LBDES_1(
PTRS.as_slice(),
&mut MAXLN,
&mut NLINE,
&mut NCOM,
&mut PCARD,
ctx,
)?;
//
// Where should this line be inserted, if at all?
//
if (NLINE == MAXLN) {
spicelib::SETMSG(b"Current line limit is #.", ctx);
spicelib::ERRINT(b"#", MAXLN, ctx);
spicelib::SIGERR(b"SPICE(LBTOOMANYLINES)", ctx)?;
} else if ((POS < 1) || ((POS - NLINE) > 1)) {
spicelib::SETMSG(b"Tried to access line # of #.", ctx);
spicelib::ERRINT(b"#", POS, ctx);
spicelib::ERRINT(b"#", NLINE, ctx);
spicelib::SIGERR(b"SPICE(LBNOSUCHLINE)", ctx)?;
} else {
POSPTR = ((2 * POS) - 1);
//
// Leading blanks are significant; trailing blanks are history.
// (Store a blank string as a single blank character.)
//
F = 1;
L = intrinsics::MAX0(&[1, spicelib::LASTNB(LINE)]);
LNLEN = ((L - F) + 1);
//
// Store each new string at the end of the end of the CB.
// If the final interval in the complement isn't large enough
// to hold the new string, pack the CB and try again.
//
AVAIL = ((PTRS[PCARD] - PTRS[(PCARD - 1)]) + 1);
if (AVAIL < LNLEN) {
LBPACK_1(PTRS.as_slice_mut(), BUFFER.as_arg_mut(), ctx)?;
LBDES_1(
PTRS.as_slice(),
&mut MAXLN,
&mut NLINE,
&mut NCOM,
&mut PCARD,
ctx,
)?;
AVAIL = ((PTRS[PCARD] - PTRS[(PCARD - 1)]) + 1);
}
//
// If there still isn't enough room? Well, those are the breaks.
//
if (AVAIL < LNLEN) {
spicelib::SIGERR(b"SPICE(LBLINETOOLONG)", ctx)?;
//
// If there is room, allocate just enough of the final interval
// in the complement to contain the new string; store the string;
// and insert the name and pointers at their proper locations.
//
} else {
PTR[1] = PTRS[(PCARD - 1)];
PTR[2] = ((PTR[1] + LNLEN) - 1);
PTRS[(PCARD - 1)] = (PTR[2] + 1);
CBPUT_1(
PTR[1],
PTR[2],
fstr::substr(LINE, F..=L),
BUFFER.as_arg_mut(),
ctx,
)?;
spicelib::INSLAI(
PTR.as_slice(),
2,
POSPTR,
PTRS.subarray_mut(1),
&mut PCARD,
ctx,
)?;
LBUPD_1((NLINE + 1), NCOM, PTRS.as_slice_mut(), ctx)?;
}
}
spicelib::CHKOUT(b"LBINS_1", ctx)?;
Ok(())
}