Code Cleanup

- All objects now use the same convention for naming members.  The
  consistency is a good thing.
This commit is contained in:
Paul Beckingham 2011-08-25 21:54:28 -04:00
parent fb6dc5058f
commit dab06f8672
53 changed files with 1347 additions and 1349 deletions

View file

@ -300,13 +300,13 @@ void A3::rc_override (
rc = File (arg->_raw.substr (3));
home = rc;
std::string::size_type last_slash = rc.data.rfind ("/");
std::string::size_type last_slash = rc._data.rfind ("/");
if (last_slash != std::string::npos)
home = rc.data.substr (0, last_slash);
home = rc._data.substr (0, last_slash);
else
home = ".";
context.header ("Using alternate .taskrc file " + rc.data);
context.header ("Using alternate .taskrc file " + rc._data);
// Keep looping, because if there are multiple rc:file arguments, we
// want the last one to dominate.

View file

@ -135,17 +135,17 @@ static int api_task_set (lua_State* L)
////////////////////////////////////////////////////////////////////////////////
API::API ()
: L (NULL)
: _L (NULL)
{
}
////////////////////////////////////////////////////////////////////////////////
API::~API ()
{
if (L)
if (_L)
{
lua_close (L);
L = NULL;
lua_close (_L);
_L = NULL;
}
}
@ -153,16 +153,16 @@ API::~API ()
void API::initialize ()
{
// Initialize Lua.
L = lua_open ();
luaL_openlibs (L); // TODO Error handling
_L = lua_open ();
luaL_openlibs (_L); // TODO Error handling
// Register all the API functions in Lua global space.
lua_pushcfunction (L, api_task_header_message); lua_setglobal (L, "task_header_message");
lua_pushcfunction (L, api_task_footnote_message); lua_setglobal (L, "task_footnote_message");
lua_pushcfunction (L, api_task_debug_message); lua_setglobal (L, "task_debug_message");
lua_pushcfunction (L, api_task_exit); lua_setglobal (L, "task_exit");
lua_pushcfunction (L, api_task_get); lua_setglobal (L, "task_get");
lua_pushcfunction (L, api_task_set); lua_setglobal (L, "task_set");
lua_pushcfunction (_L, api_task_header_message); lua_setglobal (_L, "task_header_message");
lua_pushcfunction (_L, api_task_footnote_message); lua_setglobal (_L, "task_footnote_message");
lua_pushcfunction (_L, api_task_debug_message); lua_setglobal (_L, "task_debug_message");
lua_pushcfunction (_L, api_task_exit); lua_setglobal (_L, "task_exit");
lua_pushcfunction (_L, api_task_get); lua_setglobal (_L, "task_get");
lua_pushcfunction (_L, api_task_set); lua_setglobal (_L, "task_set");
}
////////////////////////////////////////////////////////////////////////////////
@ -173,26 +173,26 @@ bool API::callProgramHook (
loadFile (file);
// Get function.
lua_getglobal (L, function.c_str ());
if (!lua_isfunction (L, -1))
lua_getglobal (_L, function.c_str ());
if (!lua_isfunction (_L, -1))
{
lua_pop (L, 1);
lua_pop (_L, 1);
throw format (STRING_API_NOFUNC, function);
}
// Make call.
if (lua_pcall (L, 0, 2, 0) != 0)
throw format (STRING_API_ERROR_CALLING, function, lua_tostring (L, -1));
if (lua_pcall (_L, 0, 2, 0) != 0)
throw format (STRING_API_ERROR_CALLING, function, lua_tostring (_L, -1));
// Call successful - get return values.
if (!lua_isnumber (L, -2))
if (!lua_isnumber (_L, -2))
throw format (STRING_API_ERROR_FAIL, function);
if (!lua_isstring (L, -1) && !lua_isnil (L, -1))
if (!lua_isstring (_L, -1) && !lua_isnil (_L, -1))
throw format (STRING_API_ERROR_NORET, function);
int rc = lua_tointeger (L, -2);
const char* message = lua_tostring (L, -1);
int rc = lua_tointeger (_L, -2);
const char* message = lua_tostring (_L, -1);
if (rc == 0)
{
@ -205,7 +205,7 @@ bool API::callProgramHook (
throw std::string (message);
}
lua_pop (L, 1);
lua_pop (_L, 1);
return rc == 0 ? true : false;
}
@ -218,32 +218,32 @@ bool API::callTaskHook (
loadFile (file);
// Save the task for reference via the API.
current = task;
_current = task;
// Get function.
lua_getglobal (L, function.c_str ());
if (!lua_isfunction (L, -1))
lua_getglobal (_L, function.c_str ());
if (!lua_isfunction (_L, -1))
{
lua_pop (L, 1);
lua_pop (_L, 1);
throw format (STRING_API_NOFUNC, function);
}
// Prepare args.
lua_pushnumber (L, current.id);
lua_pushnumber (_L, _current.id);
// Make call.
if (lua_pcall (L, 1, 2, 0) != 0)
throw format (STRING_API_ERROR_CALLING, function, lua_tostring (L, -1));
if (lua_pcall (_L, 1, 2, 0) != 0)
throw format (STRING_API_ERROR_CALLING, function, lua_tostring (_L, -1));
// Call successful - get return values.
if (!lua_isnumber (L, -2))
if (!lua_isnumber (_L, -2))
throw format (STRING_API_ERROR_FAIL, function);
if (!lua_isstring (L, -1) && !lua_isnil (L, -1))
if (!lua_isstring (_L, -1) && !lua_isnil (_L, -1))
throw format (STRING_API_ERROR_NORET, function);
int rc = lua_tointeger (L, -2);
const char* message = lua_tostring (L, -1);
int rc = lua_tointeger (_L, -2);
const char* message = lua_tostring (_L, -1);
if (rc == 0)
{
@ -256,7 +256,7 @@ bool API::callTaskHook (
throw std::string (message);
}
lua_pop (L, 1);
lua_pop (_L, 1);
return rc == 0 ? true : false;
}
@ -264,14 +264,14 @@ bool API::callTaskHook (
void API::loadFile (const std::string& file)
{
// If the file is not loaded.
if (std::find (loaded.begin (), loaded.end (), file) == loaded.end ())
if (std::find (_loaded.begin (), _loaded.end (), file) == _loaded.end ())
{
// Load the file, if possible.
if (luaL_loadfile (L, file.c_str ()) || lua_pcall (L, 0, 0, 0))
throw format (STRING_API_ERROR, lua_tostring (L, -1));
if (luaL_loadfile (_L, file.c_str ()) || lua_pcall (_L, 0, 0, 0))
throw format (STRING_API_ERROR, lua_tostring (_L, -1));
// Mark this as loaded, so as to not bother again.
loaded.push_back (file);
// Mark this as _loaded, so as to not bother again.
_loaded.push_back (file);
}
}

View file

@ -58,12 +58,12 @@ private:
void loadFile (const std::string&);
public:
lua_State* L;
std::vector <std::string> loaded;
lua_State* _L;
std::vector <std::string> _loaded;
// Context for the API.
// std::vector <Task> all;
Task current;
Task _current;
// std::string& name;
// std::string& value;
};

View file

@ -110,74 +110,74 @@ static inline std::string& str_replace (
////////////////////////////////////////////////////////////////////////////////
Att::Att ()
: mName ("")
, mValue ("")
, mMod ("")
, mSense ("positive")
: _name ("")
, _value ("")
, _mod ("")
, _sense ("positive")
{
}
////////////////////////////////////////////////////////////////////////////////
Att::Att (const std::string& name, const std::string& mod, const std::string& value)
{
mName = name;
mValue = value;
mMod = mod;
mSense = "positive";
_name = name;
_value = value;
_mod = mod;
_sense = "positive";
}
////////////////////////////////////////////////////////////////////////////////
Att::Att (const std::string& name, const std::string& mod, const std::string& value,
const std::string& sense)
{
mName = name;
mValue = value;
mMod = mod;
mSense = sense;
_name = name;
_value = value;
_mod = mod;
_sense = sense;
}
////////////////////////////////////////////////////////////////////////////////
Att::Att (const std::string& name, const std::string& mod, int value)
{
mName = name;
_name = name;
std::stringstream s;
s << value;
mValue = s.str ();
_value = s.str ();
mMod = mod;
mSense = "positive";
_mod = mod;
_sense = "positive";
}
////////////////////////////////////////////////////////////////////////////////
Att::Att (const std::string& name, const std::string& value)
{
mName = name;
mValue = value;
mMod = "";
mSense = "positive";
_name = name;
_value = value;
_mod = "";
_sense = "positive";
}
////////////////////////////////////////////////////////////////////////////////
Att::Att (const std::string& name, int value)
{
mName = name;
_name = name;
std::stringstream s;
s << value;
mValue = s.str ();
_value = s.str ();
mMod = "";
mSense = "positive";
_mod = "";
_sense = "positive";
}
////////////////////////////////////////////////////////////////////////////////
Att::Att (const Att& other)
{
mName = other.mName;
mValue = other.mValue;
mMod = other.mMod;
mSense = other.mSense;
_name = other._name;
_value = other._value;
_mod = other._mod;
_sense = other._sense;
}
////////////////////////////////////////////////////////////////////////////////
@ -185,10 +185,10 @@ Att& Att::operator= (const Att& other)
{
if (this != &other)
{
mName = other.mName;
mValue = other.mValue;
mMod = other.mMod;
mSense = other.mSense;
_name = other._name;
_value = other._value;
_mod = other._mod;
_sense = other._sense;
}
return *this;
@ -197,10 +197,10 @@ Att& Att::operator= (const Att& other)
////////////////////////////////////////////////////////////////////////////////
bool Att::operator== (const Att& other) const
{
return mName == other.mName &&
mMod == other.mMod &&
mValue == other.mValue &&
mSense == other.mSense;
return _name == other._name &&
_mod == other._mod &&
_value == other._value &&
_sense == other._sense;
}
////////////////////////////////////////////////////////////////////////////////
@ -211,14 +211,14 @@ Att::~Att ()
////////////////////////////////////////////////////////////////////////////////
bool Att::logicSense (bool match) const
{
if (mSense == "positive")
if (_sense == "positive")
return match;
else if (mSense == "negative")
else if (_sense == "negative")
return ! match;
else
{
context.debug ("mSense: " + mSense);
throw ("unknown mSense " + mSense);
context.debug ("_sense: " + _sense);
throw ("unknown _sense " + _sense);
}
}
@ -534,14 +534,14 @@ void Att::parse (const std::string& input)
void Att::parse (Nibbler& n)
{
// Ensure a clean object first.
mName = "";
mValue = "";
mMod = "";
mSense = "positive";
_name = "";
_value = "";
_mod = "";
_sense = "positive";
if (n.getUntilOneOf (".:", mName))
if (n.getUntilOneOf (".:", _name))
{
if (mName.length () == 0)
if (_name.length () == 0)
throw std::string ("Missing attribute name"); // TODO i18n
if (n.skip ('.'))
@ -551,13 +551,13 @@ void Att::parse (Nibbler& n)
if (n.skip ('~'))
{
context.debug ("using negative logic");
mSense = "negative";
_sense = "negative";
}
if (n.getUntil (":", mod))
{
if (validMod (mod))
mMod = mod;
_mod = mod;
else
throw std::string ("The name '") + mod + "' is not a valid modifier."; // TODO i18n
}
@ -569,10 +569,10 @@ void Att::parse (Nibbler& n)
{
// Both quoted and unquoted Att's are accepted.
// Consider removing this for a stricter parse.
if (n.getQuoted ('"', mValue) ||
n.getUntilEOS (mValue))
if (n.getQuoted ('"', _value) ||
n.getUntilEOS (_value))
{
decode (mValue);
decode (_value);
}
}
else
@ -582,7 +582,7 @@ void Att::parse (Nibbler& n)
throw std::string ("Missing : after attribute name."); // TODO i18n
/* TODO This might be too slow to include. Test this assumption.
validNameValue (mName, mMod, mValue);
validNameValue (_name, _mod, _value);
*/
}
@ -592,13 +592,13 @@ std::string Att::composeF4 () const
{
std::string output = "";
if (mName != "" && mValue != "")
if (_name != "" && _value != "")
{
std::string value = mValue;
std::string value = _value;
encode (value);
enquote (value);
output += mName + ":" + value;
output += _name + ":" + value;
}
return output;
@ -610,37 +610,37 @@ void Att::mod (const std::string& input)
if (input != "" && !validMod (input))
throw std::string ("The name '") + input + "' is not a valid modifier."; // TODO i18n
mMod = input;
_mod = input;
}
////////////////////////////////////////////////////////////////////////////////
std::string Att::mod () const
{
return mMod;
return _mod;
}
////////////////////////////////////////////////////////////////////////////////
std::string Att::name () const
{
return mName;
return _name;
}
////////////////////////////////////////////////////////////////////////////////
void Att::name (const std::string& name)
{
mName = name;
_name = name;
}
////////////////////////////////////////////////////////////////////////////////
std::string Att::value () const
{
return mValue;
return _value;
}
////////////////////////////////////////////////////////////////////////////////
void Att::value (const std::string& value)
{
mValue = value;
_value = value;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -77,10 +77,10 @@ private:
void decode (std::string&) const;
private:
std::string mName;
std::string mValue;
std::string mMod;
std::string mSense;
std::string _name;
std::string _value;
std::string _mod;
std::string _sense;
};
#endif

View file

@ -62,24 +62,24 @@ static struct
////////////////////////////////////////////////////////////////////////////////
Color::Color ()
: value (0)
: _value (0)
{
}
////////////////////////////////////////////////////////////////////////////////
Color::Color (const Color& other)
{
value = other.value;
_value = other._value;
}
////////////////////////////////////////////////////////////////////////////////
Color::Color (unsigned int c)
: value (0)
: _value (0)
{
if (!(c & _COLOR_HASFG)) value &= ~_COLOR_FG;
if (!(c & _COLOR_HASBG)) value &= ~_COLOR_BG;
if (!(c & _COLOR_HASFG)) _value &= ~_COLOR_FG;
if (!(c & _COLOR_HASBG)) _value &= ~_COLOR_BG;
value = c & (_COLOR_256 | _COLOR_HASBG | _COLOR_HASFG |_COLOR_UNDERLINE |
_value = c & (_COLOR_256 | _COLOR_HASBG | _COLOR_HASFG |_COLOR_UNDERLINE |
_COLOR_INVERSE | _COLOR_BOLD | _COLOR_BRIGHT | _COLOR_BG |
_COLOR_FG);
}
@ -97,7 +97,7 @@ Color::Color (unsigned int c)
// colorN 0 <= N <= 255 fg 38;5;N bg 48;5;N
// rgbRGB 0 <= R,G,B <= 5 fg 38;5;16 + R*36 + G*6 + B bg 48;5;16 + R*36 + G*6 + B
Color::Color (const std::string& spec)
: value (0)
: _value (0)
{
// By converting underscores to spaces, we inherently support the old "on_red"
// style of specifying background colors. We consider underscores to be
@ -228,56 +228,56 @@ Color::Color (const std::string& spec)
}
// Now combine the fg and bg into a single color.
value = fg_value;
_value = fg_value;
blend (Color (bg_value));
}
////////////////////////////////////////////////////////////////////////////////
Color::Color (color_id fg)
: value (0)
: _value (0)
{
if (fg != Color::nocolor)
{
value |= _COLOR_HASFG;
value |= fg;
_value |= _COLOR_HASFG;
_value |= fg;
}
}
////////////////////////////////////////////////////////////////////////////////
Color::Color (color_id fg, color_id bg)
: value (0)
: _value (0)
{
if (bg != Color::nocolor)
{
value |= _COLOR_HASBG;
value |= (bg << 8);
_value |= _COLOR_HASBG;
_value |= (bg << 8);
}
if (fg != Color::nocolor)
{
value |= _COLOR_HASFG;
value |= fg;
_value |= _COLOR_HASFG;
_value |= fg;
}
}
////////////////////////////////////////////////////////////////////////////////
Color::Color (color_id fg, color_id bg, bool underline, bool bold, bool bright)
: value (0)
: _value (0)
{
value |= ((underline ? 1 : 0) << 18)
_value |= ((underline ? 1 : 0) << 18)
| ((bold ? 1 : 0) << 17)
| ((bright ? 1 : 0) << 16);
if (bg != Color::nocolor)
{
value |= _COLOR_HASBG;
value |= (bg << 8);
_value |= _COLOR_HASBG;
_value |= (bg << 8);
}
if (fg != Color::nocolor)
{
value |= _COLOR_HASFG;
value |= fg;
_value |= _COLOR_HASFG;
_value |= fg;
}
}
@ -290,7 +290,7 @@ Color::~Color ()
Color& Color::operator= (const Color& other)
{
if (this != &other)
value = other.value;
_value = other._value;
return *this;
}
@ -299,22 +299,22 @@ Color& Color::operator= (const Color& other)
Color::operator std::string () const
{
std::string description;
if (value & _COLOR_BOLD) description += "bold";
if (_value & _COLOR_BOLD) description += "bold";
if (value & _COLOR_UNDERLINE)
if (_value & _COLOR_UNDERLINE)
description += std::string (description.length () ? " " : "") + "underline";
if (value & _COLOR_INVERSE)
if (_value & _COLOR_INVERSE)
description += std::string (description.length () ? " " : "") + "inverse";
if (value & _COLOR_HASFG)
if (_value & _COLOR_HASFG)
description += std::string (description.length () ? " " : "") + fg ();
if (value & _COLOR_HASBG)
if (_value & _COLOR_HASBG)
{
description += std::string (description.length () ? " " : "") + "on";
if (value & _COLOR_BRIGHT)
if (_value & _COLOR_BRIGHT)
description += std::string (description.length () ? " " : "") + "bright";
description += " " + bg ();
@ -326,7 +326,7 @@ Color::operator std::string () const
////////////////////////////////////////////////////////////////////////////////
Color::operator int () const
{
return (int) value;
return (int) _value;
}
////////////////////////////////////////////////////////////////////////////////
@ -335,28 +335,28 @@ Color::operator int () const
void Color::blend (const Color& other)
{
Color c (other);
value |= (c.value & _COLOR_UNDERLINE); // Always inherit underline.
value |= (c.value & _COLOR_INVERSE); // Always inherit inverse.
_value |= (c._value & _COLOR_UNDERLINE); // Always inherit underline.
_value |= (c._value & _COLOR_INVERSE); // Always inherit inverse.
// 16 <-- 16.
if (!(value & _COLOR_256) &&
!(c.value & _COLOR_256))
if (!(_value & _COLOR_256) &&
!(c._value & _COLOR_256))
{
value |= (c.value & _COLOR_BOLD); // Inherit bold.
value |= (c.value & _COLOR_BRIGHT); // Inherit bright.
_value |= (c._value & _COLOR_BOLD); // Inherit bold.
_value |= (c._value & _COLOR_BRIGHT); // Inherit bright.
if (c.value & _COLOR_HASFG)
if (c._value & _COLOR_HASFG)
{
value |= _COLOR_HASFG; // There is now a color.
value &= ~_COLOR_FG; // Remove previous color.
value |= (c.value & _COLOR_FG); // Apply other color.
_value |= _COLOR_HASFG; // There is now a color.
_value &= ~_COLOR_FG; // Remove previous color.
_value |= (c._value & _COLOR_FG); // Apply other color.
}
if (c.value & _COLOR_HASBG)
if (c._value & _COLOR_HASBG)
{
value |= _COLOR_HASBG; // There is now a color.
value &= ~_COLOR_BG; // Remove previous color.
value |= (c.value & _COLOR_BG); // Apply other color.
_value |= _COLOR_HASBG; // There is now a color.
_value &= ~_COLOR_BG; // Remove previous color.
_value |= (c._value & _COLOR_BG); // Apply other color.
}
return;
@ -364,22 +364,22 @@ void Color::blend (const Color& other)
else
{
// Upgrade either color, if necessary.
if (!(value & _COLOR_256)) upgrade ();
if (!(c.value & _COLOR_256)) c.upgrade ();
if (!(_value & _COLOR_256)) upgrade ();
if (!(c._value & _COLOR_256)) c.upgrade ();
// 256 <-- 256.
if (c.value & _COLOR_HASFG)
if (c._value & _COLOR_HASFG)
{
value |= _COLOR_HASFG; // There is now a color.
value &= ~_COLOR_FG; // Remove previous color.
value |= (c.value & _COLOR_FG); // Apply other color.
_value |= _COLOR_HASFG; // There is now a color.
_value &= ~_COLOR_FG; // Remove previous color.
_value |= (c._value & _COLOR_FG); // Apply other color.
}
if (c.value & _COLOR_HASBG)
if (c._value & _COLOR_HASBG)
{
value |= _COLOR_HASBG; // There is now a color.
value &= ~_COLOR_BG; // Remove previous color.
value |= (c.value & _COLOR_BG); // Apply other color.
_value |= _COLOR_HASBG; // There is now a color.
_value &= ~_COLOR_BG; // Remove previous color.
_value |= (c._value & _COLOR_BG); // Apply other color.
}
}
}
@ -387,27 +387,27 @@ void Color::blend (const Color& other)
////////////////////////////////////////////////////////////////////////////////
void Color::upgrade ()
{
if (!(value & _COLOR_256))
if (!(_value & _COLOR_256))
{
if (value & _COLOR_HASFG)
if (_value & _COLOR_HASFG)
{
bool bold = value & _COLOR_BOLD;
unsigned int fg = value & _COLOR_FG;
value &= ~_COLOR_FG;
value &= ~_COLOR_BOLD;
value |= (bold ? fg + 7 : fg - 1);
bool bold = _value & _COLOR_BOLD;
unsigned int fg = _value & _COLOR_FG;
_value &= ~_COLOR_FG;
_value &= ~_COLOR_BOLD;
_value |= (bold ? fg + 7 : fg - 1);
}
if (value & _COLOR_HASBG)
if (_value & _COLOR_HASBG)
{
bool bright = value & _COLOR_BRIGHT;
unsigned int bg = (value & _COLOR_BG) >> 8;
value &= ~_COLOR_BG;
value &= ~_COLOR_BRIGHT;
value |= (bright ? bg + 7 : bg - 1) << 8;
bool bright = _value & _COLOR_BRIGHT;
unsigned int bg = (_value & _COLOR_BG) >> 8;
_value &= ~_COLOR_BG;
_value &= ~_COLOR_BRIGHT;
_value |= (bright ? bg + 7 : bg - 1) << 8;
}
value |= _COLOR_256;
_value |= _COLOR_256;
}
}
@ -425,38 +425,38 @@ void Color::upgrade ()
// 256 bg \033[48;5;Nm
std::string Color::colorize (const std::string& input)
{
if (value == 0)
if (_value == 0)
return input;
int count = 0;
std::stringstream result;
// 256 color
if (value & _COLOR_256)
if (_value & _COLOR_256)
{
bool needTerminator = false;
if (value & _COLOR_UNDERLINE)
if (_value & _COLOR_UNDERLINE)
{
result << "\033[4m";
needTerminator = true;
}
if (value & _COLOR_INVERSE)
if (_value & _COLOR_INVERSE)
{
result << "\033[7m";
needTerminator = true;
}
if (value & _COLOR_HASFG)
if (_value & _COLOR_HASFG)
{
result << "\033[38;5;" << (value & _COLOR_FG) << "m";
result << "\033[38;5;" << (_value & _COLOR_FG) << "m";
needTerminator = true;
}
if (value & _COLOR_HASBG)
if (_value & _COLOR_HASBG)
{
result << "\033[48;5;" << ((value & _COLOR_BG) >> 8) << "m";
result << "\033[48;5;" << ((_value & _COLOR_BG) >> 8) << "m";
needTerminator = true;
}
@ -468,38 +468,38 @@ std::string Color::colorize (const std::string& input)
}
// 16 color
if (value != 0)
if (_value != 0)
{
result << "\033[";
if (value & _COLOR_BOLD)
if (_value & _COLOR_BOLD)
{
if (count++) result << ";";
result << "1";
}
if (value & _COLOR_UNDERLINE)
if (_value & _COLOR_UNDERLINE)
{
if (count++) result << ";";
result << "4";
}
if (value & _COLOR_INVERSE)
if (_value & _COLOR_INVERSE)
{
if (count++) result << ";";
result << "7";
}
if (value & _COLOR_HASFG)
if (_value & _COLOR_HASFG)
{
if (count++) result << ";";
result << (29 + (value & _COLOR_FG));
result << (29 + (_value & _COLOR_FG));
}
if (value & _COLOR_HASBG)
if (_value & _COLOR_HASBG)
{
if (count++) result << ";";
result << ((value & _COLOR_BRIGHT ? 99 : 39) + ((value & _COLOR_BG) >> 8));
result << ((_value & _COLOR_BRIGHT ? 99 : 39) + ((_value & _COLOR_BG) >> 8));
}
result << "m" << input << "\033[0m";
@ -545,7 +545,7 @@ std::string Color::colorize (const std::string& input, const std::string& spec)
////////////////////////////////////////////////////////////////////////////////
bool Color::nontrivial ()
{
return value != 0 ? true : false;
return _value != 0 ? true : false;
}
////////////////////////////////////////////////////////////////////////////////
@ -561,14 +561,14 @@ int Color::find (const std::string& input)
////////////////////////////////////////////////////////////////////////////////
std::string Color::fg () const
{
int index = value & _COLOR_FG;
int index = _value & _COLOR_FG;
if (value & _COLOR_256)
if (_value & _COLOR_256)
{
if (value & _COLOR_HASFG)
if (_value & _COLOR_HASFG)
{
std::stringstream s;
s << "color" << (value & _COLOR_FG);
s << "color" << (_value & _COLOR_FG);
return s.str ();
}
}
@ -585,14 +585,14 @@ std::string Color::fg () const
////////////////////////////////////////////////////////////////////////////////
std::string Color::bg () const
{
int index = (value & _COLOR_BG) >> 8;
int index = (_value & _COLOR_BG) >> 8;
if (value & _COLOR_256)
if (_value & _COLOR_256)
{
if (value & _COLOR_HASBG)
if (_value & _COLOR_HASBG)
{
std::stringstream s;
s << "color" << ((value & _COLOR_BG) >> 8);
s << "color" << ((_value & _COLOR_BG) >> 8);
return s.str ();
}
}

View file

@ -73,7 +73,7 @@ private:
std::string bg () const;
private:
unsigned int value;
unsigned int _value;
};
#endif

View file

@ -50,7 +50,7 @@
// This string is used in two ways:
// 1) It is used to create a new .taskrc file, by copying it directly to disk.
// 2) It is parsed and used as default values for all Config.get calls.
std::string Config::defaults =
std::string Config::_defaults =
"# Taskwarrior program configuration file.\n"
"# For more documentation, see http://taskwarrior.org or try 'man task', 'man task-faq',\n"
"# 'man task-tutorial', 'man task-color', 'man task-sync' or 'man taskrc'\n"
@ -469,7 +469,7 @@ std::string Config::defaults =
//
// In all real use cases, Config::load is called.
Config::Config ()
: original_file ()
: _original_file ()
{
}
@ -499,7 +499,7 @@ void Config::load (const std::string& file, int nest /* = 1 */)
if (nest == 1)
{
setDefaults ();
original_file = File (file);
_original_file = File (file);
}
// Read the file, then parse the contents.
@ -554,10 +554,10 @@ void Config::parse (const std::string& input, int nest /* = 1 */)
if (included.readable ())
this->load (included, nest + 1);
else
throw format (STRING_CONFIG_READ_INCLUDE, included.data);
throw format (STRING_CONFIG_READ_INCLUDE, included._data);
}
else
throw format (STRING_CONFIG_INCLUDE_PATH, included.data);
throw format (STRING_CONFIG_INCLUDE_PATH, included._data);
}
else
throw format (STRING_CONFIG_BAD_ENTRY, line);
@ -570,7 +570,7 @@ void Config::parse (const std::string& input, int nest /* = 1 */)
void Config::createDefaultRC (const std::string& rc, const std::string& data)
{
// Override data.location in the defaults.
std::string::size_type loc = defaults.find ("data.location=~/.task");
std::string::size_type loc = _defaults.find ("data.location=~/.task");
// loc+0^ +14^ +21^
Date now;
@ -580,7 +580,7 @@ void Config::createDefaultRC (const std::string& rc, const std::string& data)
<< " "
<< now.toString ("m/d/Y H:N:S")
<< "]\n"
<< defaults.substr (0, loc + 14)
<< _defaults.substr (0, loc + 14)
<< data
<< "\n\n# Color theme (uncomment one to use)\n"
<< "#include /usr/local/share/doc/task/rc/light-16.theme\n"
@ -616,7 +616,7 @@ void Config::createDefaultData (const std::string& data)
////////////////////////////////////////////////////////////////////////////////
void Config::setDefaults ()
{
parse (defaults);
parse (_defaults);
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -64,10 +64,10 @@ public:
std::string checkForDeprecatedColumns ();
public:
File original_file;
File _original_file;
private:
static std::string defaults;
static std::string _defaults;
};
#endif

View file

@ -100,7 +100,7 @@ int Context::initialize (int argc, const char** argv)
std::string location;
a3.get_data_location (location);
data_dir = Directory (location);
extension_dir = data_dir.data + "/extensions";
extension_dir = data_dir._data + "/extensions";
// Create missing config file and data directory, if necessary.
createDefaultConfig ();
@ -398,7 +398,7 @@ void Context::shadow ()
/*
// Determine if shadow file is enabled.
File shadowFile (config.get ("shadow.file"));
if (shadowFile.data != "")
if (shadowFile._data != "")
{
inShadow = true; // Prevents recursion in case shadow command writes.
@ -436,21 +436,21 @@ void Context::shadow ()
// parse ();
std::string result;
(void)dispatch (result);
std::ofstream out (shadowFile.data.c_str ());
std::ofstream out (shadowFile._data.c_str ());
if (out.good ())
{
out << result;
out.close ();
}
else
throw std::string ("Could not write file '") + shadowFile.data + "'";
throw std::string ("Could not write file '") + shadowFile._data + "'";
config.set ("detection", oldDetection);
config.set ("color", oldColor);
// Optionally display a notification that the shadow file was updated.
if (config.getBoolean ("shadow.notify"))
footnote (std::string ("[Shadow file '") + shadowFile.data + "' updated.]");
footnote (std::string ("[Shadow file '") + shadowFile._data + "' updated.]");
inShadow = false;
}
@ -498,7 +498,7 @@ void Context::createDefaultConfig ()
// Do we need to create a default rc?
if (! rc_file.exists ())
{
if (!confirm (format (STRING_CONTEXT_CREATE_RC, home_dir, rc_file.data)))
if (!confirm (format (STRING_CONTEXT_CREATE_RC, home_dir, rc_file._data)))
throw std::string (STRING_CONTEXT_NEED_RC);
config.createDefaultRC (rc_file, data_dir);

View file

@ -86,13 +86,13 @@ extern Context context;
// Defaults to "now".
Date::Date ()
{
mT = time (NULL);
_t = time (NULL);
}
////////////////////////////////////////////////////////////////////////////////
Date::Date (const time_t t)
{
mT = t;
_t = t;
}
////////////////////////////////////////////////////////////////////////////////
@ -105,7 +105,7 @@ Date::Date (const int m, const int d, const int y)
t.tm_mon = m - 1;
t.tm_year = y - 1900;
mT = mktime (&t);
_t = mktime (&t);
}
////////////////////////////////////////////////////////////////////////////////
@ -122,7 +122,7 @@ Date::Date (const int m, const int d, const int y,
t.tm_min = mi;
t.tm_sec = se;
mT = mktime (&t);
_t = mktime (&t);
}
////////////////////////////////////////////////////////////////////////////////
@ -138,11 +138,11 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
// Parse an ISO date.
Nibbler n (input);
if (n.getDateISO (mT) && n.depleted ())
if (n.getDateISO (_t) && n.depleted ())
return;
// Parse a formatted date.
if (n.getDate (format, mT) && n.depleted ())
if (n.getDate (format, _t) && n.depleted ())
return;
throw ::format (STRING_DATE_INVALID_FORMAT, input, format);
@ -151,7 +151,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
////////////////////////////////////////////////////////////////////////////////
Date::Date (const Date& rhs)
{
mT = rhs.mT;
_t = rhs._t;
}
////////////////////////////////////////////////////////////////////////////////
@ -162,14 +162,14 @@ Date::~Date ()
////////////////////////////////////////////////////////////////////////////////
time_t Date::toEpoch ()
{
return mT;
return _t;
}
////////////////////////////////////////////////////////////////////////////////
std::string Date::toEpochString ()
{
std::stringstream epoch;
epoch << mT;
epoch << _t;
return epoch.str ();
}
@ -177,7 +177,7 @@ std::string Date::toEpochString ()
// 19980119T070000Z = YYYYMMDDThhmmssZ
std::string Date::toISO ()
{
struct tm* t = gmtime (&mT);
struct tm* t = gmtime (&_t);
std::stringstream iso;
iso << std::setw (4) << std::setfill ('0') << t->tm_year + 1900
@ -195,19 +195,19 @@ std::string Date::toISO ()
////////////////////////////////////////////////////////////////////////////////
double Date::toJulian ()
{
return (mT / 86400.0) + 2440587.5;
return (_t / 86400.0) + 2440587.5;
}
////////////////////////////////////////////////////////////////////////////////
void Date::toEpoch (time_t& epoch)
{
epoch = mT;
epoch = _t;
}
////////////////////////////////////////////////////////////////////////////////
void Date::toMDY (int& m, int& d, int& y)
{
struct tm* t = localtime (&mT);
struct tm* t = localtime (&_t);
m = t->tm_mon + 1;
d = t->tm_mday;
@ -264,7 +264,7 @@ Date Date::startOfDay () const
////////////////////////////////////////////////////////////////////////////////
Date Date::startOfWeek () const
{
Date sow (mT);
Date sow (_t);
sow -= (dayOfWeek () * 86400);
return Date (sow.month (), sow.day (), sow.year (), 0, 0, 0);
}
@ -433,7 +433,7 @@ std::string Date::dayName (int dow)
////////////////////////////////////////////////////////////////////////////////
int Date::weekOfYear (int weekStart) const
{
struct tm* t = localtime (&mT);
struct tm* t = localtime (&_t);
char weekStr[3];
if (weekStart == 0)
@ -454,7 +454,7 @@ int Date::weekOfYear (int weekStart) const
////////////////////////////////////////////////////////////////////////////////
int Date::dayOfWeek () const
{
struct tm* t = localtime (&mT);
struct tm* t = localtime (&_t);
return t->tm_wday;
}
@ -477,7 +477,7 @@ int Date::dayOfWeek (const std::string& input)
////////////////////////////////////////////////////////////////////////////////
int Date::dayOfYear () const
{
struct tm* t = localtime (&mT);
struct tm* t = localtime (&_t);
return t->tm_yday + 1;
}
@ -563,79 +563,79 @@ time_t Date::easter (int year)
////////////////////////////////////////////////////////////////////////////////
int Date::month () const
{
struct tm* t = localtime (&mT);
struct tm* t = localtime (&_t);
return t->tm_mon + 1;
}
////////////////////////////////////////////////////////////////////////////////
int Date::day () const
{
struct tm* t = localtime (&mT);
struct tm* t = localtime (&_t);
return t->tm_mday;
}
////////////////////////////////////////////////////////////////////////////////
int Date::year () const
{
struct tm* t = localtime (&mT);
struct tm* t = localtime (&_t);
return t->tm_year + 1900;
}
////////////////////////////////////////////////////////////////////////////////
int Date::hour () const
{
struct tm* t = localtime (&mT);
struct tm* t = localtime (&_t);
return t->tm_hour;
}
////////////////////////////////////////////////////////////////////////////////
int Date::minute () const
{
struct tm* t = localtime (&mT);
struct tm* t = localtime (&_t);
return t->tm_min;
}
////////////////////////////////////////////////////////////////////////////////
int Date::second () const
{
struct tm* t = localtime (&mT);
struct tm* t = localtime (&_t);
return t->tm_sec;
}
////////////////////////////////////////////////////////////////////////////////
bool Date::operator== (const Date& rhs)
{
return rhs.mT == mT;
return rhs._t == _t;
}
////////////////////////////////////////////////////////////////////////////////
bool Date::operator!= (const Date& rhs)
{
return rhs.mT != mT;
return rhs._t != _t;
}
////////////////////////////////////////////////////////////////////////////////
bool Date::operator< (const Date& rhs)
{
return mT < rhs.mT;
return _t < rhs._t;
}
////////////////////////////////////////////////////////////////////////////////
bool Date::operator> (const Date& rhs)
{
return mT > rhs.mT;
return _t > rhs._t;
}
////////////////////////////////////////////////////////////////////////////////
bool Date::operator<= (const Date& rhs)
{
return mT <= rhs.mT;
return _t <= rhs._t;
}
////////////////////////////////////////////////////////////////////////////////
bool Date::operator>= (const Date& rhs)
{
return mT >= rhs.mT;
return _t >= rhs._t;
}
////////////////////////////////////////////////////////////////////////////////
@ -683,33 +683,33 @@ bool Date::sameYear (const Date& rhs)
////////////////////////////////////////////////////////////////////////////////
Date Date::operator- (const int delta)
{
return Date (mT - delta);
return Date (_t - delta);
}
////////////////////////////////////////////////////////////////////////////////
Date Date::operator+ (const int delta)
{
return Date (mT + delta);
return Date (_t + delta);
}
////////////////////////////////////////////////////////////////////////////////
Date& Date::operator+= (const int delta)
{
mT += (time_t) delta;
_t += (time_t) delta;
return *this;
}
////////////////////////////////////////////////////////////////////////////////
Date& Date::operator-= (const int delta)
{
mT -= (time_t) delta;
_t -= (time_t) delta;
return *this;
}
////////////////////////////////////////////////////////////////////////////////
time_t Date::operator- (const Date& rhs)
{
return mT - rhs.mT;
return _t - rhs._t;
}
////////////////////////////////////////////////////////////////////////////////
@ -723,7 +723,7 @@ void Date::operator-- ()
hour (),
minute (),
second ());
mT = yesterday.mT;
_t = yesterday._t;
}
////////////////////////////////////////////////////////////////////////////////
@ -737,7 +737,7 @@ void Date::operator-- (int)
hour (),
minute (),
second ());
mT = yesterday.mT;
_t = yesterday._t;
}
////////////////////////////////////////////////////////////////////////////////
@ -751,7 +751,7 @@ void Date::operator++ ()
hour (),
minute (),
second ());
mT = tomorrow.mT;
_t = tomorrow._t;
}
////////////////////////////////////////////////////////////////////////////////
@ -765,7 +765,7 @@ void Date::operator++ (int)
hour (),
minute (),
second ());
mT = tomorrow.mT;
_t = tomorrow._t;
}
////////////////////////////////////////////////////////////////////////////////
@ -775,7 +775,7 @@ bool Date::isEpoch (const std::string& input)
input.length () > 8 &&
input.length () <= 10 )
{
mT = (time_t) atoi (input.c_str ());
_t = (time_t) atoi (input.c_str ());
return true;
}
@ -783,7 +783,7 @@ bool Date::isEpoch (const std::string& input)
}
////////////////////////////////////////////////////////////////////////////////
// If the input string looks like a relative date, determine that date, set mT
// If the input string looks like a relative date, determine that date, set _t
// and return true.
//
// What is a relative date? All of the following should be recognizable, and
@ -844,7 +844,7 @@ bool Date::isRelativeDate (const std::string& input)
today.toMDY (m, d, y);
Date then (m, d, y);
mT = then.mT;
_t = then._t;
return true;
}
else if (found == "today")
@ -852,7 +852,7 @@ bool Date::isRelativeDate (const std::string& input)
Date then (today.month (),
today.day (),
today.year ());
mT = then.mT;
_t = then._t;
return true;
}
else if (found == "tomorrow")
@ -860,7 +860,7 @@ bool Date::isRelativeDate (const std::string& input)
Date then (today.month (),
today.day (),
today.year ());
mT = then.mT + 86400;
_t = then._t + 86400;
return true;
}
else if (found == "yesterday")
@ -868,7 +868,7 @@ bool Date::isRelativeDate (const std::string& input)
Date then (today.month (),
today.day (),
today.year ());
mT = then.mT - 86400;
_t = then._t - 86400;
return true;
}
else if (found == "eom")
@ -876,7 +876,7 @@ bool Date::isRelativeDate (const std::string& input)
Date then (today.month (),
daysInMonth (today.month (), today.year ()),
today.year ());
mT = then.mT;
_t = then._t;
return true;
}
else if (found == "eoq")
@ -895,13 +895,13 @@ bool Date::isRelativeDate (const std::string& input)
Date then (q,
Date::daysInMonth (q, y),
y);
mT = then.mT;
_t = then._t;
return true;
}
else if (found == "eoy")
{
Date then (12, 31, today.year ());
mT = then.mT;
_t = then._t;
return true;
}
else if (found == "som")
@ -914,7 +914,7 @@ bool Date::isRelativeDate (const std::string& input)
y++;
}
Date then (m, 1, y);
mT = then.mT;
_t = then._t;
return true;
}
else if (found == "soq")
@ -933,43 +933,43 @@ bool Date::isRelativeDate (const std::string& input)
Date then (q,
1,
y);
mT = then.mT;
_t = then._t;
return true;
}
else if (found == "soy")
{
Date then (1, 1, today.year () + 1);
mT = then.mT;
_t = then._t;
return true;
}
else if (found == "goodfriday")
{
Date then (Date::easter(today.year()));
mT = then.mT - 86400*2;
_t = then._t - 86400*2;
return true;
}
else if (found == "easter")
{
Date then (Date::easter(today.year()));
mT = then.mT;
_t = then._t;
return true;
}
else if (found == "eastermonday")
{
Date then (Date::easter(today.year()));
mT = then.mT + 86400;
_t = then._t + 86400;
return true;
}
else if (found == "ascension")
{
Date then (Date::easter(today.year()));
mT = then.mT + 86400*39;
_t = then._t + 86400*39;
return true;
}
else if (found == "pentecost")
{
Date then (Date::easter(today.year()));
mT = then.mT + 86400*49;
_t = then._t + 86400*49;
return true;
}
else if (found == "midsommar")
@ -979,7 +979,7 @@ bool Date::isRelativeDate (const std::string& input)
Date then (6, midsommar, today.year ());
if (6 == then.dayOfWeek ())
{
mT = then.mT;
_t = then._t;
return true;
}
}
@ -991,20 +991,20 @@ bool Date::isRelativeDate (const std::string& input)
Date then (6, midsommar, today.year ());
if (5 == then.dayOfWeek ())
{
mT = then.mT;
_t = then._t;
return true;
}
}
}
else if (found == "now")
{
mT = time (NULL);
_t = time (NULL);
return true;
}
else if (found == "later" || found == "someday")
{
Date then (1, 18, 2038);
mT = then.mT;
_t = then._t;
return true;
}
}
@ -1044,7 +1044,7 @@ bool Date::isRelativeDate (const std::string& input)
number <= Date::daysInMonth (m, y))
{
Date then (m, number, y);
mT = then.mT;
_t = then._t;
return true;
}
@ -1061,7 +1061,7 @@ bool Date::isRelativeDate (const std::string& input)
while (number > Date::daysInMonth (m, y));
Date then (m, number, y);
mT = then.mT;
_t = then._t;
return true;
}
}

View file

@ -114,7 +114,7 @@ private:
bool isRelativeDate (const std::string&);
protected:
time_t mT;
time_t _t;
};
#endif

View file

@ -83,13 +83,13 @@ Directory& Directory::operator= (const Directory& other)
////////////////////////////////////////////////////////////////////////////////
bool Directory::create ()
{
return mkdir (data.c_str (), 0755) == 0 ? true : false;
return mkdir (_data.c_str (), 0755) == 0 ? true : false;
}
////////////////////////////////////////////////////////////////////////////////
bool Directory::remove ()
{
return remove_directory (data);
return remove_directory (_data);
}
////////////////////////////////////////////////////////////////////////////////
@ -130,7 +130,7 @@ bool Directory::remove_directory (const std::string& dir)
std::vector <std::string> Directory::list ()
{
std::vector <std::string> files;
list (data, files, false);
list (_data, files, false);
return files;
}
@ -138,7 +138,7 @@ std::vector <std::string> Directory::list ()
std::vector <std::string> Directory::listRecursive ()
{
std::vector <std::string> files;
list (data, files, true);
list (_data, files, true);
return files;
}

View file

@ -101,16 +101,16 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
Duration::Duration ()
: mSecs (0)
, mNegative (false)
: _secs (0)
, _negative (false)
{
}
////////////////////////////////////////////////////////////////////////////////
Duration::Duration (const Duration& other)
{
mSecs = other.mSecs;
mNegative = other.mNegative;
_secs = other._secs;
_negative = other._negative;
}
////////////////////////////////////////////////////////////////////////////////
@ -118,25 +118,25 @@ Duration::Duration (time_t input)
{
if (input < 0)
{
mSecs = -input;
mNegative = true;
_secs = -input;
_negative = true;
}
else
{
mSecs = input;
mNegative = false;
_secs = input;
_negative = false;
}
}
////////////////////////////////////////////////////////////////////////////////
Duration::Duration (const std::string& input)
: mSecs (0)
, mNegative (false)
: _secs (0)
, _negative (false)
{
if (digitsOnly (input))
{
mSecs = (time_t) strtol (input.c_str (), NULL, 10);
mNegative = false;
_secs = (time_t) strtol (input.c_str (), NULL, 10);
_negative = false;
}
else
parse (input);
@ -145,14 +145,14 @@ Duration::Duration (const std::string& input)
////////////////////////////////////////////////////////////////////////////////
Duration::operator time_t () const
{
return mSecs;
return _secs;
}
////////////////////////////////////////////////////////////////////////////////
Duration::operator std::string () const
{
std::stringstream s;
s << (mNegative ? - (long) mSecs : (long) mSecs);
s << (_negative ? - (long) _secs : (long) _secs);
return s.str ();
}
@ -161,8 +161,8 @@ Duration& Duration::operator= (const Duration& other)
{
if (this != &other)
{
mSecs = other.mSecs;
mNegative = other.mNegative;
_secs = other._secs;
_negative = other._negative;
}
return *this;
@ -171,14 +171,14 @@ Duration& Duration::operator= (const Duration& other)
////////////////////////////////////////////////////////////////////////////////
Duration Duration::operator- (const Duration& other)
{
int left = mSecs * ( mNegative ? -1 : 1);
int right = other.mSecs * (other.mNegative ? -1 : 1);
int left = _secs * ( _negative ? -1 : 1);
int right = other._secs * (other._negative ? -1 : 1);
left -= right;
Duration result;
result.mSecs = abs (left);
result.mNegative = left < 0;
result._secs = abs (left);
result._negative = left < 0;
return result;
}
@ -186,14 +186,14 @@ Duration Duration::operator- (const Duration& other)
////////////////////////////////////////////////////////////////////////////////
Duration Duration::operator+ (const Duration& other)
{
int left = mSecs * ( mNegative ? -1 : 1);
int right = other.mSecs * (other.mNegative ? -1 : 1);
int left = _secs * ( _negative ? -1 : 1);
int right = other._secs * (other._negative ? -1 : 1);
left += right;
Duration result;
result.mSecs = abs (left);
result.mNegative = left < 0;
result._secs = abs (left);
result._negative = left < 0;
return result;
}
@ -201,13 +201,13 @@ Duration Duration::operator+ (const Duration& other)
////////////////////////////////////////////////////////////////////////////////
Duration& Duration::operator-= (const Duration& other)
{
int left = mSecs * ( mNegative ? -1 : 1);
int right = other.mSecs * (other.mNegative ? -1 : 1);
int left = _secs * ( _negative ? -1 : 1);
int right = other._secs * (other._negative ? -1 : 1);
left -= right;
mSecs = abs (left);
mNegative = left < 0;
_secs = abs (left);
_negative = left < 0;
return *this;
}
@ -215,13 +215,13 @@ Duration& Duration::operator-= (const Duration& other)
////////////////////////////////////////////////////////////////////////////////
Duration& Duration::operator+= (const Duration& other)
{
int left = mSecs * ( mNegative ? -1 : 1);
int right = other.mSecs * (other.mNegative ? -1 : 1);
int left = _secs * ( _negative ? -1 : 1);
int right = other._secs * (other._negative ? -1 : 1);
left += right;
mSecs = abs (left);
mNegative = left < 0;
_secs = abs (left);
_negative = left < 0;
return *this;
}
@ -230,34 +230,34 @@ Duration& Duration::operator+= (const Duration& other)
std::string Duration::format () const
{
char formatted[24];
float days = (float) mSecs / 86400.0;
float days = (float) _secs / 86400.0;
if (mSecs >= 86400 * 365)
sprintf (formatted, "%s%.1f yrs", (mNegative ? "-" : ""), (days / 365));
else if (mSecs > 86400 * 84)
if (_secs >= 86400 * 365)
sprintf (formatted, "%s%.1f yrs", (_negative ? "-" : ""), (days / 365));
else if (_secs > 86400 * 84)
sprintf (formatted, "%s%1d mth%s",
(mNegative ? "-" : ""), (int) (float) (days / 30.6),
(_negative ? "-" : ""), (int) (float) (days / 30.6),
((int) (float) (days / 30.6) == 1 ? "" : "s"));
else if (mSecs > 86400 * 13)
else if (_secs > 86400 * 13)
sprintf (formatted, "%s%d wk%s",
(mNegative ? "-" : ""), (int) (float) (days / 7.0),
(_negative ? "-" : ""), (int) (float) (days / 7.0),
((int) (float) (days / 7.0) == 1 ? "" : "s"));
else if (mSecs >= 86400)
else if (_secs >= 86400)
sprintf (formatted, "%s%d day%s",
(mNegative ? "-" : ""), (int) days,
(_negative ? "-" : ""), (int) days,
((int) days == 1 ? "" : "s"));
else if (mSecs >= 3600)
else if (_secs >= 3600)
sprintf (formatted, "%s%d hr%s",
(mNegative ? "-" : ""), (int) (float) (mSecs / 3600),
((int) (float) (mSecs / 3600) == 1 ? "" : "s"));
else if (mSecs >= 60)
(_negative ? "-" : ""), (int) (float) (_secs / 3600),
((int) (float) (_secs / 3600) == 1 ? "" : "s"));
else if (_secs >= 60)
sprintf (formatted, "%s%d min%s",
(mNegative ? "-" : ""), (int) (float) (mSecs / 60),
((int) (float) (mSecs / 60) == 1 ? "" : "s"));
else if (mSecs >= 1)
(_negative ? "-" : ""), (int) (float) (_secs / 60),
((int) (float) (_secs / 60) == 1 ? "" : "s"));
else if (_secs >= 1)
sprintf (formatted, "%s%d sec%s",
(mNegative ? "-" : ""), (int) mSecs,
((int) mSecs == 1 ? "" : "s"));
(_negative ? "-" : ""), (int) _secs,
((int) _secs == 1 ? "" : "s"));
else
strcpy (formatted, "-"); // no i18n
@ -268,15 +268,15 @@ std::string Duration::format () const
std::string Duration::formatCompact () const
{
char formatted[24];
float days = (float) mSecs / 86400.0;
float days = (float) _secs / 86400.0;
if (mSecs >= 86400 * 365) sprintf (formatted, "%s%.1fy", (mNegative ? "-" : ""), (days / 365));
else if (mSecs >= 86400 * 84) sprintf (formatted, "%s%1dmo", (mNegative ? "-" : ""), (int) (float) (days / 30.6));
else if (mSecs >= 86400 * 13) sprintf (formatted, "%s%dwk", (mNegative ? "-" : ""), (int) (float) (days / 7.0));
else if (mSecs >= 86400) sprintf (formatted, "%s%dd", (mNegative ? "-" : ""), (int) days);
else if (mSecs >= 3600) sprintf (formatted, "%s%dh", (mNegative ? "-" : ""), (int) (float) (mSecs / 3600));
else if (mSecs >= 60) sprintf (formatted, "%s%dm", (mNegative ? "-" : ""), (int) (float) (mSecs / 60));
else if (mSecs >= 1) sprintf (formatted, "%s%ds", (mNegative ? "-" : ""), (int) mSecs);
if (_secs >= 86400 * 365) sprintf (formatted, "%s%.1fy", (_negative ? "-" : ""), (days / 365));
else if (_secs >= 86400 * 84) sprintf (formatted, "%s%1dmo", (_negative ? "-" : ""), (int) (float) (days / 30.6));
else if (_secs >= 86400 * 13) sprintf (formatted, "%s%dwk", (_negative ? "-" : ""), (int) (float) (days / 7.0));
else if (_secs >= 86400) sprintf (formatted, "%s%dd", (_negative ? "-" : ""), (int) days);
else if (_secs >= 3600) sprintf (formatted, "%s%dh", (_negative ? "-" : ""), (int) (float) (_secs / 3600));
else if (_secs >= 60) sprintf (formatted, "%s%dm", (_negative ? "-" : ""), (int) (float) (_secs / 60));
else if (_secs >= 1) sprintf (formatted, "%s%ds", (_negative ? "-" : ""), (int) _secs);
else strcpy (formatted, "-");
return std::string (formatted);
@ -287,13 +287,13 @@ std::string Duration::formatPrecise () const
{
char formatted[24];
int days = mSecs / 86400;
int hours = (mSecs % 86400) / 3600;
int minutes = (mSecs % 3600) / 60;
int seconds = mSecs % 60;
int days = _secs / 86400;
int hours = (_secs % 86400) / 3600;
int minutes = (_secs % 3600) / 60;
int seconds = _secs % 60;
if (days > 0) sprintf (formatted, "%s%dd %d:%02d:%02d", (mNegative ? "-" : ""), days, hours, minutes, seconds);
else sprintf (formatted, "%s%d:%02d:%02d", (mNegative ? "-" : ""), hours, minutes, seconds);
if (days > 0) sprintf (formatted, "%s%dd %d:%02d:%02d", (_negative ? "-" : ""), days, hours, minutes, seconds);
else sprintf (formatted, "%s%d:%02d:%02d", (_negative ? "-" : ""), hours, minutes, seconds);
return std::string (formatted);
}
@ -301,8 +301,8 @@ std::string Duration::formatPrecise () const
////////////////////////////////////////////////////////////////////////////////
bool Duration::operator< (const Duration& other)
{
long left = (long) ( mNegative ? -mSecs : mSecs);
long right = (long) (other.mNegative ? -other.mSecs : other.mSecs);
long left = (long) ( _negative ? -_secs : _secs);
long right = (long) (other._negative ? -other._secs : other._secs);
return left < right;
}
@ -310,8 +310,8 @@ bool Duration::operator< (const Duration& other)
////////////////////////////////////////////////////////////////////////////////
bool Duration::operator<= (const Duration& other)
{
long left = (long) ( mNegative ? -mSecs : mSecs);
long right = (long) (other.mNegative ? -other.mSecs : other.mSecs);
long left = (long) ( _negative ? -_secs : _secs);
long right = (long) (other._negative ? -other._secs : other._secs);
return left <= right;
}
@ -319,8 +319,8 @@ bool Duration::operator<= (const Duration& other)
////////////////////////////////////////////////////////////////////////////////
bool Duration::operator> (const Duration& other)
{
long left = (long) ( mNegative ? -mSecs : mSecs);
long right = (long) (other.mNegative ? -other.mSecs : other.mSecs);
long left = (long) ( _negative ? -_secs : _secs);
long right = (long) (other._negative ? -other._secs : other._secs);
return left > right;
}
@ -328,8 +328,8 @@ bool Duration::operator> (const Duration& other)
////////////////////////////////////////////////////////////////////////////////
bool Duration::operator>= (const Duration& other)
{
long left = (long) ( mNegative ? -mSecs : mSecs);
long right = (long) (other.mNegative ? -other.mSecs : other.mSecs);
long left = (long) ( _negative ? -_secs : _secs);
long right = (long) (other._negative ? -other._secs : other._secs);
return left >= right;
}
@ -342,7 +342,7 @@ Duration::~Duration ()
////////////////////////////////////////////////////////////////////////////////
bool Duration::negative () const
{
return mNegative;
return _negative;
}
////////////////////////////////////////////////////////////////////////////////
@ -394,11 +394,11 @@ void Duration::parse (const std::string& input)
if (value < 0.0)
{
mNegative = true;
_negative = true;
value = -value;
}
else
mNegative = false;
_negative = false;
std::string units;
n.getUntilEOS (units);
@ -408,7 +408,7 @@ void Duration::parse (const std::string& input)
for (unsigned int i = 0; i < NUM_DURATIONS; ++i)
supported.push_back (durations[i]);
mSecs = 0;
_secs = 0;
std::vector <std::string> matches;
if (autoComplete (units,
supported,
@ -417,73 +417,73 @@ void Duration::parse (const std::string& input)
{
std::string match = matches[0];
if (match == "biannual") mSecs = (int) (value * 86400 * 730);
else if (match == "biyearly") mSecs = (int) (value * 86400 * 730);
if (match == "biannual") _secs = (int) (value * 86400 * 730);
else if (match == "biyearly") _secs = (int) (value * 86400 * 730);
else if (match == "yearly") mSecs = (int) (value * 86400 * 365);
else if (match == "annual") mSecs = (int) (value * 86400 * 365);
else if (match == "years") mSecs = (int) (value * 86400 * 365);
else if (match == "year") mSecs = (int) (value * 86400 * 365);
else if (match == "yrs") mSecs = (int) (value * 86400 * 365);
else if (match == "yr") mSecs = (int) (value * 86400 * 365);
else if (match == "y") mSecs = (int) (value * 86400 * 365);
else if (match == "yearly") _secs = (int) (value * 86400 * 365);
else if (match == "annual") _secs = (int) (value * 86400 * 365);
else if (match == "years") _secs = (int) (value * 86400 * 365);
else if (match == "year") _secs = (int) (value * 86400 * 365);
else if (match == "yrs") _secs = (int) (value * 86400 * 365);
else if (match == "yr") _secs = (int) (value * 86400 * 365);
else if (match == "y") _secs = (int) (value * 86400 * 365);
else if (match == "semiannual") mSecs = (int) (value * 86400 * 183);
else if (match == "semiannual") _secs = (int) (value * 86400 * 183);
else if (match == "bimonthly") mSecs = (int) (value * 86400 * 61);
else if (match == "quarterly") mSecs = (int) (value * 86400 * 91);
else if (match == "quarters") mSecs = (int) (value * 86400 * 91);
else if (match == "qrtrs") mSecs = (int) (value * 86400 * 91);
else if (match == "qtrs") mSecs = (int) (value * 86400 * 91);
else if (match == "qtr") mSecs = (int) (value * 86400 * 91);
else if (match == "q") mSecs = (int) (value * 86400 * 91);
else if (match == "bimonthly") _secs = (int) (value * 86400 * 61);
else if (match == "quarterly") _secs = (int) (value * 86400 * 91);
else if (match == "quarters") _secs = (int) (value * 86400 * 91);
else if (match == "qrtrs") _secs = (int) (value * 86400 * 91);
else if (match == "qtrs") _secs = (int) (value * 86400 * 91);
else if (match == "qtr") _secs = (int) (value * 86400 * 91);
else if (match == "q") _secs = (int) (value * 86400 * 91);
else if (match == "monthly") mSecs = (int) (value * 86400 * 30);
else if (match == "month") mSecs = (int) (value * 86400 * 30);
else if (match == "months") mSecs = (int) (value * 86400 * 30);
else if (match == "mnths") mSecs = (int) (value * 86400 * 30);
else if (match == "mos") mSecs = (int) (value * 86400 * 30);
else if (match == "mo") mSecs = (int) (value * 86400 * 30);
else if (match == "mths") mSecs = (int) (value * 86400 * 30);
else if (match == "mth") mSecs = (int) (value * 86400 * 30);
else if (match == "m") mSecs = (int) (value * 86400 * 30);
else if (match == "monthly") _secs = (int) (value * 86400 * 30);
else if (match == "month") _secs = (int) (value * 86400 * 30);
else if (match == "months") _secs = (int) (value * 86400 * 30);
else if (match == "mnths") _secs = (int) (value * 86400 * 30);
else if (match == "mos") _secs = (int) (value * 86400 * 30);
else if (match == "mo") _secs = (int) (value * 86400 * 30);
else if (match == "mths") _secs = (int) (value * 86400 * 30);
else if (match == "mth") _secs = (int) (value * 86400 * 30);
else if (match == "m") _secs = (int) (value * 86400 * 30);
else if (match == "biweekly") mSecs = (int) (value * 86400 * 14);
else if (match == "fortnight") mSecs = (int) (value * 86400 * 14);
else if (match == "biweekly") _secs = (int) (value * 86400 * 14);
else if (match == "fortnight") _secs = (int) (value * 86400 * 14);
else if (match == "weekly") mSecs = (int) (value * 86400 * 7);
else if (match == "sennight") mSecs = (int) (value * 86400 * 7);
else if (match == "weeks") mSecs = (int) (value * 86400 * 7);
else if (match == "week") mSecs = (int) (value * 86400 * 7);
else if (match == "wks") mSecs = (int) (value * 86400 * 7);
else if (match == "wk") mSecs = (int) (value * 86400 * 7);
else if (match == "w") mSecs = (int) (value * 86400 * 7);
else if (match == "weekly") _secs = (int) (value * 86400 * 7);
else if (match == "sennight") _secs = (int) (value * 86400 * 7);
else if (match == "weeks") _secs = (int) (value * 86400 * 7);
else if (match == "week") _secs = (int) (value * 86400 * 7);
else if (match == "wks") _secs = (int) (value * 86400 * 7);
else if (match == "wk") _secs = (int) (value * 86400 * 7);
else if (match == "w") _secs = (int) (value * 86400 * 7);
else if (match == "daily") mSecs = (int) (value * 86400 * 1);
else if (match == "day") mSecs = (int) (value * 86400 * 1);
else if (match == "weekdays") mSecs = (int) (value * 86400 * 1);
else if (match == "days") mSecs = (int) (value * 86400 * 1);
else if (match == "d") mSecs = (int) (value * 86400 * 1);
else if (match == "daily") _secs = (int) (value * 86400 * 1);
else if (match == "day") _secs = (int) (value * 86400 * 1);
else if (match == "weekdays") _secs = (int) (value * 86400 * 1);
else if (match == "days") _secs = (int) (value * 86400 * 1);
else if (match == "d") _secs = (int) (value * 86400 * 1);
else if (match == "hours") mSecs = (int) (value * 3600);
else if (match == "hour") mSecs = (int) (value * 3600);
else if (match == "hrs") mSecs = (int) (value * 3600);
else if (match == "hr") mSecs = (int) (value * 3600);
else if (match == "h") mSecs = (int) (value * 3600);
else if (match == "hours") _secs = (int) (value * 3600);
else if (match == "hour") _secs = (int) (value * 3600);
else if (match == "hrs") _secs = (int) (value * 3600);
else if (match == "hr") _secs = (int) (value * 3600);
else if (match == "h") _secs = (int) (value * 3600);
else if (match == "minutes") mSecs = (int) (value * 60);
else if (match == "mins") mSecs = (int) (value * 60);
else if (match == "min") mSecs = (int) (value * 60);
else if (match == "minutes") _secs = (int) (value * 60);
else if (match == "mins") _secs = (int) (value * 60);
else if (match == "min") _secs = (int) (value * 60);
else if (match == "seconds") mSecs = (int) value;
else if (match == "secs") mSecs = (int) value;
else if (match == "sec") mSecs = (int) value;
else if (match == "s") mSecs = (int) value;
else if (match == "seconds") _secs = (int) value;
else if (match == "secs") _secs = (int) value;
else if (match == "sec") _secs = (int) value;
else if (match == "s") _secs = (int) value;
else if (match == "-") mSecs = 0;
else if (match == "-") _secs = 0;
}
if (mSecs == 0)
if (_secs == 0)
throw ::format (STRING_DURATION_UNRECOGNIZED, input);
}

View file

@ -64,8 +64,8 @@ public:
static const std::vector <std::string> get_units ();
protected:
time_t mSecs;
bool mNegative;
time_t _secs;
bool _negative;
};
#endif

View file

@ -40,43 +40,43 @@
////////////////////////////////////////////////////////////////////////////////
File::File ()
: Path::Path ()
, fh (NULL)
, h (-1)
, locked (false)
, _fh (NULL)
, _h (-1)
, _locked (false)
{
}
////////////////////////////////////////////////////////////////////////////////
File::File (const Path& other)
: Path::Path (other)
, fh (NULL)
, h (-1)
, locked (false)
, _fh (NULL)
, _h (-1)
, _locked (false)
{
}
////////////////////////////////////////////////////////////////////////////////
File::File (const File& other)
: Path::Path (other)
, fh (NULL)
, h (-1)
, locked (false)
, _fh (NULL)
, _h (-1)
, _locked (false)
{
}
////////////////////////////////////////////////////////////////////////////////
File::File (const std::string& in)
: Path::Path (in)
, fh (NULL)
, h (-1)
, locked (false)
, _fh (NULL)
, _h (-1)
, _locked (false)
{
}
////////////////////////////////////////////////////////////////////////////////
File::~File ()
{
if (fh)
if (_fh)
close ();
}
@ -86,7 +86,7 @@ File& File::operator= (const File& other)
if (this != &other)
Path::operator= (other);
locked = false;
_locked = false;
return *this;
}
@ -105,26 +105,26 @@ bool File::create ()
////////////////////////////////////////////////////////////////////////////////
bool File::remove ()
{
return unlink (data.c_str ()) == 0 ? true : false;
return unlink (_data.c_str ()) == 0 ? true : false;
}
////////////////////////////////////////////////////////////////////////////////
bool File::open ()
{
if (data != "")
if (_data != "")
{
if (! fh)
if (! _fh)
{
bool already_exists = exists ();
if (already_exists)
if (!readable () || !writable ())
throw std::string (format (STRING_FILE_PERMS, data));
throw std::string (format (STRING_FILE_PERMS, _data));
fh = fopen (data.c_str (), (already_exists ? "r+" : "w+"));
if (fh)
_fh = fopen (_data.c_str (), (already_exists ? "r+" : "w+"));
if (_fh)
{
h = fileno (fh);
locked = false;
_h = fileno (_fh);
_locked = false;
return true;
}
}
@ -144,46 +144,46 @@ bool File::openAndLock ()
////////////////////////////////////////////////////////////////////////////////
void File::close ()
{
if (fh)
if (_fh)
{
fclose (fh);
fh = NULL;
h = -1;
locked = false;
fclose (_fh);
_fh = NULL;
_h = -1;
_locked = false;
}
}
////////////////////////////////////////////////////////////////////////////////
bool File::lock ()
{
if (fh && h != -1)
if (_fh && _h != -1)
{
// Try three times before failing.
int retry = 0;
while (flock (h, LOCK_NB | LOCK_EX) && ++retry <= 3)
while (flock (_h, LOCK_NB | LOCK_EX) && ++retry <= 3)
;
if (retry <= 3)
{
locked = true;
_locked = true;
return true;
}
}
locked = false;
_locked = false;
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool File::waitForLock ()
{
if (locked)
if (_locked)
return true;
if (fh && h != -1)
if (flock (h, LOCK_EX) == 0)
if (_fh && _h != -1)
if (flock (_h, LOCK_EX) == 0)
{
locked = true;
_locked = true;
return true;
}
@ -196,7 +196,7 @@ void File::read (std::string& contents)
{
contents = "";
std::ifstream in (data.c_str ());
std::ifstream in (_data.c_str ());
if (in.good ())
{
std::string line;
@ -213,7 +213,7 @@ void File::read (std::vector <std::string>& contents)
{
contents.clear ();
std::ifstream in (data.c_str ());
std::ifstream in (_data.c_str ());
if (in.good ())
{
std::string line;
@ -228,25 +228,25 @@ void File::read (std::vector <std::string>& contents)
// Opens if necessary.
void File::write (const std::string& line)
{
if (!fh)
if (!_fh)
open ();
if (fh)
fputs (line.c_str (), fh);
if (_fh)
fputs (line.c_str (), _fh);
}
////////////////////////////////////////////////////////////////////////////////
// Opens if necessary.
void File::write (const std::vector <std::string>& lines)
{
if (!fh)
if (!_fh)
open ();
if (fh)
if (_fh)
{
std::vector <std::string>::const_iterator it;
for (it = lines.begin (); it != lines.end (); ++it)
fputs (it->c_str (), fh);
fputs (it->c_str (), _fh);
}
}
@ -254,13 +254,13 @@ void File::write (const std::vector <std::string>& lines)
// Opens if necessary.
void File::append (const std::string& line)
{
if (!fh)
if (!_fh)
open ();
if (fh)
if (_fh)
{
fseek (fh, 0, SEEK_END);
fputs (line.c_str (), fh);
fseek (_fh, 0, SEEK_END);
fputs (line.c_str (), _fh);
}
}
@ -268,26 +268,26 @@ void File::append (const std::string& line)
// Opens if necessary.
void File::append (const std::vector <std::string>& lines)
{
if (!fh)
if (!_fh)
open ();
if (fh)
if (_fh)
{
fseek (fh, 0, SEEK_END);
fseek (_fh, 0, SEEK_END);
std::vector <std::string>::const_iterator it;
for (it = lines.begin (); it != lines.end (); ++it)
fputs (((*it) + "\n").c_str (), fh);
fputs (((*it) + "\n").c_str (), _fh);
}
}
////////////////////////////////////////////////////////////////////////////////
void File::truncate ()
{
if (!fh)
if (!_fh)
open ();
if (fh)
ftruncate (h, 0);
if (_fh)
ftruncate (_h, 0);
}
////////////////////////////////////////////////////////////////////////////////
@ -309,7 +309,7 @@ void File::truncate ()
mode_t File::mode ()
{
struct stat s;
if (!stat (data.c_str (), &s))
if (!stat (_data.c_str (), &s))
return s.st_mode;
return 0;
@ -319,7 +319,7 @@ mode_t File::mode ()
size_t File::size () const
{
struct stat s;
if (!stat (data.c_str (), &s))
if (!stat (_data.c_str (), &s))
return s.st_size;
return 0;
@ -329,7 +329,7 @@ size_t File::size () const
time_t File::mtime () const
{
struct stat s;
if (!stat (data.c_str (), &s))
if (!stat (_data.c_str (), &s))
return s.st_mtime;
return 0;

View file

@ -82,9 +82,9 @@ public:
static bool remove (const std::string&);
private:
FILE* fh;
int h;
bool locked;
FILE* _fh;
int _h;
bool _locked;
};
#endif

View file

@ -39,26 +39,26 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
Hook::Hook ()
: event ("")
, file ("")
, function ("")
: _event ("")
, _file ("")
, _function ("")
{
}
////////////////////////////////////////////////////////////////////////////////
Hook::Hook (const std::string& e, const std::string& f, const std::string& fn)
: event (e)
, file (f)
, function (fn)
: _event (e)
, _file (f)
, _function (fn)
{
}
////////////////////////////////////////////////////////////////////////////////
Hook::Hook (const Hook& other)
{
event = other.event;
file = other.file;
function = other.function;
_event = other._event;
_file = other._file;
_function = other._function;
}
////////////////////////////////////////////////////////////////////////////////
@ -66,9 +66,9 @@ Hook& Hook::operator= (const Hook& other)
{
if (this != &other)
{
event = other.event;
file = other.file;
function = other.function;
_event = other._event;
_file = other._file;
_function = other._function;
}
return *this;
@ -78,18 +78,18 @@ Hook& Hook::operator= (const Hook& other)
Hooks::Hooks ()
{
// New 2.x hooks.
validTaskEvents.push_back ("on-task-add"); // Unimplemented
validTaskEvents.push_back ("on-task-modify"); // Unimplemented
validTaskEvents.push_back ("on-task-complete"); // Unimplemented
validTaskEvents.push_back ("on-task-delete"); // Unimplemented
_validTaskEvents.push_back ("on-task-add"); // Unimplemented
_validTaskEvents.push_back ("on-task-modify"); // Unimplemented
_validTaskEvents.push_back ("on-task-complete"); // Unimplemented
_validTaskEvents.push_back ("on-task-delete"); // Unimplemented
validProgramEvents.push_back ("on-launch");
validProgramEvents.push_back ("on-exit");
validProgramEvents.push_back ("on-file-read"); // Unimplemented
validProgramEvents.push_back ("on-file-write"); // Unimplemented
validProgramEvents.push_back ("on-synch"); // Unimplemented
validProgramEvents.push_back ("on-merge"); // Unimplemented
validProgramEvents.push_back ("on-gc"); // Unimplemented
_validProgramEvents.push_back ("on-launch");
_validProgramEvents.push_back ("on-exit");
_validProgramEvents.push_back ("on-file-read"); // Unimplemented
_validProgramEvents.push_back ("on-file-write"); // Unimplemented
_validProgramEvents.push_back ("on-synch"); // Unimplemented
_validProgramEvents.push_back ("on-merge"); // Unimplemented
_validProgramEvents.push_back ("on-gc"); // Unimplemented
}
////////////////////////////////////////////////////////////////////////////////
@ -104,7 +104,7 @@ Hooks::~Hooks ()
void Hooks::initialize ()
{
#ifdef HAVE_LIBLUA
api.initialize ();
_api.initialize ();
#endif
// Allow a master switch to turn the whole thing off.
@ -142,7 +142,7 @@ void Hooks::initialize ()
{
context.debug (std::string ("Event '") + name + "' hooked by " + file + ", function " + function);
Hook h (name, Path::expand (file), function);
all.push_back (h);
_all.push_back (h);
(void) n.skip (',');
}
@ -162,16 +162,16 @@ bool Hooks::trigger (const std::string& event)
{
#ifdef HAVE_LIBLUA
std::vector <Hook>::iterator it;
for (it = all.begin (); it != all.end (); ++it)
for (it = _all.begin (); it != _all.end (); ++it)
{
if (it->event == event)
if (it->_event == event)
{
Timer timer (std::string ("Hooks::trigger ") + event);
if (validProgramEvent (event))
{
context.debug (std::string ("Event ") + event + " triggered");
if (! api.callProgramHook (it->file, it->function))
if (! _api.callProgramHook (it->_file, it->_function))
return false;
}
else
@ -189,16 +189,16 @@ bool Hooks::trigger (const std::string& event, Task& task)
{
#ifdef HAVE_LIBLUA
std::vector <Hook>::iterator it;
for (it = all.begin (); it != all.end (); ++it)
for (it = _all.begin (); it != _all.end (); ++it)
{
if (it->event == event)
if (it->_event == event)
{
Timer timer (std::string ("Hooks::trigger ") + event);
if (validTaskEvent (event))
{
context.debug (std::string ("Event ") + event + " triggered");
if (! api.callTaskHook (it->file, it->function, task))
if (! _api.callTaskHook (it->_file, it->_function, task))
return false;
}
else
@ -213,7 +213,7 @@ bool Hooks::trigger (const std::string& event, Task& task)
////////////////////////////////////////////////////////////////////////////////
bool Hooks::validProgramEvent (const std::string& event)
{
if (std::find (validProgramEvents.begin (), validProgramEvents.end (), event) != validProgramEvents.end ())
if (std::find (_validProgramEvents.begin (), _validProgramEvents.end (), event) != _validProgramEvents.end ())
return true;
return false;
@ -222,7 +222,7 @@ bool Hooks::validProgramEvent (const std::string& event)
////////////////////////////////////////////////////////////////////////////////
bool Hooks::validTaskEvent (const std::string& event)
{
if (std::find (validTaskEvents.begin (), validTaskEvents.end (), event) != validTaskEvents.end ())
if (std::find (_validTaskEvents.begin (), _validTaskEvents.end (), event) != _validTaskEvents.end ())
return true;
return false;

View file

@ -43,9 +43,9 @@ public:
Hook& operator= (const Hook&);
public:
std::string event;
std::string file;
std::string function;
std::string _event;
std::string _file;
std::string _function;
};
// Hooks class for managing the loading and calling of hook functions.
@ -68,12 +68,12 @@ private:
private:
#ifdef HAVE_LIBLUA
API api;
API _api;
#endif
std::vector <Hook> all; // All current hooks.
std::vector <Hook> _all; // All current hooks.
std::vector <std::string> validProgramEvents;
std::vector <std::string> validTaskEvents;
std::vector <std::string> _validProgramEvents;
std::vector <std::string> _validTaskEvents;
};
#endif

View file

@ -29,26 +29,26 @@
////////////////////////////////////////////////////////////////////////////////
Location::Location ()
: path ("")
, pending (NULL)
, completed (NULL)
, undo (NULL)
: _path ("")
, _pending (NULL)
, _completed (NULL)
, _undo (NULL)
{
}
////////////////////////////////////////////////////////////////////////////////
Location::Location (const std::string& p)
: path (p)
: _path (p)
{
}
////////////////////////////////////////////////////////////////////////////////
Location::Location (const Location& other)
{
path = other.path;
pending = other.pending;
completed = other.completed;
undo = other.undo;
_path = other._path;
_pending = other._pending;
_completed = other._completed;
_undo = other._undo;
}
////////////////////////////////////////////////////////////////////////////////
@ -56,10 +56,10 @@ Location& Location::operator= (const Location& other)
{
if (this != &other)
{
path = other.path;
pending = other.pending;
completed = other.completed;
undo = other.undo;
_path = other._path;
_pending = other._pending;
_completed = other._completed;
_undo = other._undo;
}
return *this;

View file

@ -41,10 +41,10 @@ public:
~Location (); // Destructor
public:
std::string path;
FILE* pending;
FILE* completed;
FILE* undo;
std::string _path;
FILE* _pending;
FILE* _completed;
FILE* _undo;
};
#endif

File diff suppressed because it is too large Load diff

View file

@ -89,10 +89,10 @@ public:
std::string dump ();
private:
std::string mInput;
std::string::size_type mLength;
std::string::size_type mCursor;
std::string::size_type mSaved;
std::string _input;
std::string::size_type _length;
std::string::size_type _cursor;
std::string::size_type _saved;
};
#endif

View file

@ -45,13 +45,13 @@ Path::Path ()
Path::Path (const Path& other)
{
if (this != &other)
data = other.data;
_data = other._data;
}
////////////////////////////////////////////////////////////////////////////////
Path::Path (const std::string& in)
{
data = expand (in);
_data = expand (in);
}
////////////////////////////////////////////////////////////////////////////////
@ -63,7 +63,7 @@ Path::~Path ()
Path& Path::operator= (const Path& other)
{
if (this != &other)
this->data = other.data;
this->_data = other._data;
return *this;
}
@ -71,36 +71,36 @@ Path& Path::operator= (const Path& other)
////////////////////////////////////////////////////////////////////////////////
bool Path::operator== (const Path& other)
{
return data == other.data;
return _data == other._data;
}
////////////////////////////////////////////////////////////////////////////////
Path::operator std::string () const
{
return data;
return _data;
}
////////////////////////////////////////////////////////////////////////////////
std::string Path::name () const
{
if (data.length ())
if (_data.length ())
{
std::string::size_type slash = data.rfind ('/');
std::string::size_type slash = _data.rfind ('/');
if (slash != std::string::npos)
return data.substr (slash + 1, std::string::npos);
return _data.substr (slash + 1, std::string::npos);
}
return data;
return _data;
}
////////////////////////////////////////////////////////////////////////////////
std::string Path::parent () const
{
if (data.length ())
if (_data.length ())
{
std::string::size_type slash = data.rfind ('/');
std::string::size_type slash = _data.rfind ('/');
if (slash != std::string::npos)
return data.substr (0, slash);
return _data.substr (0, slash);
}
return "";
@ -109,11 +109,11 @@ std::string Path::parent () const
////////////////////////////////////////////////////////////////////////////////
std::string Path::extension () const
{
if (data.length ())
if (_data.length ())
{
std::string::size_type dot = data.rfind ('.');
std::string::size_type dot = _data.rfind ('.');
if (dot != std::string::npos)
return data.substr (dot + 1, std::string::npos);
return _data.substr (dot + 1, std::string::npos);
}
return "";
@ -122,14 +122,14 @@ std::string Path::extension () const
////////////////////////////////////////////////////////////////////////////////
bool Path::exists () const
{
return access (data.c_str (), F_OK) ? false : true;
return access (_data.c_str (), F_OK) ? false : true;
}
////////////////////////////////////////////////////////////////////////////////
bool Path::is_directory () const
{
struct stat s = {0};
if (! stat (data.c_str (), &s) &&
if (! stat (_data.c_str (), &s) &&
s.st_mode & S_IFDIR)
return true;
@ -139,7 +139,7 @@ bool Path::is_directory () const
////////////////////////////////////////////////////////////////////////////////
bool Path::is_absolute () const
{
if (data.length () && data.substr (0, 1) == "/")
if (_data.length () && _data.substr (0, 1) == "/")
return true;
return false;
@ -148,19 +148,19 @@ bool Path::is_absolute () const
////////////////////////////////////////////////////////////////////////////////
bool Path::readable () const
{
return access (data.c_str (), R_OK) ? false : true;
return access (_data.c_str (), R_OK) ? false : true;
}
////////////////////////////////////////////////////////////////////////////////
bool Path::writable () const
{
return access (data.c_str (), W_OK) ? false : true;
return access (_data.c_str (), W_OK) ? false : true;
}
////////////////////////////////////////////////////////////////////////////////
bool Path::executable () const
{
return access (data.c_str (), X_OK) ? false : true;
return access (_data.c_str (), X_OK) ? false : true;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -58,7 +58,7 @@ public:
static std::vector<std::string> glob (const std::string&);
public:
std::string data;
std::string _data;
};
#endif

View file

@ -38,25 +38,25 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
Permission::Permission ()
: needConfirmation (false)
, allConfirmed (false)
, quit (false)
: _need_confirmation (false)
, _all_confirmed (false)
, _quit (false)
{
// Turning confirmations off is the same as entering "all".
if (context.config.getBoolean ("confirmation") == false)
allConfirmed = true;
_all_confirmed = true;
}
////////////////////////////////////////////////////////////////////////////////
bool Permission::confirmed (const Task& task, const std::string& question)
{
if (quit)
if (_quit)
return false;
if (!needConfirmation)
if (!_need_confirmation)
return true;
if (allConfirmed)
if (_all_confirmed)
return true;
std::cout << "\n"
@ -75,13 +75,13 @@ bool Permission::confirmed (const Task& task, const std::string& question)
std::cout << "\n"; // #499
if (answer == 2)
allConfirmed = true;
_all_confirmed = true;
if (answer == 1 || answer == 2)
return true;
if (answer == 3)
quit = true;
_quit = true;
return false;
}

View file

@ -38,14 +38,14 @@ public:
Permission (const Permission&);
Permission& operator= (const Permission&);
void bigChange () { needConfirmation = true; }
void bigSequence () { needConfirmation = true; }
void bigChange () { _need_confirmation = true; }
void bigSequence () { _need_confirmation = true; }
bool confirmed (const Task&, const std::string&);
private:
bool needConfirmation;
bool allConfirmed;
bool quit;
bool _need_confirmation;
bool _all_confirmed;
bool _quit;
};
#endif

View file

@ -144,34 +144,34 @@ void readTaskmods (std::vector <std::string> &input,
// [TDB::unlock]
//
TDB::TDB ()
: mLock (true)
, mAllOpenAndLocked (false)
, mId (1)
: _lock (true)
, _all_opened_and_locked (false)
, _id (1)
{
}
////////////////////////////////////////////////////////////////////////////////
TDB::~TDB ()
{
if (mAllOpenAndLocked)
if (_all_opened_and_locked)
unlock ();
}
////////////////////////////////////////////////////////////////////////////////
void TDB::clear ()
{
mLocations.clear ();
mLock = true;
_locations.clear ();
_lock = true;
if (mAllOpenAndLocked)
if (_all_opened_and_locked)
unlock ();
mAllOpenAndLocked = false;
mId = 1;
mPending.clear ();
mNew.clear ();
mCompleted.clear ();
mModified.clear ();
_all_opened_and_locked = false;
_id = 1;
_pending.clear ();
_new.clear ();
_completed.clear ();
_modified.clear ();
}
////////////////////////////////////////////////////////////////////////////////
@ -183,53 +183,53 @@ void TDB::location (const std::string& path)
path +
"' does not exist, or is not readable and writable.";
mLocations.push_back (Location (d));
_locations.push_back (Location (d));
}
////////////////////////////////////////////////////////////////////////////////
void TDB::lock (bool lockFile /* = true */)
{
mLock = lockFile;
_lock = lockFile;
mPending.clear ();
mNew.clear ();
mCompleted.clear ();
mModified.clear ();
_pending.clear ();
_new.clear ();
_completed.clear ();
_modified.clear ();
foreach (location, mLocations)
foreach (location, _locations)
{
location->pending = openAndLock (location->path + "/pending.data");
location->completed = openAndLock (location->path + "/completed.data");
location->undo = openAndLock (location->path + "/undo.data");
location->_pending = openAndLock (location->_path + "/pending.data");
location->_completed = openAndLock (location->_path + "/completed.data");
location->_undo = openAndLock (location->_path + "/undo.data");
}
mAllOpenAndLocked = true;
_all_opened_and_locked = true;
}
////////////////////////////////////////////////////////////////////////////////
void TDB::unlock ()
{
// Do not clear out these items, as they may be used in a read-only fashion.
// mPending.clear ();
// mNew.clear ();
// mModified.clear ();
// _pending.clear ();
// _new.clear ();
// _modified.clear ();
foreach (location, mLocations)
foreach (location, _locations)
{
fflush (location->pending);
fclose (location->pending);
location->pending = NULL;
fflush (location->_pending);
fclose (location->_pending);
location->_pending = NULL;
fflush (location->completed);
fclose (location->completed);
location->completed = NULL;
fflush (location->_completed);
fclose (location->_completed);
location->_completed = NULL;
fflush (location->undo);
fclose (location->undo);
location->completed = NULL;
fflush (location->_undo);
fclose (location->_undo);
location->_completed = NULL;
}
mAllOpenAndLocked = false;
_all_opened_and_locked = false;
}
////////////////////////////////////////////////////////////////////////////////
@ -280,32 +280,32 @@ int TDB::loadPending (std::vector <Task>& tasks)
try
{
// Only load if not already loaded.
if (mPending.size () == 0)
if (_pending.size () == 0)
{
mId = 1;
_id = 1;
char line[T_LINE_MAX];
foreach (location, mLocations)
foreach (location, _locations)
{
line_number = 1;
file = location->path + "/pending.data";
file = location->_path + "/pending.data";
fseek (location->pending, 0, SEEK_SET);
while (fgets (line, T_LINE_MAX, location->pending))
fseek (location->_pending, 0, SEEK_SET);
while (fgets (line, T_LINE_MAX, location->_pending))
{
int length = strlen (line);
if (length > 3) // []\n
{
// TODO Add hidden attribute indicating source?
Task task (line);
task.id = mId++;
task.id = _id++;
mPending.push_back (task);
_pending.push_back (task);
// Maintain mapping for ease of link/dependency resolution.
// Note that this mapping is not restricted by the filter, and is
// therefore a complete set.
mI2U[task.id] = task.get ("uuid");
mU2I[task.get ("uuid")] = task.id;
_I2U[task.id] = task.get ("uuid");
_U2I[task.get ("uuid")] = task.id;
}
++line_number;
@ -314,13 +314,13 @@ int TDB::loadPending (std::vector <Task>& tasks)
}
// Now filter and return.
foreach (task, mPending)
foreach (task, _pending)
tasks.push_back (*task);
// Hand back any accumulated additions, if TDB::loadPending is being called
// repeatedly.
int fakeId = mId;
foreach (task, mNew)
int fakeId = _id;
foreach (task, _new)
{
task->id = fakeId++;
tasks.push_back (*task);
@ -348,16 +348,16 @@ int TDB::loadCompleted (std::vector <Task>& tasks)
try
{
if (mCompleted.size () == 0)
if (_completed.size () == 0)
{
char line[T_LINE_MAX];
foreach (location, mLocations)
foreach (location, _locations)
{
line_number = 1;
file = location->path + "/completed.data";
file = location->_path + "/completed.data";
fseek (location->completed, 0, SEEK_SET);
while (fgets (line, T_LINE_MAX, location->completed))
fseek (location->_completed, 0, SEEK_SET);
while (fgets (line, T_LINE_MAX, location->_completed))
{
int length = strlen (line);
if (length > 3) // []\n
@ -367,7 +367,7 @@ int TDB::loadCompleted (std::vector <Task>& tasks)
Task task (line);
task.id = 0; // Need a value, just not a valid value.
mCompleted.push_back (task);
_completed.push_back (task);
}
++line_number;
@ -376,7 +376,7 @@ int TDB::loadCompleted (std::vector <Task>& tasks)
}
// Now filter and return.
foreach (task, mCompleted)
foreach (task, _completed)
tasks.push_back (*task);
}
@ -393,29 +393,29 @@ int TDB::loadCompleted (std::vector <Task>& tasks)
////////////////////////////////////////////////////////////////////////////////
const std::vector <Task>& TDB::getAllPending ()
{
return mPending;
return _pending;
}
////////////////////////////////////////////////////////////////////////////////
const std::vector <Task>& TDB::getAllNew ()
{
return mNew;
return _new;
}
////////////////////////////////////////////////////////////////////////////////
const std::vector <Task>& TDB::getAllCompleted ()
{
return mCompleted;
return _completed;
}
////////////////////////////////////////////////////////////////////////////////
const std::vector <Task>& TDB::getAllModified ()
{
return mModified;
return _modified;
}
////////////////////////////////////////////////////////////////////////////////
// Note: mLocations[0] is where all tasks are written.
// Note: _locations[0] is where all tasks are written.
void TDB::add (const Task& task)
{
std::string unique;
@ -429,21 +429,21 @@ void TDB::add (const Task& task)
// If the tasks are loaded, then verify that this uuid is not already in
// the file.
if (uuidAlreadyUsed (unique, mNew) ||
uuidAlreadyUsed (unique, mModified) ||
uuidAlreadyUsed (unique, mPending) ||
uuidAlreadyUsed (unique, mCompleted))
if (uuidAlreadyUsed (unique, _new) ||
uuidAlreadyUsed (unique, _modified) ||
uuidAlreadyUsed (unique, _pending) ||
uuidAlreadyUsed (unique, _completed))
throw std::string ("Cannot add task because the uuid '") + unique + "' is not unique.";
mNew.push_back (t);
mI2U[task.id] = unique;
mU2I[task.get ("uuid")] = t.id;
_new.push_back (t);
_I2U[task.id] = unique;
_U2I[task.get ("uuid")] = t.id;
}
////////////////////////////////////////////////////////////////////////////////
void TDB::update (const Task& task)
{
mModified.push_back (task);
_modified.push_back (task);
}
////////////////////////////////////////////////////////////////////////////////
@ -453,35 +453,35 @@ int TDB::commit ()
{
context.timer_gc.start ();
int quantity = mNew.size () + mModified.size ();
int quantity = _new.size () + _modified.size ();
// This is an optimization. If there are only new tasks, and none were
// modified, simply seek to the end of pending and write.
if (mNew.size () && ! mModified.size ())
if (_new.size () && ! _modified.size ())
{
fseek (mLocations[0].pending, 0, SEEK_END);
foreach (task, mNew)
fseek (_locations[0]._pending, 0, SEEK_END);
foreach (task, _new)
{
mPending.push_back (*task);
fputs (task->composeF4 ().c_str (), mLocations[0].pending);
_pending.push_back (*task);
fputs (task->composeF4 ().c_str (), _locations[0]._pending);
}
fseek (mLocations[0].undo, 0, SEEK_END);
foreach (task, mNew)
writeUndo (*task, mLocations[0].undo);
fseek (_locations[0]._undo, 0, SEEK_END);
foreach (task, _new)
writeUndo (*task, _locations[0]._undo);
mNew.clear ();
_new.clear ();
return quantity;
}
// The alternative is to potentially rewrite both files.
else if (mNew.size () || mModified.size ())
else if (_new.size () || _modified.size ())
{
// allPending is a copy of mPending, with all modifications included, and
// allPending is a copy of _pending, with all modifications included, and
// new tasks appended.
std::vector <Task> allPending;
allPending = mPending;
foreach (mtask, mModified)
allPending = _pending;
foreach (mtask, _modified)
{
foreach (task, allPending)
{
@ -496,29 +496,29 @@ int TDB::commit ()
;
}
foreach (task, mNew)
foreach (task, _new)
allPending.push_back (*task);
// Write out all pending.
if (fseek (mLocations[0].pending, 0, SEEK_SET) == 0)
if (fseek (_locations[0]._pending, 0, SEEK_SET) == 0)
{
if (ftruncate (fileno (mLocations[0].pending), 0))
if (ftruncate (fileno (_locations[0]._pending), 0))
throw std::string ("Failed to truncate pending.data file ");
foreach (task, allPending)
fputs (task->composeF4 ().c_str (), mLocations[0].pending);
fputs (task->composeF4 ().c_str (), _locations[0]._pending);
}
// Update the undo log.
if (fseek (mLocations[0].undo, 0, SEEK_END) == 0)
if (fseek (_locations[0]._undo, 0, SEEK_END) == 0)
{
foreach (mtask, mModified)
foreach (mtask, _modified)
{
foreach (task, mPending)
foreach (task, _pending)
{
if (task->id == mtask->id)
{
writeUndo (*task, *mtask, mLocations[0].undo);
writeUndo (*task, *mtask, _locations[0]._undo);
goto next_mod2;
}
}
@ -527,14 +527,14 @@ int TDB::commit ()
;
}
foreach (task, mNew)
writeUndo (*task, mLocations[0].undo);
foreach (task, _new)
writeUndo (*task, _locations[0]._undo);
}
mPending = allPending;
_pending = allPending;
mModified.clear ();
mNew.clear ();
_modified.clear ();
_new.clear ();
}
context.timer_gc.stop ();
@ -561,10 +561,10 @@ int TDB::gc ()
int count_completed_changes = 0;
Date now;
if (mNew.size ())
if (_new.size ())
throw std::string ("Unexpected new tasks found during gc.");
if (mModified.size ())
if (_modified.size ())
throw std::string ("Unexpected modified tasks found during gc.");
lock ();
@ -575,7 +575,7 @@ int TDB::gc ()
// Search for dangling dependencies. These are dependencies whose uuid cannot
// be converted to an id by TDB.
std::vector <std::string> deps;
foreach (task, mPending)
foreach (task, _pending)
{
if (task->has ("depends"))
{
@ -600,7 +600,7 @@ int TDB::gc ()
// completed list. Isn't garbage collection easy?
std::vector <Task> still_pending;
std::vector <Task> newly_completed;
foreach (task, mPending)
foreach (task, _pending)
{
Task::status s = task->getStatus ();
if (s == Task::completed ||
@ -633,16 +633,16 @@ int TDB::gc ()
// No commit - all updates performed manually.
if (count_pending_changes > 0)
{
if (fseek (mLocations[0].pending, 0, SEEK_SET) == 0)
if (fseek (_locations[0]._pending, 0, SEEK_SET) == 0)
{
if (ftruncate (fileno (mLocations[0].pending), 0))
if (ftruncate (fileno (_locations[0]._pending), 0))
throw std::string ("Failed to truncate pending.data file ");
foreach (task, still_pending)
fputs (task->composeF4 ().c_str (), mLocations[0].pending);
fputs (task->composeF4 ().c_str (), _locations[0]._pending);
// Update cached copy.
mPending = still_pending;
_pending = still_pending;
}
}
@ -650,9 +650,9 @@ int TDB::gc ()
// whole list.
if (count_completed_changes > 0)
{
fseek (mLocations[0].completed, 0, SEEK_END);
fseek (_locations[0]._completed, 0, SEEK_END);
foreach (task, newly_completed)
fputs (task->composeF4 ().c_str (), mLocations[0].completed);
fputs (task->composeF4 ().c_str (), _locations[0]._completed);
}
// Close files.
@ -669,7 +669,7 @@ int TDB::gc ()
////////////////////////////////////////////////////////////////////////////////
int TDB::nextId ()
{
return mId++;
return _id++;
}
////////////////////////////////////////////////////////////////////////////////
@ -677,9 +677,9 @@ void TDB::undo ()
{
Directory location (context.config.get ("data.location"));
std::string undoFile = location.data + "/undo.data";
std::string pendingFile = location.data + "/pending.data";
std::string completedFile = location.data + "/completed.data";
std::string undoFile = location._data + "/undo.data";
std::string pendingFile = location._data + "/pending.data";
std::string completedFile = location._data + "/completed.data";
// load undo.data
std::vector <std::string> u;
@ -1043,7 +1043,7 @@ void TDB::merge (const std::string& mergeFile)
// load undo file (left/local branch)
Directory location (context.config.get ("data.location"));
std::string undoFile = location.data + "/undo.data";
std::string undoFile = location._data + "/undo.data";
std::vector <std::string> l;
if (! File::read (undoFile, l))
@ -1364,10 +1364,10 @@ void TDB::merge (const std::string& mergeFile)
if (!mods.empty ())
{
std::string pendingFile = location.data + "/pending.data";
std::string pendingFile = location._data + "/pending.data";
std::vector <std::string> pending;
std::string completedFile = location.data + "/completed.data";
std::string completedFile = location._data + "/completed.data";
std::vector <std::string> completed;
if (! File::read (pendingFile, pending))
@ -1560,7 +1560,7 @@ void TDB::merge (const std::string& mergeFile)
std::string TDB::uuid (int id) const
{
std::map <int, std::string>::const_iterator i;
if ((i = mI2U.find (id)) != mI2U.end ())
if ((i = _I2U.find (id)) != _I2U.end ())
return i->second;
return "";
@ -1570,7 +1570,7 @@ std::string TDB::uuid (int id) const
int TDB::id (const std::string& uuid) const
{
std::map <std::string, int>::const_iterator i;
if ((i = mU2I.find (uuid)) != mU2I.end ())
if ((i = _U2I.find (uuid)) != _U2I.end ())
return i->second;
return 0;
@ -1595,7 +1595,7 @@ FILE* TDB::openAndLock (const std::string& file)
throw std::string ("Could not open '") + file + "'.";
// Lock if desired. Try three times before failing.
if (mLock)
if (_lock)
{
int retry = 0;
while (flock (fileno (in), LOCK_NB | LOCK_EX) && ++retry <= 3)

View file

@ -80,18 +80,18 @@ private:
bool uuidAlreadyUsed (const std::string&, const std::vector <Task>&);
private:
std::vector <Location> mLocations;
bool mLock;
bool mAllOpenAndLocked;
int mId;
std::vector <Location> _locations;
bool _lock;
bool _all_opened_and_locked;
int _id;
std::vector <Task> mPending; // Contents of pending.data
std::vector <Task> mCompleted; // Contents of pending.data
std::vector <Task> mNew; // Uncommitted new tasks
std::vector <Task> mModified; // Uncommitted modified tasks
std::vector <Task> _pending; // Contents of pending.data
std::vector <Task> _completed; // Contents of pending.data
std::vector <Task> _new; // Uncommitted new tasks
std::vector <Task> _modified; // Uncommitted modified tasks
std::map <int, std::string> mI2U; // ID -> UUID map
std::map <std::string, int> mU2I; // UUID -> ID map
std::map <int, std::string> _I2U; // ID -> UUID map
std::map <std::string, int> _U2I; // UUID -> ID map
};
#endif

View file

@ -62,7 +62,7 @@ void TF2::target (const std::string& f)
////////////////////////////////////////////////////////////////////////////////
const std::vector <Task>& TF2::get_tasks ()
{
// std::cout << "# TF2::get_tasks " << _file.data << "\n";
// std::cout << "# TF2::get_tasks " << _file._data << "\n";
if (! _loaded_tasks)
load_tasks ();
@ -73,7 +73,7 @@ const std::vector <Task>& TF2::get_tasks ()
////////////////////////////////////////////////////////////////////////////////
const std::vector <std::string>& TF2::get_lines ()
{
// std::cout << "# TF2::get_lines " << _file.data << "\n";
// std::cout << "# TF2::get_lines " << _file._data << "\n";
if (! _loaded_lines)
load_lines ();
@ -84,7 +84,7 @@ const std::vector <std::string>& TF2::get_lines ()
////////////////////////////////////////////////////////////////////////////////
const std::string& TF2::get_contents ()
{
// std::cout << "# TF2::get_contents " << _file.data << "\n";
// std::cout << "# TF2::get_contents " << _file._data << "\n";
if (! _loaded_contents)
load_contents ();
@ -95,7 +95,7 @@ const std::string& TF2::get_contents ()
////////////////////////////////////////////////////////////////////////////////
void TF2::add_task (const Task& task)
{
// std::cout << "# TF2::add_task " << _file.data << "\n";
// std::cout << "# TF2::add_task " << _file._data << "\n";
_tasks.push_back (task); // For subsequent queries
_added_tasks.push_back (task); // For commit/synch
@ -112,7 +112,7 @@ void TF2::add_task (const Task& task)
////////////////////////////////////////////////////////////////////////////////
void TF2::modify_task (const Task& task)
{
// std::cout << "# TF2::modify_task " << _file.data << "\n";
// std::cout << "# TF2::modify_task " << _file._data << "\n";
// Modify in-place.
std::vector <Task>::iterator i;
@ -132,7 +132,7 @@ void TF2::modify_task (const Task& task)
////////////////////////////////////////////////////////////////////////////////
void TF2::add_line (const std::string& line)
{
// std::cout << "# TF2::add_line " << _file.data << "\n";
// std::cout << "# TF2::add_line " << _file._data << "\n";
_added_lines.push_back (line);
_dirty = true;
@ -142,7 +142,7 @@ void TF2::add_line (const std::string& line)
// This is so that synch.key can just overwrite and not grow.
void TF2::clear_lines ()
{
// std::cout << "# TF2::clear_lines " << _file.data << "\n";
// std::cout << "# TF2::clear_lines " << _file._data << "\n";
_lines.clear ();
_dirty = true;
}
@ -151,7 +151,7 @@ void TF2::clear_lines ()
// Top-down recomposition.
void TF2::commit ()
{
// std::cout << "# TF2::commit " << _file.data << "\n";
// std::cout << "# TF2::commit " << _file._data << "\n";
// The _dirty flag indicates that the file needs to be written.
if (_dirty)
@ -227,7 +227,7 @@ void TF2::commit ()
////////////////////////////////////////////////////////////////////////////////
void TF2::load_tasks ()
{
// std::cout << "# TF2::load_tasks " << _file.data << "\n";
// std::cout << "# TF2::load_tasks " << _file._data << "\n";
context.timer_load.start ();
if (! _loaded_lines)
@ -266,7 +266,7 @@ void TF2::load_tasks ()
catch (std::string& e)
{
throw e + format (" in {1} at line {2}", _file.data, line_number);
throw e + format (" in {1} at line {2}", _file._data, line_number);
}
context.timer_load.stop ();
@ -275,7 +275,7 @@ void TF2::load_tasks ()
////////////////////////////////////////////////////////////////////////////////
void TF2::load_lines ()
{
// std::cout << "# TF2::load_lines " << _file.data << "\n";
// std::cout << "# TF2::load_lines " << _file._data << "\n";
if (! _loaded_contents)
load_contents ();
@ -287,7 +287,7 @@ void TF2::load_lines ()
////////////////////////////////////////////////////////////////////////////////
void TF2::load_contents ()
{
// std::cout << "# TF2::load_contents " << _file.data << "\n";
// std::cout << "# TF2::load_contents " << _file._data << "\n";
_contents = "";
@ -345,9 +345,9 @@ const std::string TF2::dump ()
// File label.
std::string label;
std::string::size_type slash = _file.data.rfind ('/');
std::string::size_type slash = _file._data.rfind ('/');
if (slash != std::string::npos)
label = rightJustify (_file.data.substr (slash + 1), 14);
label = rightJustify (_file._data.substr (slash + 1), 14);
// File mode.
std::string mode = std::string (_file.readable () ? "r" : "-") +

View file

@ -36,19 +36,19 @@
////////////////////////////////////////////////////////////////////////////////
Taskmod::Taskmod ()
{
timestamp = 0;
bAfterSet = false;
bBeforeSet = false;
_timestamp = 0;
_bAfterSet = false;
_bBeforeSet = false;
}
////////////////////////////////////////////////////////////////////////////////
Taskmod::Taskmod (const Taskmod& other)
{
this->before = other.before;
this->after = other.after;
this->timestamp = other.timestamp;
this->bAfterSet = other.bAfterSet;
this->bBeforeSet = other.bBeforeSet;
this->_before = other._before;
this->_after = other._after;
this->_timestamp = other._timestamp;
this->_bAfterSet = other._bAfterSet;
this->_bBeforeSet = other._bBeforeSet;
}
////////////////////////////////////////////////////////////////////////////////
@ -59,21 +59,21 @@ Taskmod::~Taskmod ()
////////////////////////////////////////////////////////////////////////////////
bool Taskmod::operator< (const Taskmod &compare)
{
return (timestamp < compare.getTimestamp ());
return (_timestamp < compare.getTimestamp ());
}
////////////////////////////////////////////////////////////////////////////////
bool Taskmod::operator> (const Taskmod &compare)
{
return (timestamp > compare.getTimestamp ());
return (_timestamp > compare.getTimestamp ());
}
////////////////////////////////////////////////////////////////////////////////
bool Taskmod::operator== (const Taskmod& compare)
{
return ( (compare.after == this->after)
&& (compare.before == this->before)
&& (compare.timestamp == this->timestamp) );
return ( (compare._after == this->_after)
&& (compare._before == this->_before)
&& (compare._timestamp == this->_timestamp) );
}
////////////////////////////////////////////////////////////////////////////////
@ -87,11 +87,11 @@ Taskmod& Taskmod::operator= (const Taskmod& other)
{
if (this != &other)
{
this->before = other.before;
this->after = other.after;
this->timestamp = other.timestamp;
this->bAfterSet = other.bAfterSet;
this->bBeforeSet = other.bBeforeSet;
this->_before = other._before;
this->_after = other._after;
this->_timestamp = other._timestamp;
this->_bAfterSet = other._bAfterSet;
this->_bBeforeSet = other._bBeforeSet;
}
return *this;
@ -100,58 +100,58 @@ Taskmod& Taskmod::operator= (const Taskmod& other)
////////////////////////////////////////////////////////////////////////////////
void Taskmod::reset (long timestamp)
{
this->bAfterSet = false;
this->bBeforeSet = false;
this->timestamp = timestamp;
this->_bAfterSet = false;
this->_bBeforeSet = false;
this->_timestamp = timestamp;
}
////////////////////////////////////////////////////////////////////////////////
bool Taskmod::isNew ()
{
return !bBeforeSet;
return !_bBeforeSet;
}
////////////////////////////////////////////////////////////////////////////////
bool Taskmod::issetAfter ()
{
return bAfterSet;
return _bAfterSet;
}
////////////////////////////////////////////////////////////////////////////////
bool Taskmod::issetBefore ()
{
return bBeforeSet;
return _bBeforeSet;
}
////////////////////////////////////////////////////////////////////////////////
bool Taskmod::isValid ()
{
return (timestamp > 0) && (bAfterSet);
return (_timestamp > 0) && (_bAfterSet);
}
////////////////////////////////////////////////////////////////////////////////
std::string Taskmod::getUuid ()
{
if (!bAfterSet)
if (!_bAfterSet)
throw std::string (STRING_TASKMOD_BAD_INIT);
return after.get ("uuid");
return _after.get ("uuid");
}
////////////////////////////////////////////////////////////////////////////////
std::string Taskmod::toString ()
{
assert (bAfterSet);
assert (_bAfterSet);
std::stringstream stream;
stream << STRING_TASKMOD_TIME << timestamp << "\n";
stream << STRING_TASKMOD_TIME << _timestamp << "\n";
if (bBeforeSet)
if (_bBeforeSet)
{
stream << STRING_TASKMOD_OLD << before.composeF4();
stream << STRING_TASKMOD_OLD << _before.composeF4();
}
stream << STRING_TASKMOD_NEW << after.composeF4();
stream << STRING_TASKMOD_NEW << _after.composeF4();
stream << "---\n";
return stream.str ();
@ -160,46 +160,46 @@ std::string Taskmod::toString ()
////////////////////////////////////////////////////////////////////////////////
void Taskmod::setAfter (const Task& after)
{
this->after = after;
this->bAfterSet = true;
this->_after = after;
this->_bAfterSet = true;
}
////////////////////////////////////////////////////////////////////////////////
void Taskmod::setBefore (const Task& before)
{
this->before = before;
this->bBeforeSet = true;
this->_before = before;
this->_bBeforeSet = true;
}
////////////////////////////////////////////////////////////////////////////////
void Taskmod::setTimestamp (long timestamp)
{
this->timestamp = timestamp;
this->_timestamp = timestamp;
}
////////////////////////////////////////////////////////////////////////////////
Task& Taskmod::getAfter ()
{
return after;
return _after;
}
////////////////////////////////////////////////////////////////////////////////
Task& Taskmod::getBefore ()
{
return before;
return _before;
}
////////////////////////////////////////////////////////////////////////////////
long Taskmod::getTimestamp () const
{
return timestamp;
return _timestamp;
}
////////////////////////////////////////////////////////////////////////////////
std::string Taskmod::getTimeStr () const
{
std::stringstream sstream;
sstream << timestamp;
sstream << _timestamp;
return sstream.str ();
}

View file

@ -66,11 +66,11 @@ public:
std::string getTimeStr () const;
protected:
Task after;
Task before;
long timestamp;
bool bAfterSet;
bool bBeforeSet;
Task _after;
Task _before;
long _timestamp;
bool _bAfterSet;
bool _bBeforeSet;
};
#endif

View file

@ -38,8 +38,8 @@
////////////////////////////////////////////////////////////////////////////////
Transport::Transport (const Uri& uri)
{
executable = "";
this->uri = uri;
_executable = "";
this->_uri = uri;
}
////////////////////////////////////////////////////////////////////////////////
@ -50,17 +50,17 @@ Transport::~Transport ()
////////////////////////////////////////////////////////////////////////////////
Transport* Transport::getTransport(const Uri& uri)
{
if (uri.protocol == "ssh")
if (uri._protocol == "ssh")
{
return new TransportSSH(uri);
}
else if (uri.protocol == "rsync")
else if (uri._protocol == "rsync")
{
return new TransportRSYNC(uri);
}
else if ( (uri.protocol == "http")
|| (uri.protocol == "https")
|| (uri.protocol == "ftp") )
else if ( (uri._protocol == "http")
|| (uri._protocol == "https")
|| (uri._protocol == "ftp") )
{
return new TransportCurl(uri);
}
@ -71,7 +71,7 @@ Transport* Transport::getTransport(const Uri& uri)
////////////////////////////////////////////////////////////////////////////////
int Transport::execute()
{
return ::execute(executable, arguments);
return ::execute(_executable, _arguments);
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -46,10 +46,10 @@ public:
static bool is_filelist(const std::string&);
protected:
std::string executable;
std::vector<std::string> arguments;
std::string _executable;
std::vector<std::string> _arguments;
Uri uri;
Uri _uri;
int execute();
};

View file

@ -35,19 +35,19 @@
////////////////////////////////////////////////////////////////////////////////
TransportCurl::TransportCurl(const Uri& uri) : Transport(uri)
{
executable = "curl";
_executable = "curl";
}
////////////////////////////////////////////////////////////////////////////////
void TransportCurl::send(const std::string& source)
{
if (uri.host == "")
if (_uri._host == "")
throw std::string (STRING_TRANSPORT_CURL_URI);
if (uri.user != "")
if (_uri._user != "")
{
arguments.push_back("--user");
arguments.push_back(uri.user);
_arguments.push_back("--user");
_arguments.push_back(_uri._user);
}
if (is_filelist(source))
@ -58,26 +58,26 @@ void TransportCurl::send(const std::string& source)
if (pos == std::string::npos)
throw std::string (STRING_TRANSPORT_CURL_WILDCD);
if (!uri.is_directory())
throw format (STRING_TRANSPORT_URI_NODIR, uri.path);
if (!_uri.is_directory())
throw format (STRING_TRANSPORT_URI_NODIR, _uri._path);
arguments.push_back ("-T");
arguments.push_back ("\"" + source + "\"");
_arguments.push_back ("-T");
_arguments.push_back ("\"" + source + "\"");
}
else
{
arguments.push_back ("-T");
arguments.push_back (source);
_arguments.push_back ("-T");
_arguments.push_back (source);
}
// cmd line is: curl -T source protocol://host:port/path
if (uri.port != "")
if (_uri._port != "")
{
arguments.push_back (uri.protocol + "://" + uri.host + ":" + uri.port + "/" + uri.path);
_arguments.push_back (_uri._protocol + "://" + _uri._host + ":" + _uri._port + "/" + _uri._path);
}
else
{
arguments.push_back (uri.protocol + "://" + uri.host + "/" + uri.path);
_arguments.push_back (_uri._protocol + "://" + _uri._host + "/" + _uri._path);
}
int result = execute();
@ -93,20 +93,20 @@ void TransportCurl::send(const std::string& source)
////////////////////////////////////////////////////////////////////////////////
void TransportCurl::recv(std::string target)
{
if (uri.host == "")
if (_uri._host == "")
throw std::string (STRING_TRANSPORT_CURL_URI);
if (uri.user != "")
if (_uri._user != "")
{
arguments.push_back("--user");
arguments.push_back(uri.user);
_arguments.push_back("--user");
_arguments.push_back(_uri._user);
}
if (is_filelist(uri.path))
if (is_filelist(_uri._path))
{
std::string::size_type pos;
pos = uri.path.find("{");
pos = _uri._path.find("{");
if (pos == std::string::npos)
throw std::string (STRING_TRANSPORT_CURL_WILDCD);
@ -118,7 +118,7 @@ void TransportCurl::recv(std::string target)
std::string suffix;
std::string prefix = target;
std::vector<std::string> splitted;
toSplit = uri.path.substr (pos+1);
toSplit = _uri._path.substr (pos+1);
pos = toSplit.find ("}");
suffix = toSplit.substr (pos+1);
split (splitted, toSplit.substr(0, pos), ',');
@ -135,16 +135,16 @@ void TransportCurl::recv(std::string target)
}
// cmd line is: curl protocol://host:port/path/to/source/file -o path/to/target/file
if (uri.port != "")
if (_uri._port != "")
{
arguments.push_back (uri.protocol + "://" + uri.host + ":" + uri.port + "/" + uri.path);
_arguments.push_back (_uri._protocol + "://" + _uri._host + ":" + _uri._port + "/" + _uri._path);
}
else
{
arguments.push_back (uri.protocol + "://" + uri.host + "/" + uri.path);
_arguments.push_back (_uri._protocol + "://" + _uri._host + "/" + _uri._path);
}
arguments.push_back (target);
_arguments.push_back (target);
int result = execute();
if (result)

View file

@ -34,35 +34,35 @@
////////////////////////////////////////////////////////////////////////////////
TransportRSYNC::TransportRSYNC(const Uri& uri) : Transport(uri)
{
executable = "rsync";
_executable = "rsync";
}
////////////////////////////////////////////////////////////////////////////////
void TransportRSYNC::send(const std::string& source)
{
if (uri.host == "")
if (_uri._host == "")
throw std::string (STRING_TRANSPORT_RSYNC_URI);
// Is there more than one file to transfer?
// Then path has to end with a '/'
if (is_filelist(source) && !uri.is_directory())
throw format (STRING_TRANSPORT_URI_NODIR, uri.path);
if (is_filelist(source) && !_uri.is_directory())
throw format (STRING_TRANSPORT_URI_NODIR, _uri._path);
// cmd line is: rsync [--port=PORT] source [user@]host::path
if (uri.port != "")
if (_uri._port != "")
{
arguments.push_back ("--port=" + uri.port);
_arguments.push_back ("--port=" + _uri._port);
}
arguments.push_back (source);
_arguments.push_back (source);
if (uri.user != "")
if (_uri._user != "")
{
arguments.push_back (uri.user + "@" + uri.host + "::" + uri.path);
_arguments.push_back (_uri._user + "@" + _uri._host + "::" + _uri._path);
}
else
{
arguments.push_back (uri.host + "::" + uri.path);
_arguments.push_back (_uri._host + "::" + _uri._path);
}
if (execute())
@ -72,28 +72,28 @@ void TransportRSYNC::send(const std::string& source)
////////////////////////////////////////////////////////////////////////////////
void TransportRSYNC::recv(std::string target)
{
if (uri.host == "")
if (_uri._host == "")
throw std::string (STRING_TRANSPORT_RSYNC_URI);
// Is there more than one file to transfer?
// Then target has to end with a '/'
if (is_filelist(uri.path) && !is_directory(target))
if (is_filelist(_uri._path) && !is_directory(target))
throw format (STRING_TRANSPORT_URI_NODIR, target);
// cmd line is: rsync [--port=PORT] [user@]host::path target
if (uri.port != "")
arguments.push_back ("--port=" + uri.port);
if (_uri._port != "")
_arguments.push_back ("--port=" + _uri._port);
if (uri.user != "")
if (_uri._user != "")
{
arguments.push_back (uri.user + "@" + uri.host + "::" + uri.path);
_arguments.push_back (_uri._user + "@" + _uri._host + "::" + _uri._path);
}
else
{
arguments.push_back (uri.host + "::" + uri.path);
_arguments.push_back (_uri._host + "::" + _uri._path);
}
arguments.push_back (target);
_arguments.push_back (target);
if (execute())
throw std::string (STRING_TRANSPORT_RSYNC_NORUN);

View file

@ -34,36 +34,36 @@
////////////////////////////////////////////////////////////////////////////////
TransportSSH::TransportSSH(const Uri& uri) : Transport(uri)
{
executable = "scp";
_executable = "scp";
}
////////////////////////////////////////////////////////////////////////////////
void TransportSSH::send(const std::string& source)
{
if (uri.host == "")
if (_uri._host == "")
throw std::string (STRING_TRANSPORT_SSH_URI);
// Is there more than one file to transfer?
// Then path has to end with a '/'
if (is_filelist(source) && !uri.is_directory())
throw format (STRING_TRANSPORT_URI_NODIR, uri.path);
if (is_filelist(source) && !_uri.is_directory())
throw format (STRING_TRANSPORT_URI_NODIR, _uri._path);
// cmd line is: scp [-p port] [user@]host:path
if (uri.port != "")
if (_uri._port != "")
{
arguments.push_back ("-P");
arguments.push_back (uri.port);
_arguments.push_back ("-P");
_arguments.push_back (_uri._port);
}
arguments.push_back (source);
_arguments.push_back (source);
if (uri.user != "")
if (_uri._user != "")
{
arguments.push_back (uri.user + "@" + uri.host + ":" + uri.path);
_arguments.push_back (_uri._user + "@" + _uri._host + ":" + _uri._path);
}
else
{
arguments.push_back (uri.host + ":" + uri.path);
_arguments.push_back (_uri._host + ":" + _uri._path);
}
if (execute())
@ -73,31 +73,31 @@ void TransportSSH::send(const std::string& source)
////////////////////////////////////////////////////////////////////////////////
void TransportSSH::recv(std::string target)
{
if (uri.host == "")
if (_uri._host == "")
throw std::string (STRING_TRANSPORT_SSH_URI);
// Is there more than one file to transfer?
// Then target has to end with a '/'
if (is_filelist(uri.path) && !is_directory(target))
if (is_filelist(_uri._path) && !is_directory(target))
throw format (STRING_TRANSPORT_URI_NODIR, target);
// cmd line is: scp [-p port] [user@]host:path
if (uri.port != "")
if (_uri._port != "")
{
arguments.push_back ("-P");
arguments.push_back (uri.port);
_arguments.push_back ("-P");
_arguments.push_back (_uri._port);
}
if (uri.user != "")
if (_uri._user != "")
{
arguments.push_back (uri.user + "@" + uri.host + ":" + uri.path);
_arguments.push_back (_uri._user + "@" + _uri._host + ":" + _uri._path);
}
else
{
arguments.push_back (uri.host + ":" + uri.path);
_arguments.push_back (_uri._host + ":" + _uri._path);
}
arguments.push_back (target);
_arguments.push_back (target);
if (execute())
throw std::string (STRING_TRANSPORT_SSH_NORUN);

View file

@ -37,7 +37,7 @@ extern Context context;
////////////////////////////////////////////////////////////////////////////////
Uri::Uri ()
{
parsed = false;
_parsed = false;
}
////////////////////////////////////////////////////////////////////////////////
@ -45,21 +45,21 @@ Uri::Uri (const Uri& other)
{
if (this != &other)
{
data = other.data;
host = other.host;
path = other.path;
user = other.user;
port = other.port;
protocol = other.protocol;
parsed = other.parsed;
_data = other._data;
_host = other._host;
_path = other._path;
_user = other._user;
_port = other._port;
_protocol = other._protocol;
_parsed = other._parsed;
}
}
////////////////////////////////////////////////////////////////////////////////
Uri::Uri (const std::string& in, const std::string& configPrefix)
{
data = in;
parsed = false;
_data = in;
_parsed = false;
if (configPrefix != "")
expand(configPrefix);
}
@ -74,13 +74,13 @@ Uri& Uri::operator= (const Uri& other)
{
if (this != &other)
{
this->data = other.data;
this->host = other.host;
this->path = other.path;
this->user = other.user;
this->port = other.port;
this->protocol = other.protocol;
this->parsed = other.parsed;
this->_data = other._data;
this->_host = other._host;
this->_path = other._path;
this->_user = other._user;
this->_port = other._port;
this->_protocol = other._protocol;
this->_parsed = other._parsed;
}
return *this;
@ -89,30 +89,30 @@ Uri& Uri::operator= (const Uri& other)
////////////////////////////////////////////////////////////////////////////////
Uri::operator std::string () const
{
return data;
return _data;
}
////////////////////////////////////////////////////////////////////////////////
std::string Uri::name () const
{
if (path.length ())
if (_path.length ())
{
std::string::size_type slash = path.rfind ('/');
std::string::size_type slash = _path.rfind ('/');
if (slash != std::string::npos)
return path.substr (slash + 1, std::string::npos);
return _path.substr (slash + 1, std::string::npos);
}
return path;
return _path;
}
////////////////////////////////////////////////////////////////////////////////
std::string Uri::parent () const
{
if (path.length ())
if (_path.length ())
{
std::string::size_type slash = path.rfind ('/');
std::string::size_type slash = _path.rfind ('/');
if (slash != std::string::npos)
return path.substr (0, slash+1);
return _path.substr (0, slash+1);
}
return "";
@ -121,11 +121,11 @@ std::string Uri::parent () const
////////////////////////////////////////////////////////////////////////////////
std::string Uri::extension () const
{
if (path.length ())
if (_path.length ())
{
std::string::size_type dot = path.rfind ('.');
std::string::size_type dot = _path.rfind ('.');
if (dot != std::string::npos)
return path.substr (dot + 1, std::string::npos);
return _path.substr (dot + 1, std::string::npos);
}
return "";
@ -135,21 +135,21 @@ std::string Uri::extension () const
bool Uri::is_directory () const
{
if (is_local ()) {
return Path (this->data).is_directory ();
return Path (this->_data).is_directory ();
} else
return (path == ".")
|| (path == "")
|| (path[path.length()-1] == '/');
return (_path == ".")
|| (_path == "")
|| (_path[_path.length()-1] == '/');
}
////////////////////////////////////////////////////////////////////////////////
bool Uri::is_local () const
{
if (parsed)
return (protocol == "");
if (_parsed)
return (_protocol == "");
else
return ( (data.find("://") == std::string::npos)
&& (data.find(":") == std::string::npos) );
return ( (_data.find("://") == std::string::npos)
&& (_data.find(":") == std::string::npos) );
}
////////////////////////////////////////////////////////////////////////////////
@ -157,7 +157,7 @@ bool Uri::append (const std::string& path)
{
if (is_directory ())
{
this->path += path;
this->_path += path;
return true;
}
else
@ -168,10 +168,10 @@ bool Uri::append (const std::string& path)
bool Uri::expand (const std::string& configPrefix )
{
std::string tmp;
if (data.length ())
if (_data.length ())
{
// try to replace argument with uri from config
tmp = context.config.get (configPrefix + "." + data + ".uri");
tmp = context.config.get (configPrefix + "." + _data + ".uri");
}
else
{
@ -181,7 +181,7 @@ bool Uri::expand (const std::string& configPrefix )
if (tmp != "")
{
data = tmp;
_data = tmp;
return true;
}
@ -191,90 +191,90 @@ bool Uri::expand (const std::string& configPrefix )
////////////////////////////////////////////////////////////////////////////////
void Uri::parse ()
{
if (parsed)
if (_parsed)
return;
if (is_local ())
{
path = data;
parsed = true;
_path = _data;
_parsed = true;
return;
}
std::string::size_type pos;
std::string data = this->data;
std::string _data = this->_data;
std::string pathDelimiter = "/";
user = "";
port = "";
_user = "";
_port = "";
// skip ^.*://
if ((pos = data.find ("://")) != std::string::npos)
if ((pos = _data.find ("://")) != std::string::npos)
{
protocol = data.substr(0, pos);
data = data.substr (pos+3);
_protocol = _data.substr(0, pos);
_data = _data.substr (pos+3);
// standard syntax: protocol://[user@]host.xz[:port]/path/to/undo.data
pathDelimiter = "/";
}
else
{
protocol = "ssh";
_protocol = "ssh";
// scp-like syntax: [user@]host.xz:path/to/undo.data
pathDelimiter = ":";
}
// user delimited by single quotes?
if ( data[0] == '\''
&& (pos = data.find("'", 1)) != std::string::npos )
if ( _data[0] == '\''
&& (pos = _data.find("'", 1)) != std::string::npos )
{
if (data[pos+1] == '@')
if (_data[pos+1] == '@')
{
// end of user name
user = data.substr (1, pos-1);
data = data.substr (pos+2);
_user = _data.substr (1, pos-1);
_data = _data.substr (pos+2);
}
else
{
throw std::string (format (STRING_URI_QUOTES, data));
throw std::string (format (STRING_URI_QUOTES, _data));
}
}
else
{
// find user name
if ((pos = data.find ("@")) != std::string::npos)
if ((pos = _data.find ("@")) != std::string::npos)
{
user = data.substr (0, pos);
data = data.substr (pos+1);
_user = _data.substr (0, pos);
_data = _data.substr (pos+1);
}
}
// get host, port and path
if ((pos = data.find (pathDelimiter)) != std::string::npos)
if ((pos = _data.find (pathDelimiter)) != std::string::npos)
{
host = data.substr (0, pos);
path = data.substr (pos+1);
_host = _data.substr (0, pos);
_path = _data.substr (pos+1);
}
else
{
throw std::string (format (STRING_URI_BAD_FORMAT, data));
throw std::string (format (STRING_URI_BAD_FORMAT, _data));
}
// path is absolute for ssh:// syntax
if ( (protocol == "ssh") && (pathDelimiter == "/") )
if ( (_protocol == "ssh") && (pathDelimiter == "/") )
{
path = "/" + path;
_path = "/" + _path;
}
// port specified?
// remark: this find() will never be != npos for scp-like syntax
// because we found pathDelimiter, which is ":", before
if ((pos = host.find (":")) != std::string::npos)
if ((pos = _host.find (":")) != std::string::npos)
{
port = host.substr (pos+1);
host = host.substr (0,pos);
_port = _host.substr (pos+1);
_host = _host.substr (0,pos);
}
parsed = true;
_parsed = true;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -57,13 +57,13 @@ public:
void parse ();
public:
std::string data;
std::string path;
std::string host;
std::string port;
std::string user;
std::string protocol;
bool parsed;
std::string _data;
std::string _path;
std::string _host;
std::string _port;
std::string _user;
std::string _protocol;
bool _parsed;
};
#endif

View file

@ -79,7 +79,7 @@ int CmdConfig::execute (std::string& output)
// Read .taskrc (or equivalent)
std::vector <std::string> contents;
File::read (context.config.original_file, contents);
File::read (context.config._original_file, contents);
// task config name value
// task config name ""
@ -157,9 +157,9 @@ int CmdConfig::execute (std::string& output)
// Write .taskrc (or equivalent)
if (change)
{
File::write (context.config.original_file, contents);
File::write (context.config._original_file, contents);
out << "Config file "
<< context.config.original_file.data
<< context.config._original_file._data
<< " modified.\n";
}
else

View file

@ -178,17 +178,17 @@ int CmdDiagnostics::execute (std::string& output)
// Config: .taskrc found, readable, writable
out << bold.colorize ("Configuration")
<< "\n"
<< " File: " << context.config.original_file.data
<< (context.config.original_file.exists () ? " (found)" : " (missing)")
<< ", " << context.config.original_file.size () << " bytes"
<< " File: " << context.config._original_file._data
<< (context.config._original_file.exists () ? " (found)" : " (missing)")
<< ", " << context.config._original_file.size () << " bytes"
<< ", mode "
<< std::setbase (8)
<< context.config.original_file.mode ()
<< context.config._original_file.mode ()
<< "\n";
// Config: data.location found, readable, writable
File location (context.config.get ("data.location"));
out << " Data: " << location.data
out << " Data: " << location._data
<< (location.exists () ? " (found)" : " (missing)")
<< ", " << (location.is_directory () ? "dir" : "?")
<< ", mode "

View file

@ -600,11 +600,11 @@ bool CmdEdit::editFile (Task& task)
// Create a temp file name in data.location.
std::stringstream file;
file << "task." << getpid () << "." << task.id << ".task";
std::string path = location.data + "/" + file.str ();
std::string path = location._data + "/" + file.str ();
// Format the contents, T -> text, write to a file.
std::string before = formatTask (task);
int ignored = chdir (location.data.c_str ());
int ignored = chdir (location._data.c_str ());
++ignored; // Keep compiler quiet.
File::write (file.str (), before);

View file

@ -77,7 +77,7 @@ int CmdInfo::execute (std::string& output)
if (context.config.getBoolean ("journal.info"))
{
Directory location (context.config.get ("data.location"));
std::string undoFile = location.data + "/undo.data";
std::string undoFile = location._data + "/undo.data";
File::read (undoFile, undo);
}

View file

@ -63,7 +63,7 @@ int CmdMerge::execute (std::string& output)
Uri uri (file, "merge");
uri.parse();
if (uri.data.length ())
if (uri._data.length ())
{
Directory location (context.config.get ("data.location"));
@ -73,14 +73,14 @@ int CmdMerge::execute (std::string& output)
Transport* transport;
if ((transport = Transport::getTransport (uri)) != NULL )
{
tmpfile = location.data + "/undo_remote.data";
tmpfile = location._data + "/undo_remote.data";
transport->recv (tmpfile);
delete transport;
file = tmpfile;
}
else
file = uri.path;
file = uri._path;
context.tdb.lock (context.config.getBoolean ("locking"));
context.tdb.merge (file);
@ -91,10 +91,10 @@ int CmdMerge::execute (std::string& output)
if (tmpfile != "")
remove (tmpfile.c_str ());
if ( ((sAutopush == "ask") && (confirm ("Would you like to push the merged changes to \'" + uri.data + "\'?")) )
if ( ((sAutopush == "ask") && (confirm ("Would you like to push the merged changes to \'" + uri._data + "\'?")) )
|| (bAutopush) )
{
// context.task.set ("description", uri.data);
// context.task.set ("description", uri._data);
std::string out;
context.commands["push"]->execute (out);

View file

@ -56,59 +56,59 @@ int CmdPull::execute (std::string& output)
Uri uri (file, "pull");
uri.parse ();
if (uri.data.length ())
if (uri._data.length ())
{
Directory location (context.config.get ("data.location"));
if (! uri.append ("{pending,undo,completed}.data"))
throw std::string ("The uri '") + uri.path + "' is not a directory. Did you forget a trailing '/'?";
throw std::string ("The uri '") + uri._path + "' is not a directory. Did you forget a trailing '/'?";
Transport* transport;
if ((transport = Transport::getTransport (uri)) != NULL)
{
transport->recv (location.data + "/");
transport->recv (location._data + "/");
delete transport;
}
else
{
// Verify that files are not being copied from rc.data.location to the
// same place.
if (Directory (uri.path) == Directory (context.config.get ("data.location")))
if (Directory (uri._path) == Directory (context.config.get ("data.location")))
throw std::string ("Cannot pull files when the source and destination are the same.");
// copy files locally
// remove {pending,undo,completed}.data
uri.path = uri.parent();
uri._path = uri.parent();
Path path1 (uri.path + "undo.data");
Path path2 (uri.path + "pending.data");
Path path3 (uri.path + "completed.data");
Path path1 (uri._path + "undo.data");
Path path2 (uri._path + "pending.data");
Path path3 (uri._path + "completed.data");
if (path1.exists() && path2.exists() && path3.exists())
{
// if (confirm ("xxxxxxxxxxxxx"))
// {
std::ofstream ofile1 ((location.data + "/undo.data").c_str(), std::ios_base::binary);
std::ifstream ifile1 (path1.data.c_str() , std::ios_base::binary);
std::ofstream ofile1 ((location._data + "/undo.data").c_str(), std::ios_base::binary);
std::ifstream ifile1 (path1._data.c_str() , std::ios_base::binary);
ofile1 << ifile1.rdbuf();
std::ofstream ofile2 ((location.data + "/pending.data").c_str(), std::ios_base::binary);
std::ifstream ifile2 (path2.data.c_str() , std::ios_base::binary);
std::ofstream ofile2 ((location._data + "/pending.data").c_str(), std::ios_base::binary);
std::ifstream ifile2 (path2._data.c_str() , std::ios_base::binary);
ofile2 << ifile2.rdbuf();
std::ofstream ofile3 ((location.data + "/completed.data").c_str(), std::ios_base::binary);
std::ifstream ifile3 (path3.data.c_str() , std::ios_base::binary);
std::ofstream ofile3 ((location._data + "/completed.data").c_str(), std::ios_base::binary);
std::ifstream ifile3 (path3._data.c_str() , std::ios_base::binary);
ofile3 << ifile3.rdbuf();
// }
}
else
{
throw std::string ("At least one of the database files in '" + uri.path + "' is not present.");
throw std::string ("At least one of the database files in '" + uri._path + "' is not present.");
}
}
output += "Tasks transferred from " + uri.data + "\n";
output += "Tasks transferred from " + uri._data + "\n";
}
else
throw std::string ("No uri was specified for the pull. Either specify "

View file

@ -46,7 +46,7 @@ CmdPush::CmdPush ()
}
////////////////////////////////////////////////////////////////////////////////
// Transfers the local data (from rc.location.data) to the remote path. Because
// Transfers the local data (from rc.location._data) to the remote path. Because
// this is potentially on another machine, no checking can be performed.
int CmdPush::execute (std::string& output)
{
@ -58,41 +58,41 @@ int CmdPush::execute (std::string& output)
Uri uri (file, "push");
uri.parse ();
if (uri.data.length ())
if (uri._data.length ())
{
Directory location (context.config.get ("data.location"));
Transport* transport;
if ((transport = Transport::getTransport (uri)) != NULL )
{
transport->send (location.data + "/{pending,undo,completed}.data");
transport->send (location._data + "/{pending,undo,completed}.data");
delete transport;
}
else
{
// Verify that files are not being copied from rc.data.location to the
// same place.
if (Directory (uri.path) == Directory (context.config.get ("data.location")))
if (Directory (uri._path) == Directory (context.config.get ("data.location")))
throw std::string ("Cannot push files when the source and destination are the same.");
// copy files locally
if (! Path (uri.data).is_directory ())
throw std::string ("The uri '") + uri.path + "' is not a local directory.";
if (! Path (uri._data).is_directory ())
throw std::string ("The uri '") + uri._path + "' is not a local directory.";
std::ifstream ifile1 ((location.data + "/undo.data").c_str(), std::ios_base::binary);
std::ofstream ofile1 ((uri.path + "/undo.data").c_str(), std::ios_base::binary);
std::ifstream ifile1 ((location._data + "/undo.data").c_str(), std::ios_base::binary);
std::ofstream ofile1 ((uri._path + "/undo.data").c_str(), std::ios_base::binary);
ofile1 << ifile1.rdbuf();
std::ifstream ifile2 ((location.data + "/pending.data").c_str(), std::ios_base::binary);
std::ofstream ofile2 ((uri.path + "/pending.data").c_str(), std::ios_base::binary);
std::ifstream ifile2 ((location._data + "/pending.data").c_str(), std::ios_base::binary);
std::ofstream ofile2 ((uri._path + "/pending.data").c_str(), std::ios_base::binary);
ofile2 << ifile2.rdbuf();
std::ifstream ifile3 ((location.data + "/completed.data").c_str(), std::ios_base::binary);
std::ofstream ofile3 ((uri.path + "/completed.data").c_str(), std::ios_base::binary);
std::ifstream ifile3 ((location._data + "/completed.data").c_str(), std::ios_base::binary);
std::ofstream ofile3 ((uri._path + "/completed.data").c_str(), std::ios_base::binary);
ofile3 << ifile3.rdbuf();
}
output += "Local tasks transferred to " + uri.data + "\n";
output += "Local tasks transferred to " + uri._data + "\n";
}
else
throw std::string ("No uri was specified for the push. Either specify "

View file

@ -410,7 +410,7 @@ int CmdShow::execute (std::string& output)
{
Directory location (context.config.get ("data.location"));
if (location.data == "")
if (location._data == "")
out << STRING_CMD_SHOW_NO_LOCATION << "\n";
if (! location.exists ())

View file

@ -63,13 +63,13 @@ int CmdStatistics::execute (std::string& output)
size_t dataSize = 0;
Directory location (context.config.get ("data.location"));
File pending (location.data + "/pending.data");
File pending (location._data + "/pending.data");
dataSize += pending.size ();
File completed (location.data + "/completed.data");
File completed (location._data + "/completed.data");
dataSize += completed.size ();
File undo (location.data + "/undo.data");
File undo (location._data + "/undo.data");
dataSize += undo.size ();
std::vector <std::string> undoTxns;

1
test/.gitignore vendored
View file

@ -24,7 +24,6 @@ rx.t
sensor.t
seq.t
subst.t
t.benchmark.t
t.t
t2.t
taskmod.t

View file

@ -8,8 +8,8 @@ include_directories (${CMAKE_SOURCE_DIR}
set (test_SRCS att.t autocomplete.t color.t config.t date.t directory.t dom.t
duration.t file.t i18n.t json.t list.t nibbler.t path.t rx.t
t.benchmark.t t.t t2.t taskmod.t tdb.t tdb2.t text.t uri.t util.t
view.t json_test)
t.t t2.t taskmod.t tdb.t tdb2.t text.t uri.t util.t view.t
json_test)
add_custom_target (test ./run_all DEPENDS ${test_SRCS}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test)

View file

@ -41,20 +41,20 @@ int main (int argc, char** argv)
Directory d0 (Path ("/tmp"));
Directory d1 (File ("/tmp"));
Directory d2 (File (Path ("/tmp")));
t.is (d0.data, d1.data, "Directory(std::string) == Directory (File&)");
t.is (d0.data, d2.data, "Directory(std::string) == Directory (File (Path &))");
t.is (d1.data, d2.data, "Directory(File&)) == Directory (File (Path &))");
t.is (d0._data, d1._data, "Directory(std::string) == Directory (File&)");
t.is (d0._data, d2._data, "Directory(std::string) == Directory (File (Path &))");
t.is (d1._data, d2._data, "Directory(File&)) == Directory (File (Path &))");
// Directory (const Directory&);
Directory d3 (d2);
t.is (d3.data, "/tmp", "Directory (Directory&)");
t.is (d3._data, "/tmp", "Directory (Directory&)");
// Directory (const std::string&);
Directory d4 ("/tmp/test_directory");
// Directory& operator= (const Directory&);
Directory d5 = d4;
t.is (d5.data, "/tmp/test_directory", "Directory::operator=");
t.is (d5._data, "/tmp/test_directory", "Directory::operator=");
// operator (std::string) const;
t.is ((std::string) d3, "/tmp", "Directory::operator (std::string) const");
@ -63,11 +63,11 @@ int main (int argc, char** argv)
t.ok (d5.create (), "Directory::create /tmp/test_directory");
t.ok (d5.exists (), "Directory::exists /tmp/test_directory");
Directory d6 (d5.data + "/dir");
Directory d6 (d5._data + "/dir");
t.ok (d6.create (), "Directory::create /tmp/test_directory/dir");
File::create (d5.data + "/f0");
File::create (d6.data + "/f1");
File::create (d5._data + "/f0");
File::create (d6._data + "/f1");
// std::vector <std::string> list ();
std::vector <std::string> files = d5.list ();
@ -84,8 +84,8 @@ int main (int argc, char** argv)
t.is (files[1], "/tmp/test_directory/f0", "file is /tmp/test_directory/f0");
// virtual bool remove ();
t.ok (File::remove (d5.data + "/f0"), "File::remove /tmp/test_directory/f0");
t.ok (File::remove (d6.data + "/f1"), "File::remove /tmp/test_directory/dir/f1");
t.ok (File::remove (d5._data + "/f0"), "File::remove /tmp/test_directory/f0");
t.ok (File::remove (d6._data + "/f1"), "File::remove /tmp/test_directory/dir/f1");
t.ok (d6.remove (), "Directory::remove /tmp/test_directory/dir");
t.notok (d6.exists (), "Directory::exists /tmp/test_directory/dir - no");
@ -96,10 +96,10 @@ int main (int argc, char** argv)
// bool remove (const std::string&);
Directory d7 ("/tmp/to_be_removed");
t.ok (d7.create (), "Directory::create /tmp/to_be_removed");
File::create (d7.data + "/f0");
Directory d8 (d7.data + "/another");
File::create (d7._data + "/f0");
Directory d8 (d7._data + "/another");
t.ok (d8.create (), "Directory::create /tmp/to_be_removed/another");
File::create (d8.data + "/f1");
File::create (d8._data + "/f1");
t.ok (d7.remove (), "Directory::remove /tmp/to_be_removed");
t.notok (d7.exists (), "Directory /tmp/to_be_removed gone");

View file

@ -37,22 +37,22 @@ int main (int argc, char** argv)
// Path ();
Path p0;
t.ok (p0.data == "", "Path::Path");
t.ok (p0._data == "", "Path::Path");
// Path (const Path&);
Path p1 = Path ("foo");
t.ok (p1.data == "foo", "Path::operator=");
t.ok (p1._data == "foo", "Path::operator=");
// Path (const std::string&);
Path p2 ("~");
t.ok (p2.data != "~", "~ expanded to " + p2.data);
t.ok (p2._data != "~", "~ expanded to " + p2._data);
Path p3 ("/tmp");
t.ok (p3.data == "/tmp", "/tmp -> /tmp");
t.ok (p3._data == "/tmp", "/tmp -> /tmp");
// Path& operator= (const Path&);
Path p3_copy (p3);
t.is (p3.data, p3_copy.data, "Path::Path (Path&)");
t.is (p3._data, p3_copy._data, "Path::Path (Path&)");
// operator (std::string) const;
t.is ((std::string) p3, "/tmp", "Path::operator (std::string) const");

View file

@ -39,41 +39,41 @@ int main (int argc, char** argv)
Uri uri1 ("asfd://user@host/folder/");
uri1.parse ();
t.is (uri1.user, "user", "Uri::parse() : asdf://user@host/folder/");
t.is (uri1.host, "host", "Uri::parse() : asdf://user@host/folder/");
t.is (uri1.port, "", "Uri::parse() : asdf://user@host/folder/");
t.is (uri1.path, "folder/", "Uri::parse() : asdf://user@host/folder/");
t.is (uri1.protocol, "asfd", "Uri::parse() : asdf://user@host/folder/");
t.is (uri1._user, "user", "Uri::parse() : asdf://user@host/folder/");
t.is (uri1._host, "host", "Uri::parse() : asdf://user@host/folder/");
t.is (uri1._port, "", "Uri::parse() : asdf://user@host/folder/");
t.is (uri1._path, "folder/", "Uri::parse() : asdf://user@host/folder/");
t.is (uri1._protocol, "asfd", "Uri::parse() : asdf://user@host/folder/");
t.ok (uri1.append ("file.test"), "Uri::append() to path");
t.is (uri1.path, "folder/file.test", "Uri::append() ok");
t.is (uri1._path, "folder/file.test", "Uri::append() ok");
Uri uri2 ("user@host:folder/file.test");
uri2.parse ();
t.is (uri2.user, "user", "Uri::parse() : user@host:folder/file.test");
t.is (uri2.host, "host", "Uri::parse() : user@host:folder/file.test");
t.is (uri2.port, "", "Uri::parse() : user@host/folder/file.test");
t.is (uri2.path, "folder/file.test", "Uri::parse() : user@host/folder/file.test");
t.is (uri2.protocol, "ssh", "Uri::parse() : user@host/folder/file.test");
t.is (uri2._user, "user", "Uri::parse() : user@host:folder/file.test");
t.is (uri2._host, "host", "Uri::parse() : user@host:folder/file.test");
t.is (uri2._port, "", "Uri::parse() : user@host/folder/file.test");
t.is (uri2._path, "folder/file.test", "Uri::parse() : user@host/folder/file.test");
t.is (uri2._protocol, "ssh", "Uri::parse() : user@host/folder/file.test");
t.notok (uri2.append ("test.dat"), "Uri::append() to file");
Uri uri3 ("rsync://hostname.abc.de:1234//abs/path");
uri3.parse ();
t.is (uri3.user, "", "Uri::parse() : rsync://hostname.abc.de:1234//abs/path");
t.is (uri3.host, "hostname.abc.de", "Uri::parse() : rsync://hostname.abc.de:1234//abs/path");
t.is (uri3.port, "1234", "Uri::parse() : rsync://hostname.abc.de:1234//abs/path");
t.is (uri3.path, "/abs/path", "Uri::parse() : rsync://hostname.abc.de:1234//abs/path");
t.is (uri3.protocol, "rsync", "Uri::parse() : rsync://hostname.abc.de:1234//abs/path");
t.is (uri3._user, "", "Uri::parse() : rsync://hostname.abc.de:1234//abs/path");
t.is (uri3._host, "hostname.abc.de", "Uri::parse() : rsync://hostname.abc.de:1234//abs/path");
t.is (uri3._port, "1234", "Uri::parse() : rsync://hostname.abc.de:1234//abs/path");
t.is (uri3._path, "/abs/path", "Uri::parse() : rsync://hostname.abc.de:1234//abs/path");
t.is (uri3._protocol, "rsync", "Uri::parse() : rsync://hostname.abc.de:1234//abs/path");
Uri uri4 ("hostname:");
uri4.parse ();
t.is (uri4.user, "", "Uri::parse() : hostname:");
t.is (uri4.host, "hostname", "Uri::parse() : hostname:");
t.is (uri4.port, "", "Uri::parse() : hostname:");
t.is (uri4.path, "", "Uri::parse() : hostname:");
t.is (uri4.protocol, "ssh", "Uri::parse() : hostname:");
t.is (uri4._user, "", "Uri::parse() : hostname:");
t.is (uri4._host, "hostname", "Uri::parse() : hostname:");
t.is (uri4._port, "", "Uri::parse() : hostname:");
t.is (uri4._path, "", "Uri::parse() : hostname:");
t.is (uri4._protocol, "ssh", "Uri::parse() : hostname:");
t.notok (uri4.is_local (), "Uri::is_local() : hostname:");
t.ok (uri4.append ("file.test"), "Uri::append() : hostname:");
t.is (uri4.path, "file.test","Uri::append() : ok");
t.is (uri4._path, "file.test","Uri::append() : ok");
context.config.set ("merge.default.uri", "../folder/");
context.config.set ("push.test.uri", "/home/user/.task/");
@ -81,53 +81,52 @@ int main (int argc, char** argv)
Uri uri5 ("", "merge");
t.ok (uri5.is_local (), "Uri::is_local() : ../server/");
uri5.parse ();
t.is (uri5.path, "../folder/", "Uri::expand() default");
t.is (uri5._path, "../folder/", "Uri::expand() default");
Uri uri6 ("test", "push");
t.ok (uri6.is_local(), "Uri::is_local() : /home/user/.task/");
uri6.parse ();
t.is (uri6.path, "/home/user/.task/", "Uri::expand() test");
t.is (uri6._path, "/home/user/.task/", "Uri::expand() test");
Uri uri7 ("ftp://'user@name'@host:321/path/to/x");
uri7.parse ();
t.is (uri7.user, "user@name", "Uri::parse() : ftp://'user@name'@host:321/path/to/x");
t.is (uri7.host, "host", "Uri::parse() : ftp://'user@name'@host:321/path/to/x");
t.is (uri7.port, "321", "Uri::parse() : ftp://'user@name'@host:321/path/to/x");
t.is (uri7.path, "path/to/x", "Uri::parse() : ftp://'user@name'@host:321/path/to/x");
t.is (uri7.protocol, "ftp", "Uri::parse() : ftp://'user@name'@host:321/path/to/x");
t.is (uri7._user, "user@name", "Uri::parse() : ftp://'user@name'@host:321/path/to/x");
t.is (uri7._host, "host", "Uri::parse() : ftp://'user@name'@host:321/path/to/x");
t.is (uri7._port, "321", "Uri::parse() : ftp://'user@name'@host:321/path/to/x");
t.is (uri7._path, "path/to/x", "Uri::parse() : ftp://'user@name'@host:321/path/to/x");
t.is (uri7._protocol, "ftp", "Uri::parse() : ftp://'user@name'@host:321/path/to/x");
Uri uri8 ("http://'us/er@n:ame'@host/path/to/x");
uri8.parse ();
t.is (uri8.user, "us/er@n:ame", "Uri::parse() : http://'us/er@n:ame'@host/path/to/x");
t.is (uri8.host, "host", "Uri::parse() : http://'us/er@n:ame'@host/path/to/x");
t.is (uri8.port, "", "Uri::parse() : http://'us/er@n:ame'@host/path/to/x");
t.is (uri8.path, "path/to/x", "Uri::parse() : http://'us/er@n:ame'@host/path/to/x");
t.is (uri8.protocol, "http", "Uri::parse() : http://'us/er@n:ame'@host/path/to/x");
t.is (uri8._user, "us/er@n:ame", "Uri::parse() : http://'us/er@n:ame'@host/path/to/x");
t.is (uri8._host, "host", "Uri::parse() : http://'us/er@n:ame'@host/path/to/x");
t.is (uri8._port, "", "Uri::parse() : http://'us/er@n:ame'@host/path/to/x");
t.is (uri8._path, "path/to/x", "Uri::parse() : http://'us/er@n:ame'@host/path/to/x");
t.is (uri8._protocol, "http", "Uri::parse() : http://'us/er@n:ame'@host/path/to/x");
Uri uri9 ("'user@name'@host:path/to/x");
uri9.parse ();
t.is (uri9.user, "user@name", "Uri::parse() : 'user@name'@host:path/to/x");
t.is (uri9.host, "host", "Uri::parse() : 'user@name'@host:path/to/x");
t.is (uri9.port, "", "Uri::parse() : 'user@name'@host:path/to/x");
t.is (uri9.path, "path/to/x", "Uri::parse() : 'user@name'@host:path/to/x");
t.is (uri9._user, "user@name", "Uri::parse() : 'user@name'@host:path/to/x");
t.is (uri9._host, "host", "Uri::parse() : 'user@name'@host:path/to/x");
t.is (uri9._port, "", "Uri::parse() : 'user@name'@host:path/to/x");
t.is (uri9._path, "path/to/x", "Uri::parse() : 'user@name'@host:path/to/x");
// bug #668
Uri uri10 ("user.name@host.com:undo.data");
uri10.parse ();
t.is (uri10.user, "user.name", "Uri::parse() : user.name@host.com:undo.data");
t.is (uri10.host, "host.com", "Uri::parse() : user.name@host.com:undo.data");
t.is (uri10.port, "", "Uri::parse() : user.name@host.com:undo.data");
t.is (uri10.path, "undo.data", "Uri::parse() : user.name@host.com:undo.data");
t.is (uri10.protocol, "ssh", "Uri::parse() : user.name@host.com:undo.data");
t.is (uri10._user, "user.name", "Uri::parse() : user.name@host.com:undo.data");
t.is (uri10._host, "host.com", "Uri::parse() : user.name@host.com:undo.data");
t.is (uri10._port, "", "Uri::parse() : user.name@host.com:undo.data");
t.is (uri10._path, "undo.data", "Uri::parse() : user.name@host.com:undo.data");
t.is (uri10._protocol, "ssh", "Uri::parse() : user.name@host.com:undo.data");
Uri uri11 ("ssh://user.name@host.com/undo.data");
uri11.parse ();
t.is (uri11.user, "user.name", "Uri::parse() : ssh://user.name@host.com/undo.data");
t.is (uri11.host, "host.com", "Uri::parse() : ssh://user.name@host.com/undo.data");
t.is (uri11.port, "", "Uri::parse() : ssh://user.name@host.com/undo.data");
t.is (uri11.path, "/undo.data", "Uri::parse() : ssh://user.name@host.com/undo.data");
t.is (uri11.protocol, "ssh", "Uri::parse() : ssh://user.name@host.com/undo.data");
t.is (uri11._user, "user.name", "Uri::parse() : ssh://user.name@host.com/undo.data");
t.is (uri11._host, "host.com", "Uri::parse() : ssh://user.name@host.com/undo.data");
t.is (uri11._port, "", "Uri::parse() : ssh://user.name@host.com/undo.data");
t.is (uri11._path, "/undo.data", "Uri::parse() : ssh://user.name@host.com/undo.data");
t.is (uri11._protocol, "ssh", "Uri::parse() : ssh://user.name@host.com/undo.data");
return 0;
}