reuse code from legacy parser

This commit is contained in:
BVK Chaitanya 2010-11-19 19:08:44 +05:30
parent 7e623b0d74
commit f866fe808b
5 changed files with 45 additions and 35 deletions

View file

@ -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>

View 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;
}

View 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 *

View file

@ -22,6 +22,27 @@
#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

View 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)
{