Skip to content

Commit ce0dd00

Browse files
committed
Port bibtex_main - just cleanup of engine to go
1 parent 651be34 commit ce0dd00

13 files changed

Lines changed: 180 additions & 521 deletions

File tree

crates/engine_bibtex/bibtex/bibtex.c

Lines changed: 0 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -9,159 +9,6 @@
99

1010
/* duplicated from xetexd.h: */
1111

12-
#include <setjmp.h>
13-
14-
static jmp_buf error_jmpbuf, recover_jmpbuf;
15-
16-
static void unwrap(CResult res) {
17-
switch (res) {
18-
case CResult_Error:
19-
longjmp(error_jmpbuf, 1);
20-
break;
21-
case CResult_Recover:
22-
longjmp(recover_jmpbuf, 1);
23-
break;
24-
case CResult_Ok:
25-
break;
26-
}
27-
}
28-
29-
static int32_t unwrap_int(CResultInt res) {
30-
switch (res.tag) {
31-
case CResultInt_Error:
32-
longjmp(error_jmpbuf, 1);
33-
break;
34-
case CResultInt_Recover:
35-
longjmp(recover_jmpbuf, 1);
36-
break;
37-
case CResultInt_Ok:
38-
break;
39-
}
40-
return res.ok;
41-
}
42-
43-
#define FMT_BUF_SIZE 1024
44-
static char fmt_buf[FMT_BUF_SIZE] = "";
45-
46-
PRINTF_FUNC(1,2) static void
47-
printf_log(const char *fmt, ...)
48-
{
49-
va_list ap;
50-
51-
va_start (ap, fmt);
52-
vsnprintf (fmt_buf, FMT_BUF_SIZE, fmt, ap);
53-
va_end (ap);
54-
55-
puts_log(fmt_buf);
56-
}
57-
58-
History
59-
bibtex_main(Bibtex* glbl_ctx, const char *aux_file_name)
60-
{
61-
reset_all();
62-
63-
if (!init_standard_output())
64-
return HISTORY_FATAL_ERROR;
65-
66-
if (unwrap_int(initialize(glbl_ctx, aux_file_name))) {
67-
/* TODO: log initialization or get_the_..() error */
68-
return HISTORY_FATAL_ERROR;
69-
}
70-
71-
if (setjmp(error_jmpbuf) == 1)
72-
goto close_up_shop;
73-
74-
if (glbl_ctx->config.verbose)
75-
puts_log("This is BibTeX, Version 0.99d\n");
76-
else
77-
bib_log_prints("This is BibTeX, Version 0.99d\n");
78-
79-
{
80-
char buf[512];
81-
snprintf (buf, sizeof(buf) - 1, "Capacity: max_strings=%ld, hash_size=%ld, hash_prime=%ld\n",
82-
(long) bib_max_strings(), (long) hash_size(), (long) hash_prime());
83-
bib_log_prints(buf);
84-
}
85-
86-
if (glbl_ctx->config.verbose) {
87-
puts_log("The top-level auxiliary file: ");
88-
unwrap(print_aux_name());
89-
} else {
90-
bib_log_prints("The top-level auxiliary file: ");
91-
unwrap(log_pr_aux_name());
92-
}
93-
94-
while (true) {
95-
set_cur_aux_ln(cur_aux_ln() + 1);
96-
97-
if (!input_ln(cur_aux_file())) {
98-
if (pop_the_aux_stack())
99-
break;
100-
} else {
101-
unwrap(get_aux_command_and_process(glbl_ctx));
102-
}
103-
}
104-
105-
unwrap(last_check_for_aux_errors(glbl_ctx));
106-
107-
if (glbl_ctx->bst_str == 0)
108-
goto no_bst_file;
109-
110-
glbl_ctx->bst_line_num = 0;
111-
glbl_ctx->bbl_line_num = 1;
112-
bib_set_buf_offset(BUF_TY_BASE, 2, bib_buf_len(BUF_TY_BASE));
113-
114-
if (setjmp(recover_jmpbuf) == 0) {
115-
ExecCtx ctx = init_exec_ctx(glbl_ctx);
116-
while(true) {
117-
if (!eat_bst_white_space(ctx.glbl_ctx))
118-
break;
119-
unwrap(get_bst_command_and_process(&ctx));
120-
}
121-
}
122-
123-
peekable_close(glbl_ctx->bst_file);
124-
glbl_ctx->bst_file = NULL;
125-
126-
no_bst_file:
127-
ttstub_output_close (glbl_ctx->bbl_file);
128-
129-
close_up_shop:
130-
131-
if (glbl_ctx->read_performed && !glbl_ctx->reading_completed) {
132-
printf_log("Aborted at line %ld of file ", (long) bib_line_num());
133-
unwrap(print_bib_name());
134-
}
135-
136-
switch (get_history()) {
137-
case HISTORY_SPOTLESS:
138-
break;
139-
case HISTORY_WARNING_ISSUED:
140-
if (err_count() == 1)
141-
puts_log("(There was 1 warning)\n");
142-
else
143-
printf_log("(There were %ld warnings)\n", (long) err_count());
144-
break;
145-
case HISTORY_ERROR_ISSUED:
146-
if (err_count() == 1)
147-
puts_log("(There was 1 error message)\n");
148-
else
149-
printf_log("(There were %ld error messages)\n", (long) err_count());
150-
break;
151-
case HISTORY_FATAL_ERROR:
152-
puts_log("(That was a fatal error)\n");
153-
break;
154-
default:
155-
puts_log("History is bunk");
156-
print_confusion();
157-
break;
158-
}
159-
160-
bib_close_log();
161-
return get_history();
162-
}
163-
164-
16512
History
16613
tt_engine_bibtex_main(ttbc_state_t *api, Bibtex* ctx, const char *aux_file_name)
16714
{

crates/engine_bibtex/bibtex/bibtex_bindings.h

Lines changed: 1 addition & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,6 @@
77
#include <stdlib.h>
88
#include "tectonic_bridge_core.h"
99

10-
typedef enum {
11-
BUF_TY_BASE,
12-
BUF_TY_SV,
13-
BUF_TY_EX,
14-
BUF_TY_OUT,
15-
BUF_TY_NAME_SEP,
16-
} BufTy;
17-
18-
typedef enum {
19-
CResult_Error,
20-
CResult_Recover,
21-
CResult_Ok,
22-
} CResult;
23-
2410
typedef enum {
2511
HISTORY_SPOTLESS = 0,
2612
HISTORY_WARNING_ISSUED = 1,
@@ -31,23 +17,6 @@ typedef enum {
3117

3218
typedef struct PeekableInput PeekableInput;
3319

34-
typedef struct XBuf_ExecVal XBuf_ExecVal;
35-
36-
typedef enum {
37-
CResultInt_Error,
38-
CResultInt_Recover,
39-
CResultInt_Ok,
40-
} CResultInt_Tag;
41-
42-
typedef struct {
43-
CResultInt_Tag tag;
44-
union {
45-
struct {
46-
int32_t ok;
47-
};
48-
};
49-
} CResultInt;
50-
5120
typedef struct {
5221
uint32_t min_crossrefs;
5322
bool verbose;
@@ -82,84 +51,18 @@ typedef struct {
8251
HashPointer s_aux_extension;
8352
} Bibtex;
8453

85-
typedef struct {
86-
Bibtex *glbl_ctx;
87-
HashPointer _default;
88-
XBuf_ExecVal *lit_stack;
89-
uintptr_t lit_stk_ptr;
90-
bool mess_with_entries;
91-
/**
92-
* Pointer to the current top of the string pool, used to optimize certain string operations
93-
*/
94-
StrNumber bib_str_ptr;
95-
} ExecCtx;
96-
97-
typedef uintptr_t BufPointer;
98-
9954
#ifdef __cplusplus
10055
extern "C" {
10156
#endif // __cplusplus
10257

103-
void reset_all(void);
104-
105-
CResultInt initialize(Bibtex *ctx, const char *aux_file_name);
58+
History bibtex_main(Bibtex *ctx, const char *aux_file_name);
10659

10760
extern History tt_engine_bibtex_main(ttbc_state_t *api, Bibtex *ctx, const char *aux_name);
10861

109-
PeekableInput *cur_aux_file(void);
110-
111-
int32_t cur_aux_ln(void);
112-
113-
void set_cur_aux_ln(int32_t ln);
114-
115-
CResult get_aux_command_and_process(Bibtex *ctx);
116-
117-
bool pop_the_aux_stack(void);
118-
119-
CResult last_check_for_aux_errors(Bibtex *ctx);
120-
121-
int32_t bib_line_num(void);
122-
123-
CResult get_bst_command_and_process(ExecCtx *ctx);
124-
125-
void bib_set_buf_offset(BufTy ty, uintptr_t num, BufPointer offset);
126-
127-
BufPointer bib_buf_len(BufTy ty);
128-
129-
ExecCtx init_exec_ctx(Bibtex *glbl_ctx);
130-
131-
int32_t hash_size(void);
132-
133-
uintptr_t hash_prime(void);
134-
13562
History get_history(void);
13663

13764
uint32_t err_count(void);
13865

139-
bool init_standard_output(void);
140-
141-
void bib_close_log(void);
142-
143-
void bib_log_prints(const char *str);
144-
145-
void puts_log(const char *str);
146-
147-
void print_confusion(void);
148-
149-
CResult print_aux_name(void);
150-
151-
CResult log_pr_aux_name(void);
152-
153-
CResult print_bib_name(void);
154-
155-
int peekable_close(PeekableInput *peekable);
156-
157-
bool input_ln(PeekableInput *peekable);
158-
159-
uintptr_t bib_max_strings(void);
160-
161-
bool eat_bst_white_space(Bibtex *ctx);
162-
16366
#ifdef __cplusplus
16467
} // extern "C"
16568
#endif // __cplusplus

0 commit comments

Comments
 (0)