Start adding linking
This commit is contained in:
94
src/lib.rs
94
src/lib.rs
@@ -13,6 +13,8 @@ pub use self::products::create_products;
|
||||
mod shared_models;
|
||||
pub use self::shared_models::*;
|
||||
|
||||
pub mod link;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn move_money_from_text(
|
||||
rules: *const c_char,
|
||||
@@ -22,22 +24,10 @@ pub extern "C" fn move_money_from_text(
|
||||
use_numeric_accounts: bool,
|
||||
) -> *mut c_char {
|
||||
let mut output_writer = csv::Writer::from_writer(vec![]);
|
||||
let safe_rules = unsafe {
|
||||
assert!(!rules.is_null());
|
||||
CStr::from_ptr(rules)
|
||||
};
|
||||
let safe_lines = unsafe {
|
||||
assert!(!lines.is_null());
|
||||
CStr::from_ptr(lines)
|
||||
};
|
||||
let safe_accounts = unsafe {
|
||||
assert!(!accounts.is_null());
|
||||
CStr::from_ptr(accounts)
|
||||
};
|
||||
let safe_cost_centres = unsafe {
|
||||
assert!(!cost_centres.is_null());
|
||||
CStr::from_ptr(cost_centres)
|
||||
};
|
||||
let safe_rules = unwrap_c_char(rules);
|
||||
let safe_lines = unwrap_c_char(lines);
|
||||
let safe_accounts = unwrap_c_char(accounts);
|
||||
let safe_cost_centres = unwrap_c_char(cost_centres);
|
||||
move_money(
|
||||
&mut csv::Reader::from_reader(safe_rules.to_bytes()),
|
||||
&mut csv::Reader::from_reader(safe_lines.to_bytes()),
|
||||
@@ -81,30 +71,12 @@ pub extern "C" fn allocate_overheads_from_text(
|
||||
account_type: *const c_char,
|
||||
use_numeric_accounts: bool,
|
||||
) -> *mut c_char {
|
||||
let lines = unsafe {
|
||||
assert!(!lines.is_null());
|
||||
CStr::from_ptr(lines)
|
||||
};
|
||||
let accounts = unsafe {
|
||||
assert!(!accounts.is_null());
|
||||
CStr::from_ptr(accounts)
|
||||
};
|
||||
let allocation_statistics = unsafe {
|
||||
assert!(!allocation_statistics.is_null());
|
||||
CStr::from_ptr(allocation_statistics)
|
||||
};
|
||||
let areas = unsafe {
|
||||
assert!(!areas.is_null());
|
||||
CStr::from_ptr(areas)
|
||||
};
|
||||
let cost_centres = unsafe {
|
||||
assert!(!cost_centres.is_null());
|
||||
CStr::from_ptr(cost_centres)
|
||||
};
|
||||
let account_type = unsafe {
|
||||
assert!(!account_type.is_null());
|
||||
CStr::from_ptr(account_type)
|
||||
};
|
||||
let lines = unwrap_c_char(lines);
|
||||
let accounts = unwrap_c_char(accounts);
|
||||
let allocation_statistics = unwrap_c_char(allocation_statistics);
|
||||
let areas = unwrap_c_char(areas);
|
||||
let cost_centres = unwrap_c_char(cost_centres);
|
||||
let account_type = unwrap_c_char(account_type);
|
||||
let mut output_writer = csv::Writer::from_writer(vec![]);
|
||||
reciprocal_allocation(
|
||||
&mut csv::Reader::from_reader(lines.to_bytes()),
|
||||
@@ -142,34 +114,13 @@ pub extern "C" fn allocate_overheads_from_text_to_file(
|
||||
use_numeric_accounts: bool,
|
||||
show_from: bool,
|
||||
) {
|
||||
let lines = unsafe {
|
||||
assert!(!lines.is_null());
|
||||
CStr::from_ptr(lines)
|
||||
};
|
||||
let accounts = unsafe {
|
||||
assert!(!accounts.is_null());
|
||||
CStr::from_ptr(accounts)
|
||||
};
|
||||
let allocation_statistics = unsafe {
|
||||
assert!(!allocation_statistics.is_null());
|
||||
CStr::from_ptr(allocation_statistics)
|
||||
};
|
||||
let areas = unsafe {
|
||||
assert!(!areas.is_null());
|
||||
CStr::from_ptr(areas)
|
||||
};
|
||||
let cost_centres = unsafe {
|
||||
assert!(!cost_centres.is_null());
|
||||
CStr::from_ptr(cost_centres)
|
||||
};
|
||||
let account_type = unsafe {
|
||||
assert!(!account_type.is_null());
|
||||
CStr::from_ptr(account_type)
|
||||
};
|
||||
let output_path = unsafe {
|
||||
assert!(!output_path.is_null());
|
||||
CStr::from_ptr(output_path)
|
||||
};
|
||||
let lines = unwrap_c_char(lines);
|
||||
let accounts = unwrap_c_char(accounts);
|
||||
let allocation_statistics = unwrap_c_char(allocation_statistics);
|
||||
let areas = unwrap_c_char(areas);
|
||||
let cost_centres = unwrap_c_char(cost_centres);
|
||||
let account_type = unwrap_c_char(account_type);
|
||||
let output_path = unwrap_c_char(output_path);
|
||||
reciprocal_allocation(
|
||||
&mut csv::Reader::from_reader(lines.to_bytes()),
|
||||
&mut csv::Reader::from_reader(accounts.to_bytes()),
|
||||
@@ -187,6 +138,13 @@ pub extern "C" fn allocate_overheads_from_text_to_file(
|
||||
.expect("Failed to allocate overheads");
|
||||
}
|
||||
|
||||
fn unwrap_c_char<'a>(s: *const c_char) -> &'a CStr {
|
||||
unsafe {
|
||||
assert!(!s.is_null());
|
||||
CStr::from_ptr(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn allocate_overheads_from_text_free(s: *mut c_char) {
|
||||
unsafe {
|
||||
|
||||
Reference in New Issue
Block a user