#!/usr/bin/perl

use strict;

my $base = '/usr/share/fonts-font-awesome/css/';
unshift @ARGV, $base . 'font-awesome.css';

sub read_font {
    my $font = shift;
    my $filename = $base . $font;
    my $data = `base64 --wrap=0 $filename`;
    return "src: url(data:application/font-woff;charset=utf-8;base64,$data) format(\"woff\");"
}

while (<>) {
    if (/src: url\("([^"]*)"\);/) {
        next;
    } elsif (/src:.*url\("([^"]*)"\) format\("woff2"\)/) {
        my $src = read_font($1);
        print($src, "\n");
        if (/}\s*$/) {
            print("}\n");
        }
        next;
    }
    print;
}
