#include <X11/Xlib.h>
#include <stdio.h>
#include <unistd.h>

/*
 * Find iso8859-1 (latin1) fonts with other than 256 codepoints.
 *
 * You might need to "sort -u" the result of this,
 * as duplicate font entries are likely.
 */

int main(int argc, char **argv) {

    int i;
    char **fonts;
    int maxnames, actual_count_return;
    Display *display;
    XFontStruct *font_struct;

    if ((display = XOpenDisplay(NULL)) == NULL) {
        fprintf(stderr, "display == NULL\n");
        exit(1);
    }

    if (argc == 2) {
        maxnames = atoi(argv[1]);
        fprintf(stdout, "requesting to inspect %d fonts.\n", maxnames);
    } else {
        fprintf(stderr, "number of fonts requested to inspect?\n");
        exit(1);
    }

    fonts = XListFonts(display, "-*-iso8859-1", maxnames, &actual_count_return);

    if (fonts == NULL) {
        fprintf(stderr, "fonts == NULL\n");
        exit(1);
    }

    for (i=0; i<actual_count_return; i++) {
            font_struct = XLoadQueryFont(display, fonts[i]);
            if (font_struct == NULL) {
                fprintf(stderr, "font_struct == NULL\n");
                exit(1);
            }
            if (font_struct->max_char_or_byte2 != 255) {
                /* fprintf(stdout, "[%d] ", font_struct->max_char_or_byte2); */
		/* all 127 */
                fprintf(stdout, "%s\n", fonts[i]);
            }
    }
    return(0);
}

