* The sh substitution problem.
@ 2002-06-10 12:05 Peter Stephenson
2002-06-10 16:07 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: Peter Stephenson @ 2002-06-10 12:05 UTC (permalink / raw)
To: Zsh hackers list
namely ${1+"$@"} when using `sh' word-spliting makes a scalar out of "$@"
and splits it later on, with consequent undesirable effects.
I thought I had a way of doing the important cases (i.e. the ones
required for POSIX) simply but it turns out it doesn't work. We just
have a completely different notion of how a command line word is formed
(because ours is more logical :-)). So I've given that up.
I have a vague plan for doing it `properly' but it doesn't fill me with
delight:
- When calling prefork() from multsub(), don't remove nulls (hence
preserving information about quotes, which are retained as Snull,
Dnull and Bnull).
- In multsub(), handle arrays properly, i.e. stick the results in what
is currently its second argument. This will have knock-on effects
since paramsubst() messes around with val and aval all the time. The
way mult_isarr has been hacked in to avoid the calling sequence may
make this more difficult. (Ideally we would replace mult_isarr by
making multsub() always return arrays. This is probably even harder,
but I don't understand the details of mult_isarr, which handles
nested substitutions, well enough to say.)
[It might be possible to keep val and aval as a pair in a structure,
a sort of pseudo-parameter, and only convert between scalar and array
when really necessary with a `forcescalar' or `forcearray'
function/macro.]
- Avoid joining words before splitting them (unless it is a forced
join with a given string). This changes the current rules but is
inevitable for getting this to work at all. This probably also means
handling certain types of scalar result by joining arrays at this point
instead of before (even if they are not going to be split). This is
also probably tricky because there are umpteen different ways of
ending up with a scalar. This is probably where we would have to do
any joining due to letting multsub() always return an array. I used
the word `probably' three times in that paragraph.
- When splitting, handle a loop over multiple array elements and
keep track of quotes. This also fixes:
% ARGV0=sh zsh
$ set word
$ print -l ${1+'this should not be split'}
this
should
not
be
split
This is tricky and I have no idea of its detailed feasibility. If
anyone wants to try they should. Otherwise just make comments.
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070
**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential
and/or privileged material.
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is
prohibited.
If you received this in error, please contact the sender and
delete the material from any computer.
**********************************************************************
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: The sh substitution problem.
2002-06-10 12:05 The sh substitution problem Peter Stephenson
@ 2002-06-10 16:07 ` Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2002-06-10 16:07 UTC (permalink / raw)
To: Peter Stephenson, Zsh hackers list
On Jun 10, 1:05pm, Peter Stephenson wrote:
} Subject: The sh substitution problem.
}
} This is tricky and I have no idea of its detailed feasibility. If
} anyone wants to try they should. Otherwise just make comments.
I think the discussion Oliver and I had earlier this year, e.g.
http://www.zsh.org/mla/workers/2002/msg00512.html
regarding passing around Parameter structs instead of Value structs, is
the key to this problem as well. If the right-hand-side of the :+ (etc.)
were encoded as a parameter, it can carry around all the state necessary
to properly substitute it when the time comes. Passing it around as just
a string or array is not sufficient, no matter what you do WRT preserving
nulls etc.
You sort of hint at this when you say:
} [It might be possible to keep val and aval as a pair in a structure,
} a sort of pseudo-parameter, and only convert between scalar and array
} when really necessary with a `forcescalar' or `forcearray'
} function/macro.]
Of course this is a more significant rewrite than just "fixing" multsub(),
but last year I had several goes at multsub() without coming up with
anything usable.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-06-10 16:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-10 12:05 The sh substitution problem Peter Stephenson
2002-06-10 16:07 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).