summaryrefslogtreecommitdiff
path: root/sc/includer.cpp
blob: 69d9b6abd477aba1195839860793dcf78536a51b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "includer.hpp"

#include <stdio.h>
#include <filesystem>

extern "C" {
#include "plat.h"
}

using IncludeResult = glslang::TShader::Includer::IncludeResult;

IncludeResult* Includer::includeSystem(
	const char* headerName,
	const char* includerName,
	size_t inclusionDepth
) {
	return 0;
}

extern bool rf(const char* n, char*& buf, size_t& size);

IncludeResult* Includer::includeLocal(
	const char* header_name,
	const char* includer_name,
	size_t inclusionDepth
) {
	char* src;
	size_t src_size;
	std::filesystem::path inc(includer_name);
	inc.remove_filename();
	inc /= header_name;
	auto hn = std::filesystem::absolute(inc).string();
	if (!rf(hn.c_str(), src, src_size)) {
		print_err("Failed to include %s\n", header_name);
		print_err("\tTried %s\n", hn.c_str());
		return 0;
	}
	return new IncludeResult(hn, src, src_size, 0);
}

void Includer::releaseInclude(IncludeResult* i) {
	delete i;
}