mirror of
https://salsa.debian.org/dskoll/remind.git
synced 2026-04-16 06:18:47 +02:00
Better diagnostics of unmatched IFs
This commit is contained in:
12
src/files.c
12
src/files.c
@@ -79,6 +79,7 @@ typedef struct {
|
|||||||
int LineNo;
|
int LineNo;
|
||||||
unsigned int IfFlags;
|
unsigned int IfFlags;
|
||||||
int NumIfs;
|
int NumIfs;
|
||||||
|
int IfLinenos[IF_NEST];
|
||||||
long offset;
|
long offset;
|
||||||
CachedLine *CLine;
|
CachedLine *CLine;
|
||||||
int ownedByMe;
|
int ownedByMe;
|
||||||
@@ -526,8 +527,14 @@ static int NextChainedFile(IncludeStruct *i)
|
|||||||
static int PopFile(void)
|
static int PopFile(void)
|
||||||
{
|
{
|
||||||
IncludeStruct *i;
|
IncludeStruct *i;
|
||||||
|
int j;
|
||||||
|
|
||||||
if (!Hush && NumIfs) Eprint("%s", ErrMsg[E_MISS_ENDIF]);
|
if (!Hush && NumIfs) {
|
||||||
|
Eprint("%s", ErrMsg[E_MISS_ENDIF]);
|
||||||
|
for (j=NumIfs-1; j >=0; j--) {
|
||||||
|
fprintf(ErrFp, "%s(%d): IF without ENDIF\n", FileName, IfLinenos[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!IStackPtr) return E_EOF;
|
if (!IStackPtr) return E_EOF;
|
||||||
i = &IStack[IStackPtr-1];
|
i = &IStack[IStackPtr-1];
|
||||||
|
|
||||||
@@ -547,6 +554,7 @@ static int PopFile(void)
|
|||||||
|
|
||||||
LineNo = i->LineNo;
|
LineNo = i->LineNo;
|
||||||
IfFlags = i->IfFlags;
|
IfFlags = i->IfFlags;
|
||||||
|
memcpy(IfLinenos, i->IfLinenos, IF_NEST);
|
||||||
NumIfs = i->NumIfs;
|
NumIfs = i->NumIfs;
|
||||||
CLine = i->CLine;
|
CLine = i->CLine;
|
||||||
fp = NULL;
|
fp = NULL;
|
||||||
@@ -871,6 +879,7 @@ static int IncludeCmd(char const *cmd)
|
|||||||
i->LineNo = LineNo;
|
i->LineNo = LineNo;
|
||||||
i->NumIfs = NumIfs;
|
i->NumIfs = NumIfs;
|
||||||
i->IfFlags = IfFlags;
|
i->IfFlags = IfFlags;
|
||||||
|
memcpy(i->IfLinenos, IfLinenos, IF_NEST);
|
||||||
i->CLine = CLine;
|
i->CLine = CLine;
|
||||||
i->offset = -1L;
|
i->offset = -1L;
|
||||||
i->chain = NULL;
|
i->chain = NULL;
|
||||||
@@ -973,6 +982,7 @@ int IncludeFile(char const *fname)
|
|||||||
i->LineNo = LineNo;
|
i->LineNo = LineNo;
|
||||||
i->NumIfs = NumIfs;
|
i->NumIfs = NumIfs;
|
||||||
i->IfFlags = IfFlags;
|
i->IfFlags = IfFlags;
|
||||||
|
memcpy(i->IfLinenos, IfLinenos, IF_NEST);
|
||||||
i->CLine = CLine;
|
i->CLine = CLine;
|
||||||
i->offset = -1L;
|
i->offset = -1L;
|
||||||
i->chain = NULL;
|
i->chain = NULL;
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ EXTERN INIT( int PurgeIncludeDepth, 0);
|
|||||||
EXTERN INIT( FILE *PurgeFP, NULL);
|
EXTERN INIT( FILE *PurgeFP, NULL);
|
||||||
EXTERN INIT( int NumIfs, 0);
|
EXTERN INIT( int NumIfs, 0);
|
||||||
EXTERN INIT( unsigned int IfFlags, 0);
|
EXTERN INIT( unsigned int IfFlags, 0);
|
||||||
|
EXTERN INIT( int IfLinenos[IF_NEST], {0});
|
||||||
EXTERN INIT( int LastTrigValid, 0);
|
EXTERN INIT( int LastTrigValid, 0);
|
||||||
EXTERN Trigger LastTrigger;
|
EXTERN Trigger LastTrigger;
|
||||||
EXTERN TimeTrig LastTimeTrig;
|
EXTERN TimeTrig LastTimeTrig;
|
||||||
|
|||||||
@@ -955,6 +955,7 @@ int DoIf(ParsePtr p)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IfLinenos[NumIfs] = LineNo;
|
||||||
NumIfs++;
|
NumIfs++;
|
||||||
IfFlags &= ~(IF_MASK << (2*NumIfs - 2));
|
IfFlags &= ~(IF_MASK << (2*NumIfs - 2));
|
||||||
IfFlags |= syndrome << (2 * NumIfs - 2);
|
IfFlags |= syndrome << (2 * NumIfs - 2);
|
||||||
|
|||||||
4
tests/if1.rem
Normal file
4
tests/if1.rem
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
BANNER %
|
||||||
|
set $AddBlankLines 0
|
||||||
|
IF 1
|
||||||
|
INCLUDE [filedir()]/if2.rem
|
||||||
5
tests/if2.rem
Normal file
5
tests/if2.rem
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Another unmatched IF
|
||||||
|
IF 0
|
||||||
|
ELSE
|
||||||
|
IF 1
|
||||||
|
|
||||||
@@ -566,6 +566,9 @@ POP
|
|||||||
PUSH
|
PUSH
|
||||||
POP
|
POP
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
../src/remind ../tests/if1.rem 2020-03-03 >> ../tests/test.out 2>&1
|
||||||
|
|
||||||
# Remove references to SysInclude, which is build-specific
|
# Remove references to SysInclude, which is build-specific
|
||||||
grep -F -v '$SysInclude' < ../tests/test.out > ../tests/test.out.1 && mv -f ../tests/test.out.1 ../tests/test.out
|
grep -F -v '$SysInclude' < ../tests/test.out > ../tests/test.out.1 && mv -f ../tests/test.out.1 ../tests/test.out
|
||||||
cmp -s ../tests/test.out ../tests/test.cmp
|
cmp -s ../tests/test.out ../tests/test.cmp
|
||||||
|
|||||||
@@ -12349,3 +12349,9 @@ Expression nodes high-water: 499
|
|||||||
-stdin-(14): Unmatched PUSH-OMIT-CONTEXT at -(7)
|
-stdin-(14): Unmatched PUSH-OMIT-CONTEXT at -(7)
|
||||||
-stdin-(14): Warning: PUSH-OMIT-CONTEXT without matching POP-OMIT-CONTEXT
|
-stdin-(14): Warning: PUSH-OMIT-CONTEXT without matching POP-OMIT-CONTEXT
|
||||||
No reminders.
|
No reminders.
|
||||||
|
../tests/if2.rem(6): Warning: Missing ENDIF
|
||||||
|
../tests/if2.rem(4): IF without ENDIF
|
||||||
|
../tests/if2.rem(2): IF without ENDIF
|
||||||
|
../tests/if1.rem(5): Warning: Missing ENDIF
|
||||||
|
../tests/if1.rem(3): IF without ENDIF
|
||||||
|
No reminders.
|
||||||
|
|||||||
Reference in New Issue
Block a user