Re: [Qemu-devel] Fix double backslash problem in Windows

2008-01-11 Thread Laurent Vivier
Le jeudi 10 janvier 2008 à 19:13 +0100, Laurent Vivier a écrit :
 Le jeudi 10 janvier 2008 à 16:02 +0100, Laurent Vivier a écrit :
  Le jeudi 10 janvier 2008 à 15:18 +0100, Jernej Simončič a écrit :
   On Thursday, January 10, 2008, 14:58:28, Laurent Vivier wrote:
   
Do you like '^' ?
   
   Bad idea - this is the escape character in Windows shell :)
  
  Perhaps this should work:
  
  - option name must end with '='
  - option value must end with ',' or '\0' (allows '=' in filename)
  - if option name must have ',', we double it (allows ',' in filename)
  - ' ', '\' and '' are not separators at this level and are managed at
  shell level
 
 Here is the patch.
 

After a night of thought, I think it is better to merge my patch with
one from Johannes.

Here it is.

Laurent
-- 
- [EMAIL PROTECTED]  --
  La perfection est atteinte non quand il ne reste rien à
ajouter mais quand il ne reste rien à enlever. Saint Exupéry
Signed-off-by: Johannes Schindelin [EMAIL PROTECTED]
Signed-off-by: Laurent Vivier [EMAIL PROTECTED]
---
 qemu-doc.texi |3 +
 vl.c  |  108 +-
 2 files changed, 64 insertions(+), 47 deletions(-)

Index: qemu/vl.c
===
--- qemu.orig/vl.c	2008-01-11 09:49:42.0 +0100
+++ qemu/vl.c	2008-01-11 09:51:14.0 +0100
@@ -231,7 +231,10 @@ unsigned int nb_prom_envs = 0;
 const char *prom_envs[MAX_PROM_ENVS];
 #endif
 int nb_drives_opt;
-char drives_opt[MAX_DRIVES][1024];
+struct drive_opt {
+const char *file;
+char opt[1024];
+} drives_opt[MAX_DRIVES];
 
 static CPUState *cur_cpu;
 static CPUState *next_cpu;
@@ -4581,24 +4584,33 @@ static int net_socket_mcast_init(VLANSta
 
 }
 
-static const char *get_word(char *buf, int buf_size, const char *p)
+static const char *get_opt_name(char *buf, int buf_size, const char *p)
+{
+char *q;
+
+q = buf;
+while (*p != '\0'  *p != '=') {
+if (q  (q - buf)  buf_size - 1)
+*q++ = *p;
+p++;
+}
+if (q)
+*q = '\0';
+
+return p;
+}
+
+static const char *get_opt_value(char *buf, int buf_size, const char *p)
 {
 char *q;
-int substring;
 
-substring = 0;
 q = buf;
 while (*p != '\0') {
-if (*p == '\\') {
-p++;
-if (*p == '\0')
+if (*p == ',') {
+if (*(p + 1) != ',')
 break;
-} else if (*p == '\') {
-substring = !substring;
 p++;
-continue;
-} else if (!substring  (*p == ',' || *p == '='))
-break;
+}
 if (q  (q - buf)  buf_size - 1)
 *q++ = *p;
 p++;
@@ -4617,15 +4629,15 @@ static int get_param_value(char *buf, in
 
 p = str;
 for(;;) {
-p = get_word(option, sizeof(option), p);
+p = get_opt_name(option, sizeof(option), p);
 if (*p != '=')
 break;
 p++;
 if (!strcmp(tag, option)) {
-(void)get_word(buf, buf_size, p);
+(void)get_opt_value(buf, buf_size, p);
 return strlen(buf);
 } else {
-p = get_word(NULL, 0, p);
+p = get_opt_value(NULL, 0, p);
 }
 if (*p != ',')
 break;
@@ -4642,7 +4654,7 @@ static int check_params(char *buf, int b
 
 p = str;
 for(;;) {
-p = get_word(buf, buf_size, p);
+p = get_opt_name(buf, buf_size, p);
 if (*p != '=')
 return -1;
 p++;
@@ -4651,7 +4663,7 @@ static int check_params(char *buf, int b
 break;
 if (params[i] == NULL)
 return -1;
-p = get_word(NULL, 0, p);
+p = get_opt_value(NULL, 0, p);
 if (*p != ',')
 break;
 p++;
@@ -4810,18 +4822,18 @@ void do_info_network(void)
 }
 }
 
-#define HD_ALIAS file=\%s\,index=%d,media=disk
+#define HD_ALIAS index=%d,media=disk
 #ifdef TARGET_PPC
 #define CDROM_ALIAS index=1,media=cdrom
 #else
 #define CDROM_ALIAS index=2,media=cdrom
 #endif
 #define FD_ALIAS index=%d,if=floppy
-#define PFLASH_ALIAS file=\%s\,if=pflash
-#define MTD_ALIAS file=\%s\,if=mtd
+#define PFLASH_ALIAS if=pflash
+#define MTD_ALIAS if=mtd
 #define SD_ALIAS index=0,if=sd
 
-static int drive_add(const char *fmt, ...)
+static int drive_add(const char *file, const char *fmt, ...)
 {
 va_list ap;
 
@@ -4830,8 +4842,10 @@ static int drive_add(const char *fmt, ..
 exit(1);
 }
 
+drives_opt[nb_drives_opt].file = file;
 va_start(ap, fmt);
-vsnprintf(drives_opt[nb_drives_opt], sizeof(drives_opt[0]), fmt, ap);
+vsnprintf(drives_opt[nb_drives_opt].opt,
+  sizeof(drives_opt[0].opt), fmt, ap);
 va_end(ap);
 
 return nb_drives_opt++;
@@ -4866,7 +4880,8 @@ int drive_get_max_bus(BlockInterfaceType
 return max_bus;
 }
 
-static int drive_init(const char *str, int snapshot, QEMUMachine 

Re: [Qemu-devel] Fix double backslash problem in Windows

2008-01-10 Thread Jernej Simončič
On Thursday, January 10, 2008, 14:58:28, Laurent Vivier wrote:

 Do you like '^' ?

Bad idea - this is the escape character in Windows shell :)

-- 
 Jernej Simončič  http://deepthought.ena.si/ 

The chief cause of problems is solutions.
   -- Sevareid's Law





Re: [Qemu-devel] Fix double backslash problem in Windows

2008-01-10 Thread Laurent Vivier
Le jeudi 10 janvier 2008 à 15:18 +0100, Jernej Simončič a écrit :
 On Thursday, January 10, 2008, 14:58:28, Laurent Vivier wrote:
 
  Do you like '^' ?
 
 Bad idea - this is the escape character in Windows shell :)

Perhaps this should work:

- option name must end with '='
- option value must end with ',' or '\0' (allows '=' in filename)
- if option name must have ',', we double it (allows ',' in filename)
- ' ', '\' and '' are not separators at this level and are managed at
shell level


Examples:

qemu -drive file=my=file,if=scsi - filename is my=file
qemu -drive file=my,,if=ide,if=scsi - filname is my,if=ide

Laurent
-- 
- [EMAIL PROTECTED]  --
  La perfection est atteinte non quand il ne reste rien à
ajouter mais quand il ne reste rien à enlever. Saint Exupéry


signature.asc
Description: Ceci est une partie de message	numériquement signée


Re: [Qemu-devel] Fix double backslash problem in Windows

2008-01-10 Thread Laurent Vivier
Le jeudi 10 janvier 2008 à 16:02 +0100, Laurent Vivier a écrit :
 Le jeudi 10 janvier 2008 à 15:18 +0100, Jernej Simončič a écrit :
  On Thursday, January 10, 2008, 14:58:28, Laurent Vivier wrote:
  
   Do you like '^' ?
  
  Bad idea - this is the escape character in Windows shell :)
 
 Perhaps this should work:
 
 - option name must end with '='
 - option value must end with ',' or '\0' (allows '=' in filename)
 - if option name must have ',', we double it (allows ',' in filename)
 - ' ', '\' and '' are not separators at this level and are managed at
 shell level

Here is the patch.

All comments are welcome.
Laurent
-- 
- [EMAIL PROTECTED]  --
  La perfection est atteinte non quand il ne reste rien à
ajouter mais quand il ne reste rien à enlever. Saint Exupéry
---
 qemu-doc.texi |3 ++-
 vl.c  |   53 +++--
 2 files changed, 33 insertions(+), 23 deletions(-)

Index: qemu/vl.c
===
--- qemu.orig/vl.c	2008-01-10 17:48:08.0 +0100
+++ qemu/vl.c	2008-01-10 19:06:40.0 +0100
@@ -4581,24 +4581,33 @@ static int net_socket_mcast_init(VLANSta
 
 }
 
-static const char *get_word(char *buf, int buf_size, const char *p)
+static const char *get_opt_name(char *buf, int buf_size, const char *p)
+{
+char *q;
+
+q = buf;
+while (*p != '\0'  *p != '=') {
+if (q  (q - buf)  buf_size - 1)
+*q++ = *p;
+p++;
+}
+if (q)
+*q = '\0';
+
+return p;
+}
+
+static const char *get_opt_value(char *buf, int buf_size, const char *p)
 {
 char *q;
-int substring;
 
-substring = 0;
 q = buf;
 while (*p != '\0') {
-if (*p == '\\') {
-p++;
-if (*p == '\0')
+if (*p == ',') {
+if (*(p + 1) != ',')
 break;
-} else if (*p == '\') {
-substring = !substring;
 p++;
-continue;
-} else if (!substring  (*p == ',' || *p == '='))
-break;
+}
 if (q  (q - buf)  buf_size - 1)
 *q++ = *p;
 p++;
@@ -4617,15 +4626,15 @@ static int get_param_value(char *buf, in
 
 p = str;
 for(;;) {
-p = get_word(option, sizeof(option), p);
+p = get_opt_name(option, sizeof(option), p);
 if (*p != '=')
 break;
 p++;
 if (!strcmp(tag, option)) {
-(void)get_word(buf, buf_size, p);
+(void)get_opt_value(buf, buf_size, p);
 return strlen(buf);
 } else {
-p = get_word(NULL, 0, p);
+p = get_opt_value(NULL, 0, p);
 }
 if (*p != ',')
 break;
@@ -4642,7 +4651,7 @@ static int check_params(char *buf, int b
 
 p = str;
 for(;;) {
-p = get_word(buf, buf_size, p);
+p = get_opt_name(buf, buf_size, p);
 if (*p != '=')
 return -1;
 p++;
@@ -4651,7 +4660,7 @@ static int check_params(char *buf, int b
 break;
 if (params[i] == NULL)
 return -1;
-p = get_word(NULL, 0, p);
+p = get_opt_value(NULL, 0, p);
 if (*p != ',')
 break;
 p++;
@@ -4810,15 +4819,15 @@ void do_info_network(void)
 }
 }
 
-#define HD_ALIAS file=\%s\,index=%d,media=disk
+#define HD_ALIAS file=%s,index=%d,media=disk
 #ifdef TARGET_PPC
 #define CDROM_ALIAS index=1,media=cdrom
 #else
 #define CDROM_ALIAS index=2,media=cdrom
 #endif
 #define FD_ALIAS index=%d,if=floppy
-#define PFLASH_ALIAS file=\%s\,if=pflash
-#define MTD_ALIAS file=\%s\,if=mtd
+#define PFLASH_ALIAS file=%s,if=pflash
+#define MTD_ALIAS file=%s,if=mtd
 #define SD_ALIAS index=0,if=sd
 
 static int drive_add(const char *fmt, ...)
@@ -8246,7 +8255,7 @@ int main(int argc, char **argv)
 	drive_add(MTD_ALIAS, optarg);
 break;
 case QEMU_OPTION_sd:
-drive_add(file=\%s\, SD_ALIAS, optarg);
+drive_add(file=%s, SD_ALIAS, optarg);
 break;
 case QEMU_OPTION_pflash:
 	drive_add(PFLASH_ALIAS, optarg);
@@ -8317,7 +8326,7 @@ int main(int argc, char **argv)
 kernel_cmdline = optarg;
 break;
 case QEMU_OPTION_cdrom:
-		drive_add(file=\%s\, CDROM_ALIAS, optarg);
+		drive_add(file=%s, CDROM_ALIAS, optarg);
 break;
 case QEMU_OPTION_boot:
 boot_devices = optarg;
@@ -8352,7 +8361,7 @@ int main(int argc, char **argv)
 break;
 case QEMU_OPTION_fda:
 case QEMU_OPTION_fdb:
-		drive_add(file=\%s\, FD_ALIAS, optarg,
+		drive_add(file=%s, FD_ALIAS, optarg,
 		  popt-index - QEMU_OPTION_fda);
 break;
 #ifdef TARGET_I386
Index: qemu/qemu-doc.texi
===
--- qemu.orig/qemu-doc.texi	2008-01-10