diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ctor.h | 2 | ||||
| -rw-r--r-- | src/tools.cc | 10 | ||||
| -rw-r--r-- | src/util.cc | 93 | ||||
| -rw-r--r-- | src/util.h | 3 | 
4 files changed, 102 insertions, 6 deletions
| @@ -191,7 +191,7 @@ using asm_flag = ctor::flag<ctor::asm_opt>;  using c_flags = std::vector<ctor::c_flag>;  using cxx_flags = std::vector<ctor::cxx_flag>; -using ld_flags= std::vector<ctor::ld_flag>; +using ld_flags = std::vector<ctor::ld_flag>;  using ar_flags = std::vector<ctor::ar_flag>;  using asm_flags = std::vector<ctor::asm_flag>; diff --git a/src/tools.cc b/src/tools.cc index f6cb437..dfabdff 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -441,7 +441,7 @@ std::vector<std::string> cxx_option(ctor::cxx_opt opt, const std::string& arg,  		}  		return {"-D" + arg};  	case ctor::cxx_opt::custom: -		return {arg}; +		return argsplit(arg);  	}  	std::cerr << "Unsupported compiler option.\n"; @@ -488,7 +488,7 @@ std::vector<std::string> c_option(ctor::c_opt opt, const std::string& arg,  		}  		return {"-D" + arg};  	case ctor::c_opt::custom: -		return {arg}; +		return argsplit(arg);  	}  	std::cerr << "Unsupported compiler option.\n"; @@ -521,7 +521,7 @@ std::vector<std::string> ld_option(ctor::ld_opt opt, const std::string& arg,  	case ctor::ld_opt::position_independent_executable:  		return {"-fPIE"};  	case ctor::ld_opt::custom: -		return {arg}; +		return argsplit(arg);  	}  	std::cerr << "Unsupported compiler option.\n"; @@ -542,7 +542,7 @@ std::vector<std::string> ar_option(ctor::ar_opt opt, const std::string& arg,  	case ctor::ar_opt::output:  		return {arg};  	case ctor::ar_opt::custom: -		return {arg}; +		return argsplit(arg);  	}  	std::cerr << "Unsupported compiler option.\n"; @@ -555,7 +555,7 @@ std::vector<std::string> asm_option(ctor::asm_opt opt, const std::string& arg,  	switch(opt)  	{  	case ctor::asm_opt::custom: -		return {arg}; +		return argsplit(arg);  	}  	std::cerr << "Unsupported compiler option.\n"; diff --git a/src/util.cc b/src/util.cc index dbd4c3c..6fc650a 100644 --- a/src/util.cc +++ b/src/util.cc @@ -6,6 +6,7 @@  #include <iostream>  #include <fstream>  #include <algorithm> +#include <sstream>  std::string to_lower(const std::string& str)  { @@ -184,3 +185,95 @@ std::string locate(const std::string& prog,  	return {};  } + +std::vector<std::string> argsplit(const std::string& str) +{ +	enum class state +	{ +		normal, +		in_quot, +		in_apotrophe, +	} state{state::normal}; +	bool esc{false}; + +	std::string token; +	std::vector<std::string> tokens; +	for(auto c : str) +	{ +		switch(state) +		{ +		case state::normal: +			if(esc) +			{ +				esc = false; +			} +			else +			{ +				if(c == ' ') +				{ +					tokens.push_back(token); +					token.clear(); +					continue; +				} +				if(c == '\\') +				{ +					esc = true; +				} +				if(c == '"') +				{ +					state = state::in_quot; +				} +				if(c == '\'') +				{ +					state = state::in_apotrophe; +				} +			} + +			token += c; +			break; +		case state::in_quot: +			if(esc) +			{ +				esc = false; +			} +			else +			{ +				if(c == '\\') +				{ +					esc = true; +				} +				if(c == '"') +				{ +					state = state::normal; +				} +			} + +			token += c; +			break; +		case state::in_apotrophe: +			if(esc) +			{ +				esc = false; +			} +			else +			{ +				if(c == '\\') +				{ +					esc = true; +				} +				if(c == '\'') +				{ +					state = state::normal; +				} +			} + +			token += c; +			break; +		} +	} +	if(!token.empty()) +	{ +		tokens.push_back(token); +	} +	return tokens; +} @@ -28,3 +28,6 @@ std::vector<std::string> get_paths(const std::string& path_env = std::getenv("PA  std::string locate(const std::string& app,                     const std::vector<std::string>& paths,                     const std::string& arch = {}); + +//! Splits string into tokens adhering to quotations " and ' +std::vector<std::string> argsplit(const std::string& str); | 
