To avoid duplication, why not define

    static int charicmp(char c1, char c2)
    {
        if ('A' <= c1 && c1 <= 'Z') c1 += 'a' - 'A';
        if ('A' <= c2 && c2 <= 'Z') c2 += 'a' - 'A';
        return c1 - c2;
    }

or simpler just use `toupper(c1) - toupper(c2)` inline.