- Coded around the absence of wordexp on some BSD systems.
This commit is contained in:
Paul Beckingham 2014-01-12 16:30:01 -05:00
parent 6018a174e0
commit 3e04ff5e44
5 changed files with 52 additions and 94 deletions

View file

@ -1,7 +1,7 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2006-2014, Paul Beckingham, Federico Hernandez.
// Copyright 2006 - 2014, Paul Beckingham, Federico Hernandez.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@ -75,65 +75,3 @@ bool Readline::interactiveMode (const std::istream& in)
}
////////////////////////////////////////////////////////////////////////////////
Wordexp::Wordexp (const std::string &str)
{
#ifdef HAVE_WORDEXP_H
std::string strCopy (str);
escapeSpecialChars(strCopy);
wordexp (strCopy.c_str (), &_p, 0);
#else
_input = str;
escapeSpecialChars(_input);
#endif
}
////////////////////////////////////////////////////////////////////////////////
Wordexp::~Wordexp ()
{
#ifdef HAVE_WORDEXP_H
wordfree (&_p);
#endif
}
////////////////////////////////////////////////////////////////////////////////
int Wordexp::argc ()
{
#ifdef HAVE_WORDEXP_H
return _p.we_wordc;
#else
return 1;
#endif
}
////////////////////////////////////////////////////////////////////////////////
char** Wordexp::argv ()
{
#ifdef HAVE_WORDEXP_H
return _p.we_wordv;
#else
return (char**)_input.c_str ();
#endif
}
////////////////////////////////////////////////////////////////////////////////
char* Wordexp::argv (int i)
{
#ifdef HAVE_WORDEXP_H
return _p.we_wordv[i];
#else
return (char*)_input.c_str ();
#endif
}
////////////////////////////////////////////////////////////////////////////////
void Wordexp::escapeSpecialChars(std::string& str)
{
size_t i = 0;
while ((i = str.find_first_of ("$*?!|&;<>(){}~#@", i)) != std::string::npos)
{
str.insert(i, 1, '\\');
i += 2;
}
}
////////////////////////////////////////////////////////////////////////////////