]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
reuse code from legacy parser
authorBVK Chaitanya <bvk.groups@gmail.com>
Fri, 19 Nov 2010 13:38:44 +0000 (19:08 +0530)
committerBVK Chaitanya <bvk.groups@gmail.com>
Fri, 19 Nov 2010 13:38:44 +0000 (19:08 +0530)
ChangeLog
grub-core/commands/menuentry.c
grub-core/lib/legacy_parse.c
grub-core/script/script.c
include/grub/script_sh.h

index b53b396b5988cdabbd8a4fb2b90cd8d4e3929d12..eb8064188d1aeae10ae482657d361d24f6f5080d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,13 @@
 
        * grub-core/commands/menuentry.c (setparams_prefix): Use single
        quotes for arguments.
+       * grub-core/lib/legacy_parse.c (grub_legacy_escape): Use
+       grub_script_escape_squotes function instead.
+
+       * include/grub/script_sh.h (grub_script_escape_squotes): New
+       prototype.
+       * grub-core/script/script.c (grub_script_escape_squotes): New
+       function.
 
 2010-11-18  Vladimir Serbinenko  <phcoder@gmail.com>
 
index 7a07698d87d15e645c18539d91aac042dc43eae0..f64378724510bd6c75f55079b2e6ec65ca4d7827 100644 (file)
@@ -24,6 +24,7 @@
 #include <grub/extcmd.h>
 #include <grub/i18n.h>
 #include <grub/normal.h>
+#include <grub/script_sh.h>
 
 static const struct grub_arg_option options[] =
   {
@@ -221,26 +222,17 @@ setparams_prefix (int argc, char **args)
     return 0;
 
   grub_strcpy (result, "setparams");
-  i = 9;
+  p = result + 9;
 
   for (j = 0; j < argc; j++)
     {
-      result[i++] = ' ';
-      result[i++] = '\'';
-      p = args[j];
-      while (*p) {
-       result[i++] = *p;
-       if (*p == '\'') {
-         result[i++] = '\\';
-         result[i++] = '\'';
-         result[i++] = '\'';
-       }
-       p++;
-      }
-      result[i++] = '\'';
+      *p++ = ' ';
+      *p++ = '\'';
+      p = grub_script_escape_squotes (p, args[j], grub_strlen (args[j]));
+      *p++ = '\'';
     }
-  result[i++] = '\n';
-  result[i] = '\0';
+  *p++ = '\n';
+  *p = '\0';
   return result;
 }
 
index 5a359ff1c7e560c6a12b5d022fc1c0f827e4500a..8fe60b03d5f3e03940b691301e7e62a0bb517fd4 100644 (file)
@@ -20,6 +20,7 @@
 #include <grub/misc.h>
 #include <grub/mm.h>
 #include <grub/err.h>
+#include <grub/script_sh.h>
 #include <grub/legacy_parse.h>
 #include <grub/i386/pc/vesa_modes_table.h>
 
@@ -323,30 +324,16 @@ char *
 grub_legacy_escape (const char *in, grub_size_t len)
 {
   const char *ptr;
-  char *ret, *outptr;
+  char *outptr;
   int overhead = 0;
   for (ptr = in; ptr < in + len && *ptr; ptr++)
     if (*ptr == '\'')
       overhead += 3;
-  ret = grub_malloc (ptr - in + overhead + 1);
-  if (!ret)
+  outptr = grub_malloc (ptr - in + overhead + 1);
+  if (!outptr)
     return NULL;
-  outptr = ret;
-  for (ptr = in; ptr < in + len && *ptr; ptr++)
-    {
-      if (*ptr == '\'')
-       {
-         *outptr++ = '\'';
-         *outptr++ = '\\';
-         *outptr++ = '\'';
-         *outptr++ = '\'';
-         continue;
-       }
-      
-      *outptr++ = *ptr;
-    }
-  *outptr++ = 0;
-  return ret;
+  grub_script_escape_squotes (outptr, in, len);
+  return outptr;
 }
 
 static char *
index ad30183577e50203551560748758a1aa16f9bd91..45c3222b2581b1e66dafa6af04bc31dfee66c4e1 100644 (file)
 #include <grub/parser.h>
 #include <grub/mm.h>
 
+/* Escape single quotes in first `len' characters of `in' into a GRUB
+   script argument form into `out'; return address of the end in
+   `out'. */
+char *
+grub_script_escape_squotes (char *out, const char *in, grub_size_t len)
+{
+  while (*in && len--)
+    {
+      *out++ = *in;
+      if (*in == '\'')
+       {
+         *out++ = '\\';
+         *out++ = '\'';
+         *out++ = '\'';
+       }
+      in++;
+    }
+  *out = '\0';
+  return out;
+}
+
 /* It is not possible to deallocate the memory when a syntax error was
    found.  Because of that it is required to keep track of all memory
    allocations.  The memory is freed in case of an error, or assigned
index 6d31fca5ae89e24a729b18fe1578b5d3b26de2aa..f5dcd881e6a43aaf59f5e80beb580adc32dc361f 100644 (file)
@@ -382,6 +382,9 @@ grub_script_execute_arglist_to_argv (struct grub_script_arglist *arglist, int *c
 grub_err_t
 grub_normal_parse_line (char *line, grub_reader_getline_t getline);
 
+char *
+grub_script_escape_squotes (char *out, const char *in, grub_size_t len);
+
 static inline struct grub_script *
 grub_script_ref (struct grub_script *script)
 {