Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f33cdc0e4 | |||
| afcc33329f |
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.15)
|
||||
project(ke C) # Specify C language explicitly
|
||||
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(KE_VERSION "1.3.0")
|
||||
set(KE_VERSION "1.3.1")
|
||||
|
||||
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wshadow -Werror -std=c99 -g")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DEFAULT_SOURCE -D_XOPEN_SOURCE")
|
||||
|
||||
58
main.c
58
main.c
@@ -480,7 +480,7 @@ erow_init(struct erow *row, int len)
|
||||
row->rsize = 0;
|
||||
row->render = NULL;
|
||||
row->line = NULL;
|
||||
row->cap = cap_growth(0, len);
|
||||
row->cap = cap_growth(0, len)+1; /* extra byte for NUL end */
|
||||
|
||||
row->line = malloc(row->cap);
|
||||
assert(row->line != NULL);
|
||||
@@ -818,6 +818,9 @@ delete_region(void)
|
||||
deletech(KILLRING_NO_OP);
|
||||
killed++;
|
||||
}
|
||||
|
||||
editor.kill = 1;
|
||||
editor_set_status("Region killed.");
|
||||
}
|
||||
|
||||
|
||||
@@ -1708,9 +1711,56 @@ newline(void)
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
get_cloc_code_lines(const char* filename)
|
||||
{
|
||||
// Build the shell command dynamically
|
||||
char command[512];
|
||||
snprintf(command,
|
||||
sizeof(command),
|
||||
"cloc --quiet %s | tail -2 | head -1 | awk '{print $5}'",
|
||||
filename);
|
||||
|
||||
// Open a pipe to run the command
|
||||
FILE *pipe = popen(command, "r");
|
||||
if (!pipe) {
|
||||
return NULL; // Error opening pipe
|
||||
}
|
||||
|
||||
// Read the output (single line/number)
|
||||
char buffer[256];
|
||||
if (fgets(buffer, sizeof(buffer), pipe) != NULL) {
|
||||
// Remove trailing newline
|
||||
size_t len = strlen(buffer);
|
||||
if (len > 0 && buffer[len - 1] == '\n') {
|
||||
buffer[len - 1] = '\0';
|
||||
}
|
||||
|
||||
// Allocate and copy the string
|
||||
char *result = malloc(strlen(buffer) + 1);
|
||||
if (result) {
|
||||
strcpy(result, buffer);
|
||||
pclose(pipe);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// On error or empty output, return "0"
|
||||
pclose(pipe);
|
||||
char *zero = malloc(2);
|
||||
if (zero) {
|
||||
strcpy(zero, "0");
|
||||
return zero;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
process_kcommand(int16_t c)
|
||||
{
|
||||
char *buf = NULL;
|
||||
|
||||
switch (c) {
|
||||
case ' ':
|
||||
toggle_markset();
|
||||
@@ -1773,6 +1823,12 @@ process_kcommand(int16_t c)
|
||||
case 'f':
|
||||
editor_find();
|
||||
break;
|
||||
case 'l':
|
||||
buf = get_cloc_code_lines(editor.filename);
|
||||
|
||||
editor_set_status("Lines of code: %s", buf);
|
||||
free(buf);
|
||||
break;
|
||||
case 'm':
|
||||
if (system("make") != 0) {
|
||||
editor_set_status(
|
||||
|
||||
Reference in New Issue
Block a user