Fixed many compiler warnings from g++ 4.4
This commit is contained in:
parent
dc66840dd7
commit
588f2ef2f5
28 changed files with 150 additions and 123 deletions
|
|
@ -88,7 +88,7 @@ AC_CACHE_CHECK(
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
;
|
;
|
||||||
} else if (status == 0) {
|
} else if (status == 0) {
|
||||||
char *arg0;
|
char *arg0 = NULL;
|
||||||
|
|
||||||
status = dup2(pfd[0], STDIN_FILENO);
|
status = dup2(pfd[0], STDIN_FILENO);
|
||||||
|
|
||||||
|
|
@ -160,8 +160,8 @@ AC_CACHE_CHECK(
|
||||||
[[#include <stdlib.h>
|
[[#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <editline/readline.h>]],
|
#include <editline/readline.h>]],
|
||||||
[[rl_readline_name = "foo";
|
[[rl_readline_name = const_cast<char *>("foo");
|
||||||
char * line = readline("foo: ");
|
char * line = readline(const_cast<char *>("foo: "));
|
||||||
free(line);]])],[libedit_avail_cv_=true],[libedit_avail_cv_=false])
|
free(line);]])],[libedit_avail_cv_=true],[libedit_avail_cv_=false])
|
||||||
AC_LANG_POP
|
AC_LANG_POP
|
||||||
LIBS=$libedit_save_libs])
|
LIBS=$libedit_save_libs])
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ std::streamsize straccbuf::xsputn(const char * s, std::streamsize num)
|
||||||
if (*p == '%') {
|
if (*p == '%') {
|
||||||
const char * q = p + 1;
|
const char * q = p + 1;
|
||||||
if (*q && *q != '%' && std::isdigit(*q) &&
|
if (*q && *q != '%' && std::isdigit(*q) &&
|
||||||
std::size_t(*q - '0') == index) {
|
std::string::size_type(*q - '0') == index) {
|
||||||
p++;
|
p++;
|
||||||
buf << std::string(s, num);
|
buf << std::string(s, num);
|
||||||
matched = true;
|
matched = true;
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ class straccbuf : public std::streambuf
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
std::string str; // accumulator
|
std::string str; // accumulator
|
||||||
std::size_t index;
|
std::string::size_type index;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
straccbuf() : index(0) {}
|
straccbuf() : index(0) {}
|
||||||
|
|
|
||||||
|
|
@ -623,9 +623,9 @@ namespace {
|
||||||
"mpfr_print = " << buf << " (precision " << prec << ")");
|
"mpfr_print = " << buf << " (precision " << prec << ")");
|
||||||
|
|
||||||
if (zeros_prec >= 0) {
|
if (zeros_prec >= 0) {
|
||||||
int index = std::strlen(buf);
|
string::size_type index = std::strlen(buf);
|
||||||
int point = 0;
|
string::size_type point = 0;
|
||||||
for (int i = 0; i < index; i++) {
|
for (string::size_type i = 0; i < index; i++) {
|
||||||
if (buf[i] == '.') {
|
if (buf[i] == '.') {
|
||||||
point = i;
|
point = i;
|
||||||
break;
|
break;
|
||||||
|
|
@ -837,7 +837,7 @@ namespace {
|
||||||
READ_INTO(in, buf, 255, c,
|
READ_INTO(in, buf, 255, c,
|
||||||
std::isdigit(c) || c == '-' || c == '.' || c == ',');
|
std::isdigit(c) || c == '-' || c == '.' || c == ',');
|
||||||
|
|
||||||
int len = std::strlen(buf);
|
string::size_type len = std::strlen(buf);
|
||||||
while (len > 0 && ! std::isdigit(buf[len - 1])) {
|
while (len > 0 && ! std::isdigit(buf[len - 1])) {
|
||||||
buf[--len] = '\0';
|
buf[--len] = '\0';
|
||||||
in.unget();
|
in.unget();
|
||||||
|
|
@ -989,7 +989,7 @@ bool amount_t::parse(std::istream& in, const parse_flags_t& flags)
|
||||||
// necessary.
|
// necessary.
|
||||||
|
|
||||||
if (last_comma != string::npos || last_period != string::npos) {
|
if (last_comma != string::npos || last_period != string::npos) {
|
||||||
int len = quant.length();
|
string::size_type len = quant.length();
|
||||||
scoped_array<char> buf(new char[len + 1]);
|
scoped_array<char> buf(new char[len + 1]);
|
||||||
const char * p = quant.c_str();
|
const char * p = quant.c_str();
|
||||||
char * t = buf.get();
|
char * t = buf.get();
|
||||||
|
|
|
||||||
|
|
@ -66,9 +66,9 @@ post_handler_ptr chain_post_handlers(report_t& report,
|
||||||
handler.reset
|
handler.reset
|
||||||
(new truncate_xacts(handler,
|
(new truncate_xacts(handler,
|
||||||
report.HANDLED(head_) ?
|
report.HANDLED(head_) ?
|
||||||
report.HANDLER(head_).value.to_long() : 0,
|
report.HANDLER(head_).value.to_int() : 0,
|
||||||
report.HANDLED(tail_) ?
|
report.HANDLED(tail_) ?
|
||||||
report.HANDLER(tail_).value.to_long() : 0));
|
report.HANDLER(tail_).value.to_int() : 0));
|
||||||
|
|
||||||
// filter_posts will only pass through posts matching the
|
// filter_posts will only pass through posts matching the
|
||||||
// `display_predicate'.
|
// `display_predicate'.
|
||||||
|
|
|
||||||
|
|
@ -498,9 +498,8 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol)
|
||||||
char * _p = buf;
|
char * _p = buf;
|
||||||
c = static_cast<char>(in.peek());
|
c = static_cast<char>(in.peek());
|
||||||
while (_p - buf < 255 && in.good() && ! in.eof() && c != '\n') {
|
while (_p - buf < 255 && in.good() && ! in.eof() && c != '\n') {
|
||||||
int bytes = 0;
|
std::size_t bytes = 0;
|
||||||
int size = _p - buf;
|
std::ptrdiff_t size = _p - buf;
|
||||||
|
|
||||||
unsigned char d = c;
|
unsigned char d = c;
|
||||||
|
|
||||||
// Check for the start of a UTF-8 multi-byte encoded string
|
// Check for the start of a UTF-8 multi-byte encoded string
|
||||||
|
|
@ -518,7 +517,7 @@ void commodity_t::parse_symbol(std::istream& in, string& symbol)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (bytes > 0) { // we're looking at a UTF-8 encoding
|
if (bytes > 0) { // we're looking at a UTF-8 encoding
|
||||||
for (int i = 0; i < bytes; i++) {
|
for (std::size_t i = 0; i < bytes; i++) {
|
||||||
in.get(c);
|
in.get(c);
|
||||||
if (in.bad() || in.eof())
|
if (in.bad() || in.eof())
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ namespace ledger {
|
||||||
void format_emacs_posts::write_xact(xact_t& xact)
|
void format_emacs_posts::write_xact(xact_t& xact)
|
||||||
{
|
{
|
||||||
out << "\"" << xact.pathname << "\" "
|
out << "\"" << xact.pathname << "\" "
|
||||||
<< (static_cast<std::size_t>(xact.beg_line) + 1) << " ";
|
<< (xact.beg_line + 1) << " ";
|
||||||
|
|
||||||
tm when = gregorian::to_tm(xact.date());
|
tm when = gregorian::to_tm(xact.date());
|
||||||
std::time_t date = std::mktime(&when); // jww (2008-04-20): Is this GMT or local?
|
std::time_t date = std::mktime(&when); // jww (2008-04-20): Is this GMT or local?
|
||||||
|
|
@ -77,7 +77,7 @@ void format_emacs_posts::operator()(post_t& post)
|
||||||
out << "\n";
|
out << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
out << " (" << (static_cast<std::size_t>(post.beg_line) + 1) << " ";
|
out << " (" << (post.beg_line + 1) << " ";
|
||||||
out << "\"" << post.reported_account()->fullname() << "\" \""
|
out << "\"" << post.reported_account()->fullname() << "\" \""
|
||||||
<< post.amount << "\"";
|
<< post.amount << "\"";
|
||||||
|
|
||||||
|
|
|
||||||
23
src/error.cc
23
src/error.cc
|
|
@ -47,7 +47,7 @@ string error_context()
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
string file_context(const path& file, std::size_t line)
|
string file_context(const path& file, const std::size_t line)
|
||||||
{
|
{
|
||||||
std::ostringstream buf;
|
std::ostringstream buf;
|
||||||
buf << "\"" << file << "\", line " << line << ": ";
|
buf << "\"" << file << "\", line " << line << ": ";
|
||||||
|
|
@ -55,8 +55,8 @@ string file_context(const path& file, std::size_t line)
|
||||||
}
|
}
|
||||||
|
|
||||||
string line_context(const string& line,
|
string line_context(const string& line,
|
||||||
std::size_t pos,
|
const string::size_type pos,
|
||||||
std::size_t end_pos)
|
const string::size_type end_pos)
|
||||||
{
|
{
|
||||||
std::ostringstream buf;
|
std::ostringstream buf;
|
||||||
buf << " " << line << "\n";
|
buf << " " << line << "\n";
|
||||||
|
|
@ -64,11 +64,11 @@ string line_context(const string& line,
|
||||||
if (pos != 0) {
|
if (pos != 0) {
|
||||||
buf << " ";
|
buf << " ";
|
||||||
if (end_pos == 0) {
|
if (end_pos == 0) {
|
||||||
for (std::size_t i = 0; i < pos; i += 1)
|
for (string::size_type i = 0; i < pos; i += 1)
|
||||||
buf << " ";
|
buf << " ";
|
||||||
buf << "^";
|
buf << "^";
|
||||||
} else {
|
} else {
|
||||||
for (std::size_t i = 0; i < end_pos; i += 1) {
|
for (string::size_type i = 0; i < end_pos; i += 1) {
|
||||||
if (i >= pos)
|
if (i >= pos)
|
||||||
buf << "^";
|
buf << "^";
|
||||||
else
|
else
|
||||||
|
|
@ -80,11 +80,11 @@ string line_context(const string& line,
|
||||||
}
|
}
|
||||||
|
|
||||||
string source_context(const path& file,
|
string source_context(const path& file,
|
||||||
istream_pos_type pos,
|
const istream_pos_type pos,
|
||||||
istream_pos_type end_pos,
|
const istream_pos_type end_pos,
|
||||||
const string& prefix)
|
const string& prefix)
|
||||||
{
|
{
|
||||||
std::streamoff len = end_pos - pos;
|
const std::streamoff len = end_pos - pos;
|
||||||
if (! len || file == path("/dev/stdin"))
|
if (! len || file == path("/dev/stdin"))
|
||||||
return _("<no source context>");
|
return _("<no source context>");
|
||||||
|
|
||||||
|
|
@ -97,10 +97,9 @@ string source_context(const path& file,
|
||||||
in.seekg(pos, std::ios::beg);
|
in.seekg(pos, std::ios::beg);
|
||||||
|
|
||||||
scoped_array<char> buf(new char[len + 1]);
|
scoped_array<char> buf(new char[len + 1]);
|
||||||
in.read(buf.get(), static_cast<int>(len));
|
in.read(buf.get(), len);
|
||||||
assert(static_cast<std::size_t>(in.gcount()) ==
|
assert(in.gcount() == len);
|
||||||
static_cast<std::size_t>(len));
|
buf[len] = '\0';
|
||||||
buf[static_cast<int>(len)] = '\0';
|
|
||||||
|
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (char * p = std::strtok(buf.get(), "\n");
|
for (char * p = std::strtok(buf.get(), "\n");
|
||||||
|
|
|
||||||
|
|
@ -88,12 +88,12 @@ string error_context();
|
||||||
|
|
||||||
string file_context(const path& file, std::size_t line);
|
string file_context(const path& file, std::size_t line);
|
||||||
string line_context(const string& line,
|
string line_context(const string& line,
|
||||||
std::size_t pos = 0,
|
const string::size_type pos = 0,
|
||||||
std::size_t end_pos = 0);
|
const string::size_type end_pos = 0);
|
||||||
|
|
||||||
string source_context(const path& file,
|
string source_context(const path& file,
|
||||||
istream_pos_type pos,
|
const istream_pos_type pos,
|
||||||
istream_pos_type end_pos,
|
const istream_pos_type end_pos,
|
||||||
const string& prefix = "");
|
const string& prefix = "");
|
||||||
|
|
||||||
#define DECLARE_EXCEPTION(name, kind) \
|
#define DECLARE_EXCEPTION(name, kind) \
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,8 @@ class truncate_xacts : public item_handler<post_t>
|
||||||
truncate_xacts();
|
truncate_xacts();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
truncate_xacts(post_handler_ptr handler, int _head_count, int _tail_count)
|
truncate_xacts(post_handler_ptr handler,
|
||||||
|
int _head_count, int _tail_count)
|
||||||
: item_handler<post_t>(handler),
|
: item_handler<post_t>(handler),
|
||||||
head_count(_head_count), tail_count(_tail_count),
|
head_count(_head_count), tail_count(_tail_count),
|
||||||
xacts_seen(0), last_xact(NULL) {
|
xacts_seen(0), last_xact(NULL) {
|
||||||
|
|
|
||||||
|
|
@ -345,7 +345,7 @@ void format_t::format(std::ostream& out_str, scope_t& scope)
|
||||||
}
|
}
|
||||||
DEBUG("format.expr", "value = (" << value << ")");
|
DEBUG("format.expr", "value = (" << value << ")");
|
||||||
|
|
||||||
value.print(out, elem->min_width, -1,
|
value.print(out, static_cast<int>(elem->min_width), -1,
|
||||||
! elem->has_flags(ELEMENT_ALIGN_LEFT));
|
! elem->has_flags(ELEMENT_ALIGN_LEFT));
|
||||||
}
|
}
|
||||||
catch (const calc_error&) {
|
catch (const calc_error&) {
|
||||||
|
|
@ -362,14 +362,13 @@ void format_t::format(std::ostream& out_str, scope_t& scope)
|
||||||
|
|
||||||
if (elem->max_width > 0 || elem->min_width > 0) {
|
if (elem->max_width > 0 || elem->min_width > 0) {
|
||||||
unistring temp(out.str());
|
unistring temp(out.str());
|
||||||
|
|
||||||
string result;
|
string result;
|
||||||
|
|
||||||
if (elem->max_width > 0 && elem->max_width < temp.length()) {
|
if (elem->max_width > 0 && elem->max_width < temp.length()) {
|
||||||
result = truncate(temp, elem->max_width);
|
result = truncate(temp, elem->max_width);
|
||||||
} else {
|
} else {
|
||||||
result = temp.extract();
|
result = temp.extract();
|
||||||
for (int i = 0; i < (static_cast<int>(elem->min_width) -
|
for (std::size_t i = 0; i < elem->min_width - temp.length(); i++)
|
||||||
static_cast<int>(temp.length())); i++)
|
|
||||||
result += " ";
|
result += " ";
|
||||||
}
|
}
|
||||||
out_str << result;
|
out_str << result;
|
||||||
|
|
@ -379,8 +378,9 @@ void format_t::format(std::ostream& out_str, scope_t& scope)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string format_t::truncate(const unistring& ustr, std::size_t width,
|
string format_t::truncate(const unistring& ustr,
|
||||||
const int account_abbrev_length)
|
const std::size_t width,
|
||||||
|
const std::size_t account_abbrev_length)
|
||||||
{
|
{
|
||||||
assert(width < 4095);
|
assert(width < 4095);
|
||||||
|
|
||||||
|
|
@ -434,7 +434,7 @@ string format_t::truncate(const unistring& ustr, std::size_t width,
|
||||||
|
|
||||||
if (newlen > width) {
|
if (newlen > width) {
|
||||||
unistring temp(*i);
|
unistring temp(*i);
|
||||||
if (temp.length() > static_cast<std::size_t>(account_abbrev_length)) {
|
if (temp.length() > account_abbrev_length) {
|
||||||
result << temp.extract(0, account_abbrev_length) << ":";
|
result << temp.extract(0, account_abbrev_length) << ":";
|
||||||
newlen -= temp.length() - account_abbrev_length;
|
newlen -= temp.length() - account_abbrev_length;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
12
src/format.h
12
src/format.h
|
|
@ -65,10 +65,7 @@ class format_t : public noncopyable
|
||||||
{
|
{
|
||||||
#define ELEMENT_ALIGN_LEFT 0x01
|
#define ELEMENT_ALIGN_LEFT 0x01
|
||||||
|
|
||||||
enum kind_t {
|
enum kind_t { STRING, EXPR };
|
||||||
STRING,
|
|
||||||
EXPR,
|
|
||||||
};
|
|
||||||
|
|
||||||
kind_t type;
|
kind_t type;
|
||||||
std::size_t min_width;
|
std::size_t min_width;
|
||||||
|
|
@ -89,7 +86,7 @@ class format_t : public noncopyable
|
||||||
friend inline void mark_red(std::ostream& out, const element_t * elem) {
|
friend inline void mark_red(std::ostream& out, const element_t * elem) {
|
||||||
out.setf(std::ios::left);
|
out.setf(std::ios::left);
|
||||||
out.width(0);
|
out.width(0);
|
||||||
out << "\e[31m";
|
out << "\033[31m";
|
||||||
|
|
||||||
if (elem->has_flags(ELEMENT_ALIGN_LEFT))
|
if (elem->has_flags(ELEMENT_ALIGN_LEFT))
|
||||||
out << std::left;
|
out << std::left;
|
||||||
|
|
@ -145,8 +142,9 @@ public:
|
||||||
elem->dump(out);
|
elem->dump(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
static string truncate(const unistring& str, std::size_t width,
|
static string truncate(const unistring& str,
|
||||||
const int account_abbrev_length = -1);
|
const std::size_t width,
|
||||||
|
const std::size_t account_abbrev_length = 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define FMT_PREFIX "fmt_"
|
#define FMT_PREFIX "fmt_"
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,10 @@ inline bool interactive_t::get<bool>(std::size_t index) {
|
||||||
return value_at(index).to_boolean();
|
return value_at(index).to_boolean();
|
||||||
}
|
}
|
||||||
template <>
|
template <>
|
||||||
|
inline int interactive_t::get<int>(std::size_t index) {
|
||||||
|
return value_at(index).to_int();
|
||||||
|
}
|
||||||
|
template <>
|
||||||
inline long interactive_t::get<long>(std::size_t index) {
|
inline long interactive_t::get<long>(std::size_t index) {
|
||||||
return value_at(index).to_long();
|
return value_at(index).to_long();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ void item_t::parse_tags(const char * p, optional<date_t::year_type> current_year
|
||||||
for (char * q = std::strtok(buf.get(), " \t");
|
for (char * q = std::strtok(buf.get(), " \t");
|
||||||
q;
|
q;
|
||||||
q = std::strtok(NULL, " \t")) {
|
q = std::strtok(NULL, " \t")) {
|
||||||
const std::size_t len = std::strlen(q);
|
const string::size_type len = std::strlen(q);
|
||||||
if (! tag.empty()) {
|
if (! tag.empty()) {
|
||||||
if (! has_tag(tag))
|
if (! has_tag(tag))
|
||||||
set_tag(tag, string(p + (q - buf.get())));
|
set_tag(tag, string(p + (q - buf.get())));
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ void process_environment(const char ** envp, const string& tag,
|
||||||
scope_t& scope)
|
scope_t& scope)
|
||||||
{
|
{
|
||||||
const char * tag_p = tag.c_str();
|
const char * tag_p = tag.c_str();
|
||||||
std::size_t tag_len = tag.length();
|
string::size_type tag_len = tag.length();
|
||||||
|
|
||||||
for (const char ** p = envp; *p; p++) {
|
for (const char ** p = envp; *p; p++) {
|
||||||
if (! tag_p || std::strncmp(*p, tag_p, tag_len) == 0) {
|
if (! tag_p || std::strncmp(*p, tag_p, tag_len) == 0) {
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ class option_t
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
const char * name;
|
const char * name;
|
||||||
std::size_t name_len;
|
string::size_type name_len;
|
||||||
const char ch;
|
const char ch;
|
||||||
bool handled;
|
bool handled;
|
||||||
optional<string> source;
|
optional<string> source;
|
||||||
|
|
|
||||||
|
|
@ -491,9 +491,10 @@ expr_t::parser_t::parse(std::istream& in, const parse_flags_t& flags,
|
||||||
if (original_string) {
|
if (original_string) {
|
||||||
add_error_context(_("While parsing value expression:"));
|
add_error_context(_("While parsing value expression:"));
|
||||||
|
|
||||||
std::size_t end_pos =
|
std::streamoff end_pos = 0;
|
||||||
in.good() ? static_cast<std::size_t>(in.tellg()) : 0;
|
if (in.good())
|
||||||
std::size_t pos = static_cast<std::size_t>(end_pos);
|
end_pos = in.tellg();
|
||||||
|
std::streamoff pos = end_pos;
|
||||||
|
|
||||||
if (pos > 0)
|
if (pos > 0)
|
||||||
pos -= lookahead.length;
|
pos -= lookahead.length;
|
||||||
|
|
@ -504,7 +505,9 @@ expr_t::parser_t::parse(std::istream& in, const parse_flags_t& flags,
|
||||||
DEBUG("parser.error", " token kind = " << int(lookahead.kind));
|
DEBUG("parser.error", " token kind = " << int(lookahead.kind));
|
||||||
DEBUG("parser.error", " token length = " << lookahead.length);
|
DEBUG("parser.error", " token length = " << lookahead.length);
|
||||||
|
|
||||||
add_error_context(line_context(*original_string, pos, end_pos));
|
add_error_context(line_context(*original_string,
|
||||||
|
static_cast<string::size_type>(pos),
|
||||||
|
static_cast<string::size_type>(end_pos)));
|
||||||
}
|
}
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,8 @@ namespace {
|
||||||
string name = env->reported_account()->fullname();
|
string name = env->reported_account()->fullname();
|
||||||
|
|
||||||
if (env.has(0) && env.get<long>(0) > 2)
|
if (env.has(0) && env.get<long>(0) > 2)
|
||||||
name = format_t::truncate(name, env.get<long>(0) - 2, true);
|
name = format_t::truncate(name, env.get<long>(0) - 2,
|
||||||
|
2 /* account_abbrev_length */);
|
||||||
|
|
||||||
if (env->has_flags(POST_VIRTUAL)) {
|
if (env->has_flags(POST_VIRTUAL)) {
|
||||||
if (env->must_balance())
|
if (env->must_balance())
|
||||||
|
|
|
||||||
|
|
@ -109,8 +109,8 @@ protected:
|
||||||
* - at most, pbSize characters in putback area plus
|
* - at most, pbSize characters in putback area plus
|
||||||
* - at most, bufSize characters in ordinary read buffer
|
* - at most, bufSize characters in ordinary read buffer
|
||||||
*/
|
*/
|
||||||
static const int pbSize = 4; // size of putback area
|
static const size_t pbSize = 4; // size of putback area
|
||||||
static const int bufSize = 1024; // size of the data buffer
|
static const size_t bufSize = 1024; // size of the data buffer
|
||||||
char buffer[bufSize + pbSize]; // data buffer
|
char buffer[bufSize + pbSize]; // data buffer
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -147,7 +147,7 @@ protected:
|
||||||
* - use number of characters read
|
* - use number of characters read
|
||||||
* - but at most size of putback area
|
* - but at most size of putback area
|
||||||
*/
|
*/
|
||||||
int numPutback;
|
size_t numPutback;
|
||||||
numPutback = gptr() - eback();
|
numPutback = gptr() - eback();
|
||||||
if (numPutback > pbSize) {
|
if (numPutback > pbSize) {
|
||||||
numPutback = pbSize;
|
numPutback = pbSize;
|
||||||
|
|
@ -160,14 +160,13 @@ protected:
|
||||||
numPutback);
|
numPutback);
|
||||||
|
|
||||||
// read at most bufSize new characters
|
// read at most bufSize new characters
|
||||||
int num;
|
|
||||||
PyObject *line = PyFile_GetLine(reinterpret_cast<PyObject *>(fo), bufSize);
|
PyObject *line = PyFile_GetLine(reinterpret_cast<PyObject *>(fo), bufSize);
|
||||||
if (! line || ! PyString_Check(line)) {
|
if (! line || ! PyString_Check(line)) {
|
||||||
// ERROR or EOF
|
// ERROR or EOF
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
num = PyString_Size(line);
|
Py_ssize_t num = PyString_Size(line);
|
||||||
if (num == 0)
|
if (num == 0)
|
||||||
return EOF;
|
return EOF;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -266,7 +266,7 @@ value_t python_interpreter_t::python_command(call_scope_t& args)
|
||||||
std::strcpy(argv[i + 1], arg.c_str());
|
std::strcpy(argv[i + 1], arg.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
int status = Py_Main(args.size() + 1, argv);
|
int status = Py_Main(static_cast<int>(args.size()) + 1, argv);
|
||||||
|
|
||||||
for (std::size_t i = 0; i < args.size() + 1; i++)
|
for (std::size_t i = 0; i < args.size() + 1; i++)
|
||||||
delete[] argv[i];
|
delete[] argv[i];
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,7 @@ public:
|
||||||
|
|
||||||
virtual expr_t::ptr_op_t lookup(const string& name);
|
virtual expr_t::ptr_op_t lookup(const string& name);
|
||||||
|
|
||||||
|
#if BOOST_VERSION >= 103700
|
||||||
OPTION_(python_interpreter_t, import_, DO_(scope) {
|
OPTION_(python_interpreter_t, import_, DO_(scope) {
|
||||||
interactive_t args(scope, "s");
|
interactive_t args(scope, "s");
|
||||||
|
|
||||||
|
|
@ -114,23 +115,31 @@ public:
|
||||||
python::object sys_dict = module_sys.attr("__dict__");
|
python::object sys_dict = module_sys.attr("__dict__");
|
||||||
|
|
||||||
python::list paths(sys_dict["path"]);
|
python::list paths(sys_dict["path"]);
|
||||||
#if BOOST_VERSION >= 103700
|
|
||||||
paths.insert(0, file.parent_path().string());
|
paths.insert(0, file.parent_path().string());
|
||||||
#else
|
|
||||||
paths.insert(0, file.branch_path().string());
|
|
||||||
#endif
|
|
||||||
sys_dict["path"] = paths;
|
sys_dict["path"] = paths;
|
||||||
|
|
||||||
#if BOOST_VERSION >= 103700
|
|
||||||
string name = file.filename();
|
string name = file.filename();
|
||||||
if (contains(name, ".py"))
|
if (contains(name, ".py"))
|
||||||
parent->import(file.stem());
|
parent->import(file.stem());
|
||||||
else
|
else
|
||||||
parent->import(name);
|
parent->import(name);
|
||||||
#else
|
|
||||||
parent->import(file.leaf());
|
|
||||||
#endif
|
|
||||||
});
|
});
|
||||||
|
#else // BOOST_VERSION >= 103700
|
||||||
|
OPTION_(python_interpreter_t, import_, DO_(scope) {
|
||||||
|
interactive_t args(scope, "s");
|
||||||
|
|
||||||
|
path file(args.get<string>(0));
|
||||||
|
|
||||||
|
python::object module_sys = parent->import("sys");
|
||||||
|
python::object sys_dict = module_sys.attr("__dict__");
|
||||||
|
|
||||||
|
python::list paths(sys_dict["path"]);
|
||||||
|
paths.insert(0, file.branch_path().string());
|
||||||
|
sys_dict["path"] = paths;
|
||||||
|
|
||||||
|
parent->import(file.leaf());
|
||||||
|
});
|
||||||
|
#endif // BOOST_VERSION >= 103700
|
||||||
};
|
};
|
||||||
|
|
||||||
extern shared_ptr<python_interpreter_t> python_session;
|
extern shared_ptr<python_interpreter_t> python_session;
|
||||||
|
|
|
||||||
|
|
@ -211,8 +211,8 @@ value_t report_t::fn_truncated(call_scope_t& scope)
|
||||||
interactive_t args(scope, "v&ll");
|
interactive_t args(scope, "v&ll");
|
||||||
return string_value(format_t::truncate
|
return string_value(format_t::truncate
|
||||||
(args.get<string>(0),
|
(args.get<string>(0),
|
||||||
args.has(1) && args.get<long>(1) > 0 ? args.get<long>(1) : 0,
|
args.has(1) && args.get<int>(1) > 0 ? args.get<int>(1) : 0,
|
||||||
args.has(2) ? args.get<long>(2) : -1));
|
args.has(2) ? args.get<int>(2) : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
value_t report_t::fn_justify(call_scope_t& scope)
|
value_t report_t::fn_justify(call_scope_t& scope)
|
||||||
|
|
@ -220,8 +220,8 @@ value_t report_t::fn_justify(call_scope_t& scope)
|
||||||
interactive_t args(scope, "vl&lbbs");
|
interactive_t args(scope, "vl&lbbs");
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
args.value_at(0)
|
args.value_at(0)
|
||||||
.print(out, args.get<long>(1),
|
.print(out, args.get<int>(1),
|
||||||
args.has(2) ? args.get<long>(2) : -1,
|
args.has(2) ? args.get<int>(2) : -1,
|
||||||
args.has(3) ? args.get<bool>(3) : false,
|
args.has(3) ? args.get<bool>(3) : false,
|
||||||
args.has(4) ? args.get<bool>(4) : false,
|
args.has(4) ? args.get<bool>(4) : false,
|
||||||
args.has(5) ? args.get<string>(5) :
|
args.has(5) ? args.get<string>(5) :
|
||||||
|
|
@ -275,19 +275,19 @@ value_t report_t::fn_ansify_if(call_scope_t& scope)
|
||||||
if (args.has(1)) {
|
if (args.has(1)) {
|
||||||
string color = args.get<string>(1);
|
string color = args.get<string>(1);
|
||||||
std::ostringstream buf;
|
std::ostringstream buf;
|
||||||
if (color == "black") buf << "\e[30m";
|
if (color == "black") buf << "\033[30m";
|
||||||
else if (color == "red") buf << "\e[31m";
|
else if (color == "red") buf << "\033[31m";
|
||||||
else if (color == "green") buf << "\e[32m";
|
else if (color == "green") buf << "\033[32m";
|
||||||
else if (color == "yellow") buf << "\e[33m";
|
else if (color == "yellow") buf << "\033[33m";
|
||||||
else if (color == "blue") buf << "\e[34m";
|
else if (color == "blue") buf << "\033[34m";
|
||||||
else if (color == "magenta") buf << "\e[35m";
|
else if (color == "magenta") buf << "\033[35m";
|
||||||
else if (color == "cyan") buf << "\e[36m";
|
else if (color == "cyan") buf << "\033[36m";
|
||||||
else if (color == "white") buf << "\e[37m";
|
else if (color == "white") buf << "\033[37m";
|
||||||
else if (color == "bold") buf << "\e[1m";
|
else if (color == "bold") buf << "\033[1m";
|
||||||
else if (color == "underline") buf << "\e[4m";
|
else if (color == "underline") buf << "\033[4m";
|
||||||
else if (color == "blink") buf << "\e[5m";
|
else if (color == "blink") buf << "\033[5m";
|
||||||
buf << args.value_at(0);
|
buf << args.value_at(0);
|
||||||
buf << "\e[0m";
|
buf << "\033[0m";
|
||||||
return string_value(buf.str());
|
return string_value(buf.str());
|
||||||
} else {
|
} else {
|
||||||
return args.value_at(0);
|
return args.value_at(0);
|
||||||
|
|
|
||||||
|
|
@ -83,8 +83,8 @@ namespace std {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef std::size_t istream_pos_type;
|
typedef std::streamoff istream_pos_type;
|
||||||
typedef std::size_t ostream_pos_type;
|
typedef std::streamoff ostream_pos_type;
|
||||||
|
|
||||||
#else // ! (defined(__GNUG__) && __GNUG__ < 3)
|
#else // ! (defined(__GNUG__) && __GNUG__ < 3)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,9 +103,9 @@ inline void justify(std::ostream& out,
|
||||||
bool redden = false)
|
bool redden = false)
|
||||||
{
|
{
|
||||||
if (! right) {
|
if (! right) {
|
||||||
if (redden) out << "\e[31m";
|
if (redden) out << "\033[31m";
|
||||||
out << str;
|
out << str;
|
||||||
if (redden) out << "\e[0m";
|
if (redden) out << "\033[0m";
|
||||||
}
|
}
|
||||||
|
|
||||||
unistring temp(str);
|
unistring temp(str);
|
||||||
|
|
@ -115,9 +115,9 @@ inline void justify(std::ostream& out,
|
||||||
out << ' ';
|
out << ' ';
|
||||||
|
|
||||||
if (right) {
|
if (right) {
|
||||||
if (redden) out << "\e[31m";
|
if (redden) out << "\033[31m";
|
||||||
out << str;
|
out << str;
|
||||||
if (redden) out << "\e[0m";
|
if (redden) out << "\033[0m";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
18
src/utils.cc
18
src/utils.cc
|
|
@ -402,17 +402,19 @@ string::string(const char * str) : std::string(str) {
|
||||||
string::string(const char * str, const char * end) : std::string(str, end) {
|
string::string(const char * str, const char * end) : std::string(str, end) {
|
||||||
TRACE_CTOR(string, "const char *, const char *");
|
TRACE_CTOR(string, "const char *, const char *");
|
||||||
}
|
}
|
||||||
string::string(const string& str, int x) : std::string(str, x) {
|
string::string(const string& str, size_type x) : std::string(str, x) {
|
||||||
TRACE_CTOR(string, "const string&, int");
|
TRACE_CTOR(string, "const string&, size_type");
|
||||||
}
|
}
|
||||||
string::string(const string& str, int x, int y) : std::string(str, x, y) {
|
string::string(const string& str, size_type x, size_type y)
|
||||||
TRACE_CTOR(string, "const string&, int, int");
|
: std::string(str, x, y) {
|
||||||
|
TRACE_CTOR(string, "const string&, size_type, size_type");
|
||||||
}
|
}
|
||||||
string::string(const char * str, int x) : std::string(str, x) {
|
string::string(const char * str, size_type x) : std::string(str, x) {
|
||||||
TRACE_CTOR(string, "const char *, int");
|
TRACE_CTOR(string, "const char *, size_type");
|
||||||
}
|
}
|
||||||
string::string(const char * str, int x, int y) : std::string(str, x, y) {
|
string::string(const char * str, size_type x, size_type y)
|
||||||
TRACE_CTOR(string, "const char *, int, int");
|
: std::string(str, x, y) {
|
||||||
|
TRACE_CTOR(string, "const char *, size_type, size_type");
|
||||||
}
|
}
|
||||||
string::~string() throw() {
|
string::~string() throw() {
|
||||||
TRACE_DTOR(string);
|
TRACE_DTOR(string);
|
||||||
|
|
|
||||||
|
|
@ -173,10 +173,10 @@ public:
|
||||||
string(size_type len, char x);
|
string(size_type len, char x);
|
||||||
string(const char * str);
|
string(const char * str);
|
||||||
string(const char * str, const char * end);
|
string(const char * str, const char * end);
|
||||||
string(const string& str, int x);
|
string(const string& str, size_type x);
|
||||||
string(const string& str, int x, int y);
|
string(const string& str, size_type x, size_type y);
|
||||||
string(const char * str, int x);
|
string(const char * str, size_type x);
|
||||||
string(const char * str, int x, int y);
|
string(const char * str, size_type x, size_type y);
|
||||||
~string() throw();
|
~string() throw();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
11
src/value.cc
11
src/value.cc
|
|
@ -173,6 +173,17 @@ date_t value_t::to_date() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int value_t::to_int() const
|
||||||
|
{
|
||||||
|
if (is_long()) {
|
||||||
|
return static_cast<int>(as_long());
|
||||||
|
} else {
|
||||||
|
value_t temp(*this);
|
||||||
|
temp.in_place_cast(INTEGER);
|
||||||
|
return static_cast<int>(temp.as_long());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
long value_t::to_long() const
|
long value_t::to_long() const
|
||||||
{
|
{
|
||||||
if (is_long()) {
|
if (is_long()) {
|
||||||
|
|
|
||||||
|
|
@ -733,6 +733,7 @@ public:
|
||||||
* exception is thrown.
|
* exception is thrown.
|
||||||
*/
|
*/
|
||||||
bool to_boolean() const;
|
bool to_boolean() const;
|
||||||
|
int to_int() const;
|
||||||
long to_long() const;
|
long to_long() const;
|
||||||
datetime_t to_datetime() const;
|
datetime_t to_datetime() const;
|
||||||
date_t to_date() const;
|
date_t to_date() const;
|
||||||
|
|
@ -788,7 +789,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Collection-style access methods for SEQUENCE values.
|
* Collection-style access methods for SEQUENCE values.
|
||||||
*/
|
*/
|
||||||
value_t& operator[](const int index) {
|
value_t& operator[](const std::size_t index) {
|
||||||
VERIFY(! is_null());
|
VERIFY(! is_null());
|
||||||
if (is_sequence())
|
if (is_sequence())
|
||||||
return as_sequence_lval()[index];
|
return as_sequence_lval()[index];
|
||||||
|
|
@ -799,7 +800,7 @@ public:
|
||||||
static value_t null;
|
static value_t null;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const value_t& operator[](const int index) const {
|
const value_t& operator[](const std::size_t index) const {
|
||||||
VERIFY(! is_null());
|
VERIFY(! is_null());
|
||||||
if (is_sequence())
|
if (is_sequence())
|
||||||
return as_sequence()[index];
|
return as_sequence()[index];
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue