pair<unsigned int, unsigned int>
-read_nums(const string& str)
+read_nums(const string& str, const string& delim = "..")
{
- string::size_type pos = str.find("..");
+ string::size_type pos = str.find(delim);
if (pos == string::npos)
{
cerr << _("Invalid snapshots.") << endl;
}
unsigned int num1 = read_num(str.substr(0, pos));
- unsigned int num2 = read_num(str.substr(pos + 2));
+ unsigned int num2 = read_num(str.substr(pos + delim.size()));
if (num1 == num2)
{
exit(EXIT_FAILURE);
}
+ XSnapshots snapshots = command_list_xsnapshots(conn, config_name);
+
+ list<unsigned int> nums;
+
while (getopts.hasArgs())
{
- unsigned int num = read_num(getopts.popArg());
+ string arg = getopts.popArg();
- list<unsigned int> nums;
- nums.push_back(num);
- command_delete_xsnapshots(conn, config_name, nums);
+ if (arg.find_first_of("-") == string::npos)
+ {
+ unsigned int i = read_num(arg);
+ nums.push_back(i);
+ }
+ else
+ {
+ pair<unsigned int, unsigned int> r(read_nums(arg, "-"));
+
+ if (r.first > r.second)
+ swap(r.first, r.second);
+
+ for (unsigned int i = r.first; i <= r.second; ++i)
+ {
+ if (snapshots.find(i) != snapshots.end() &&
+ find(nums.begin(), nums.end(), i) == nums.end())
+ {
+ nums.push_back(i);
+ }
+ }
+ }
}
+
+ command_delete_xsnapshots(conn, config_name, nums);
}
#include "types.h"
+XSnapshots::const_iterator
+XSnapshots::find(unsigned int num) const
+{
+ for (const_iterator it = begin(); it != end(); ++it)
+ {
+ if (it->getNum() == num)
+ return it;
+ }
+
+ return end();
+}
+
+
XSnapshots::const_iterator
XSnapshots::findPre(const_iterator post) const
{
typedef list<XSnapshot>::const_iterator const_iterator;
const_iterator begin() const { return entries.begin(); }
-
const_iterator end() const { return entries.end(); }
+ const_iterator find(unsigned int num) const;
+
const_iterator findPre(const_iterator post) const;
const_iterator findPost(const_iterator pre) const;