diff --git a/manpage b/manpage index 66fb5ef..6ca73cf 100644 --- a/manpage +++ b/manpage @@ -973,6 +973,10 @@ does not. When no .I CONTEXT is active, returns the same value as .B recno(). +.IP "ctxoffset()" 3 +Returns the current effective context offset. When no +.I CONTEXT +is active, returns 0. .IP "record()" 3 Returns the entire input record. Equivalent to .B range(1,-1) diff --git a/specs/docs/alu_adv.md b/specs/docs/alu_adv.md index c7b03aa..764953f 100644 --- a/specs/docs/alu_adv.md +++ b/specs/docs/alu_adv.md @@ -165,6 +165,7 @@ All three regular expression functions have an argument called `matchFlags`. Thi | `range(n,m)` | Returns the substring from the *n*-th character (default first) to the *m*-th character (default last) | | `recno()` | Returns the number of the currently read record. If the `READ` or `READSTOP` keywords are used this may be greater than `number()` | | `ctxrecno()` | Returns the record number of the record that input parts work on. This is similar to `recno()`, but considers rolling context, which `recno()` does not. | +| `ctxoffset()` | Returns the current effective context offset. Returns 0 when no `CONTEXT` is in effect. | | `record()` | Returns the entire input record. Equivalent to `@!`. | | `cfrecord()` | Returns the entire input record, disregarding rolling context. Same as `record()` when `CONTEXT` is not in effect. Equivalent to `@@`. | | `word(n)` | Returns the *n*-th word | diff --git a/specs/src/test/ProcessingTest.cc b/specs/src/test/ProcessingTest.cc index 0d0bef0..9134d47 100644 --- a/specs/src/test/ProcessingTest.cc +++ b/specs/src/test/ProcessingTest.cc @@ -1124,6 +1124,10 @@ int main(int argc, char** argv) " Using cfrecord(): But I can't help falling in love with you"; VERIFY2(spec, strm.c_str(), res.c_str()); // TEST #260 + // ctxoffset() function test + spec = "PRINT 'ctxoffset()' 1 CONTEXT +1 PRINT 'ctxoffset()' NW CONTEXT -1 PRINT 'ctxoffset()' NW"; + VERIFY2(spec, "x", "0 1 -1"); // TEST #261 + if (errorCount) { std::cout << '\n' << errorCount << '/' << testCount << " tests failed.\n"; std::cout << "Failed tests: "; diff --git a/specs/src/utils/aluFunctions.cc b/specs/src/utils/aluFunctions.cc index e689be3..4a68192 100644 --- a/specs/src/utils/aluFunctions.cc +++ b/specs/src/utils/aluFunctions.cc @@ -419,6 +419,11 @@ PValue AluFunc_ctxrecno() return mkValue(g_pStateQueryAgent->getRecordCount() + g_pStateQueryAgent->getContextOffset()); } +PValue AluFunc_ctxoffset() +{ + return mkValue(g_pStateQueryAgent->getContextOffset()); +} + PValue AluFunc_eof() { bool isRunOut = g_pStateQueryAgent->isEOF(); diff --git a/specs/src/utils/aluFunctions.h b/specs/src/utils/aluFunctions.h index d21bdb9..619e7af 100644 --- a/specs/src/utils/aluFunctions.h +++ b/specs/src/utils/aluFunctions.h @@ -42,6 +42,8 @@ "() - Returns the record number of the current record.","Increments with every READ or READSTOP.") \ X(ctxrecno, 0, ALUFUNC_REGULAR, true, \ "() - Returns the record number of the record that input parts work on.","This is similar to recno, but considers rolling context, which recno does not.") \ + X(ctxoffset, 0, ALUFUNC_REGULAR, true, \ + "() - Returns the current effective context offset.","Returns 0 when no CONTEXT is in effect.") \ X(number, 0, ALUFUNC_REGULAR, true, \ "() - Returns the number of times this specification has restarted","Does not increment with READ or READSTOP. Otherwise similar to recno().") \ X(eof, 0, ALUFUNC_REGULAR, false, \ diff --git a/specs/tests/valgrind_unit_tests.py b/specs/tests/valgrind_unit_tests.py index acd636c..e87fc50 100644 --- a/specs/tests/valgrind_unit_tests.py +++ b/specs/tests/valgrind_unit_tests.py @@ -1,7 +1,7 @@ import sys, memcheck, argparse count_ALU_tests = 832 -count_processing_tests = 260 +count_processing_tests = 261 count_token_tests = 17 # Parse the one command line options