#!/usr/bin/env perl
# Copyright (C) 2012 Zvi Gilboa (zgilboa@virginia.edu)
# This script is hereby released to the public domain.
# You may use or modify it at your own risk in any way you see fit.
use strict;
use warnings;

my %glyph_unicode_values;
my %glyph_names;
my %glyph_references;

my $glyph_test;
my $glyph_tex_definition;

open (SortedFontGlyphs, $ARGV[0]);
open (GlyphReferences, $ARGV[1]);

while (<SortedFontGlyphs>) {
  chomp;
  my ($glyph_unicode, $glyph_name) = split (": ", $_); # output from SortGlyphs.pl
  $glyph_unicode_values{$glyph_name} = $glyph_unicode;
  $glyph_names{$glyph_unicode} = $glyph_name;
}

while (<GlyphReferences>) {
  chomp;
  my ($glyph_unicode, $glyph_tex_reference) = split (": ", $_); # input from the user
  $glyph_references{$glyph_unicode} = $glyph_tex_reference;
}

my @sorted_glyphs = sort {
  $glyph_unicode_values{$a} <=> $glyph_unicode_values{$b}
} keys %glyph_unicode_values;

my @sorted_refs = sort { $a <=> $b } keys %glyph_references;

for my $glyph_unicode (@sorted_refs) {
    if (defined $glyph_names{$glyph_unicode} && length $glyph_names{$glyph_unicode} >0) {
      print "\\def\\Glyph$glyph_references{$glyph_unicode}\{$glyph_names{$glyph_unicode}\}\n";
    }
}

close (SortedFontGlyphs);
close (GlyphReferences);
