From: Sergey Vlasov <vsu@altlinux.ru>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: Junio C Hamano <junkio@cox.net>, git@vger.kernel.org
Subject: Re: [PATCH] Teach for-each-ref about a little language called Tcl.
Date: Sat, 27 Jan 2007 14:30:56 +0300 [thread overview]
Message-ID: <20070127143056.d19e80da.vsu@altlinux.ru> (raw)
In-Reply-To: <20070127072258.GA10512@spearce.org>
[-- Attachment #1: Type: text/plain, Size: 2872 bytes --]
On Sat, 27 Jan 2007 02:22:58 -0500 Shawn O. Pearce wrote:
> Love it or hate it, some people actually still program in Tcl. Some
> of those programs are meant for interfacing with Git. Programs such as
> gitk and git-gui. It may be useful to have Tcl-safe output available
> from for-each-ref, just like shell, Perl and Python already enjoy.
[...]
> +void tcl_quote_print(FILE *stream, const char *src)
> +{
> + const char lb = '{';
> + const char rb = '}';
> + const char bq = '\\';
> + char c;
> +
> + fputc(lb, stream);
> + while ((c = *src++)) {
> + if (c == lb || c == rb || c == bq)
> + fputc(bq, stream);
> + fputc(c, stream);
> + }
> + fputc(rb, stream);
> +}
No, this is broken - backslashes cannot be used to quote special
characters in braces.
If the first character of a word is an open brace (``{'') then
the word is terminated by the matching close brace (``}'').
Braces nest within the word: for each additional open brace
there must be an additional close brace (however, if an open
brace or close brace within the word is quoted with a backslash
then it is not counted in locating the matching close brace).
No substitutions are performed on the characters between the
braces except for backslash-newline substitutions described
below, nor do semi-colons, newlines, close brackets, or white
space receive any special interpretation. The word will consist
of exactly the characters between the outer braces, not includ-
ing the braces themselves.
The problem is that using '\{' will protect from nonmatching braces,
but the backslash will stay in the resulting string - it will not be
removed. Similarly for '\}' and '\\'.
Tcl itself checks whether using braces is safe (it could be safe if
the text does not have nonmatching braces and does not have an odd
number of backslash characters at end of line), and uses just
backslashes if braces cannot be used. See tclUtil.c,
Tcl_ScanCountedElement() and Tcl_ConvertCountedElement().
This code adds a backslash before ']', '[', '$', ';', ' ', '\\', '"',
'{', '}', and also converts special characters '\f', '\n', '\r', '\t',
'\v' to C-style escape sequences.
Untested code (output will not look very nice, but it is not intended
for human consumption anyway):
void tcl_quote_print(FILE *stream, const char *src)
{
char c;
while ((c = *src++)) {
switch (c) {
case ']':
case '[':
case '$':
case ';':
case ' ':
case '\\':
case '"':
case '{':
case '}':
fputc('\\', stream);
default:
fputc(c, stream);
break;
case '\f':
fputs("\\f", stream);
break;
case '\n':
fputs("\\n", stream);
break;
case '\r':
fputs("\\r", stream);
break;
case '\t':
fputs("\\t", stream);
break;
case '\v':
fputs("\\v", stream);
break;
}
}
}
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
prev parent reply other threads:[~2007-01-27 11:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-27 7:22 [PATCH] Teach for-each-ref about a little language called Tcl Shawn O. Pearce
2007-01-27 11:30 ` Sergey Vlasov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20070127143056.d19e80da.vsu@altlinux.ru \
--to=vsu@altlinux.ru \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.