Implement overhead allocation for different account types, add it to binaries

This commit is contained in:
Piv
2023-02-10 21:46:19 +10:30
parent d1eb0b6e35
commit 51ece6317f
10 changed files with 442 additions and 172 deletions

View File

@@ -54,3 +54,65 @@ pub extern "C" fn move_money_from_text_free(s: *mut c_char) {
CString::from_raw(s)
};
}
#[no_mangle]
pub extern "C" fn allocate_overheads_from_text(
lines: *const c_char,
accounts: *const c_char,
allocation_statistics: *const c_char,
areas: *const c_char,
cost_centres: *const c_char,
account_type: *const c_char,
) -> *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 mut output_writer = csv::Writer::from_writer(vec![]);
reciprocal_allocation(
csv::Reader::from_reader(lines.to_bytes()),
csv::Reader::from_reader(accounts.to_bytes()),
csv::Reader::from_reader(allocation_statistics.to_bytes()),
csv::Reader::from_reader(areas.to_bytes()),
csv::Reader::from_reader(cost_centres.to_bytes()),
&mut output_writer,
true,
false,
true,
account_type.to_str().unwrap().to_owned(),
);
let inner = output_writer.into_inner().unwrap();
CString::new(String::from_utf8(inner).unwrap())
.unwrap()
.into_raw()
}
#[no_mangle]
pub extern "C" fn allocate_overheads_from_text_free(s: *mut c_char) {
unsafe {
if s.is_null() {
return;
}
CString::from_raw(s)
};
}