| 820 | } |
| 821 | |
| 822 | static string path_source_handle_preprocessor(const string &preprocessor_line, |
| 823 | const string &source_filepath, |
| 824 | const size_t line_number, |
| 825 | SourceReplaceState *state) |
| 826 | { |
| 827 | string result = preprocessor_line; |
| 828 | |
| 829 | string rest_of_line = string_strip(preprocessor_line.substr(1)); |
| 830 | |
| 831 | if (0 == strncmp(rest_of_line.c_str(), "include", 7)) { |
| 832 | rest_of_line = string_strip(rest_of_line.substr(8)); |
| 833 | if (rest_of_line[0] == '"') { |
| 834 | const size_t n_start = 1; |
| 835 | const size_t n_end = rest_of_line.find("\"", n_start); |
| 836 | const string filename = rest_of_line.substr(n_start, n_end - n_start); |
| 837 | |
| 838 | string filepath = path_join(state->base, filename); |
| 839 | if (!path_exists(filepath)) { |
| 840 | filepath = path_join(path_dirname(source_filepath), filename); |
| 841 | } |
| 842 | string text; |
| 843 | if (path_read_text(filepath, text)) { |
| 844 | text = path_source_replace_includes_recursive(text, filepath, state); |
| 845 | /* Use line directives for better error messages. */ |
| 846 | result = line_directive(*state, filepath, 1) + "\n" + text + "\n" + |
| 847 | line_directive(*state, source_filepath, line_number + 1); |
| 848 | } |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | return result; |
| 853 | } |
| 854 | |
| 855 | /* Our own little c preprocessor that replaces #includes with the file |
| 856 | * contents, to work around issue of OpenCL drivers not supporting |
no test coverage detected