#include <simulate.h>
array sizes=({ 32,64 });


array get_font_list()
{
  array fonts =  popen("xlsfonts | grep '.*-0-0-.-0-iso8859-2'")/"\n";
  string font;
  array res = ({ });
  foreach(fonts, font)
  {
    string fndry, fmly, wght, slant, sWdth, spc, slant, encoding;
    if(!strlen(font)) continue;
    if(sscanf(font, "-%s-%s-%s-%s-normal-%*[^-]-0-0-0-0-%s-0-%s", 
              fndry, fmly, wght, slant, spc, encoding) != 7)
    {
      perror("Not used: '"+font+"'\n");
    }
    else if(!strlen(fndry))
    {
      perror("Odd foundry.\n");
    } else {
      res += ({ ({ "-"+fndry+"-"+fmly+"-"+wght+"-"+slant+"-normal"
		     "-*-%d-*-*-*-"+spc+"-*-"+encoding,
		     replace(fndry+"_"+fmly+"-"+wght+"-"+slant," ","_"),
		     }) });
    }
  }
  return res;
}

array fonts = get_font_list();

#define SCALE 8

void main()
{
  int size;
  array font;
  foreach(sizes, size)
  {
    foreach(fonts, font)
    {
      mkdir("fonts/");
      mkdir("fonts/"+size);
      perror("Generating "+sprintf(font[0],size*SCALE)+"... ("+size+"/"+font[1]+")\n");
      popen("/usr/proc/bin/ptime ./xdumpfont '"+sprintf(font[0],size*SCALE)+"'");
      mv("font", "fonts/"+size+"/"+font[1]);
    }
  }
}
