Fix failure to open paths ending in a slash.

Redmine #3905.
Remove unused global variables
Don't set $(match) during process selection and DeleteItem*

This causes EvalContext to disappear from significant amount of code.
Move SelectItemMatching to the place of use
Move MatchRegion to the place of use
Move a few $(match)-setting functions to cf-agent.
CFEngine functions ought not to reset $(match) context

Hence, they should not use FullTextMatch function
Move BlockTextMatch/FullTextMatch to cf-agent, as only useful there

Those functions set $(match) scope, which is only well-defined for
cf-agent (indeed, there is a check inside to only set it for
cf-agent). Hence any use of those functions outside of cf-agent
is a bug and has been eliminated.
Don't check for agent type, it's always cf-agent
Do not attempt to expand functions in the middle of an iteration
Add warning when using known problematic variables in package promise.

Discovered while writing acceptance tests for package promises, and
very hard to understand what's going on unless you get this warning.
Fix incorrect return value for empty string in safe_open.
Tiny optimization in safe_open.

We already know that next_component is neither null nor empty in the
second branch, because of 7f137f0ad5.
Merge pull request #1243 from kacfengine/safe_open_fixes

[Redmine #3905] Safe open fixes
Merge pull request #1246 from kacfengine/packages_variables_warning

Add warning when using known problematic variables in package promise.
Instead of using $(match) scope, return captures from matching function

This change makes a few CFEngine function implementations to use
matches returned directly from the StringMatchCaptures instead of
relying on side-effects of FullTextMatch.
Fix escape() testsuite

Previous tests were broken due to way regmatch() matched strings.
Remove unused VSHIFT variable
Remove obsolete comment
Fix default value for repchar attribute