I attach then new test.c for grub2. (I worked from Grub 1.94 version).
It only implements the test -e feature.
I haven't been able to check it. ./configure says something about a LZO
version.
1) Why cat uses the file = grub_gzfile_open (args[0], 1); sentence to
check if a file can be opened or not? Is it cat supposed to cat also
gzipped files?
Is it better for me to use grub_gzfile_open on my test command?
2) I've done this:
static const struct grub_arg_option options[] =
{
{"file", 'e', 0, "test if a file exists", 0, 0},
{0, 0, 0, 0, 0, 0}
};
copying-pasting from search.c but I do not understand it too much... if
this is repeated in test.c and search.c the compiler should complain...
isn't it ?
3) And you're free to tell to only attach patchs instead of the full
file... and you're free to tell me an url for a gnu c syntax or
convention as far as I do not know if the gnu project has any. And, of
course, tell me if it compiles or not.
adrian15
P.S.: I am going to update from Knoppix 4 to Knoppix 5 soon and I think
I won't hae the lzo problem.
/* 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 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");
}
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel