46#include <boost/uuid/detail/sha1.hpp>
57 using namespace boost;
62 typedef posix_time::ptime
ptime;
64 typedef gregorian::date
date;
68 typedef boost::filesystem::path
path;
89 const string& file, std::size_t
line);
93 ((x) ? ((void)0) : debug_assert(#x, BOOST_CURRENT_FUNCTION, \
98#define assert(x) ((void)(x))
115#define VERIFY(x) if (ledger::verify_enabled) { assert(x); }
116#define DO_VERIFY() ledger::verify_enabled
128#define TRACE_CTOR(cls, args) \
130 ledger::trace_ctor_func(this, #cls, args, sizeof(cls)) : ((void)0))
131#define TRACE_DTOR(cls) \
133 ledger::trace_dtor_func(this, #cls, sizeof(cls)) : ((void)0))
142#define DO_VERIFY() false
143#define TRACE_CTOR(cls, args)
144#define TRACE_DTOR(cls)
148#define IF_VERIFY() if (DO_VERIFY())
169 std::ostringstream buf;
175 std::ostringstream buf;
186inline string operator+(
const char * left,
const string& right) {
187 return string(left) + right;
225 static const char * const _this_category = cat
231#define SHOW_TRACE(lvl) \
232 (ledger::_log_level >= ledger::LOG_TRACE && lvl <= ledger::_trace_level)
233#define TRACE(lvl, msg) \
235 ((ledger::_log_buffer << msg), \
236 ledger::logger_func(ledger::LOG_TRACE)) : (void)0)
240#define SHOW_TRACE(lvl) false
241#define TRACE(lvl, msg)
248#if HAVE_BOOST_REGEX_UNICODE
258#if HAVE_BOOST_REGEX_UNICODE
260 boost::regex::perl | boost::regex::icase);
263 boost::regex::perl | boost::regex::icase);
266#if HAVE_BOOST_REGEX_UNICODE
275#define SHOW_DEBUG(cat) \
276 (ledger::_log_level >= ledger::LOG_DEBUG && ledger::category_matches(cat))
277#define SHOW_DEBUG_() SHOW_DEBUG(_this_category)
279#define DEBUG(cat, msg) \
281 ((ledger::_log_buffer << msg), \
282 ledger::logger_func(ledger::LOG_DEBUG)) : (void)0)
283#define DEBUG_(msg) DEBUG(_this_category, msg)
287#define SHOW_DEBUG(cat) false
288#define SHOW_DEBUG_() false
289#define DEBUG(cat, msg)
294#define LOG_MACRO(level, msg) \
295 (ledger::_log_level >= level ? \
296 ((ledger::_log_buffer << msg), ledger::logger_func(level)) : (void)0)
298#define SHOW_INFO() (ledger::_log_level >= ledger::LOG_INFO)
299#define SHOW_WARN() (ledger::_log_level >= ledger::LOG_WARN)
300#define SHOW_ERROR() (ledger::_log_level >= ledger::LOG_ERROR)
301#define SHOW_FATAL() (ledger::_log_level >= ledger::LOG_FATAL)
302#define SHOW_CRITICAL() (ledger::_log_level >= ledger::LOG_CRIT)
304#define INFO(msg) LOG_MACRO(ledger::LOG_INFO, msg)
305#define WARN(msg) LOG_MACRO(ledger::LOG_WARN, msg)
306#define ERROR(msg) LOG_MACRO(ledger::LOG_ERROR, msg)
307#define FATAL(msg) LOG_MACRO(ledger::LOG_FATAL, msg)
308#define CRITICAL(msg) LOG_MACRO(ledger::LOG_CRIT, msg)
309#define EXCEPTION(msg) LOG_MACRO(ledger::LOG_EXCEPT, msg)
317#define SHOW_TRACE(lvl) false
318#define SHOW_DEBUG(cat) false
319#define SHOW_DEBUG_() false
320#define SHOW_INFO() false
321#define SHOW_WARN() false
322#define SHOW_ERROR() false
323#define SHOW_FATAL() false
324#define SHOW_CRITICAL() false
326#define TRACE(lvl, msg)
327#define DEBUG(cat, msg)
337#define IF_TRACE(lvl) if (SHOW_TRACE(lvl))
338#define IF_DEBUG(cat) if (SHOW_DEBUG(cat))
339#define IF_DEBUG_() if (SHOW_DEBUG_())
340#define IF_INFO() if (SHOW_INFO())
341#define IF_WARN() if (SHOW_WARN())
342#define IF_ERROR() if (SHOW_ERROR())
343#define IF_FATAL() if (SHOW_FATAL())
344#define IF_CRITICAL() if (SHOW_CRITICAL())
354#if LOGGING_ON && TIMERS_ON
363#define TRACE_START(name, lvl, msg) \
365 ((ledger::_log_buffer << msg), \
366 ledger::start_timer(#name, ledger::LOG_TRACE)) : ((void)0))
367#define TRACE_STOP(name, lvl) \
368 (SHOW_TRACE(lvl) ? ledger::stop_timer(#name) : ((void)0))
369#define TRACE_FINISH(name, lvl) \
370 (SHOW_TRACE(lvl) ? ledger::finish_timer(#name) : ((void)0))
372#define TRACE_START(name, lvl, msg)
373#define TRACE_STOP(name, lvl)
374#define TRACE_FINISH(name, lvl)
378#define DEBUG_START(name, cat, msg) \
380 ((ledger::_log_buffer << msg), \
381 ledger::start_timer(#name, ledger::LOG_DEBUG)) : ((void)0))
382#define DEBUG_START_(name, msg) \
383 DEBUG_START_(name, _this_category, msg)
384#define DEBUG_STOP(name, cat) \
385 (SHOW_DEBUG(cat) ? ledger::stop_timer(#name) : ((void)0))
386#define DEBUG_STOP_(name) \
387 DEBUG_STOP_(name, _this_category)
388#define DEBUG_FINISH(name, cat) \
389 (SHOW_DEBUG(cat) ? ledger::finish_timer(#name) : ((void)0))
390#define DEBUG_FINISH_(name) \
391 DEBUG_FINISH_(name, _this_category)
393#define DEBUG_START(name, cat, msg)
394#define DEBUG_START_(name, msg)
395#define DEBUG_STOP(name)
396#define DEBUG_FINISH(name)
399#define INFO_START(name, msg) \
401 ((ledger::_log_buffer << msg), \
402 ledger::start_timer(#name, ledger::LOG_INFO)) : ((void)0))
403#define INFO_STOP(name) \
404 (SHOW_INFO() ? stop_timer(#name) : ((void)0))
405#define INFO_FINISH(name) \
406 (SHOW_INFO() ? finish_timer(#name) : ((void)0))
412#define TRACE_START(lvl, msg, name)
413#define TRACE_STOP(name, lvl)
414#define TRACE_FINISH(name, lvl)
416#define DEBUG_START(name, msg)
417#define DEBUG_START_(name, cat, msg)
418#define DEBUG_STOP(name)
419#define DEBUG_FINISH(name)
421#define INFO_START(name, msg)
422#define INFO_STOP(name)
423#define INFO_FINISH(name)
451 throw std::runtime_error(_(
"Interrupted by user (use Control-D to quit)"));
453 throw std::runtime_error(_(
"Pipe terminated"));
462#define foreach BOOST_FOREACH
463using std::unique_ptr;
467template <
typename T,
typename U>
480 while (*ptr ==
' ' || *ptr ==
'\t' || *ptr ==
'\n')
486 std::size_t len = std::strlen(ptr);
487 int i =
int(len) - 1;
488 while (
i >= 0 && (ptr[
i] ==
' ' || ptr[
i] ==
'\t' || ptr[
i] ==
'\n'))
494 for (
char *
p = buf; *
p;
p++) {
495 if (! (*
p ==
' ' || *
p ==
'\t'))
502 else if (*
p ==
'\t') {
506 else if (*(
p + 1) ==
' ') {
516 while (
in.good() && !
in.eof() && std::isspace(
c)) {
523#define READ_INTO(str, targ, size, var, cond) { \
526 while (str.good() && ! str.eof() && var != '\n' && \
527 (cond) && _p - targ < size) { \
536 case 'b': var = '\b'; break; \
537 case 'f': var = '\f'; break; \
538 case 'n': var = '\n'; break; \
539 case 'r': var = '\r'; break; \
540 case 't': var = '\t'; break; \
541 case 'v': var = '\v'; break; \
551#define READ_INTO_(str, targ, size, var, idx, cond) { \
554 while (str.good() && ! str.eof() && var != '\n' && \
555 (cond) && _p - targ < size) { \
565 case 'b': var = '\b'; break; \
566 case 'f': var = '\f'; break; \
567 case 'n': var = '\n'; break; \
568 case 'r': var = '\r'; break; \
569 case 't': var = '\t'; break; \
570 case 'v': var = '\v'; break; \
583 size_t len =
sizeof(boost::uuids::detail::sha1::digest_type) * 2
585 std::ostringstream buf;
586 buf.setf(std::ios_base::hex, std::ios_base::basefield);
590 const size_t count = std::min(
594 for(
size_t i = 0;
i < count;
i++) {
598 string hex = buf.str();
599 hex.resize(len,
'0');
605 size_t len =
sizeof(boost::uuids::detail::sha1::digest_type) * 2
607 static boost::uuids::detail::sha1
sha;
611 sha.process_bytes(str.c_str(), str.length());
void sigint_handler(int sig)
void sigpipe_handler(int sig)
caught_signal_t caught_signal
boost::filesystem::ifstream ifstream
boost::filesystem::ofstream ofstream
string operator+(const char *left, const string &right)
string lowered(const string &str)
const string & either_or(const string &first, const string &second)
ptime::time_duration_type time_duration
boost::filesystem::filesystem_error filesystem_error
gregorian::date_duration date_duration
string sha1sum(const string &str, size_t len=sizeof(boost::uuids::detail::sha1::digest_type) *2)
char * next_element(char *buf, bool variable=false)
string to_string(long num)
boost::filesystem::path path
char * trim_ws(char *ptr)
int peek_next_nonws(std::istream &in)
void debug_assert(const string &reason, const string &func, const string &file, std::size_t line)
std::list< string > strings_list
posix_time::seconds seconds
string digest_to_hex(const boost::uuids::detail::sha1::digest_type &message_digest, size_t len=sizeof(boost::uuids::detail::sha1::digest_type) *2)
path resolve_path(const path &pathname)
strings_list split_arguments(const char *line)
char * skip_ws(char *ptr)