grub/util/grub-script-check.c

208 lines
4.5 KiB
C
Raw Normal View History

2010-01-09 14:57:58 +00:00
/* grub-script-check.c - check grub script file for syntax errors */
/*
* GRUB -- GRand Unified Bootloader
2010-01-22 13:37:27 +00:00
* Copyright (C) 2009,2010 Free Software Foundation, Inc.
2010-01-09 14:57:58 +00:00
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <grub/types.h>
#include <grub/mm.h>
#include <grub/misc.h>
2010-05-06 06:04:04 +00:00
#include <grub/emu/misc.h>
2010-01-18 11:28:03 +00:00
#include <grub/util/misc.h>
2010-01-09 14:57:58 +00:00
#include <grub/i18n.h>
#include <grub/parser.h>
#include <grub/script_sh.h>
#define _GNU_SOURCE 1
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <argp.h>
2010-01-09 14:57:58 +00:00
#include "progname.h"
struct arguments
2010-01-09 14:57:58 +00:00
{
int verbose;
char *filename;
};
static struct argp_option options[] = {
Clarify and unify messages. * grub-core/commands/hashsum.c (options): Unify messages. * grub-core/commands/keystatus.c (GRUB_MOD_INIT): Don't mark a literal-only message as translatable. * grub-core/commands/lsacpi.c (GRUB_MOD_INIT): Likewise. * grub-core/loader/ia64/efi/linux.c (GRUB_MOD_INIT): Likewise. * grub-core/commands/legacycfg.c (GRUB_MOD_INIT): Add quoting around commands. * grub-core/commands/menuentry.c (options): Clarify that it's a keyboard key, not the key used to unlock. Clarify what it's used for. * grub-core/kern/emu/hostdisk.c (read_device_map): Unify error message. * grub-core/loader/xnu.c (grub_xnu_load_driver): Remove erroneous colon. * grub-core/script/main.c (GRUB_MOD_INIT): Clarify [n] to be [NUM]. * util/grub-editenv.c (options): Unify "verbose" message. * util/grub-fstest.c (read_file): Unify error message. (fstest): Add quotes around commands. (options): Unify "verbose" message. * util/grub-install.in: Add quotes around variable name. * util/grub-kbdcomp.in: Unify error message. * util/grub-mkfont.c (main): Likewise. * util/grub-mkrescue.in: Likewise. * util/grub-mklayout.c (options): Unify "verbose" message. * util/grub-mkstandalone.in: Unify help and verbose messages. * util/grub-mount.c (options): Unify "verbose" message. * util/grub-probe.c (options): Likewise. * util/grub-script-check.c (options): Likewise. * util/grub-setup.c (setup): Unify no-terminator message. (options): Use DEVICE and not DEV. Unify "verbose" message. * util/ieee1275/ofpath.c (xrealpath): Unify error message.
2012-02-05 10:23:47 +00:00
{"verbose", 'v', 0, 0, N_("print verbose messages."), 0},
{ 0, 0, 0, 0, 0, 0 }
};
static error_t
argp_parser (int key, char *arg, struct argp_state *state)
{
/* Get the input argument from argp_parse, which we
know is a pointer to our arguments structure. */
struct arguments *arguments = state->input;
switch (key)
{
case 'v':
arguments->verbose = 1;
break;
case ARGP_KEY_ARG:
if (state->arg_num == 0)
arguments->filename = xstrdup (arg);
else
{
/* Too many arguments. */
fprintf (stderr, _("Unknown extra argument `%s'."), arg);
fprintf (stderr, "\n");
argp_usage (state);
}
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
2010-01-09 14:57:58 +00:00
}
static struct argp argp = {
options, argp_parser, N_("[PATH]"),
N_("Checks GRUB script configuration file for syntax errors."),
NULL, NULL, NULL
};
Remove nested functions from script reading and parsing. * grub-core/kern/parser.c (grub_parser_split_cmdline): Add getline_data argument, passed to getline. * grub-core/kern/rescue_parser.c (grub_rescue_parse_line): Add getline_data argument, passed to grub_parser_split_cmdline. * grub-core/script/lexer.c (grub_script_lexer_yywrap): Pass lexerstate->getline_data to lexerstate->getline. (grub_script_lexer_init): Add getline_data argument, saved in lexerstate->getline_data. * grub-core/script/main.c (grub_normal_parse_line): Add getline_data argument, passed to grub_script_parse. * grub-core/script/script.c (grub_script_parse): Add getline_data argument, passed to grub_script_lexer_init. * include/grub/parser.h (grub_parser_split_cmdline): Update prototype. Update all callers to pass appropriate getline data. (struct grub_parser.parse_line): Likewise. (grub_rescue_parse_line): Likewise. * include/grub/reader.h (grub_reader_getline_t): Add void * argument. * include/grub/script_sh.h (struct grub_lexer_param): Add getline_data member. (grub_script_parse): Update prototype. Update all callers to pass appropriate getline data. (grub_script_lexer_init): Likewise. (grub_normal_parse_line): Likewise. * grub-core/commands/legacycfg.c (legacy_file_getline): Add unused data argument. * grub-core/kern/parser.c (grub_parser_execute: getline): Make static instead of nested. Rename to ... (grub_parser_execute_getline): ... this. * grub-core/kern/rescue_reader.c (grub_rescue_read_line): Add unused data argument. * grub-core/normal/main.c (read_config_file: getline): Make static instead of nested. Rename to ... (read_config_file_getline): ... this. (grub_normal_read_line): Add unused data argument. * grub-core/script/execute.c (grub_script_execute_sourcecode: getline): Make static instead of nested. Rename to ... (grub_script_execute_sourcecode_getline): ... this. * util/grub-script-check.c (main: get_config_line): Make static instead of nested.
2013-01-15 12:03:25 +00:00
/* Context for main. */
struct main_ctx
{
int lineno;
FILE *file;
struct arguments arguments;
};
/* Helper for main. */
static grub_err_t
get_config_line (char **line, int cont __attribute__ ((unused)), void *data)
{
struct main_ctx *ctx = data;
int i;
char *cmdline = 0;
size_t len = 0;
ssize_t curread;
curread = getline (&cmdline, &len, (ctx->file ?: stdin));
if (curread == -1)
{
*line = 0;
grub_errno = GRUB_ERR_READ_ERROR;
if (cmdline)
free (cmdline);
return grub_errno;
}
if (ctx->arguments.verbose)
grub_printf ("%s", cmdline);
for (i = 0; cmdline[i] != '\0'; i++)
{
/* Replace tabs and carriage returns with spaces. */
if (cmdline[i] == '\t' || cmdline[i] == '\r')
cmdline[i] = ' ';
/* Replace '\n' with '\0'. */
if (cmdline[i] == '\n')
cmdline[i] = '\0';
}
ctx->lineno++;
*line = grub_strdup (cmdline);
free (cmdline);
return 0;
}
2010-01-09 14:57:58 +00:00
int
main (int argc, char *argv[])
{
Remove nested functions from script reading and parsing. * grub-core/kern/parser.c (grub_parser_split_cmdline): Add getline_data argument, passed to getline. * grub-core/kern/rescue_parser.c (grub_rescue_parse_line): Add getline_data argument, passed to grub_parser_split_cmdline. * grub-core/script/lexer.c (grub_script_lexer_yywrap): Pass lexerstate->getline_data to lexerstate->getline. (grub_script_lexer_init): Add getline_data argument, saved in lexerstate->getline_data. * grub-core/script/main.c (grub_normal_parse_line): Add getline_data argument, passed to grub_script_parse. * grub-core/script/script.c (grub_script_parse): Add getline_data argument, passed to grub_script_lexer_init. * include/grub/parser.h (grub_parser_split_cmdline): Update prototype. Update all callers to pass appropriate getline data. (struct grub_parser.parse_line): Likewise. (grub_rescue_parse_line): Likewise. * include/grub/reader.h (grub_reader_getline_t): Add void * argument. * include/grub/script_sh.h (struct grub_lexer_param): Add getline_data member. (grub_script_parse): Update prototype. Update all callers to pass appropriate getline data. (grub_script_lexer_init): Likewise. (grub_normal_parse_line): Likewise. * grub-core/commands/legacycfg.c (legacy_file_getline): Add unused data argument. * grub-core/kern/parser.c (grub_parser_execute: getline): Make static instead of nested. Rename to ... (grub_parser_execute_getline): ... this. * grub-core/kern/rescue_reader.c (grub_rescue_read_line): Add unused data argument. * grub-core/normal/main.c (read_config_file: getline): Make static instead of nested. Rename to ... (read_config_file_getline): ... this. (grub_normal_read_line): Add unused data argument. * grub-core/script/execute.c (grub_script_execute_sourcecode: getline): Make static instead of nested. Rename to ... (grub_script_execute_sourcecode_getline): ... this. * util/grub-script-check.c (main: get_config_line): Make static instead of nested.
2013-01-15 12:03:25 +00:00
struct main_ctx ctx = {
.lineno = 0,
.file = 0
};
2010-01-09 14:57:58 +00:00
char *input;
int found_input = 0;
struct grub_script *script = NULL;
2010-01-09 14:57:58 +00:00
set_program_name (argv[0]);
2010-01-18 11:28:03 +00:00
grub_util_init_nls ();
2010-01-09 14:57:58 +00:00
Remove nested functions from script reading and parsing. * grub-core/kern/parser.c (grub_parser_split_cmdline): Add getline_data argument, passed to getline. * grub-core/kern/rescue_parser.c (grub_rescue_parse_line): Add getline_data argument, passed to grub_parser_split_cmdline. * grub-core/script/lexer.c (grub_script_lexer_yywrap): Pass lexerstate->getline_data to lexerstate->getline. (grub_script_lexer_init): Add getline_data argument, saved in lexerstate->getline_data. * grub-core/script/main.c (grub_normal_parse_line): Add getline_data argument, passed to grub_script_parse. * grub-core/script/script.c (grub_script_parse): Add getline_data argument, passed to grub_script_lexer_init. * include/grub/parser.h (grub_parser_split_cmdline): Update prototype. Update all callers to pass appropriate getline data. (struct grub_parser.parse_line): Likewise. (grub_rescue_parse_line): Likewise. * include/grub/reader.h (grub_reader_getline_t): Add void * argument. * include/grub/script_sh.h (struct grub_lexer_param): Add getline_data member. (grub_script_parse): Update prototype. Update all callers to pass appropriate getline data. (grub_script_lexer_init): Likewise. (grub_normal_parse_line): Likewise. * grub-core/commands/legacycfg.c (legacy_file_getline): Add unused data argument. * grub-core/kern/parser.c (grub_parser_execute: getline): Make static instead of nested. Rename to ... (grub_parser_execute_getline): ... this. * grub-core/kern/rescue_reader.c (grub_rescue_read_line): Add unused data argument. * grub-core/normal/main.c (read_config_file: getline): Make static instead of nested. Rename to ... (read_config_file_getline): ... this. (grub_normal_read_line): Add unused data argument. * grub-core/script/execute.c (grub_script_execute_sourcecode: getline): Make static instead of nested. Rename to ... (grub_script_execute_sourcecode_getline): ... this. * util/grub-script-check.c (main: get_config_line): Make static instead of nested.
2013-01-15 12:03:25 +00:00
memset (&ctx.arguments, 0, sizeof (struct arguments));
2010-01-09 14:57:58 +00:00
/* Check for options. */
Remove nested functions from script reading and parsing. * grub-core/kern/parser.c (grub_parser_split_cmdline): Add getline_data argument, passed to getline. * grub-core/kern/rescue_parser.c (grub_rescue_parse_line): Add getline_data argument, passed to grub_parser_split_cmdline. * grub-core/script/lexer.c (grub_script_lexer_yywrap): Pass lexerstate->getline_data to lexerstate->getline. (grub_script_lexer_init): Add getline_data argument, saved in lexerstate->getline_data. * grub-core/script/main.c (grub_normal_parse_line): Add getline_data argument, passed to grub_script_parse. * grub-core/script/script.c (grub_script_parse): Add getline_data argument, passed to grub_script_lexer_init. * include/grub/parser.h (grub_parser_split_cmdline): Update prototype. Update all callers to pass appropriate getline data. (struct grub_parser.parse_line): Likewise. (grub_rescue_parse_line): Likewise. * include/grub/reader.h (grub_reader_getline_t): Add void * argument. * include/grub/script_sh.h (struct grub_lexer_param): Add getline_data member. (grub_script_parse): Update prototype. Update all callers to pass appropriate getline data. (grub_script_lexer_init): Likewise. (grub_normal_parse_line): Likewise. * grub-core/commands/legacycfg.c (legacy_file_getline): Add unused data argument. * grub-core/kern/parser.c (grub_parser_execute: getline): Make static instead of nested. Rename to ... (grub_parser_execute_getline): ... this. * grub-core/kern/rescue_reader.c (grub_rescue_read_line): Add unused data argument. * grub-core/normal/main.c (read_config_file: getline): Make static instead of nested. Rename to ... (read_config_file_getline): ... this. (grub_normal_read_line): Add unused data argument. * grub-core/script/execute.c (grub_script_execute_sourcecode: getline): Make static instead of nested. Rename to ... (grub_script_execute_sourcecode_getline): ... this. * util/grub-script-check.c (main: get_config_line): Make static instead of nested.
2013-01-15 12:03:25 +00:00
if (argp_parse (&argp, argc, argv, 0, 0, &ctx.arguments) != 0)
2010-01-09 14:57:58 +00:00
{
fprintf (stderr, "%s", _("Error in parsing command line arguments\n"));
exit(1);
2010-01-09 14:57:58 +00:00
}
/* Obtain ARGUMENT. */
Remove nested functions from script reading and parsing. * grub-core/kern/parser.c (grub_parser_split_cmdline): Add getline_data argument, passed to getline. * grub-core/kern/rescue_parser.c (grub_rescue_parse_line): Add getline_data argument, passed to grub_parser_split_cmdline. * grub-core/script/lexer.c (grub_script_lexer_yywrap): Pass lexerstate->getline_data to lexerstate->getline. (grub_script_lexer_init): Add getline_data argument, saved in lexerstate->getline_data. * grub-core/script/main.c (grub_normal_parse_line): Add getline_data argument, passed to grub_script_parse. * grub-core/script/script.c (grub_script_parse): Add getline_data argument, passed to grub_script_lexer_init. * include/grub/parser.h (grub_parser_split_cmdline): Update prototype. Update all callers to pass appropriate getline data. (struct grub_parser.parse_line): Likewise. (grub_rescue_parse_line): Likewise. * include/grub/reader.h (grub_reader_getline_t): Add void * argument. * include/grub/script_sh.h (struct grub_lexer_param): Add getline_data member. (grub_script_parse): Update prototype. Update all callers to pass appropriate getline data. (grub_script_lexer_init): Likewise. (grub_normal_parse_line): Likewise. * grub-core/commands/legacycfg.c (legacy_file_getline): Add unused data argument. * grub-core/kern/parser.c (grub_parser_execute: getline): Make static instead of nested. Rename to ... (grub_parser_execute_getline): ... this. * grub-core/kern/rescue_reader.c (grub_rescue_read_line): Add unused data argument. * grub-core/normal/main.c (read_config_file: getline): Make static instead of nested. Rename to ... (read_config_file_getline): ... this. (grub_normal_read_line): Add unused data argument. * grub-core/script/execute.c (grub_script_execute_sourcecode: getline): Make static instead of nested. Rename to ... (grub_script_execute_sourcecode_getline): ... this. * util/grub-script-check.c (main: get_config_line): Make static instead of nested.
2013-01-15 12:03:25 +00:00
if (!ctx.arguments.filename)
2010-01-09 14:57:58 +00:00
{
Remove nested functions from script reading and parsing. * grub-core/kern/parser.c (grub_parser_split_cmdline): Add getline_data argument, passed to getline. * grub-core/kern/rescue_parser.c (grub_rescue_parse_line): Add getline_data argument, passed to grub_parser_split_cmdline. * grub-core/script/lexer.c (grub_script_lexer_yywrap): Pass lexerstate->getline_data to lexerstate->getline. (grub_script_lexer_init): Add getline_data argument, saved in lexerstate->getline_data. * grub-core/script/main.c (grub_normal_parse_line): Add getline_data argument, passed to grub_script_parse. * grub-core/script/script.c (grub_script_parse): Add getline_data argument, passed to grub_script_lexer_init. * include/grub/parser.h (grub_parser_split_cmdline): Update prototype. Update all callers to pass appropriate getline data. (struct grub_parser.parse_line): Likewise. (grub_rescue_parse_line): Likewise. * include/grub/reader.h (grub_reader_getline_t): Add void * argument. * include/grub/script_sh.h (struct grub_lexer_param): Add getline_data member. (grub_script_parse): Update prototype. Update all callers to pass appropriate getline data. (grub_script_lexer_init): Likewise. (grub_normal_parse_line): Likewise. * grub-core/commands/legacycfg.c (legacy_file_getline): Add unused data argument. * grub-core/kern/parser.c (grub_parser_execute: getline): Make static instead of nested. Rename to ... (grub_parser_execute_getline): ... this. * grub-core/kern/rescue_reader.c (grub_rescue_read_line): Add unused data argument. * grub-core/normal/main.c (read_config_file: getline): Make static instead of nested. Rename to ... (read_config_file_getline): ... this. (grub_normal_read_line): Add unused data argument. * grub-core/script/execute.c (grub_script_execute_sourcecode: getline): Make static instead of nested. Rename to ... (grub_script_execute_sourcecode_getline): ... this. * util/grub-script-check.c (main: get_config_line): Make static instead of nested.
2013-01-15 12:03:25 +00:00
ctx.file = 0; /* read from stdin */
2010-01-09 14:57:58 +00:00
}
else
{
Remove nested functions from script reading and parsing. * grub-core/kern/parser.c (grub_parser_split_cmdline): Add getline_data argument, passed to getline. * grub-core/kern/rescue_parser.c (grub_rescue_parse_line): Add getline_data argument, passed to grub_parser_split_cmdline. * grub-core/script/lexer.c (grub_script_lexer_yywrap): Pass lexerstate->getline_data to lexerstate->getline. (grub_script_lexer_init): Add getline_data argument, saved in lexerstate->getline_data. * grub-core/script/main.c (grub_normal_parse_line): Add getline_data argument, passed to grub_script_parse. * grub-core/script/script.c (grub_script_parse): Add getline_data argument, passed to grub_script_lexer_init. * include/grub/parser.h (grub_parser_split_cmdline): Update prototype. Update all callers to pass appropriate getline data. (struct grub_parser.parse_line): Likewise. (grub_rescue_parse_line): Likewise. * include/grub/reader.h (grub_reader_getline_t): Add void * argument. * include/grub/script_sh.h (struct grub_lexer_param): Add getline_data member. (grub_script_parse): Update prototype. Update all callers to pass appropriate getline data. (grub_script_lexer_init): Likewise. (grub_normal_parse_line): Likewise. * grub-core/commands/legacycfg.c (legacy_file_getline): Add unused data argument. * grub-core/kern/parser.c (grub_parser_execute: getline): Make static instead of nested. Rename to ... (grub_parser_execute_getline): ... this. * grub-core/kern/rescue_reader.c (grub_rescue_read_line): Add unused data argument. * grub-core/normal/main.c (read_config_file: getline): Make static instead of nested. Rename to ... (read_config_file_getline): ... this. (grub_normal_read_line): Add unused data argument. * grub-core/script/execute.c (grub_script_execute_sourcecode: getline): Make static instead of nested. Rename to ... (grub_script_execute_sourcecode_getline): ... this. * util/grub-script-check.c (main: get_config_line): Make static instead of nested.
2013-01-15 12:03:25 +00:00
ctx.file = fopen (ctx.arguments.filename, "r");
if (! ctx.file)
2010-01-09 14:57:58 +00:00
{
char *program = xstrdup(program_name);
fprintf (stderr, _("cannot open `%s': %s"),
Remove nested functions from script reading and parsing. * grub-core/kern/parser.c (grub_parser_split_cmdline): Add getline_data argument, passed to getline. * grub-core/kern/rescue_parser.c (grub_rescue_parse_line): Add getline_data argument, passed to grub_parser_split_cmdline. * grub-core/script/lexer.c (grub_script_lexer_yywrap): Pass lexerstate->getline_data to lexerstate->getline. (grub_script_lexer_init): Add getline_data argument, saved in lexerstate->getline_data. * grub-core/script/main.c (grub_normal_parse_line): Add getline_data argument, passed to grub_script_parse. * grub-core/script/script.c (grub_script_parse): Add getline_data argument, passed to grub_script_lexer_init. * include/grub/parser.h (grub_parser_split_cmdline): Update prototype. Update all callers to pass appropriate getline data. (struct grub_parser.parse_line): Likewise. (grub_rescue_parse_line): Likewise. * include/grub/reader.h (grub_reader_getline_t): Add void * argument. * include/grub/script_sh.h (struct grub_lexer_param): Add getline_data member. (grub_script_parse): Update prototype. Update all callers to pass appropriate getline data. (grub_script_lexer_init): Likewise. (grub_normal_parse_line): Likewise. * grub-core/commands/legacycfg.c (legacy_file_getline): Add unused data argument. * grub-core/kern/parser.c (grub_parser_execute: getline): Make static instead of nested. Rename to ... (grub_parser_execute_getline): ... this. * grub-core/kern/rescue_reader.c (grub_rescue_read_line): Add unused data argument. * grub-core/normal/main.c (read_config_file: getline): Make static instead of nested. Rename to ... (read_config_file_getline): ... this. (grub_normal_read_line): Add unused data argument. * grub-core/script/execute.c (grub_script_execute_sourcecode: getline): Make static instead of nested. Rename to ... (grub_script_execute_sourcecode_getline): ... this. * util/grub-script-check.c (main: get_config_line): Make static instead of nested.
2013-01-15 12:03:25 +00:00
ctx.arguments.filename, strerror (errno));
argp_help (&argp, stderr, ARGP_HELP_STD_USAGE, program);
free(program);
exit(1);
2010-01-09 14:57:58 +00:00
}
}
do
{
input = 0;
Remove nested functions from script reading and parsing. * grub-core/kern/parser.c (grub_parser_split_cmdline): Add getline_data argument, passed to getline. * grub-core/kern/rescue_parser.c (grub_rescue_parse_line): Add getline_data argument, passed to grub_parser_split_cmdline. * grub-core/script/lexer.c (grub_script_lexer_yywrap): Pass lexerstate->getline_data to lexerstate->getline. (grub_script_lexer_init): Add getline_data argument, saved in lexerstate->getline_data. * grub-core/script/main.c (grub_normal_parse_line): Add getline_data argument, passed to grub_script_parse. * grub-core/script/script.c (grub_script_parse): Add getline_data argument, passed to grub_script_lexer_init. * include/grub/parser.h (grub_parser_split_cmdline): Update prototype. Update all callers to pass appropriate getline data. (struct grub_parser.parse_line): Likewise. (grub_rescue_parse_line): Likewise. * include/grub/reader.h (grub_reader_getline_t): Add void * argument. * include/grub/script_sh.h (struct grub_lexer_param): Add getline_data member. (grub_script_parse): Update prototype. Update all callers to pass appropriate getline data. (grub_script_lexer_init): Likewise. (grub_normal_parse_line): Likewise. * grub-core/commands/legacycfg.c (legacy_file_getline): Add unused data argument. * grub-core/kern/parser.c (grub_parser_execute: getline): Make static instead of nested. Rename to ... (grub_parser_execute_getline): ... this. * grub-core/kern/rescue_reader.c (grub_rescue_read_line): Add unused data argument. * grub-core/normal/main.c (read_config_file: getline): Make static instead of nested. Rename to ... (read_config_file_getline): ... this. (grub_normal_read_line): Add unused data argument. * grub-core/script/execute.c (grub_script_execute_sourcecode: getline): Make static instead of nested. Rename to ... (grub_script_execute_sourcecode_getline): ... this. * util/grub-script-check.c (main: get_config_line): Make static instead of nested.
2013-01-15 12:03:25 +00:00
get_config_line (&input, 0, &ctx);
2010-01-09 14:57:58 +00:00
if (! input)
break;
found_input = 1;
2010-01-09 14:57:58 +00:00
Remove nested functions from script reading and parsing. * grub-core/kern/parser.c (grub_parser_split_cmdline): Add getline_data argument, passed to getline. * grub-core/kern/rescue_parser.c (grub_rescue_parse_line): Add getline_data argument, passed to grub_parser_split_cmdline. * grub-core/script/lexer.c (grub_script_lexer_yywrap): Pass lexerstate->getline_data to lexerstate->getline. (grub_script_lexer_init): Add getline_data argument, saved in lexerstate->getline_data. * grub-core/script/main.c (grub_normal_parse_line): Add getline_data argument, passed to grub_script_parse. * grub-core/script/script.c (grub_script_parse): Add getline_data argument, passed to grub_script_lexer_init. * include/grub/parser.h (grub_parser_split_cmdline): Update prototype. Update all callers to pass appropriate getline data. (struct grub_parser.parse_line): Likewise. (grub_rescue_parse_line): Likewise. * include/grub/reader.h (grub_reader_getline_t): Add void * argument. * include/grub/script_sh.h (struct grub_lexer_param): Add getline_data member. (grub_script_parse): Update prototype. Update all callers to pass appropriate getline data. (grub_script_lexer_init): Likewise. (grub_normal_parse_line): Likewise. * grub-core/commands/legacycfg.c (legacy_file_getline): Add unused data argument. * grub-core/kern/parser.c (grub_parser_execute: getline): Make static instead of nested. Rename to ... (grub_parser_execute_getline): ... this. * grub-core/kern/rescue_reader.c (grub_rescue_read_line): Add unused data argument. * grub-core/normal/main.c (read_config_file: getline): Make static instead of nested. Rename to ... (read_config_file_getline): ... this. (grub_normal_read_line): Add unused data argument. * grub-core/script/execute.c (grub_script_execute_sourcecode: getline): Make static instead of nested. Rename to ... (grub_script_execute_sourcecode_getline): ... this. * util/grub-script-check.c (main: get_config_line): Make static instead of nested.
2013-01-15 12:03:25 +00:00
script = grub_script_parse (input, get_config_line, &ctx);
2010-01-09 14:57:58 +00:00
if (script)
{
grub_script_execute (script);
grub_script_free (script);
}
grub_free (input);
} while (script != 0);
Remove nested functions from script reading and parsing. * grub-core/kern/parser.c (grub_parser_split_cmdline): Add getline_data argument, passed to getline. * grub-core/kern/rescue_parser.c (grub_rescue_parse_line): Add getline_data argument, passed to grub_parser_split_cmdline. * grub-core/script/lexer.c (grub_script_lexer_yywrap): Pass lexerstate->getline_data to lexerstate->getline. (grub_script_lexer_init): Add getline_data argument, saved in lexerstate->getline_data. * grub-core/script/main.c (grub_normal_parse_line): Add getline_data argument, passed to grub_script_parse. * grub-core/script/script.c (grub_script_parse): Add getline_data argument, passed to grub_script_lexer_init. * include/grub/parser.h (grub_parser_split_cmdline): Update prototype. Update all callers to pass appropriate getline data. (struct grub_parser.parse_line): Likewise. (grub_rescue_parse_line): Likewise. * include/grub/reader.h (grub_reader_getline_t): Add void * argument. * include/grub/script_sh.h (struct grub_lexer_param): Add getline_data member. (grub_script_parse): Update prototype. Update all callers to pass appropriate getline data. (grub_script_lexer_init): Likewise. (grub_normal_parse_line): Likewise. * grub-core/commands/legacycfg.c (legacy_file_getline): Add unused data argument. * grub-core/kern/parser.c (grub_parser_execute: getline): Make static instead of nested. Rename to ... (grub_parser_execute_getline): ... this. * grub-core/kern/rescue_reader.c (grub_rescue_read_line): Add unused data argument. * grub-core/normal/main.c (read_config_file: getline): Make static instead of nested. Rename to ... (read_config_file_getline): ... this. (grub_normal_read_line): Add unused data argument. * grub-core/script/execute.c (grub_script_execute_sourcecode: getline): Make static instead of nested. Rename to ... (grub_script_execute_sourcecode_getline): ... this. * util/grub-script-check.c (main: get_config_line): Make static instead of nested.
2013-01-15 12:03:25 +00:00
if (ctx.file) fclose (ctx.file);
2010-01-09 14:57:58 +00:00
2010-12-03 03:25:57 +00:00
if (found_input && script == 0)
{
Remove nested functions from script reading and parsing. * grub-core/kern/parser.c (grub_parser_split_cmdline): Add getline_data argument, passed to getline. * grub-core/kern/rescue_parser.c (grub_rescue_parse_line): Add getline_data argument, passed to grub_parser_split_cmdline. * grub-core/script/lexer.c (grub_script_lexer_yywrap): Pass lexerstate->getline_data to lexerstate->getline. (grub_script_lexer_init): Add getline_data argument, saved in lexerstate->getline_data. * grub-core/script/main.c (grub_normal_parse_line): Add getline_data argument, passed to grub_script_parse. * grub-core/script/script.c (grub_script_parse): Add getline_data argument, passed to grub_script_lexer_init. * include/grub/parser.h (grub_parser_split_cmdline): Update prototype. Update all callers to pass appropriate getline data. (struct grub_parser.parse_line): Likewise. (grub_rescue_parse_line): Likewise. * include/grub/reader.h (grub_reader_getline_t): Add void * argument. * include/grub/script_sh.h (struct grub_lexer_param): Add getline_data member. (grub_script_parse): Update prototype. Update all callers to pass appropriate getline data. (grub_script_lexer_init): Likewise. (grub_normal_parse_line): Likewise. * grub-core/commands/legacycfg.c (legacy_file_getline): Add unused data argument. * grub-core/kern/parser.c (grub_parser_execute: getline): Make static instead of nested. Rename to ... (grub_parser_execute_getline): ... this. * grub-core/kern/rescue_reader.c (grub_rescue_read_line): Add unused data argument. * grub-core/normal/main.c (read_config_file: getline): Make static instead of nested. Rename to ... (read_config_file_getline): ... this. (grub_normal_read_line): Add unused data argument. * grub-core/script/execute.c (grub_script_execute_sourcecode: getline): Make static instead of nested. Rename to ... (grub_script_execute_sourcecode_getline): ... this. * util/grub-script-check.c (main: get_config_line): Make static instead of nested.
2013-01-15 12:03:25 +00:00
fprintf (stderr, _("Syntax error at line %u\n"), ctx.lineno);
2010-12-03 03:25:57 +00:00
return 1;
}
return 0;
2010-01-09 14:57:58 +00:00
}