* test -e command for grub2
@ 2006-06-13 13:00 adrian15
2006-06-13 14:01 ` Hollis Blanchard
0 siblings, 1 reply; 2+ messages in thread
From: adrian15 @ 2006-06-13 13:00 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 1091 bytes --]
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.
[-- Attachment #2: test.c --]
[-- Type: text/x-csrc, Size: 2143 bytes --]
/* 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;
}
\f
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");
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: test -e command for grub2
2006-06-13 13:00 test -e command for grub2 adrian15
@ 2006-06-13 14:01 ` Hollis Blanchard
0 siblings, 0 replies; 2+ messages in thread
From: Hollis Blanchard @ 2006-06-13 14:01 UTC (permalink / raw)
To: The development of GRUB 2
On Tue, 2006-06-13 at 15:00 +0200, adrian15 wrote:
> 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.
You haven't even compiled it? Perhaps you should install the LZO
libraries you need.
> 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?
I guess so.
> Is it better for me to use grub_gzfile_open on my test command?
Probably not, since you're just testing for existence.
> 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 ?
No, it's static.
> 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.
Google for GNU Coding Style. Then, since that document is incomplete,
you will need to mimic the style you see elsewhere in GRUB.
> P.S.: I am going to update from Knoppix 4 to Knoppix 5 soon and I think
> I won't hae the lzo problem.
Try installing the LZO development package on Knoppix 4.
-Hollis
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-06-13 14:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-06-13 13:00 test -e command for grub2 adrian15
2006-06-13 14:01 ` Hollis Blanchard
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.