MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
sys.h
Go to the documentation of this file.
1#pragma once
2
3#include <filesystem>
4#include <optional>
5#include <string>
6
7#ifdef _WIN32
8# define MIM_WHICH "where"
9#else
10# define MIM_WHICH "which"
11#endif
12
13namespace mim {
14
15namespace fs = std::filesystem;
16
17namespace sys {
18
19/// Yields `std::nullopt` if an error occurred.
20/// The returned path is adjusted so `<parent>/mim` resolves to the default in-tree plugin directory when possible.
21std::optional<fs::path> path_to_libmim();
22
23/// Executes command @p cmd.
24/// @returns the output as string.
25std::string exec(std::string cmd);
26
27std::string find_cmd(std::string);
28
29/// Wraps `std::system` and makes the return value usable.
30int system(std::string);
31
32/// Wraps sys::system and puts `.exe` at the back (Windows) and `./` at the front (otherwise) of @p cmd.
33int run(std::string cmd, std::string args = {});
34
35/// Returns the @p path as `std::string` and escapes all whitespaces with backslash.
36std::string escape(const std::filesystem::path& path);
37
38} // namespace sys
39} // namespace mim
Definition sys.h:17
int run(std::string cmd, std::string args={})
Wraps sys::system and puts .exe at the back (Windows) and ./ at the front (otherwise) of cmd.
Definition sys.cpp:107
int system(std::string)
Wraps std::system and makes the return value usable.
Definition sys.cpp:101
std::string escape(const std::filesystem::path &path)
Returns the path as std::string and escapes all whitespaces with backslash.
Definition sys.cpp:116
std::string find_cmd(std::string)
Definition sys.cpp:95
std::optional< fs::path > path_to_libmim()
Yields std::nullopt if an error occurred.
Definition sys.cpp:52
std::string exec(std::string cmd)
Executes command cmd.
Definition sys.cpp:83
Definition ast.h:14