]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- moved function to separate file
authorArvin Schnell <aschnell@suse.de>
Thu, 10 Apr 2014 08:55:09 +0000 (10:55 +0200)
committerArvin Schnell <aschnell@suse.de>
Thu, 10 Apr 2014 08:55:09 +0000 (10:55 +0200)
client/Makefile.am
client/misc.cc [new file with mode: 0644]
client/misc.h [new file with mode: 0644]
client/snapper.cc

index 1820156bb606ee0a0fa9c660efa811808f9c6c0a..ed05cc2d9dd732b1e6ebcf61fa86b0bdce2a3a40 100644 (file)
@@ -13,6 +13,7 @@ snapper_SOURCES =                     \
        types.cc        types.h         \
        commands.cc     commands.h      \
        cleanup.cc      cleanup.h       \
+       misc.cc         misc.h          \
        errors.cc       errors.h
 
 snapper_LDADD = ../snapper/libsnapper.la utils/libutils.la ../dbus/libdbus.la
diff --git a/client/misc.cc b/client/misc.cc
new file mode 100644 (file)
index 0000000..a894bc1
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) [2011-2014] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include "config.h"
+
+#include <iostream>
+#include <sstream>
+#include <boost/algorithm/string.hpp>
+
+#include <snapper/AppUtil.h>
+
+#include "utils/text.h"
+
+#include "misc.h"
+
+
+Snapshots::iterator
+read_num(Snapper* snapper, const string& str)
+{
+    Snapshots& snapshots = snapper->getSnapshots();
+
+    istringstream s(str);
+    unsigned int num = 0;
+    s >> num;
+
+    if (s.fail() || !s.eof())
+    {
+       cerr << sformat(_("Invalid snapshot '%s'."), str.c_str()) << endl;
+       exit(EXIT_FAILURE);
+    }
+
+    Snapshots::iterator snap = snapshots.find(num);
+    if (snap == snapshots.end())
+    {
+       cerr << sformat(_("Snapshot '%u' not found."), num) << endl;
+       exit(EXIT_FAILURE);
+    }
+
+    return snap;
+}
+
+
+unsigned int
+read_num(const string& str)
+{
+    istringstream s(str);
+    unsigned int num = 0;
+    s >> num;
+
+    if (s.fail() || !s.eof())
+    {
+       cerr << sformat(_("Invalid snapshot '%s'."), str.c_str()) << endl;
+       exit(EXIT_FAILURE);
+    }
+
+    return num;
+}
+
+
+pair<unsigned int, unsigned int>
+read_nums(const string& str, const string& delim)
+{
+    string::size_type pos = str.find(delim);
+    if (pos == string::npos)
+    {
+       cerr << _("Invalid snapshots.") << endl;
+       exit(EXIT_FAILURE);
+    }
+
+    unsigned int num1 = read_num(str.substr(0, pos));
+    unsigned int num2 = read_num(str.substr(pos + delim.size()));
+
+    if (num1 == num2)
+    {
+       cerr << _("Identical snapshots.") << endl;
+       exit(EXIT_FAILURE);
+    }
+
+    return pair<unsigned int, unsigned int>(num1, num2);
+}
+
+
+map<string, string>
+read_userdata(const string& s, const map<string, string>& old)
+{
+    map<string, string> userdata = old;
+
+    list<string> tmp;
+    boost::split(tmp, s, boost::is_any_of(","), boost::token_compress_on);
+    if (tmp.empty())
+    {
+       cerr << _("Invalid userdata.") << endl;
+       exit(EXIT_FAILURE);
+    }
+
+    for (list<string>::const_iterator it = tmp.begin(); it != tmp.end(); ++it)
+    {
+       string::size_type pos = it->find("=");
+       if (pos == string::npos)
+       {
+           cerr << _("Invalid userdata.") << endl;
+           exit(EXIT_FAILURE);
+       }
+
+       string key = boost::trim_copy(it->substr(0, pos));
+       string value = boost::trim_copy(it->substr(pos + 1));
+
+       if (key.empty())
+       {
+           cerr << _("Invalid userdata.") << endl;
+           exit(EXIT_FAILURE);
+       }
+
+       if (value.empty())
+           userdata.erase(key);
+       else
+           userdata[key] = value;
+    }
+
+    return userdata;
+}
+
+
+string
+show_userdata(const map<string, string>& userdata)
+{
+    string s;
+
+    for (map<string, string>::const_iterator it = userdata.begin(); it != userdata.end(); ++it)
+    {
+       if (!s.empty())
+           s += ", ";
+       s += it->first + "=" + it->second;
+    }
+
+    return s;
+}
diff --git a/client/misc.h b/client/misc.h
new file mode 100644 (file)
index 0000000..ae89c95
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) [2011-2014] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include <string>
+
+#include <snapper/Snapper.h>
+
+
+using namespace snapper;
+using namespace std;
+
+
+Snapshots::iterator
+read_num(Snapper* snapper, const string& str);
+
+unsigned int
+read_num(const string& str);
+
+pair<unsigned int, unsigned int>
+read_nums(const string& str, const string& delim = "..");
+
+map<string, string>
+read_userdata(const string& s, const map<string, string>& old = map<string, string>());
+
+string
+show_userdata(const map<string, string>& userdata);
+
index b6e437b6172a33b54d23483d9c047ab985830b1b..d65709ba4dac4e1f5ec640bcde9059e3b2ef9bf1 100644 (file)
@@ -48,6 +48,7 @@
 #include "commands.h"
 #include "cleanup.h"
 #include "errors.h"
+#include "misc.h"
 
 
 using namespace snapper;
@@ -82,129 +83,6 @@ string config_name = "root";
 bool no_dbus = false;
 
 
-Snapshots::iterator
-read_num(Snapper* snapper, const string& str)
-{
-    Snapshots& snapshots = snapper->getSnapshots();
-
-    istringstream s(str);
-    unsigned int num = 0;
-    s >> num;
-
-    if (s.fail() || !s.eof())
-    {
-        cerr << sformat(_("Invalid snapshot '%s'."), str.c_str()) << endl;
-        exit(EXIT_FAILURE);
-    }
-
-    Snapshots::iterator snap = snapshots.find(num);
-    if (snap == snapshots.end())
-    {
-        cerr << sformat(_("Snapshot '%u' not found."), num) << endl;
-        exit(EXIT_FAILURE);
-    }
-
-    return snap;
-}
-
-
-unsigned int
-read_num(const string& str)
-{
-    istringstream s(str);
-    unsigned int num = 0;
-    s >> num;
-
-    if (s.fail() || !s.eof())
-    {
-       cerr << sformat(_("Invalid snapshot '%s'."), str.c_str()) << endl;
-       exit(EXIT_FAILURE);
-    }
-
-    return num;
-}
-
-
-pair<unsigned int, unsigned int>
-read_nums(const string& str, const string& delim = "..")
-{
-    string::size_type pos = str.find(delim);
-    if (pos == string::npos)
-    {
-       cerr << _("Invalid snapshots.") << endl;
-       exit(EXIT_FAILURE);
-    }
-
-    unsigned int num1 = read_num(str.substr(0, pos));
-    unsigned int num2 = read_num(str.substr(pos + delim.size()));
-
-    if (num1 == num2)
-    {
-       cerr << _("Identical snapshots.") << endl;
-       exit(EXIT_FAILURE);
-    }
-
-    return pair<unsigned int, unsigned int>(num1, num2);
-}
-
-
-map<string, string>
-read_userdata(const string& s, const map<string, string>& old = map<string, string>())
-{
-    map<string, string> userdata = old;
-
-    list<string> tmp;
-    boost::split(tmp, s, boost::is_any_of(","), boost::token_compress_on);
-    if (tmp.empty())
-    {
-       cerr << _("Invalid userdata.") << endl;
-       exit(EXIT_FAILURE);
-    }
-
-    for (list<string>::const_iterator it = tmp.begin(); it != tmp.end(); ++it)
-    {
-       string::size_type pos = it->find("=");
-       if (pos == string::npos)
-       {
-           cerr << _("Invalid userdata.") << endl;
-           exit(EXIT_FAILURE);
-       }
-
-       string key = boost::trim_copy(it->substr(0, pos));
-       string value = boost::trim_copy(it->substr(pos + 1));
-
-       if (key.empty())
-       {
-           cerr << _("Invalid userdata.") << endl;
-           exit(EXIT_FAILURE);
-       }
-
-       if (value.empty())
-           userdata.erase(key);
-       else
-           userdata[key] = value;
-    }
-
-    return userdata;
-}
-
-
-string
-show_userdata(const map<string, string>& userdata)
-{
-    string s;
-
-    for (map<string, string>::const_iterator it = userdata.begin(); it != userdata.end(); ++it)
-    {
-       if (!s.empty())
-           s += ", ";
-       s += it->first + "=" + it->second;
-    }
-
-    return s;
-}
-
-
 struct MyFiles : public Files
 {
     friend class MyComparison;