mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-11 20:52:30 +00:00
* Was using wide char std::isspace version by mistake.
* More cleanup of old option code. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@910 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -75,7 +75,7 @@ const torrent::Object
|
||||
CommandDownloadSlot::call_value_base(Variable* rawVariable, core::Download* download, const torrent::Object& rawArgs, int base, int unit) {
|
||||
CommandDownloadSlot* command = static_cast<CommandDownloadSlot*>(rawVariable);
|
||||
|
||||
const torrent::Object& arg = to_single_argument(rawArgs);
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
@@ -100,7 +100,7 @@ const torrent::Object
|
||||
CommandDownloadSlot::call_string(Variable* rawVariable, core::Download* download, const torrent::Object& rawArgs) {
|
||||
CommandDownloadSlot* command = static_cast<CommandDownloadSlot*>(rawVariable);
|
||||
|
||||
const torrent::Object& arg = to_single_argument(rawArgs);
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_STRING:
|
||||
|
||||
@@ -74,7 +74,7 @@ const torrent::Object
|
||||
CommandSlot::call_value_base(Variable* rawVariable, const torrent::Object& rawArgs, int base, int unit) {
|
||||
CommandSlot* command = static_cast<CommandSlot*>(rawVariable);
|
||||
|
||||
const torrent::Object& arg = to_single_argument(rawArgs);
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
@@ -99,7 +99,7 @@ const torrent::Object
|
||||
CommandSlot::call_string(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
CommandSlot* command = static_cast<CommandSlot*>(rawVariable);
|
||||
|
||||
const torrent::Object& arg = to_single_argument(rawArgs);
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
switch (arg.type()) {
|
||||
// case torrent::Object::TYPE_VALUE:
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "command_variable.h"
|
||||
#include "parse.h"
|
||||
|
||||
namespace utils {
|
||||
|
||||
@@ -44,7 +45,7 @@ const torrent::Object
|
||||
CommandVariable::set_bool(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawVariable);
|
||||
|
||||
const torrent::Object& arg = to_single_argument(rawArgs);
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_VALUE:
|
||||
@@ -82,7 +83,7 @@ const torrent::Object
|
||||
CommandVariable::set_value(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawVariable);
|
||||
|
||||
const torrent::Object& arg = to_single_argument(rawArgs);
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_NONE:
|
||||
@@ -95,7 +96,7 @@ CommandVariable::set_value(Variable* rawVariable, const torrent::Object& rawArgs
|
||||
|
||||
case torrent::Object::TYPE_STRING:
|
||||
int64_t value;
|
||||
string_to_value_unit(arg.as_string().c_str(), &value, 0, 1);
|
||||
parse_whole_value(arg.as_string().c_str(), &value, 0, 1);
|
||||
|
||||
variable->m_variable = value;
|
||||
break;
|
||||
@@ -118,7 +119,7 @@ const torrent::Object
|
||||
CommandVariable::set_string(Variable* rawVariable, const torrent::Object& rawArgs) {
|
||||
CommandVariable* variable = static_cast<CommandVariable*>(rawVariable);
|
||||
|
||||
const torrent::Object& arg = to_single_argument(rawArgs);
|
||||
const torrent::Object& arg = convert_to_single_argument(rawArgs);
|
||||
|
||||
switch (arg.type()) {
|
||||
case torrent::Object::TYPE_NONE:
|
||||
|
||||
+14
-10
@@ -45,7 +45,7 @@ namespace utils {
|
||||
|
||||
const char*
|
||||
parse_skip_wspace(const char* first, const char* last) {
|
||||
while (first != last && std::iswspace(*first))
|
||||
while (first != last && std::isspace(*first))
|
||||
first++;
|
||||
|
||||
return first;
|
||||
@@ -53,8 +53,8 @@ parse_skip_wspace(const char* first, const char* last) {
|
||||
|
||||
const char*
|
||||
parse_skip_wspace(const char* first) {
|
||||
// Assume iswspace('\0') == false.
|
||||
while (std::iswspace(*first))
|
||||
// Assume isspace('\0') == false.
|
||||
while (std::isspace(*first))
|
||||
first++;
|
||||
|
||||
return first;
|
||||
@@ -76,7 +76,7 @@ parse_string(const char* first, const char* last, std::string* dest) {
|
||||
return ++first;
|
||||
|
||||
} else {
|
||||
if (parse_is_seperator(*first) || std::iswspace(*first))
|
||||
if (parse_is_seperator(*first) || std::isspace(*first))
|
||||
return first;
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ parse_string(const char* first, const char* last, std::string* dest) {
|
||||
return first;
|
||||
}
|
||||
|
||||
const char*
|
||||
void
|
||||
parse_whole_string(const char* first, const char* last, std::string* dest) {
|
||||
first = parse_skip_wspace(first, last);
|
||||
first = parse_string(first, last, dest);
|
||||
@@ -102,8 +102,6 @@ parse_whole_string(const char* first, const char* last, std::string* dest) {
|
||||
|
||||
if (first != last)
|
||||
throw torrent::input_error("Junk at end of input.");
|
||||
|
||||
return first;
|
||||
}
|
||||
|
||||
const char*
|
||||
@@ -116,6 +114,14 @@ parse_value(const char* src, int64_t* value, int base, int unit) {
|
||||
return last;
|
||||
}
|
||||
|
||||
void
|
||||
parse_whole_value(const char* src, int64_t* value, int base, int unit) {
|
||||
const char* last = parse_value_nothrow(src, value, base, unit);
|
||||
|
||||
if (last == src || *parse_skip_wspace(last) != '\0')
|
||||
throw torrent::input_error("Could not convert string to value.");
|
||||
}
|
||||
|
||||
bool
|
||||
parse_whole_value_nothrow(const char* src, int64_t* value, int base, int unit) {
|
||||
const char* last = parse_value_nothrow(src, value, base, unit);
|
||||
@@ -184,7 +190,7 @@ parse_list(const char* first, const char* last, torrent::Object* dest) {
|
||||
return first;
|
||||
}
|
||||
|
||||
const char*
|
||||
void
|
||||
parse_whole_list(const char* first, const char* last, torrent::Object* dest) {
|
||||
std::string str;
|
||||
|
||||
@@ -204,8 +210,6 @@ parse_whole_list(const char* first, const char* last, torrent::Object* dest) {
|
||||
|
||||
if (first != last)
|
||||
throw torrent::input_error("Junk at end of input.");
|
||||
|
||||
return first;
|
||||
}
|
||||
|
||||
std::string
|
||||
|
||||
+11
-2
@@ -54,15 +54,16 @@ const char* parse_skip_wspace(const char* first);
|
||||
const char* parse_skip_wspace(const char* first, const char* last);
|
||||
|
||||
const char* parse_string(const char* first, const char* last, std::string* dest);
|
||||
const char* parse_whole_string(const char* first, const char* last, std::string* dest);
|
||||
void parse_whole_string(const char* first, const char* last, std::string* dest);
|
||||
|
||||
const char* parse_value(const char* src, int64_t* value, int base = 0, int unit = 1);
|
||||
const char* parse_value_nothrow(const char* src, int64_t* value, int base = 0, int unit = 1);
|
||||
|
||||
void parse_whole_value(const char* src, int64_t* value, int base = 0, int unit = 1);
|
||||
bool parse_whole_value_nothrow(const char* src, int64_t* value, int base = 0, int unit = 1);
|
||||
|
||||
const char* parse_list(const char* first, const char* last, torrent::Object* dest);
|
||||
const char* parse_whole_list(const char* first, const char* last, torrent::Object* dest);
|
||||
void parse_whole_list(const char* first, const char* last, torrent::Object* dest);
|
||||
|
||||
std::string convert_list_to_string(const torrent::Object& src);
|
||||
std::string convert_list_to_string(torrent::Object::list_type::const_iterator first, torrent::Object::list_type::const_iterator last);
|
||||
@@ -71,4 +72,12 @@ std::string convert_list_to_command(torrent::Object::list_type::const_iterator f
|
||||
int64_t convert_to_value(const torrent::Object& src, int base = 0, int unit = 1);
|
||||
bool convert_to_value_nothrow(const torrent::Object& src, int64_t* value, int base = 0, int unit = 1);
|
||||
|
||||
inline const torrent::Object&
|
||||
convert_to_single_argument(const torrent::Object& args) {
|
||||
if (args.type() == torrent::Object::TYPE_LIST && args.as_list().size() == 1)
|
||||
return args.as_list().front();
|
||||
else
|
||||
return args;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+51
-75
@@ -42,92 +42,68 @@
|
||||
|
||||
namespace utils {
|
||||
|
||||
const torrent::Object Variable::m_emptyObject;
|
||||
// const char*
|
||||
// Variable::string_to_value_unit(const char* pos, value_type* value, int base, int unit) {
|
||||
// if (unit <= 0)
|
||||
// throw torrent::input_error("Variable::string_to_value_unit(...) received unit <= 0.");
|
||||
|
||||
// Consider throwing an exception.
|
||||
const torrent::Object&
|
||||
Variable::get() {
|
||||
// return m_emptyObject;
|
||||
throw torrent::internal_error("Variable::get() called.");
|
||||
}
|
||||
// char* last;
|
||||
// *value = strtoll(pos, &last, base);
|
||||
|
||||
void
|
||||
Variable::set(const torrent::Object& arg) {
|
||||
throw torrent::internal_error("Variable::set() called.");
|
||||
}
|
||||
// if (last == pos) {
|
||||
// if (strcasecmp(pos, "no") == 0) { *value = 0; return pos + strlen("no"); }
|
||||
// if (strcasecmp(pos, "yes") == 0) { *value = 1; return pos + strlen("yes"); }
|
||||
// if (strcasecmp(pos, "true") == 0) { *value = 1; return pos + strlen("true"); }
|
||||
// if (strcasecmp(pos, "false") == 0) { *value = 0; return pos + strlen("false"); }
|
||||
|
||||
const torrent::Object&
|
||||
Variable::get_d(core::Download* download) {
|
||||
return get();
|
||||
}
|
||||
// throw torrent::input_error("Could not convert string to value.");
|
||||
// }
|
||||
|
||||
void
|
||||
Variable::set_d(core::Download* download, const torrent::Object& arg) {
|
||||
set(arg);
|
||||
}
|
||||
// switch (*last) {
|
||||
// case 'b':
|
||||
// case 'B':
|
||||
// ++last;
|
||||
// break;
|
||||
|
||||
const char*
|
||||
Variable::string_to_value_unit(const char* pos, value_type* value, int base, int unit) {
|
||||
if (unit <= 0)
|
||||
throw torrent::input_error("Variable::string_to_value_unit(...) received unit <= 0.");
|
||||
// case 'k':
|
||||
// case 'K':
|
||||
// *value = *value << 10;
|
||||
// ++last;
|
||||
// break;
|
||||
|
||||
char* last;
|
||||
*value = strtoll(pos, &last, base);
|
||||
// case 'm':
|
||||
// case 'M':
|
||||
// *value = *value << 20;
|
||||
// ++last;
|
||||
// break;
|
||||
|
||||
if (last == pos) {
|
||||
if (strcasecmp(pos, "no") == 0) { *value = 0; return pos + strlen("no"); }
|
||||
if (strcasecmp(pos, "yes") == 0) { *value = 1; return pos + strlen("yes"); }
|
||||
if (strcasecmp(pos, "true") == 0) { *value = 1; return pos + strlen("true"); }
|
||||
if (strcasecmp(pos, "false") == 0) { *value = 0; return pos + strlen("false"); }
|
||||
// case 'g':
|
||||
// case 'G':
|
||||
// *value = *value << 30;
|
||||
// ++last;
|
||||
// break;
|
||||
|
||||
throw torrent::input_error("Could not convert string to value.");
|
||||
}
|
||||
// case ' ':
|
||||
// case '\0':
|
||||
// *value = *value * unit;
|
||||
// break;
|
||||
|
||||
switch (*last) {
|
||||
case 'b':
|
||||
case 'B':
|
||||
++last;
|
||||
break;
|
||||
// default:
|
||||
// throw torrent::input_error("Could not parse value.");
|
||||
// }
|
||||
|
||||
case 'k':
|
||||
case 'K':
|
||||
*value = *value << 10;
|
||||
++last;
|
||||
break;
|
||||
// return last;
|
||||
// }
|
||||
|
||||
case 'm':
|
||||
case 'M':
|
||||
*value = *value << 20;
|
||||
++last;
|
||||
break;
|
||||
// bool
|
||||
// Variable::string_to_value_unit_nothrow(const char* pos, value_type* value, int base, int unit) {
|
||||
// try {
|
||||
// string_to_value_unit(pos, value, base, unit);
|
||||
|
||||
case 'g':
|
||||
case 'G':
|
||||
*value = *value << 30;
|
||||
++last;
|
||||
break;
|
||||
|
||||
case ' ':
|
||||
case '\0':
|
||||
*value = *value * unit;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw torrent::input_error("Could not parse value.");
|
||||
}
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
bool
|
||||
Variable::string_to_value_unit_nothrow(const char* pos, value_type* value, int base, int unit) {
|
||||
try {
|
||||
string_to_value_unit(pos, value, base, unit);
|
||||
|
||||
return true;
|
||||
} catch (const torrent::input_error& e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// return true;
|
||||
// } catch (const torrent::input_error& e) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -56,35 +56,11 @@ public:
|
||||
Variable() {}
|
||||
virtual ~Variable() {}
|
||||
|
||||
virtual const torrent::Object& get();
|
||||
virtual void set(const torrent::Object& arg);
|
||||
|
||||
// The default action is to throw away the 'download' argument.
|
||||
virtual const torrent::Object& get_d(core::Download* download);
|
||||
virtual void set_d(core::Download* download, const torrent::Object& arg);
|
||||
|
||||
static const char* string_to_value_unit(const char* pos, value_type* value, int base, int unit);
|
||||
static bool string_to_value_unit_nothrow(const char* pos, value_type* value, int base, int unit);
|
||||
|
||||
static const torrent::Object& to_single_argument(const torrent::Object& args);
|
||||
|
||||
// Temporary hack, until torrent::Object is extended to allow
|
||||
// references so we can return a copy, not a const reference.
|
||||
static const torrent::Object m_emptyObject;
|
||||
|
||||
protected:
|
||||
Variable(const Variable&);
|
||||
void operator = (const Variable&);
|
||||
};
|
||||
|
||||
inline const torrent::Object&
|
||||
Variable::to_single_argument(const torrent::Object& args) {
|
||||
if (args.type() == torrent::Object::TYPE_LIST && args.as_list().size() == 1)
|
||||
return args.as_list().front();
|
||||
else
|
||||
return args;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -129,11 +129,11 @@ VariableMap::process_single(const char* first, const char* last) {
|
||||
throw torrent::input_error("Could not find '='.");
|
||||
|
||||
mapped_type args;
|
||||
first = parse_whole_list(first + 1, last, &args);
|
||||
parse_whole_list(first + 1, last, &args);
|
||||
|
||||
call_command(key.c_str(), args);
|
||||
|
||||
return first;
|
||||
return last;
|
||||
}
|
||||
|
||||
const char*
|
||||
@@ -151,11 +151,11 @@ VariableMap::process_d_single(core::Download* download, const char* first, const
|
||||
throw torrent::input_error("Could not find '='.");
|
||||
|
||||
mapped_type args;
|
||||
first = parse_whole_list(first + 1, last, &args);
|
||||
parse_whole_list(first + 1, last, &args);
|
||||
|
||||
call_command_d(key.c_str(), download, args);
|
||||
|
||||
return first;
|
||||
return last;
|
||||
}
|
||||
|
||||
// Consider what the command scheduler should do.
|
||||
|
||||
Reference in New Issue
Block a user