From: Gurusamy Sarathy Date: Sun, 27 Jul 1997 13:00:48 +0000 (+1200) Subject: Re: q and escaping paired delimiters X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6d07e5e939afa671a7159961283be7a3f91c8c79;p=p5sagit%2Fp5-mst-13.2.git Re: q and escaping paired delimiters On Sun, 27 Jul 1997 19:57:31 EDT, Kenneth Albanowski wrote: >In fact, the code in toke.c looks a little suspicious, as if a cut'n'paste >error happened, and the balanced branch didn't get the cleanup it >deserved. There's a "if term != '\\'" statement that does nothing, for >example. Keen. That same deadcode was in one of my post 4_01 patches too (it does no damage, but like you say it serves no purpose either). >Here'a patch over 5.004_01 (although I'd expect it to work with most >versions) to allow you to escape both the starting and end quotes for q >(unbalanced and qq is unchanged), and the obligatory addition to the >tests. If nobody has any complaints, I expect this will be in _02. The toke.c hunk is "dangerous", in the sense that GNU patch will apply it to the wrong branch, if it needs to offset the patch due to later patches having been applied. This is thanks to the two branches having the exact same 8 lines of code. I of course recommend the change you suggest, and to prove my faith, I attach my own version, which: * eliminates the same deadcode in one of my later patches * uses the more meaningful names in the balanced branch * doesn't provoke the GNU patch problem with inadequate context Credited: Kenneth Albanowski p5p-msgid: 199707280516.BAA14055@aatma.engin.umich.edu --- diff --git a/toke.c b/toke.c index ff3be0d..9221bf1 100644 --- a/toke.c +++ b/toke.c @@ -2033,16 +2033,16 @@ yylex() close = term; if (open == close) for (t++; t < bufend; t++) { - if (*t == '\\' && t+1 < bufend && term != '\\') + if (*t == '\\' && t+1 < bufend && open != '\\') t++; - else if (*t == term) + else if (*t == open) break; } else for (t++; t < bufend; t++) { - if (*t == '\\' && t+1 < bufend && term != '\\') + if (*t == '\\' && t+1 < bufend) t++; - else if (*t == term && --brackets <= 0) + else if (*t == close && --brackets <= 0) break; else if (*t == open) brackets++; @@ -4968,13 +4968,13 @@ char *start; for (; s < bufend; s++,to++) { if (*s == '\n' && !rsfp) curcop->cop_line++; - if (*s == '\\' && s+1 < bufend && term != '\\') { - if (s[1] == term) + if (*s == '\\' && s+1 < bufend) { + if ((s[1] == multi_open) || (s[1] == multi_close)) s++; else *to++ = *s++; } - else if (*s == term && --brackets <= 0) + else if (*s == multi_close && --brackets <= 0) break; else if (*s == multi_open) brackets++;