From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Fq8Wd-0003iu-F9 for mharc-grub-devel@gnu.org; Tue, 13 Jun 2006 09:01:43 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Fq8Wa-0003hz-Jq for grub-devel@gnu.org; Tue, 13 Jun 2006 09:01:40 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Fq8WY-0003f6-Ft for grub-devel@gnu.org; Tue, 13 Jun 2006 09:01:39 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Fq8WX-0003es-8A for grub-devel@gnu.org; Tue, 13 Jun 2006 09:01:37 -0400 Received: from [193.144.10.29] (helo=relay2.udl.es) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1Fq8fT-0001sg-Hz for grub-devel@gnu.org; Tue, 13 Jun 2006 09:10:52 -0400 Received: from jupiter.udl.net (jupiter.udl.net [172.16.2.2]) by relay2.udl.es (8.13.6/8.13.4) with ESMTP id k5DD0wuv004997 for ; Tue, 13 Jun 2006 15:01:22 +0200 Received: from [172.16.2.145] (eup34_16 [172.16.2.145]) by jupiter.udl.net (8.11.7p1+Sun/8.11.6) with ESMTP id k5DD0Lq12436 for ; Tue, 13 Jun 2006 15:00:23 +0200 (MET DST) Message-ID: <448EB6E5.9070300@raulete.net> Date: Tue, 13 Jun 2006 15:00:21 +0200 From: adrian15 User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 To: grub-devel@gnu.org Content-Type: multipart/mixed; boundary="------------010001060407020700000508" X-Virus-Scanned: ClamAV 0.88.2/1537/Tue Jun 13 13:24:06 2006 on relay2.udl.es X-Virus-Status: Clean Subject: test -e command for grub2 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Jun 2006 13:01:41 -0000 This is a multi-part message in MIME format. --------------010001060407020700000508 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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. --------------010001060407020700000508 Content-Type: text/x-csrc; name="test.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="test.c" /* 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"); } --------------010001060407020700000508--