From 5a7ca9106a305555922ef78c2dd84ab8779c7718 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Sat, 30 Jan 2021 14:21:42 -0500 Subject: fixed warnings on GCC, fixed opening an absolute path, README --- LICENSE.txt | 24 ++++++++++++++++++++++++ Makefile | 2 +- README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ main.c | 7 +++++-- node.c | 2 +- ted.png | Bin 0 -> 81487 bytes ui.c | 6 +----- unicode.h | 18 +++++++++--------- util.c | 8 ++++++++ 9 files changed, 101 insertions(+), 18 deletions(-) create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 ted.png diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..68a49da --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/Makefile b/Makefile index 41bd8a5..cd60533 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ ALL_CFLAGS=$(CFLAGS) -Wall -Wextra -Wshadow -Wconversion -Wpedantic -pedantic -std=gnu11 \ - -Wno-unused-function -Wno-fixed-enum-extension -Wimplicit-fallthrough + -Wno-unused-function -Wno-fixed-enum-extension -Wimplicit-fallthrough -Wno-format-truncation -Wno-unknown-warning-option LIBS=-lSDL2 -lGL -ldl -lm DEBUG_CFLAGS=$(ALL_CFLAGS) -DDEBUG -O0 -g RELEASE_CFLAGS=$(ALL_CFLAGS) -O3 diff --git a/README.md b/README.md new file mode 100644 index 0000000..57fce19 --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +# ted + +A text editor. + +**ted is still very new, and there are almost certainly bugs. There are also definitely important features missing. I don't recommend using this as your main text editor yet.** + + + +To install `ted` on Linux, you will need: + +- A C compiler +- SDL2 +- The GL development libraries + +These can be installed on Ubuntu/Debian with: + +``` +sudo apt install gcc libsdl2-dev libgl-dev +``` + +Then run + +``` +sudo make install -j4 +``` + +There is no nice way of installing on Windows yet. + +## Why? + +There are a lot of text editors out there. ted doesn't do anything new. +But in the modern world of text editors running browsers internally, it can be nice to have +a simple editor that starts up practically instantaneously, and performs well on reasonably-sized files. + +## Supported features (more coming soon) + +- Multiple tabs, each with a different file +- Auto-indent +- Customization of (pretty much) all colours and keyboard commands. + +## Building from source + +On Linux, run `make`; on Windows, run `make.bat`. + +## License + +ted is in the public domain (see `LICENSE.txt`). + +## Reporting bugs + +You can report a bug by sending an email to `pommicket at pommicket.com`. + diff --git a/main.c b/main.c index 1709a97..8b68662 100644 --- a/main.c +++ b/main.c @@ -257,8 +257,11 @@ int main(int argc, char **argv) { char path[TED_PATH_MAX]; if (starting_filename) { // get full path to file - strbuf_printf(path, "%s%s%s", ted->cwd, ted->cwd[strlen(ted->cwd) - 1] == PATH_SEPARATOR ? "" : PATH_SEPARATOR_STR, - starting_filename); + if (!path_is_absolute(starting_filename)) + strbuf_printf(path, "%s%s%s", ted->cwd, ted->cwd[strlen(ted->cwd) - 1] == PATH_SEPARATOR ? "" : PATH_SEPARATOR_STR, + starting_filename); + else + strbuf_printf(path, "%s", starting_filename); } else { strbuf_printf(path, "Untitled"); } diff --git a/node.c b/node.c index a767c7a..f0e85e0 100644 --- a/node.c +++ b/node.c @@ -56,7 +56,7 @@ static bool node_tab_close(Ted *ted, Node *node, u16 index) { } else { u16 buffer_index = node->tabs[index]; // remove tab from array - memmove(&node->tabs[index], &node->tabs[index + 1], (ntabs - (index + 1)) * sizeof *node->tabs); + memmove(&node->tabs[index], &node->tabs[index + 1], (size_t)(ntabs - (index + 1)) * sizeof *node->tabs); arr_remove_last(node->tabs); ted_delete_buffer(ted, buffer_index); diff --git a/ted.png b/ted.png new file mode 100644 index 0000000..1f70e83 Binary files /dev/null and b/ted.png differ diff --git a/ui.c b/ui.c index 058f76b..26f56cd 100644 --- a/ui.c +++ b/ui.c @@ -186,11 +186,7 @@ static Status file_selector_cd_(Ted const *ted, FileSelector *fs, char const *pa char *const cwd = fs->cwd; if (path[0] == '\0') return true; - if (path[0] == PATH_SEPARATOR - #if _WIN32 - || path[1] == ':' && path[2] == PATH_SEPARATOR - #endif - ) { + if (path_is_absolute(path)) { // absolute path (e.g. /foo, c:\foo) // start out by replacing cwd with the start of the absolute path cwd[0] = '\0'; diff --git a/unicode.h b/unicode.h index cb4f2bc..53941d2 100644 --- a/unicode.h +++ b/unicode.h @@ -119,14 +119,14 @@ static size_t unicode_utf32_to_utf8(char *s, char32_t c32) { return 1; } else if (c32 <= 0x7FF) { // two bytes needed - *p++ = 0xC0 | (u8)(c32 >> 6); - *p = 0x80 | (u8)(c32 & 0x3F); + *p++ = (u8)(0xC0 | (c32 >> 6)); + *p = (u8)(0x80 | (c32 & 0x3F)); return 2; } else if (c32 <= 0x7FFF) { if (c32 < 0xD800 || c32 > 0xDFFF) { - *p++ = 0xE0 | (u8)( c32 >> 12); - *p++ = 0x80 | (u8)((c32 >> 6) & 0x3F); - *p = 0x80 | (u8)( c32 & 0x3F); + *p++ = (u8)(0xE0 | ( c32 >> 12)); + *p++ = (u8)(0x80 | ((c32 >> 6) & 0x3F)); + *p = (u8)(0x80 | ( c32 & 0x3F)); return 3; } else { // UTF-16 surrogate halves @@ -134,10 +134,10 @@ static size_t unicode_utf32_to_utf8(char *s, char32_t c32) { return (size_t)-1; } } else if (c32 <= 0x10FFFF) { - *p++ = 0xF0 | (u8)( c32 >> 18); - *p++ = 0x80 | (u8)((c32 >> 12) & 0x3F); - *p++ = 0x80 | (u8)((c32 >> 6) & 0x3F); - *p = 0x80 | (u8)( c32 & 0x3F); + *p++ = (u8)(0xF0 | ( c32 >> 18)); + *p++ = (u8)(0x80 | ((c32 >> 12) & 0x3F)); + *p++ = (u8)(0x80 | ((c32 >> 6) & 0x3F)); + *p = (u8)(0x80 | ( c32 & 0x3F)); return 4; } else { // code point too big diff --git a/util.c b/util.c index 7a970a2..ed0b178 100644 --- a/util.c +++ b/util.c @@ -217,3 +217,11 @@ static char const *path_filename(char const *path) { // (a relative path with no path separators) return path; } + +static bool path_is_absolute(char const *path) { + return path[0] == PATH_SEPARATOR + #if _WIN32 + || path[1] == ':' && path[2] == PATH_SEPARATOR + #endif + ; +} -- cgit v1.2.3