* kern/parser.c: Indented.
This commit is contained in:
parent
ed0e3d30cd
commit
f84afb2775
2 changed files with 74 additions and 70 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
2010-03-18 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
|
* kern/parser.c: Indented.
|
||||||
|
|
||||||
2010-03-17 Vladimir Serbinenko <phcoder@gmail.com>
|
2010-03-17 Vladimir Serbinenko <phcoder@gmail.com>
|
||||||
|
|
||||||
* term/i386/pc/vesafb.c: Removed (orphaned, deprecated and broken).
|
* term/i386/pc/vesafb.c: Removed (orphaned, deprecated and broken).
|
||||||
|
|
140
kern/parser.c
140
kern/parser.c
|
@ -26,32 +26,31 @@
|
||||||
/* All the possible state transitions on the command line. If a
|
/* All the possible state transitions on the command line. If a
|
||||||
transition can not be found, it is assumed that there is no
|
transition can not be found, it is assumed that there is no
|
||||||
transition and keep_value is assumed to be 1. */
|
transition and keep_value is assumed to be 1. */
|
||||||
static struct grub_parser_state_transition state_transitions[] =
|
static struct grub_parser_state_transition state_transitions[] = {
|
||||||
{
|
{GRUB_PARSER_STATE_TEXT, GRUB_PARSER_STATE_QUOTE, '\'', 0},
|
||||||
{ GRUB_PARSER_STATE_TEXT, GRUB_PARSER_STATE_QUOTE, '\'', 0},
|
{GRUB_PARSER_STATE_TEXT, GRUB_PARSER_STATE_DQUOTE, '\"', 0},
|
||||||
{ GRUB_PARSER_STATE_TEXT, GRUB_PARSER_STATE_DQUOTE, '\"', 0},
|
{GRUB_PARSER_STATE_TEXT, GRUB_PARSER_STATE_VAR, '$', 0},
|
||||||
{ GRUB_PARSER_STATE_TEXT, GRUB_PARSER_STATE_VAR, '$', 0},
|
{GRUB_PARSER_STATE_TEXT, GRUB_PARSER_STATE_ESC, '\\', 0},
|
||||||
{ GRUB_PARSER_STATE_TEXT, GRUB_PARSER_STATE_ESC, '\\', 0},
|
|
||||||
|
|
||||||
{ GRUB_PARSER_STATE_ESC, GRUB_PARSER_STATE_TEXT, 0, 1},
|
{GRUB_PARSER_STATE_ESC, GRUB_PARSER_STATE_TEXT, 0, 1},
|
||||||
|
|
||||||
{ GRUB_PARSER_STATE_QUOTE, GRUB_PARSER_STATE_TEXT, '\'', 0},
|
{GRUB_PARSER_STATE_QUOTE, GRUB_PARSER_STATE_TEXT, '\'', 0},
|
||||||
|
|
||||||
{ GRUB_PARSER_STATE_DQUOTE, GRUB_PARSER_STATE_TEXT, '\"', 0},
|
{GRUB_PARSER_STATE_DQUOTE, GRUB_PARSER_STATE_TEXT, '\"', 0},
|
||||||
{ GRUB_PARSER_STATE_DQUOTE, GRUB_PARSER_STATE_QVAR, '$', 0},
|
{GRUB_PARSER_STATE_DQUOTE, GRUB_PARSER_STATE_QVAR, '$', 0},
|
||||||
|
|
||||||
{ GRUB_PARSER_STATE_VAR, GRUB_PARSER_STATE_VARNAME2, '{', 0},
|
{GRUB_PARSER_STATE_VAR, GRUB_PARSER_STATE_VARNAME2, '{', 0},
|
||||||
{ GRUB_PARSER_STATE_VAR, GRUB_PARSER_STATE_VARNAME, 0, 1},
|
{GRUB_PARSER_STATE_VAR, GRUB_PARSER_STATE_VARNAME, 0, 1},
|
||||||
{ GRUB_PARSER_STATE_VARNAME, GRUB_PARSER_STATE_TEXT, ' ', 1},
|
{GRUB_PARSER_STATE_VARNAME, GRUB_PARSER_STATE_TEXT, ' ', 1},
|
||||||
{ GRUB_PARSER_STATE_VARNAME2, GRUB_PARSER_STATE_TEXT, '}', 0},
|
{GRUB_PARSER_STATE_VARNAME2, GRUB_PARSER_STATE_TEXT, '}', 0},
|
||||||
|
|
||||||
{ GRUB_PARSER_STATE_QVAR, GRUB_PARSER_STATE_QVARNAME2, '{', 0},
|
{GRUB_PARSER_STATE_QVAR, GRUB_PARSER_STATE_QVARNAME2, '{', 0},
|
||||||
{ GRUB_PARSER_STATE_QVAR, GRUB_PARSER_STATE_QVARNAME, 0, 1},
|
{GRUB_PARSER_STATE_QVAR, GRUB_PARSER_STATE_QVARNAME, 0, 1},
|
||||||
{ GRUB_PARSER_STATE_QVARNAME, GRUB_PARSER_STATE_TEXT, '\"', 0},
|
{GRUB_PARSER_STATE_QVARNAME, GRUB_PARSER_STATE_TEXT, '\"', 0},
|
||||||
{ GRUB_PARSER_STATE_QVARNAME, GRUB_PARSER_STATE_DQUOTE, ' ', 1},
|
{GRUB_PARSER_STATE_QVARNAME, GRUB_PARSER_STATE_DQUOTE, ' ', 1},
|
||||||
{ GRUB_PARSER_STATE_QVARNAME2, GRUB_PARSER_STATE_DQUOTE, '}', 0},
|
{GRUB_PARSER_STATE_QVARNAME2, GRUB_PARSER_STATE_DQUOTE, '}', 0},
|
||||||
|
|
||||||
{ 0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,17 +73,17 @@ grub_parser_cmdline_state (grub_parser_state_t state, char c, char *result)
|
||||||
if (transition->input == c)
|
if (transition->input == c)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (transition->input == ' ' && ! grub_isalpha (c)
|
if (transition->input == ' ' && !grub_isalpha (c)
|
||||||
&& ! grub_isdigit (c) && c != '_')
|
&& !grub_isdigit (c) && c != '_')
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* A less perfect match was found, use this one if no exact
|
/* A less perfect match was found, use this one if no exact
|
||||||
match can be found. */
|
match can be found. */
|
||||||
if (transition->input == 0)
|
if (transition->input == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! transition->from_state)
|
if (!transition->from_state)
|
||||||
transition = &default_transition;
|
transition = &default_transition;
|
||||||
|
|
||||||
if (transition->keep_value)
|
if (transition->keep_value)
|
||||||
|
@ -113,43 +112,44 @@ grub_parser_split_cmdline (const char *cmdline, grub_reader_getline_t getline,
|
||||||
auto int check_varstate (grub_parser_state_t s);
|
auto int check_varstate (grub_parser_state_t s);
|
||||||
|
|
||||||
int check_varstate (grub_parser_state_t s)
|
int check_varstate (grub_parser_state_t s)
|
||||||
{
|
{
|
||||||
return (s == GRUB_PARSER_STATE_VARNAME
|
return (s == GRUB_PARSER_STATE_VARNAME
|
||||||
|| s == GRUB_PARSER_STATE_VARNAME2
|
|| s == GRUB_PARSER_STATE_VARNAME2
|
||||||
|| s == GRUB_PARSER_STATE_QVARNAME
|
|| s == GRUB_PARSER_STATE_QVARNAME
|
||||||
|| s == GRUB_PARSER_STATE_QVARNAME2);
|
|| s == GRUB_PARSER_STATE_QVARNAME2);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto void add_var (grub_parser_state_t newstate);
|
auto void add_var (grub_parser_state_t newstate);
|
||||||
|
|
||||||
void add_var (grub_parser_state_t newstate)
|
void add_var (grub_parser_state_t newstate)
|
||||||
{
|
{
|
||||||
char *val;
|
char *val;
|
||||||
|
|
||||||
/* Check if a variable was being read in and the end of the name
|
/* Check if a variable was being read in and the end of the name
|
||||||
was reached. */
|
was reached. */
|
||||||
if (! (check_varstate (state) && !check_varstate (newstate)))
|
if (!(check_varstate (state) && !check_varstate (newstate)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
*(vp++) = '\0';
|
*(vp++) = '\0';
|
||||||
val = grub_env_get (varname);
|
val = grub_env_get (varname);
|
||||||
vp = varname;
|
vp = varname;
|
||||||
if (! val)
|
if (!val)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Insert the contents of the variable in the buffer. */
|
/* Insert the contents of the variable in the buffer. */
|
||||||
for (; *val; val++)
|
for (; *val; val++)
|
||||||
*(bp++) = *val;
|
*(bp++) = *val;
|
||||||
}
|
}
|
||||||
|
|
||||||
*argc = 0;
|
*argc = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (! rd || !*rd)
|
if (!rd || !*rd)
|
||||||
{
|
{
|
||||||
if (getline)
|
if (getline)
|
||||||
getline (&rd, 1);
|
getline (&rd, 1);
|
||||||
else break;
|
else
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rd)
|
if (!rd)
|
||||||
|
@ -190,7 +190,8 @@ grub_parser_split_cmdline (const char *cmdline, grub_reader_getline_t getline,
|
||||||
}
|
}
|
||||||
state = newstate;
|
state = newstate;
|
||||||
}
|
}
|
||||||
} while (state != GRUB_PARSER_STATE_TEXT && !check_varstate (state));
|
}
|
||||||
|
while (state != GRUB_PARSER_STATE_TEXT && !check_varstate (state));
|
||||||
|
|
||||||
/* A special case for when the last character was part of a
|
/* A special case for when the last character was part of a
|
||||||
variable. */
|
variable. */
|
||||||
|
@ -204,12 +205,12 @@ grub_parser_split_cmdline (const char *cmdline, grub_reader_getline_t getline,
|
||||||
|
|
||||||
/* Reserve memory for the return values. */
|
/* Reserve memory for the return values. */
|
||||||
args = grub_malloc (bp - buffer);
|
args = grub_malloc (bp - buffer);
|
||||||
if (! args)
|
if (!args)
|
||||||
return grub_errno;
|
return grub_errno;
|
||||||
grub_memcpy (args, buffer, bp - buffer);
|
grub_memcpy (args, buffer, bp - buffer);
|
||||||
|
|
||||||
*argv = grub_malloc (sizeof (char *) * (*argc + 1));
|
*argv = grub_malloc (sizeof (char *) * (*argc + 1));
|
||||||
if (! *argv)
|
if (!*argv)
|
||||||
{
|
{
|
||||||
grub_free (args);
|
grub_free (args);
|
||||||
return grub_errno;
|
return grub_errno;
|
||||||
|
@ -229,35 +230,34 @@ grub_parser_split_cmdline (const char *cmdline, grub_reader_getline_t getline,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct grub_handler_class grub_parser_class =
|
struct grub_handler_class grub_parser_class = {
|
||||||
{
|
.name = "parser"
|
||||||
.name = "parser"
|
};
|
||||||
};
|
|
||||||
|
|
||||||
grub_err_t
|
grub_err_t
|
||||||
grub_parser_execute (char *source)
|
grub_parser_execute (char *source)
|
||||||
{
|
{
|
||||||
auto grub_err_t getline (char **line, int cont);
|
auto grub_err_t getline (char **line, int cont);
|
||||||
grub_err_t getline (char **line, int cont __attribute__ ((unused)))
|
grub_err_t getline (char **line, int cont __attribute__ ((unused)))
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if (! source)
|
if (!source)
|
||||||
{
|
{
|
||||||
*line = 0;
|
*line = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = grub_strchr (source, '\n');
|
p = grub_strchr (source, '\n');
|
||||||
if (p)
|
if (p)
|
||||||
*p = 0;
|
*p = 0;
|
||||||
|
|
||||||
*line = grub_strdup (source);
|
*line = grub_strdup (source);
|
||||||
if (p)
|
if (p)
|
||||||
*p = '\n';
|
*p = '\n';
|
||||||
source = p ? p + 1 : 0;
|
source = p ? p + 1 : 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (source)
|
while (source)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue