diff --git a/4coder_custom.h b/4coder_custom.h index c2d43904..77b0686f 100644 --- a/4coder_custom.h +++ b/4coder_custom.h @@ -198,23 +198,21 @@ enum Command_ID{ cmdid_interactive_kill_buffer, cmdid_kill_buffer, - cmdid_change_active_panel, - cmdid_to_uppercase, cmdid_to_lowercase, cmdid_toggle_line_wrap, cmdid_toggle_show_whitespace, - cmdid_eol_dosify, - cmdid_eol_nixify, - cmdid_clean_all_lines, cmdid_auto_tab_range, + cmdid_eol_dosify, + cmdid_eol_nixify, cmdid_open_panel_vsplit, cmdid_open_panel_hsplit, cmdid_close_panel, + cmdid_change_active_panel, cmdid_page_up, cmdid_page_down, @@ -226,7 +224,9 @@ enum Command_ID{ cmdid_hide_scrollbar, cmdid_show_scrollbar, + cmdid_set_settings, + cmdid_command_line, // cmdid_count @@ -360,7 +360,7 @@ struct Theme_Color{ #define GET_BINDING_DATA(name) int name(void *data, int size) #define CUSTOM_COMMAND_SIG(name) void name(struct Application_Links *app) #define HOOK_SIG(name) int name(struct Application_Links *app) -#define SCROLL_RULE_SIG(name) int name(float target_x, float target_y, float *scroll_x, float *scroll_y, int view_id, int is_new_target) +#define SCROLL_RULE_SIG(name) int name(float target_x, float target_y, float *scroll_x, float *scroll_y, int view_id, int is_new_target, float dt) extern "C"{ typedef VIEW_ROUTINE_SIG(View_Routine_Function); diff --git a/4coder_default_bindings.cpp b/4coder_default_bindings.cpp index 2efa6106..d5f94cd9 100644 --- a/4coder_default_bindings.cpp +++ b/4coder_default_bindings.cpp @@ -244,6 +244,7 @@ default_keys(Bind_Helper *context){ bind(context, 'k', MDFR_CTRL, cmdid_interactive_kill_buffer); bind(context, 'i', MDFR_CTRL, cmdid_interactive_switch_buffer); bind(context, 'c', MDFR_ALT, cmdid_open_color_tweaker); + bind(context, 'd', MDFR_ALT, cmdid_open_debug); bind(context, 'o', MDFR_ALT, open_in_other); bind(context, 'w', MDFR_CTRL, save_as); diff --git a/4coder_keycodes.h b/4coder_keycodes.h index 92df28f2..16c4ee75 100644 --- a/4coder_keycodes.h +++ b/4coder_keycodes.h @@ -1,30 +1,65 @@ enum Key_Code{ - key_back = 1, - key_up = 2, - key_down = 3, - key_left = 4, - key_right = 5, - key_del = 6, - key_insert = 7, - key_home = 8, - key_end = 11, - key_page_up = 12, - key_page_down = 13, - key_esc = 14, - key_f1 = 127, - key_f2 = 128, - key_f3 = 129, - key_f4 = 130, - key_f5 = 131, - key_f6 = 132, - key_f7 = 133, - key_f8 = 134, - key_f9 = 135, - key_f10 = 136, - key_f11 = 137, - key_f12 = 138, - key_f13 = 139, - key_f14 = 140, - key_f15 = 141, - key_f16 = 142, +key_back = 1, +key_up = 2, +key_down = 3, +key_left = 4, +key_right = 5, +key_del = 6, +key_insert = 7, +key_home = 8, +key_end = 11, +key_page_up = 12, +key_page_down = 13, +key_esc = 14, +key_f1 = 127, +key_f2 = 128, +key_f3 = 129, +key_f4 = 130, +key_f5 = 131, +key_f6 = 132, +key_f7 = 133, +key_f8 = 134, +key_f9 = 135, +key_f10 = 136, +key_f11 = 137, +key_f12 = 138, +key_f13 = 139, +key_f14 = 140, +key_f15 = 141, +key_f16 = 142, }; +static char* +global_key_name(int key_code, int *size){ +char *result = 0; +switch(key_code){ +case key_back: result = "back"; *size = sizeof("back")-1; break; +case key_up: result = "up"; *size = sizeof("up")-1; break; +case key_down: result = "down"; *size = sizeof("down")-1; break; +case key_left: result = "left"; *size = sizeof("left")-1; break; +case key_right: result = "right"; *size = sizeof("right")-1; break; +case key_del: result = "del"; *size = sizeof("del")-1; break; +case key_insert: result = "insert"; *size = sizeof("insert")-1; break; +case key_home: result = "home"; *size = sizeof("home")-1; break; +case key_end: result = "end"; *size = sizeof("end")-1; break; +case key_page_up: result = "page_up"; *size = sizeof("page_up")-1; break; +case key_page_down: result = "page_down"; *size = sizeof("page_down")-1; break; +case key_esc: result = "esc"; *size = sizeof("esc")-1; break; +case key_f1: result = "f1"; *size = sizeof("f1")-1; break; +case key_f2: result = "f2"; *size = sizeof("f2")-1; break; +case key_f3: result = "f3"; *size = sizeof("f3")-1; break; +case key_f4: result = "f4"; *size = sizeof("f4")-1; break; +case key_f5: result = "f5"; *size = sizeof("f5")-1; break; +case key_f6: result = "f6"; *size = sizeof("f6")-1; break; +case key_f7: result = "f7"; *size = sizeof("f7")-1; break; +case key_f8: result = "f8"; *size = sizeof("f8")-1; break; +case key_f9: result = "f9"; *size = sizeof("f9")-1; break; +case key_f10: result = "f10"; *size = sizeof("f10")-1; break; +case key_f11: result = "f11"; *size = sizeof("f11")-1; break; +case key_f12: result = "f12"; *size = sizeof("f12")-1; break; +case key_f13: result = "f13"; *size = sizeof("f13")-1; break; +case key_f14: result = "f14"; *size = sizeof("f14")-1; break; +case key_f15: result = "f15"; *size = sizeof("f15")-1; break; +case key_f16: result = "f16"; *size = sizeof("f16")-1; break; +} +return(result); +} diff --git a/4coder_string.h b/4coder_string.h index c51c82bc..4556ef5c 100644 --- a/4coder_string.h +++ b/4coder_string.h @@ -10,19 +10,17 @@ NOTES ON USE: in the same unit do not continue to output implementations FSTRING_LINK - defines linkage of non-inline functions, defaults to static - FCPP_EXTERN changes FCPP_LINK default to extern, this option is ignored if FCPP_LINK is defined - + include the file "4cpp_clear_config.h" if yo want to undefine all options for some reason - - HIDDEN DEPENDENCIES: - none - */ +*/ // TOP #ifndef FCPP_STRING_INC #define FCPP_STRING_INC +#include + #ifndef FSTRING_LINK # define FSTRING_LINK static #endif @@ -35,136 +33,143 @@ NOTES ON USE: #define FRED_STRING_STRUCT struct String{ char *str; - int size; - int memory_size; + int32_t size; + int32_t memory_size; }; struct Offset_String{ - int offset; - int size; + int32_t offset; + int32_t size; }; #endif -FSTRING_INLINE bool char_not_slash(char c) { return (c != '\\' && c != '/'); } -FSTRING_INLINE bool char_is_slash(char c) { return (c == '\\' || c == '/'); } +#ifndef fstr_bool +# define fstr_bool int +#endif + +#ifndef literal +# define literal(s) (s), (sizeof(s)-1) +#endif + +FSTRING_INLINE fstr_bool char_not_slash(char c) { return (c != '\\' && c != '/'); } +FSTRING_INLINE fstr_bool char_is_slash(char c) { return (c == '\\' || c == '/'); } FSTRING_INLINE char char_to_upper(char c) { return (c >= 'a' && c <= 'z') ? c + (char)('A' - 'a') : c; } FSTRING_INLINE char char_to_lower(char c) { return (c >= 'A' && c <= 'Z') ? c - (char)('A' - 'a') : c; } -FSTRING_INLINE int char_to_int(char c) { return (c - '0'); } -FSTRING_INLINE char int_to_char(int x) { return (char)(x + '0'); } +FSTRING_INLINE int32_t char_to_int(char c) { return (c - '0'); } +FSTRING_INLINE char int_to_char(int32_t x) { return (char)(x + '0'); } -FSTRING_INLINE bool char_is_whitespace(char c) { return (c == ' ' || c == '\n' || c == '\r' || c == '\t'); } -FSTRING_INLINE bool char_is_white_not_r(char c) { return (c == ' ' || c == '\n' || c == '\t'); } -FSTRING_INLINE bool char_is_lower(char c) { return (c >= 'a' && c <= 'z'); } -FSTRING_INLINE bool char_is_upper(char c) { return (c >= 'A' && c <= 'Z'); } -FSTRING_INLINE bool char_is_alpha(char c) { return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '_'); } -FSTRING_INLINE bool char_is_alpha_true(char c) { return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'); } -FSTRING_INLINE bool char_is_numeric(char c) { return (c >= '0' && c <= '9'); } -FSTRING_INLINE bool char_is_alpha_numeric_true(char c) { return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9'); } -FSTRING_INLINE bool char_is_alpha_numeric(char c) { return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_'); } -FSTRING_INLINE bool char_is_hex(char c) { return c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f'; } -FSTRING_INLINE bool char_is_basic(char c) { return c >= ' ' && c <= '~'; } +FSTRING_INLINE fstr_bool char_is_whitespace(char c) { return (c == ' ' || c == '\n' || c == '\r' || c == '\t'); } +FSTRING_INLINE fstr_bool char_is_white_not_r(char c) { return (c == ' ' || c == '\n' || c == '\t'); } +FSTRING_INLINE fstr_bool char_is_lower(char c) { return (c >= 'a' && c <= 'z'); } +FSTRING_INLINE fstr_bool char_is_upper(char c) { return (c >= 'A' && c <= 'Z'); } +FSTRING_INLINE fstr_bool char_is_alpha(char c) { return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '_'); } +FSTRING_INLINE fstr_bool char_is_alpha_true(char c) { return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'); } +FSTRING_INLINE fstr_bool char_is_numeric(char c) { return (c >= '0' && c <= '9'); } +FSTRING_INLINE fstr_bool char_is_alpha_numeric_true(char c) { return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9'); } +FSTRING_INLINE fstr_bool char_is_alpha_numeric(char c) { return (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_'); } +FSTRING_INLINE fstr_bool char_is_hex(char c) { return c >= '0' && c <= '9' || c >= 'A' && c <= 'F' || c >= 'a' && c <= 'f'; } +FSTRING_INLINE fstr_bool char_is_basic(char c) { return c >= ' ' && c <= '~'; } FSTRING_INLINE String string_zero(); -FSTRING_INLINE String make_string(void *s, int size, int mem_size); -FSTRING_INLINE String make_string(void *s, int size); +FSTRING_INLINE String make_string(void *s, int32_t size, int32_t mem_size); +FSTRING_INLINE String make_string(void *s, int32_t size); #define make_lit_string(str) (make_string((char*)(str), sizeof(str)-1, sizeof(str))) #define make_fixed_width_string(str) (make_string((char*)(str), 0, sizeof(str))) -#ifndef literal -#define literal(s) (s), (sizeof(s)-1) -#endif - #define expand_str(s) ((s).str), ((s).size) -FSTRING_INLINE String make_string_slowly(void *s); -FSTRING_INLINE char* make_c_str(String s); +FSTRING_INLINE String make_string_slowly(void *s); +FSTRING_INLINE char* make_c_str(String s); -FSTRING_INLINE String substr(String str, int start); -FSTRING_INLINE String substr(String str, int start, int size); -FSTRING_INLINE String substr_slowly(char *s, int start); -FSTRING_INLINE String substr(char *s, int start, int size); -FSTRING_INLINE String tailstr(String s); +FSTRING_INLINE String substr(String str, int32_t start); +FSTRING_INLINE String substr(String str, int32_t start, int32_t size); +FSTRING_INLINE String substr_slowly(char *s, int32_t start); +FSTRING_INLINE String substr(char *s, int32_t start, int32_t size); +FSTRING_INLINE String tailstr(String s); -FSTRING_LINK int str_size(char *s); +FSTRING_LINK int32_t str_size(char *s); -FSTRING_LINK bool match(char *a, char *b); -FSTRING_LINK bool match(String a, char *b); -FSTRING_INLINE bool match(char *a, String b) { return match(b,a); } -FSTRING_LINK bool match(String a, String b); +FSTRING_LINK fstr_bool match(char *a, char *b); +FSTRING_LINK fstr_bool match(String a, char *b); +FSTRING_INLINE fstr_bool match(char *a, String b) { return match(b,a); } +FSTRING_LINK fstr_bool match(String a, String b); -FSTRING_LINK bool match_part(char *a, char *b, int *len); -FSTRING_LINK bool match_part(String a, char *b, int *len); -FSTRING_INLINE bool match_part(char *a, char *b) { int x; return match_part(a,b,&x); } -FSTRING_INLINE bool match_part(String a, char *b) { int x; return match_part(a,b,&x); } -FSTRING_LINK bool match_part(char *a, String b); -FSTRING_LINK bool match_part(String a, String b); +FSTRING_LINK fstr_bool match_part(char *a, char *b, int32_t *len); +FSTRING_LINK fstr_bool match_part(String a, char *b, int32_t *len); +FSTRING_INLINE fstr_bool match_part(char *a, char *b) { int32_t x; return match_part(a,b,&x); } +FSTRING_INLINE fstr_bool match_part(String a, char *b) { int32_t x; return match_part(a,b,&x); } +FSTRING_LINK fstr_bool match_part(char *a, String b); +FSTRING_LINK fstr_bool match_part(String a, String b); -FSTRING_LINK bool match_insensitive(char *a, char *b); -FSTRING_LINK bool match_insensitive(String a, char *b); -FSTRING_INLINE bool match_insensitive(char *a, String b) { return match_insensitive(b,a); } -FSTRING_LINK bool match_insensitive(String a, String b); +FSTRING_LINK fstr_bool match_insensitive(char *a, char *b); +FSTRING_LINK fstr_bool match_insensitive(String a, char *b); +FSTRING_INLINE fstr_bool match_insensitive(char *a, String b) { return match_insensitive(b,a); } +FSTRING_LINK fstr_bool match_insensitive(String a, String b); -FSTRING_LINK bool match_part_insensitive(char *a, char *b, int *len); -FSTRING_LINK bool match_part_insensitive(String a, char *b, int *len); -FSTRING_INLINE bool match_part_insensitive(char *a, char *b) { int x; return match_part(a,b,&x); } -FSTRING_INLINE bool match_part_insensitive(String a, char *b) { int x; return match_part(a,b,&x); } -FSTRING_LINK bool match_part_insensitive(char *a, String b); -FSTRING_LINK bool match_part_insensitive(String a, String b); +FSTRING_LINK fstr_bool match_part_insensitive(char *a, char *b, int32_t *len); +FSTRING_LINK fstr_bool match_part_insensitive(String a, char *b, int32_t *len); +FSTRING_INLINE fstr_bool match_part_insensitive(char *a, char *b) { int32_t x; return match_part(a,b,&x); } +FSTRING_INLINE fstr_bool match_part_insensitive(String a, char *b) { int32_t x; return match_part(a,b,&x); } +FSTRING_LINK fstr_bool match_part_insensitive(char *a, String b); +FSTRING_LINK fstr_bool match_part_insensitive(String a, String b); -FSTRING_LINK int find(char *s, int start, char c); -FSTRING_LINK int find(String s, int start, char c); -FSTRING_LINK int find(char *s, int start, char *c); -FSTRING_LINK int find(String s, int start, char *c); +FSTRING_LINK int32_t find(char *s, int32_t start, char c); +FSTRING_LINK int32_t find(String s, int32_t start, char c); +FSTRING_LINK int32_t find(char *s, int32_t start, char *c); +FSTRING_LINK int32_t find(String s, int32_t start, char *c); -FSTRING_LINK int find_substr(char *s, int start, String seek); -FSTRING_LINK int find_substr(String s, int start, String seek); -FSTRING_LINK int rfind_substr(String s, int start, String seek); +FSTRING_LINK int32_t find_substr(char *s, int32_t start, String seek); +FSTRING_LINK int32_t find_substr(String s, int32_t start, String seek); +FSTRING_LINK int32_t rfind_substr(String s, int32_t start, String seek); -FSTRING_LINK int find_substr_insensitive(char *s, int start, String seek); -FSTRING_LINK int find_substr_insensitive(String s, int start, String seek); +FSTRING_LINK int32_t find_substr_insensitive(char *s, int32_t start, String seek); +FSTRING_LINK int32_t find_substr_insensitive(String s, int32_t start, String seek); -FSTRING_INLINE bool has_substr(char *s, String seek) { return (s[find_substr(s, 0, seek)] != 0); } -FSTRING_INLINE bool has_substr(String s, String seek) { return (find_substr(s, 0, seek) < s.size); } +FSTRING_INLINE fstr_bool has_substr(char *s, String seek) { return (s[find_substr(s, 0, seek)] != 0); } +FSTRING_INLINE fstr_bool has_substr(String s, String seek) { return (find_substr(s, 0, seek) < s.size); } -FSTRING_INLINE bool has_substr_insensitive(char *s, String seek) { return (s[find_substr_insensitive(s, 0, seek)] != 0); } -FSTRING_INLINE bool has_substr_insensitive(String s, String seek) { return (find_substr_insensitive(s, 0, seek) < s.size); } +FSTRING_INLINE fstr_bool has_substr_insensitive(char *s, String seek) { return (s[find_substr_insensitive(s, 0, seek)] != 0); } +FSTRING_INLINE fstr_bool has_substr_insensitive(String s, String seek) { return (find_substr_insensitive(s, 0, seek) < s.size); } -FSTRING_LINK int int_to_str_size(int x); -FSTRING_LINK int int_to_str(int x, char *s_out); -FSTRING_LINK bool int_to_str(int x, String *s_out); -FSTRING_LINK bool append_int_to_str(int x, String *s_out); +FSTRING_LINK int32_t int_to_str_size(int32_t x); +FSTRING_LINK fstr_bool int_to_str(String *s_out, int32_t x); +FSTRING_LINK fstr_bool append_int_to_str(String *s_out, int32_t x); -FSTRING_LINK int str_to_int(char *s); -FSTRING_LINK int str_to_int(String s); -FSTRING_LINK int hexchar_to_int(char c); -FSTRING_LINK char int_to_hexchar(int c); -FSTRING_LINK unsigned int hexstr_to_int(String s); +FSTRING_LINK int32_t u64_to_str_size(uint64_t x); +FSTRING_LINK fstr_bool u64_to_str(String *s_out, uint64_t x); +FSTRING_LINK fstr_bool append_u64_to_str(String *s_out, uint64_t x); -FSTRING_LINK bool color_to_hexstr(unsigned int color, String *s_out); -FSTRING_LINK bool hexstr_to_color(String s, unsigned int *color); +FSTRING_LINK int32_t str_to_int(char *s); +FSTRING_LINK int32_t str_to_int(String s); +FSTRING_LINK int32_t hexchar_to_int(char c); +FSTRING_LINK char int_to_hexchar(int32_t c); +FSTRING_LINK uint32_t hexstr_to_int(String s); -FSTRING_LINK int copy_fast_unsafe(char *dest, char *src); +FSTRING_LINK fstr_bool color_to_hexstr(uint32_t color, String *s_out); +FSTRING_LINK fstr_bool hexstr_to_color(String s, uint32_t *color); + +FSTRING_LINK int32_t copy_fast_unsafe(char *dest, char *src); FSTRING_LINK void copy_fast_unsafe(char *dest, String src); -FSTRING_LINK bool copy_checked(String *dest, String src); -FSTRING_LINK bool copy_partial(String *dest, char *src); -FSTRING_LINK bool copy_partial(String *dest, String src); +FSTRING_LINK fstr_bool copy_checked(String *dest, String src); +FSTRING_LINK fstr_bool copy_partial(String *dest, char *src); +FSTRING_LINK fstr_bool copy_partial(String *dest, String src); -FSTRING_INLINE int copy(char *dest, char *src) { return copy_fast_unsafe(dest, src); } +FSTRING_INLINE int32_t copy(char *dest, char *src) { return copy_fast_unsafe(dest, src); } FSTRING_INLINE void copy(String *dest, String src) { copy_checked(dest, src); } FSTRING_INLINE void copy(String *dest, char *src) { copy_partial(dest, src); } -FSTRING_LINK bool append_checked(String *dest, String src); -FSTRING_LINK bool append_partial(String *dest, char *src); -FSTRING_LINK bool append_partial(String *dest, String src); +FSTRING_LINK fstr_bool append_checked(String *dest, String src); +FSTRING_LINK fstr_bool append_partial(String *dest, char *src); +FSTRING_LINK fstr_bool append_partial(String *dest, String src); -FSTRING_LINK bool append(String *dest, char c); -FSTRING_INLINE bool append(String *dest, String src) { return append_partial(dest, src); } -FSTRING_INLINE bool append(String *dest, char *src) { return append_partial(dest, src); } -FSTRING_INLINE bool terminate_with_null(String *str){ - bool result; +FSTRING_LINK fstr_bool append(String *dest, char c); +FSTRING_INLINE fstr_bool append(String *dest, String src) { return append_partial(dest, src); } +FSTRING_INLINE fstr_bool append(String *dest, char *src) { return append_partial(dest, src); } +FSTRING_INLINE fstr_bool terminate_with_null(String *str){ + fstr_bool result; if (str->size < str->memory_size){ str->str[str->size] = 0; result = 1; @@ -176,23 +181,23 @@ FSTRING_INLINE bool terminate_with_null(String *str){ return result; } -FSTRING_LINK int compare(char *a, char *b); -FSTRING_LINK int compare(String a, char *b); -FSTRING_INLINE int compare(char *a, String b) { return -compare(b,a); } -FSTRING_LINK int compare(String a, String b); +FSTRING_LINK int32_t compare(char *a, char *b); +FSTRING_LINK int32_t compare(String a, char *b); +FSTRING_INLINE int32_t compare(char *a, String b) { return -compare(b,a); } +FSTRING_LINK int32_t compare(String a, String b); -FSTRING_LINK int reverse_seek_slash(String str); -FSTRING_LINK int reverse_seek_slash(String str, int start_pos); +FSTRING_LINK int32_t reverse_seek_slash(String str); +FSTRING_LINK int32_t reverse_seek_slash(String str, int32_t start_pos); FSTRING_INLINE String front_of_directory(String dir) { return substr(dir, reverse_seek_slash(dir) + 1); } FSTRING_INLINE String path_of_directory(String dir) { return substr(dir, 0, reverse_seek_slash(dir) + 1); } -FSTRING_INLINE bool get_front_of_directory(String *dest, String dir) { return append_checked(dest, front_of_directory(dir)); } -FSTRING_INLINE bool get_path_of_directory(String *dest, String dir) { return append_checked(dest, path_of_directory(dir)); } -FSTRING_LINK bool set_last_folder(String *dir, char *folder_name, char slash); -FSTRING_LINK bool set_last_folder(String *dir, String folder_name, char slash); +FSTRING_INLINE fstr_bool get_front_of_directory(String *dest, String dir) { return append_checked(dest, front_of_directory(dir)); } +FSTRING_INLINE fstr_bool get_path_of_directory(String *dest, String dir) { return append_checked(dest, path_of_directory(dir)); } +FSTRING_LINK fstr_bool set_last_folder(String *dir, char *folder_name, char slash); +FSTRING_LINK fstr_bool set_last_folder(String *dir, String folder_name, char slash); FSTRING_LINK String file_extension(String str); FSTRING_LINK String file_extension_slowly(char *str); FSTRING_LINK char * file_extension_c(String str); -FSTRING_LINK bool remove_last_folder(String *str); +FSTRING_LINK fstr_bool remove_last_folder(String *str); FSTRING_LINK void replace_char(String str, char replace, char with); FSTRING_LINK void replace_char(char *str, char replace, char with); @@ -201,7 +206,7 @@ FSTRING_INLINE String string_zero(){ return(str); } -FSTRING_INLINE String make_string(void *str, int size, int mem_size){ +FSTRING_INLINE String make_string(void *str, int32_t size, int32_t mem_size){ String result; result.str = (char*)str; result.size = size; @@ -210,7 +215,7 @@ FSTRING_INLINE String make_string(void *str, int size, int mem_size){ } FSTRING_INLINE String -make_string(void *str, int size){ +make_string(void *str, int32_t size){ String result; result.str = (char*)str; result.size = size; @@ -239,7 +244,7 @@ make_c_str(String str){ } FSTRING_INLINE String -substr(String str, int start){ +substr(String str, int32_t start){ String result; result.str = str.str + start; result.size = str.size - start; @@ -247,7 +252,7 @@ substr(String str, int start){ } FSTRING_INLINE String -substr(String str, int start, int size){ +substr(String str, int32_t start, int32_t size){ String result; result.str = str.str + start; if (start + size > str.size){ @@ -260,7 +265,7 @@ substr(String str, int start, int size){ } FSTRING_INLINE String -substr_slowly(char *str, int start){ +substr_slowly(char *str, int32_t start){ String result; result.str = str + start; result.size = str_size(result.str); @@ -268,11 +273,11 @@ substr_slowly(char *str, int start){ } FSTRING_INLINE String -substr(char *str, int start, int size){ +substr(char *str, int32_t start, int32_t size){ String result; result.str = str + start; result.size = size; - for (int i = 0; i < size; ++i){ + for (int32_t i = 0; i < size; ++i){ if (result.str[i] == 0){ result.size = i; break; @@ -297,16 +302,16 @@ tailstr(String str){ #ifndef FCPP_DID_STRING_IMPLEMENTATION #define FCPP_DID_STRING_IMPLEMENTATION -FSTRING_LINK int +FSTRING_LINK int32_t str_size(char *str){ - int i = 0; + int32_t i = 0; while (str[i]) ++i; return i; } -FSTRING_LINK bool +FSTRING_LINK fstr_bool match(char *a, char *b){ - for (int i = 0;; ++i){ + for (int32_t i = 0;; ++i){ if (a[i] != b[i]){ return 0; } @@ -316,9 +321,9 @@ match(char *a, char *b){ } } -FSTRING_LINK bool +FSTRING_LINK fstr_bool match(String a, char *b){ - int i = 0; + int32_t i = 0; for (; i < a.size; ++i){ if (a.str[i] != b[i]){ return 0; @@ -330,12 +335,12 @@ match(String a, char *b){ return 1; } -FSTRING_LINK bool +FSTRING_LINK fstr_bool match(String a, String b){ if (a.size != b.size){ return 0; } - for (int i = 0; i < b.size; ++i){ + for (int32_t i = 0; i < b.size; ++i){ if (a.str[i] != b.str[i]){ return 0; } @@ -343,9 +348,9 @@ match(String a, String b){ return 1; } -FSTRING_LINK bool -match_part(char *a, char *b, int *len){ - int i; +FSTRING_LINK fstr_bool +match_part(char *a, char *b, int32_t *len){ + int32_t i; for (i = 0; b[i] != 0; ++i){ if (a[i] != b[i]){ return 0; @@ -355,9 +360,9 @@ match_part(char *a, char *b, int *len){ return 1; } -FSTRING_LINK bool -match_part(String a, char *b, int *len){ - int i; +FSTRING_LINK fstr_bool +match_part(String a, char *b, int32_t *len){ + int32_t i; for (i = 0; b[i] != 0; ++i){ if (a.str[i] != b[i] || i == a.size){ return 0; @@ -367,9 +372,9 @@ match_part(String a, char *b, int *len){ return 1; } -FSTRING_LINK bool +FSTRING_LINK fstr_bool match_part(char *a, String b){ - for (int i = 0; i != b.size; ++i){ + for (int32_t i = 0; i != b.size; ++i){ if (a[i] != b.str[i]){ return 0; } @@ -377,12 +382,12 @@ match_part(char *a, String b){ return 1; } -FSTRING_LINK bool +FSTRING_LINK fstr_bool match_part(String a, String b){ if (a.size < b.size){ return 0; } - for (int i = 0; i < b.size; ++i){ + for (int32_t i = 0; i < b.size; ++i){ if (a.str[i] != b.str[i]){ return 0; } @@ -390,9 +395,9 @@ match_part(String a, String b){ return 1; } -FSTRING_LINK bool +FSTRING_LINK fstr_bool match_insensitive(char *a, char *b){ - for (int i = 0;; ++i){ + for (int32_t i = 0;; ++i){ if (char_to_upper(a[i]) != char_to_upper(b[i])){ return 0; @@ -403,9 +408,9 @@ match_insensitive(char *a, char *b){ } } -FSTRING_LINK bool +FSTRING_LINK fstr_bool match_insensitive(String a, char *b){ - int i = 0; + int32_t i = 0; for (; i < a.size; ++i){ if (char_to_upper(a.str[i]) != char_to_upper(b[i])){ @@ -418,12 +423,12 @@ match_insensitive(String a, char *b){ return 1; } -FSTRING_LINK bool +FSTRING_LINK fstr_bool match_insensitive(String a, String b){ if (a.size != b.size){ return 0; } - for (int i = 0; i < b.size; ++i){ + for (int32_t i = 0; i < b.size; ++i){ if (char_to_upper(a.str[i]) != char_to_upper(b.str[i])){ return 0; @@ -432,9 +437,9 @@ match_insensitive(String a, String b){ return 1; } -FSTRING_LINK bool -match_part_insensitive(char *a, char *b, int *len){ - int i; +FSTRING_LINK fstr_bool +match_part_insensitive(char *a, char *b, int32_t *len){ + int32_t i; for (i = 0; b[i] != 0; ++i){ if (char_to_upper(a[i]) != char_to_upper(b[i])){ return 0; @@ -444,9 +449,9 @@ match_part_insensitive(char *a, char *b, int *len){ return 1; } -FSTRING_LINK bool -match_part_insensitive(String a, char *b, int *len){ - int i; +FSTRING_LINK fstr_bool +match_part_insensitive(String a, char *b, int32_t *len){ + int32_t i; for (i = 0; b[i] != 0; ++i){ if (char_to_upper(a.str[i]) != char_to_upper(b[i]) || i == a.size){ @@ -457,9 +462,9 @@ match_part_insensitive(String a, char *b, int *len){ return 1; } -FSTRING_LINK bool +FSTRING_LINK fstr_bool match_part_insensitive(char *a, String b){ - for (int i = 0; i != b.size; ++i){ + for (int32_t i = 0; i != b.size; ++i){ if (char_to_upper(a[i]) != char_to_upper(b.str[i])){ return 0; } @@ -467,12 +472,12 @@ match_part_insensitive(char *a, String b){ return 1; } -FSTRING_LINK bool +FSTRING_LINK fstr_bool match_part_insensitive(String a, String b){ if (a.size < b.size){ return 0; } - for (int i = 0; i < b.size; ++i){ + for (int32_t i = 0; i < b.size; ++i){ if (char_to_upper(a.str[i]) != char_to_upper(b.str[i])){ return 0; } @@ -480,23 +485,23 @@ match_part_insensitive(String a, String b){ return 1; } -FSTRING_LINK int -find(char *str, int start, char character){ - int i = start; +FSTRING_LINK int32_t +find(char *str, int32_t start, char character){ + int32_t i = start; while (str[i] != character && str[i] != 0) ++i; return i; } -FSTRING_LINK int -find(String str, int start, char character){ - int i = start; +FSTRING_LINK int32_t +find(String str, int32_t start, char character){ + int32_t i = start; while (i < str.size && str.str[i] != character) ++i; return i; } -FSTRING_LINK int -find(char *str, int start, char *characters){ - int i = start, j; +FSTRING_LINK int32_t +find(char *str, int32_t start, char *characters){ + int32_t i = start, j; while (str[i] != 0){ for (j = 0; characters[j]; ++j){ if (str[i] == characters[j]){ @@ -508,9 +513,9 @@ find(char *str, int start, char *characters){ return i; } -FSTRING_LINK int -find(String str, int start, char *characters){ - int i = start, j; +FSTRING_LINK int32_t +find(String str, int32_t start, char *characters){ + int32_t i = start, j; while (i < str.size){ for (j = 0; characters[j]; ++j){ if (str.str[i] == characters[j]){ @@ -522,10 +527,10 @@ find(String str, int start, char *characters){ return i; } -FSTRING_LINK int -find_substr(char *str, int start, String seek){ - int i, j, k; - bool hit; +FSTRING_LINK int32_t +find_substr(char *str, int32_t start, String seek){ + int32_t i, j, k; + fstr_bool hit; if (seek.size == 0){ return str_size(str); @@ -547,10 +552,10 @@ find_substr(char *str, int start, String seek){ return i; } -FSTRING_LINK int -find_substr(String str, int start, String seek){ - int stop_at, i, j, k; - bool hit; +FSTRING_LINK int32_t +find_substr(String str, int32_t start, String seek){ + int32_t stop_at, i, j, k; + fstr_bool hit; if (seek.size == 0){ return str.size; @@ -573,10 +578,10 @@ find_substr(String str, int start, String seek){ return str.size; } -FSTRING_LINK int -rfind_substr(String str, int start, String seek){ - int i, j, k; - bool hit; +FSTRING_LINK int32_t +rfind_substr(String str, int32_t start, String seek){ + int32_t i, j, k; + fstr_bool hit; if (seek.size == 0){ return -1; @@ -601,10 +606,10 @@ rfind_substr(String str, int start, String seek){ return -1; } -FSTRING_LINK int -find_substr_insensitive(char *str, int start, String seek){ - int i, j, k; - bool hit; +FSTRING_LINK int32_t +find_substr_insensitive(char *str, int32_t start, String seek){ + int32_t i, j, k; + fstr_bool hit; char a_upper, b_upper; if (seek.size == 0){ @@ -629,11 +634,11 @@ find_substr_insensitive(char *str, int start, String seek){ return i; } -FSTRING_LINK int -find_substr_insensitive(String str, int start, String seek){ - int i, j, k; - int stop_at; - bool hit; +FSTRING_LINK int32_t +find_substr_insensitive(String str, int32_t start, String seek){ + int32_t i, j, k; + int32_t stop_at; + fstr_bool hit; char a_upper, b_upper; if (seek.size == 0){ @@ -659,67 +664,27 @@ find_substr_insensitive(String str, int start, String seek){ return str.size; } -FSTRING_LINK int -int_to_str_size(int x){ - int size; +FSTRING_LINK int32_t +int_to_str_size(int32_t x){ + int32_t size = 1; if (x < 0){ - size = 0; + size = 2; } - else{ - size = 1; + x /= 10; + while (x != 0){ x /= 10; - while (x != 0){ - x /= 10; - ++size; - } + ++size; } - return size; + return(size); } -FSTRING_LINK int -int_to_str(int x, char *str){ - int size, i, j; - bool negative; - char temp; - - size = 0; - if (x == 0){ - str[0] = '0'; - str[1] = 0; - size = 1; - } - else{ - size = 0; - negative = 0; - if (x < 0){ - negative = 1; - x = -x; - str[size++] = '-'; - } - while (x != 0){ - i = x % 10; - x /= 10; - str[size++] = (char)('0' + i); - } - // NOTE(allen): Start i = 0 if not negative, start i = 1 if is negative - // because - should not be flipped if it is negative :) - for (i = negative, j = size-1; i < j; ++i, --j){ - temp = str[i]; - str[i] = str[j]; - str[j] = temp; - } - str[size] = 0; - } - return size; -} - -FSTRING_LINK bool -int_to_str(int x, String *dest){ - bool result = 1; +FSTRING_LINK fstr_bool +int_to_str(String *dest, int32_t x){ + fstr_bool result = 1; char *str = dest->str; - int memory_size = dest->memory_size; - int size, i, j; - bool negative; + int32_t memory_size = dest->memory_size; + int32_t size, i, j; + fstr_bool negative; if (x == 0){ str[0] = '0'; @@ -756,22 +721,87 @@ int_to_str(int x, String *dest){ dest->size = 0; } } - return result; + return(result); } -FSTRING_LINK bool -append_int_to_str(int x, String *dest){ +FSTRING_LINK fstr_bool +append_int_to_str(String *dest, int32_t x){ String last_part = tailstr(*dest); - bool result = int_to_str(x, &last_part); + fstr_bool result = int_to_str(&last_part, x); if (result){ dest->size += last_part.size; } - return result; + return(result); } -FSTRING_LINK int +FSTRING_LINK int32_t +u64_to_str_size(uint64_t x){ + int32_t size; + if (x < 0){ + size = 0; + } + else{ + size = 1; + x /= 10; + while (x != 0){ + x /= 10; + ++size; + } + } + return(size); +} + +FSTRING_LINK fstr_bool +u64_to_str(String *dest, uint64_t x){ + fstr_bool result = 1; + char *str = dest->str; + int32_t memory_size = dest->memory_size; + int32_t size, i, j; + + if (x == 0){ + str[0] = '0'; + dest->size = 1; + } + else{ + size = 0; + while (x != 0){ + if (size == memory_size){ + result = 0; + break; + } + i = x % 10; + x /= 10; + str[size++] = (char)('0' + i); + } + if (result){ + for (i = 0, j = size-1; i < j; ++i, --j){ + char temp = str[i]; + str[i] = str[j]; + str[j] = temp; + } + dest->size = size; + } + else{ + dest->size = 0; + } + } + return(result); +} + +FSTRING_LINK fstr_bool +append_u64_to_str(String *dest, uint64_t x){ + String last_part = tailstr(*dest); + fstr_bool result = u64_to_str(&last_part, x); + if (result){ + dest->size += last_part.size; + } + return(result); +} + + +FSTRING_LINK int32_t str_to_int(char *str){ - int x = 0; + int32_t x = 0; for (; *str; ++str){ if (*str >= '0' || *str <= '9'){ x *= 10; @@ -785,9 +815,9 @@ str_to_int(char *str){ return(x); } -FSTRING_LINK int +FSTRING_LINK int32_t str_to_int(String str){ - int x, i; + int32_t x, i; if (str.size == 0){ x = 0; } @@ -801,9 +831,9 @@ str_to_int(String str){ return x; } -FSTRING_LINK int +FSTRING_LINK int32_t hexchar_to_int(char c){ - int x; + int32_t x; if (c >= '0' && c <= '9'){ x = c-'0'; } @@ -817,14 +847,14 @@ hexchar_to_int(char c){ } FSTRING_LINK char -int_to_hexchar(int x){ +int_to_hexchar(int32_t x){ return (x<10)?((char)x+'0'):((char)x+'a'-10); } FSTRING_LINK unsigned int hexstr_to_int(String str){ - unsigned int x; - int i; + uint32_t x; + int32_t i; if (str.size == 0){ x = 0; } @@ -838,10 +868,10 @@ hexstr_to_int(String str){ return x; } -FSTRING_LINK bool -color_to_hexstr(unsigned int color, String *s){ - bool result = 0; - int i; +FSTRING_LINK fstr_bool +color_to_hexstr(uint32_t color, String *s){ + fstr_bool result = 0; + int32_t i; if (s->memory_size == 7 || s->memory_size == 8){ result = 1; @@ -865,10 +895,10 @@ color_to_hexstr(unsigned int color, String *s){ return(result); } -FSTRING_LINK bool -hexstr_to_color(String s, unsigned int *out){ - bool result = 0; - unsigned int color = 0; +FSTRING_LINK fstr_bool +hexstr_to_color(String s, uint32_t *out){ + fstr_bool result = 0; + uint32_t color = 0; if (s.size == 6){ result = 1; color = (unsigned int)hexstr_to_int(s); @@ -883,7 +913,7 @@ hexstr_to_color(String s, unsigned int *out){ return(result); } -FSTRING_LINK int +FSTRING_LINK int32_t copy_fast_unsafe(char *dest, char *src){ char *start = dest; while (*src != 0){ @@ -896,17 +926,17 @@ copy_fast_unsafe(char *dest, char *src){ FSTRING_LINK void copy_fast_unsafe(char *dest, String src){ - int i = 0; + int32_t i = 0; while (i != src.size){ dest[i] = src.str[i]; ++i; } } -FSTRING_LINK bool +FSTRING_LINK fstr_bool copy_checked(String *dest, String src){ char *dest_str; - int i; + int32_t i; if (dest->memory_size < src.size){ return 0; } @@ -918,10 +948,10 @@ copy_checked(String *dest, String src){ return 1; } -FSTRING_LINK bool +FSTRING_LINK fstr_bool copy_partial(String *dest, char *src){ - int i = 0; - int memory_size = dest->memory_size; + int32_t i = 0; + int32_t memory_size = dest->memory_size; char *dest_str = dest->str; while (src[i] != 0){ if (i >= memory_size){ @@ -934,21 +964,21 @@ copy_partial(String *dest, char *src){ return 1; } -FSTRING_LINK bool +FSTRING_LINK fstr_bool copy_partial(String *dest, String src){ - bool result; - int memory_size = dest->memory_size; + fstr_bool result; + int32_t memory_size = dest->memory_size; char *dest_str = dest->str; if (memory_size < src.size){ result = 0; - for (int i = 0; i < memory_size; ++i){ + for (int32_t i = 0; i < memory_size; ++i){ dest_str[i] = src.str[i]; } dest->size = memory_size; } else{ result = 1; - for (int i = 0; i < src.size; ++i){ + for (int32_t i = 0; i < src.size; ++i){ dest_str[i] = src.str[i]; } dest->size = src.size; @@ -956,36 +986,36 @@ copy_partial(String *dest, String src){ return result; } -FSTRING_LINK bool +FSTRING_LINK fstr_bool append_checked(String *dest, String src){ String end; end = tailstr(*dest); - bool result = copy_checked(&end, src); + fstr_bool result = copy_checked(&end, src); // NOTE(allen): This depends on end.size still being 0 if // the check failed and no coppy occurred. dest->size += end.size; return result; } -FSTRING_LINK bool +FSTRING_LINK fstr_bool append_partial(String *dest, char *src){ String end = tailstr(*dest); - bool result = copy_partial(&end, src); + fstr_bool result = copy_partial(&end, src); dest->size += end.size; return result; } -FSTRING_LINK bool +FSTRING_LINK fstr_bool append_partial(String *dest, String src){ String end = tailstr(*dest); - bool result = copy_partial(&end, src); + fstr_bool result = copy_partial(&end, src); dest->size += end.size; return result; } -FSTRING_LINK bool +FSTRING_LINK fstr_bool append(String *dest, char c){ - bool result = 0; + fstr_bool result = 0; if (dest->size < dest->memory_size){ dest->str[dest->size++] = c; result = 1; @@ -993,18 +1023,18 @@ append(String *dest, char c){ return result; } -FSTRING_LINK int +FSTRING_LINK int32_t compare(char *a, char *b){ - int i = 0; + int32_t i = 0; while (a[i] == b[i] && a[i] != 0){ ++i; } return (a[i] > b[i]) - (a[i] < b[i]); } -FSTRING_LINK int +FSTRING_LINK int32_t compare(String a, char *b){ - int i = 0; + int32_t i = 0; while (i < a.size && a.str[i] == b[i]){ ++i; } @@ -1021,9 +1051,9 @@ compare(String a, char *b){ } } -FSTRING_LINK int +FSTRING_LINK int32_t compare(String a, String b){ - int i = 0; + int32_t i = 0; while (i < a.size && i < b.size && a.str[i] == b.str[i]){ ++i; } @@ -1035,25 +1065,25 @@ compare(String a, String b){ } } -FSTRING_LINK int -reverse_seek_slash(String str, int pos){ - int i = str.size - 1 - pos; +FSTRING_LINK int32_t +reverse_seek_slash(String str, int32_t pos){ + int32_t i = str.size - 1 - pos; while (i >= 0 && char_not_slash(str.str[i])){ --i; } return i; } -FSTRING_LINK int +FSTRING_LINK int32_t reverse_seek_slash(String str){ return(reverse_seek_slash(str, 0)); } -FSTRING_LINK bool +FSTRING_LINK fstr_bool set_last_folder(String *dir, char *folder_name, char slash){ char str[2]; - bool result = 0; - int size = reverse_seek_slash(*dir) + 1; + fstr_bool result = 0; + int32_t size = reverse_seek_slash(*dir) + 1; dir->size = size; str[0] = slash; str[1] = 0; @@ -1068,11 +1098,11 @@ set_last_folder(String *dir, char *folder_name, char slash){ return result; } -FSTRING_LINK bool +FSTRING_LINK fstr_bool set_last_folder(String *dir, String folder_name, char slash){ char str[2]; - bool result = 0; - int size = reverse_seek_slash(*dir) + 1; + fstr_bool result = 0; + int32_t size = reverse_seek_slash(*dir) + 1; dir->size = size; str[0] = slash; str[1] = 0; @@ -1089,7 +1119,7 @@ set_last_folder(String *dir, String folder_name, char slash){ FSTRING_LINK String file_extension(String str){ - int i; + int32_t i; for (i = str.size - 1; i >= 0; --i){ if (str.str[i] == '.') break; } @@ -1099,7 +1129,7 @@ file_extension(String str){ FSTRING_LINK String file_extension_slowly(char *str){ - int s, i; + int32_t s, i; for (s = 0; str[s]; ++s); for (i = s - 1; i >= 0; --i){ if (str[i] == '.') break; @@ -1110,7 +1140,7 @@ file_extension_slowly(char *str){ FSTRING_LINK char* file_extension_c(String str){ - int i; + int32_t i; for (i = str.size - 1; i >= 0; --i){ if (str.str[i] == '.') break; } @@ -1118,10 +1148,10 @@ file_extension_c(String str){ return str.str+i; } -FSTRING_LINK bool +FSTRING_LINK fstr_bool remove_last_folder(String *str){ - bool result = 0; - int end = reverse_seek_slash(*str, 1); + fstr_bool result = 0; + int32_t end = reverse_seek_slash(*str, 1); if (end >= 0){ result = 1; str->size = end + 1; @@ -1132,7 +1162,7 @@ remove_last_folder(String *str){ FSTRING_LINK void replace_char(String str, char replace, char with){ char *s = str.str; - int i; + int32_t i; for (i = 0; i < str.size; ++i, ++s){ if (*s == replace) *s = with; @@ -1155,27 +1185,27 @@ replace_char(char *str, char replace, char with){ struct Absolutes{ String a[8]; - int count; + int32_t count; }; FSTRING_LINK void -get_absolutes(String name, Absolutes *absolutes, bool implicit_first, bool implicit_last){ - int count = 0; - int max = ArrayCount(absolutes->a) - 1; +get_absolutes(String name, Absolutes *absolutes, fstr_bool implicit_first, fstr_bool implicit_last){ + int32_t count = 0; + int32_t max = ArrayCount(absolutes->a) - 1; if (implicit_last) --max; String str; str.str = name.str; str.size = 0; str.memory_size = 0; - bool prev_was_wild = 0; + fstr_bool prev_was_wild = 0; if (implicit_first){ absolutes->a[count++] = str; prev_was_wild = 1; } - int i; + int32_t i; for (i = 0; i < name.size; ++i){ if (name.str[i] == '*' && count < max){ if (!prev_was_wild){ @@ -1204,13 +1234,13 @@ get_absolutes(String name, Absolutes *absolutes, bool implicit_first, bool impli absolutes->count = count; } -FSTRING_LINK bool -wildcard_match(Absolutes *absolutes, char *x, int case_sensitive){ - bool r = 1; +FSTRING_LINK fstr_bool +wildcard_match(Absolutes *absolutes, char *x, int32_t case_sensitive){ + fstr_bool r = 1; String *a = absolutes->a; - bool (*match_func)(char*, String); - bool (*match_part_func)(char*, String); + fstr_bool (*match_func)(char*, String); + fstr_bool (*match_part_func)(char*, String); if (case_sensitive){ match_func = match; @@ -1262,8 +1292,8 @@ wildcard_match(Absolutes *absolutes, char *x, int case_sensitive){ return r; } -FSTRING_LINK bool -wildcard_match(Absolutes *absolutes, String x, int case_sensitive){ +FSTRING_LINK fstr_bool +wildcard_match(Absolutes *absolutes, String x, int32_t case_sensitive){ terminate_with_null(&x); return wildcard_match(absolutes, x.str, case_sensitive); } diff --git a/4ed.cpp b/4ed.cpp index b5a2ddb8..3df9fd5b 100644 --- a/4ed.cpp +++ b/4ed.cpp @@ -2295,37 +2295,47 @@ internal void setup_command_table(){ #define SET(n) command_table[cmdid_##n] = command_##n SET(null); + SET(seek_left); SET(seek_right); + SET(center_view); + SET(word_complete); + SET(copy); SET(cut); SET(paste); SET(paste_next); + SET(undo); SET(redo); SET(history_backward); SET(history_forward); + SET(interactive_new); SET(interactive_open); SET(reopen); SET(save); - SET(change_active_panel); SET(interactive_switch_buffer); SET(interactive_kill_buffer); SET(kill_buffer); + SET(to_uppercase); SET(to_lowercase); + SET(toggle_line_wrap); SET(toggle_show_whitespace); + SET(clean_all_lines); + SET(auto_tab_range); SET(eol_dosify); SET(eol_nixify); - SET(auto_tab_range); + SET(open_panel_vsplit); SET(open_panel_hsplit); SET(close_panel); + SET(change_active_panel); SET(page_up); SET(page_down); @@ -3120,7 +3130,7 @@ update_cli_handle_with_file(System_Functions *system, Models *models, char str_space[256]; String str = make_fixed_width_string(str_space); append(&str, "exited with code "); - append_int_to_str(cli->exit, &str); + append_int_to_str(&str, cli->exit); output_file_append(system, models, file, str, cursor_at_end); result = -1; } @@ -3705,7 +3715,6 @@ App_Step_Sig(app_step){ View *view = 0, *active_view = 0; b32 active = 0; Input_Summary summary = {0}; - Input_Process_Result result = {0}; active_view = cmd->panel->view; used_panels = &models->layout.used_sentinel; @@ -3726,13 +3735,8 @@ App_Step_Sig(app_step){ if (result.consume_keys || result.consume_esc){ consume_input(&available_input, Input_Esc); } - } - - for (dll_items(panel, used_panels)){ - view = panel->view; if (view->changed_context_in_step == 0){ - Assert(view->current_scroll); active = (panel == cmd->panel); summary = (active)?(active_input):(dead_input); if (panel == mouse_panel && !input->mouse.out_of_window){ @@ -3740,15 +3744,15 @@ App_Step_Sig(app_step){ } GUI_Scroll_Vars *vars = view->current_scroll; - // TODO(allen): I feel like the scroll context should actually not - // be allowed to change in here at all. - result = do_step_file_view(system, view, panel->inner, active, - &summary, *vars, view->scroll_region); - if (result.is_animating){ + Input_Process_Result ip_result = + do_step_file_view(system, view, panel->inner, active, + &summary, *vars, view->scroll_region); + if (ip_result.is_animating){ app_result.animating = 1; } - *vars = result.vars; - view->scroll_region = result.region; + Assert(view->current_scroll == vars); + *vars = ip_result.vars; + view->scroll_region = ip_result.region; } } } diff --git a/4ed.h b/4ed.h index 47b66a5b..99b27cf3 100644 --- a/4ed.h +++ b/4ed.h @@ -54,6 +54,7 @@ get_single_key(Key_Summary *summary, i32 index){ struct Input_Summary{ Mouse_State mouse; Key_Summary keys; + f32 dt; }; struct Command_Line_Parameters{ diff --git a/4ed_app_models.h b/4ed_app_models.h index 0022ec49..40787d7e 100644 --- a/4ed_app_models.h +++ b/4ed_app_models.h @@ -23,6 +23,19 @@ struct App_Settings{ i32 font_size; }; +struct Debug_Input_Event{ + char key; + + b8 is_hold; + b8 is_ctrl; + b8 is_alt; + b8 is_shift; +}; + +struct Debug_Data{ + Debug_Input_Event input_events[16]; +}; + struct Models{ Mem_Options mem; App_Settings settings; @@ -64,6 +77,8 @@ struct Models{ Scroll_Rule_Function *scroll_rule; b32 keep_playing; + + Debug_Data debug; }; // BOTTOM diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index d13091ba..c313fa98 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -404,7 +404,7 @@ file_set_name(Working_Set *working_set, Editing_File *file, char *filename){ if (hit_conflict){ file->name.live_name.size = original_len; append(&file->name.live_name, " <"); - append_int_to_str(file_x, &file->name.live_name); + append_int_to_str(&file->name.live_name, file_x); append(&file->name.live_name, ">"); } } @@ -4428,24 +4428,24 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su case IInt_Sure_To_Kill: { i32 action = -1; - + String empty_str = {0}; String message = make_lit_string("There are unsaved changes, close anyway?"); - + gui_do_text_field(target, message, empty_str); - + id.id[0] = (u64)('y'); message = make_lit_string("(Y)es"); if (gui_do_fixed_option(target, id, message, 'y')){ action = 0; } - + id.id[0] = (u64)('n'); message = make_lit_string("(N)o"); if (gui_do_fixed_option(target, id, message, 'n')){ action = 1; } - + id.id[0] = (u64)('s'); message = make_lit_string("(S)ave and kill"); if (gui_do_fixed_option(target, id, message, 's')){ @@ -4468,8 +4468,99 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su case VUI_Debug: { - -}break; + view->current_scroll = &view->gui_scroll; + + // TODO(allen): + // - Incoming input + // - Memory info + // - Thread info + // - View inspection + // - Buffer inspection + // - Command maps inspection + + String empty_str = string_zero(); + char space[512]; + String string = make_fixed_width_string(space); + + // Time Watcher + { + string.size = 0; + u64 time = system->now_time_stamp(); + + append(&string, "last event time stamp: "); + append_u64_to_str(&string, time); + + gui_do_text_field(target, string, empty_str); + } + + // Incoming input + // - keeping track of where something get's consumed!? + // - convert mouse clicks into key coded events??!! + { + Debug_Data *debug = &view->persistent.models->debug; + + { + int mx = input.mouse.x; + int my = input.mouse.y; + + string.size = 0; + append(&string, "mouse: ("); + append_int_to_str(&string, mx); + append(&string, ","); + append_int_to_str(&string, my); + append(&string, ")"); + } + + gui_do_text_field(target, string, empty_str); + + Debug_Input_Event *input_event = debug->input_events; + for (i32 i = 0; + i < ArrayCount(debug->input_events); + ++i, ++input_event){ + string.size = 0; + + if (input_event->is_hold){ + append(&string, "hold: "); + } + else{ + append(&string, "press: "); + } + + if (input_event->is_ctrl){ + append(&string, "ctrl-"); + } + else{ + append(&string, " -"); + } + + if (input_event->is_alt){ + append(&string, "alt-"); + } + else{ + append(&string, " -"); + } + + if (input_event->is_shift){ + append(&string, "shift "); + } + else{ + append(&string, " "); + } + + if (input_event->key >= ' ' && input_event->key <= '~'){ + append(&string, make_string(&input_event->key, 1)); + } + else{ + String str; + str.str = global_key_name(input_event->key, &str.size); + str.memory_size = str.size + 1; + append(&string, str); + } + + gui_do_text_field(target, string, empty_str); + } + } + }break; } } } @@ -4748,7 +4839,7 @@ do_step_file_view(System_Functions *system, if (view->persistent.models->scroll_rule(scroll_vars.target_x, scroll_vars.target_y, &scroll_vars.scroll_x, &scroll_vars.scroll_y, - (view->persistent.id) + 1, is_new_target)){ + (view->persistent.id) + 1, is_new_target, user_input->dt)){ result.is_animating = 1; } @@ -5040,9 +5131,9 @@ draw_file_bar(Render_Target *target, View *view, Editing_File *file, i32_Rect re char line_number_space[30]; String line_number = make_fixed_width_string(line_number_space); append(&line_number, " L#"); - append_int_to_str(view->recent->cursor.line, &line_number); + append_int_to_str(&line_number, view->recent->cursor.line); append(&line_number, " C#"); - append_int_to_str(view->recent->cursor.character, &line_number); + append_int_to_str(&line_number, view->recent->cursor.character); intbar_draw_string(target, &bar, line_number, base_color); diff --git a/4ed_keycodes.h b/4ed_keycodes.h deleted file mode 100644 index c8d6b77f..00000000 --- a/4ed_keycodes.h +++ /dev/null @@ -1,30 +0,0 @@ -enum Key_Code{ -key_back = 1, -key_up = 2, -key_down = 3, -key_left = 4, -key_right = 5, -key_del = 6, -key_insert = 7, -key_home = 8, -key_end = 11, -key_page_up = 12, -key_page_down = 13, -key_esc = 14, -key_f1 = 127, -key_f2 = 128, -key_f3 = 129, -key_f4 = 130, -key_f5 = 131, -key_f6 = 132, -key_f7 = 133, -key_f8 = 134, -key_f9 = 135, -key_f10 = 136, -key_f11 = 137, -key_f12 = 138, -key_f13 = 139, -key_f14 = 140, -key_f15 = 141, -key_f15 = 142, -} diff --git a/4ed_metagen.cpp b/4ed_metagen.cpp index d052ce25..7c19fc36 100644 --- a/4ed_metagen.cpp +++ b/4ed_metagen.cpp @@ -125,7 +125,7 @@ char* generate_keycode_enum(){ file = fopen(filename, "wb"); fprintf(file, "enum Key_Code{\n"); count = ArrayCount(keys_that_need_codes); - for (i = 0; i < count;){ + for (i = 0; i < count; i){ if (strcmp(keys_that_need_codes[i], "f1") == 0 && code < 0x7F){ code = 0x7F; } @@ -134,11 +134,32 @@ char* generate_keycode_enum(){ case '\t': code++; break; case 0x20: code = 0x7F; break; default: - fprintf(file, " key_%s = %d,\n", keys_that_need_codes[i++], code++); + fprintf(file, "key_%s = %d,\n", keys_that_need_codes[i++], code++); break; } } fprintf(file, "};\n"); + + fprintf(file, + "static char*\n" + "global_key_name(int key_code, int *size){\n" + "char *result = 0;\n" + "switch(key_code){\n" + ); + for (i = 0; i < count; ++i){ + fprintf(file, + "case key_%s: result = \"%s\"; *size = sizeof(\"%s\")-1; break;\n", + keys_that_need_codes[i], + keys_that_need_codes[i], + keys_that_need_codes[i] + ); + } + fprintf(file, + "}\n" + "return(result);\n" + "}\n" + ); + fclose(file); return(filename); } diff --git a/power/4coder_casey.cpp b/power/4coder_casey.cpp index 6f36fd77..cbb0992c 100644 --- a/power/4coder_casey.cpp +++ b/power/4coder_casey.cpp @@ -1326,10 +1326,9 @@ struct Casey_Scroll_Velocity }; Casey_Scroll_Velocity casey_scroll_velocity_[16] = {0}; -Casey_Scroll_Velocity *casey_scroll_velocity = casey_scroll_velocity_; +Casey_Scroll_Velocity *casey_scroll_velocity = casey_scroll_velocity_ - 1; SCROLL_RULE_SIG(casey_smooth_scroll_rule){ - float dt = 1.0f/60.0f; // TODO(casey): Why do I not get the timestep here? Casey_Scroll_Velocity *velocity = casey_scroll_velocity + view_id; int result = 0; if(is_new_target)