grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCHv2] dprintf implementation


From: Hollis Blanchard
Subject: Re: [PATCHv2] dprintf implementation
Date: Wed, 13 Apr 2005 22:31:40 -0500

On Feb 25, 2005, at 11:12 AM, Yoshinori K. Okuji wrote:

grub_strword ("filesystem", "file") returns 0 in your implementation.

If I write this function, I use grub_strstr and check if the previous
character and the next character are boundaries.

This is a very good idea. The standalone testcase below works for me:

int
grub_isspace (int c)
{
    return (c == '\n' || c == '\r' || c == ' ' || c == '\t');
}

int
grub_iswordseparator (int c)
{
return (grub_isspace (c) || c == ',' || c == ';' || c == '|' || c == '&');
}

int
grub_strword(const char *haystack, const char *needle)
{
    char *match;
    char *end;

    match = strstr (haystack, needle);

    if (match == NULL)
        return 0;
    if ((match > haystack) && (!grub_iswordseparator (match[-1])))
        return 0;

    end = match + strlen(needle)+1;
    if (*end && !grub_iswordseparator (*end))
        return 0;

    return 1;
}

int main(void)
{
    int i;
    char *list[][2] = {
        { "foo", "bar" },
        { "file", "file" },
        { "filesystem", "file" },
        { NULL, NULL},
    };

    for (i=0; list[i][0] != NULL; i++) {
        if (grub_strword (list[i][0], list[i][1]))
            printf ("%s/%s matched\n", list[i][0], list[i][1]);
        else
            printf ("%s/%s didn't match\n", list[i][0], list[i][1]);
    }
    return 0;
}

I would like to make sure Vincent's patch gets in soon, so that as I debug I can leave conditional debug printfs in the code where they're needed. I believe grub_strword was the only subject of conversation in his patch; are there any other comments? If so please speak up soon... :)

-Hollis





reply via email to

[Prev in Thread] Current Thread [Next in Thread]