Merge lp:~mordred/drizzle/bug669635 into lp:drizzle/7.0

Proposed by Monty Taylor
Status: Merged
Approved by: Brian Aker
Approved revision: 1929
Merged at revision: 1932
Proposed branch: lp:~mordred/drizzle/bug669635
Merge into: lp:drizzle/7.0
Diff against target: 298 lines (+111/-79)
2 files modified
drizzled/drizzled.cc (+2/-58)
drizzled/program_options/config_file.h (+109/-21)
To merge this branch: bzr merge lp:~mordred/drizzle/bug669635
Reviewer Review Type Date Requested Status
Drizzle Developers Pending
Review via email: mp+40775@code.launchpad.net

Description of the change

Fixes boolean values in config files, and also size suffix processing.

To post a comment you must log in.
lp:~mordred/drizzle/bug669635 updated
1928. By Monty Taylor

Make sure we pop the pid-file path out to an absolute path in fix_paths,
else the chdir() will screw us up later.

Revision history for this message
Brian Aker (brianaker) wrote :

The formatting and the code style is a bit off. typedef on stl would also be nice.

Do you mind fixing it up before merge?

Thanks,
  -Brian

Revision history for this message
Monty Taylor (mordred) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 11/13/2010 02:02 PM, Brian Aker wrote:
> The formatting and the code style is a bit off. typedef on stl would also be nice.
>
> Do you mind fixing it up before merge?

That file is intended to be submitted upstream to boost once it's done,
so I've been keeping to boost codestyle for it... I could re-format it
for our style if you prefer.

Can totally add the typedef though.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkzfPxcACgkQ2Jv7/VK1RgEQHgCghYDmzU6DenJYykcZDZQoGKHU
W20AniweNdIlD/w+wc426Ole7YFAnXUN
=aXU5
-----END PGP SIGNATURE-----

lp:~mordred/drizzle/bug669635 updated
1929. By Monty Taylor

Cleaned up stylewq

Revision history for this message
Monty Taylor (mordred) wrote :

Ok. I went ahead and fixed the codestyle.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'drizzled/drizzled.cc'
2--- drizzled/drizzled.cc 2010-11-09 17:12:40 +0000
3+++ drizzled/drizzled.cc 2010-11-14 02:07:07 +0000
4@@ -1046,62 +1046,6 @@
5 global_system_variables.transaction_message_threshold= in_transaction_message_threshold;
6 }
7
8-static pair<string, string> parse_size_suffixes(string s)
9-{
10- size_t equal_pos= s.find("=");
11- if (equal_pos != string::npos)
12- {
13- string arg_key(s.substr(0, equal_pos));
14- string arg_val(s.substr(equal_pos+1));
15-
16- try
17- {
18- size_t size_suffix_pos= arg_val.find_last_of("kmgKMG");
19- if (size_suffix_pos == arg_val.size()-1)
20- {
21- char suffix= arg_val[size_suffix_pos];
22- string size_val(arg_val.substr(0, size_suffix_pos));
23-
24- uint64_t base_size= boost::lexical_cast<uint64_t>(size_val);
25- uint64_t new_size= 0;
26-
27- switch (suffix)
28- {
29- case 'K':
30- case 'k':
31- new_size= base_size * 1024;
32- break;
33- case 'M':
34- case 'm':
35- new_size= base_size * 1024 * 1024;
36- break;
37- case 'G':
38- case 'g':
39- new_size= base_size * 1024 * 1024 * 1024;
40- break;
41- }
42- return make_pair(arg_key,
43- boost::lexical_cast<string>(new_size));
44- }
45- }
46- catch (...)
47- {
48- /* Screw it, let the normal parser take over */
49- }
50- }
51-
52- return make_pair(string(""), string(""));
53-}
54-
55-static pair<string, string> parse_size_arg(string s)
56-{
57- if (s.find("--") == 0)
58- {
59- return parse_size_suffixes(s.substr(2));
60- }
61- return make_pair(string(""), string(""));
62-}
63-
64 static void process_defaults_files()
65 {
66 for (vector<string>::iterator iter= defaults_file_list.begin();
67@@ -1502,7 +1446,7 @@
68 {
69 po::parsed_options final_parsed=
70 po::command_line_parser(unknown_options).style(style).
71- options(full_options).extra_parser(parse_size_arg).run();
72+ options(full_options).extra_parser(dpo::parse_size_arg).run();
73
74 final_unknown_options=
75 po::collect_unrecognized(final_parsed.options, po::include_positional);
76@@ -2408,7 +2352,7 @@
77 pid_file_path= getDataHome();
78 pid_file_path /= pid_file;
79 }
80- pid_file= pid_file_path;
81+ pid_file= fs::system_complete(pid_file_path);
82
83 if (not opt_help)
84 {
85
86=== modified file 'drizzled/program_options/config_file.h'
87--- drizzled/program_options/config_file.h 2010-10-02 19:14:34 +0000
88+++ drizzled/program_options/config_file.h 2010-11-14 02:07:07 +0000
89@@ -1,5 +1,6 @@
90 /*
91 * Copyright (c) 2002-2004 Vladimir Prus.
92+ * Copyright (c) 2010 Monty Taylor
93 *
94 * Distributed under the Boost Software License, Version 1.0.
95 * (See accompanying file LICENSE_1_0.txt or copy at
96@@ -28,11 +29,80 @@
97 namespace program_options
98 {
99
100+typedef std::pair<std::string, std::string> option_result_pair;
101+std::string parse_suffix(const std::string& arg_val);
102+option_result_pair parse_size_suffixes(std::string s);
103+option_result_pair parse_size_arg(std::string s);
104+
105+std::string parse_suffix(const std::string& arg_val)
106+{
107+ try
108+ {
109+ size_t size_suffix_pos= arg_val.find_last_of("kmgKMG");
110+ if (size_suffix_pos == arg_val.size()-1)
111+ {
112+ char suffix= arg_val[size_suffix_pos];
113+ std::string size_val(arg_val.substr(0, size_suffix_pos));
114+
115+ uint64_t base_size= boost::lexical_cast<uint64_t>(size_val);
116+ uint64_t new_size= 0;
117+
118+ switch (suffix)
119+ {
120+ case 'K':
121+ case 'k':
122+ new_size= base_size * 1024;
123+ break;
124+ case 'M':
125+ case 'm':
126+ new_size= base_size * 1024 * 1024;
127+ break;
128+ case 'G':
129+ case 'g':
130+ new_size= base_size * 1024 * 1024 * 1024;
131+ break;
132+ }
133+ return boost::lexical_cast<std::string>(new_size);
134+ }
135+ }
136+ catch (...)
137+ { }
138+
139+ return arg_val;
140+}
141+
142+option_result_pair parse_size_suffixes(std::string s)
143+{
144+ size_t equal_pos= s.find("=");
145+ if (equal_pos != std::string::npos)
146+ {
147+ std::string arg_key(s.substr(0, equal_pos));
148+ std::string arg_val(parse_suffix(s.substr(equal_pos+1)));
149+
150+ if (arg_val != s.substr(equal_pos+1))
151+ {
152+ return std::make_pair(arg_key, arg_val);
153+ }
154+ }
155+
156+ return std::make_pair(std::string(""), std::string(""));
157+}
158+
159+option_result_pair parse_size_arg(std::string s)
160+{
161+ if (s.find("--") == 0)
162+ {
163+ return parse_size_suffixes(s.substr(2));
164+ }
165+ return make_pair(std::string(""), std::string(""));
166+}
167+
168 class invalid_syntax :
169 public boost::program_options::error
170 {
171 public:
172- enum kind_t {
173+ enum kind_t
174+ {
175 long_not_allowed = 30,
176 long_adjacent_not_allowed,
177 short_adjacent_not_allowed,
178@@ -106,10 +176,10 @@
179
180 invalid_syntax::invalid_syntax(const std::string& in_tokens,
181 invalid_syntax::kind_t in_kind) :
182- boost::program_options::error(error_message(in_kind).append(" in '").append(in_tokens).append("'"))
183-, m_tokens(in_tokens)
184- , m_kind(in_kind)
185-{}
186+ boost::program_options::error(error_message(in_kind).append(" in '").append(in_tokens).append("'")),
187+ m_tokens(in_tokens),
188+ m_kind(in_kind)
189+{ }
190
191 namespace detail
192 {
193@@ -185,15 +255,29 @@
194
195 if (!s.empty()) {
196 // Handle section name
197- if (*s.begin() == '[' && *s.rbegin() == ']') {
198+ if (*s.begin() == '[' && *s.rbegin() == ']')
199+ {
200 m_prefix = s.substr(1, s.size()-2);
201 if (*m_prefix.rbegin() != '.')
202 m_prefix += '.';
203 }
204- else if ((n = s.find('=')) != std::string::npos) {
205-
206- std::string name = m_prefix + boost::trim_copy(s.substr(0, n));
207- std::string option_value = boost::trim_copy(s.substr(n+1));
208+ else
209+ {
210+
211+ std::string name;
212+ std::string option_value("true");
213+
214+ if ((n = s.find('=')) != std::string::npos)
215+ {
216+
217+ name = m_prefix + boost::trim_copy(s.substr(0, n));
218+ option_value = boost::trim_copy(parse_suffix(s.substr(n+1)));
219+
220+ }
221+ else
222+ {
223+ name = m_prefix + boost::trim_copy(s);
224+ }
225
226 bool registered = allowed_option(name);
227 if (!registered && !m_allow_unregistered)
228@@ -209,8 +293,6 @@
229 this->value().original_tokens.push_back(option_value);
230 break;
231
232- } else {
233- boost::throw_exception(invalid_syntax(s, invalid_syntax::unrecognized_line));
234 }
235 }
236 }
237@@ -236,7 +318,8 @@
238 {
239 std::string s(name);
240 assert(!s.empty());
241- if (*s.rbegin() == '*') {
242+ if (*s.rbegin() == '*')
243+ {
244 s.resize(s.size()-1);
245 bool bad_prefixes(false);
246 // If 's' is a prefix of one of allowed suffix, then
247@@ -244,11 +327,13 @@
248 // If some element is prefix of 's', then lower_bound will
249 // return the next element.
250 std::set<std::string>::iterator i = allowed_prefixes.lower_bound(s);
251- if (i != allowed_prefixes.end()) {
252+ if (i != allowed_prefixes.end())
253+ {
254 if (i->find(s) == 0)
255 bad_prefixes = true;
256 }
257- if (i != allowed_prefixes.begin()) {
258+ if (i != allowed_prefixes.begin())
259+ {
260 --i;
261 if (s.find(*i) == 0)
262 bad_prefixes = true;
263@@ -338,9 +423,12 @@
264 bool
265 basic_config_file_iterator<charT>::getline(std::string& s)
266 {
267- if (std::getline(*is, s)) {
268+ if (std::getline(*is, s))
269+ {
270 return true;
271- } else {
272+ }
273+ else
274+ {
275 return false;
276 }
277 }
278@@ -365,16 +453,16 @@
279 const boost::program_options::option_description& d= *options[i];
280
281 if (d.long_name().empty())
282- boost::throw_exception(
283- boost::program_options::error("long name required for config file"));
284+ boost::throw_exception(boost::program_options::error("long name required for config file"));
285
286 allowed_options.insert(d.long_name());
287 }
288
289 // Parser return char strings
290 boost::program_options::parsed_options result(&desc);
291- std::copy(detail::basic_config_file_iterator<charT>(
292- is, allowed_options, allow_unregistered),
293+ std::copy(detail::basic_config_file_iterator<charT>(is,
294+ allowed_options,
295+ allow_unregistered),
296 detail::basic_config_file_iterator<charT>(),
297 std::back_inserter(result.options));
298 // Convert char strings into desired type.

Subscribers

People subscribed via source and target branches