diff --git a/src/A3.cpp b/src/A3.cpp index 581b245fb..d927484fc 100644 --- a/src/A3.cpp +++ b/src/A3.cpp @@ -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. diff --git a/src/API.cpp b/src/API.cpp index 22c7f32f4..41ea099eb 100644 --- a/src/API.cpp +++ b/src/API.cpp @@ -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); } } diff --git a/src/API.h b/src/API.h index d3fe362b9..e0b5a3c39 100644 --- a/src/API.h +++ b/src/API.h @@ -58,12 +58,12 @@ private: void loadFile (const std::string&); public: - lua_State* L; - std::vector loaded; + lua_State* _L; + std::vector _loaded; // Context for the API. // std::vector all; - Task current; + Task _current; // std::string& name; // std::string& value; }; diff --git a/src/Att.cpp b/src/Att.cpp index 536b2e632..0c471cfed 100644 --- a/src/Att.cpp +++ b/src/Att.cpp @@ -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; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Att.h b/src/Att.h index 80feb6b9e..592c7dfd4 100644 --- a/src/Att.h +++ b/src/Att.h @@ -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 diff --git a/src/Color.cpp b/src/Color.cpp index a53730461..b0b95ca49 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -62,26 +62,26 @@ 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 | - _COLOR_INVERSE | _COLOR_BOLD | _COLOR_BRIGHT | _COLOR_BG | - _COLOR_FG); + _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) - | ((bold ? 1 : 0) << 17) - | ((bright ? 1 : 0) << 16); + _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 (); } } diff --git a/src/Color.h b/src/Color.h index 2422f58cf..98130ada5 100644 --- a/src/Color.h +++ b/src/Color.h @@ -73,7 +73,7 @@ private: std::string bg () const; private: - unsigned int value; + unsigned int _value; }; #endif diff --git a/src/Config.cpp b/src/Config.cpp index 50b97814f..3102b6e10 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -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); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Config.h b/src/Config.h index 07d6ff1a8..14c125a97 100644 --- a/src/Config.h +++ b/src/Config.h @@ -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 diff --git a/src/Context.cpp b/src/Context.cpp index 2018c30e4..383c603e1 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -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); diff --git a/src/Date.cpp b/src/Date.cpp index b9522dd99..b11dfda8c 100644 --- a/src/Date.cpp +++ b/src/Date.cpp @@ -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; } } diff --git a/src/Date.h b/src/Date.h index c28c0733c..0691c3a81 100644 --- a/src/Date.h +++ b/src/Date.h @@ -114,7 +114,7 @@ private: bool isRelativeDate (const std::string&); protected: - time_t mT; + time_t _t; }; #endif diff --git a/src/Directory.cpp b/src/Directory.cpp index 15488a2bd..1dc4af5c0 100644 --- a/src/Directory.cpp +++ b/src/Directory.cpp @@ -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 Directory::list () { std::vector files; - list (data, files, false); + list (_data, files, false); return files; } @@ -138,7 +138,7 @@ std::vector Directory::list () std::vector Directory::listRecursive () { std::vector files; - list (data, files, true); + list (_data, files, true); return files; } diff --git a/src/Duration.cpp b/src/Duration.cpp index 34e1f2a55..9f311de8c 100644 --- a/src/Duration.cpp +++ b/src/Duration.cpp @@ -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 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); } diff --git a/src/Duration.h b/src/Duration.h index 318ef9370..98f7b1cb5 100644 --- a/src/Duration.h +++ b/src/Duration.h @@ -64,8 +64,8 @@ public: static const std::vector get_units (); protected: - time_t mSecs; - bool mNegative; + time_t _secs; + bool _negative; }; #endif diff --git a/src/File.cpp b/src/File.cpp index 55bf44e94..a194e9775 100644 --- a/src/File.cpp +++ b/src/File.cpp @@ -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 & 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 & 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 & lines) { - if (!fh) + if (!_fh) open (); - if (fh) + if (_fh) { std::vector ::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 & 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 & lines) { - if (!fh) + if (!_fh) open (); - if (fh) + if (_fh) { - fseek (fh, 0, SEEK_END); + fseek (_fh, 0, SEEK_END); std::vector ::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; diff --git a/src/File.h b/src/File.h index c5c41c5f3..2acf98aaa 100644 --- a/src/File.h +++ b/src/File.h @@ -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 diff --git a/src/Hooks.cpp b/src/Hooks.cpp index 0cd904f4c..78624d880 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -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 ::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 ::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; diff --git a/src/Hooks.h b/src/Hooks.h index b1d6e5004..74d6a84a8 100644 --- a/src/Hooks.h +++ b/src/Hooks.h @@ -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 all; // All current hooks. + std::vector _all; // All current hooks. - std::vector validProgramEvents; - std::vector validTaskEvents; + std::vector _validProgramEvents; + std::vector _validTaskEvents; }; #endif diff --git a/src/Location.cpp b/src/Location.cpp index 357e2639a..afc06c916 100644 --- a/src/Location.cpp +++ b/src/Location.cpp @@ -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; diff --git a/src/Location.h b/src/Location.h index 225696c12..41c03e2ae 100644 --- a/src/Location.h +++ b/src/Location.h @@ -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 diff --git a/src/Nibbler.cpp b/src/Nibbler.cpp index 646ab0439..8c7380bb9 100644 --- a/src/Nibbler.cpp +++ b/src/Nibbler.cpp @@ -41,35 +41,35 @@ const char* c_digits = "0123456789"; //////////////////////////////////////////////////////////////////////////////// Nibbler::Nibbler () -: mInput ("") -, mLength (0) -, mCursor (0) -, mSaved (0) +: _input ("") +, _length (0) +, _cursor (0) +, _saved (0) { } //////////////////////////////////////////////////////////////////////////////// Nibbler::Nibbler (const char* input) -: mInput (input) -, mLength (strlen (input)) -, mCursor (0) +: _input (input) +, _length (strlen (input)) +, _cursor (0) { } //////////////////////////////////////////////////////////////////////////////// Nibbler::Nibbler (const std::string& input) -: mInput (input) -, mLength (input.length ()) -, mCursor (0) +: _input (input) +, _length (input.length ()) +, _cursor (0) { } //////////////////////////////////////////////////////////////////////////////// Nibbler::Nibbler (const Nibbler& other) { - mInput = other.mInput; - mLength = other.mLength; - mCursor = other.mCursor; + _input = other._input; + _length = other._length; + _cursor = other._cursor; } //////////////////////////////////////////////////////////////////////////////// @@ -77,9 +77,9 @@ Nibbler& Nibbler::operator= (const Nibbler& other) { if (this != &other) { - mInput = other.mInput; - mLength = other.mLength; - mCursor = other.mCursor; + _input = other._input; + _length = other._length; + _cursor = other._cursor; } return *this; @@ -94,18 +94,18 @@ Nibbler::~Nibbler () // Extract up until the next c (but not including) or EOS. bool Nibbler::getUntil (char c, std::string& result) { - if (mCursor < mLength) + if (_cursor < _length) { - std::string::size_type i = mInput.find (c, mCursor); + std::string::size_type i = _input.find (c, _cursor); if (i != std::string::npos) { - result = mInput.substr (mCursor, i - mCursor); - mCursor = i; + result = _input.substr (_cursor, i - _cursor); + _cursor = i; } else { - result = mInput.substr (mCursor); - mCursor = mLength; + result = _input.substr (_cursor); + _cursor = _length; } return true; @@ -117,18 +117,18 @@ bool Nibbler::getUntil (char c, std::string& result) //////////////////////////////////////////////////////////////////////////////// bool Nibbler::getUntil (const std::string& terminator, std::string& result) { - if (mCursor < mLength) + if (_cursor < _length) { - std::string::size_type i = mInput.find (terminator, mCursor); + std::string::size_type i = _input.find (terminator, _cursor); if (i != std::string::npos) { - result = mInput.substr (mCursor, i - mCursor); - mCursor = i; + result = _input.substr (_cursor, i - _cursor); + _cursor = i; } else { - result = mInput.substr (mCursor); - mCursor = mLength; + result = _input.substr (_cursor); + _cursor = _length; } return true; @@ -140,7 +140,7 @@ bool Nibbler::getUntil (const std::string& terminator, std::string& result) //////////////////////////////////////////////////////////////////////////////// bool Nibbler::getUntilRx (const std::string& regex, std::string& result) { - if (mCursor < mLength) + if (_cursor < _length) { std::string modified_regex; if (regex[0] != '(') @@ -151,15 +151,15 @@ bool Nibbler::getUntilRx (const std::string& regex, std::string& result) RX r (modified_regex, true); std::vector start; std::vector end; - if (r.match (start, end, mInput.substr (mCursor))) + if (r.match (start, end, _input.substr (_cursor))) { - result = mInput.substr (mCursor, start[0]); - mCursor += start[0]; + result = _input.substr (_cursor, start[0]); + _cursor += start[0]; } else { - result = mInput.substr (mCursor); - mCursor = mLength; + result = _input.substr (_cursor); + _cursor = _length; } return true; @@ -171,18 +171,18 @@ bool Nibbler::getUntilRx (const std::string& regex, std::string& result) //////////////////////////////////////////////////////////////////////////////// bool Nibbler::getUntilOneOf (const std::string& chars, std::string& result) { - if (mCursor < mLength) + if (_cursor < _length) { - std::string::size_type i = mInput.find_first_of (chars, mCursor); + std::string::size_type i = _input.find_first_of (chars, _cursor); if (i != std::string::npos) { - result = mInput.substr (mCursor, i - mCursor); - mCursor = i; + result = _input.substr (_cursor, i - _cursor); + _cursor = i; } else { - result = mInput.substr (mCursor); - mCursor = mLength; + result = _input.substr (_cursor); + _cursor = _length; } return true; @@ -206,10 +206,10 @@ bool Nibbler::getUntilEOL (std::string& result) //////////////////////////////////////////////////////////////////////////////// bool Nibbler::getUntilEOS (std::string& result) { - if (mCursor < mLength) + if (_cursor < _length) { - result = mInput.substr (mCursor); - mCursor = mLength; + result = _input.substr (_cursor); + _cursor = _length; return true; } @@ -219,10 +219,10 @@ bool Nibbler::getUntilEOS (std::string& result) //////////////////////////////////////////////////////////////////////////////// bool Nibbler::getN (const int quantity, std::string& result) { - if (mCursor + quantity <= mLength) + if (_cursor + quantity <= _length) { - result = mInput.substr (mCursor, quantity); - mCursor += quantity; + result = _input.substr (_cursor, quantity); + _cursor += quantity; return true; } @@ -240,15 +240,15 @@ bool Nibbler::getQuoted ( char current = 0; result = ""; - if (mCursor >= mLength || - mInput[mCursor] != c) + if (_cursor >= _length || + _input[_cursor] != c) { return false; } - for (std::string::size_type i = mCursor; i < mLength; ++i) + for (std::string::size_type i = _cursor; i < _length; ++i) { - current = mInput[i]; + current = _input[i]; if (current == '\\' && !inescape) { @@ -267,7 +267,7 @@ bool Nibbler::getQuoted ( } else { - mCursor = i + 1; + _cursor = i + 1; return true; } } @@ -284,10 +284,10 @@ bool Nibbler::getQuoted ( //////////////////////////////////////////////////////////////////////////////// bool Nibbler::getDigit (int& result) { - if (mCursor < mLength && - isdigit (mInput[mCursor])) + if (_cursor < _length && + isdigit (_input[_cursor])) { - result = mInput[mCursor++] - '0'; + result = _input[_cursor++] - '0'; return true; } @@ -297,24 +297,24 @@ bool Nibbler::getDigit (int& result) //////////////////////////////////////////////////////////////////////////////// bool Nibbler::getInt (int& result) { - std::string::size_type i = mCursor; + std::string::size_type i = _cursor; - if (i < mLength) + if (i < _length) { - if (mInput[i] == '-') + if (_input[i] == '-') ++i; - else if (mInput[i] == '+') + else if (_input[i] == '+') ++i; } // TODO Potential for use of find_first_not_of - while (i < mLength && isdigit (mInput[i])) + while (i < _length && isdigit (_input[i])) ++i; - if (i > mCursor) + if (i > _cursor) { - result = strtoimax (mInput.substr (mCursor, i - mCursor).c_str (), NULL, 10); - mCursor = i; + result = strtoimax (_input.substr (_cursor, i - _cursor).c_str (), NULL, 10); + _cursor = i; return true; } @@ -324,24 +324,24 @@ bool Nibbler::getInt (int& result) //////////////////////////////////////////////////////////////////////////////// bool Nibbler::getHex (int& result) { - std::string::size_type i = mCursor; + std::string::size_type i = _cursor; - if (i < mLength) + if (i < _length) { - if (mInput[i] == '-') + if (_input[i] == '-') ++i; - else if (mInput[i] == '+') + else if (_input[i] == '+') ++i; } // TODO Potential for use of find_first_not_of - while (i < mLength && isxdigit (mInput[i])) + while (i < _length && isxdigit (_input[i])) ++i; - if (i > mCursor) + if (i > _cursor) { - result = strtoimax (mInput.substr (mCursor, i - mCursor).c_str (), NULL, 16); - mCursor = i; + result = strtoimax (_input.substr (_cursor, i - _cursor).c_str (), NULL, 16); + _cursor = i; return true; } @@ -351,15 +351,15 @@ bool Nibbler::getHex (int& result) //////////////////////////////////////////////////////////////////////////////// bool Nibbler::getUnsignedInt (int& result) { - std::string::size_type i = mCursor; + std::string::size_type i = _cursor; // TODO Potential for use of find_first_not_of - while (i < mLength && isdigit (mInput[i])) + while (i < _length && isdigit (_input[i])) ++i; - if (i > mCursor) + if (i > _cursor) { - result = strtoimax (mInput.substr (mCursor, i - mCursor).c_str (), NULL, 10); - mCursor = i; + result = strtoimax (_input.substr (_cursor, i - _cursor).c_str (), NULL, 10); + _cursor = i; return true; } @@ -384,54 +384,54 @@ bool Nibbler::getUnsignedInt (int& result) // bool Nibbler::getNumber (double& result) { - std::string::size_type i = mCursor; + std::string::size_type i = _cursor; // [+-]? - if (i < mLength && mInput[i] == '-') + if (i < _length && _input[i] == '-') ++i; // digit+ - if (i < mLength && isdigit (mInput[i])) + if (i < _length && isdigit (_input[i])) { ++i; - while (i < mLength && isdigit (mInput[i])) + while (i < _length && isdigit (_input[i])) ++i; // ( . digit+ )? - if (i < mLength && mInput[i] == '.') + if (i < _length && _input[i] == '.') { ++i; - while (i < mLength && isdigit (mInput[i])) + while (i < _length && isdigit (_input[i])) ++i; } // ( [eE] [+-]? digit+ )? - if (i < mLength && (mInput[i] == 'e' || mInput[i] == 'E')) + if (i < _length && (_input[i] == 'e' || _input[i] == 'E')) { ++i; - if (i < mLength && (mInput[i] == '+' || mInput[i] == '-')) + if (i < _length && (_input[i] == '+' || _input[i] == '-')) ++i; - if (i < mLength && isdigit (mInput[i])) + if (i < _length && isdigit (_input[i])) { ++i; - while (i < mLength && isdigit (mInput[i])) + while (i < _length && isdigit (_input[i])) ++i; - result = strtof (mInput.substr (mCursor, i - mCursor).c_str (), NULL); - mCursor = i; + result = strtof (_input.substr (_cursor, i - _cursor).c_str (), NULL); + _cursor = i; return true; } return false; } - result = strtof (mInput.substr (mCursor, i - mCursor).c_str (), NULL); - mCursor = i; + result = strtof (_input.substr (_cursor, i - _cursor).c_str (), NULL); + _cursor = i; return true; } @@ -441,10 +441,10 @@ bool Nibbler::getNumber (double& result) //////////////////////////////////////////////////////////////////////////////// bool Nibbler::getLiteral (const std::string& literal) { - if (mCursor < mLength && - mInput.find (literal, mCursor) == mCursor) + if (_cursor < _length && + _input.find (literal, _cursor) == _cursor) { - mCursor += literal.length (); + _cursor += literal.length (); return true; } @@ -454,7 +454,7 @@ bool Nibbler::getLiteral (const std::string& literal) //////////////////////////////////////////////////////////////////////////////// bool Nibbler::getRx (const std::string& regex, std::string& result) { - if (mCursor < mLength) + if (_cursor < _length) { // Regex may be anchored to the beginning and include capturing parentheses, // otherwise they are added. @@ -466,10 +466,10 @@ bool Nibbler::getRx (const std::string& regex, std::string& result) RX r (modified_regex, true); std::vector results; - if (r.match (results, mInput.substr (mCursor))) + if (r.match (results, _input.substr (_cursor))) { result = results[0]; - mCursor += result.length (); + _cursor += result.length (); return true; } } @@ -480,51 +480,51 @@ bool Nibbler::getRx (const std::string& regex, std::string& result) //////////////////////////////////////////////////////////////////////////////// bool Nibbler::getUUID (std::string& result) { - std::string::size_type i = mCursor; + std::string::size_type i = _cursor; - if (i < mLength && - mLength - i >= 36) + if (i < _length && + _length - i >= 36) { // 88888888-4444-4444-4444-cccccccccccc - if (isxdigit (mInput[i + 0]) && - isxdigit (mInput[i + 1]) && - isxdigit (mInput[i + 2]) && - isxdigit (mInput[i + 3]) && - isxdigit (mInput[i + 4]) && - isxdigit (mInput[i + 5]) && - isxdigit (mInput[i + 6]) && - isxdigit (mInput[i + 7]) && - mInput[i + 8] == '-' && - isxdigit (mInput[i + 9]) && - isxdigit (mInput[i + 10]) && - isxdigit (mInput[i + 11]) && - isxdigit (mInput[i + 12]) && - mInput[i + 13] == '-' && - isxdigit (mInput[i + 14]) && - isxdigit (mInput[i + 15]) && - isxdigit (mInput[i + 16]) && - isxdigit (mInput[i + 17]) && - mInput[i + 18] == '-' && - isxdigit (mInput[i + 19]) && - isxdigit (mInput[i + 20]) && - isxdigit (mInput[i + 21]) && - isxdigit (mInput[i + 22]) && - mInput[i + 23] == '-' && - isxdigit (mInput[i + 24]) && - isxdigit (mInput[i + 25]) && - isxdigit (mInput[i + 26]) && - isxdigit (mInput[i + 27]) && - isxdigit (mInput[i + 28]) && - isxdigit (mInput[i + 29]) && - isxdigit (mInput[i + 30]) && - isxdigit (mInput[i + 31]) && - isxdigit (mInput[i + 32]) && - isxdigit (mInput[i + 33]) && - isxdigit (mInput[i + 34]) && - isxdigit (mInput[i + 35])) + if (isxdigit (_input[i + 0]) && + isxdigit (_input[i + 1]) && + isxdigit (_input[i + 2]) && + isxdigit (_input[i + 3]) && + isxdigit (_input[i + 4]) && + isxdigit (_input[i + 5]) && + isxdigit (_input[i + 6]) && + isxdigit (_input[i + 7]) && + _input[i + 8] == '-' && + isxdigit (_input[i + 9]) && + isxdigit (_input[i + 10]) && + isxdigit (_input[i + 11]) && + isxdigit (_input[i + 12]) && + _input[i + 13] == '-' && + isxdigit (_input[i + 14]) && + isxdigit (_input[i + 15]) && + isxdigit (_input[i + 16]) && + isxdigit (_input[i + 17]) && + _input[i + 18] == '-' && + isxdigit (_input[i + 19]) && + isxdigit (_input[i + 20]) && + isxdigit (_input[i + 21]) && + isxdigit (_input[i + 22]) && + _input[i + 23] == '-' && + isxdigit (_input[i + 24]) && + isxdigit (_input[i + 25]) && + isxdigit (_input[i + 26]) && + isxdigit (_input[i + 27]) && + isxdigit (_input[i + 28]) && + isxdigit (_input[i + 29]) && + isxdigit (_input[i + 30]) && + isxdigit (_input[i + 31]) && + isxdigit (_input[i + 32]) && + isxdigit (_input[i + 33]) && + isxdigit (_input[i + 34]) && + isxdigit (_input[i + 35])) { - result = mInput.substr (mCursor, 36); - mCursor = i + 36; + result = _input.substr (_cursor, 36); + _cursor = i + 36; return true; } } @@ -536,49 +536,49 @@ bool Nibbler::getUUID (std::string& result) // 19980119T070000Z = YYYYMMDDThhmmssZ bool Nibbler::getDateISO (time_t& t) { - std::string::size_type i = mCursor; + std::string::size_type i = _cursor; - if (i < mLength && - mLength - i >= 16) + if (i < _length && + _length - i >= 16) { - if (isdigit (mInput[i + 0]) && - isdigit (mInput[i + 1]) && - isdigit (mInput[i + 2]) && - isdigit (mInput[i + 3]) && - isdigit (mInput[i + 4]) && - isdigit (mInput[i + 5]) && - isdigit (mInput[i + 6]) && - isdigit (mInput[i + 7]) && - mInput[i + 8] == 'T' && - isdigit (mInput[i + 9]) && - isdigit (mInput[i + 10]) && - isdigit (mInput[i + 11]) && - isdigit (mInput[i + 12]) && - isdigit (mInput[i + 13]) && - isdigit (mInput[i + 14]) && - mInput[i + 15] == 'Z') + if (isdigit (_input[i + 0]) && + isdigit (_input[i + 1]) && + isdigit (_input[i + 2]) && + isdigit (_input[i + 3]) && + isdigit (_input[i + 4]) && + isdigit (_input[i + 5]) && + isdigit (_input[i + 6]) && + isdigit (_input[i + 7]) && + _input[i + 8] == 'T' && + isdigit (_input[i + 9]) && + isdigit (_input[i + 10]) && + isdigit (_input[i + 11]) && + isdigit (_input[i + 12]) && + isdigit (_input[i + 13]) && + isdigit (_input[i + 14]) && + _input[i + 15] == 'Z') { - mCursor += 16; + _cursor += 16; - int year = (mInput[i + 0] - '0') * 1000 - + (mInput[i + 1] - '0') * 100 - + (mInput[i + 2] - '0') * 10 - + (mInput[i + 3] - '0'); + int year = (_input[i + 0] - '0') * 1000 + + (_input[i + 1] - '0') * 100 + + (_input[i + 2] - '0') * 10 + + (_input[i + 3] - '0'); - int month = (mInput[i + 4] - '0') * 10 - + (mInput[i + 5] - '0'); + int month = (_input[i + 4] - '0') * 10 + + (_input[i + 5] - '0'); - int day = (mInput[i + 6] - '0') * 10 - + (mInput[i + 7] - '0'); + int day = (_input[i + 6] - '0') * 10 + + (_input[i + 7] - '0'); - int hour = (mInput[i + 9] - '0') * 10 - + (mInput[i + 10] - '0'); + int hour = (_input[i + 9] - '0') * 10 + + (_input[i + 10] - '0'); - int minute = (mInput[i + 11] - '0') * 10 - + (mInput[i + 12] - '0'); + int minute = (_input[i + 11] - '0') * 10 + + (_input[i + 12] - '0'); - int second = (mInput[i + 13] - '0') * 10 - + (mInput[i + 14] - '0'); + int second = (_input[i + 13] - '0') * 10 + + (_input[i + 14] - '0'); // Convert to epoch. struct tm tms = {0}; @@ -610,7 +610,7 @@ bool Nibbler::getDateISO (time_t& t) //////////////////////////////////////////////////////////////////////////////// bool Nibbler::getDate (const std::string& format, time_t& t) { - std::string::size_type i = mCursor; + std::string::size_type i = _cursor; int month = 0; int day = 0; @@ -624,17 +624,17 @@ bool Nibbler::getDate (const std::string& format, time_t& t) switch (format[f]) { case 'm': - if (i + 2 <= mLength && - (mInput[i + 0] == '0' || mInput[i + 0] == '1') && - isdigit (mInput[i + 1])) + if (i + 2 <= _length && + (_input[i + 0] == '0' || _input[i + 0] == '1') && + isdigit (_input[i + 1])) { - month = atoi (mInput.substr (i, 2).c_str ()); + month = atoi (_input.substr (i, 2).c_str ()); i += 2; } - else if (i + 1 <= mLength && - isdigit (mInput[i + 0])) + else if (i + 1 <= _length && + isdigit (_input[i + 0])) { - month = mInput[i] - '0'; + month = _input[i] - '0'; i += 1; } else @@ -642,17 +642,17 @@ bool Nibbler::getDate (const std::string& format, time_t& t) break; case 'd': - if (i + 2 <= mLength && - isdigit (mInput[i + 1]) && - isdigit (mInput[i + 1])) + if (i + 2 <= _length && + isdigit (_input[i + 1]) && + isdigit (_input[i + 1])) { - day = atoi (mInput.substr (i, 2).c_str ()); + day = atoi (_input.substr (i, 2).c_str ()); i += 2; } - else if (i + 1 <= mLength && - isdigit (mInput[i + 0])) + else if (i + 1 <= _length && + isdigit (_input[i + 0])) { - day = mInput[i] - '0'; + day = _input[i] - '0'; i += 1; } else @@ -660,11 +660,11 @@ bool Nibbler::getDate (const std::string& format, time_t& t) break; case 'y': - if (i + 2 <= mLength && - isdigit (mInput[i + 0]) && - isdigit (mInput[i + 1])) + if (i + 2 <= _length && + isdigit (_input[i + 0]) && + isdigit (_input[i + 1])) { - year = 2000 + atoi (mInput.substr (i, 2).c_str ()); + year = 2000 + atoi (_input.substr (i, 2).c_str ()); i += 2; } else @@ -672,11 +672,11 @@ bool Nibbler::getDate (const std::string& format, time_t& t) break; case 'M': - if (i + 2 <= mLength && - isdigit (mInput[i + 0]) && - isdigit (mInput[i + 1])) + if (i + 2 <= _length && + isdigit (_input[i + 0]) && + isdigit (_input[i + 1])) { - month = atoi (mInput.substr (i, 2).c_str ()); + month = atoi (_input.substr (i, 2).c_str ()); i += 2; } else @@ -684,11 +684,11 @@ bool Nibbler::getDate (const std::string& format, time_t& t) break; case 'D': - if (i + 2 <= mLength && - isdigit (mInput[i + 0]) && - isdigit (mInput[i + 1])) + if (i + 2 <= _length && + isdigit (_input[i + 0]) && + isdigit (_input[i + 1])) { - day = atoi (mInput.substr (i, 2).c_str ()); + day = atoi (_input.substr (i, 2).c_str ()); i += 2; } else @@ -697,11 +697,11 @@ bool Nibbler::getDate (const std::string& format, time_t& t) // Merely parse, not extract. case 'V': - if (i + 2 <= mLength && - isdigit (mInput[i + 0]) && - isdigit (mInput[i + 1])) + if (i + 2 <= _length && + isdigit (_input[i + 0]) && + isdigit (_input[i + 1])) { - day = atoi (mInput.substr (i, 2).c_str ()); + day = atoi (_input.substr (i, 2).c_str ()); i += 2; } else @@ -709,13 +709,13 @@ bool Nibbler::getDate (const std::string& format, time_t& t) break; case 'Y': - if (i + 4 <= mLength && - isdigit (mInput[i + 0]) && - isdigit (mInput[i + 1]) && - isdigit (mInput[i + 2]) && - isdigit (mInput[i + 3])) + if (i + 4 <= _length && + isdigit (_input[i + 0]) && + isdigit (_input[i + 1]) && + isdigit (_input[i + 2]) && + isdigit (_input[i + 3])) { - year = atoi (mInput.substr (i, 4).c_str ()); + year = atoi (_input.substr (i, 4).c_str ()); i += 4; } else @@ -724,10 +724,10 @@ bool Nibbler::getDate (const std::string& format, time_t& t) // Merely parse, not extract. case 'a': - if (i + 3 <= mLength && - ! isdigit (mInput[i + 0]) && - ! isdigit (mInput[i + 1]) && - ! isdigit (mInput[i + 2])) + if (i + 3 <= _length && + ! isdigit (_input[i + 0]) && + ! isdigit (_input[i + 1]) && + ! isdigit (_input[i + 2])) i += 3; else return false; @@ -735,12 +735,12 @@ bool Nibbler::getDate (const std::string& format, time_t& t) // Merely parse, not extract. case 'b': - if (i + 3 <= mLength && - ! isdigit (mInput[i + 0]) && - ! isdigit (mInput[i + 1]) && - ! isdigit (mInput[i + 2])) + if (i + 3 <= _length && + ! isdigit (_input[i + 0]) && + ! isdigit (_input[i + 1]) && + ! isdigit (_input[i + 2])) { - month = Date::monthOfYear (mInput.substr (i, 3).c_str()); + month = Date::monthOfYear (_input.substr (i, 3).c_str()); i += 3; } else @@ -749,22 +749,22 @@ bool Nibbler::getDate (const std::string& format, time_t& t) // Merely parse, not extract. case 'A': - if (i + 3 <= mLength && - ! isdigit (mInput[i + 0]) && - ! isdigit (mInput[i + 1]) && - ! isdigit (mInput[i + 2])) - i += Date::dayName (Date::dayOfWeek (mInput.substr (i, 3).c_str ())).size (); + if (i + 3 <= _length && + ! isdigit (_input[i + 0]) && + ! isdigit (_input[i + 1]) && + ! isdigit (_input[i + 2])) + i += Date::dayName (Date::dayOfWeek (_input.substr (i, 3).c_str ())).size (); else return false; break; case 'B': - if (i + 3 <= mLength && - ! isdigit (mInput[i + 0]) && - ! isdigit (mInput[i + 1]) && - ! isdigit (mInput[i + 2])) + if (i + 3 <= _length && + ! isdigit (_input[i + 0]) && + ! isdigit (_input[i + 1]) && + ! isdigit (_input[i + 2])) { - month = Date::monthOfYear (mInput.substr (i, 3).c_str ()); + month = Date::monthOfYear (_input.substr (i, 3).c_str ()); i += Date::monthName (month).size (); } else @@ -772,17 +772,17 @@ bool Nibbler::getDate (const std::string& format, time_t& t) break; case 'h': - if (i + 2 <= mLength && - (mInput[i + 0] == '0' || mInput[i + 0] == '1') && - isdigit (mInput[i + 1])) + if (i + 2 <= _length && + (_input[i + 0] == '0' || _input[i + 0] == '1') && + isdigit (_input[i + 1])) { - hour = atoi (mInput.substr (i, 2).c_str ()); + hour = atoi (_input.substr (i, 2).c_str ()); i += 2; } - else if (i + 1 <= mLength && - isdigit (mInput[i + 0])) + else if (i + 1 <= _length && + isdigit (_input[i + 0])) { - hour = atoi (mInput.substr (i, 1).c_str ()); + hour = atoi (_input.substr (i, 1).c_str ()); i += 1; } else @@ -790,11 +790,11 @@ bool Nibbler::getDate (const std::string& format, time_t& t) break; case 'H': - if (i + 2 <= mLength && - isdigit (mInput[i + 0]) && - isdigit (mInput[i + 1])) + if (i + 2 <= _length && + isdigit (_input[i + 0]) && + isdigit (_input[i + 1])) { - hour = atoi (mInput.substr (i, 2).c_str ()); + hour = atoi (_input.substr (i, 2).c_str ()); i += 2; } else @@ -802,11 +802,11 @@ bool Nibbler::getDate (const std::string& format, time_t& t) break; case 'N': - if (i + 2 <= mLength && - isdigit (mInput[i + 0]) && - isdigit (mInput[i + 1])) + if (i + 2 <= _length && + isdigit (_input[i + 0]) && + isdigit (_input[i + 1])) { - minute = atoi (mInput.substr (i, 2).c_str ()); + minute = atoi (_input.substr (i, 2).c_str ()); i += 2; } else @@ -814,11 +814,11 @@ bool Nibbler::getDate (const std::string& format, time_t& t) break; case 'S': - if (i + 2 <= mLength && - isdigit (mInput[i + 0]) && - isdigit (mInput[i + 1])) + if (i + 2 <= _length && + isdigit (_input[i + 0]) && + isdigit (_input[i + 1])) { - second = atoi (mInput.substr (i, 2).c_str ()); + second = atoi (_input.substr (i, 2).c_str ()); i += 2; } else @@ -826,25 +826,25 @@ bool Nibbler::getDate (const std::string& format, time_t& t) break; case 'j': - if (i + 3 <= mLength && - isdigit (mInput[i + 0]) && - isdigit (mInput[i + 1]) && - isdigit (mInput[i + 2])) + if (i + 3 <= _length && + isdigit (_input[i + 0]) && + isdigit (_input[i + 1]) && + isdigit (_input[i + 2])) { - day = atoi (mInput.substr (i, 3).c_str ()); + day = atoi (_input.substr (i, 3).c_str ()); i += 3; } - else if (i + 2 <= mLength && - isdigit (mInput[i + 0]) && - isdigit (mInput[i + 1])) + else if (i + 2 <= _length && + isdigit (_input[i + 0]) && + isdigit (_input[i + 1])) { - day = atoi (mInput.substr (i, 2).c_str ()); + day = atoi (_input.substr (i, 2).c_str ()); i += 2; } - else if (i + 1 <= mLength && - isdigit (mInput[i + 0])) + else if (i + 1 <= _length && + isdigit (_input[i + 0])) { - day = atoi (mInput.substr (i, 1).c_str ()); + day = atoi (_input.substr (i, 1).c_str ()); i += 1; } else @@ -852,12 +852,12 @@ bool Nibbler::getDate (const std::string& format, time_t& t) break; case 'J': - if (i + 3 <= mLength && - isdigit (mInput[i + 0]) && - isdigit (mInput[i + 1]) && - isdigit (mInput[i + 2])) + if (i + 3 <= _length && + isdigit (_input[i + 0]) && + isdigit (_input[i + 1]) && + isdigit (_input[i + 2])) { - day = atoi (mInput.substr (i, 3).c_str ()); + day = atoi (_input.substr (i, 3).c_str ()); i += 3; } else @@ -865,8 +865,8 @@ bool Nibbler::getDate (const std::string& format, time_t& t) break; default: - if (i + 1 <= mLength && - mInput[i] == format[f]) + if (i + 1 <= _length && + _input[i] == format[f]) ++i; else return false; @@ -909,7 +909,7 @@ bool Nibbler::getDate (const std::string& format, time_t& t) tms.tm_sec = second; t = mktime (&tms); - mCursor = i; + _cursor = i; return true; } @@ -938,25 +938,25 @@ bool Nibbler::getOneOf ( // A name is a string of alpha-numeric characters. bool Nibbler::getName (std::string& result) { - std::string::size_type i = mCursor; + std::string::size_type i = _cursor; - if (i < mLength) + if (i < _length) { - if (isalpha (mInput[i])) + if (isalpha (_input[i])) { ++i; - while (i < mLength && - (isalpha (mInput[i]) || - isdigit (mInput[i]))) + while (i < _length && + (isalpha (_input[i]) || + isdigit (_input[i]))) { ++i; } } - if (i > mCursor) + if (i > _cursor) { - result = mInput.substr (mCursor, i - mCursor); - mCursor = i; + result = _input.substr (_cursor, i - _cursor); + _cursor = i; return true; } } @@ -968,21 +968,21 @@ bool Nibbler::getName (std::string& result) // A word is a contiguous string of non-space, non-digit, non-punct characters. bool Nibbler::getWord (std::string& result) { - std::string::size_type i = mCursor; + std::string::size_type i = _cursor; - if (i < mLength) + if (i < _length) { - while (!isdigit (mInput[i]) && - !ispunct (mInput[i]) && - !isspace (mInput[i])) + while (!isdigit (_input[i]) && + !ispunct (_input[i]) && + !isspace (_input[i])) { ++i; } - if (i > mCursor) + if (i > _cursor) { - result = mInput.substr (mCursor, i - mCursor); - mCursor = i; + result = _input.substr (_cursor, i - _cursor); + _cursor = i; return true; } } @@ -993,10 +993,10 @@ bool Nibbler::getWord (std::string& result) //////////////////////////////////////////////////////////////////////////////// bool Nibbler::skipN (const int quantity /* = 1 */) { - if (mCursor < mLength && - mCursor <= mLength - quantity) + if (_cursor < _length && + _cursor <= _length - quantity) { - mCursor += quantity; + _cursor += quantity; return true; } @@ -1006,10 +1006,10 @@ bool Nibbler::skipN (const int quantity /* = 1 */) //////////////////////////////////////////////////////////////////////////////// bool Nibbler::skip (char c) { - if (mCursor < mLength && - mInput[mCursor] == c) + if (_cursor < _length && + _input[_cursor] == c) { - ++mCursor; + ++_cursor; return true; } @@ -1019,16 +1019,16 @@ bool Nibbler::skip (char c) //////////////////////////////////////////////////////////////////////////////// bool Nibbler::skipAll (char c) { - if (mCursor < mLength) + if (_cursor < _length) { - std::string::size_type i = mInput.find_first_not_of (c, mCursor); - if (i == mCursor) + std::string::size_type i = _input.find_first_not_of (c, _cursor); + if (i == _cursor) return false; if (i == std::string::npos) - mCursor = mLength; // Yes, off the end. + _cursor = _length; // Yes, off the end. else - mCursor = i; + _cursor = i; return true; } @@ -1045,7 +1045,7 @@ bool Nibbler::skipWS () //////////////////////////////////////////////////////////////////////////////// bool Nibbler::skipRx (const std::string& regex) { - if (mCursor < mLength) + if (_cursor < _length) { // Regex may be anchored to the beginning and include capturing parentheses, // otherwise they are added. @@ -1057,9 +1057,9 @@ bool Nibbler::skipRx (const std::string& regex) RX r (modified_regex, true); std::vector results; - if (r.match (results, mInput.substr (mCursor))) + if (r.match (results, _input.substr (_cursor))) { - mCursor += results[0].length (); + _cursor += results[0].length (); return true; } } @@ -1070,16 +1070,16 @@ bool Nibbler::skipRx (const std::string& regex) //////////////////////////////////////////////////////////////////////////////// bool Nibbler::skipAllOneOf (const std::string& chars) { - if (mCursor < mLength) + if (_cursor < _length) { - std::string::size_type i = mInput.find_first_not_of (chars, mCursor); - if (i == mCursor) + std::string::size_type i = _input.find_first_not_of (chars, _cursor); + if (i == _cursor) return false; if (i == std::string::npos) - mCursor = mLength; // Yes, off the end. + _cursor = _length; // Yes, off the end. else - mCursor = i; + _cursor = i; return true; } @@ -1091,8 +1091,8 @@ bool Nibbler::skipAllOneOf (const std::string& chars) // Peeks ahead - does not move cursor. char Nibbler::next () { - if (mCursor < mLength) - return mInput[mCursor]; + if (_cursor < _length) + return _input[_cursor]; return '\0'; } @@ -1100,17 +1100,17 @@ char Nibbler::next () //////////////////////////////////////////////////////////////////////////////// std::string::size_type Nibbler::cursor () { - return mCursor; + return _cursor; } //////////////////////////////////////////////////////////////////////////////// // Peeks ahead - does not move cursor. std::string Nibbler::next (const int quantity) { - if ( mCursor < mLength && - (unsigned) quantity <= mLength && - mCursor <= mLength - quantity) - return mInput.substr (mCursor, quantity); + if ( _cursor < _length && + (unsigned) quantity <= _length && + _cursor <= _length - quantity) + return _input.substr (_cursor, quantity); return ""; } @@ -1118,25 +1118,25 @@ std::string Nibbler::next (const int quantity) //////////////////////////////////////////////////////////////////////////////// std::string::size_type Nibbler::save () { - return mSaved = mCursor; + return _saved = _cursor; } //////////////////////////////////////////////////////////////////////////////// std::string::size_type Nibbler::restore () { - return mCursor = mSaved; + return _cursor = _saved; } //////////////////////////////////////////////////////////////////////////////// const std::string& Nibbler::str () const { - return mInput; + return _input; } //////////////////////////////////////////////////////////////////////////////// bool Nibbler::depleted () { - if (mCursor >= mLength) + if (_cursor >= _length) return true; return false; @@ -1146,7 +1146,7 @@ bool Nibbler::depleted () std::string Nibbler::dump () { return std::string ("Nibbler ‹") - + mInput.substr (mCursor) + + _input.substr (_cursor) + "›"; } diff --git a/src/Nibbler.h b/src/Nibbler.h index c29de1487..21f16c0cc 100644 --- a/src/Nibbler.h +++ b/src/Nibbler.h @@ -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 diff --git a/src/Path.cpp b/src/Path.cpp index 09ccae7be..9afd0ab75 100644 --- a/src/Path.cpp +++ b/src/Path.cpp @@ -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; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Path.h b/src/Path.h index 8f9859467..8e7b9933e 100644 --- a/src/Path.h +++ b/src/Path.h @@ -58,7 +58,7 @@ public: static std::vector glob (const std::string&); public: - std::string data; + std::string _data; }; #endif diff --git a/src/Permission.cpp b/src/Permission.cpp index 10f2026c6..179d1ba99 100644 --- a/src/Permission.cpp +++ b/src/Permission.cpp @@ -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; } diff --git a/src/Permission.h b/src/Permission.h index 10a68c791..9f56e760c 100644 --- a/src/Permission.h +++ b/src/Permission.h @@ -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 diff --git a/src/TDB.cpp b/src/TDB.cpp index 81d8ad9f0..feeec44ad 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -144,34 +144,34 @@ void readTaskmods (std::vector &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 & 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 & 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 & 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 & 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 & tasks) } // Now filter and return. - foreach (task, mCompleted) + foreach (task, _completed) tasks.push_back (*task); } @@ -393,29 +393,29 @@ int TDB::loadCompleted (std::vector & tasks) //////////////////////////////////////////////////////////////////////////////// const std::vector & TDB::getAllPending () { - return mPending; + return _pending; } //////////////////////////////////////////////////////////////////////////////// const std::vector & TDB::getAllNew () { - return mNew; + return _new; } //////////////////////////////////////////////////////////////////////////////// const std::vector & TDB::getAllCompleted () { - return mCompleted; + return _completed; } //////////////////////////////////////////////////////////////////////////////// const std::vector & 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 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 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 still_pending; std::vector 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 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 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 pending; - std::string completedFile = location.data + "/completed.data"; + std::string completedFile = location._data + "/completed.data"; std::vector 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 ::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 ::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) diff --git a/src/TDB.h b/src/TDB.h index 4bb9d92d6..e0948cbda 100644 --- a/src/TDB.h +++ b/src/TDB.h @@ -80,18 +80,18 @@ private: bool uuidAlreadyUsed (const std::string&, const std::vector &); private: - std::vector mLocations; - bool mLock; - bool mAllOpenAndLocked; - int mId; + std::vector _locations; + bool _lock; + bool _all_opened_and_locked; + int _id; - std::vector mPending; // Contents of pending.data - std::vector mCompleted; // Contents of pending.data - std::vector mNew; // Uncommitted new tasks - std::vector mModified; // Uncommitted modified tasks + std::vector _pending; // Contents of pending.data + std::vector _completed; // Contents of pending.data + std::vector _new; // Uncommitted new tasks + std::vector _modified; // Uncommitted modified tasks - std::map mI2U; // ID -> UUID map - std::map mU2I; // UUID -> ID map + std::map _I2U; // ID -> UUID map + std::map _U2I; // UUID -> ID map }; #endif diff --git a/src/TDB2.cpp b/src/TDB2.cpp index 5224c6d90..115bc2891 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -62,7 +62,7 @@ void TF2::target (const std::string& f) //////////////////////////////////////////////////////////////////////////////// const std::vector & 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 & TF2::get_tasks () //////////////////////////////////////////////////////////////////////////////// const std::vector & 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 & 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 ::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" : "-") + diff --git a/src/Taskmod.cpp b/src/Taskmod.cpp index 191829fb5..399aa79c8 100644 --- a/src/Taskmod.cpp +++ b/src/Taskmod.cpp @@ -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 (); } diff --git a/src/Taskmod.h b/src/Taskmod.h index 480a6545d..56a9f2839 100644 --- a/src/Taskmod.h +++ b/src/Taskmod.h @@ -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 diff --git a/src/Transport.cpp b/src/Transport.cpp index ae6f57bbb..12d3ecbba 100644 --- a/src/Transport.cpp +++ b/src/Transport.cpp @@ -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); } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Transport.h b/src/Transport.h index 55f5aa266..1900b8ef1 100644 --- a/src/Transport.h +++ b/src/Transport.h @@ -46,10 +46,10 @@ public: static bool is_filelist(const std::string&); protected: - std::string executable; - std::vector arguments; + std::string _executable; + std::vector _arguments; - Uri uri; + Uri _uri; int execute(); }; diff --git a/src/TransportCurl.cpp b/src/TransportCurl.cpp index f28f562f9..dd54b114d 100644 --- a/src/TransportCurl.cpp +++ b/src/TransportCurl.cpp @@ -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 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) diff --git a/src/TransportRSYNC.cpp b/src/TransportRSYNC.cpp index 0a28c2f5a..5bdf352f2 100644 --- a/src/TransportRSYNC.cpp +++ b/src/TransportRSYNC.cpp @@ -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); diff --git a/src/TransportSSH.cpp b/src/TransportSSH.cpp index 2be951ad0..6c6a75d2b 100644 --- a/src/TransportSSH.cpp +++ b/src/TransportSSH.cpp @@ -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); diff --git a/src/Uri.cpp b/src/Uri.cpp index 46357ac9e..c4bbb0b15 100644 --- a/src/Uri.cpp +++ b/src/Uri.cpp @@ -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; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/Uri.h b/src/Uri.h index 85febe45d..695ae9e17 100644 --- a/src/Uri.h +++ b/src/Uri.h @@ -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 diff --git a/src/commands/CmdConfig.cpp b/src/commands/CmdConfig.cpp index 8c20a663d..cc4966fd2 100644 --- a/src/commands/CmdConfig.cpp +++ b/src/commands/CmdConfig.cpp @@ -79,7 +79,7 @@ int CmdConfig::execute (std::string& output) // Read .taskrc (or equivalent) std::vector 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 diff --git a/src/commands/CmdDiagnostics.cpp b/src/commands/CmdDiagnostics.cpp index bbf47316b..b9016e609 100644 --- a/src/commands/CmdDiagnostics.cpp +++ b/src/commands/CmdDiagnostics.cpp @@ -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 " diff --git a/src/commands/CmdEdit.cpp b/src/commands/CmdEdit.cpp index fe2c9f5b2..17947f0ea 100644 --- a/src/commands/CmdEdit.cpp +++ b/src/commands/CmdEdit.cpp @@ -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); diff --git a/src/commands/CmdInfo.cpp b/src/commands/CmdInfo.cpp index 04ddbc42c..689158875 100644 --- a/src/commands/CmdInfo.cpp +++ b/src/commands/CmdInfo.cpp @@ -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); } diff --git a/src/commands/CmdMerge.cpp b/src/commands/CmdMerge.cpp index 9f2a0fa03..682e1c9cf 100644 --- a/src/commands/CmdMerge.cpp +++ b/src/commands/CmdMerge.cpp @@ -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); diff --git a/src/commands/CmdPull.cpp b/src/commands/CmdPull.cpp index d24cb6a60..057c16513 100644 --- a/src/commands/CmdPull.cpp +++ b/src/commands/CmdPull.cpp @@ -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 " diff --git a/src/commands/CmdPush.cpp b/src/commands/CmdPush.cpp index 394344d06..568dbe353 100644 --- a/src/commands/CmdPush.cpp +++ b/src/commands/CmdPush.cpp @@ -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 " diff --git a/src/commands/CmdShow.cpp b/src/commands/CmdShow.cpp index 9a9b80611..8e2d8fbcb 100644 --- a/src/commands/CmdShow.cpp +++ b/src/commands/CmdShow.cpp @@ -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 ()) diff --git a/src/commands/CmdStatistics.cpp b/src/commands/CmdStatistics.cpp index 04d96d45e..736a3ebe4 100644 --- a/src/commands/CmdStatistics.cpp +++ b/src/commands/CmdStatistics.cpp @@ -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 undoTxns; diff --git a/test/.gitignore b/test/.gitignore index 127105c54..aca92984b 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -24,7 +24,6 @@ rx.t sensor.t seq.t subst.t -t.benchmark.t t.t t2.t taskmod.t diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4c1dd5be1..c01fe6c00 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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) diff --git a/test/directory.t.cpp b/test/directory.t.cpp index 3b8f955a7..fa1baf771 100644 --- a/test/directory.t.cpp +++ b/test/directory.t.cpp @@ -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 list (); std::vector 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"); diff --git a/test/path.t.cpp b/test/path.t.cpp index 4387c5921..23742f404 100644 --- a/test/path.t.cpp +++ b/test/path.t.cpp @@ -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"); diff --git a/test/uri.t.cpp b/test/uri.t.cpp index 55163677e..8882f92c6 100644 --- a/test/uri.t.cpp +++ b/test/uri.t.cpp @@ -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; }