convert to CMake.

This commit is contained in:
2025-11-21 23:11:38 -08:00
parent a3a987f6c4
commit 7ab50da2af
2 changed files with 26 additions and 9 deletions

17
CMakeLists.txt Normal file
View File

@@ -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
)

18
main.c
View File

@@ -181,7 +181,7 @@ init_editor(void)
editor.rows = 0; editor.rows = 0;
if (get_winsz(&editor.rows, &editor.cols) == -1) { 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--; /* status bar */
editor.rows--; /* message line */ editor.rows--; /* message line */
@@ -225,9 +225,9 @@ reset_editor(void)
void void
ab_append(struct abuf *buf, const char *s, int len) ab_append(struct abuf *buf, const char *s, int len)
{ {
char *nc = buf->b; const int delta = (len < 0) ? 0 : len;
int delta = (len < 0) ? 0 : len; char *nc = buf->b;
int sz; int sz;
assert((delta <= 0 && buf->len < INT_MAX - delta)); assert((delta <= 0 && buf->len < INT_MAX - delta));
sz = buf->len + delta; sz = buf->len + delta;
@@ -425,14 +425,14 @@ erow_free(struct erow *row)
void void
die(const char *s) 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[2J", 4);
write(STDOUT_FILENO, "\x1b[H", 3); write(STDOUT_FILENO, "\x1b[H", 3);
perror(s); if (errno != 0) {
perror(s);
} else {
fprintf(stderr, "%s\n", s);
}
exit(1); exit(1);
} }