vaseboot/VasEBoot-core/commands/eval.c

72 lines
1.8 KiB
C

/*
* VasEBoot -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* VasEBoot 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.
*
* VasEBoot 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 VasEBoot. If not, see <http://www.gnu.org/licenses/>.
*/
#include <VasEBoot/dl.h>
#include <VasEBoot/misc.h>
#include <VasEBoot/script_sh.h>
#include <VasEBoot/command.h>
#include <VasEBoot/i18n.h>
#include <VasEBoot/term.h>
VasEBoot_MOD_LICENSE ("GPLv3+");
static VasEBoot_err_t
VasEBoot_cmd_eval (VasEBoot_command_t cmd __attribute__((__unused__)),
int argc, char *argv[])
{
int i;
VasEBoot_size_t size = argc; /* +1 for final zero */
char *str, *p;
VasEBoot_err_t ret;
if (argc == 0)
return VasEBoot_ERR_NONE;
for (i = 0; i < argc; i++)
size += VasEBoot_strlen (argv[i]);
str = p = VasEBoot_malloc (size);
if (!str)
return VasEBoot_errno;
for (i = 0; i < argc; i++)
{
p = VasEBoot_stpcpy (p, argv[i]);
*p++ = ' ';
}
*--p = '\0';
ret = VasEBoot_script_execute_sourcecode (str);
VasEBoot_free (str);
return ret;
}
static VasEBoot_command_t cmd;
VasEBoot_MOD_INIT(eval)
{
cmd = VasEBoot_register_command ("eval", VasEBoot_cmd_eval, N_("STRING ..."),
N_("Evaluate arguments as VasEBoot commands"));
}
VasEBoot_MOD_FINI(eval)
{
VasEBoot_unregister_command (cmd);
}