From 6dc5ca4e60b80a1d900f87a4e70954cd29cfcee4 Mon Sep 17 00:00:00 2001 From: simonb Date: Tue, 27 Jun 2006 08:54:24 +0000 Subject: some minor code cleanups thanks Slava Semushin (php-coder), who also thanks Mikhail Gusarov --- ChangeLog | 2 ++ src/FbTk/StringUtil.cc | 12 ------------ src/FbTk/StringUtil.hh | 1 - src/Remember.cc | 26 +++++++++++--------------- 4 files changed, 13 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index c19e33b..8f7b251 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ (Format: Year/Month/Day) Changes for 1.0rc2: *06/06/27: + * Some minor cleaning (thanks Slava Semushin + Mikhail Gusarov) + FbTk/StringUtil.hh/cc Remember.cc * Fix slit menu so it closes when you press escape (Mark) Slit.cc *06/06/26: diff --git a/src/FbTk/StringUtil.cc b/src/FbTk/StringUtil.cc index 1a6814c..11bd87d 100644 --- a/src/FbTk/StringUtil.cc +++ b/src/FbTk/StringUtil.cc @@ -58,18 +58,6 @@ namespace FbTk { namespace StringUtil { /** - Takes a pointer to string *s as an argument, - creates a new string n, copies s to n and - returns a pointer to n. -*/ -char *strdup(const char *s) { - int l = strlen(s) + 1; - char *n = new char[l]; - strncpy(n, s, l); - return n; -} - -/** Tries to find a string in another and ignoring the case of the characters Returns 0 on success else pointer to str. diff --git a/src/FbTk/StringUtil.hh b/src/FbTk/StringUtil.hh index c9f6818..b45d6a2 100644 --- a/src/FbTk/StringUtil.hh +++ b/src/FbTk/StringUtil.hh @@ -30,7 +30,6 @@ namespace FbTk { namespace StringUtil { -char *strdup(const char *); /// Similar to `strstr' but this function ignores the case of both strings const char *strcasestr(const char *str, const char *ptn); diff --git a/src/Remember.cc b/src/Remember.cc index 99a0d1d..eace6bc 100644 --- a/src/Remember.cc +++ b/src/Remember.cc @@ -61,7 +61,7 @@ using namespace std; namespace { bool getuint(const char *val, unsigned int &ret) { - return (sscanf(val, "%ui", &ret) == 1); + return (sscanf(val, "%u", &ret) == 1); } class RememberMenuItem : public FbTk::MenuItem { @@ -263,9 +263,8 @@ Remember::~Remember() { } std::set::iterator ait = all_apps.begin(); // no duplicates - while (ait != all_apps.end()) { + for (; ait != all_apps.end(); ++ait) { delete (*ait); - ++ait; } s_instance = 0; @@ -380,7 +379,7 @@ int Remember::parseApp(std::ifstream &file, Application &app, std::string *first app.rememberLayer(l); } else if (strcasecmp(str_key.c_str(), "Dimensions") == 0) { unsigned int h,w; - if (sscanf(str_label.c_str(), "%i %i", &w, &h) == 2) + if (sscanf(str_label.c_str(), "%u %u", &w, &h) == 2) app.rememberDimensions(w, h); else had_error = true; @@ -404,7 +403,7 @@ int Remember::parseApp(std::ifstream &file, Application &app, std::string *first } } - if (!had_error && sscanf(str_label.c_str(), "%i %i", &x, &y) == 2) + if (!had_error && sscanf(str_label.c_str(), "%u %u", &x, &y) == 2) app.rememberPosition(x, y, r); else had_error = true; @@ -501,12 +500,11 @@ Application *Remember::findMatchingPatterns(ClientPattern *pat, Patterns *patlis } // forward - while (it != it_end && it->second == ret) { - tmpit = it; - ++it; - delete tmpit->first; - patlist->erase(tmpit); + for(; it != it_end && it->second == ret; ++it) { + delete it->first; } + patlist->erase(patlist->begin(), it); + return ret; } } @@ -643,9 +641,8 @@ void Remember::reconfigure() { } std::set::iterator ait = old_apps.begin(); // no duplicates - while (ait != old_apps.end()) { + for (; ait != old_apps.end(); ++ait) { delete (*ait); - ++ait; } delete old_pats; @@ -1062,7 +1059,7 @@ void Remember::updateClientClose(WinClient &winclient) { if (app && (app->save_on_close_remember && app->save_on_close)) { - for (int attrib = 0; attrib <= REM_LASTATTRIB; attrib++) { + for (int attrib = 0; attrib < REM_LASTATTRIB; attrib++) { if (isRemembered(winclient, (Attribute) attrib)) { rememberAttrib(winclient, (Attribute) attrib); } @@ -1091,9 +1088,8 @@ void Remember::initForScreen(BScreen &screen) { void Remember::updateFrameClose(FluxboxWindow &win) { // scan all applications and remove this fbw if it is a recorded group Patterns::iterator it = m_pats->begin(); - while (it != m_pats->end()) { + for (; it != m_pats->end(); ++it) { if (&win == it->second->group) it->second->group = 0; - ++it; } } -- cgit v0.11.2