All of lore.kernel.org
 help / color / mirror / Atom feed
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 1/1] Teach for-each-ref about a little language called Tcl.
Date: Sun, 28 Jan 2007 12:49:09 +0300	[thread overview]
Message-ID: <20070128094909.GA3740@procyon.home> (raw)
In-Reply-To: <20070128073913.GA9915@spearce.org>

[-- Attachment #1: Type: text/plain, Size: 1775 bytes --]

On Sun, Jan 28, 2007 at 02:39:13AM -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.
> 
> Thanks to Sergey Vlasov for pointing out the horrible flaws in the
> first version of this patch, and steering me in the right direction
> for Tcl value quoting.
[...]
> +void tcl_quote_print(FILE *stream, const char *src)
> +{
> +	char c;
> +
> +	fputc('"', stream);
> +	while ((c = *src++)) {
> +		switch (c) {
> +		case '[':
> +		case ']':
> +		case '$':
> +		case '\\':
> +		case '"':
> +			fputc('\\', stream);
> +		default:
> +			fputc(c, stream);
> +			break;
> +		case '\f':
> +			fputs("\\f", stream);
> +			break;
> +		case '\r':
> +			fputs("\\r", stream);
> +			break;
> +		case '\n':
> +			fputs("\\n", stream);
> +			break;
> +		case '\t':
> +			fputs("\\t", stream);
> +			break;
> +		case '\v':
> +			fputs("\\v", stream);
> +			break;
> +		}
> +	}
> +	fputc('"', stream);
> +}

This is better; however, wrapping this format inside { ... } (which
you may want to do in the template for some uses) won't work if the
string contains unmatched braces.  Quoting '{' and '}' characters with
backslashes should fix this.

BTW, escaping newline characters as done here is not strictly required
for a double-quoted string, but is very useful, because you may read
the output line by line with "gets" and get fields from each line with
"lindex"; without this escaping you will need to read the whole output
before trying to parse it as a single huge list.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2007-01-28  9:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-28  7:39 [PATCH 1/1] Teach for-each-ref about a little language called Tcl Shawn O. Pearce
2007-01-28  9:49 ` Sergey Vlasov [this message]
2007-01-28 20:58   ` Junio C Hamano
2007-01-29  9:51     ` Sergey Vlasov

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=20070128094909.GA3740@procyon.home \
    --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.