From 0dbb38fe27e81790451a8233c5959e0fe26dc5ee Mon Sep 17 00:00:00 2001 From: Tim Crews Date: Fri, 14 Jun 2013 21:29:47 -0700 Subject: Source changes needed for Microsoft Visual C++ compatibility. Includes an implementation of strptime, compiled only for Win32 platform. --- src/CMakeLists.txt | 4 +- src/account.h | 4 +- src/history.cc | 4 +- src/strptime.cpp | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/strptime.h | 6 ++ src/times.cc | 4 ++ 6 files changed, 206 insertions(+), 5 deletions(-) create mode 100644 src/strptime.cpp create mode 100644 src/strptime.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2d6b22f7..9fd7d295 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -48,7 +48,8 @@ set(LEDGER_SOURCES mask.cc times.cc error.cc - utils.cc) + utils.cc + strptime.cc) if(HAVE_BOOST_PYTHON) list(APPEND LEDGER_SOURCES @@ -130,6 +131,7 @@ set(LEDGER_INCLUDES value.h views.h xact.h + strptime.h ${PROJECT_BINARY_DIR}/system.hh) if(CMAKE_BUILD_TYPE STREQUAL "Debug") diff --git a/src/account.h b/src/account.h index 7b53de15..daeee038 100644 --- a/src/account.h +++ b/src/account.h @@ -128,11 +128,11 @@ public: accounts_map_seconds_iterator accounts_begin() { return make_transform_iterator - (accounts.begin(), bind(&accounts_map::value_type::second, _1)); + (accounts.begin(), boost::bind(&accounts_map::value_type::second, _1)); } accounts_map_seconds_iterator accounts_end() { return make_transform_iterator - (accounts.end(), bind(&accounts_map::value_type::second, _1)); + (accounts.end(), boost::bind(&accounts_map::value_type::second, _1)); } void add_post(post_t * post); diff --git a/src/history.cc b/src/history.cc index dde8c441..93883ae0 100644 --- a/src/history.cc +++ b/src/history.cc @@ -334,7 +334,7 @@ void commodity_history_impl_t::map_prices( FNameMap namemap(get(vertex_name, fg)); graph_traits::adjacency_iterator f_vi, f_vend; - for (tie(f_vi, f_vend) = adjacent_vertices(sv, fg); f_vi != f_vend; ++f_vi) { + for (boost::tuples::tie(f_vi, f_vend) = adjacent_vertices(sv, fg); f_vi != f_vend; ++f_vi) { std::pair edgePair = edge(sv, *f_vi, fg); Graph::edge_descriptor edge = edgePair.first; @@ -392,7 +392,7 @@ commodity_history_impl_t::find_price(const commodity_t& source, amount_t price; graph_traits::adjacency_iterator f_vi, f_vend; - for (tie(f_vi, f_vend) = adjacent_vertices(sv, fg); f_vi != f_vend; ++f_vi) { + for (boost::tuples::tie(f_vi, f_vend) = adjacent_vertices(sv, fg); f_vi != f_vend; ++f_vi) { std::pair edgePair = edge(sv, *f_vi, fg); Graph::edge_descriptor edge = edgePair.first; diff --git a/src/strptime.cpp b/src/strptime.cpp new file mode 100644 index 00000000..b64af96b --- /dev/null +++ b/src/strptime.cpp @@ -0,0 +1,189 @@ +// Copyright 2009 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +#ifdef WIN32 +// Implement strptime under windows + +#include "strptime.h" + +#include +#include +#include + +static const char* kWeekFull[] = { + "Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday" +}; + +static const char* kWeekAbbr[] = { + "Sun", "Mon", "Tue", "Wed", + "Thu", "Fri", "Sat" +}; + +static const char* kMonthFull[] = { + "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December" +}; + +static const char* kMonthAbbr[] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" +}; + +static const char* _parse_num(const char* s, int low, int high, int* value) { + const char* p = s; + for (*value = 0; *p != NULL && isdigit(*p); ++p) { + *value = (*value) * 10 + static_cast(*p) - static_cast('0'); + } + + if (p == s || *value < low || *value > high) return NULL; + return p; +} + +static char* _strptime(const char *s, const char *format, struct tm *tm) { + while (*format != NULL && *s != NULL) { + if (*format != '%') { + if (*s != *format) return NULL; + + ++format; + ++s; + continue; + } + + ++format; + int len = 0; + switch (*format) { + // weekday name. + case 'a': + case 'A': + tm->tm_wday = -1; + for (int i = 0; i < 7; ++i) { + len = static_cast(strlen(kWeekAbbr[i])); + if (strnicmp(kWeekAbbr[i], s, len) == 0) { + tm->tm_wday = i; + break; + } + + len = static_cast(strlen(kWeekFull[i])); + if (strnicmp(kWeekFull[i], s, len) == 0) { + tm->tm_wday = i; + break; + } + } + if (tm->tm_wday == -1) return NULL; + s += len; + break; + + // month name. + case 'b': + case 'B': + case 'h': + tm->tm_mon = -1; + for (int i = 0; i < 12; ++i) { + len = static_cast(strlen(kMonthAbbr[i])); + if (strnicmp(kMonthAbbr[i], s, len) == 0) { + tm->tm_mon = i; + break; + } + + len = static_cast(strlen(kMonthFull[i])); + if (strnicmp(kMonthFull[i], s, len) == 0) { + tm->tm_mon = i; + break; + } + } + if (tm->tm_mon == -1) return NULL; + s += len; + break; + + // month [1, 12]. + case 'm': + s = _parse_num(s, 1, 12, &tm->tm_mon); + if (s == NULL) return NULL; + --tm->tm_mon; + break; + + // day [1, 31]. + case 'd': + case 'e': + s = _parse_num(s, 1, 31, &tm->tm_mday); + if (s == NULL) return NULL; + break; + + // hour [0, 23]. + case 'H': + s = _parse_num(s, 0, 23, &tm->tm_hour); + if (s == NULL) return NULL; + break; + + // minute [0, 59] + case 'M': + s = _parse_num(s, 0, 59, &tm->tm_min); + if (s == NULL) return NULL; + break; + + // seconds [0, 60]. 60 is for leap year. + case 'S': + s = _parse_num(s, 0, 60, &tm->tm_sec); + if (s == NULL) return NULL; + break; + + // year [1900, 9999]. + case 'Y': + s = _parse_num(s, 1900, 9999, &tm->tm_year); + if (s == NULL) return NULL; + tm->tm_year -= 1900; + break; + + // year [0, 99]. + case 'y': + s = _parse_num(s, 0, 99, &tm->tm_year); + if (s == NULL) return NULL; + if (tm->tm_year <= 68) { + tm->tm_year += 100; + } + break; + + // arbitray whitespace. + case 't': + case 'n': + while (isspace(*s)) ++s; + break; + + // '%'. + case '%': + if (*s != '%') return NULL; + ++s; + break; + + // All the other format are not supported. + default: + return NULL; + } + ++format; + } + + if (*format != NULL) { + return NULL; + } else { + return const_cast(s); + } +} + +char* strptime(const char *buf, const char *fmt, struct tm *tm) { + return _strptime(buf, fmt, tm); +} + +#endif // WIN32 diff --git a/src/strptime.h b/src/strptime.h new file mode 100644 index 00000000..f5482201 --- /dev/null +++ b/src/strptime.h @@ -0,0 +1,6 @@ +#ifndef STRPTIME_H +#define STRPTIME_H + +char* strptime(const char *buf, const char *fmt, struct tm *tm); + +#endif \ No newline at end of file diff --git a/src/times.cc b/src/times.cc index f9a6c279..b1cb3494 100644 --- a/src/times.cc +++ b/src/times.cc @@ -33,6 +33,10 @@ #include "times.h" +#ifdef WIN32 +#include "strptime.h" +#endif + namespace ledger { optional epoch; -- cgit v1.2.3 From 0c071d6e1c52006e1a582ccb1ba5b2c31e6bc1d8 Mon Sep 17 00:00:00 2001 From: Tim Crews Date: Sat, 15 Jun 2013 16:37:04 -0700 Subject: Corrected filename for strptime.cc --- src/strptime.cc | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/strptime.cpp | 189 ------------------------------------------------------- 2 files changed, 189 insertions(+), 189 deletions(-) create mode 100644 src/strptime.cc delete mode 100644 src/strptime.cpp (limited to 'src') diff --git a/src/strptime.cc b/src/strptime.cc new file mode 100644 index 00000000..b64af96b --- /dev/null +++ b/src/strptime.cc @@ -0,0 +1,189 @@ +// Copyright 2009 Google Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + + +#ifdef WIN32 +// Implement strptime under windows + +#include "strptime.h" + +#include +#include +#include + +static const char* kWeekFull[] = { + "Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday" +}; + +static const char* kWeekAbbr[] = { + "Sun", "Mon", "Tue", "Wed", + "Thu", "Fri", "Sat" +}; + +static const char* kMonthFull[] = { + "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December" +}; + +static const char* kMonthAbbr[] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" +}; + +static const char* _parse_num(const char* s, int low, int high, int* value) { + const char* p = s; + for (*value = 0; *p != NULL && isdigit(*p); ++p) { + *value = (*value) * 10 + static_cast(*p) - static_cast('0'); + } + + if (p == s || *value < low || *value > high) return NULL; + return p; +} + +static char* _strptime(const char *s, const char *format, struct tm *tm) { + while (*format != NULL && *s != NULL) { + if (*format != '%') { + if (*s != *format) return NULL; + + ++format; + ++s; + continue; + } + + ++format; + int len = 0; + switch (*format) { + // weekday name. + case 'a': + case 'A': + tm->tm_wday = -1; + for (int i = 0; i < 7; ++i) { + len = static_cast(strlen(kWeekAbbr[i])); + if (strnicmp(kWeekAbbr[i], s, len) == 0) { + tm->tm_wday = i; + break; + } + + len = static_cast(strlen(kWeekFull[i])); + if (strnicmp(kWeekFull[i], s, len) == 0) { + tm->tm_wday = i; + break; + } + } + if (tm->tm_wday == -1) return NULL; + s += len; + break; + + // month name. + case 'b': + case 'B': + case 'h': + tm->tm_mon = -1; + for (int i = 0; i < 12; ++i) { + len = static_cast(strlen(kMonthAbbr[i])); + if (strnicmp(kMonthAbbr[i], s, len) == 0) { + tm->tm_mon = i; + break; + } + + len = static_cast(strlen(kMonthFull[i])); + if (strnicmp(kMonthFull[i], s, len) == 0) { + tm->tm_mon = i; + break; + } + } + if (tm->tm_mon == -1) return NULL; + s += len; + break; + + // month [1, 12]. + case 'm': + s = _parse_num(s, 1, 12, &tm->tm_mon); + if (s == NULL) return NULL; + --tm->tm_mon; + break; + + // day [1, 31]. + case 'd': + case 'e': + s = _parse_num(s, 1, 31, &tm->tm_mday); + if (s == NULL) return NULL; + break; + + // hour [0, 23]. + case 'H': + s = _parse_num(s, 0, 23, &tm->tm_hour); + if (s == NULL) return NULL; + break; + + // minute [0, 59] + case 'M': + s = _parse_num(s, 0, 59, &tm->tm_min); + if (s == NULL) return NULL; + break; + + // seconds [0, 60]. 60 is for leap year. + case 'S': + s = _parse_num(s, 0, 60, &tm->tm_sec); + if (s == NULL) return NULL; + break; + + // year [1900, 9999]. + case 'Y': + s = _parse_num(s, 1900, 9999, &tm->tm_year); + if (s == NULL) return NULL; + tm->tm_year -= 1900; + break; + + // year [0, 99]. + case 'y': + s = _parse_num(s, 0, 99, &tm->tm_year); + if (s == NULL) return NULL; + if (tm->tm_year <= 68) { + tm->tm_year += 100; + } + break; + + // arbitray whitespace. + case 't': + case 'n': + while (isspace(*s)) ++s; + break; + + // '%'. + case '%': + if (*s != '%') return NULL; + ++s; + break; + + // All the other format are not supported. + default: + return NULL; + } + ++format; + } + + if (*format != NULL) { + return NULL; + } else { + return const_cast(s); + } +} + +char* strptime(const char *buf, const char *fmt, struct tm *tm) { + return _strptime(buf, fmt, tm); +} + +#endif // WIN32 diff --git a/src/strptime.cpp b/src/strptime.cpp deleted file mode 100644 index b64af96b..00000000 --- a/src/strptime.cpp +++ /dev/null @@ -1,189 +0,0 @@ -// Copyright 2009 Google Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - - -#ifdef WIN32 -// Implement strptime under windows - -#include "strptime.h" - -#include -#include -#include - -static const char* kWeekFull[] = { - "Sunday", "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday" -}; - -static const char* kWeekAbbr[] = { - "Sun", "Mon", "Tue", "Wed", - "Thu", "Fri", "Sat" -}; - -static const char* kMonthFull[] = { - "January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December" -}; - -static const char* kMonthAbbr[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" -}; - -static const char* _parse_num(const char* s, int low, int high, int* value) { - const char* p = s; - for (*value = 0; *p != NULL && isdigit(*p); ++p) { - *value = (*value) * 10 + static_cast(*p) - static_cast('0'); - } - - if (p == s || *value < low || *value > high) return NULL; - return p; -} - -static char* _strptime(const char *s, const char *format, struct tm *tm) { - while (*format != NULL && *s != NULL) { - if (*format != '%') { - if (*s != *format) return NULL; - - ++format; - ++s; - continue; - } - - ++format; - int len = 0; - switch (*format) { - // weekday name. - case 'a': - case 'A': - tm->tm_wday = -1; - for (int i = 0; i < 7; ++i) { - len = static_cast(strlen(kWeekAbbr[i])); - if (strnicmp(kWeekAbbr[i], s, len) == 0) { - tm->tm_wday = i; - break; - } - - len = static_cast(strlen(kWeekFull[i])); - if (strnicmp(kWeekFull[i], s, len) == 0) { - tm->tm_wday = i; - break; - } - } - if (tm->tm_wday == -1) return NULL; - s += len; - break; - - // month name. - case 'b': - case 'B': - case 'h': - tm->tm_mon = -1; - for (int i = 0; i < 12; ++i) { - len = static_cast(strlen(kMonthAbbr[i])); - if (strnicmp(kMonthAbbr[i], s, len) == 0) { - tm->tm_mon = i; - break; - } - - len = static_cast(strlen(kMonthFull[i])); - if (strnicmp(kMonthFull[i], s, len) == 0) { - tm->tm_mon = i; - break; - } - } - if (tm->tm_mon == -1) return NULL; - s += len; - break; - - // month [1, 12]. - case 'm': - s = _parse_num(s, 1, 12, &tm->tm_mon); - if (s == NULL) return NULL; - --tm->tm_mon; - break; - - // day [1, 31]. - case 'd': - case 'e': - s = _parse_num(s, 1, 31, &tm->tm_mday); - if (s == NULL) return NULL; - break; - - // hour [0, 23]. - case 'H': - s = _parse_num(s, 0, 23, &tm->tm_hour); - if (s == NULL) return NULL; - break; - - // minute [0, 59] - case 'M': - s = _parse_num(s, 0, 59, &tm->tm_min); - if (s == NULL) return NULL; - break; - - // seconds [0, 60]. 60 is for leap year. - case 'S': - s = _parse_num(s, 0, 60, &tm->tm_sec); - if (s == NULL) return NULL; - break; - - // year [1900, 9999]. - case 'Y': - s = _parse_num(s, 1900, 9999, &tm->tm_year); - if (s == NULL) return NULL; - tm->tm_year -= 1900; - break; - - // year [0, 99]. - case 'y': - s = _parse_num(s, 0, 99, &tm->tm_year); - if (s == NULL) return NULL; - if (tm->tm_year <= 68) { - tm->tm_year += 100; - } - break; - - // arbitray whitespace. - case 't': - case 'n': - while (isspace(*s)) ++s; - break; - - // '%'. - case '%': - if (*s != '%') return NULL; - ++s; - break; - - // All the other format are not supported. - default: - return NULL; - } - ++format; - } - - if (*format != NULL) { - return NULL; - } else { - return const_cast(s); - } -} - -char* strptime(const char *buf, const char *fmt, struct tm *tm) { - return _strptime(buf, fmt, tm); -} - -#endif // WIN32 -- cgit v1.2.3 From 4bcaa45f1663ca4ce3399ae412642624050c5060 Mon Sep 17 00:00:00 2001 From: Tim Crews Date: Sun, 16 Jun 2013 12:39:30 -0700 Subject: Additional changes required for MSVC to compile ledger. These changes only matter if ledger is compiled with USE_PYTHON. --- src/history.h | 4 ++-- src/py_commodity.cc | 12 ++++++------ src/pyinterp.cc | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/history.h b/src/history.h index baefb333..fa69d8da 100644 --- a/src/history.h +++ b/src/history.h @@ -76,12 +76,12 @@ public: const datetime_t& _oldest = datetime_t(), bool bidirectionally = false); - optional + boost::optional find_price(const commodity_t& source, const datetime_t& moment, const datetime_t& oldest = datetime_t()); - optional + boost::optional find_price(const commodity_t& source, const commodity_t& target, const datetime_t& moment, diff --git a/src/py_commodity.cc b/src/py_commodity.cc index 44a45e33..fd932fc7 100644 --- a/src/py_commodity.cc +++ b/src/py_commodity.cc @@ -151,13 +151,13 @@ namespace { py_pool_commodities_keys_begin(commodity_pool_t& pool) { return make_transform_iterator (pool.commodities.begin(), - bind(&commodity_pool_t::commodities_map::value_type::first, _1)); + boost::bind(&commodity_pool_t::commodities_map::value_type::first, _1)); } commodities_map_firsts_iterator py_pool_commodities_keys_end(commodity_pool_t& pool) { return make_transform_iterator (pool.commodities.end(), - bind(&commodity_pool_t::commodities_map::value_type::first, _1)); + boost::bind(&commodity_pool_t::commodities_map::value_type::first, _1)); } typedef transform_iterator @@ -169,15 +169,15 @@ namespace { py_pool_commodities_values_begin(commodity_pool_t& pool) { return make_transform_iterator (pool.commodities.begin(), - bind(&shared_ptr::get, - bind(&commodity_pool_t::commodities_map::value_type::second, _1))); + boost::bind(&shared_ptr::get, + boost::bind(&commodity_pool_t::commodities_map::value_type::second, _1))); } commodities_map_seconds_iterator py_pool_commodities_values_end(commodity_pool_t& pool) { return make_transform_iterator (pool.commodities.end(), - bind(&shared_ptr::get, - bind(&commodity_pool_t::commodities_map::value_type::second, _1))); + boost::bind(&shared_ptr::get, + boost::bind(&commodity_pool_t::commodities_map::value_type::second, _1))); } void py_add_price_2(commodity_t& commodity, diff --git a/src/pyinterp.cc b/src/pyinterp.cc index 3354d3e9..e15ff503 100644 --- a/src/pyinterp.cc +++ b/src/pyinterp.cc @@ -320,7 +320,7 @@ value_t python_interpreter_t::python_command(call_scope_t& args) if (! is_initialized) initialize(); - char ** argv(new char *[args.size() + 1]); + char ** argv = new char *[args.size() + 1]; argv[0] = new char[std::strlen(argv0) + 1]; std::strcpy(argv[0], argv0); -- cgit v1.2.3