Index: include/grub/misc.h =================================================================== RCS file: /cvsroot/grub/grub2/include/grub/misc.h,v retrieving revision 1.12 diff -u -p -r1.12 misc.h --- include/grub/misc.h 29 Jan 2005 22:01:53 -0000 1.12 +++ include/grub/misc.h 25 Feb 2005 07:28:31 -0000 @@ -26,6 +26,7 @@ #include #include +#define grub_dprintf(condition, fmt, args...) grub_real_dprintf(__FILE__, __LINE__, condition, fmt, args); /* XXX: If grub_memmove is too slow, we must implement grub_memcpy. */ #define grub_memcpy(d,s,n) grub_memmove ((d), (s), (n)) @@ -46,6 +47,8 @@ int EXPORT_FUNC(grub_strncmp) (const cha int EXPORT_FUNC(grub_strncasecmp) (const char *s1, const char *s2, int c); char *EXPORT_FUNC(grub_strchr) (const char *s, int c); char *EXPORT_FUNC(grub_strrchr) (const char *s, int c); +int EXPORT_FUNC(grub_strword) (const char *s, const char *w); +int EXPORT_FUNC(grub_iswordseparator) (int c); int EXPORT_FUNC(grub_isspace) (int c); int EXPORT_FUNC(grub_isprint) (int c); int EXPORT_FUNC(grub_isalpha) (int c); @@ -58,6 +61,10 @@ char *EXPORT_FUNC(grub_strndup) (const c void *EXPORT_FUNC(grub_memset) (void *s, int c, grub_size_t n); grub_size_t EXPORT_FUNC(grub_strlen) (const char *s); int EXPORT_FUNC(grub_printf) (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); +void EXPORT_FUNC(grub_real_dprintf) (const char *file, + const int line, + const char *condition, + const char *fmt, ...) __attribute__ ((format (printf, 4, 5))); int EXPORT_FUNC(grub_vprintf) (const char *fmt, va_list args); int EXPORT_FUNC(grub_sprintf) (char *str, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); int EXPORT_FUNC(grub_vsprintf) (char *str, const char *fmt, va_list args); Index: kern/misc.c =================================================================== RCS file: /cvsroot/grub/grub2/kern/misc.c,v retrieving revision 1.18 diff -u -p -r1.18 misc.c --- kern/misc.c 19 Feb 2005 20:56:07 -0000 1.18 +++ kern/misc.c 25 Feb 2005 07:28:32 -0000 @@ -128,6 +128,23 @@ grub_printf (const char *fmt, ...) return ret; } +void +grub_real_dprintf(const char *file, const int line, const char *condition, + const char *fmt, ...) +{ + va_list args; + const char *debug = grub_env_get ("debug"); + if (! debug) + return; + if (grub_strword (debug, "all") || grub_strword (debug, condition)) + { + grub_printf ("%s,%d : ", file, line); + va_start (args, fmt); + grub_vprintf (fmt, args); + va_end (args); + } +} + int grub_vprintf (const char *fmt, va_list args) { @@ -238,6 +255,48 @@ grub_strrchr (const char *s, int c) } int +grub_strword (const char *s, const char *w) +{ + const char *a, *b; + + a = s; + b = w; + /* Find the begining of a word. */ + while (grub_iswordseparator (*a)) + a++; + while (*a) + { + while(*a && ! grub_iswordseparator (*a) && *a == *b) + { + a++; + b++; + } + /* If both are outside of a word at the same time, the word is found. */ + if ( (! *a || grub_iswordseparator (*a)) + && (! *b || grub_iswordseparator (*b))) + return 1; + else + { + b = w; + /* Find the end of the current word. */ + while (*a && ! grub_iswordseparator (*a)) + a++; + /* Skip separators. */ + while (grub_iswordseparator (*a)) + a++; + } + } + + return 0; +} + +int +grub_iswordseparator (int c) +{ + return (grub_isspace (c) || c == ',' || c == ';' || c == '|' || c == '&'); +} + +int grub_isspace (int c) { return (c == '\n' || c == '\r' || c == ' ' || c == '\t');