ia64/xen-unstable

changeset 18384:f17ab0889f3b

stubdom: support quotes in argument passing

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Aug 27 09:47:49 2008 +0100 (2008-08-27)
parents 846590f85062
children 38557884d2cd
files extras/mini-os/main.c
line diff
     1.1 --- a/extras/mini-os/main.c	Wed Aug 27 09:47:24 2008 +0100
     1.2 +++ b/extras/mini-os/main.c	Wed Aug 27 09:47:49 2008 +0100
     1.3 @@ -42,7 +42,7 @@ void _fini(void)
     1.4  extern char __app_bss_start, __app_bss_end;
     1.5  static void call_main(void *p)
     1.6  {
     1.7 -    char *c;
     1.8 +    char *c, quote;
     1.9  #ifdef CONFIG_QEMU
    1.10      char *domargs, *msg;
    1.11  #endif
    1.12 @@ -101,32 +101,53 @@ static void call_main(void *p)
    1.13  
    1.14      argc = 1;
    1.15  
    1.16 -#define PARSE_ARGS(ARGS,START,END) \
    1.17 +#define PARSE_ARGS(ARGS,START,QUOTE,END) \
    1.18      c = ARGS; \
    1.19 +    quote = 0; \
    1.20      while (*c) { \
    1.21  	if (*c != ' ') { \
    1.22  	    START; \
    1.23 -	    while (*c && *c != ' ') \
    1.24 +	    while (*c) { \
    1.25 +		if (quote) { \
    1.26 +		    if (*c == quote) { \
    1.27 +			quote = 0; \
    1.28 +			QUOTE; \
    1.29 +			continue; \
    1.30 +		    } \
    1.31 +		} else if (*c == ' ') \
    1.32 +		    break; \
    1.33 +		if (*c == '"' || *c == '\'') { \
    1.34 +		    quote = *c; \
    1.35 +		    QUOTE; \
    1.36 +		    continue; \
    1.37 +		} \
    1.38  		c++; \
    1.39 +	    } \
    1.40  	} else { \
    1.41              END; \
    1.42  	    while (*c == ' ') \
    1.43  		c++; \
    1.44  	} \
    1.45 +    } \
    1.46 +    if (quote) {\
    1.47 +	printk("Warning: unterminated quotation %c\n", quote); \
    1.48 +	quote = 0; \
    1.49      }
    1.50 +#define PARSE_ARGS_COUNT(ARGS) PARSE_ARGS(ARGS, argc++, c++, )
    1.51 +#define PARSE_ARGS_STORE(ARGS) PARSE_ARGS(ARGS, argv[argc++] = c, memmove(c, c + 1, strlen(c + 1) + 1), *c++ = 0)
    1.52  
    1.53 -    PARSE_ARGS((char*)start_info.cmd_line, argc++, );
    1.54 +    PARSE_ARGS_COUNT((char*)start_info.cmd_line);
    1.55  #ifdef CONFIG_QEMU
    1.56 -    PARSE_ARGS(domargs, argc++, );
    1.57 +    PARSE_ARGS_COUNT(domargs);
    1.58  #endif
    1.59  
    1.60      argv = alloca((argc + 1) * sizeof(char *));
    1.61      argv[0] = "main";
    1.62      argc = 1;
    1.63  
    1.64 -    PARSE_ARGS((char*)start_info.cmd_line, argv[argc++] = c, *c++ = 0)
    1.65 +    PARSE_ARGS_STORE((char*)start_info.cmd_line)
    1.66  #ifdef CONFIG_QEMU
    1.67 -    PARSE_ARGS(domargs, argv[argc++] = c, *c++ = 0)
    1.68 +    PARSE_ARGS_STORE(domargs)
    1.69  #endif
    1.70  
    1.71      argv[argc] = NULL;