mirror of
https://git.savannah.gnu.org/git/grub.git
synced 2026-10-21 14:59:34 +00:00
reuse code from legacy parser
This commit is contained in:
1 parent
7e623b0d74
commit
f866fe808b
5 files changed
+45
-35
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 *
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user