13
0

Use boost::tokenizer in PBD::parse_debug_options for portability

This commit is contained in:
Paul Davis 2013-07-11 12:36:16 -04:00
parent 36a55b8674
commit acc13d37a7

View File

@ -24,6 +24,8 @@
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <boost/tokenizer.hpp>
#include "pbd/debug.h" #include "pbd/debug.h"
#include "i18n.h" #include "i18n.h"
@ -75,36 +77,31 @@ PBD::set_debug_bits (uint64_t bits)
int int
PBD::parse_debug_options (const char* str) PBD::parse_debug_options (const char* str)
{ {
char* p; typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
char* sp; boost::char_separator<char> sep (",");
tokenizer tokens (string(str), sep);
uint64_t bits = 0; uint64_t bits = 0;
char* copy = strdup (str);
p = strtok_r (copy, ",", &sp); for (tokenizer::iterator tok_iter = tokens.begin(); tok_iter != tokens.end(); ++tok_iter) {
if (*tok_iter == "list") {
while (p) {
if (strcasecmp (p, "list") == 0) {
list_debug_options (); list_debug_options ();
free (copy);
return 1; return 1;
} }
if (strcasecmp (p, "all") == 0) { if (*tok_iter == "all") {
PBD::set_debug_bits (~0ULL); PBD::set_debug_bits (~0ULL);
free (copy);
return 0; return 0;
} }
for (map<const char*,uint64_t>::iterator i = _debug_bit_map().begin(); i != _debug_bit_map().end(); ++i) { for (map<const char*,uint64_t>::iterator i = _debug_bit_map().begin(); i != _debug_bit_map().end(); ++i) {
if (strncasecmp (p, i->first, strlen (p)) == 0) { const char* cstr = (*tok_iter).c_str();
if (strncasecmp (cstr, i->first, strlen (cstr)) == 0) {
bits |= i->second; bits |= i->second;
} }
} }
p = strtok_r (0, ",", &sp);
} }
free (copy);
PBD::set_debug_bits (bits); PBD::set_debug_bits (bits);
return 0; return 0;
} }