summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/global.cc2
-rw-r--r--src/main.cc2
-rw-r--r--src/quotes.cc2
-rw-r--r--src/report.h2
-rw-r--r--src/stream.cc4
-rw-r--r--src/strptime.cc33
-rw-r--r--src/system.hh.in2
-rw-r--r--src/textual.cc26
-rw-r--r--src/times.cc2
9 files changed, 48 insertions, 27 deletions
diff --git a/src/global.cc b/src/global.cc
index a3f84409..882840de 100644
--- a/src/global.cc
+++ b/src/global.cc
@@ -451,7 +451,7 @@ expr_t::func_t global_scope_t::look_for_command(scope_t& scope,
void global_scope_t::visit_man_page() const
{
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__CYGWIN__)
int pid = fork();
if (pid < 0) {
throw std::logic_error(_("Failed to fork child process"));
diff --git a/src/main.cc b/src/main.cc
index df1933f9..07192651 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -74,7 +74,7 @@ int main(int argc, char * argv[], char * envp[])
#endif
std::signal(SIGINT, sigint_handler);
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__CYGWIN__)
std::signal(SIGPIPE, sigpipe_handler);
#endif
diff --git a/src/quotes.cc b/src/quotes.cc
index 0dd9c4ed..cef9b713 100644
--- a/src/quotes.cc
+++ b/src/quotes.cc
@@ -62,7 +62,7 @@ commodity_quote_from_script(commodity_t& commodity,
DEBUG("commodity.download", "invoking command: " << getquote_cmd);
bool success = true;
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__CYGWIN__)
if (FILE * fp = popen(getquote_cmd.c_str(), "r")) {
if (std::feof(fp) || ! std::fgets(buf, 255, fp))
success = false;
diff --git a/src/report.h b/src/report.h
index cdff13ae..e943de1d 100644
--- a/src/report.h
+++ b/src/report.h
@@ -794,7 +794,7 @@ public:
OPTION(report_t, output_); // -o
// setenv() is not available on WIN32
-#if defined(HAVE_ISATTY) and !defined(_WIN32)
+#if defined(HAVE_ISATTY) and !defined(_WIN32) and !defined(__CYGWIN__)
OPTION__
(report_t, pager_,
CTOR(report_t, pager_) {
diff --git a/src/stream.cc b/src/stream.cc
index 0c3ed995..e07fd61d 100644
--- a/src/stream.cc
+++ b/src/stream.cc
@@ -58,7 +58,7 @@ namespace {
*/
int do_fork(std::ostream ** os, const path& pager_path)
{
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__CYGWIN__)
int pfd[2];
int status = pipe(pfd);
@@ -115,7 +115,7 @@ void output_stream_t::initialize(const optional<path>& output_file,
void output_stream_t::close()
{
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__CYGWIN__)
if (os != &std::cout) {
checked_delete(os);
os = &std::cout;
diff --git a/src/strptime.cc b/src/strptime.cc
index b9d485d2..6f670baf 100644
--- a/src/strptime.cc
+++ b/src/strptime.cc
@@ -12,8 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
// Implement strptime under windows
#include "strptime.h"
@@ -22,6 +21,20 @@
#include <ctype.h>
#include <string.h>
+// Define strnicmp for Cygwin.
+#ifndef strcmpi
+#define strcmpi strcasecmp
+#endif
+#ifndef stricmp
+#define stricmp strcasecmp
+#endif
+#ifndef strncmpi
+#define strncmpi strncasecmp
+#endif
+#ifndef strnicmp
+#define strnicmp strncasecmp
+#endif
+
static const char* kWeekFull[] = {
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
@@ -70,14 +83,14 @@ static char* _strptime(const char *s, const char *format, struct tm *tm) {
case 'A':
tm->tm_wday = -1;
for (int i = 0; i < 7; ++i) {
- len = static_cast<int>(strlen(kWeekAbbr[i]));
- if (strnicmp(kWeekAbbr[i], s, len) == 0) {
+ len = static_cast<int>(strlen(kWeekFull[i]));
+ if (strnicmp(kWeekFull[i], s, len) == 0) {
tm->tm_wday = i;
break;
}
- len = static_cast<int>(strlen(kWeekFull[i]));
- if (strnicmp(kWeekFull[i], s, len) == 0) {
+ len = static_cast<int>(strlen(kWeekAbbr[i]));
+ if (strnicmp(kWeekAbbr[i], s, len) == 0) {
tm->tm_wday = i;
break;
}
@@ -92,14 +105,14 @@ static char* _strptime(const char *s, const char *format, struct tm *tm) {
case 'h':
tm->tm_mon = -1;
for (int i = 0; i < 12; ++i) {
- len = static_cast<int>(strlen(kMonthAbbr[i]));
- if (strnicmp(kMonthAbbr[i], s, len) == 0) {
+ len = static_cast<int>(strlen(kMonthFull[i]));
+ if (strnicmp(kMonthFull[i], s, len) == 0) {
tm->tm_mon = i;
break;
}
- len = static_cast<int>(strlen(kMonthFull[i]));
- if (strnicmp(kMonthFull[i], s, len) == 0) {
+ len = static_cast<int>(strlen(kMonthAbbr[i]));
+ if (strnicmp(kMonthAbbr[i], s, len) == 0) {
tm->tm_mon = i;
break;
}
diff --git a/src/system.hh.in b/src/system.hh.in
index 105436f6..331f7a0e 100644
--- a/src/system.hh.in
+++ b/src/system.hh.in
@@ -144,7 +144,7 @@ typedef std::ostream::pos_type ostream_pos_type;
#endif
#include <sys/stat.h>
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
#include <io.h>
#else
#include <unistd.h>
diff --git a/src/textual.cc b/src/textual.cc
index 4549581b..456ff8af 100644
--- a/src/textual.cc
+++ b/src/textual.cc
@@ -721,15 +721,12 @@ void instance_t::include_directive(char * line)
if (line[0] != '/' && line[0] != '\\' && line[0] != '~') {
DEBUG("textual.include", "received a relative path");
DEBUG("textual.include", "parent file path: " << context.pathname);
- string pathstr(context.pathname.string());
- string::size_type pos = pathstr.rfind('/');
- if (pos == string::npos)
- pos = pathstr.rfind('\\');
- if (pos != string::npos) {
- filename = path(string(pathstr, 0, pos + 1)) / line;
- DEBUG("textual.include", "normalized path: " << filename.string());
- } else {
+ path parent_path = context.pathname.parent_path();
+ if (parent_path.empty()) {
filename = path(string(".")) / line;
+ } else {
+ filename = parent_path / line;
+ DEBUG("textual.include", "normalized path: " << filename.string());
}
} else {
filename = line;
@@ -1658,7 +1655,8 @@ post_t * instance_t::parse_post(char * line,
switch (account_total.type()) {
case value_t::AMOUNT:
- diff -= account_total.as_amount();
+ if (account_total.as_amount().commodity_ptr() == diff.commodity_ptr())
+ diff -= account_total.as_amount();
break;
case value_t::BALANCE:
@@ -1676,6 +1674,16 @@ post_t * instance_t::parse_post(char * line,
DEBUG("textual.parse", "line " << context.linenum << ": "
<< "POST assign: diff = " << diff);
+ // Subtract amounts from previous posts to this account in the xact.
+ for (post_t* p : xact->posts) {
+ if (p->account == post->account &&
+ p->amount.commodity_ptr() == diff.commodity_ptr()) {
+ diff -= p->amount;
+ DEBUG("textual.parse", "line " << context.linenum << ": "
+ << "Subtract " << p->amount << ", diff = " << diff);
+ }
+ }
+
if (post->amount.is_null()) {
// balance assignment
if (! diff.is_zero()) {
diff --git a/src/times.cc b/src/times.cc
index 01b89848..8b0490ff 100644
--- a/src/times.cc
+++ b/src/times.cc
@@ -33,7 +33,7 @@
#include "times.h"
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__CYGWIN__)
#include "strptime.h"
#endif