summaryrefslogtreecommitdiff
path: root/src/administration_writer.cpp
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2025-10-05 15:41:23 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2025-10-05 15:41:23 +0200
commit8aa66a6c6c0d8984b7d2668c03bad5a3b29e3a33 (patch)
treed7d985151b5bcd6687aead3547bdfbdb0600a8c6 /src/administration_writer.cpp
parentb278d242d03ba614779243ec9e9495fc95abea3d (diff)
memops wrapper, remove unused includes
Diffstat (limited to 'src/administration_writer.cpp')
-rw-r--r--src/administration_writer.cpp68
1 files changed, 33 insertions, 35 deletions
diff --git a/src/administration_writer.cpp b/src/administration_writer.cpp
index 040b842..f7069a6 100644
--- a/src/administration_writer.cpp
+++ b/src/administration_writer.cpp
@@ -14,13 +14,11 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#define _CRT_SECURE_NO_WARNINGS
-
#include <zip.h>
#include <xml.h>
-#include <stdlib.h>
#include <threads.h>
+#include "memops.hpp"
#include "logger.hpp"
#include "ui.hpp"
#include "locales.hpp"
@@ -94,9 +92,9 @@ static char* copy_template(const char* template_str, int* buf_size)
{
size_t template_size = strlen(template_str);
size_t buf_length = template_size*5; // Ballpark file content size.
- char* file_content = (char*)malloc(buf_length);
+ char* file_content = (char*)memops::alloc(buf_length);
memset(file_content, 0, buf_length);
- memcpy(file_content, template_str, template_size);
+ memops::copy(file_content, template_str, template_size);
*buf_size = (int)buf_length;
return file_content;
}
@@ -311,7 +309,7 @@ static void _add_document_to_zip(invoice* inv)
long sz = ftell(orig_file);
fseek(orig_file, 0, SEEK_SET);
- char* file_copy = (char*)malloc(sz);
+ char* file_copy = (char*)memops::alloc(sz);
fread(file_copy, sz, 1, orig_file);
file_copy[sz-1] = 0;
@@ -325,7 +323,7 @@ static void _add_document_to_zip(invoice* inv)
logger::error("ERROR: failed to make copy of original document '%s'.", doc->original_path);
}
- free(file_copy);
+ memops::unalloc(file_copy);
}
}
@@ -335,9 +333,9 @@ bool administration_writer::save_invoice_blocking(invoice inv)
bool result = 1;
int buf_length = 150000; // Ballpark file content size.
- char* file_content = (char*)malloc(buf_length);
+ char* file_content = (char*)memops::alloc(buf_length);
memset(file_content, 0, buf_length);
- memcpy(file_content, file_template::peppol_invoice_template, strlen(file_template::peppol_invoice_template));
+ memops::copy(file_content, file_template::peppol_invoice_template, strlen(file_template::peppol_invoice_template));
struct tm *tm_info = 0;
char date_buffer[11]; // "YYYY-MM-DD" + null terminator
@@ -409,11 +407,11 @@ bool administration_writer::save_invoice_blocking(invoice inv)
// Tax breakdown
strops::replace_float(file_content, buf_length, "{{TOTAL_TAX_AMOUNT}}", inv.tax, 2);
{ // Create tax subtotal list.
- tax_rate* tax_rate_buffer = (tax_rate*)malloc(sizeof(tax_rate)*administration::billing_item_count(&inv));
+ tax_rate* tax_rate_buffer = (tax_rate*)memops::alloc(sizeof(tax_rate)*administration::billing_item_count(&inv));
u32 tax_rate_count = administration::invoice_get_tax_rates(&inv, tax_rate_buffer);
u32 tax_subtotal_list_buffer_size = (u32)strlen(file_template::peppol_invoice_tax_subtotal_template) * 2 * tax_rate_count; // Ballpark list size.
- char* tax_subtotal_list_buffer = (char*)malloc(tax_subtotal_list_buffer_size);
+ char* tax_subtotal_list_buffer = (char*)memops::alloc(tax_subtotal_list_buffer_size);
memset(tax_subtotal_list_buffer, 0, tax_subtotal_list_buffer_size);
u32 tax_subtotal_list_buffer_cursor = 0;
@@ -432,7 +430,7 @@ bool administration_writer::save_invoice_blocking(invoice inv)
strops::replace_float(tax_entry_file_content, tax_entry_buf_length, "{{TAX_PERCENT}}", tax_rate_buffer[i].rate, 2);
u32 content_len = (u32)strlen(tax_entry_file_content);
- memcpy(tax_subtotal_list_buffer+tax_subtotal_list_buffer_cursor, tax_entry_file_content, content_len);
+ memops::copy(tax_subtotal_list_buffer+tax_subtotal_list_buffer_cursor, tax_entry_file_content, content_len);
tax_subtotal_list_buffer_cursor += content_len;
}
@@ -440,8 +438,8 @@ bool administration_writer::save_invoice_blocking(invoice inv)
strops::replace(file_content, buf_length, "{{TAX_SUBTOTAL_LIST}}", tax_subtotal_list_buffer);
- free(tax_subtotal_list_buffer);
- free(tax_rate_buffer);
+ memops::unalloc(tax_subtotal_list_buffer);
+ memops::unalloc(tax_rate_buffer);
}
// Totals
@@ -452,11 +450,11 @@ bool administration_writer::save_invoice_blocking(invoice inv)
// Invoice lines
{
- billing_item* billing_item_buffer = (billing_item*)malloc(sizeof(billing_item) * administration::billing_item_count(&inv));
+ billing_item* billing_item_buffer = (billing_item*)memops::alloc(sizeof(billing_item) * administration::billing_item_count(&inv));
u32 billing_item_count = administration::billing_item_get_all_for_invoice(&inv, billing_item_buffer);
u32 billing_item_list_buffer_size = (u32)strlen(file_template::peppol_invoice_line_template) * 2 * billing_item_count; // Ballpark list size.
- char* billing_item_list_buffer = (char*)malloc(billing_item_list_buffer_size);
+ char* billing_item_list_buffer = (char*)memops::alloc(billing_item_list_buffer_size);
memset(billing_item_list_buffer, 0, billing_item_list_buffer_size);
u32 billing_item_list_buffer_cursor = 0;
@@ -492,7 +490,7 @@ bool administration_writer::save_invoice_blocking(invoice inv)
strops::replace_float(billing_item_file_content, billing_item_buf_length, "{{DISCOUNT_TOTAL}}", bi.allowance, 2);
u32 content_len = (u32)strlen(billing_item_file_content);
- memcpy(billing_item_list_buffer+billing_item_list_buffer_cursor, billing_item_file_content, content_len);
+ memops::copy(billing_item_list_buffer+billing_item_list_buffer_cursor, billing_item_file_content, content_len);
billing_item_list_buffer_cursor += content_len;
}
@@ -500,8 +498,8 @@ bool administration_writer::save_invoice_blocking(invoice inv)
billing_item_list_buffer[billing_item_list_buffer_cursor] = 0;
strops::replace(file_content, buf_length, "{{INVOICE_LINE_LIST}}", billing_item_list_buffer);
- free(billing_item_list_buffer);
- free(billing_item_buffer);
+ memops::unalloc(billing_item_list_buffer);
+ memops::unalloc(billing_item_buffer);
}
// Dates
@@ -523,7 +521,7 @@ bool administration_writer::save_invoice_blocking(invoice inv)
if (!xml_parse_document((uint8_t*)file_content, final_length)) result = 0;
else if (!write_to_zip(final_path, file_content, final_length)) result = 0;
- free(file_content);
+ memops::unalloc(file_content);
if (result) logger::info("Saved invoice '%s' in %.3fms.", inv.sequential_number, STOPWATCH_TIME);
else logger::error("Failed to save invoice '%s'.", inv.sequential_number);
@@ -536,7 +534,7 @@ static bool save_all_invoices_blocking()
bool result = 1;
u32 num_invoices = administration::invoice_count();
u32 buffer_size = sizeof(invoice) * num_invoices;
- invoice* invoice_buffer = (invoice*)malloc(buffer_size);
+ invoice* invoice_buffer = (invoice*)memops::alloc(buffer_size);
num_invoices = administration::invoice_get_all(invoice_buffer);
for (u32 i = 0; i < num_invoices; i++) {
@@ -544,7 +542,7 @@ static bool save_all_invoices_blocking()
if (!administration_writer::save_invoice_blocking(c)) result = 0;
}
- free(invoice_buffer);
+ memops::unalloc(invoice_buffer);
return result;
}
@@ -582,7 +580,7 @@ bool administration_writer::save_project_blocking(project project)
if (!xml_parse_document((uint8_t*)file_content, final_length)) result = 0;
else if (!write_to_zip(final_path, file_content, final_length)) result = 0;
- free(file_content);
+ memops::unalloc(file_content);
if (result) logger::info("Saved project '%s' in %.3fms.", project.description, STOPWATCH_TIME);
else logger::error("Failed to save project '%s'.", project.description);
@@ -595,7 +593,7 @@ static bool save_all_projects_blocking()
bool result = 1;
u32 num_projects = administration::project_count();
u32 buffer_size = sizeof(project) * num_projects;
- project* project_buffer = (project*)malloc(buffer_size);
+ project* project_buffer = (project*)memops::alloc(buffer_size);
num_projects = administration::project_get_all(project_buffer);
for (u32 i = 0; i < num_projects; i++) {
@@ -603,7 +601,7 @@ static bool save_all_projects_blocking()
if (!administration_writer::save_project_blocking(c)) result = 0;
}
- free(project_buffer);
+ memops::unalloc(project_buffer);
return result;
}
@@ -630,7 +628,7 @@ bool administration_writer::save_cost_center_blocking(cost_center cost)
if (!xml_parse_document((uint8_t*)file_content, final_length)) result = 0;
else if (!write_to_zip(final_path, file_content, final_length)) result = 0;
- free(file_content);
+ memops::unalloc(file_content);
if (result) logger::info("Saved cost center '%s' in %.3fms.", cost.code, STOPWATCH_TIME);
else logger::error("Failed to save cost center '%s'.", cost.code);
@@ -643,7 +641,7 @@ bool administration_writer::save_all_cost_centers_blocking()
bool result = 1;
u32 num_costcenters = administration::cost_center_count();
u32 buffer_size = sizeof(cost_center) * num_costcenters;
- cost_center* costcenter_buffer = (cost_center*)malloc(buffer_size);
+ cost_center* costcenter_buffer = (cost_center*)memops::alloc(buffer_size);
num_costcenters = administration::cost_center_get_all(costcenter_buffer);
for (u32 i = 0; i < num_costcenters; i++) {
@@ -651,7 +649,7 @@ bool administration_writer::save_all_cost_centers_blocking()
if (!administration_writer::save_cost_center_blocking(c)) result = 0;
}
- free(costcenter_buffer);
+ memops::unalloc(costcenter_buffer);
return result;
}
@@ -679,7 +677,7 @@ bool administration_writer::save_tax_rate_blocking(tax_rate rate)
if (!xml_parse_document((uint8_t*)file_content, final_length)) result = 0;
else if (!write_to_zip(final_path, file_content, final_length)) result = 0;
- free(file_content);
+ memops::unalloc(file_content);
if (result) logger::info("Saved tax rate '%s/%.1f' in %.3fms.", rate.country_code, rate.rate, STOPWATCH_TIME);
else logger::error("Failed to save tax rate '%s/%.1f'.", rate.country_code, rate.rate);
@@ -692,7 +690,7 @@ bool administration_writer::save_all_tax_rates_blocking()
//// Get all data.
u32 num_rates = administration::tax_rate_count();
u32 buffer_size = sizeof(tax_rate) * num_rates;
- tax_rate* rate_buffer = (tax_rate*)malloc(buffer_size);
+ tax_rate* rate_buffer = (tax_rate*)memops::alloc(buffer_size);
num_rates = administration::tax_rate_get_all(rate_buffer);
bool result = 1;
@@ -702,7 +700,7 @@ bool administration_writer::save_all_tax_rates_blocking()
if (!administration_writer::save_tax_rate_blocking(c)) result = 0;
}
- free(rate_buffer);
+ memops::unalloc(rate_buffer);
return result;
}
@@ -739,7 +737,7 @@ bool administration_writer::save_contact_blocking(contact c)
if (!xml_parse_document((uint8_t*)file_content, final_length)) result = 0;
else if (!write_to_zip(final_path, file_content, final_length)) result = 0;
- free(file_content);
+ memops::unalloc(file_content);
if (result) logger::info("Saved contact '%s' in %.3fms.", c.name, STOPWATCH_TIME);
else logger::error("Failed to save contact '%s'.", c.name);
@@ -752,7 +750,7 @@ static bool save_all_contacts_blocking()
//// Get all data.
u32 num_contacts = administration::contact_count();
u32 buffer_size = sizeof(contact) * num_contacts;
- contact* contact_buffer = (contact*)malloc(buffer_size);
+ contact* contact_buffer = (contact*)memops::alloc(buffer_size);
num_contacts = administration::contact_get_all(contact_buffer);
bool result = 1;
@@ -766,7 +764,7 @@ static bool save_all_contacts_blocking()
if (!administration_writer::save_contact_blocking(c)) result = 0;
}
- free(contact_buffer);
+ memops::unalloc(contact_buffer);
return result;
}
@@ -794,7 +792,7 @@ bool administration_writer::save_all_administration_info_blocking()
if (!xml_parse_document((uint8_t*)file_content, final_length)) result = 0;
else if (!write_to_zip(ADMIN_FILE_INFO, file_content, final_length)) result = 0;
- free(file_content);
+ memops::unalloc(file_content);
if (result) logger::info("Saved administration info in %.3fms.", STOPWATCH_TIME);
else logger::error("Failed to save administration info.");