diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..d7e391f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.15) +project(ke C) # Specify C language explicitly + +set(CMAKE_C_STANDARD 99) +set(KE_VERSION "0.9.3") + +# Add executable +add_executable(ke main.c) + +# Define KE_VERSION for use in C code (e.g., #define KE_VERSION) +target_compile_definitions(ke PRIVATE KE_VERSION="${KE_VERSION}") + +# Set output properties +set_target_properties(ke PROPERTIES + FOLDER bin + RUNTIME_OUTPUT_DIRECTORY bin +) \ No newline at end of file diff --git a/main.c b/main.c index 300f18b..dc9fc4f 100644 --- a/main.c +++ b/main.c @@ -181,7 +181,7 @@ init_editor(void) editor.rows = 0; if (get_winsz(&editor.rows, &editor.cols) == -1) { - die("can't get window size"); + die("can't get window size - is this an interactive terminal?"); } editor.rows--; /* status bar */ editor.rows--; /* message line */ @@ -225,9 +225,9 @@ reset_editor(void) void ab_append(struct abuf *buf, const char *s, int len) { - char *nc = buf->b; - int delta = (len < 0) ? 0 : len; - int sz; + const int delta = (len < 0) ? 0 : len; + char *nc = buf->b; + int sz; assert((delta <= 0 && buf->len < INT_MAX - delta)); sz = buf->len + delta; @@ -425,14 +425,14 @@ erow_free(struct erow *row) void die(const char *s) { - /* - * NOTE(kyle): this is a duplication of the code in display.c - * but I would like to be able to import these files from there. - */ write(STDOUT_FILENO, "\x1b[2J", 4); write(STDOUT_FILENO, "\x1b[H", 3); - perror(s); + if (errno != 0) { + perror(s); + } else { + fprintf(stderr, "%s\n", s); + } exit(1); }