2005-05-08 Vincent Pelletier <subdino2004@yahoo.fr>

* include/grub/misc.h (grub_dprintf): New macro.
	(grub_real_dprintf): New prototype.
	(grub_strword): Likewise.
	(grub_iswordseparator): Likewise.
	* kern/misc.c (grub_real_dprintf): New function.
	(grub_strword): Likewise.
	(grub_iswordseparator): Likewise.
This commit is contained in:
hollisb 2005-05-09 01:47:37 +00:00
parent f4c5e67ca4
commit 708b345f74
3 changed files with 77 additions and 0 deletions

View file

@ -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)
{
@ -237,6 +254,49 @@ grub_strrchr (const char *s, int c)
return p;
}
int
grub_strword (const char *haystack, const char *needle)
{
const char *n_pos = needle;
while (grub_iswordseparator (*haystack))
haystack++;
while (*haystack)
{
/* Crawl both the needle and the haystack word we're on. */
while(*haystack && !grub_iswordseparator (*haystack)
&& *haystack == *n_pos)
{
haystack++;
n_pos++;
}
/* If we reached the end of both words at the same time, the word
is found. If not, eat everything in the haystack that isn't the
next word (or the end of string) and "reset" the needle. */
if ( (!*haystack || grub_iswordseparator (*haystack))
&& (!*n_pos || grub_iswordseparator (*n_pos)))
return 1;
else
{
n_pos = needle;
while (*haystack && !grub_iswordseparator (*haystack))
haystack++;
while (grub_iswordseparator (*haystack))
haystack++;
}
}
return 0;
}
int
grub_iswordseparator (int c)
{
return (grub_isspace (c) || c == ',' || c == ';' || c == '|' || c == '&');
}
int
grub_isspace (int c)
{