On Wed, 14 Apr 2021 at 18:56, Johnson, Andrew N. <
anj at anl.gov> wrote:
On Apr 14, 2021, at 11:13 AM, Ralph Lange via Core-talk <core-talk at aps.anl.gov> wrote:
>
> AppData is one of quite a few standard Windows variables. Obviously, introducing my own variables would work and make the whole thing non-portable.
>
> The getenv() call works just fine, mixed paths work fine, I can read directly from the environment and have utilities that convert forward to backslashes etc etc.
> The one and only real show stopper is that the iocShell's macro expansion changes the value of those standard environment variables when you use them.
Even epicsEnvSet preserves back-slashes in the values it sets. The macLib routines are supposed to preserve strings inside single quotes, but then they don’t expand the macros inside. I just experimented with various ways of quoting stuff, but that doesn’t seem to help at all:
[...]
> epics> epicsEnvSet eeed '\\\"'
> epics> epicsEnvShow eeed
> eeed=\\\"
> epics> echo "$(eeed)$(APPDATA)$(eeed)"
> Unbalanced quote.
That last error (from iocsh, not macLib) is interesting, but probably not useful.
:-)
Do we need some syntax in macros to prevent them from escaping back-slashes when expanding values? I’m not sure how easy it would be to implement that, but it might be possible. Any other suggestions on what might be changed?
Looking at the macLib code, I was getting the _expression_ that the original intention might have been to do it right.
/* discard quotes and escapes if level is > 0 (i.e. if these aren't
the user's quotes and escapes) */
Or not? (Shouldn't quotes and escapes only be discarded when they are the user's, and kept through replacements?)
Well, at least there was an intention.
What if using a variable wouldn't change its content? After the second line, I would expect PP and QQ to be the same.
We could maybe add another bracket character pair for verbatim usage.
epics> echo $[eeed]
I am afraid that changing the current behaviour - even if it was "correcting" it - would add a pretty high risk of breaking things for users.
Cheers,
~Ralph