naemon/macros.c: solved undefined behaviour on incomplete macro

if a macro is defined as `$ something' the previous version of
process_macros_r() returned `$ something$', and that behaviour
is not what we supposedly want.

with the patch below we verify if we reached the end of string
before add a new $ sign, making process_macros_r() leave
string untouched in case of an incomplete macro has been
provided.

also added a test case to assure we are treating this correctly.

Signed-off-by: Ricardo Maraschini <ricardo.maraschini@gmail.com>