//
// aegis - project change supervisor
// Copyright (C) 2013 Peter Miller
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or (at
// your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program. If not, see .
//
#include
#include
#include
#include
#include
#include
#include
#include
void
exe(const char *cmd)
{
exe(cmd, 0);
}
void
exe(const char *cmd, const char *arg)
{
exe(cmd, arg, 0);
}
void
exe(const char *cmd, const char *arg1, const char *arg2)
{
std::vector args;
args.push_back(cmd);
if (arg1 && *arg1)
args.push_back(arg1);
if (arg2 && *arg2)
args.push_back(arg2);
for (;;)
{
switch (arglex_get_string())
{
case arglex_token_string:
args.push_back(arglex_value.alv_string);
continue;
default:
usage();
// NOTREACHED
case arglex_token_eoln:
break;
}
break;
}
{
nstring_accumulator acc;
acc.push_back(args[0].quote_shell());
for (size_t j = 1; j < args.size(); ++j)
{
acc.push_back(' ');
acc.push_back(args[j].quote_shell());
}
error_raw("%s", acc.mkstr().c_str());
}
unsigned argc = args.size();
char **argv = new char * [argc + 1];
argv[argc] = 0;
for (size_t j = 0; j < argc; ++j)
argv[j] = (char *)args[j].c_str();
execvp(cmd, argv);
nfatal("exec(%s, ...)", nstring(cmd).quote_c().c_str());
delete [] argv;
}
// vim: set ts=8 sw=4 et :