From 59267a64180f4d28a6b5449f444f3eaf02fc7da0 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 17 Feb 2017 20:04:41 -0500 Subject: [PATCH] new utf8 <-> utf16 code --- 4coder_API/keycodes.h | 66 ++++---- 4coder_base_commands.cpp | 2 + 4coder_default_include.cpp | 3 +- 4coder_helper/4coder_helper.h | 2 +- 4coder_lib/4coder_mem.h | 6 + 4coder_lib/4coder_string.h | 2 + 4coder_lib/4coder_table.h | 2 + 4coder_lib/4coder_utf8.h | 253 +++++++++++++++++++++++++++++ 4ed.cpp | 30 ++-- 4ed_command.cpp | 32 +++- 4ed_file_view.cpp | 5 +- 4ed_utf8_conversions.h | 45 ----- filetrack/4tech_file_track_win32.c | 9 +- internal_4coder_tests.cpp | 3 +- linux_4ed.cpp | 4 +- meta/4ed_metagen.cpp | 2 +- meta/build.cpp | 3 +- string/4tech_standard_preamble.h | 2 + win32_4ed.cpp | 33 ++-- 19 files changed, 373 insertions(+), 131 deletions(-) create mode 100644 4coder_lib/4coder_utf8.h delete mode 100644 4ed_utf8_conversions.h diff --git a/4coder_API/keycodes.h b/4coder_API/keycodes.h index 015ce577..4516fac0 100644 --- a/4coder_API/keycodes.h +++ b/4coder_API/keycodes.h @@ -1,39 +1,39 @@ enum{ -key_back = 57344, -key_up = 57345, -key_down = 57346, -key_left = 57347, -key_right = 57348, -key_del = 57349, -key_insert = 57350, -key_home = 57351, -key_end = 57352, -key_page_up = 57353, -key_page_down = 57354, -key_esc = 57355, -key_mouse_left = 57356, -key_mouse_right = 57357, -key_mouse_left_release = 57358, -key_mouse_right_release = 57359, -key_f1 = 57360, -key_f2 = 57361, -key_f3 = 57362, -key_f4 = 57363, -key_f5 = 57364, -key_f6 = 57365, -key_f7 = 57366, -key_f8 = 57367, -key_f9 = 57368, -key_f10 = 57369, -key_f11 = 57370, -key_f12 = 57371, -key_f13 = 57372, -key_f14 = 57373, -key_f15 = 57374, -key_f16 = 57375, +key_back = 55296, +key_up = 55297, +key_down = 55298, +key_left = 55299, +key_right = 55300, +key_del = 55301, +key_insert = 55302, +key_home = 55303, +key_end = 55304, +key_page_up = 55305, +key_page_down = 55306, +key_esc = 55307, +key_mouse_left = 55308, +key_mouse_right = 55309, +key_mouse_left_release = 55310, +key_mouse_right_release = 55311, +key_f1 = 55312, +key_f2 = 55313, +key_f3 = 55314, +key_f4 = 55315, +key_f5 = 55316, +key_f6 = 55317, +key_f7 = 55318, +key_f8 = 55319, +key_f9 = 55320, +key_f10 = 55321, +key_f11 = 55322, +key_f12 = 55323, +key_f13 = 55324, +key_f14 = 55325, +key_f15 = 55326, +key_f16 = 55327, }; static char* -global_key_name(int32_t key_code, int32_t *size){ +global_key_name(uint32_t key_code, int32_t *size){ char *result = 0; switch(key_code){ case key_back: result = "back"; *size = sizeof("back")-1; break; diff --git a/4coder_base_commands.cpp b/4coder_base_commands.cpp index cd72aad1..391588b7 100644 --- a/4coder_base_commands.cpp +++ b/4coder_base_commands.cpp @@ -13,6 +13,8 @@ TYPE: 'drop-in-command-pack' #include "4coder_helper/4coder_helper.h" #include "4coder_helper/4coder_long_seek.h" +#include "4coder_lib/4coder_utf8.h" + // // Fundamental Editing Commands // diff --git a/4coder_default_include.cpp b/4coder_default_include.cpp index c51a6292..2a1bfc43 100644 --- a/4coder_default_include.cpp +++ b/4coder_default_include.cpp @@ -33,11 +33,10 @@ TYPE: 'major-system-include' #include "4coder_lib/4coder_string.h" #include "4coder_lib/4coder_table.h" #include "4coder_lib/4coder_mem.h" +#include "4coder_lib/4coder_utf8.h" #include "4cpp/4cpp_lexer.h" -#include - // // Seeks Using Default Framework Memory // diff --git a/4coder_helper/4coder_helper.h b/4coder_helper/4coder_helper.h index 62587937..da00f800 100644 --- a/4coder_helper/4coder_helper.h +++ b/4coder_helper/4coder_helper.h @@ -63,7 +63,7 @@ to_writable_char(Key_Code long_character){ character = '\t'; } } - else if (long_character >= ' ' && long_character <= 255 && long_character != 127){ + else if (long_character <= 255 && long_character != 127){ character = (char)long_character; } return(character); diff --git a/4coder_lib/4coder_mem.h b/4coder_lib/4coder_mem.h index d0301cbf..8ed09fb5 100644 --- a/4coder_lib/4coder_mem.h +++ b/4coder_lib/4coder_mem.h @@ -7,6 +7,8 @@ recognized, you are granted a perpetual, irrevocable license to copy, distribute, and modify this file as you see fit. */ +// TOP + #if !defined(FCODER_MEM_H) #define FCODER_MEM_H @@ -24,6 +26,8 @@ typedef uint16_t u16_4tech; typedef uint32_t u32_4tech; typedef uint64_t u64_4tech; +typedef u64_4tech umem_4tech; + typedef float f32_4tech; typedef double f64_4tech; @@ -349,3 +353,5 @@ general_memory_reallocate_nocopy(General_Memory *general, void *old, i32_4tech s #endif +// BOTTOM + diff --git a/4coder_lib/4coder_string.h b/4coder_lib/4coder_string.h index 84dfa847..38a8272c 100644 --- a/4coder_lib/4coder_string.h +++ b/4coder_lib/4coder_string.h @@ -26,6 +26,8 @@ typedef uint16_t u16_4tech; typedef uint32_t u32_4tech; typedef uint64_t u64_4tech; +typedef u64_4tech umem_4tech; + typedef float f32_4tech; typedef double f64_4tech; diff --git a/4coder_lib/4coder_table.h b/4coder_lib/4coder_table.h index df587ce3..17e9bce4 100644 --- a/4coder_lib/4coder_table.h +++ b/4coder_lib/4coder_table.h @@ -26,6 +26,8 @@ typedef uint16_t u16_4tech; typedef uint32_t u32_4tech; typedef uint64_t u64_4tech; +typedef u64_4tech umem_4tech; + typedef float f32_4tech; typedef double f64_4tech; diff --git a/4coder_lib/4coder_utf8.h b/4coder_lib/4coder_utf8.h new file mode 100644 index 00000000..a5632580 --- /dev/null +++ b/4coder_lib/4coder_utf8.h @@ -0,0 +1,253 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 17.02.2017 + * + * Code for converting to and from utf8 to ANSI and utf16 text encodings. + * + */ + +// TOP + +#if !defined(FED_UTF8_CONVERSION_H) +#define FED_UTF8_CONVERSION_H + +// 4tech_standard_preamble.h +#if !defined(FTECH_INTEGERS) +#define FTECH_INTEGERS +#include +typedef int8_t i8_4tech; +typedef int16_t i16_4tech; +typedef int32_t i32_4tech; +typedef int64_t i64_4tech; + +typedef uint8_t u8_4tech; +typedef uint16_t u16_4tech; +typedef uint32_t u32_4tech; +typedef uint64_t u64_4tech; + +typedef u64_4tech umem_4tech; + +typedef float f32_4tech; +typedef double f64_4tech; + +typedef int8_t b8_4tech; +typedef int32_t b32_4tech; +#endif + +#if !defined(Assert) +# define Assert(n) do{ if (!(n)) *(int*)0 = 0xA11E; }while(0) +#endif +// standard preamble end + +static u32_4tech +utf8_to_u32_unchecked(u8_4tech *buffer){ + u32_4tech result = 0; + + if (buffer[0] <= 0x7F){ + result = (u32_4tech)buffer[0]; + } + else if (buffer[0] <= 0xE0){ + result = ((u32_4tech)((buffer[0])&0x1F)) << 6; + result |= ((u32_4tech)((buffer[1])&0x3F)); + } + else if (buffer[0] <= 0xF0){ + result = ((u32_4tech)((buffer[0])&0x0F)) << 12; + result |= ((u32_4tech)((buffer[1])&0x3F)) << 6; + result |= ((u32_4tech)((buffer[2])&0x3F)); + } + else{ + result = ((u32_4tech)((buffer[0])&0x07)) << 18; + result |= ((u32_4tech)((buffer[1])&0x3F)) << 12; + result |= ((u32_4tech)((buffer[2])&0x3F)) << 6; + result |= ((u32_4tech)((buffer[3])&0x3F)); + } + + return(result); +} + +static umem_4tech +utf8_to_utf16_minimal_checking(u16_4tech *dst, umem_4tech max_wchars, u8_4tech *src, umem_4tech length, b32_4tech *error){ + u8_4tech *s = src; + u8_4tech *s_end = s + length; + + u16_4tech *d = dst; + u16_4tech *d_end = d + max_wchars; + umem_4tech limit = length; + + umem_4tech needed_max = 0; + u32_4tech advance = 1; + + *error = false; + for(; s < s_end;){ + u32_4tech code_point = 0; + u32_4tech utf8_size = 0; + + if (s[0] <= 0x7F){ + code_point = (u32_4tech)s[0]; + utf8_size = 1; + } + else if (s[0] <= 0xE0){ + if (limit <= 1){ + *error = true; + break; + } + + code_point = ((u32_4tech)((s[0])&0x1F)) << 6; + code_point |= ((u32_4tech)((s[1])&0x3F)); + utf8_size = 2; + } + else if (s[0] <= 0xF0){ + if (limit <= 2){ + *error = true; + break; + } + + code_point = ((u32_4tech)((s[0])&0x0F)) << 12; + code_point |= ((u32_4tech)((s[1])&0x3F)) << 6; + code_point |= ((u32_4tech)((s[2])&0x3F)); + utf8_size = 3; + } + else{ + if (limit > 3){ + *error = true; + break; + } + + code_point = ((u32_4tech)((s[0])&0x07)) << 18; + code_point |= ((u32_4tech)((s[1])&0x3F)) << 12; + code_point |= ((u32_4tech)((s[2])&0x3F)) << 6; + code_point |= ((u32_4tech)((s[3])&0x3F)); + utf8_size = 4; + } + + s += utf8_size; + limit -= utf8_size; + + if (code_point <= 0xD7FF || (code_point >= 0xE000 && code_point <= 0xFFFF)){ + *d = (u16_4tech)(code_point); + d += advance; + needed_max += 1; + } + else if (code_point >= 0x10000 && code_point <= 0x10FFFF){ + code_point -= 0x10000; + + u32_4tech high = (code_point >> 10) & 0x03FF; + u32_4tech low = (code_point) & 0x03FF; + + high += 0xD800; + low += 0xDC00; + + if (d + advance < d_end){ + *d = (u16_4tech)high; + d += advance; + *d = (u16_4tech)low; + d += advance; + } + else{ + advance = 0; + } + + needed_max += 2; + } + else{ + *error = true; + break; + } + + if (d >= d_end){ + advance = 0; + } + } + + return(needed_max); +} + +static umem_4tech +utf16_to_utf8_minimal_checking(u8_4tech *dst, umem_4tech max_chars, u16_4tech *src, umem_4tech length, b32_4tech *error){ + u16_4tech *s = src; + u16_4tech *s_end = s + max_chars; + + u8_4tech *d = dst; + u8_4tech *d_end = d + length; + umem_4tech limit = length; + + umem_4tech needed_max = 0; + + *error = false; + + for (; s < s_end;){ + u32_4tech code_point = 0; + u32_4tech utf16_size = 0; + + if (s[0] <= 0xD7FF || (s[0] >= 0xE000 && s[0] <= 0xFFFF)){ + code_point = s[0]; + utf16_size = 1; + } + else{ + if (s[0] >= 0xD800 && s[0] <= 0xDBFF){ + if (limit <= 1){ + *error = true; + break; + } + + u32_4tech high = s[0] - 0xD800; + u32_4tech low = s[1] - 0xDC00; + code_point = ((high << 10) | (low)) + 0x10000; + utf16_size = 2; + } + else{ + *error = true; + break; + } + } + + s += utf16_size; + limit -= utf16_size; + + u8_4tech d_fill[4]; + u32_4tech d_fill_count = 0; + + if (code_point <= 0x7F){ + d_fill[0] = (u8_4tech)code_point; + d_fill_count = 1; + } + else if (code_point <= 0x7FF){ + d_fill[0] = (u8_4tech)(0xC0 | (code_point >> 6)); + d_fill[1] = (u8_4tech)(0x80 | (code_point & 0x3F)); + d_fill_count = 2; + } + else if (code_point <= 0xFFFF){ + d_fill[0] = (u8_4tech)(0xE0 | (code_point >> 12)); + d_fill[1] = (u8_4tech)(0x80 | ((code_point >> 6) & 0x3F)); + d_fill[2] = (u8_4tech)(0x80 | (code_point & 0x3F)); + d_fill_count = 3; + } + else if (code_point <= 0x10FFFF){ + d_fill[0] = (u8_4tech)(0xF0 | (code_point >> 18)); + d_fill[1] = (u8_4tech)(0x80 | ((code_point >> 12) & 0x3F)); + d_fill[2] = (u8_4tech)(0x80 | ((code_point >> 6) & 0x3F)); + d_fill[3] = (u8_4tech)(0x80 | (code_point & 0x3F)); + d_fill_count = 4; + } + else{ + *error = true; + break; + } + + if (d + d_fill_count <= d_end){ + for (u32_4tech i = 0; i < d_fill_count; ++i){ + *d = d_fill[i]; + ++d; + } + } + needed_max += d_fill_count; + } + + return(needed_max); +} + +#endif + +// BOTTOM + diff --git a/4ed.cpp b/4ed.cpp index 89af34d2..70e6196c 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -579,8 +579,7 @@ app_links_init(System_Functions *system, Application_Links *app_links, void *dat internal void setup_ui_commands(Command_Map *commands, Partition *part, Command_Map *parent){ map_init(commands, part, 32, parent); - - commands->vanilla_keyboard_default.function = command_null; + map_clear(commands); // TODO(allen): This is hacky, when the new UI stuff happens, let's fix it, // and by that I mean actually fix it, don't just say you fixed it with @@ -1294,27 +1293,28 @@ App_Init_Sig(app_init){ i32 mapid = unit->map_begin.mapid; i32 count = map_get_max_count(models, mapid); i32 table_max = count * 3 / 2; + b32 auto_clear = false; if (mapid == mapid_global){ map_ptr = &models->map_top; - map_init(map_ptr, &models->mem.part, table_max, global_map); + auto_clear = map_init(map_ptr, &models->mem.part, table_max, global_map); did_top = true; } else if (mapid == mapid_file){ map_ptr = &models->map_file; - map_init(map_ptr, &models->mem.part, table_max, global_map); + auto_clear = map_init(map_ptr, &models->mem.part, table_max, global_map); did_file = true; } else if (mapid < mapid_global){ i32 index = get_or_add_map_index(models, mapid); Assert(index < user_map_count); map_ptr = models->user_maps + index; - map_init(map_ptr, &models->mem.part, table_max, global_map); + auto_clear = map_init(map_ptr, &models->mem.part, table_max, global_map); } else{ map_ptr = 0; } - if (map_ptr && unit->map_begin.replace){ + if (map_ptr && (unit->map_begin.replace || auto_clear)){ map_clear(map_ptr); } }break; @@ -1339,9 +1339,12 @@ App_Init_Sig(app_init){ if (unit->binding.command_id >= 0 && unit->binding.command_id < cmdid_count) func = command_table[unit->binding.command_id]; if (func){ - if (unit->binding.code == 0 && unit->binding.modifiers == 0){ - map_ptr->vanilla_keyboard_default.function = func; - map_ptr->vanilla_keyboard_default.custom_id = unit->binding.command_id; + if (unit->binding.code == 0){ + u32 index = 0; + if (map_get_modifiers_hash(unit->binding.modifiers, &index)){ + map_ptr->vanilla_keyboard_default[index].function = func; + map_ptr->vanilla_keyboard_default[index].custom_id = unit->binding.command_id; + } } else{ map_add(map_ptr, unit->binding.code, unit->binding.modifiers, func, unit->binding.command_id); @@ -1354,9 +1357,12 @@ App_Init_Sig(app_init){ Command_Function func = command_user_callback; Custom_Command_Function *custom = unit->callback.func; if (func){ - if (unit->callback.code == 0 && unit->callback.modifiers == 0){ - map_ptr->vanilla_keyboard_default.function = func; - map_ptr->vanilla_keyboard_default.custom = custom; + if (unit->callback.code == 0){ + u32 index = 0; + if (map_get_modifiers_hash(unit->binding.modifiers, &index)){ + map_ptr->vanilla_keyboard_default[index].function = func; + map_ptr->vanilla_keyboard_default[index].custom = custom; + } } else{ map_add(map_ptr, unit->callback.code, unit->callback.modifiers, func, custom); diff --git a/4ed_command.cpp b/4ed_command.cpp index a4a38ad3..0d6d3590 100644 --- a/4ed_command.cpp +++ b/4ed_command.cpp @@ -26,7 +26,7 @@ static Command_Binding null_command_binding = {0}; struct Command_Map{ Command_Map *parent; - Command_Binding vanilla_keyboard_default; + Command_Binding vanilla_keyboard_default[8]; Command_Binding *commands; u32 count, max; }; @@ -121,24 +121,46 @@ internal void map_clear(Command_Map *commands){ u32 max = commands->max; memset(commands->commands, 0, max*sizeof(*commands->commands)); - commands->vanilla_keyboard_default = null_command_binding; + memset(commands->vanilla_keyboard_default, 0, sizeof(commands->vanilla_keyboard_default)); commands->count = 0; } -internal void +internal b32 map_init(Command_Map *commands, Partition *part, u32 max, Command_Map *parent){ + b32 result = false; if (commands->commands == 0){ max = clamp_bottom((u32)6, max); commands->parent = parent; commands->commands = push_array(part, Command_Binding, max); + commands->count = 0; commands->max = max; + result = true; } + return(result); +} + +internal b32 +map_get_modifiers_hash(u8 modifiers, u32 *hash_out){ + b32 result = true; + u32 hash = 0; + if (modifiers & MDFR_SHIFT){ + hash += 0x1; + } + if (modifiers & MDFR_CTRL){ + hash += 0x2; + } + if (modifiers & MDFR_ALT){ + hash += 0x4; + } + *hash_out = hash; + return(result); } internal void map_get_vanilla_keyboard_default(Command_Map *map, u8 command, Command_Binding *bind_out){ - if (command == MDFR_NONE){ - *bind_out = map->vanilla_keyboard_default; + u32 modifiers_hashed = 0; + if (map_get_modifiers_hash(command, &modifiers_hashed)){ + *bind_out = map->vanilla_keyboard_default[modifiers_hashed]; } } diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 9329aba6..c8f56991 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -5704,10 +5704,7 @@ to_writable_char(Key_Code long_character){ } internal Input_Process_Result -do_step_file_view(System_Functions *system, - View *view, i32_Rect rect, b32 is_active, - Input_Summary *user_input, - GUI_Scroll_Vars vars, i32_Rect region, i32 max_y){ +do_step_file_view(System_Functions *system, View *view, i32_Rect rect, b32 is_active, Input_Summary *user_input, GUI_Scroll_Vars vars, i32_Rect region, i32 max_y){ Input_Process_Result result = {0}; b32 is_file_scroll = 0; diff --git a/4ed_utf8_conversions.h b/4ed_utf8_conversions.h deleted file mode 100644 index 2026b2b8..00000000 --- a/4ed_utf8_conversions.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Mr. 4th Dimention - Allen Webster - * - * 17.02.2017 - * - * File for reading and writing utf8. - * - */ - -// TOP - -#if !defined(FED_UTF8_CONVERSION_H) -#define FED_UTF8_CONVERSION_H - -internal u32 -utf8_to_u32_unchecked(u8 *buffer){ - u32 result = 0; - - if (buffer[0] <= 0x7F){ - result = (u32)buffer[0]; - } - else if (buffer[0] <= 0xE0){ - result = ((u32)((buffer[0])&0x1F)) << 6; - result |= ((u32)((buffer[1])&0x3F)); - } - else if (buffer[0] <= 0xF0){ - result = ((u32)((buffer[0])&0x0F)) << 12; - result |= ((u32)((buffer[1])&0x3F)) << 6; - result |= ((u32)((buffer[2])&0x3F)); - } - else{ - result = ((u32)((buffer[0])&0x07)) << 18; - result |= ((u32)((buffer[1])&0x3F)) << 12; - result |= ((u32)((buffer[2])&0x3F)) << 6; - result |= ((u32)((buffer[3])&0x3F)); - } - - return(result); -} - - -#endif - -// BOTTOM - diff --git a/filetrack/4tech_file_track_win32.c b/filetrack/4tech_file_track_win32.c index 4d416e4c..9156a8f0 100644 --- a/filetrack/4tech_file_track_win32.c +++ b/filetrack/4tech_file_track_win32.c @@ -158,14 +158,7 @@ add_listener(File_Track_System *system, char *filename){ if (node){ if (CreateIoCompletionPort(dir, vars->iocp, (ULONG_PTR)node, 1)){ ZeroStruct(node->listener.overlapped); - if (ReadDirectoryChangesW(dir, - node->listener.result, - sizeof(node->listener.result), - 1, - FLAGS, - 0, - &node->listener.overlapped, - 0)){ + if (ReadDirectoryChangesW(dir, node->listener.result, sizeof(node->listener.result), 1, FLAGS, 0, &node->listener.overlapped, 0)){ node->listener.dir = dir; node->listener.user_count = 1; diff --git a/internal_4coder_tests.cpp b/internal_4coder_tests.cpp index d3a9967a..59184519 100644 --- a/internal_4coder_tests.cpp +++ b/internal_4coder_tests.cpp @@ -16,6 +16,7 @@ Allen Webster #include "4coder_default_include.cpp" +#include #include #include @@ -50,7 +51,7 @@ CUSTOM_COMMAND_SIG(load_lots_of_files){ if (!info->folder){ append_ss(&str, make_string(info->filename, info->filename_len)); Buffer_Summary buffer = create_buffer(app, str.str, str.size, - BufferCreate_Background); + BufferCreate_Background); assert(buffer.size != 0); str.size = size; } diff --git a/linux_4ed.cpp b/linux_4ed.cpp index 1df86b2c..a9522eb0 100644 --- a/linux_4ed.cpp +++ b/linux_4ed.cpp @@ -15,6 +15,8 @@ #include "4tech_defines.h" #include "4coder_API/version.h" +#include "4coder_lib/4coder_utf8.h" + #if defined(FRED_SUPER) # include "4coder_API/keycodes.h" # include "4coder_API/style.h" @@ -37,8 +39,6 @@ #include "4ed_rendering.h" #include "4ed.h" -#include "4ed_utf8_conversions.h" - #include #include #include diff --git a/meta/4ed_metagen.cpp b/meta/4ed_metagen.cpp index 4fac97b0..b07cca91 100644 --- a/meta/4ed_metagen.cpp +++ b/meta/4ed_metagen.cpp @@ -74,7 +74,7 @@ internal void generate_keycode_enum(){ char *filename_keycodes = KEYCODES_FILE; - uint16_t code = 0xE000; + uint16_t code = 0xD800; String out = make_out_string(10 << 20); diff --git a/meta/build.cpp b/meta/build.cpp index 54956925..5d9e2dcf 100644 --- a/meta/build.cpp +++ b/meta/build.cpp @@ -424,6 +424,7 @@ do_buildsuper(char *cdir, i32 custom_option){ static void build_main(char *cdir, u32 flags){ DECL_STR(dir, BUILD_DIR); + { DECL_STR(file, "4ed_app_target.cpp"); BEGIN_TIME_SECTION(); @@ -440,8 +441,6 @@ build_main(char *cdir, u32 flags){ static void standard_build(char *cdir, u32 flags){ - //run_update("4coder_string.h"); - //run_update("4cpp/4cpp_lexer.h 4cpp/4cpp_lexer.h 4cpp/4cpp_lexer.h"); fsm_generator(cdir); metagen(cdir); do_buildsuper(cdir, Custom_Experiments); diff --git a/string/4tech_standard_preamble.h b/string/4tech_standard_preamble.h index a44a897e..5be1182f 100644 --- a/string/4tech_standard_preamble.h +++ b/string/4tech_standard_preamble.h @@ -12,6 +12,8 @@ typedef uint16_t u16_4tech; typedef uint32_t u32_4tech; typedef uint64_t u64_4tech; +typedef u64_4tech umem_4tech; + typedef float f32_4tech; typedef double f64_4tech; diff --git a/win32_4ed.cpp b/win32_4ed.cpp index d758d78e..c35d4b38 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -14,6 +14,8 @@ #include "4tech_defines.h" #include "4coder_API/version.h" +#include "4coder_lib/4coder_utf8.h" + #if defined(FRED_SUPER) # include "4coder_API/keycodes.h" # include "4coder_API/style.h" @@ -285,12 +287,14 @@ Sys_Free_Memory_Sig(system_free_memory){ #define Win32ScratchPartitionGrow sysshared_partition_grow #define Win32ScratchPartitionDouble sysshared_partition_double +#if 0 #if FRED_INTERNAL internal void INTERNAL_system_debug_message(char *message){ - OutputDebugStringA(message); + OutputDebugStringW(message); } #endif +#endif // @@ -749,7 +753,7 @@ Sys_Set_File_List_Sig(system_set_file_list){ HANDLE dir_handle = CreateFile(dir.str, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (dir_handle != INVALID_HANDLE_VALUE){ - DWORD final_length = GetFinalPathNameByHandleA(dir_handle, dir_space, sizeof(dir_space), 0); + DWORD final_length = GetFinalPathNameByHandle(dir_handle, dir_space, sizeof(dir_space), 0); CloseHandle(dir_handle); if (final_length < sizeof(dir_space)){ @@ -778,7 +782,7 @@ Sys_Set_File_List_Sig(system_set_file_list){ } WIN32_FIND_DATA find_data; - HANDLE search = FindFirstFileA(c_str_dir, &find_data); + HANDLE search = FindFirstFile(c_str_dir, &find_data); if (search != INVALID_HANDLE_VALUE){ i32 character_count = 0; @@ -806,7 +810,7 @@ Sys_Set_File_List_Sig(system_set_file_list){ file_list->infos = (File_Info*)file_list->block; char *name = (char*)(file_list->infos + file_count); if (file_list->block != 0){ - search = FindFirstFileA(c_str_dir, &find_data); + search = FindFirstFile(c_str_dir, &find_data); if (search != INVALID_HANDLE_VALUE){ File_Info *info = file_list->infos; @@ -848,7 +852,6 @@ Sys_Set_File_List_Sig(system_set_file_list){ } } -#if 1 internal u32 win32_canonical_ascii_name(char *src, u32 len, char *dst, u32 max){ u32 result = 0; @@ -861,7 +864,7 @@ win32_canonical_ascii_name(char *src, u32 len, char *dst, u32 max){ HANDLE file = CreateFile(src_space, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (file != INVALID_HANDLE_VALUE){ - DWORD final_length = GetFinalPathNameByHandleA(file, dst, max, 0); + DWORD final_length = GetFinalPathNameByHandle(file, dst, max, 0); if (final_length < max && final_length >= 4){ if (dst[final_length-1] == 0){ @@ -886,7 +889,7 @@ win32_canonical_ascii_name(char *src, u32 len, char *dst, u32 max){ HANDLE dir = CreateFile(src_space, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, 0); if (dir != INVALID_HANDLE_VALUE){ - DWORD final_length = GetFinalPathNameByHandleA(dir, dst, max, 0); + DWORD final_length = GetFinalPathNameByHandle(dir, dst, max, 0); if (final_length < max && final_length >= 4){ if (dst[final_length-1] == 0){ @@ -909,7 +912,7 @@ win32_canonical_ascii_name(char *src, u32 len, char *dst, u32 max){ return(result); } -#else +#if 0 internal u32 win32_canonical_ascii_name(char *src, u32 len, char *dst, u32 max){ char *wrt = dst; @@ -1065,10 +1068,10 @@ Sys_Now_Time_Sig(system_now_time){ return(result); } -b32 Win32DirectoryExists(char *path){ - DWORD attrib = GetFileAttributesA(path); - return (attrib != INVALID_FILE_ATTRIBUTES && - (attrib & FILE_ATTRIBUTE_DIRECTORY)); +internal b32 +Win32DirectoryExists(char *path){ + DWORD attrib = GetFileAttributes(path); + return (attrib != INVALID_FILE_ATTRIBUTES && (attrib & FILE_ATTRIBUTE_DIRECTORY)); } internal @@ -2216,7 +2219,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS if (win32vars.custom_api.get_alpha_4coder_version == 0 || win32vars.custom_api.get_alpha_4coder_version(MAJOR, MINOR, PATCH) == 0){ - MessageBoxA(0,"Error: The application and custom version numbers don't match.\n", "Error",0); + MessageBox(0,"Error: The application and custom version numbers don't match.\n", "Error",0); exit(1); } win32vars.custom_api.get_bindings = (Get_Binding_Data_Function*) @@ -2224,7 +2227,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS } if (win32vars.custom_api.get_bindings == 0){ - MessageBoxA(0,"Error: The custom dll is missing.\n", "Error",0); + MessageBox(0,"Error: The custom dll is missing.\n", "Error",0); exit(1); } @@ -2277,7 +2280,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdS window_style |= WS_MAXIMIZE; } - win32vars.window_handle = CreateWindowA(window_class.lpszClassName, WINDOW_NAME, window_style, window_x, window_y, window_rect.right - window_rect.left, window_rect.bottom - window_rect.top, 0, 0, hInstance, 0); + win32vars.window_handle = CreateWindow(window_class.lpszClassName, WINDOW_NAME, window_style, window_x, window_y, window_rect.right - window_rect.left, window_rect.bottom - window_rect.top, 0, 0, hInstance, 0); if (win32vars.window_handle == 0){ exit(1);