diff options
author | pommicket <pommicket@gmail.com> | 2022-01-01 18:44:55 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-01-01 18:44:55 -0500 |
commit | f167f2ffd5e5c61787ab02b2353c243c3b7876e8 (patch) | |
tree | 9c40a45fe008202dcd16a87e337e7a7fc187c660 | |
parent | ba337edceb8cb5cc32d1d5cf71437e8d885cf45f (diff) |
windows fixes
- mysterious carriage returns fixed?
- fixed c:/x opening separately from c:\x
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | buffer.c | 26 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | make.bat | 8 | ||||
-rw-r--r-- | util.c | 18 |
6 files changed, 41 insertions, 20 deletions
@@ -17,6 +17,7 @@ TAGS *.res *.zip *.a -pcre2-10.36 +pcre2* SDL2 *.deb +test.txt @@ -125,8 +125,8 @@ On Windows (64-bit), first you will need to install Microsoft Visual Studio, the Next you will need the SDL2 VC development libraries: https://www.libsdl.org/download-2.0.php Extract the zip, copy SDL2-2.x.y into the ted directory, and rename it to SDL2. Also copy SDL2\\lib\\x64\\SDL2.dll to the ted directory. -You will also need PCRE2. Download it here: https://ftp.pcre.org/pub/pcre/pcre2-10.36.zip, -unzip it, and put pcre2-10.36 in the same folder as ted. +You will also need PCRE2. Download it here: https://github.com/PhilipHazel/pcre2/releases, +unzip it, put pcre2-10.X in the same folder as ted, and rename it to pcre2. Then run `make.bat release`. To build the .msi file, you will need Visual Studio, as well as the @@ -672,6 +672,7 @@ static Status buffer_lines_set_min_capacity(TextBuffer *buffer, Line **lines, u3 } static void buffer_line_append_char(TextBuffer *buffer, Line *line, char32_t c) { + if (c == '\r') return; if (buffer_line_set_len(buffer, line, line->len + 1)) line->str[line->len-1] = c; } @@ -1343,16 +1344,28 @@ BufferPos buffer_insert_text_at_pos(TextBuffer *buffer, BufferPos pos, String32 BufferPos ret = {0,0}; return ret; } - + if (str.len == 0) { + // no text to insert + return pos; + } + + // create a copy of str. we need to do this to remove carriage returns and newlines in the case of line buffers + char32_t str_copy[256]; + if (str.len > arr_count(str_copy)) { + char32_t *new_str = buffer_calloc(buffer, str.len, sizeof *new_str); + memcpy(new_str, str.str, str.len * sizeof *str.str); + str.str = new_str; + } else { + memcpy(str_copy, str.str, str.len * sizeof *str.str); + str.str = str_copy; + } + if (buffer->is_line_buffer) { // remove all the newlines from str. str32_remove_all_instances_of_char(&str, '\n'); } + str32_remove_all_instances_of_char(&str, '\r'); - if (str.len == 0) { - // no text to insert - return pos; - } if (buffer->store_undo_events) { BufferEdit *last_edit = arr_lastp(buffer->undo_history); @@ -1434,6 +1447,9 @@ BufferPos buffer_insert_text_at_pos(TextBuffer *buffer, BufferPos pos, String32 buffer_lines_modified(buffer, pos.line, line_idx); BufferPos b = {.line = line_idx, .index = index}; + if (str.len > arr_count(str_copy)) { + free(str.str); + } return b; } @@ -23,7 +23,7 @@ no_warn_end #endif #define PCRE2_STATIC #define PCRE2_CODE_UNIT_WIDTH 32 -#include "pcre2-10.36/pcre2.h" +#include <pcre2.h> #include "unicode.h" #include "util.c" @@ -3,14 +3,14 @@ if _%VCVARS% == _ ( set VCVARS=1 call vcvarsall x64 ) -if not exist pcre2-32.lib ( - pushd pcre2-10.36 +if not exist pcre2-32-static.lib ( + pushd pcre2 cmake -D PCRE2_BUILD_PCRE2_8=OFF -D PCRE2_BUILD_TESTS=OFF -D PCRE2_BUILD_PCRE2_32=ON -D CMAKE_BUILD_TYPE=Release -D CMAKE_GENERATOR_PLATFORM=x64 -D PCRE2_STATIC=ON . cmake --build . --config Release popd - copy pcre2-10.36\Release\pcre2-32.lib + copy pcre2\Release\pcre2-32-static.lib ) -SET C_FLAGS=/nologo /W4 /MD /wd4200 /wd4204 /wd4221 /wd4706 /wd4214 /D_CRT_SECURE_NO_WARNINGS /I SDL2/include SDL2/lib/x64/SDL2main.lib SDL2/lib/x64/SDL2.lib pcre2-32.lib +SET C_FLAGS=/nologo /W4 /MD /wd4200 /wd4204 /wd4221 /wd4706 /wd4214 /D_CRT_SECURE_NO_WARNINGS /I SDL2/include /I pcre2 SDL2/lib/x64/SDL2main.lib SDL2/lib/x64/SDL2.lib pcre2-32-static.lib rc /nologo ted.rc if _%1 == _ ( cl main.c stb_truetype.c ted.res /DDEBUG /DEBUG /Zi %C_FLAGS% /Fe:ted @@ -265,20 +265,24 @@ static bool path_is_absolute(char const *path) { // assuming `dir` is an absolute path, returns the absolute path of `relpath`, relative to `dir`. static void path_full(char const *dir, char const *relpath, char *abspath, size_t abspath_size) { assert(abspath_size); + abspath[0] = '\0'; + if (path_is_absolute(relpath)) { if (strchr(ALL_PATH_SEPARATORS, relpath[0])) { // make sure that on windows, if dir's drive is C: the absolute path of \a is c:\a - abspath[0] = '\0'; strn_cat(abspath, abspath_size, dir, strcspn(dir, ALL_PATH_SEPARATORS)); - str_cat(abspath, abspath_size, relpath); } else { - str_cpy(abspath, abspath_size, relpath); + // copy drive component (e.g. set abspath to "C:") + size_t drive_len = strcspn(relpath, ALL_PATH_SEPARATORS); + strn_cat(abspath, abspath_size, relpath, drive_len); + relpath += drive_len; + if (*relpath) ++relpath; // move past separator } - return; + } else { + str_cpy(abspath, abspath_size, dir); } - str_cpy(abspath, abspath_size, dir); - - while (1) { + + while (*relpath) { size_t component_len = strcspn(relpath, ALL_PATH_SEPARATORS); char const *component_end = relpath + component_len; |