/* 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 #include #include #include #include #include static void test_file_exists (const char *key, const char *var) { char *p; grub_file_t file; file = grub_file_open (key); if (file) { grub_printf (" %s", key); grub_file_close (file); grub_errno = GRUB_ERR_NONE; return 0; } else { grub_error (GRUB_ERR_FILE_NOT_FOUND, "File does not exists."); } } static const struct grub_arg_option options[] = { {"file", 'e', 0, "test if a file exists", 0, 0}, {0, 0, 0, 0, 0, 0} }; static grub_err_t grub_cmd_test (struct grub_arg_list *state, int argc, char **args) { const char *var = 0; if (argc == 0) return grub_error (GRUB_ERR_INVALID_COMMAND, "no argument specified"); if (state[0].set) test_file_exists (args[0], var); return grub_errno; } GRUB_MOD_INIT(test) { (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(test) { grub_unregister_command ("["); grub_unregister_command ("test"); }