diff -urN grub2_2007_05_31_original/commands/test.c grub2_2007_05_31/commands/test.c --- grub2_2007_05_31_original/commands/test.c 2005-11-13 16:47:08.000000000 +0100 +++ grub2_2007_05_31/commands/test.c 2007-06-01 12:13:11.000000000 +0200 @@ -24,32 +24,64 @@ #include #include #include +#include + +static const struct grub_arg_option options[] = + { + {"file", 'e', 0, "Test if a file exists", 0, 0}, + {0, 0, 0, 0, 0, 0} + }; + +static void +test_file_exists (const char *key) +{ + grub_file_t file; + + file = grub_file_open (key); + if (file) + { + grub_printf (" %s", key); + grub_file_close (file); + grub_errno = GRUB_ERR_NONE; + } + else + { + grub_error (GRUB_ERR_FILE_NOT_FOUND, "File does not exists."); + } +} + 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 (state[0].set) + test_file_exists (args[0]); + else + { + /* XXX: No fancy expression evaluation yet. */ - if (argc == 0) - return 0; + 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); + } - 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; }