1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//! Read .sdf files, full waveform data files from Riegl Laser Measurement Systems.
//!
//! This is in part a wrapper library around `libsdfifc.so`, Riegl's sdf library. This library also
//! provides functions to convert .sdf files to discrete return .sdc files using Gaussian
//! decomposition.
//!
//! The `sdfifc` library **is not thread-safe**, and so this library should only be used in
//! single-threaded applications. When running this library's test suite, you must set
//! `RUST_TEST_THREADS=1` or else you most likely will get a segfault.

#![deny(box_pointers, fat_ptr_transmutes, missing_copy_implementations, missing_debug_implementations, missing_docs, trivial_casts, trivial_numeric_casts, unused_extern_crates, unused_import_braces, unused_qualifications, unused_results, variant_size_differences)]

extern crate libc;
#[macro_use]
extern crate log;
extern crate peakbag;

macro_rules! sdftry {
    ($expr:expr) => {{
        match $expr {
            0 => {},
            code @ _ => return Err(Error::from_i32(code)),
        }
    }}
}

pub mod convert;
pub mod error;
mod ffi;
pub mod file;

pub use error::Error;
pub use file::File;

use std::ffi::CStr;
use std::ptr;
use std::result;

use libc::c_char;

/// Container structure for information about the library.
#[derive(Debug)]
pub struct LibraryVersion {
    /// The library's major api version.
    pub api_major: u16,
    /// The library's minor api version.
    pub api_minor: u16,
    /// The library's build version.
    pub build_version: String,
    /// The library's build tag.
    pub build_tag: String,
}

/// Returns information about the fwifc library.
///
/// # Examples
///
/// ```
/// let library_version = sdf::library_version();
/// ```
pub fn library_version() -> Result<LibraryVersion> {
    unsafe {
        let mut api_major = 0u16;
        let mut api_minor = 0u16;
        let mut build_version: *const c_char = ptr::null_mut();
        let mut build_tag: *const c_char = ptr::null_mut();
        sdftry!(ffi::fwifc_get_library_version(&mut api_major,
                                               &mut api_minor,
                                               &mut build_version,
                                               &mut build_tag));
        Ok(LibraryVersion {
            api_major: api_major,
            api_minor: api_minor,
            build_version: try!(CStr::from_ptr(build_version).to_str()).to_string(),
            build_tag: try!(CStr::from_ptr(build_tag).to_str()).to_string(),
        })
    }
}

/// Our custom result type.
pub type Result<T> = result::Result<T, Error>;