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

int main ( int argc, char *argv[] )
{
	char **font_list = NULL;
	int max = 30;
	int num_ret = 0;
	Display *display = NULL;
	Font font;
	int cnt = 0;
	
	printf ("Submitted pattern: %s\n", argv[1]);
	
	display = XOpenDisplay (NULL);
	if (display==NULL)
	{
		printf ("Cannot open display\n");
		exit (1);
	}

	font_list = XListFonts (display, argv[1], max, &num_ret);
	if (!font_list)
	{
		printf ("Pattern not match\n");
		exit (0);
	}

	for (cnt=0; cnt<num_ret; cnt++)
	{
		printf ("Possible match %02d: %s\n", cnt, font_list[cnt]);
	}

	printf ("Trying to load font: %s\n", font_list[0]);

	//font = XLoadFont (display, argv[1]);
	font = XLoadFont (display, font_list[0]);
	if (!font)
	{
		printf ("Font not exist\n");
		exit (0);
	}
	printf ("Success\n");
	XUnloadFont (display,font);
	XCloseDisplay (display);
}
