merge with mainline
This commit is contained in:
commit
e5a73c4247
182 changed files with 9977 additions and 5276 deletions
|
@ -119,76 +119,86 @@ grub_script_lexer_record (struct grub_parser_param *parser, char *str)
|
|||
lexer->recordpos += len;
|
||||
}
|
||||
|
||||
/* Append '\n' to SRC, before '\0' */
|
||||
static char *
|
||||
append_newline (const char *src)
|
||||
{
|
||||
char *line;
|
||||
grub_size_t len;
|
||||
|
||||
len = grub_strlen (src);
|
||||
line = grub_malloc (len + 2);
|
||||
if (!line)
|
||||
return 0;
|
||||
|
||||
grub_strcpy (line, src);
|
||||
|
||||
line[len] = '\n';
|
||||
line[len + 1] = '\0';
|
||||
return line;
|
||||
}
|
||||
|
||||
/* Read next line of input if necessary, and set yyscanner buffers. */
|
||||
int
|
||||
grub_script_lexer_yywrap (struct grub_parser_param *parserstate)
|
||||
grub_script_lexer_yywrap (struct grub_parser_param *parserstate,
|
||||
const char *input)
|
||||
{
|
||||
int len;
|
||||
char *line;
|
||||
char *line2;
|
||||
char *p = 0;
|
||||
char *line = 0;
|
||||
YY_BUFFER_STATE buffer;
|
||||
struct grub_lexer_param *lexerstate = parserstate->lexerstate;
|
||||
|
||||
if (!lexerstate->refs)
|
||||
return 0;
|
||||
if (! lexerstate->refs && ! lexerstate->prefix && ! input)
|
||||
return 1;
|
||||
|
||||
if (!lexerstate->getline)
|
||||
if (! lexerstate->getline && ! input)
|
||||
{
|
||||
grub_script_yyerror (parserstate, "unexpected end of file");
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
line = 0;
|
||||
buffer = 0;
|
||||
lexerstate->getline (&line, 1);
|
||||
if (!line)
|
||||
{
|
||||
grub_script_yyerror (parserstate, 0); /* XXX this could be for ^C case? */
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = grub_strlen (line);
|
||||
if (line[len - 1] == '\n')
|
||||
{
|
||||
buffer = yy_scan_string (line, lexerstate->yyscanner);
|
||||
}
|
||||
if (! input)
|
||||
lexerstate->getline (&line, 1);
|
||||
else
|
||||
line = grub_strdup (input);
|
||||
|
||||
/* Ensure '\n' at the end. */
|
||||
if (line && line[0] == '\0')
|
||||
{
|
||||
line2 = append_newline (line);
|
||||
if (line2)
|
||||
{
|
||||
buffer = yy_scan_string (line2, lexerstate->yyscanner);
|
||||
grub_free (line2);
|
||||
}
|
||||
grub_free (line);
|
||||
line = grub_strdup ("\n");
|
||||
}
|
||||
|
||||
if (line && (len = grub_strlen(line)) && line[len - 1] != '\n')
|
||||
{
|
||||
p = grub_realloc (line, len + 2);
|
||||
if (p)
|
||||
{
|
||||
p[len++] = '\n';
|
||||
p[len] = '\0';
|
||||
}
|
||||
line = p;
|
||||
}
|
||||
|
||||
if (! line)
|
||||
{
|
||||
grub_script_yyerror (parserstate, "out of memory");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Prepend any left over unput-text. */
|
||||
if (lexerstate->prefix)
|
||||
{
|
||||
int plen = grub_strlen (lexerstate->prefix);
|
||||
|
||||
p = grub_malloc (len + plen + 1);
|
||||
if (! p)
|
||||
{
|
||||
grub_free (line);
|
||||
return 1;
|
||||
}
|
||||
grub_strcpy (p, lexerstate->prefix);
|
||||
lexerstate->prefix = 0;
|
||||
|
||||
grub_strcpy (p + plen, line);
|
||||
grub_free (line);
|
||||
|
||||
line = p;
|
||||
len = len + plen;
|
||||
}
|
||||
|
||||
buffer = yy_scan_string (line, lexerstate->yyscanner);
|
||||
grub_free (line);
|
||||
if (!buffer)
|
||||
|
||||
if (! buffer)
|
||||
{
|
||||
grub_script_yyerror (parserstate, 0);
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct grub_lexer_param *
|
||||
|
@ -196,7 +206,6 @@ grub_script_lexer_init (struct grub_parser_param *parser, char *script,
|
|||
grub_reader_getline_t getline)
|
||||
{
|
||||
int len;
|
||||
char *script2;
|
||||
YY_BUFFER_STATE buffer;
|
||||
struct grub_lexer_param *lexerstate;
|
||||
|
||||
|
@ -220,34 +229,18 @@ grub_script_lexer_init (struct grub_parser_param *parser, char *script,
|
|||
return 0;
|
||||
}
|
||||
|
||||
buffer = 0;
|
||||
script = script ? : "\n";
|
||||
len = grub_strlen (script);
|
||||
yyset_extra (parser, lexerstate->yyscanner);
|
||||
parser->lexerstate = lexerstate;
|
||||
|
||||
if (script[len - 1] == '\n')
|
||||
{
|
||||
buffer = yy_scan_string (script, lexerstate->yyscanner);
|
||||
}
|
||||
else
|
||||
{
|
||||
script2 = append_newline (script);
|
||||
if (script2)
|
||||
{
|
||||
buffer = yy_scan_string (script2, lexerstate->yyscanner);
|
||||
grub_free (script2);
|
||||
}
|
||||
}
|
||||
|
||||
if (!buffer)
|
||||
if (grub_script_lexer_yywrap (parser, script ?: "\n"))
|
||||
{
|
||||
parser->lexerstate = 0;
|
||||
yylex_destroy (lexerstate->yyscanner);
|
||||
grub_free (lexerstate->yyscanner);
|
||||
|
||||
grub_free (lexerstate->text);
|
||||
grub_free (lexerstate);
|
||||
return 0;
|
||||
}
|
||||
yyset_extra (parser, lexerstate->yyscanner);
|
||||
|
||||
return lexerstate;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue