nix-build: Clean up a bit
This commit is contained in:
parent
1bffd83e1a
commit
821380c77b
|
@ -16,6 +16,9 @@ using std::stringstream;
|
||||||
|
|
||||||
extern char ** environ;
|
extern char ** environ;
|
||||||
|
|
||||||
|
/* Recreate the effect of the perl shellwords function, breaking up a
|
||||||
|
* string into arguments like a shell word, including escapes
|
||||||
|
*/
|
||||||
std::vector<string> shellwords(const string & s)
|
std::vector<string> shellwords(const string & s)
|
||||||
{
|
{
|
||||||
auto whitespace = std::regex("^(\\s+).*");
|
auto whitespace = std::regex("^(\\s+).*");
|
||||||
|
@ -101,15 +104,14 @@ int main(int argc, char ** argv)
|
||||||
if (runEnv && argc > 1 && !std::regex_search(argv[1], std::regex("nix-shell"))) {
|
if (runEnv && argc > 1 && !std::regex_search(argv[1], std::regex("nix-shell"))) {
|
||||||
script = argv[1];
|
script = argv[1];
|
||||||
if (access(script.c_str(), F_OK) == 0 && access(script.c_str(), X_OK) == 0) {
|
if (access(script.c_str(), F_OK) == 0 && access(script.c_str(), X_OK) == 0) {
|
||||||
auto SCRIPT = std::ifstream(script);
|
auto lines = tokenizeString<Strings>(readFile(script), "\n");
|
||||||
string first;
|
if (std::regex_search(lines.front(), std::regex("^#!"))) {
|
||||||
std::getline(SCRIPT, first);
|
lines.pop_front();
|
||||||
if (std::regex_search(first, std::regex("^#!"))) {
|
|
||||||
inShebang = true;
|
inShebang = true;
|
||||||
for (int i = 2; i < argc - 1; ++i)
|
for (int i = 2; i < argc - 1; ++i)
|
||||||
savedArgs.push_back(argv[i]);
|
savedArgs.push_back(argv[i]);
|
||||||
args = std::vector<string>{};
|
args = std::vector<string>{};
|
||||||
for (string line; std::getline(SCRIPT, line);) {
|
for (auto line : lines) {
|
||||||
line = chomp(line);
|
line = chomp(line);
|
||||||
std::smatch match;
|
std::smatch match;
|
||||||
if (std::regex_match(line, match, std::regex("^#!\\s*nix-shell (.*)$")))
|
if (std::regex_match(line, match, std::regex("^#!\\s*nix-shell (.*)$")))
|
||||||
|
@ -120,7 +122,7 @@ int main(int argc, char ** argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto n = decltype(args)::size_type{0}; n < args.size(); ++n) {
|
for (size_t n = 0; n < args.size(); ++n) {
|
||||||
auto arg = args[n];
|
auto arg = args[n];
|
||||||
|
|
||||||
if (arg == "--help") {
|
if (arg == "--help") {
|
||||||
|
|
Loading…
Reference in a new issue