#!/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_name;

my $anchor_name;
my $anchor_type;
my $anchor_shift_x;
my $anchor_shift_y;

open (GlyphAnchorInfo, $ARGV[0]);
$glyph_name = $ARGV[1];

print "\% $glyph_name\n";

$anchor_name        = '';
$anchor_type        = '';
$anchor_shift_x     = '';
$anchor_shift_y     = '';

while (<GlyphAnchorInfo>) {
    chomp;
    ($anchor_name, $anchor_type, $anchor_shift_x, $anchor_shift_y) = split (",", $_);

    if (defined $anchor_name && length $anchor_name > 0) {
        if ($anchor_type ne 'mark') {
            if ($anchor_name eq 'DiaToBase1') {
                print "\\ResetKernWithOffset\{$glyph_name\}\{\\GlyphSchwa\}\{\\neg\{$anchor_shift_x\}\}\{\\GlyphSchwaCorrection\}\n" ;
                print "\\ResetKernWithOffset\{$glyph_name\}\{\\GlyphHiriq\}\{\\neg\{$anchor_shift_x\}\}\{\\GlyphHiriqCorrection\}\n" ;
            }

            elsif ($anchor_name eq 'DiaToBase2') {
                print "\\ResetKernWithOffset\{$glyph_name\}\{\\GlyphTsere\}\{\\neg\{$anchor_shift_x\}\}\{\\GlyphTsereCorrection\}\n" ;
                print "\\ResetKernWithOffset\{$glyph_name\}\{\\GlyphSegol\}\{\\neg\{$anchor_shift_x\}\}\{\\GlyphSegolCorrection\}\n" ;
                print "\\ResetKernWithOffset\{$glyph_name\}\{\\GlyphPatah\}\{\\neg\{$anchor_shift_x\}\}\{\\GlyphPatahCorrection\}\n" ;
                print "\\ResetKernWithOffset\{$glyph_name\}\{\\GlyphQamats\}\{\\neg\{$anchor_shift_x\}\}\{\\GlyphQamatsCorrection\}\n" ;
                print "\\ResetKernWithOffset\{$glyph_name\}\{\\GlyphQamatsQatan\}\{\\neg\{$anchor_shift_x\}\}\{\\GlyphQamatsQatanCorrection\}\n" ;
            }

            elsif ($anchor_name eq 'DiaToBase3') {
                print "\\ResetKernWithOffset\{$glyph_name\}\{\\GlyphHatafSegol\}\{\\neg\{$anchor_shift_x\}\}\{\\GlyphHatafSegolCorrection\}\n" ;
                print "\\ResetKernWithOffset\{$glyph_name\}\{\\GlyphHatafPatah\}\{\\neg\{$anchor_shift_x\}\}\{\\GlyphHatafPatahCorrection\}\n" ;
                print "\\ResetKernWithOffset\{$glyph_name\}\{\\GlyphHatafQamats\}\{\\neg\{$anchor_shift_x\}\}\{\\GlyphHatafQamatsCorrection\}\n" ;
            }

            elsif ($anchor_name eq 'DiaToBaseU') {
                print "\\ResetKernWithOffset\{$glyph_name\}\{\\GlyphQubuts\}\{\\neg\{$anchor_shift_x\}\}\{\\GlyphQubutsCorrection\}\n" ;
            }

            elsif ($anchor_name eq 'DiaToBaseO') {
                print "\\ResetKernWithOffset\{$glyph_name\}\{\\GlyphHolam\}\{\\neg\{$anchor_shift_x\}\}\{\\GlyphHolamCorrection\}\n" ;
            }            

            elsif ($anchor_name eq 'DiaToBaseD') {
                print "\\ResetKernWithOffset\{$glyph_name\}\{\\GlyphDagesh\}\{\\neg\{$anchor_shift_x\}\}\{\\GlyphDageshCorrection\}\n" ;
            }            
        }
    }
}

print "\n";

close (GlyphAnchorInfo);
