lcpex rewrite - alpha

This commit is contained in:
phanes
2023-02-15 18:44:21 -05:00
parent bb85754dc0
commit 7ed6e13fa5
82 changed files with 4510 additions and 2592 deletions

View File

@@ -0,0 +1,24 @@
#include "string_expansion.h"
// convert a string to a char** representing our artificial argv to be consumed by execvp
char ** expand_env(const std::string& var, int flags )
{
std::vector<std::string> vars;
wordexp_t p;
if(!wordexp(var.c_str(), &p, flags))
{
if(p.we_wordc)
for(char** exp = p.we_wordv; *exp; ++exp)
vars.push_back(exp[0]);
wordfree(&p);
}
char ** arr = new char*[vars.size() + 1];
for(size_t i = 0; i < vars.size(); i++){
arr[i] = new char[vars[i].size() + 1];
strcpy(arr[i], vars[i].c_str());
}
arr[vars.size()] = (char * ) nullptr;
return arr;
}