Skip to content

Commit 765101c

Browse files
committed
Basic cleanup of C remnants
1 parent 5cf8609 commit 765101c

19 files changed

Lines changed: 726 additions & 746 deletions

File tree

crates/engine_bibtex/README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,3 @@ project](https://tectonic-typesetting.github.io/en-US/). It provides the
1717
This crate does not currently provides any [Cargo features][features].
1818

1919
[features]: https://doc.rust-lang.org/cargo/reference/features.html
20-
21-
22-
## Updating the generated header
23-
24-
This crate exposes Rust functions to C/C++ code using a header file created by
25-
[cbindgen]. To update the header, run:
26-
27-
[cbindgen]: https://github.com/eqrion/cbindgen/
28-
29-
```sh
30-
cbindgen --output bibtex/bibtex_bindings.h
31-
```
Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
use crate::{
2-
c_api::{
3-
bibs::BibData,
4-
buffer::{BufTy, GlobalBuffer},
5-
char_info::LexClass,
6-
cite::CiteInfo,
7-
exec::print_bst_name,
8-
hash::HashData,
9-
log::{
10-
aux_end1_err_print, aux_end2_err_print, aux_err_illegal_another_print,
11-
aux_err_no_right_brace_print, aux_err_print, aux_err_stuff_after_right_brace_print,
12-
aux_err_white_space_in_argument_print, hash_cite_confusion, log_pr_bst_name,
13-
print_a_pool_str, print_a_token, print_confusion, print_overflow, log_pr_aux_name,
14-
print_aux_name, print_bib_name, write_log_file, write_logs, AuxTy,
15-
},
16-
peekable::{peekable_close, peekable_open, PeekableInput},
17-
pool::StringPool,
18-
scan::Scan,
19-
AuxNumber, Bibtex, GlobalItems, StrIlk, StrNumber,
2+
bibs::BibData,
3+
buffer::{BufTy, GlobalBuffer},
4+
char_info::LexClass,
5+
cite::CiteInfo,
6+
exec::print_bst_name,
7+
hash::HashData,
8+
log::{
9+
aux_end1_err_print, aux_end2_err_print, aux_err_illegal_another_print,
10+
aux_err_no_right_brace_print, aux_err_print, aux_err_stuff_after_right_brace_print,
11+
aux_err_white_space_in_argument_print, hash_cite_confusion, log_pr_aux_name,
12+
log_pr_bst_name, print_a_pool_str, print_a_token, print_aux_name, print_bib_name,
13+
print_confusion, print_overflow, write_log_file, write_logs, AuxTy,
2014
},
21-
BibtexError,
15+
peekable::{peekable_close, peekable_open, PeekableInput},
16+
pool::StringPool,
17+
scan::Scan,
18+
AuxNumber, Bibtex, BibtexError, GlobalItems, StrIlk, StrNumber,
2219
};
2320
use std::{cell::RefCell, ffi::CString, ptr, ptr::NonNull};
2421
use tectonic_bridge_core::FileFormat;
@@ -88,7 +85,7 @@ pub(crate) fn with_aux_mut<T>(f: impl FnOnce(&mut AuxData) -> T) -> T {
8885
}
8986

9087
fn aux_bib_data_command(
91-
ctx: &mut Bibtex,
88+
ctx: &mut Bibtex<'_, '_>,
9289
buffers: &mut GlobalBuffer,
9390
bibs: &mut BibData,
9491
aux: &AuxData,
@@ -161,7 +158,7 @@ fn aux_bib_data_command(
161158
}
162159

163160
fn aux_bib_style_command(
164-
ctx: &mut Bibtex,
161+
ctx: &mut Bibtex<'_, '_>,
165162
buffers: &mut GlobalBuffer,
166163
aux: &AuxData,
167164
pool: &mut StringPool,
@@ -232,7 +229,7 @@ fn aux_bib_style_command(
232229
}
233230

234231
fn aux_citation_command(
235-
ctx: &mut Bibtex,
232+
ctx: &mut Bibtex<'_, '_>,
236233
buffers: &mut GlobalBuffer,
237234
aux: &AuxData,
238235
pool: &mut StringPool,
@@ -334,7 +331,7 @@ fn aux_citation_command(
334331
}
335332

336333
fn aux_input_command(
337-
ctx: &mut Bibtex,
334+
ctx: &mut Bibtex<'_, '_>,
338335
buffers: &mut GlobalBuffer,
339336
aux: &mut AuxData,
340337
pool: &mut StringPool,
@@ -419,7 +416,7 @@ fn aux_input_command(
419416
}
420417

421418
pub(crate) fn get_aux_command_and_process(
422-
ctx: &mut Bibtex,
419+
ctx: &mut Bibtex<'_, '_>,
423420
globals: &mut GlobalItems<'_>,
424421
) -> Result<(), BibtexError> {
425422
globals.buffers.set_offset(BufTy::Base, 2, 0);
@@ -489,7 +486,7 @@ pub(crate) fn pop_the_aux_stack(ctx: &mut Bibtex<'_, '_>, aux: &mut AuxData) ->
489486
}
490487

491488
pub(crate) fn last_check_for_aux_errors(
492-
ctx: &mut Bibtex,
489+
ctx: &mut Bibtex<'_, '_>,
493490
aux: &AuxData,
494491
pool: &StringPool,
495492
cites: &mut CiteInfo,
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
use crate::{
2-
c_api::{
3-
buffer::{BufTy, GlobalBuffer},
4-
char_info::LexClass,
5-
cite::add_database_cite,
6-
hash::{FnClass, HashData},
7-
log::{
8-
bib_cmd_confusion, bib_equals_sign_print, bib_err_print, bib_id_print,
9-
bib_one_of_two_print, bib_warn_print, cite_key_disappeared_confusion, eat_bib_print,
10-
hash_cite_confusion, print_a_token, print_confusion, write_log_file, write_logs,
11-
},
12-
peekable::{input_ln, PeekableInput},
13-
pool::StringPool,
14-
scan::{scan_and_store_the_field_value_and_eat_white, scan_identifier, Scan, ScanRes},
15-
xbuf::XBuf,
16-
BibNumber, Bibtex, CiteNumber, GlobalItems, HashPointer, StrIlk, StrNumber,
2+
buffer::{BufTy, GlobalBuffer},
3+
char_info::LexClass,
4+
cite::add_database_cite,
5+
hash::{FnClass, HashData},
6+
log::{
7+
bib_cmd_confusion, bib_equals_sign_print, bib_err_print, bib_id_print,
8+
bib_one_of_two_print, bib_warn_print, cite_key_disappeared_confusion, eat_bib_print,
9+
hash_cite_confusion, print_a_token, print_confusion, write_log_file, write_logs,
1710
},
18-
BibtexError,
11+
peekable::{input_ln, PeekableInput},
12+
pool::StringPool,
13+
scan::{scan_and_store_the_field_value_and_eat_white, scan_identifier, Scan, ScanRes},
14+
xbuf::XBuf,
15+
BibNumber, Bibtex, BibtexError, CiteNumber, GlobalItems, HashPointer, StrIlk, StrNumber,
1916
};
2017
use std::{cell::RefCell, ptr::NonNull};
2118

@@ -181,7 +178,7 @@ pub(crate) fn compress_bib_white(
181178
// - tied to that, command_num is only used when at_bib_command is true
182179
// - There's some messed up control flow that's porting weird `goto` style, can probably be simplified
183180
pub(crate) fn get_bib_command_or_entry_and_process(
184-
ctx: &Bibtex,
181+
ctx: &Bibtex<'_, '_>,
185182
globals: &mut GlobalItems<'_>,
186183
cur_macro_loc: &mut HashPointer,
187184
field_name_loc: &mut HashPointer,
Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
use crate::{
2-
c_api::{
3-
bibs::get_bib_command_or_entry_and_process,
4-
buffer::{BufTy, GlobalBuffer},
5-
char_info::LexClass,
6-
cite::find_cite_locs_for_this_cite_key,
7-
exec::{check_command_execution, execute_fn, ExecCtx},
8-
hash::{FnClass, HashData},
9-
history::mark_warning,
10-
log::{
11-
already_seen_function_print, bst_err_print_and_look_for_blank_line, bst_id_print,
12-
bst_left_brace_print, bst_right_brace_print, bst_warn_print,
13-
cite_key_disappeared_confusion, eat_bst_print, hash_cite_confusion, log_pr_bib_name,
14-
print_a_token, print_confusion, print_missing_entry, rs_bad_cross_reference_print,
15-
rs_nonexistent_cross_reference_error, print_bib_name, rs_print_fn_class,
16-
write_log_file, write_logs,
17-
},
18-
peekable::{peekable_close, tectonic_eof},
19-
pool::StringPool,
20-
scan::{eat_bst_white_space, scan_fn_def, scan_identifier, Scan, ScanRes},
21-
Bibtex, CiteNumber, GlobalItems, HashPointer, StrIlk,
2+
bibs::get_bib_command_or_entry_and_process,
3+
buffer::{BufTy, GlobalBuffer},
4+
char_info::LexClass,
5+
cite::find_cite_locs_for_this_cite_key,
6+
exec::{check_command_execution, execute_fn, ExecCtx},
7+
hash::{FnClass, HashData},
8+
history::mark_warning,
9+
log::{
10+
already_seen_function_print, bst_err_print_and_look_for_blank_line, bst_id_print,
11+
bst_left_brace_print, bst_right_brace_print, bst_warn_print,
12+
cite_key_disappeared_confusion, eat_bst_print, hash_cite_confusion, log_pr_bib_name,
13+
print_a_token, print_bib_name, print_confusion, print_missing_entry,
14+
rs_bad_cross_reference_print, rs_nonexistent_cross_reference_error, rs_print_fn_class,
15+
write_log_file, write_logs,
2216
},
23-
BibtexError,
17+
peekable::{peekable_close, tectonic_eof},
18+
pool::StringPool,
19+
scan::{eat_bst_white_space, scan_fn_def, scan_identifier, Scan, ScanRes},
20+
Bibtex, BibtexError, CiteNumber, GlobalItems, HashPointer, StrIlk,
2421
};
2522
use std::ptr::NonNull;
2623

@@ -85,7 +82,10 @@ macro_rules! bst_ident {
8582
};
8683
}
8784

88-
fn bst_entry_command(ctx: &mut ExecCtx, globals: &mut GlobalItems<'_>) -> Result<(), BibtexError> {
85+
fn bst_entry_command(
86+
ctx: &mut ExecCtx<'_, '_, '_>,
87+
globals: &mut GlobalItems<'_>,
88+
) -> Result<(), BibtexError> {
8989
if ctx.glbl_ctx().entry_seen {
9090
write_logs("Illegal, another entry command");
9191
bst_err_print_and_look_for_blank_line(ctx.glbl_ctx_mut(), globals.buffers, globals.pool)?;
@@ -226,7 +226,7 @@ fn bst_entry_command(ctx: &mut ExecCtx, globals: &mut GlobalItems<'_>) -> Result
226226
}
227227

228228
fn bst_execute_command(
229-
ctx: &mut ExecCtx,
229+
ctx: &mut ExecCtx<'_, '_, '_>,
230230
globals: &mut GlobalItems<'_>,
231231
) -> Result<(), BibtexError> {
232232
if !ctx.glbl_ctx().read_seen {
@@ -272,7 +272,7 @@ fn bst_execute_command(
272272
}
273273

274274
fn bst_function_command(
275-
ctx: &mut ExecCtx,
275+
ctx: &mut ExecCtx<'_, '_, '_>,
276276
globals: &mut GlobalItems<'_>,
277277
) -> Result<(), BibtexError> {
278278
eat_bst_white!(ctx, globals, "function");
@@ -329,7 +329,7 @@ fn bst_function_command(
329329
}
330330

331331
fn bst_integers_command(
332-
ctx: &mut ExecCtx,
332+
ctx: &mut ExecCtx<'_, '_, '_>,
333333
globals: &mut GlobalItems<'_>,
334334
) -> Result<(), BibtexError> {
335335
eat_bst_white!(ctx, globals, "integers");
@@ -373,7 +373,7 @@ fn bst_integers_command(
373373
}
374374

375375
fn bst_iterate_command(
376-
ctx: &mut ExecCtx,
376+
ctx: &mut ExecCtx<'_, '_, '_>,
377377
globals: &mut GlobalItems<'_>,
378378
) -> Result<(), BibtexError> {
379379
if !ctx.glbl_ctx().read_seen {
@@ -422,7 +422,10 @@ fn bst_iterate_command(
422422
Ok(())
423423
}
424424

425-
fn bst_macro_command(ctx: &mut ExecCtx, globals: &mut GlobalItems<'_>) -> Result<(), BibtexError> {
425+
fn bst_macro_command(
426+
ctx: &mut ExecCtx<'_, '_, '_>,
427+
globals: &mut GlobalItems<'_>,
428+
) -> Result<(), BibtexError> {
426429
if ctx.glbl_ctx().read_seen {
427430
write_logs("Illegal, macro command after read command");
428431
bst_err_print_and_look_for_blank_line(ctx.glbl_ctx_mut(), globals.buffers, globals.pool)?;
@@ -502,7 +505,10 @@ fn bst_macro_command(ctx: &mut ExecCtx, globals: &mut GlobalItems<'_>) -> Result
502505
Ok(())
503506
}
504507

505-
fn bst_read_command(ctx: &mut ExecCtx, globals: &mut GlobalItems<'_>) -> Result<(), BibtexError> {
508+
fn bst_read_command(
509+
ctx: &mut ExecCtx<'_, '_, '_>,
510+
globals: &mut GlobalItems<'_>,
511+
) -> Result<(), BibtexError> {
506512
if ctx.glbl_ctx().read_seen {
507513
write_logs("Illegal, another read command");
508514
bst_err_print_and_look_for_blank_line(ctx.glbl_ctx_mut(), globals.buffers, globals.pool)?;
@@ -579,7 +585,12 @@ fn bst_read_command(ctx: &mut ExecCtx, globals: &mut GlobalItems<'_>) -> Result<
579585
)?;
580586
}
581587
// SAFETY: take_cur_bib_file returns reference to which we're the last owner
582-
unsafe { peekable_close(ctx.glbl_ctx_mut(), globals.bibs.take_cur_bib_file().map(NonNull::from)) };
588+
unsafe {
589+
peekable_close(
590+
ctx.glbl_ctx_mut(),
591+
globals.bibs.take_cur_bib_file().map(NonNull::from),
592+
)
593+
};
583594
globals.bibs.set_ptr(globals.bibs.ptr() + 1);
584595
}
585596

@@ -783,7 +794,7 @@ fn bst_read_command(ctx: &mut ExecCtx, globals: &mut GlobalItems<'_>) -> Result<
783794
}
784795

785796
fn bst_reverse_command(
786-
ctx: &mut ExecCtx,
797+
ctx: &mut ExecCtx<'_, '_, '_>,
787798
globals: &mut GlobalItems<'_>,
788799
) -> Result<(), BibtexError> {
789800
if !ctx.glbl_ctx().read_seen {
@@ -831,7 +842,10 @@ fn bst_reverse_command(
831842
Ok(())
832843
}
833844

834-
fn bst_sort_command(ctx: &mut ExecCtx, globals: &mut GlobalItems<'_>) -> Result<(), BibtexError> {
845+
fn bst_sort_command(
846+
ctx: &mut ExecCtx<'_, '_, '_>,
847+
globals: &mut GlobalItems<'_>,
848+
) -> Result<(), BibtexError> {
835849
if !ctx.glbl_ctx().read_seen {
836850
write_logs("Illegal, sort command before read command");
837851
bst_err_print_and_look_for_blank_line(ctx.glbl_ctx_mut(), globals.buffers, globals.pool)?;
@@ -848,7 +862,7 @@ fn bst_sort_command(ctx: &mut ExecCtx, globals: &mut GlobalItems<'_>) -> Result<
848862
}
849863

850864
fn bst_strings_command(
851-
ctx: &mut ExecCtx,
865+
ctx: &mut ExecCtx<'_, '_, '_>,
852866
globals: &mut GlobalItems<'_>,
853867
) -> Result<(), BibtexError> {
854868
eat_bst_white!(ctx, globals, "strings");
@@ -904,7 +918,7 @@ fn bst_strings_command(
904918
}
905919

906920
fn bad_argument_token(
907-
ctx: &mut Bibtex,
921+
ctx: &mut Bibtex<'_, '_>,
908922
fn_out: Option<&mut HashPointer>,
909923
buffers: &mut GlobalBuffer,
910924
pool: &StringPool,
@@ -937,7 +951,7 @@ fn bad_argument_token(
937951
}
938952

939953
pub(crate) fn get_bst_command_and_process(
940-
ctx: &mut ExecCtx,
954+
ctx: &mut ExecCtx<'_, '_, '_>,
941955
globals: &mut GlobalItems<'_>,
942956
) -> Result<(), BibtexError> {
943957
let init = globals.buffers.init(BufTy::Base);
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::c_api::{
1+
use crate::{
22
xbuf::{SafelyZero, XBuf},
33
ASCIICode, BufPointer,
44
};
@@ -211,10 +211,8 @@ impl GlobalBuffer {
211211
}
212212
}
213213

214-
/// cbindgen:rename-all=ScreamingSnakeCase
215214
#[derive(Copy, Clone, Debug, PartialEq)]
216-
#[repr(C)]
217-
pub enum BufTy {
215+
pub(crate) enum BufTy {
218216
Base,
219217
Sv,
220218
Ex,

crates/engine_bibtex/src/c_api/char_info.rs renamed to crates/engine_bibtex/src/char_info.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::c_api::ASCIICode;
1+
use crate::ASCIICode;
22

33
macro_rules! const_for {
44
($start:literal..$end:literal => $arr:ident[..] = $expr:expr) => {
@@ -19,17 +19,14 @@ macro_rules! const_for {
1919

2020
/// The lexer class of a character - this represents whether the parser considers it to be alphabetic,
2121
/// numeric, etc. Illegal represents tokens that shouldn't show up at all, such as ASCII backspace.
22-
///
23-
/// cbindgen:rename-all=ScreamingSnakeCase
2422
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
25-
#[repr(C)]
26-
pub enum LexClass {
27-
Illegal = 0,
28-
Whitespace = 1,
29-
Alpha = 2,
30-
Numeric = 3,
31-
Sep = 4,
32-
Other = 5,
23+
pub(crate) enum LexClass {
24+
Illegal,
25+
Whitespace,
26+
Alpha,
27+
Numeric,
28+
Sep,
29+
Other,
3330
}
3431

3532
impl LexClass {
@@ -40,13 +37,10 @@ impl LexClass {
4037
}
4138

4239
/// Whether a token counts as valid in an identifier
43-
///
44-
/// cbindgen:rename-all=ScreamingSnakeCase
4540
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
46-
#[repr(C)]
47-
pub enum IdClass {
48-
IllegalIdChar = 0,
49-
LegalIdChar = 1,
41+
pub(crate) enum IdClass {
42+
IllegalIdChar,
43+
LegalIdChar,
5044
}
5145

5246
impl IdClass {

0 commit comments

Comments
 (0)