summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.c27
-rw-r--r--main.c3
-rw-r--r--ted.c27
-rw-r--r--ted.h1
-rw-r--r--util.c31
5 files changed, 60 insertions, 29 deletions
diff --git a/build.c b/build.c
index 04c6250..e9d9ddc 100644
--- a/build.c
+++ b/build.c
@@ -7,20 +7,25 @@ static void build_clear(Ted *ted) {
}
static void build_start(Ted *ted) {
+ ted_save_all(ted);
+
// get rid of any old build errors
build_clear(ted);
bool cargo = false;
chdir(ted->cwd);
+ strcpy(ted->build_dir, ted->cwd);
if (fs_file_exists("Cargo.toml")) {
cargo = true;
} else if (fs_file_exists(".." PATH_SEPARATOR_STR "Cargo.toml")) {
chdir("..");
+ ted_full_path(ted, "..", ted->build_dir, sizeof ted->build_dir);
cargo = true;
} else if (fs_file_exists(".." PATH_SEPARATOR_STR ".." PATH_SEPARATOR_STR "Cargo.toml")) {
chdir(".." PATH_SEPARATOR_STR "..");
+ ted_full_path(ted, "../..", ted->build_dir, sizeof ted->build_dir);
cargo = true;
}
@@ -166,15 +171,31 @@ static void build_frame(Ted *ted, float x1, float y1, float x2, float y2) {
continue;
}
bool is_error = true;
- u32 i = 0;
char32_t *str = line->str; u32 len = line->len;
+ {
+ // rust errors look like:
+ // " --> file:line:column"
+ while (len > 0 && *str == ' ') {
+ --len;
+ ++str;
+ }
+ if (len >= 4 && str[0] == '-' && str[1] == '-' && str[2] == '>' && str[3] == ' ') {
+ str += 4;
+ len -= 4;
+ }
+ }
// we have something like main.c:5
+ u32 i = 0;
// get file name
while (i < len) {
if (str[i] == ':') break;
- if (!is32_alnum(str[i]) && str[i] != '/' && str[i] != '.' && str[i] != '\\') {
+ // make sure that the start of the line is a file name
+ char const *allowed_ascii_symbols_in_path = "./\\-_";
+ bool is_path = str[i] > CHAR_MAX || isalnum((char)str[i])
+ || strchr(allowed_ascii_symbols_in_path, (char)str[i]);
+ if (!is_path) {
is_error = false;
break;
}
@@ -234,7 +255,7 @@ static void build_frame(Ted *ted, float x1, float y1, float x2, float y2) {
char *filename = str32_to_utf8_cstr(str32(str, filename_len));
if (filename) {
char full_path[TED_PATH_MAX];
- ted_full_path(ted, filename, full_path, sizeof full_path);
+ path_full(ted->build_dir, filename, full_path, sizeof full_path);
BuildError error = {
.filename = str_dup(full_path),
.pos = {.line = (u32)line_number, .index = (u32)column},
diff --git a/main.c b/main.c
index 09009f5..98d0f3a 100644
--- a/main.c
+++ b/main.c
@@ -556,6 +556,9 @@ int main(int argc, char **argv) {
Font *font = ted->font;
+ // default window title
+ strcpy(ted->window_title, "ted");
+
if (ted->active_node) {
float const padding = settings->padding;
float x1 = padding, y = window_height-padding, x2 = window_width-padding;
diff --git a/ted.c b/ted.c
index 94505df..b6e100c 100644
--- a/ted.c
+++ b/ted.c
@@ -264,30 +264,5 @@ static bool ted_save_all(Ted *ted) {
}
static void ted_full_path(Ted *ted, char const *relpath, char *abspath, size_t abspath_size) {
- str_cpy(abspath, abspath_size, ted->cwd);
-
- while (1) {
- size_t component_len = strcspn(relpath, ALL_PATH_SEPARATORS);
- char const *component_end = relpath + component_len;
-
- size_t len = strlen(abspath);
- if (abspath[len - 1] != PATH_SEPARATOR)
- str_cat(abspath, abspath_size, PATH_SEPARATOR_STR);
- if (component_len == 1 && relpath[0] == '.') {
- // ., do nothing
- } else if (component_len == 2 && relpath[0] == '.' && relpath[1] == '.') {
- // ..
- char *lastsep = strrchr(abspath, PATH_SEPARATOR);
- if (lastsep == abspath)
- lastsep[1] = '\0';
- else
- lastsep[0] = '\0';
- } else {
- strn_cat(abspath, abspath_size, relpath, component_len);
- }
- if (*component_end == 0)
- break;
- else
- relpath = component_end + 1;
- }
+ path_full(ted->cwd, relpath, abspath, abspath_size);
}
diff --git a/ted.h b/ted.h
index ad94ab8..9b839c2 100644
--- a/ted.h
+++ b/ted.h
@@ -268,6 +268,7 @@ typedef struct Ted {
char global_data_dir[TED_PATH_MAX];
char home[TED_PATH_MAX];
char cwd[TED_PATH_MAX]; // current working directory
+ char build_dir[TED_PATH_MAX]; // directory where we run the build command
bool nodes_used[TED_MAX_NODES];
Node nodes[TED_MAX_NODES];
bool buffers_used[TED_MAX_BUFFERS];
diff --git a/util.c b/util.c
index 0e07b25..24c6971 100644
--- a/util.c
+++ b/util.c
@@ -243,3 +243,34 @@ static bool path_is_absolute(char const *path) {
#endif
;
}
+
+// 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) {
+ str_cpy(abspath, abspath_size, dir);
+
+ while (1) {
+ size_t component_len = strcspn(relpath, ALL_PATH_SEPARATORS);
+ char const *component_end = relpath + component_len;
+
+ size_t len = strlen(abspath);
+ if (component_len == 1 && relpath[0] == '.') {
+ // ., do nothing
+ } else if (component_len == 2 && relpath[0] == '.' && relpath[1] == '.') {
+ // ..
+ char *lastsep = strrchr(abspath, PATH_SEPARATOR);
+ if (lastsep == abspath)
+ lastsep[1] = '\0';
+ else
+ lastsep[0] = '\0';
+ } else {
+ if (abspath[len - 1] != PATH_SEPARATOR)
+ str_cat(abspath, abspath_size, PATH_SEPARATOR_STR);
+ strn_cat(abspath, abspath_size, relpath, component_len);
+ }
+ if (*component_end == 0)
+ break;
+ else
+ relpath = component_end + 1;
+ }
+}
+