Skip to content

Commit

Permalink
Format code using 'cargo fmt'
Browse files Browse the repository at this point in the history
  • Loading branch information
Atul9 committed Nov 21, 2019
1 parent 7cd148e commit 152e0c2
Show file tree
Hide file tree
Showing 84 changed files with 2,806 additions and 2,747 deletions.
42 changes: 29 additions & 13 deletions bridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
unused_mut
)]

use std::io::{prelude::*, Result};
use std::io::SeekFrom;
use std::io::{prelude::*, Result};
use std::ptr::NonNull;

extern "C" {
Expand Down Expand Up @@ -59,22 +59,24 @@ pub struct InputHandleWrapper(pub NonNull<libc::c_void>);
impl Read for InputHandleWrapper {
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
unsafe {
Ok(ttstub_input_read(self.0.as_ptr(), buf.as_mut_ptr() as *mut i8, buf.len() as u64) as usize)
Ok(ttstub_input_read(
self.0.as_ptr(),
buf.as_mut_ptr() as *mut i8,
buf.len() as u64,
) as usize)
}
}
}

impl Seek for InputHandleWrapper {
fn seek(&mut self, pos: SeekFrom) -> Result<u64> {
use libc::{SEEK_SET, SEEK_CUR, SEEK_END};
use libc::{SEEK_CUR, SEEK_END, SEEK_SET};
let (offset, whence) = match pos {
SeekFrom::Start(o) => (o as ssize_t, SEEK_SET),
SeekFrom::Current(o) => (o as ssize_t, SEEK_CUR),
SeekFrom::End(o) => (o as ssize_t, SEEK_END),
};
unsafe {
Ok(ttstub_input_seek(self.0.as_ptr(), offset, whence) as u64)
}
unsafe { Ok(ttstub_input_seek(self.0.as_ptr(), offset, whence) as u64) }
}
}

Expand Down Expand Up @@ -336,20 +338,27 @@ pub unsafe extern "C" fn ttstub_input_open(
InputHandleWrapper::new((*tectonic_global_bridge)
.input_open
.expect("non-null function pointer")(
(*tectonic_global_bridge).context, path, format, is_gz
(*tectonic_global_bridge).context,
path,
format,
is_gz,
))
}
#[no_mangle]
pub unsafe extern "C" fn ttstub_input_open_primary() -> Option<InputHandleWrapper> {
InputHandleWrapper::new((*tectonic_global_bridge)
.input_open_primary
.expect("non-null function pointer")((*tectonic_global_bridge).context))
.expect("non-null function pointer")(
(*tectonic_global_bridge).context
))
}
#[no_mangle]
pub unsafe extern "C" fn ttstub_input_get_size(handle: &mut InputHandleWrapper) -> size_t {
(*tectonic_global_bridge)
.input_get_size
.expect("non-null function pointer")((*tectonic_global_bridge).context, handle.0.as_ptr())
.expect("non-null function pointer")(
(*tectonic_global_bridge).context, handle.0.as_ptr()
)
}
#[no_mangle]
pub unsafe extern "C" fn ttstub_input_seek(
Expand Down Expand Up @@ -389,20 +398,27 @@ pub unsafe extern "C" fn ttstub_input_read(
pub unsafe extern "C" fn ttstub_input_getc(handle: &mut InputHandleWrapper) -> i32 {
(*tectonic_global_bridge)
.input_getc
.expect("non-null function pointer")((*tectonic_global_bridge).context, handle.0.as_ptr())
.expect("non-null function pointer")(
(*tectonic_global_bridge).context, handle.0.as_ptr()
)
}
#[no_mangle]
pub unsafe extern "C" fn ttstub_input_ungetc(handle: &mut InputHandleWrapper, mut ch: i32) -> i32 {
(*tectonic_global_bridge)
.input_ungetc
.expect("non-null function pointer")((*tectonic_global_bridge).context, handle.0.as_ptr(), ch)
.expect("non-null function pointer")(
(*tectonic_global_bridge).context,
handle.0.as_ptr(),
ch,
)
}
#[no_mangle]
pub unsafe extern "C" fn ttstub_input_close(mut handle: InputHandleWrapper) -> i32 {
if (*tectonic_global_bridge)
.input_close
.expect("non-null function pointer")((*tectonic_global_bridge).context, handle.0.as_ptr())
!= 0
.expect("non-null function pointer")(
(*tectonic_global_bridge).context, handle.0.as_ptr()
) != 0
{
// Nonzero return value indicates a serious internal error.
panic!("ttstub_input_close");
Expand Down
79 changes: 46 additions & 33 deletions dpx/src/dpx_bmpimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ use super::dpx_mem::new;
use super::dpx_numbers::tt_get_unsigned_byte;
use super::dpx_pdfximage::{pdf_ximage_init_image_info, pdf_ximage_set_image};
use crate::dpx_pdfobj::{
pdf_new_name, pdf_new_number, IntoObj,
pdf_new_stream, pdf_new_string, pdf_release_obj,
pdf_stream_set_predictor, STREAM_COMPRESS,
pdf_new_name, pdf_new_number, pdf_new_stream, pdf_new_string, pdf_release_obj,
pdf_stream_set_predictor, IntoObj, STREAM_COMPRESS,
};
use crate::ttstub_input_read;
use crate::warn;
use crate::{ttstub_input_read};
use libc::{free, memset};

use std::io::{Seek, SeekFrom};
Expand Down Expand Up @@ -95,16 +94,16 @@ pub unsafe fn bmp_get_bbox(
mut ydensity: *mut f64,
) -> i32 {
let mut hdr: hdr_info = hdr_info {
offset: 0_u32,
hsize: 0_u32,
width: 0_u32,
height: 0i32,
compression: 0i32,
bit_count: 0_u16,
psize: 0i32,
x_pix_per_meter: 0_u32,
y_pix_per_meter: 0_u32,
};
offset: 0_u32,
hsize: 0_u32,
width: 0_u32,
height: 0i32,
compression: 0i32,
bit_count: 0_u16,
psize: 0i32,
x_pix_per_meter: 0_u32,
y_pix_per_meter: 0_u32,
};
handle.seek(SeekFrom::Start(0)).unwrap();
let r = read_header(handle, &mut hdr);
*width = hdr.width;
Expand All @@ -123,16 +122,16 @@ pub unsafe fn bmp_include_image(
) -> i32 {
let mut info = ximage_info::default();
let mut hdr: hdr_info = hdr_info {
offset: 0_u32,
hsize: 0_u32,
width: 0_u32,
height: 0i32,
compression: 0i32,
bit_count: 0_u16,
psize: 0i32,
x_pix_per_meter: 0_u32,
y_pix_per_meter: 0_u32,
};
offset: 0_u32,
hsize: 0_u32,
width: 0_u32,
height: 0i32,
compression: 0i32,
bit_count: 0_u16,
psize: 0i32,
x_pix_per_meter: 0_u32,
y_pix_per_meter: 0_u32,
};
let num_palette;
pdf_ximage_init_image_info(&mut info);
handle.seek(SeekFrom::Start(0)).unwrap();
Expand Down Expand Up @@ -189,10 +188,14 @@ pub unsafe fn bmp_include_image(
let colorspace = if (hdr.bit_count as i32) < 24i32 {
let mut bgrq: [u8; 4] = [0; 4];
let palette = new(((num_palette * 3i32 + 1i32) as u32 as u64)
.wrapping_mul(::std::mem::size_of::<u8>() as u64) as u32) as *mut u8;
.wrapping_mul(::std::mem::size_of::<u8>() as u64) as u32)
as *mut u8;
for i in 0..num_palette {
if ttstub_input_read(handle.0.as_ptr(), bgrq.as_mut_ptr() as *mut i8, hdr.psize as size_t)
!= hdr.psize as i64
if ttstub_input_read(
handle.0.as_ptr(),
bgrq.as_mut_ptr() as *mut i8,
hdr.psize as size_t,
) != hdr.psize as i64
{
warn!("Reading file failed...");
free(palette as *mut libc::c_void);
Expand Down Expand Up @@ -287,7 +290,9 @@ pub unsafe fn bmp_include_image(
let mut n = info.height - 1i32;
while n >= 0i32 {
let p = stream_data_ptr.offset((n * rowbytes) as isize);
(*stream).as_stream_mut().add(p as *const libc::c_void, rowbytes);
(*stream)
.as_stream_mut()
.add(p as *const libc::c_void, rowbytes);
n -= 1
}
} else {
Expand Down Expand Up @@ -315,8 +320,11 @@ use crate::FromLEByteSlice;
unsafe fn read_header(handle: &mut InputHandleWrapper, hdr: &mut hdr_info) -> i32 {
let mut buf: [u8; 142] = [0; 142];
let p = &mut buf;
if ttstub_input_read(handle.0.as_ptr(), p.as_mut_ptr() as *mut i8, (14i32 + 4i32) as size_t)
!= (14i32 + 4i32) as i64
if ttstub_input_read(
handle.0.as_ptr(),
p.as_mut_ptr() as *mut i8,
(14i32 + 4i32) as size_t,
) != (14i32 + 4i32) as i64
{
warn!("Could not read BMP file header...");
return -1i32;
Expand Down Expand Up @@ -438,7 +446,9 @@ unsafe fn read_raster_rle8(
warn!("RLE decode failed...");
return -1i32;
}
if ttstub_input_read(handle.0.as_ptr(), p as *mut i8, b1 as size_t) != b1 as i64 {
if ttstub_input_read(handle.0.as_ptr(), p as *mut i8, b1 as size_t)
!= b1 as i64
{
return -1i32;
}
count += b1 as i32;
Expand Down Expand Up @@ -533,8 +543,11 @@ unsafe fn read_raster_rle4(
*fresh0 = (*fresh0 as i32 | b as i32 >> 4i32 & 0xfi32) as u8;
*p = ((b as i32) << 4i32 & 0xf0i32) as u8;
}
} else if ttstub_input_read(handle.0.as_ptr(), p as *mut i8, nbytes as size_t)
!= nbytes as i64
} else if ttstub_input_read(
handle.0.as_ptr(),
p as *mut i8,
nbytes as size_t,
) != nbytes as i64
{
return -1i32;
}
Expand Down
Loading

0 comments on commit 152e0c2

Please sign in to comment.