|
5 | 5 | #include "core.hpp" |
6 | 6 | #include "dependency_iterator.hpp" |
7 | 7 | #include "platform.hpp" |
| 8 | +#include "runtime.hpp" |
| 9 | +#include "result.hpp" |
8 | 10 |
|
9 | 11 | Dependency_Iterator::Dependency_Iterator (const File_Mapping *_mapping) |
10 | 12 | : mapping { _mapping }, |
@@ -37,7 +39,9 @@ static const char* find_substring (const char *memory, size_t memory_size, const |
37 | 39 | return nullptr; |
38 | 40 | } |
39 | 41 |
|
40 | | -bool get_next_include_value (Dependency_Iterator *iterator, String *include) { |
| 42 | +Result<bool> get_next_include_value (Dependency_Iterator *iterator, String *include) { |
| 43 | + use(Status_Code); |
| 44 | + |
41 | 45 | auto cursor = iterator->cursor; |
42 | 46 | auto end = iterator->mapping->memory + iterator->mapping->size; |
43 | 47 |
|
@@ -82,14 +86,21 @@ bool get_next_include_value (Dependency_Iterator *iterator, String *include) { |
82 | 86 | auto end_of_safe_word = reinterpret_cast<const char *>(memchr(safe_word, '(', end - safe_word)); |
83 | 87 | if (end_of_safe_word == nullptr) return false; |
84 | 88 |
|
85 | | - auto safe_word_length = end_of_safe_word - safe_word; |
86 | | - auto raw_string_end_position = find_substring(end_of_safe_word, end - end_of_safe_word, safe_word, safe_word_length); |
87 | | - assert(*(raw_string_end_position - 1) == ')'); |
| 89 | + auto safe_word_length = end_of_safe_word - safe_word; |
| 90 | + char raw_string_closing_path[64] = { ')' }; |
| 91 | + copy_memory(raw_string_closing_path + 1, safe_word, safe_word_length); |
| 92 | + |
| 93 | + auto raw_string_closing_path_length = safe_word_length + 1; |
| 94 | + auto raw_string_end_position = find_substring(end_of_safe_word, end - end_of_safe_word, |
| 95 | + raw_string_closing_path, raw_string_closing_path_length); |
| 96 | + if ((raw_string_end_position == nullptr) || |
| 97 | + (raw_string_end_position[raw_string_closing_path_length] != '"')) { |
| 98 | + return Invalid_Value; // Unclosed string literal, TODO: report a proper error message |
| 99 | + } |
88 | 100 |
|
89 | | - auto position = raw_string_end_position + safe_word_length; |
90 | | - assert(*position == '"'); |
| 101 | + auto position = raw_string_end_position + safe_word_length + 1; |
91 | 102 |
|
92 | | - cursor = position + 1; |
| 103 | + cursor = position + 1; // closing " for a string literal |
93 | 104 |
|
94 | 105 | continue; |
95 | 106 | } |
|
0 commit comments