Hello, I imported regexp from gnulib into grub. Available from people/phcoder/regexp. Following changes required: common.rmk Add: pkglib_MODULES += regexp.mod regexp_mod_SOURCES = gnulib/regex.c commands/regexp.c regexp_mod_CFLAGS = $(COMMON_CFLAGS) -Wno-sign-compare -Wno-unused regexp_mod_LDFLAGS = $(COMMON_LDFLAGS) commands/regexp.c New file (attached) gnulib/regcomp.c, gnulib/regex_internal.c, gnulib/regexec.c: Copied verbatim from gnulib. gnulib/regex.c: New file (attached). Based on file from gnulib, heavily modified gnulib/regex_internal.h. Copied from gnulib following modification needed: --- /home/phcoder/repos/gnulib/lib/regex_internal.h 2009-11-19 14:02:55.406619037 +0100 +++ gnulib/regex_internal.h 2009-12-27 14:28:10.504789886 +0100 @@ -21,33 +21,6 @@ #ifndef _REGEX_INTERNAL_H #define _REGEX_INTERNAL_H 1 -#include <assert.h> -#include <ctype.h> -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#ifdef _LIBC -# include <langinfo.h> -#else -# include "localcharset.h" -#endif -#if defined HAVE_LOCALE_H || defined _LIBC -# include <locale.h> -#endif - -#include <wchar.h> -#include <wctype.h> -#include <stdint.h> -#if defined _LIBC -# include <bits/libc-lock.h> -#else -# define __libc_lock_init(NAME) do { } while (0) -# define __libc_lock_lock(NAME) do { } while (0) -# define __libc_lock_unlock(NAME) do { } while (0) -#endif - /* In case that the system doesn't have isblank(). */ #if !defined _LIBC && ! (defined isblank || (HAVE_ISBLANK && HAVE_DECL_ISBLANK)) # define isblank(ch) ((ch) == ' ' || (ch) == '\t')
include/grub/gnulib-wrap.h: New file include/grub/regex.h: Copied from gnulib. Following modification: --- /home/phcoder/repos/gnulib/lib/regex.h 2009-11-19 14:02:55.402619158 +0100 +++ include/grub/regex.h 2009-12-27 14:20:37.356524246 +0100 @@ -21,7 +21,7 @@ #ifndef _REGEX_H #define _REGEX_H 1 -#include <sys/types.h> +#include <grub/gnulib-wrap.h> /* Allow the use in C++ code. */ #ifdef __cplusplus -- Regards Vladimir 'φ-coder/phcoder' Serbinenko
/* regexp.c -- The regexp command. */ /* * GRUB -- GRand Unified Bootloader * Copyright (C) 2005,2007 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 3 of the License, or * (at your option) any later version. * * GRUB 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, see <http://www.gnu.org/licenses/>. */ #include <grub/dl.h> #include <grub/misc.h> #include <grub/mm.h> #include <grub/command.h> #include <grub/regex.h> static grub_err_t grub_cmd_regexp (grub_command_t cmd __attribute__ ((unused)), int argc, char **args) { int argn = 0; int matches = 0; regex_t regex; int ret; grub_size_t s; char *comperr; grub_err_t err; if (argc != 2) return grub_error (GRUB_ERR_BAD_ARGUMENT, "2 arguments expected"); ret = regcomp (®ex, args[0], RE_SYNTAX_GNU_AWK); if (ret) goto fail; ret = regexec (®ex, args[1], 0, 0, 0); if (!ret) { regfree (®ex); return GRUB_ERR_NONE; } fail: s = regerror (ret, ®ex, 0, 0); comperr = grub_malloc (s); if (!comperr) { regfree (®ex); return grub_errno; } regerror (ret, ®ex, comperr, s); err = grub_error (GRUB_ERR_TEST_FAILURE, "%s", comperr); regfree (®ex); grub_free (comperr); return err; } static grub_command_t cmd; GRUB_MOD_INIT(regexp) { cmd = grub_register_command ("regexp", grub_cmd_regexp, "REGEXP STRING", "Test if REGEXP matches STRING."); } GRUB_MOD_FINI(regexp) { grub_unregister_command (cmd); }
/* Extended regular expression matching and search library. Copyright (C) 2002, 2003, 2005, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Isamu Hasegawa <is...@yamato.ibm.com>. This program 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, 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include <grub/regex.h> #include "regex_internal.h" #include "regex_internal.c" #include "regcomp.c" #include "regexec.c"
/* * GRUB -- GRand Unified Bootloader * Copyright (C) 2009 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 3 of the License, or * (at your option) any later version. * * GRUB 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, see <http://www.gnu.org/licenses/>. */ #ifndef GRUB_GNULIB_WRAP_H #define GRUB_GNULIB_WRAP_H 1 #include <grub/mm.h> #include <grub/misc.h> typedef grub_size_t size_t; typedef int bool; static const bool true = 1; static const bool false = 0; #define assert(x) assert_real(__FILE__, __LINE__, x) static inline void assert_real (const char *file, int line, int cond) { if (!cond) grub_fatal ("Assertion failed at %s:%d\n", file, line); } static inline char * locale_charset (void) { return "UTF-8"; } #define MB_CUR_MAX 6 static inline void * realloc (void *ptr, grub_size_t size) { return grub_realloc (ptr, size); } static inline int toupper (int c) { return grub_toupper (c); } static inline int isspace (int c) { return grub_isspace (c); } static inline int isdigit (int c) { return grub_isdigit (c); } static inline int islower (int c) { return (c >= 'a' && c <= 'z'); } static inline int isupper (int c) { return (c >= 'A' && c <= 'Z'); } static inline int isxdigit (int c) { return (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F') || (c >= '0' && c <= '9'); } static inline int isprint (int c) { return grub_isprint (c); } static inline int iscntrl (int c) { return !grub_isprint (c); } static inline int isgraph (int c) { return grub_isprint (c) && !grub_isspace (c); } static inline int isalnum (int c) { return grub_isalpha (c) || grub_isdigit (c); } static inline int ispunct (int c) { return grub_isprint (c) && !grub_isspace (c) && !isalnum (c); } static inline int isalpha (int c) { return grub_isalpha (c); } static inline int tolower (int c) { return grub_tolower (c); } static inline grub_size_t strlen (const char *s) { return grub_strlen (s); } static inline int strcmp (const char *s1, const char *s2) { return grub_strcmp (s1, s2); } static inline void abort (void) { grub_abort (); } static inline void free (void *ptr) { grub_free (ptr); } static inline void * malloc (grub_size_t size) { return grub_malloc (size); } static inline void * calloc (grub_size_t size, grub_size_t nelem) { return grub_zalloc (size * nelem); } #define ULONG_MAX GRUB_ULONG_MAX #define UCHAR_MAX 0xff /* UCS-4. */ typedef grub_uint32_t wchar_t; #undef __libc_lock_init #define __libc_lock_init(x) #undef __libc_lock_lock #define __libc_lock_lock(x) #undef __libc_lock_unlock #define __libc_lock_unlock(x) #endif
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Grub-devel mailing list Grub-devel@gnu.org http://lists.gnu.org/mailman/listinfo/grub-devel