mathtex-portable-engine-generated 0.1.2

Machine generated portable TeX engine core for mathtex, translated from the TeX, eTeX and XeTeX sources
Documentation
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
//! shared TeX core candidates auto-patched from TeX source when compatible (group `d`).
//! Generated by `cargo run -p mathtex-web2c-import --bin patch_engine`.

#![allow(dead_code, non_camel_case_types, non_snake_case, unused_assignments, unused_must_use, unused_mut, unused_variables)]

use crate::runtime::*;

impl<'resources> PortableTexEngine<'resources> {

    pub(crate) unsafe fn defaultrulethickness(&mut self) -> scaled {
        let mut Result: scaled = 0;
        let eqtb = self.state.zeqtb.as_mut_ptr();
        let mut f_0: integer = 0;
        let mut rval: scaled = 0;
        f_0 = (*eqtb.offset((1206827 as i64 + self.state.cursize as i64) as isize))
            .hh
            .v
            .RH as integer;
        if *self.state.fontarea.offset(f_0 as isize) as i64 == 65534 as i64
            && Self::is_opentype_math_font(
                self as *mut PortableTexEngine<'_>,
                *self.state.fontlayoutengine.offset(f_0 as isize) as FontHandle,
            ) != 0
        {
            rval = Self::get_native_mathex_parameter(
                self as *mut PortableTexEngine<'resources>,
                f_0 as i32,
                8 as i32,
            ) as scaled;
        } else {
            rval = (*self
                .state
                .fontinfo
                .offset(
                    (8 as integer + *self.state.parambase.offset(f_0 as isize)) as isize,
                ))
                .u
                .CINT as scaled;
        }
        Result = rval;
        return Result;
    }
    pub(crate) unsafe fn deletelast(&mut self) -> EngineFlow<()> {
        let mut mem: *mut memoryword = self.state.zmem.as_mut_ptr();
        let mut p: halfword = 0;
        let mut q: halfword = 0;
        let mut r: halfword = 0;
        let mut fm: boolean = 0;
        let mut tx: halfword = 0;
        let mut m: quarterword = 0;
        if self.state.curlist.modefield as i32 == 1 as i32
            && self.state.curlist.tailfield == self.state.curlist.headfield
        {
            if self.state.curchr != 10 as i32
                || self.state.lastglue as i64 != 1073741823 as i64
            {
                (&mut *(self as *mut PortableTexEngine<'_>)).youcant();
                self.state.helpptr = 2 as eightbits;
                self.state.helpline[1 as i32 as usize] = 66505 as i64 as strnumber;
                self.state.helpline[0 as i32 as usize] = 66522 as i64 as strnumber;
                if self.state.curchr == 11 as i32 {
                    self.state.helpline[0 as i32 as usize] = 66523 as i64 as strnumber;
                } else if self.state.curchr != 10 as i32 {
                    self.state.helpline[0 as i32 as usize] = 66524 as i64 as strnumber;
                }
                (&mut *(self as *mut PortableTexEngine<'_>)).error()?;
            }
        } else {
            tx = self.state.curlist.tailfield;
            if !(tx >= self.state.himemmin) {
                if (*mem.offset(tx as isize)).hh.u.B0 as i32 == 9 as i32
                    && (*mem.offset(tx as isize)).hh.u.B1 as i32 == 3 as i32
                {
                    r = self.state.curlist.headfield;
                    loop {
                        q = r;
                        r = (*mem.offset(q as isize)).hh.v.RH;
                        if r == tx {
                            break;
                        }
                    }
                    tx = q;
                }
            }
            if !(tx >= self.state.himemmin) {
                if (*mem.offset(tx as isize)).hh.u.B0 as i32 == self.state.curchr {
                    q = self.state.curlist.headfield;
                    p = -(268435455 as i64) as halfword;
                    loop {
                        r = p;
                        p = q;
                        fm = false_0 as boolean;
                        if !(q >= self.state.himemmin) {
                            if (*mem.offset(q as isize)).hh.u.B0 as i32 == 7 as i32 {
                                let mut for_end: integer = 0;
                                m = 1 as quarterword;
                                for_end = (*mem.offset(q as isize)).hh.u.B1 as integer;
                                if m as i32 <= for_end {
                                    loop {
                                        p = (*mem.offset(p as isize)).hh.v.RH;
                                        let fresh162 = m;
                                        m = m.wrapping_add(1);
                                        if !((fresh162 as i32) < for_end) {
                                            break;
                                        }
                                    }
                                }
                                if p == tx {
                                    return Ok(());
                                }
                            } else if (*mem.offset(q as isize)).hh.u.B0 as i32
                                == 9 as i32
                                && (*mem.offset(q as isize)).hh.u.B1 as i32 == 2 as i32
                            {
                                fm = true_0 as boolean;
                            }
                        }
                        q = (*mem.offset(p as isize)).hh.v.RH;
                        if q == tx {
                            break;
                        }
                    }
                    q = (*mem.offset(tx as isize)).hh.v.RH;
                    (*mem.offset(p as isize)).hh.v.RH = q;
                    (*mem.offset(tx as isize)).hh.v.RH = -(268435455 as i64) as halfword;
                    if q as i64 == -(268435455 as i64) {
                        if fm != 0 {
                            match (&mut *(self as *mut PortableTexEngine<'_>))
                                .zconfusion(66503 as i64 as strnumber)?
                            {};
                        } else {
                            self.state.curlist.tailfield = p;
                        }
                    } else if fm != 0 {
                        self.state.curlist.tailfield = r;
                        (*mem.offset(r as isize)).hh.v.RH = -(268435455 as i64)
                            as halfword;
                        (&mut *(self as *mut PortableTexEngine<'_>)).zflushnodelist(p)?;
                    }
                    (&mut *(self as *mut PortableTexEngine<'_>)).zflushnodelist(tx)?;
                }
            }
        };
        Ok(())
    }
    pub(crate) unsafe fn doassignments(&mut self) -> EngineFlow<()> {
        loop {
            loop {
                (&mut *(self as *mut PortableTexEngine<'_>)).getxtoken()?;
                if self.state.curcmd as i32 != 10 as i32
                    && self.state.curcmd as i32 != 0 as i32
                {
                    break;
                }
            }
            if self.state.curcmd as i32 <= 71 as i32 {
                return Ok(());
            }
            self.state.setboxallowed = false_0 as boolean;
            (&mut *(self as *mut PortableTexEngine<'_>)).prefixedcommand()?;
            self.state.setboxallowed = true_0 as boolean;
        }
    }
    pub(crate) unsafe fn doendv(&mut self) -> EngineFlow<()> {
        self.state.baseptr = self.state.inputptr;
        *self.state.inputstack.offset(self.state.baseptr as isize) = self.state.curinput;
        while (*self.state.inputstack.offset(self.state.baseptr as isize)).indexfield
            as i32 != 2 as i32
            && (*self.state.inputstack.offset(self.state.baseptr as isize)).locfield
                as i64 == -(268435455 as i64)
            && (*self.state.inputstack.offset(self.state.baseptr as isize)).statefield
                as i32 == 0 as i32
        {
            self.state.baseptr -= 1;
        }
        if (*self.state.inputstack.offset(self.state.baseptr as isize)).indexfield as i32
            != 2 as i32
            || (*self.state.inputstack.offset(self.state.baseptr as isize)).locfield
                as i64 != -(268435455 as i64)
            || (*self.state.inputstack.offset(self.state.baseptr as isize)).statefield
                as i32 != 0 as i32
        {
            match (&mut *(self as *mut PortableTexEngine<'_>))
                .zfatalerror(65924 as i64 as strnumber)?
            {};
        }
        if self.state.curgroup as i32 == 6 as i32 {
            (&mut *(self as *mut PortableTexEngine<'_>)).endgraf()?;
            if (&mut *(self as *mut PortableTexEngine<'_>)).fincol()? != 0 {
                (&mut *(self as *mut PortableTexEngine<'_>)).finrow()?;
            }
        } else {
            (&mut *(self as *mut PortableTexEngine<'_>)).offsave()?;
        };
        Ok(())
    }
    pub(crate) unsafe fn doextension(&mut self) -> EngineFlow<()> {
        let mut mem: *mut memoryword = self.state.zmem.as_mut_ptr();
        let eqtb = self.state.zeqtb.as_mut_ptr();
        let mut i: integer = 0;
        let mut j: integer = 0;
        let mut k: integer = 0;
        let mut p: halfword = 0;
        match self.state.curchr {
            0 => {
                (&mut *(self as *mut PortableTexEngine<'_>))
                    .znewwritewhatsit(3 as i32 as smallnumber)?;
                (&mut *(self as *mut PortableTexEngine<'_>)).scanoptionalequals()?;
                (&mut *(self as *mut PortableTexEngine<'_>)).scanfilename()?;
                (*mem.offset((self.state.curlist.tailfield as i32 + 1 as i32) as isize))
                    .hh
                    .v
                    .RH = self.state.curname as halfword;
                (*mem.offset((self.state.curlist.tailfield as i32 + 2 as i32) as isize))
                    .hh
                    .v
                    .LH = self.state.curarea as halfword;
                (*mem.offset((self.state.curlist.tailfield as i32 + 2 as i32) as isize))
                    .hh
                    .v
                    .RH = self.state.curext as halfword;
            }
            1 => {
                k = self.state.curcs as integer;
                (&mut *(self as *mut PortableTexEngine<'_>))
                    .znewwritewhatsit(2 as i32 as smallnumber)?;
                self.state.curcs = k as halfword;
                p = (&mut *(self as *mut PortableTexEngine<'_>))
                    .zscantoks(0 as i32, 0 as i32)?;
                (*mem.offset((self.state.curlist.tailfield as i32 + 1 as i32) as isize))
                    .hh
                    .v
                    .RH = self.state.defref;
            }
            2 => {
                (&mut *(self as *mut PortableTexEngine<'_>))
                    .znewwritewhatsit(2 as i32 as smallnumber)?;
                (*mem.offset((self.state.curlist.tailfield as i32 + 1 as i32) as isize))
                    .hh
                    .v
                    .RH = -(268435455 as i64) as halfword;
            }
            3 => {
                if (&mut *(self as *mut PortableTexEngine<'_>))
                    .zscankeyword(66495 as i64 as strnumber)? != 0
                {
                    (&mut *(self as *mut PortableTexEngine<'_>))
                        .znewwhatsit(4 as i32 as smallnumber, 2 as i32 as smallnumber)?;
                    (*mem
                        .offset(
                            (self.state.curlist.tailfield as i32 + 1 as i32) as isize,
                        ))
                        .hh
                        .v
                        .LH = -(268435455 as i64) as halfword;
                    p = (&mut *(self as *mut PortableTexEngine<'_>))
                        .zscantoks(0 as i32, 0 as i32)?;
                    (*mem
                        .offset(
                            (self.state.curlist.tailfield as i32 + 1 as i32) as isize,
                        ))
                        .hh
                        .v
                        .RH = self.state.defref;
                } else {
                    (&mut *(self as *mut PortableTexEngine<'_>))
                        .znewwhatsit(3 as i32 as smallnumber, 2 as i32 as smallnumber)?;
                    (*mem
                        .offset(
                            (self.state.curlist.tailfield as i32 + 1 as i32) as isize,
                        ))
                        .hh
                        .v
                        .LH = -(268435455 as i64) as halfword;
                    p = (&mut *(self as *mut PortableTexEngine<'_>))
                        .zscantoks(0 as i32, 1 as i32)?;
                    (*mem
                        .offset(
                            (self.state.curlist.tailfield as i32 + 1 as i32) as isize,
                        ))
                        .hh
                        .v
                        .RH = self.state.defref;
                }
            }
            5 => {
                (&mut *(self as *mut PortableTexEngine<'_>)).getxtoken()?;
                if self.state.curcmd as i32 == 59 as i32 && self.state.curchr <= 2 as i32
                {
                    p = self.state.curlist.tailfield;
                    (&mut *(self as *mut PortableTexEngine<'_>)).doextension()?;
                    Self::boundary_special_out(
                        self as *mut PortableTexEngine<'_>,
                        self.state.curlist.tailfield,
                    )?;
                    (&mut *(self as *mut PortableTexEngine<'_>))
                        .zflushnodelist(self.state.curlist.tailfield)?;
                    self.state.curlist.tailfield = p;
                    (*mem.offset(p as isize)).hh.v.RH = -(268435455 as i64) as halfword;
                } else {
                    (&mut *(self as *mut PortableTexEngine<'_>)).backinput()?;
                }
            }
            6 => {
                if (if self.state.curlist.modefield as integer >= 0 as i32 {
                    self.state.curlist.modefield as integer
                } else {
                    -(self.state.curlist.modefield as i32)
                }) != 105 as i32
                {
                    (&mut *(self as *mut PortableTexEngine<'_>)).reportillegalcase()?;
                } else {
                    (&mut *(self as *mut PortableTexEngine<'_>))
                        .znewwhatsit(5 as i32 as smallnumber, 2 as i32 as smallnumber)?;
                    (&mut *(self as *mut PortableTexEngine<'_>)).scanint()?;
                    if self.state.curval <= 0 as i32 {
                        self.state.curlist.auxfield.hh.v.RH = 0 as i32 as halfword;
                    } else if self.state.curval > 255 as i32 {
                        self.state.curlist.auxfield.hh.v.RH = 0 as i32 as halfword;
                    } else {
                        self.state.curlist.auxfield.hh.v.RH = self.state.curval
                            as halfword;
                    }
                    (*mem
                        .offset(
                            (self.state.curlist.tailfield as i32 + 1 as i32) as isize,
                        ))
                        .hh
                        .v
                        .RH = self.state.curlist.auxfield.hh.v.RH;
                    (*mem
                        .offset(
                            (self.state.curlist.tailfield as i32 + 1 as i32) as isize,
                        ))
                        .hh
                        .u
                        .B0 = (&mut *(self as *mut PortableTexEngine<'_>))
                        .znormmin((*eqtb.offset(7892315 as i64 as isize)).u.CINT) as i16;
                    (*mem
                        .offset(
                            (self.state.curlist.tailfield as i32 + 1 as i32) as isize,
                        ))
                        .hh
                        .u
                        .B1 = (&mut *(self as *mut PortableTexEngine<'_>))
                        .znormmin((*eqtb.offset(7892316 as i64 as isize)).u.CINT) as i16;
                }
            }
            23 => {
                (&mut *(self as *mut PortableTexEngine<'_>))
                    .znewwhatsit(23 as i32 as smallnumber, 2 as i32 as smallnumber)?;
            }
            33 => {
                Self::get_seconds_and_micros(
                    self as *mut PortableTexEngine<'_>,
                    &raw mut self.state.epochseconds,
                    &raw mut self.state.microseconds,
                );
            }
            35 => {
                (&mut *(self as *mut PortableTexEngine<'_>)).scanint()?;
                if self.state.curval < 0 as i32 {
                    self.state.curval = -self.state.curval;
                }
                self.state.randomseed = self.state.curval as scaled;
                (&mut *(self as *mut PortableTexEngine<'_>))
                    .zinitrandoms(self.state.randomseed);
            }
            41 => {
                if (if self.state.curlist.modefield as integer >= 0 as i32 {
                    self.state.curlist.modefield as integer
                } else {
                    -(self.state.curlist.modefield as i32)
                }) == 209 as i32
                {
                    (&mut *(self as *mut PortableTexEngine<'_>)).reportillegalcase()?;
                } else {
                    Self::boundary_load_picture(
                        self as *mut PortableTexEngine<'_>,
                        0 as i32,
                    );
                }
            }
            42 => {
                if (if self.state.curlist.modefield as integer >= 0 as i32 {
                    self.state.curlist.modefield as integer
                } else {
                    -(self.state.curlist.modefield as i32)
                }) == 209 as i32
                {
                    (&mut *(self as *mut PortableTexEngine<'_>)).reportillegalcase()?;
                } else {
                    Self::boundary_load_picture(
                        self as *mut PortableTexEngine<'_>,
                        1 as i32,
                    );
                }
            }
            43 => {
                if (if self.state.curlist.modefield as integer >= 0 as i32 {
                    self.state.curlist.modefield as integer
                } else {
                    -(self.state.curlist.modefield as i32)
                }) == 1 as i32
                {
                    (&mut *(self as *mut PortableTexEngine<'_>)).backinput()?;
                    (&mut *(self as *mut PortableTexEngine<'_>)).znewgraf(1 as i32)?;
                } else if (if self.state.curlist.modefield as integer >= 0 as i32 {
                    self.state.curlist.modefield as integer
                } else {
                    -(self.state.curlist.modefield as i32)
                }) == 209 as i32
                {
                    (&mut *(self as *mut PortableTexEngine<'_>)).reportillegalcase()?;
                } else if *self
                    .state
                    .fontarea
                    .offset((*eqtb.offset(1206823 as i64 as isize)).hh.v.RH as isize)
                    as i64 == 65535 as i64
                    || *self
                        .state
                        .fontarea
                        .offset((*eqtb.offset(1206823 as i64 as isize)).hh.v.RH as isize)
                        as i64 == 65534 as i64
                {
                    (&mut *(self as *mut PortableTexEngine<'_>))
                        .znewwhatsit(42 as i32 as smallnumber, 5 as i32 as smallnumber)?;
                    (&mut *(self as *mut PortableTexEngine<'_>)).scanint()?;
                    if self.state.curval < 0 as i32
                        || self.state.curval as i64 > 65535 as i64
                    {
                        self.state.interaction as i32 == 3 as i32;
                        if self.state.filelineerrorstylep != 0 {
                            (&mut *(self as *mut PortableTexEngine<'_>)).printfileline();
                        } else {
                            (&mut *(self as *mut PortableTexEngine<'_>))
                                .zprintnl(65544 as i64 as strnumber);
                        }
                        (&mut *(self as *mut PortableTexEngine<'_>))
                            .zprint(66794 as i64 as integer);
                        self.state.helpptr = 2 as eightbits;
                        self.state.helpline[1 as i32 as usize] = 66795 as i64
                            as strnumber;
                        self.state.helpline[0 as i32 as usize] = 66005 as i64
                            as strnumber;
                        (&mut *(self as *mut PortableTexEngine<'_>))
                            .zinterror(self.state.curval)?;
                        self.state.curval = 0 as i32 as integer;
                    }
                    (*mem
                        .offset(
                            (self.state.curlist.tailfield as i32 + 4 as i32) as isize,
                        ))
                        .v
                        .QQQQ
                        .u
                        .B1 = ((*eqtb.offset(1206823 as i64 as isize)).hh.v.RH
                        as quarterword) as u16;
                    (*mem
                        .offset(
                            (self.state.curlist.tailfield as i32 + 4 as i32) as isize,
                        ))
                        .v
                        .QQQQ
                        .u
                        .B2 = (self.state.curval as quarterword) as u16;
                    Self::measure_native_glyph(
                        self as *mut PortableTexEngine<'resources>,
                        mem.offset(self.state.curlist.tailfield as isize)
                            as *mut memoryword as *mut (),
                        ((*eqtb.offset(7892342 as i64 as isize)).u.CINT > 0 as i32)
                            as i32,
                    );
                } else {
                    (&mut *(self as *mut PortableTexEngine<'_>))
                        .znotnativefonterror(
                            59 as i32,
                            43 as i32,
                            (*eqtb.offset(1206823 as i64 as isize)).hh.v.RH,
                        )?;
                }
            }
            44 => {
                (&mut *(self as *mut PortableTexEngine<'_>)).scanandpackname()?;
                i = Self::get_encoding_mode_and_info(
                    self as *mut PortableTexEngine<'_>,
                    &raw mut j,
                ) as integer;
                if i == 0 as i32 {
                    self.state.interaction as i32 == 3 as i32;
                    if self.state.filelineerrorstylep != 0 {
                        (&mut *(self as *mut PortableTexEngine<'_>)).printfileline();
                    } else {
                        (&mut *(self as *mut PortableTexEngine<'_>))
                            .zprintnl(65544 as i64 as strnumber);
                    }
                    (&mut *(self as *mut PortableTexEngine<'_>))
                        .zprint(66813 as i64 as integer);
                    self.state.helpptr = 2 as eightbits;
                    self.state.helpline[1 as i32 as usize] = 66814 as i64 as strnumber;
                    self.state.helpline[0 as i32 as usize] = 66815 as i64 as strnumber;
                    (&mut *(self as *mut PortableTexEngine<'_>)).error()?;
                } else {
                    setinputfileencoding(
                        *self.state.inputfile.offset(self.state.inopen as isize),
                        i,
                        j,
                    );
                }
            }
            45 => {
                (&mut *(self as *mut PortableTexEngine<'_>)).scanandpackname()?;
                i = Self::get_encoding_mode_and_info(
                    self as *mut PortableTexEngine<'_>,
                    &raw mut j,
                ) as integer;
                (*eqtb.offset(7892345 as i64 as isize)).u.CINT = i;
                (*eqtb.offset(7892346 as i64 as isize)).u.CINT = j;
            }
            91 => {
                (&mut *(self as *mut PortableTexEngine<'_>)).scanint()?;
                Self::host_box_insert(
                    self as *mut PortableTexEngine<'_>,
                    self.state.curval,
                )?;
            }
            46 => {
                (&mut *(self as *mut PortableTexEngine<'_>)).scanfilename()?;
                if (&mut *(self as *mut PortableTexEngine<'_>))
                    .zlength(self.state.curname) == 0 as i32
                {
                    (*eqtb.offset(7892336 as i64 as isize)).u.CINT = 0 as i32 as integer;
                } else {
                    (*eqtb.offset(7892336 as i64 as isize)).u.CINT = self.state.curname
                        as integer;
                }
            }
            _ => {
                match (&mut *(self as *mut PortableTexEngine<'_>))
                    .zconfusion(66764 as i64 as strnumber)?
                {};
            }
        };
        Ok(())
    }
}