Skip to content

Commit 651be34

Browse files
committed
Port get_bst_command_and_process
1 parent 0f16f26 commit 651be34

11 files changed

Lines changed: 111 additions & 457 deletions

File tree

crates/bridge_harfbuzz/harfbuzz

Submodule harfbuzz updated 82 files

crates/engine_bibtex/bibtex/bibtex.c

Lines changed: 1 addition & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,12 @@
77

88
#include <stdio.h> /* EOF, snprintf */
99

10-
/* hack: the name eof conflicts with other function declarations under mingw. */
11-
#define eof tectonic_eof
12-
1310
/* duplicated from xetexd.h: */
1411

1512
#include <setjmp.h>
1613

1714
static jmp_buf error_jmpbuf, recover_jmpbuf;
1815

19-
typedef size_t hash_loc;
20-
typedef size_t cite_number;
21-
typedef size_t field_loc;
22-
2316
static void unwrap(CResult res) {
2417
switch (res) {
2518
case CResult_Error:
@@ -47,17 +40,6 @@ static int32_t unwrap_int(CResultInt res) {
4740
return res.ok;
4841
}
4942

50-
static LookupRes unwrap_lookup(CResultLookup res) {
51-
switch (res.tag) {
52-
case CResultLookup_Error:
53-
longjmp(error_jmpbuf, 1);
54-
break;
55-
case CResultLookup_Ok:
56-
break;
57-
}
58-
return res.ok;
59-
}
60-
6143
#define FMT_BUF_SIZE 1024
6244
static char fmt_buf[FMT_BUF_SIZE] = "";
6345

@@ -73,129 +55,6 @@ printf_log(const char *fmt, ...)
7355
puts_log(fmt_buf);
7456
}
7557

76-
//static void
77-
//bst_strings_command(Bibtex* ctx)
78-
//{
79-
// if (!eat_bst_white_space(ctx)) {
80-
// eat_bst_print();
81-
// puts_log("strings");
82-
// unwrap(bst_err_print_and_look_for_blank_line(ctx));
83-
// return;
84-
// }
85-
//
86-
// if (bib_buf_at_offset(BUF_TY_BASE, 2) != 123 /*left_brace */ ) {
87-
// bst_left_brace_print();
88-
// puts_log("strings");
89-
// unwrap(bst_err_print_and_look_for_blank_line(ctx));
90-
// return;
91-
// }
92-
//
93-
// bib_set_buf_offset(BUF_TY_BASE, 2, bib_buf_offset(BUF_TY_BASE, 2) + 1);
94-
//
95-
// if (!eat_bst_white_space(ctx)) {
96-
// eat_bst_print();
97-
// puts_log("strings");
98-
// unwrap(bst_err_print_and_look_for_blank_line(ctx));
99-
// return;
100-
// }
101-
//
102-
// while (bib_buf_at_offset(BUF_TY_BASE, 2) != 125 /*right_brace */ ) {
103-
// ScanRes scan_result = scan_identifier(125 /*right_brace */ , 37 /*comment */ , 37 /*comment */);
104-
// if (scan_result != SCAN_RES_WHITESPACE_ADJACENT && scan_result != SCAN_RES_SPECIFIED_CHAR_ADJACENT) {
105-
// unwrap(bst_id_print(scan_result));
106-
// puts_log("strings");
107-
// unwrap(bst_err_print_and_look_for_blank_line(ctx));
108-
// return;
109-
// }
110-
//
111-
// lower_case(BUF_TY_BASE, bib_buf_offset(BUF_TY_BASE, 1), bib_buf_offset(BUF_TY_BASE, 2) - bib_buf_offset(BUF_TY_BASE, 1));
112-
// LookupRes hash = unwrap_lookup(str_lookup(BUF_TY_BASE, bib_buf_offset(BUF_TY_BASE, 1),
113-
// bib_buf_offset(BUF_TY_BASE, 2) - bib_buf_offset(BUF_TY_BASE, 1),
114-
// STR_ILK_BST_FN, true));
115-
// hash_loc fn_loc = hash.loc;
116-
// if (hash.exists) {
117-
// unwrap(already_seen_function_print(ctx, fn_loc));
118-
// return;
119-
// }
120-
//
121-
// set_fn_type(fn_loc, FN_CLASS_STR_GLBL_VAR);
122-
// set_ilk_info(fn_loc, num_glb_strs());
123-
//
124-
// check_grow_global_strs();
125-
//
126-
// set_num_glb_strs(num_glb_strs() + 1);
127-
//
128-
// if (!eat_bst_white_space(ctx)) {
129-
// eat_bst_print();
130-
// puts_log("strings");
131-
// unwrap(bst_err_print_and_look_for_blank_line(ctx));
132-
// return;
133-
// }
134-
// }
135-
//
136-
// bib_set_buf_offset(BUF_TY_BASE, 2, bib_buf_offset(BUF_TY_BASE, 2) + 1);
137-
//}
138-
139-
static void
140-
get_bst_command_and_process(ExecCtx* ctx)
141-
{
142-
if (!scan_alpha()) {
143-
printf_log("\"%c\" can't start a style-file command", bib_buf_at_offset(BUF_TY_BASE, 2));
144-
bst_err_print_and_look_for_blank_line(ctx->glbl_ctx);
145-
return;
146-
}
147-
148-
lower_case(BUF_TY_BASE, bib_buf_offset(BUF_TY_BASE, 1), (bib_buf_offset(BUF_TY_BASE, 2) - bib_buf_offset(BUF_TY_BASE, 1)));
149-
LookupRes hash = unwrap_lookup(str_lookup(BUF_TY_BASE, bib_buf_offset(BUF_TY_BASE, 1),
150-
(bib_buf_offset(BUF_TY_BASE, 2) - bib_buf_offset(BUF_TY_BASE, 1)),
151-
STR_ILK_BST_COMMAND, false));
152-
int32_t command_num = ilk_info(hash.loc);
153-
if (!hash.exists) {
154-
print_a_token();
155-
puts_log(" is an illegal style-file command");
156-
bst_err_print_and_look_for_blank_line(ctx->glbl_ctx);
157-
return;
158-
}
159-
160-
switch (command_num) {
161-
case 0:
162-
unwrap(bst_entry_command(ctx));
163-
break;
164-
case 1:
165-
unwrap(bst_execute_command(ctx));
166-
break;
167-
case 2:
168-
unwrap(bst_function_command(ctx));
169-
break;
170-
case 3:
171-
unwrap(bst_integers_command(ctx));
172-
break;
173-
case 4:
174-
unwrap(bst_iterate_command(ctx));
175-
break;
176-
case 5:
177-
unwrap(bst_macro_command(ctx));
178-
break;
179-
case 6:
180-
unwrap(bst_read_command(ctx));
181-
break;
182-
case 7:
183-
unwrap(bst_reverse_command(ctx));
184-
break;
185-
case 8:
186-
unwrap(bst_sort_command(ctx));
187-
break;
188-
case 9:
189-
unwrap(bst_strings_command(ctx));
190-
break;
191-
default:
192-
puts_log("Unknown style-file command");
193-
print_confusion();
194-
longjmp(error_jmpbuf, 1);
195-
break;
196-
}
197-
}
198-
19958
History
20059
bibtex_main(Bibtex* glbl_ctx, const char *aux_file_name)
20160
{
@@ -257,7 +116,7 @@ bibtex_main(Bibtex* glbl_ctx, const char *aux_file_name)
257116
while(true) {
258117
if (!eat_bst_white_space(ctx.glbl_ctx))
259118
break;
260-
get_bst_command_and_process(&ctx);
119+
unwrap(get_bst_command_and_process(&ctx));
261120
}
262121
}
263122

crates/engine_bibtex/bibtex/bibtex_bindings.h

Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,6 @@ typedef enum {
2929
HISTORY_ABORTED = 4,
3030
} History;
3131

32-
enum StrIlk
33-
#ifdef __cplusplus
34-
: uint8_t
35-
#endif // __cplusplus
36-
{
37-
STR_ILK_TEXT = 0,
38-
STR_ILK_INTEGER = 1,
39-
STR_ILK_AUX_COMMAND = 2,
40-
STR_ILK_AUX_FILE = 3,
41-
STR_ILK_BST_COMMAND = 4,
42-
STR_ILK_BST_FILE = 5,
43-
STR_ILK_BIB_FILE = 6,
44-
STR_ILK_FILE_EXT = 7,
45-
STR_ILK_CITE = 9,
46-
STR_ILK_LC_CITE = 10,
47-
STR_ILK_BST_FN = 11,
48-
STR_ILK_BIB_COMMAND = 12,
49-
STR_ILK_MACRO = 13,
50-
STR_ILK_CONTROL_SEQ = 14,
51-
};
52-
#ifndef __cplusplus
53-
typedef uint8_t StrIlk;
54-
#endif // __cplusplus
55-
5632
typedef struct PeekableInput PeekableInput;
5733

5834
typedef struct XBuf_ExecVal XBuf_ExecVal;
@@ -118,36 +94,8 @@ typedef struct {
11894
StrNumber bib_str_ptr;
11995
} ExecCtx;
12096

121-
typedef uint8_t ASCIICode;
122-
12397
typedef uintptr_t BufPointer;
12498

125-
typedef struct {
126-
/**
127-
* The location of the string - where it exists, was inserted, of if insert is false,
128-
* where it *would* have been inserted
129-
*/
130-
uintptr_t loc;
131-
/**
132-
* Whether the string existed in the hash table already
133-
*/
134-
bool exists;
135-
} LookupRes;
136-
137-
typedef enum {
138-
CResultLookup_Error,
139-
CResultLookup_Ok,
140-
} CResultLookup_Tag;
141-
142-
typedef struct {
143-
CResultLookup_Tag tag;
144-
union {
145-
struct {
146-
LookupRes ok;
147-
};
148-
};
149-
} CResultLookup;
150-
15199
#ifdef __cplusplus
152100
extern "C" {
153101
#endif // __cplusplus
@@ -172,40 +120,14 @@ CResult last_check_for_aux_errors(Bibtex *ctx);
172120

173121
int32_t bib_line_num(void);
174122

175-
CResult bst_entry_command(ExecCtx *ctx);
176-
177-
CResult bst_execute_command(ExecCtx *ctx);
178-
179-
CResult bst_function_command(ExecCtx *ctx);
180-
181-
CResult bst_integers_command(ExecCtx *ctx);
182-
183-
CResult bst_iterate_command(ExecCtx *ctx);
184-
185-
CResult bst_macro_command(ExecCtx *ctx);
186-
187-
CResult bst_read_command(ExecCtx *ctx);
188-
189-
CResult bst_reverse_command(ExecCtx *ctx);
190-
191-
CResult bst_sort_command(ExecCtx *ctx);
192-
193-
CResult bst_strings_command(ExecCtx *ctx);
194-
195-
ASCIICode bib_buf_at_offset(BufTy ty, uintptr_t num);
196-
197-
BufPointer bib_buf_offset(BufTy ty, uintptr_t num);
123+
CResult get_bst_command_and_process(ExecCtx *ctx);
198124

199125
void bib_set_buf_offset(BufTy ty, uintptr_t num, BufPointer offset);
200126

201127
BufPointer bib_buf_len(BufTy ty);
202128

203-
void lower_case(BufTy buf, BufPointer ptr, BufPointer len);
204-
205129
ExecCtx init_exec_ctx(Bibtex *glbl_ctx);
206130

207-
int32_t ilk_info(HashPointer pos);
208-
209131
int32_t hash_size(void);
210132

211133
uintptr_t hash_prime(void);
@@ -224,26 +146,18 @@ void puts_log(const char *str);
224146

225147
void print_confusion(void);
226148

227-
void print_a_token(void);
228-
229149
CResult print_aux_name(void);
230150

231151
CResult log_pr_aux_name(void);
232152

233153
CResult print_bib_name(void);
234154

235-
CResult bst_err_print_and_look_for_blank_line(Bibtex *ctx);
236-
237155
int peekable_close(PeekableInput *peekable);
238156

239157
bool input_ln(PeekableInput *peekable);
240158

241159
uintptr_t bib_max_strings(void);
242160

243-
CResultLookup str_lookup(BufTy buf, BufPointer ptr, BufPointer len, StrIlk ilk, bool insert);
244-
245-
bool scan_alpha(void);
246-
247161
bool eat_bst_white_space(Bibtex *ctx);
248162

249163
#ifdef __cplusplus

crates/engine_bibtex/src/c_api/auxi.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ use crate::{
1010
aux_end1_err_print, aux_end2_err_print, aux_err_illegal_another_print,
1111
aux_err_no_right_brace_print, aux_err_print, aux_err_stuff_after_right_brace_print,
1212
aux_err_white_space_in_argument_print, hash_cite_confusion, log_pr_bst_name,
13-
print_a_pool_str, print_confusion, print_overflow, rs_log_pr_aux_name,
14-
rs_print_a_token, rs_print_aux_name, rs_print_bib_name, write_log_file, write_logs,
15-
AuxTy,
13+
print_a_pool_str, print_a_token, print_confusion, print_overflow, rs_log_pr_aux_name,
14+
rs_print_aux_name, rs_print_bib_name, write_log_file, write_logs, AuxTy,
1615
},
1716
peekable::{peekable_close, peekable_open, PeekableInput},
1817
pool::{with_pool, StringPool},
@@ -320,7 +319,7 @@ fn aux_citation_command(
320319
let uc_res = pool.lookup_str(hash, cite, StrIlk::Cite);
321320
if !uc_res.exists {
322321
write_logs("Case mismatch error between cite keys ");
323-
rs_print_a_token(buffers);
322+
print_a_token(buffers);
324323
write_logs(" and ");
325324
print_a_pool_str(
326325
cites.get_cite(hash.ilk_info(hash.ilk_info(lc_res.loc) as usize) as usize),
@@ -385,7 +384,7 @@ fn aux_input_command(
385384

386385
aux.set_ptr(aux.ptr() + 1);
387386
if aux.ptr() == AUX_STACK_SIZE {
388-
rs_print_a_token(buffers);
387+
print_a_token(buffers);
389388
write_logs(": ");
390389
print_overflow();
391390
write_logs(&format!("auxiliary file depth {}\n", AUX_STACK_SIZE));
@@ -400,7 +399,7 @@ fn aux_input_command(
400399
[buffers.offset(BufTy::Base, 2) - aux_ext.len()..buffers.offset(BufTy::Base, 2)]);
401400

402401
if !aux_extension_ok {
403-
rs_print_a_token(buffers);
402+
print_a_token(buffers);
404403
write_logs(" has a wrong extension");
405404
aux.set_ptr(aux.ptr() - 1);
406405
aux_err_print(buffers, aux, pool)?;

crates/engine_bibtex/src/c_api/bibs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
log::{
88
bib_cmd_confusion, bib_equals_sign_print, bib_err_print, bib_id_print,
99
bib_one_of_two_print, bib_warn_print, cite_key_disappeared_confusion, eat_bib_print,
10-
hash_cite_confusion, print_confusion, rs_print_a_token, write_log_file, write_logs,
10+
hash_cite_confusion, print_a_token, print_confusion, write_log_file, write_logs,
1111
},
1212
peekable::{rs_input_ln, PeekableInput},
1313
pool::StringPool,
@@ -648,7 +648,7 @@ pub(crate) fn get_bib_command_or_entry_and_process(
648648
.cites
649649
.set_type(globals.cites.entry_ptr(), HashData::undefined());
650650
write_logs("Warning--entry type for \"");
651-
rs_print_a_token(globals.buffers);
651+
print_a_token(globals.buffers);
652652
write_logs("\" isn't style-file defined\n");
653653
bib_warn_print(globals.pool, globals.bibs)?;
654654
}

0 commit comments

Comments
 (0)