daac212ae3
Add initial scripting support. * commands/test.c: New file. * include/grub/script.h: Likewise. * normal/execute.c: Likewise. * normal/function.c: Likewise. * normal/lexer.c: Likewise. * normal/parser.y: Likewise. * normal/script.c: Likewise. * configure.ac: Add `AC_PROG_YACC' test. * conf/i386-pc.rmk (grub_emu_SOURCES): Add `commands/test.c', `normal/execute.c', `normal/lexer.c', `grub_script.tab.c', `normal/function.c' and `normal/script.c'. (normal_mod_SOURCES): `normal/execute.c', `normal/lexer.c', `grub_script.tab.c', `normal/function.c' and `normal/script.c'. (test_mod_SOURCES, test_mod_CFLAGS, test_mod_LDFLAGS): New variables. (pkgdata_MODULES): Add `test.mod'. (grub_script.tab.c): New rule. (grub_script.tab.h): Likewise. * include/grub/err.h (grub_err_t): Add `GRUB_ERR_TEST_FAILURE'. * include/grub/normal.h (grub_test_init): New prototype. (grub_test_fini): Likewise. * normal/command.c: Include <grub/script.h>. (grub_command_execute): Rewritten. * util/grub-emu.c (main): Call `grub_test_init' and `grub_test_fini'.
89 lines
2.3 KiB
C
89 lines
2.3 KiB
C
/* test.c -- The test command.. */
|
||
/*
|
||
* GRUB -- GRand Unified Bootloader
|
||
* Copyright (C) 2005 Free Software Foundation, Inc.
|
||
*
|
||
* 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 2 of the License, or
|
||
* (at your option) any later version.
|
||
*
|
||
* This program 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, write to the Free Software
|
||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||
*/
|
||
|
||
#include <grub/normal.h>
|
||
#include <grub/dl.h>
|
||
#include <grub/arg.h>
|
||
#include <grub/misc.h>
|
||
#include <grub/mm.h>
|
||
#include <grub/env.h>
|
||
|
||
static grub_err_t
|
||
grub_cmd_test (struct grub_arg_list *state __attribute__ ((unused)), int argc,
|
||
char **args)
|
||
|
||
{
|
||
char *eq;
|
||
char *eqis;
|
||
|
||
/* XXX: No fancy expression evaluation yet. */
|
||
|
||
if (argc == 0)
|
||
return 0;
|
||
|
||
eq = grub_strdup (args[0]);
|
||
eqis = grub_strchr (eq, '=');
|
||
if (! eqis)
|
||
return 0;
|
||
|
||
*eqis = '\0';
|
||
eqis++;
|
||
/* Check an expression in the form `A=B'. */
|
||
if (grub_strcmp (eq, eqis))
|
||
grub_error (GRUB_ERR_TEST_FAILURE, "false");
|
||
grub_free (eq);
|
||
|
||
return grub_errno;
|
||
}
|
||
|
||
|
||
|
||
#ifdef GRUB_UTIL
|
||
void
|
||
grub_test_init (void)
|
||
{
|
||
grub_register_command ("[", grub_cmd_test, GRUB_COMMAND_FLAG_CMDLINE,
|
||
"[ EXPRESSION ]", "Evaluate an expression", 0);
|
||
grub_register_command ("test", grub_cmd_test, GRUB_COMMAND_FLAG_CMDLINE,
|
||
"test EXPRESSION", "Evaluate an expression", 0);
|
||
}
|
||
|
||
void
|
||
grub_test_fini (void)
|
||
{
|
||
grub_unregister_command ("[");
|
||
grub_unregister_command ("test");
|
||
}
|
||
#else /* ! GRUB_UTIL */
|
||
GRUB_MOD_INIT
|
||
{
|
||
(void)mod; /* To stop warning. */
|
||
grub_register_command ("[", grub_cmd_test, GRUB_COMMAND_FLAG_CMDLINE,
|
||
"[ EXPRESSION ]", "Evaluate an expression", 0);
|
||
grub_register_command ("test", grub_cmd_test, GRUB_COMMAND_FLAG_CMDLINE,
|
||
"test EXPRESSION", "Evaluate an expression", 0);
|
||
}
|
||
|
||
GRUB_MOD_FINI
|
||
{
|
||
grub_unregister_command ("[");
|
||
grub_unregister_command ("test");
|
||
}
|
||
#endif /* ! GRUB_UTIL */
|