All of lore.kernel.org
 help / color / mirror / Atom feed
From: adrian15 <adrian15@raulete.net>
To: grub-devel@gnu.org
Subject: test -e command for grub2
Date: Tue, 13 Jun 2006 15:00:21 +0200	[thread overview]
Message-ID: <448EB6E5.9070300@raulete.net> (raw)

[-- 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");
}


             reply	other threads:[~2006-06-13 13:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-13 13:00 adrian15 [this message]
2006-06-13 14:01 ` test -e command for grub2 Hollis Blanchard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=448EB6E5.9070300@raulete.net \
    --to=adrian15@raulete.net \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.