summaryrefslogtreecommitdiff
path: root/build.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-30 23:39:27 -0500
committerpommicket <pommicket@gmail.com>2022-12-30 23:39:27 -0500
commit25f6cd6f5ffb9ff34d9e22c38e9d72cdadce2dc9 (patch)
tree7f731a4098bd08fb0a301b3dfad7159a1a589374 /build.c
parent43bd0763959ecd8f8a835d09190b55ba6fab7d67 (diff)
basic find usages
Diffstat (limited to 'build.c')
-rw-r--r--build.c156
1 files changed, 83 insertions, 73 deletions
diff --git a/build.c b/build.c
index 9c5ee7a..04a9488 100644
--- a/build.c
+++ b/build.c
@@ -61,12 +61,16 @@ static bool build_run_next_command_in_queue(Ted *ted) {
}
}
-// make sure you set ted->build_dir before running this!
-static void build_queue_finish(Ted *ted) {
+void build_setup_buffer(Ted *ted) {
// new empty build output buffer
TextBuffer *build_buffer = &ted->build_buffer;
buffer_new_file(build_buffer, NULL);
build_buffer->store_undo_events = false; // don't need undo events for build output buffer
+}
+
+// make sure you set ted->build_dir before running this!
+static void build_queue_finish(Ted *ted) {
+ build_setup_buffer(ted);
build_run_next_command_in_queue(ted); // run the first command
}
@@ -160,7 +164,82 @@ static bool is_source_path(char32_t c) {
|| strchr(allowed_ascii_symbols_in_path, (char)c);
}
-static void build_frame(Ted *ted, float x1, float y1, float x2, float y2) {
+// make sure you set ted->build_dir before running this!
+void build_check_for_errors(Ted *ted) {
+ TextBuffer *buffer = &ted->build_buffer;
+ arr_clear(ted->build_errors);
+ for (u32 line_idx = 0; line_idx < buffer->nlines; ++line_idx) {
+ Line *line = &buffer->lines[line_idx];
+ if (line->len < 3) {
+ continue;
+ }
+ bool is_error = true;
+ char32_t *p = line->str, *end = p + line->len;
+
+ {
+ // rust errors look like:
+ // " --> file:line:column"
+ while (p != end && *p == ' ') {
+ ++p;
+ }
+ if (end - p >= 4 && p[0] == '-' && p[1] == '-' && p[2] == '>' && p[3] == ' ') {
+ p += 4;
+ }
+ }
+
+ // check if we have something like main.c:5 or main.c(5)
+
+ // get file name
+ char32_t *filename_start = p;
+ while (p != end) {
+ if ((*p == ':' || *p == '(')
+ && p != line->str + 1) // don't catch "C:\thing\whatever.c" as "filename: C, line number: \thing\whatever.c"
+ break;
+ if (!is_source_path(*p)) {
+ is_error = false;
+ break;
+ }
+ ++p;
+ }
+ if (p == end) is_error = false;
+ u32 filename_len = (u32)(p - filename_start);
+ if (filename_len == 0) is_error = false;
+
+ if (is_error) {
+ ++p; // move past : or (
+ int line_number = parse_nonnegative_integer(&p, end);
+ if (p != end && line_number > 0) {
+ // it's an error
+ line_number -= 1; // line numbers in output start from 1.
+ int column_number = 0;
+ // check if there's a column number
+ if (*p == ':') {
+ ++p; // move past :
+ int num = parse_nonnegative_integer(&p, end);
+ if (num > 0) {
+ column_number = num - 1; // column numbers in output start from 1
+ }
+ }
+ char *filename = str32_to_utf8_cstr(str32(filename_start, filename_len));
+ if (filename) {
+ char full_path[TED_PATH_MAX];
+ 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_number},
+ .build_output_line = line_idx
+ };
+ arr_add(ted->build_errors, error);
+ }
+ }
+ }
+ }
+ // go to the first error (if there is one)
+ ted->build_error = 0;
+ build_go_to_error(ted);
+}
+
+void build_frame(Ted *ted, float x1, float y1, float x2, float y2) {
TextBuffer *buffer = &ted->build_buffer;
Process *process = &ted->build_process;
assert(ted->build_shown);
@@ -230,76 +309,7 @@ static void build_frame(Ted *ted, float x1, float y1, float x2, float y2) {
if (!build_run_next_command_in_queue(ted)) {
ted->building = false;
// done command queue; check for errors
- for (u32 line_idx = 0; line_idx < buffer->nlines; ++line_idx) {
- Line *line = &buffer->lines[line_idx];
- if (line->len < 3) {
- continue;
- }
- bool is_error = true;
- char32_t *p = line->str, *end = p + line->len;
-
- {
- // rust errors look like:
- // " --> file:line:column"
- while (p != end && *p == ' ') {
- ++p;
- }
- if (end - p >= 4 && p[0] == '-' && p[1] == '-' && p[2] == '>' && p[3] == ' ') {
- p += 4;
- }
- }
-
- // check if we have something like main.c:5 or main.c(5)
-
- // get file name
- char32_t *filename_start = p;
- while (p != end) {
- if ((*p == ':' || *p == '(')
- && p != line->str + 1) // don't catch "C:\thing\whatever.c" as "filename: C, line number: \thing\whatever.c"
- break;
- if (!is_source_path(*p)) {
- is_error = false;
- break;
- }
- ++p;
- }
- if (p == end) is_error = false;
- u32 filename_len = (u32)(p - filename_start);
- if (filename_len == 0) is_error = false;
-
- if (is_error) {
- ++p; // move past : or (
- int line_number = parse_nonnegative_integer(&p, end);
- if (p != end && line_number > 0) {
- // it's an error
- line_number -= 1; // line numbers in output start from 1.
- int column_number = 0;
- // check if there's a column number
- if (*p == ':') {
- ++p; // move past :
- int num = parse_nonnegative_integer(&p, end);
- if (num > 0) {
- column_number = num - 1; // column numbers in output start from 1
- }
- }
- char *filename = str32_to_utf8_cstr(str32(filename_start, filename_len));
- if (filename) {
- char full_path[TED_PATH_MAX];
- 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_number},
- .build_output_line = line_idx
- };
- arr_add(ted->build_errors, error);
- }
- }
- }
- }
-
- // go to the first error (if there is one)
- ted->build_error = 0;
- build_go_to_error(ted);
+ build_check_for_errors(ted);
}
}
buffer->view_only = true;