diff --git a/src/dorem.c b/src/dorem.c index 3762bdde..5a7f424b 100644 --- a/src/dorem.c +++ b/src/dorem.c @@ -58,7 +58,10 @@ int DoRem(ParsePtr p) /* Parse the trigger date and time */ if ( (r=ParseRem(p, &trig, &tim, 1)) ) return r; - if (trig.typ == NO_TYPE) return E_EOLN; + if (trig.typ == NO_TYPE) { + PurgeEchoLine("%s\n%s\n", "#!PURGE Cannot parse next line", CurLine); + return E_EOLN; + } if (trig.typ == SAT_TYPE) { PurgeEchoLine("%s\n", "#!PURGE Cannot purge SATISFY-type reminders"); PurgeEchoLine("%s\n", CurLine); @@ -94,14 +97,20 @@ int DoRem(ParsePtr p) } else { /* Calculate the trigger date */ jul = ComputeTrigger(trig.scanfrom, &trig, &r, 1); - if (r) return r; + if (r) { + if (PurgeMode) { + PurgeEchoLine("%s: %s\n", "#!PURGE Problem calculating trigger date", ErrMsg[r]); + PurgeEchoLine("%s\n", CurLine); + } + return r; + } } if (PurgeMode) { - if (trig.expired) { + if (trig.expired || jul < JulianToday) { if (p->expr_happened) { PurgeEchoLine("%s\n", "#!PURGE Next line may have expired, but contains expression"); - PurgeEchoLine("%s\n", CurLine); + PurgeEchoLine("%s\n", CurLine); } else { PurgeEchoLine("#!PURGE EXPIRED: %s\n", CurLine); } diff --git a/src/files.c b/src/files.c index 8ba0ca16..bce25686 100644 --- a/src/files.c +++ b/src/files.c @@ -102,6 +102,11 @@ static void OpenPurgeFile(char const *fname, char const *mode) { DynamicBuffer fname_buf; + if (PurgeFP != NULL && PurgeFP != stdout) { + fclose(PurgeFP); + } + PurgeFP = NULL; + /* Do not open a purge file if we're below purge include depth */ if (IStackPtr-2 >= PurgeIncludeDepth) { @@ -195,12 +200,6 @@ static int ReadLineFromFile(void) } if (feof(fp)) { FCLOSE(fp); - if (PurgeMode) { - if (PurgeFP != NULL && PurgeFP != stdout) { - fclose(PurgeFP); - } - PurgeFP = NULL; - } } l = DBufLen(&buf); if (l && (DBufValue(&buf)[l-1] == '\\')) { @@ -244,6 +243,13 @@ int OpenFile(char const *fname) CachedFile *h = CachedFiles; int r; + if (PurgeMode) { + if (PurgeFP != NULL && PurgeFP != stdout) { + fclose(PurgeFP); + } + PurgeFP = NULL; + } + /* Assume we own the file for now */ RunDisabled &= ~RUN_NOTOWNER; @@ -332,12 +338,6 @@ static int CacheFile(char const *fname) if (!cf) { ShouldCache = 0; FCLOSE(fp); - if (PurgeMode) { - if (PurgeFP != NULL && PurgeFP != stdout) { - fclose(PurgeFP); - } - PurgeFP = NULL; - } return E_NO_MEM; } cf->filename = StrDup(fname); @@ -345,12 +345,6 @@ static int CacheFile(char const *fname) ShouldCache = 0; FCLOSE(fp); free(cf); - if (PurgeMode) { - if (PurgeFP != NULL && PurgeFP != stdout) { - fclose(PurgeFP); - } - PurgeFP = NULL; - } return E_NO_MEM; } @@ -367,12 +361,6 @@ static int CacheFile(char const *fname) DestroyCache(cf); ShouldCache = 0; FCLOSE(fp); - if (PurgeMode) { - if (PurgeFP != NULL && PurgeFP != stdout) { - fclose(PurgeFP); - } - PurgeFP = NULL; - } return r; } /* Skip blank chars */ @@ -387,12 +375,6 @@ static int CacheFile(char const *fname) DestroyCache(cf); ShouldCache = 0; FCLOSE(fp); - if (PurgeMode) { - if (PurgeFP != NULL && PurgeFP != stdout) { - fclose(PurgeFP); - } - PurgeFP = NULL; - } return E_NO_MEM; } cl = cf->cache; @@ -402,12 +384,6 @@ static int CacheFile(char const *fname) DBufFree(&LineBuffer); DestroyCache(cf); ShouldCache = 0; - if (PurgeMode) { - if (PurgeFP != NULL && PurgeFP != stdout) { - fclose(PurgeFP); - } - PurgeFP = NULL; - } FCLOSE(fp); return E_NO_MEM; } @@ -420,12 +396,6 @@ static int CacheFile(char const *fname) if (!cl->text) { DestroyCache(cf); ShouldCache = 0; - if (PurgeMode) { - if (PurgeFP != NULL && PurgeFP != stdout) { - fclose(PurgeFP); - } - PurgeFP = NULL; - } FCLOSE(fp); return E_NO_MEM; } @@ -700,12 +670,6 @@ int IncludeFile(char const *fname) if (fp) { i->offset = ftell(fp); FCLOSE(fp); - if (PurgeMode) { - if (PurgeFP != NULL && PurgeFP != stdout) { - fclose(PurgeFP); - } - PurgeFP = NULL; - } } IStackPtr++; diff --git a/src/main.c b/src/main.c index 7399389c..05a6e07d 100644 --- a/src/main.c +++ b/src/main.c @@ -794,8 +794,10 @@ int DoIfTrig(ParsePtr p) syndrome = IF_TRUE | BEFORE_ELSE; } else { syndrome = IF_FALSE | BEFORE_ELSE; - PurgeEchoLine("%s\n", "#!PURGE The next IFTRIG did not trigger."); - PurgeEchoLine("%s\n", "#!PURGE REM statements in IFTRIG block not checked for purging."); + if (PurgeMode) { + PurgeEchoLine("%s\n", "#!PURGE The next IFTRIG did not trigger."); + PurgeEchoLine("%s\n", "#!PURGE REM statements in IFTRIG block not checked for purging."); + } } } } diff --git a/src/trigger.c b/src/trigger.c index d344bea9..ebe1f2fe 100644 --- a/src/trigger.c +++ b/src/trigger.c @@ -301,7 +301,10 @@ static int GetNextTriggerDate(Trigger *trig, int start, int *err, int *nextstart /* First: Have we passed the UNTIL date? */ if (trig->until != NO_UNTIL && - trig->until < start) return -1; /* expired */ + trig->until < start) { + trig->expired = 1; + return -1; /* expired */ + } /* Next: If it's an "AFTER"-type skip, back up until we're at the start of a block of holidays */ diff --git a/tests/purge_dir/f1.rem b/tests/purge_dir/f1.rem new file mode 100644 index 00000000..469e0648 --- /dev/null +++ b/tests/purge_dir/f1.rem @@ -0,0 +1,7 @@ +# This is f1.rem +INCLUDE f2.rem +INCLUDE f2.rem + +REM 1 Oct 1991 MSG old1. + +REM Monday UNTIL 1 Oct 1991 MSG old2. \ No newline at end of file diff --git a/tests/purge_dir/f2.rem b/tests/purge_dir/f2.rem new file mode 100644 index 00000000..a9480836 --- /dev/null +++ b/tests/purge_dir/f2.rem @@ -0,0 +1,6 @@ +# This is f2.rem + +REM 3 feb 2012 MSG new +REM 3 1998 MSG old + +INCLUDE f3.rem diff --git a/tests/purge_dir/f3.rem b/tests/purge_dir/f3.rem new file mode 100644 index 00000000..72b61a87 --- /dev/null +++ b/tests/purge_dir/f3.rem @@ -0,0 +1,18 @@ +# This is f3.rem + +REM Mon MSG repeat + +REM Mon SATISFY [1] MSG repeat + +IF 0 +REM 1991 MSG wookie +ENDIF + +IF 1 +REM 1991 MSG wookie +ENDIF + +IFTRIG 1991 +REM MSG wookie +ENDIF +