2006-09-22 Marco Gerards <marco@gnu.org>
* normal/main.c (get_line): Malloc memory instead of using preallocated memory. Removed the arguments `cmdline' and `max_len'. Updated all callers.
This commit is contained in:
parent
6ba4688b23
commit
2cff3677bb
2 changed files with 67 additions and 22 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2006-09-22 Marco Gerards <marco@gnu.org>
|
||||||
|
|
||||||
|
* normal/main.c (get_line): Malloc memory instead of using
|
||||||
|
preallocated memory. Removed the arguments `cmdline' and
|
||||||
|
`max_len'. Updated all callers.
|
||||||
|
|
||||||
2006-09-22 Marco Gerards <marco@gnu.org>
|
2006-09-22 Marco Gerards <marco@gnu.org>
|
||||||
|
|
||||||
* conf/i386-efi.rmk (grub_emu_DEPENDENCIES): New variable.
|
* conf/i386-efi.rmk (grub_emu_DEPENDENCIES): New variable.
|
||||||
|
|
|
@ -40,13 +40,20 @@ static grub_menu_t current_menu = 0;
|
||||||
#define GRUB_DEFAULT_HISTORY_SIZE 50
|
#define GRUB_DEFAULT_HISTORY_SIZE 50
|
||||||
|
|
||||||
/* Read a line from the file FILE. */
|
/* Read a line from the file FILE. */
|
||||||
static int
|
static char *
|
||||||
get_line (grub_file_t file, char cmdline[], int max_len)
|
get_line (grub_file_t file)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
int literal = 0;
|
int literal = 0;
|
||||||
int comment = 0;
|
int comment = 0;
|
||||||
|
char *cmdline;
|
||||||
|
int max_len = 64;
|
||||||
|
|
||||||
|
/* Initially locate some space. */
|
||||||
|
cmdline = grub_malloc (max_len);
|
||||||
|
if (! cmdline)
|
||||||
|
return 0;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
@ -97,14 +104,32 @@ get_line (grub_file_t file, char cmdline[], int max_len)
|
||||||
if (c == '\n')
|
if (c == '\n')
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (pos < max_len)
|
if (pos >= max_len)
|
||||||
|
{
|
||||||
|
char *old_cmdline = cmdline;
|
||||||
|
max_len = max_len * 2;
|
||||||
|
cmdline = grub_realloc (cmdline, max_len);
|
||||||
|
if (! cmdline)
|
||||||
|
{
|
||||||
|
grub_free (old_cmdline);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cmdline[pos++] = c;
|
cmdline[pos++] = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdline[pos] = '\0';
|
cmdline[pos] = '\0';
|
||||||
|
|
||||||
return pos;
|
/* If the buffer is empty, don't return anything at all. */
|
||||||
|
if (pos == 0)
|
||||||
|
{
|
||||||
|
grub_free (cmdline);
|
||||||
|
cmdline = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cmdline;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -168,20 +193,15 @@ read_config_file (const char *config)
|
||||||
|
|
||||||
grub_err_t getline (char **line)
|
grub_err_t getline (char **line)
|
||||||
{
|
{
|
||||||
char cmdline[100];
|
|
||||||
currline++;
|
currline++;
|
||||||
|
|
||||||
if (! get_line (file, cmdline, sizeof (cmdline)))
|
*line = get_line (file);
|
||||||
return 0;
|
|
||||||
|
|
||||||
*line = grub_strdup (cmdline);
|
|
||||||
if (! *line)
|
if (! *line)
|
||||||
return grub_errno;
|
return grub_errno;
|
||||||
|
|
||||||
return GRUB_ERR_NONE;
|
return GRUB_ERR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
char cmdline[100];
|
|
||||||
grub_menu_t newmenu;
|
grub_menu_t newmenu;
|
||||||
|
|
||||||
newmenu = grub_malloc (sizeof (*newmenu));
|
newmenu = grub_malloc (sizeof (*newmenu));
|
||||||
|
@ -196,16 +216,23 @@ read_config_file (const char *config)
|
||||||
if (! file)
|
if (! file)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
while (get_line (file, cmdline, sizeof (cmdline)))
|
while (1)
|
||||||
{
|
{
|
||||||
struct grub_script *parsed_script;
|
struct grub_script *parsed_script;
|
||||||
int startline;
|
int startline;
|
||||||
|
char *cmdline;
|
||||||
|
|
||||||
|
cmdline = get_line (file);
|
||||||
|
if (!cmdline)
|
||||||
|
break;
|
||||||
|
|
||||||
startline = ++currline;
|
startline = ++currline;
|
||||||
|
|
||||||
/* Execute the script, line for line. */
|
/* Execute the script, line for line. */
|
||||||
parsed_script = grub_script_parse (cmdline, getline);
|
parsed_script = grub_script_parse (cmdline, getline);
|
||||||
|
|
||||||
|
grub_free (cmdline);
|
||||||
|
|
||||||
if (! parsed_script)
|
if (! parsed_script)
|
||||||
{
|
{
|
||||||
grub_printf ("(line %d-%d)\n", startline, currline);
|
grub_printf ("(line %d-%d)\n", startline, currline);
|
||||||
|
@ -278,12 +305,14 @@ read_command_list (void)
|
||||||
file = grub_file_open (filename);
|
file = grub_file_open (filename);
|
||||||
if (file)
|
if (file)
|
||||||
{
|
{
|
||||||
char buf[80]; /* XXX arbitrary */
|
while (1)
|
||||||
|
|
||||||
while (get_line (file, buf, sizeof (buf)))
|
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
grub_command_t cmd;
|
grub_command_t cmd;
|
||||||
|
char *buf = get_line (file);
|
||||||
|
|
||||||
|
if (! buf)
|
||||||
|
break;
|
||||||
|
|
||||||
if (! grub_isgraph (buf[0]))
|
if (! grub_isgraph (buf[0]))
|
||||||
continue;
|
continue;
|
||||||
|
@ -303,11 +332,15 @@ read_command_list (void)
|
||||||
GRUB_COMMAND_FLAG_NOT_LOADED,
|
GRUB_COMMAND_FLAG_NOT_LOADED,
|
||||||
0, 0, 0);
|
0, 0, 0);
|
||||||
if (! cmd)
|
if (! cmd)
|
||||||
|
{
|
||||||
|
grub_free (buf);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
cmd->module_name = grub_strdup (p);
|
cmd->module_name = grub_strdup (p);
|
||||||
if (! cmd->module_name)
|
if (! cmd->module_name)
|
||||||
grub_unregister_command (buf);
|
grub_unregister_command (buf);
|
||||||
|
grub_free (buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
grub_file_close (file);
|
grub_file_close (file);
|
||||||
|
@ -360,14 +393,20 @@ read_fs_list (void)
|
||||||
file = grub_file_open (filename);
|
file = grub_file_open (filename);
|
||||||
if (file)
|
if (file)
|
||||||
{
|
{
|
||||||
char buf[80]; /* XXX arbitrary */
|
while (1)
|
||||||
|
|
||||||
while (get_line (file, buf, sizeof (buf)))
|
|
||||||
{
|
{
|
||||||
char *p = buf;
|
char *buf;
|
||||||
char *q = buf + grub_strlen (buf) - 1;
|
char *p;
|
||||||
|
char *q;
|
||||||
grub_fs_module_list_t fs_mod;
|
grub_fs_module_list_t fs_mod;
|
||||||
|
|
||||||
|
buf = get_line (file);
|
||||||
|
if (! buf)
|
||||||
|
break;
|
||||||
|
|
||||||
|
p = buf;
|
||||||
|
q = buf + grub_strlen (buf) - 1;
|
||||||
|
|
||||||
/* Ignore space. */
|
/* Ignore space. */
|
||||||
while (grub_isspace (*p))
|
while (grub_isspace (*p))
|
||||||
p++;
|
p++;
|
||||||
|
|
Loading…
Reference in a new issue