From f57e2eabe0a10c9732c83532e01654a499fb8dcf Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Mon, 21 Jun 2021 17:47:13 -0400 Subject: many, many changes; settings is broken --- src/user/settings/string_kind.cpp | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/user/settings/string_kind.cpp (limited to 'src/user/settings/string_kind.cpp') diff --git a/src/user/settings/string_kind.cpp b/src/user/settings/string_kind.cpp new file mode 100644 index 0000000..0afe102 --- /dev/null +++ b/src/user/settings/string_kind.cpp @@ -0,0 +1,52 @@ +#include "string_kind.h" + +#include + +void write_string_main(uint32_t &data_offset, file *f, const backing_t backing) { + const uint32_t len = strlen((const char *)backing); + + uint32_t main[2]; + main[0] = data_offset; + main[1] = len; + + data_offset += len; + + write_to_file(f, 8, main); +} + +void write_string_data(file *f, const backing_t backing) { + const char *b = (const char *)backing; + write_to_file(f, strlen(b), b); +} + +backing_t read_string_backing(file *f, uint32_t data_start) { + uint32_t main[2]; + read_from_file(f, 8, main); + + seek_file_to(f, data_start + main[0]); + + char *buf = new char[main[1] + 1]; + read_from_file(f, main[1], buf); + buf[main[1]] = '\0'; + + return (backing_t)buf; +} + +void load_into_entry(raleigh::entry &e, const char *s) { + e.set_contents(s); +} + +void save_from_entry(raleigh::entry &e, const char *&s) { + s = e.get_contents(); +} + +void open_string_editor(setting &s) { + do_common_editor(s); +} + +const setting_kind_info string_kind = { + &write_string_main, + &write_string_data, + &read_string_backing, + &open_string_editor +}; \ No newline at end of file -- cgit v1.2.3