Skip to content

Commit

Permalink
Merge pull request #149 from pkgw/c-cleanups
Browse files Browse the repository at this point in the history
C cleanups
  • Loading branch information
pkgw authored Jan 22, 2018
2 parents 17ee426 + df6a915 commit 00b8d8a
Show file tree
Hide file tree
Showing 38 changed files with 4,657 additions and 4,907 deletions.
18 changes: 1 addition & 17 deletions src/engines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ impl<'a, I: 'a + IoProvider> ExecutionState<'a, I> {
#[repr(C)]
struct TectonicBridgeApi {
context: *const libc::c_void,
kpse_find_file: *const libc::c_void,
issue_warning: *const libc::c_void,
issue_error: *const libc::c_void,
get_file_md5: *const libc::c_void,
Expand Down Expand Up @@ -463,20 +462,6 @@ extern {

// Entry points for the C/C++ API functions.

fn kpse_find_file<'a, I: 'a + IoProvider>(es: *mut ExecutionState<'a, I>, name: *const libc::c_char, format: libc::c_int, must_exist: libc::c_int) -> *const libc::c_char {
let es = unsafe { &mut *es };
let rname = unsafe { CStr::from_ptr(name) };
let rformat = c_format_to_rust(format);
let rmust_exist = must_exist != 0;

// This function can never work for Tectonic because files in the bundle
// can't be referenced by path names.
tt_error!(es.status, "unimplemented feature: kpse_find_file(); please report an issue on GitHub!");
tt_error!(es.status, "Diagnostics: {:?}, {:?} ({}), {}", rname, rformat, format, rmust_exist);

ptr::null()
}

fn issue_warning<'a, I: 'a + IoProvider>(es: *mut ExecutionState<'a, I>, text: *const libc::c_char) {
let es = unsafe { &mut *es };
let rtext = unsafe { CStr::from_ptr(text) };
Expand Down Expand Up @@ -692,7 +677,6 @@ impl TectonicBridgeApi {
fn new<'a, I: 'a + IoProvider>(exec_state: &ExecutionState<'a, I>) -> TectonicBridgeApi {
TectonicBridgeApi {
context: (exec_state as *const ExecutionState<'a, I>) as *const libc::c_void,
kpse_find_file: kpse_find_file::<'a, I> as *const libc::c_void,
issue_warning: issue_warning::<'a, I> as *const libc::c_void,
issue_error: issue_error::<'a, I> as *const libc::c_void,
get_file_md5: get_file_md5::<'a, I> as *const libc::c_void,
Expand All @@ -718,7 +702,7 @@ impl TectonicBridgeApi {

// Finally, some support -- several of the C API functions pass arguments that
// are "file format" enumerations. This code bridges the two. See the
// `kpse_file_format_type` enum in <tectonic/core-bridge.h>.
// `tt_input_format_type` enum in <tectonic/core-bridge.h>.

#[derive(Clone,Copy,Debug)]
enum FileFormat {
Expand Down
8 changes: 4 additions & 4 deletions tectonic/XeTeXFontInst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,11 @@ XeTeXFontInst::initialize(const char* pathname, int index, int &status)
}

// Here we emulate some logic that was originally in find_native_font();
rust_input_handle_t handle = ttstub_input_open (pathname, kpse_opentype_format, 0);
rust_input_handle_t handle = ttstub_input_open (pathname, TTIF_OPENTYPE, 0);
if (handle == NULL)
handle = ttstub_input_open (pathname, kpse_truetype_format, 0);
handle = ttstub_input_open (pathname, TTIF_TRUETYPE, 0);
if (handle == NULL)
handle = ttstub_input_open (pathname, kpse_type1_format, 0);
handle = ttstub_input_open (pathname, TTIF_TYPE1, 0);
if (handle == NULL) {
status = 1;
return;
Expand Down Expand Up @@ -353,7 +353,7 @@ XeTeXFontInst::initialize(const char* pathname, int index, int &status)
if (p != NULL && strlen(p) == 4 && tolower(*(p+1)) == 'p' && tolower(*(p+2)) == 'f')
strcpy(p, ".afm");

rust_input_handle_t afm_handle = ttstub_input_open (afm, kpse_afm_format, 0);
rust_input_handle_t afm_handle = ttstub_input_open (afm, TTIF_AFM, 0);
free (afm);

if (afm_handle != NULL) {
Expand Down
8 changes: 4 additions & 4 deletions tectonic/XeTeX_ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ load_mapping_file(const char* s, const char* e, char byteMapping)
buffer[e - s] = 0;
strcat(buffer, ".tec");

map = ttstub_input_open (buffer, kpse_miscfonts_format, 0);
map = ttstub_input_open (buffer, TTIF_MISCFONTS, 0);
if (map) {
size_t mappingSize = ttstub_input_get_size (map);
Byte *mapping = xmalloc(mappingSize);
Expand Down Expand Up @@ -1334,9 +1334,9 @@ snap_zone(scaled* value, scaled snap_value, scaled fuzz)
void
get_native_char_height_depth(integer font, integer ch, scaled* height, scaled* depth)
{
#define QUAD(f) font_info[6+param_base[f]].cint
#define X_HEIGHT(f) font_info[5+param_base[f]].cint
#define CAP_HEIGHT(f) font_info[8+param_base[f]].cint
#define QUAD(f) font_info[6+param_base[f]].b32.s1
#define X_HEIGHT(f) font_info[5+param_base[f]].b32.s1
#define CAP_HEIGHT(f) font_info[8+param_base[f]].b32.s1

float ht = 0.0;
float dp = 0.0;
Expand Down
12 changes: 6 additions & 6 deletions tectonic/XeTeX_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ authorization from the copyright holders.
#define native_info_offset 4
#define native_glyph_info_offset 5

#define node_width(node) node[width_offset].cint
#define node_depth(node) node[depth_offset].cint
#define node_height(node) node[height_offset].cint
#define native_length(node) node[native_info_offset].qqqq.u.B2
#define native_font(node) node[native_info_offset].qqqq.u.B1
#define native_glyph_count(node) node[native_info_offset].qqqq.u.B3
#define node_width(node) node[width_offset].b32.s1
#define node_depth(node) node[depth_offset].b32.s1
#define node_height(node) node[height_offset].b32.s1
#define native_length(node) node[native_info_offset].b16.s1
#define native_font(node) node[native_info_offset].b16.s2
#define native_glyph_count(node) node[native_info_offset].b16.s0
#define native_glyph_info_ptr(node) node[native_glyph_info_offset].ptr
#define native_glyph_info_size 10 /* info for each glyph is location (FixedPoint) + glyph ID (uint16_t) */

Expand Down
4 changes: 2 additions & 2 deletions tectonic/XeTeX_pic.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ count_pdf_file_pages (void)
rust_input_handle_t handle;
pdf_file *pf;

handle = ttstub_input_open ((const char *) name_of_file + 1, kpse_pict_format, 0);
handle = ttstub_input_open ((const char *) name_of_file + 1, TTIF_PICT, 0);
if (handle == NULL)
return 0;

Expand Down Expand Up @@ -204,7 +204,7 @@ find_pic_file (char **path, real_rect *bounds, int pdfBoxType, int page)
int err = -1;
rust_input_handle_t handle;

handle = ttstub_input_open (in_path, kpse_pict_format, 0);
handle = ttstub_input_open (in_path, TTIF_PICT, 0);
bounds->x = bounds->y = bounds->wd = bounds->ht = 0.0;

if (handle == NULL)
Expand Down
10 changes: 5 additions & 5 deletions tectonic/bibtex.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ typedef struct {


static peekable_input_t *
peekable_open (const char *path, kpse_file_format_type format)
peekable_open (const char *path, tt_input_format_type format)
{
rust_input_handle_t handle;
peekable_input_t *peekable;
Expand Down Expand Up @@ -5092,7 +5092,7 @@ get_the_top_level_aux_file_name(const char *aux_file_name)
/* this code used to auto-add the .aux extension if needed; we don't */

aux_ptr = 0;
if ((aux_file[aux_ptr] = peekable_open ((char *) name_of_file + 1, kpse_tex_format)) == NULL) {
if ((aux_file[aux_ptr] = peekable_open ((char *) name_of_file + 1, TTIF_TEX)) == NULL) {
sam_wrong_file_name_print();
return 1;
}
Expand Down Expand Up @@ -5185,7 +5185,7 @@ static void aux_bib_data_command(void)
return;
}
start_name(bib_list[bib_ptr]);
if ((bib_file[bib_ptr] = peekable_open ((char *) name_of_file + 1, kpse_bib_format)) == NULL) {
if ((bib_file[bib_ptr] = peekable_open ((char *) name_of_file + 1, TTIF_BIB)) == NULL) {
puts_log("I couldn't open database file ");
print_bib_name();
aux_err_print();
Expand Down Expand Up @@ -5237,7 +5237,7 @@ static void aux_bib_style_command(void)
longjmp(error_jmpbuf, 1);
}
start_name(bst_str);
if ((bst_file = peekable_open ((char *) name_of_file + 1, kpse_bst_format)) == NULL) {
if ((bst_file = peekable_open ((char *) name_of_file + 1, TTIF_BST)) == NULL) {
puts_log("I couldn't open style file ");
print_bst_name();
bst_str = 0;
Expand Down Expand Up @@ -5398,7 +5398,7 @@ static void aux_input_command(void)
start_name(aux_list[aux_ptr]);
name_ptr = name_length + 1;
name_of_file[name_ptr] = 0;
if ((aux_file[aux_ptr] = peekable_open ((char *) name_of_file + 1, kpse_tex_format)) == NULL) {
if ((aux_file[aux_ptr] = peekable_open ((char *) name_of_file + 1, TTIF_TEX)) == NULL) {
puts_log("I couldn't open auxiliary file ");
print_aux_name();
aux_ptr = aux_ptr - 1;
Expand Down
36 changes: 18 additions & 18 deletions tectonic/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@
#define GLUE_PAR__thick_mu_skip 18
#define GLUE_PARS 19

#define GLUEPAR(X) (eqtb[GLUE_BASE + GLUE_PAR__##X].hh.v.RH)
#define GLUEPAR(X) (eqtb[GLUE_BASE + GLUE_PAR__##X].b32.s1)

#define SKIP_BASE (GLUE_BASE + GLUE_PARS)
#define SKIP_REG(n) (eqtb[SKIP_BASE + (n)].hh.v.RH)
#define SKIP_REG(n) (eqtb[SKIP_BASE + (n)].b32.s1)

#define MU_SKIP_BASE (SKIP_BASE + NUMBER_REGS)
#define MU_SKIP_REG(n) (eqtb[MU_SKIP_BASE + (n)].hh.v.RH)
#define MU_SKIP_REG(n) (eqtb[MU_SKIP_BASE + (n)].b32.s1)

/* "region 4": local halfword values like baselineskip. Some of these are
* used as arguments to ASSIGN_TOKS, SET_SHAPE, etc. */
Expand All @@ -113,10 +113,10 @@
#define LOCAL__xetex_inter_char 11
#define LOCAL__TectonicCodaTokens 12
#define NUM_LOCALS 13
#define LOCAL(n) (eqtb[LOCAL_BASE + LOCAL__##n].hh.v.RH)
#define LOCAL(n) (eqtb[LOCAL_BASE + LOCAL__##n].b32.s1)

#define TOKS_BASE (LOCAL_BASE + NUM_LOCALS)
#define TOKS_REG(n) (eqtb[TOKS_BASE + (n)].hh.v.RH)
#define TOKS_REG(n) (eqtb[TOKS_BASE + (n)].b32.s1)

#define ETEX_PEN_BASE (TOKS_BASE + NUMBER_REGS)
#define INTER_LINE_PENALTIES_LOC (ETEX_PEN_BASE + 0)
Expand All @@ -126,29 +126,29 @@
#define ETEX_PENS (ETEX_PEN_BASE + 4)

#define BOX_BASE ETEX_PENS
#define BOX_REG(n) (eqtb[BOX_BASE + (n)].hh.v.RH)
#define BOX_REG(n) (eqtb[BOX_BASE + (n)].b32.s1)

#define CUR_FONT_LOC (BOX_BASE + NUMBER_REGS)
#define MATH_FONT_BASE (CUR_FONT_LOC + 1)
#define MATH_FONT(n) (eqtb[MATH_FONT_BASE + (n)].hh.v.RH)
#define MATH_FONT(n) (eqtb[MATH_FONT_BASE + (n)].b32.s1)

#define CAT_CODE_BASE (MATH_FONT_BASE + NUMBER_MATH_FONTS)
#define CAT_CODE(n) (eqtb[CAT_CODE_BASE + (n)].hh.v.RH)
#define CAT_CODE(n) (eqtb[CAT_CODE_BASE + (n)].b32.s1)

#define LC_CODE_BASE (CAT_CODE_BASE + NUMBER_USVS)
#define LC_CODE(n) (eqtb[LC_CODE_BASE + (n)].hh.v.RH)
#define LC_CODE(n) (eqtb[LC_CODE_BASE + (n)].b32.s1)

#define UC_CODE_BASE (LC_CODE_BASE + NUMBER_USVS)
#define UC_CODE(n) (eqtb[UC_CODE_BASE + (n)].hh.v.RH)
#define UC_CODE(n) (eqtb[UC_CODE_BASE + (n)].b32.s1)

#define SF_CODE_BASE (UC_CODE_BASE + NUMBER_USVS)
#define SF_CODE(n) (eqtb[SF_CODE_BASE + (n)].hh.v.RH)
#define SF_CODE(n) (eqtb[SF_CODE_BASE + (n)].b32.s1)

#define MATH_CODE_BASE (SF_CODE_BASE + NUMBER_USVS)
#define MATH_CODE(n) (eqtb[MATH_CODE_BASE + (n)].hh.v.RH)
#define MATH_CODE(n) (eqtb[MATH_CODE_BASE + (n)].b32.s1)

#define CHAR_SUB_CODE_BASE (MATH_CODE_BASE + NUMBER_USVS)
#define CHAR_SUB_CODE(n) (eqtb[CHAR_SUB_CODE_BASE + (n)].hh.v.RH)
#define CHAR_SUB_CODE(n) (eqtb[CHAR_SUB_CODE_BASE + (n)].b32.s1)

/* "region 5": current fullword integers like hyphenation penalty */

Expand Down Expand Up @@ -241,13 +241,13 @@
#define INT_PAR__pdfoutput 84
#define INT_PARS 85

#define INTPAR(x) (eqtb[INT_BASE + INT_PAR__##x].cint)
#define INTPAR(x) (eqtb[INT_BASE + INT_PAR__##x].b32.s1)

#define COUNT_BASE (INT_BASE + INT_PARS)
#define COUNT_REG(n) (eqtb[COUNT_BASE + (n)].cint)
#define COUNT_REG(n) (eqtb[COUNT_BASE + (n)].b32.s1)

#define DEL_CODE_BASE (COUNT_BASE + NUMBER_REGS)
#define DEL_CODE(n) (eqtb[DEL_CODE_BASE + (n)].cint)
#define DEL_CODE(n) (eqtb[DEL_CODE_BASE + (n)].b32.s1)

/* "region 6": current fullword dimensions like hsize */

Expand Down Expand Up @@ -278,10 +278,10 @@
#define DIMEN_PAR__pdf_page_height 22
#define DIMEN_PARS 23

#define DIMENPAR(x) (eqtb[DIMEN_BASE + DIMEN_PAR__##x].cint)
#define DIMENPAR(x) (eqtb[DIMEN_BASE + DIMEN_PAR__##x].b32.s1)

#define SCALED_BASE (DIMEN_BASE + DIMEN_PARS)
#define SCALED_REG(n) (eqtb[SCALED_BASE + (n)].cint)
#define SCALED_REG(n) (eqtb[SCALED_BASE + (n)].b32.s1)

#define EQTB_SIZE (SCALED_BASE + NUMBER_REGS - 1)

Expand Down
9 changes: 1 addition & 8 deletions tectonic/core-bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@ bibtex_simple_main(tt_bridge_api_t *api, char *aux_file_name)

#define TGB tectonic_global_bridge

char *
kpse_find_file(char const *name, kpse_file_format_type format, int must_exist)
{
return TGB->kpse_find_file(TGB->context, name, format, must_exist);
}


PRINTF_FUNC(1,2) void
ttstub_issue_warning(const char *format, ...)
{
Expand Down Expand Up @@ -207,7 +200,7 @@ ttstub_output_close(rust_output_handle_t handle)
}

rust_input_handle_t
ttstub_input_open(char const *path, kpse_file_format_type format, int is_gz)
ttstub_input_open(char const *path, tt_input_format_type format, int is_gz)
{
return TGB->input_open(TGB->context, path, format, is_gz);
}
Expand Down
Loading

0 comments on commit 00b8d8a

Please sign in to comment.