Skip to content

Commit

Permalink
Expanding ~ and variables in @include path
Browse files Browse the repository at this point in the history
  • Loading branch information
houmain committed Jul 28, 2024
1 parent 66d5dec commit 5162136
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ set(SOURCES_CONTROL
set(SOURCES_COMMON
src/common/Connection.cpp
src/common/Connection.h
src/common/expand_path.h
src/common/Filter.h
src/common/Host.cpp
src/common/Host.h
Expand Down
23 changes: 23 additions & 0 deletions src/common/expand_path.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <string>

#if !defined(_WIN32)

#include <wordexp.h>

inline std::string expand_path(std::string string) {
auto exp_result = wordexp_t{ };
wordexp(string.c_str(), &exp_result, 0);
string = exp_result.we_wordv[0];
wordfree(&exp_result);
return string;
}

#else // !_WIN32

inline std::string expand_path(std::string string) {
return string;
}

#endif // !_WIN32
3 changes: 2 additions & 1 deletion src/config/ParseConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "string_iteration.h"
#include "runtime/Key.h"
#include "common/parse_regex.h"
#include "common/expand_path.h"
#include <cassert>
#include <cctype>
#include <istream>
Expand Down Expand Up @@ -260,7 +261,7 @@ void ParseConfig::parse_directive(It* it, const It end) {
const auto ident = read_ident(it, end);
skip_space_and_comments(it, end);
if (ident == "include") {
const auto filename = read_value(it, end);
const auto filename = expand_path(read_value(it, end));
auto is = std::ifstream(filename);
if (!is.good())
error("Opening include file '" + filename + "' failed");
Expand Down

0 comments on commit 5162136

Please sign in to comment.