summaryrefslogtreecommitdiff
path: root/src/user/settings/string_kind.cpp
diff options
context:
space:
mode:
authorBenji Dial <benji6283@gmail.com>2021-06-21 17:47:13 -0400
committerBenji Dial <benji6283@gmail.com>2021-06-21 17:47:13 -0400
commitf57e2eabe0a10c9732c83532e01654a499fb8dcf (patch)
treecbf91a23fcdd65e0ea7ed55b0940ca7042d59bef /src/user/settings/string_kind.cpp
parent83835306d57461205a7bcfef9f4c3e06bc504006 (diff)
downloadportland-os-f57e2eabe0a10c9732c83532e01654a499fb8dcf.tar.gz
many, many changes; settings is broken
Diffstat (limited to 'src/user/settings/string_kind.cpp')
-rw-r--r--src/user/settings/string_kind.cpp52
1 files changed, 52 insertions, 0 deletions
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 <raleigh/w/entry.h>
+
+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<const char *, raleigh::entry, &load_into_entry, &save_from_entry>(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