All of lore.kernel.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Junio C Hamano <junkio@cox.net>, Andreas Ericsson <ae@op5.se>,
	git@vger.kernel.org
Subject: Re: User-relative paths
Date: Sun, 23 Oct 2005 18:44:13 -0700	[thread overview]
Message-ID: <435C3C6D.7000201@zytor.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0510231836020.10477@g5.osdl.org>

Linus Torvalds wrote:
> 
> On Sun, 23 Oct 2005, H. Peter Anvin wrote:
> 
>>If this is meant to dequote shell-quoted paths, it really should be modal.
> 
> It _only_ accepts quoted strings, so it "is" modal. It has one mode: 
> string. And it's a bitch about enforcing it, too (it just dies if it 
> wasn't one).
> 

That wasn't what I meant.  '...' is a modal escape in the shell.  Thus, 
something like this which actually mimics the state machine, at least 
for the potential characters we care about.


#define EMIT(x) { ( ++len < n ) && *dst++ = (x) )

int unquote(char *dst, size_t n, const char *src)
{
	enum state st = { st_zero, st_quote, st_escape };
	int len = 0;
	char c;
	
	while ( (c = *src++) ) {
		switch ( st ) {
		case st_zero:
			if ( c == '\'' )
				st = st_quote;
			else if ( c == '\\' )
				st = st_escape;
			else
				EMIT(c);
			break;
			
		case st_quote:
			if ( c == '\'' )
				st = st_zero;
			else
				EMIT(c);
			break;
			
		case st_escape:
			EMIT(c);
			st = st_zero;
			break;
		}
	}
	
	if ( n )
		*dst = 0;
	
	return (st == st_zero) ? len : -1;
}

  reply	other threads:[~2005-10-24  1:44 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-22 22:22 Server side programs Andreas Ericsson
2005-10-23  0:30 ` Junio C Hamano
2005-10-23  9:41   ` User-relative paths (was: Server side programs) Andreas Ericsson
2005-10-23 18:37     ` Petr Baudis
2005-10-23 19:50       ` User-relative paths Junio C Hamano
2005-10-23 22:25         ` Petr Baudis
2005-10-23 22:30           ` Junio C Hamano
2005-10-24  6:28         ` Daniel Barkalow
2005-10-25  7:47       ` Andreas Ericsson
2005-10-23 19:56     ` Junio C Hamano
2005-10-23 21:30       ` Linus Torvalds
2005-10-23 22:57         ` Junio C Hamano
2005-10-23 23:02         ` Junio C Hamano
2005-10-24  1:08           ` H. Peter Anvin
2005-10-24  1:37             ` Linus Torvalds
2005-10-24  1:44               ` H. Peter Anvin [this message]
2005-10-24  1:56             ` Junio C Hamano
2005-10-24  0:21         ` [PATCH] Add git-shell Junio C Hamano
2005-10-24  0:52           ` Linus Torvalds
2005-10-24  0:55             ` Linus Torvalds
2005-10-24  1:36             ` Junio C Hamano
2005-10-24  2:08       ` User-relative paths Junio C Hamano
2005-10-25  9:11       ` [PATCH] git_progname (was: Re: User-relative paths) Andreas Ericsson
2005-10-25  9:31         ` Petr Baudis
2005-10-25 11:12           ` [PATCH] git_progname Andreas Ericsson
2005-10-25 12:53             ` Andreas Ericsson
2005-10-25 13:32               ` Petr Baudis
2005-10-26  6:07                 ` Junio C Hamano
2005-10-27  8:34           ` [PATCH] git_progname (was: Re: User-relative paths) Matthias Urlichs
2005-10-23  0:42 ` Server side programs Linus Torvalds

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=435C3C6D.7000201@zytor.com \
    --to=hpa@zytor.com \
    --cc=ae@op5.se \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    --cc=torvalds@osdl.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.