Simplify if/#if-ery to avoid confusing emacs indentation.

(cherry picked from commit 2e3a00af1faeb78d05a331f5ae019eaadc701679)
redmine 5893: scalar variables in unexpanded array references

Fix parsing, add acceptance test.

(cherry picked from commit 8596c8af5ca5a94a685b7ceb5e396f5cf4362d6e)
Patch for parsing of arrays of lists

(cherry picked from commit 0f80c3cc99f3be36d90aa60ea17a9172ded44c54)

Conflicts:
	libpromises/cf3.defs.h
	libpromises/mod_common.c
Add: Acceptance test for rendering quotes in mustache

Ref: https://dev.cfengine.com/issues/6516
(cherry picked from commit 51ca2ac5964d8a2966f728c96e15d654ab13c514)
Fix for test of mustache's rendering of quotes.

The test expected variable expansion to be unescaped, but it's escaped
by default; it needs an & at the start of the variable name to
suppress escaping.  I've duly expanded the test to test both escaped
and unescaped variable expansion.

(cherry picked from commit b2e5b9b1abf6291cb5da5fef16c1047476b8f7d1)
Assorted clean-up in processes_select.c

Casting the paramater of isspace to int is dumb; even without the
overt cast, that would happen.  As it happens, isspace wants to be
given an int whose value is either that of an unsigned char or EOF
(which is -1).  So, when passing a char to it (which is what we're
doing) we *do* need to cast it - to unsigned char - after all.
Likewise for isalnum().

Various loops were needlessly complicated by mishandling the 0 case,
leading to kludges to not end up with the wrong answer.  Use the right
test, avoid the dumb kludges.

Prefer memcpy (with explicit termination) over strncpy and kill the
wanton memset(,0,)s implicit in an initializer that assured the
strncpy() would have a trailing '\0'.

Kill a spurious continue (in an if, whose else was the rest of the
loop anyway).

Removed misleading " INFO - " from the front of a LOG_LEVEL_VERBOSE.
Chop() was being called with the wrong size for its buffer.
A loop variable could be made more local and const.
Turn some untidy while loops into for loops.
Split some lines to make them more readable.
Made diverse other locals more local.
Fewer parentheses.

(cherry picked from commit 4d8404417605e41687d1d76a9a5f1700d2114750)
Rework SplitProcLine(): smarter growing of fields outside columns.

GetProcessColumnNames() records the start and end columns of the
headings for ps-output.  SplitProcLine() uses these in its second
heuristic for parsing the columns from data lines.  (The first
heuristic simply splits on spaces, aside from a minor kludge for
STIME.  If the two heuristics disagree, we Log() a warning.)  It used
to grow the field outwards, to a space on each side, but limiting
growth to the right to (arbitrarily) ten characters.  This might
extend beyond the next column to either side.  We see Solaris ps can
have fields that abut, which would lead several fields to use the same
text, this way.

Having now studied actual ps output (details documented in a comment
at the start of the heuristic), I've changed this so that:
 * for numeric fields, it grows left, potentially into the previous
   column but never to its start;
 * for text columns it grows right but never overlaps the next column
   header.
Other columns are limited to the width of their header.

It also now strips all leading and trailing space (it used to neglect
this for the last column, even after I fixed assorted off-by-one
errors), which eliminates the need for Chop().

I've also eliminated the assumption that CMD/COMMAND is the last
column - it's easier, safer and correct to test for last column, for
all that this always just happens, for good reason, to be CMD.

(cherry picked from commit cbf52201b0c202140380b08f78944066a2fadeb0)
Rewrite SplitProcLine() without temp buffers.

Rather than scanning the line twice, filling two arrays with fragments
obtained by two heuristics, so as to be able to compare them, do the
two scans in parallel.  This removes the needs for arrays to hold the
fragments, hence the need to clip a long field if we hit one (it'll be
COMMAND, if it happens), and saves a lot of copying.  We only need to
copy the contents (and clip them) when warning and as part of the
xstrndup(), replacing xstrdup() of a copy, needed to allocate the
fragment saved.

(cherry picked from commit 2dc3be355f846bbca47693da4eaf26b5322b74c9)
Include {admit,deny}_{ips,hostnames} in the relevant legacy lists.

Entries provided by admit are delivered both to the legacy ACL list
and to the new ACL system's relevant list for admit_ips or
admit_hostnames; likewise for deny.  However, entries given with these
new controls were only added to the new system's lists, not to the
legacy lists, so parts of the code that still use the legacy lists
were not honouring ACLs set using the new keywords.  Add also to the
legacy lists to fix this, until we're finally rid of the legacy code.

(cherry picked from commit 49258153202cfa131ef40d687ca08bc97f26f4aa)
Bug in makerule - and make it compatible with if/ifvarclass.

Function was declared incorrectly and would not match in
if/ifvarclass. Also it must return false in order to be compatible
with these cases, not merely fail as previously argued. This is the
only way to make class functions consistent

Downgrade the level of a Log() message.

(cherry picked from commit e3f11abf91a07a78439594ab32819c0d0514b3ee)
Refine old-ACL representation of new-ACL hostnames.

The old-style ACLs used regex matching on hostnames, alongside exact
matching; new-style uses only sub-domain and exact matching.  So map
sub-domain matches to regexes in the natural way.

(cherry picked from commit 52c72ceb900785353a1345be4d18ddf84571f634)
Fix fence-post error in my re-write of SplitProcLine().

I was leaving ep pointing at the last character of the space-delimited
field, not at the character after it.  How did that even work on the
systems where it did ?

(cherry picked from commit 74eb756c2e3363254ef7fb5b798157d9f8c258ad)
Cope with ps's numeric (e.g. time) fields overflowing to the right.

This can happen, despite such fields normally being right-aligned,
when the field is too wide or some earlier field has overflowed, thus
pushing the affected field to the right.  This can push an internal
punctuator of the shunted field into the right-alignment position, so
adjust the test for "looks like a numeric field that may overspill
left" test as well as ajusting the "grow right" stanza to also happen
for numeric fields that have been shunted.

Prompted by overnight tests failing on a build machine which sees:
USER       PID  PPID  PGID %CPU %MEM  NI    SZ    VSZ   RSS NLWP STIME     ELAPSED     TIME COMMAND
jenkins  31941 31939 31939  1.1  0.2   0  9938  39752  4552    1 May20 92-21:17:55 1-02:07:14 sshd: jenkins@notty
(eliding a bunch of other lines), in which the TIME field's part
directly under the header, ":07:", starts and ends in colons, so was
not recognised as "numeric" (ends in digit); and needs to grow to the
right as well as left, despite being numeric (so trying to be
right-aligned).

(cherry picked from commit 90096eba39e9cca47eb3f55ec42a32262a3ba77a)
Change: Add alternate unescape form to mustache render quotes test

The mustache spec allows variables to be inside of `{{{`.
This extends the test to cover that style in addition to including the
characters to not escape.

(cherry picked from commit efaeab2bdbc4b563fd4045c5ca277e392276379f)