tcsh-org / tcsh

This is a read-only mirror of the tcsh code repository.
https://www.tcsh.org/
Other
232 stars 42 forks source link

:g and :a changes #17

Closed alzwded closed 4 years ago

alzwded commented 4 years ago

This has irritated me for quite some time.

The man pages state:

           g       Apply the following modifier once to each word.
           a (+)   Apply the following modifier as many times as possible to a
                   single word.  `a' and `g' can be used together to  apply  a
                   modifier  globally.   With  the `s' modifier, only the pat‐
                   terns contained in the original word are  substituted,  not
                   patterns that contain any substitution result.

...yet that wasn't actually true in practice, which resulted in very amusing problems.

I've changed the scalar dolmcnt and dol_flag_a to be array to effectively track the state of those two meta-modifiers per modifier they affect. This is done by counting, but since this was consumed in only one place (setDolp) it's probably fine.

The following are now possible, and, to me, they seem valid cases per the man pages and according to common sense:

tcsh> set x=(aa bb aa bb)
tcsh> echo $x:gas/a/c/:gs/b/d/
cc db cc db

tcsh> foreach i ( "$x:gas/a/c/:q" )
foreach? echo $i
foreach? end
cc bb cc bb

tcsh> set x=(aa bb aa bb)
tcsh> echo $x:gas/a/q/:gs/b/w/:s/b/e/
qq we qq wb

I had to update sh.lex.c because it kinda contradicted sh.dol.c and the man page: it only accepted :gas once, subsequently complaining a is an invalid modifier.

zoulasc commented 4 years ago

Committed, many thanks!