Re: [PATCH 1/1] Teach for-each-ref about a little language called Tcl.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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: signature.asc
Description: Digital signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]