diff options
author | P. J. McDermott <pj@pehjota.net> | 2014-07-13 09:38:56 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2014-07-13 09:38:56 (EDT) |
commit | c29bc6055375ceb9e7e71c79b04b8adc777cf190 (patch) | |
tree | bfd2e41237db015429eedef16570e119bc7a6b57 | |
parent | 26a0741a46dbe1cdef229734e5e84d422f86c45d (diff) |
bdf2fbcon: Choose a more sensible output filename
-rwxr-xr-x | bin/bdf2fbcon | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/bin/bdf2fbcon b/bin/bdf2fbcon index 0085b19..b2d8d18 100755 --- a/bin/bdf2fbcon +++ b/bin/bdf2fbcon @@ -26,7 +26,6 @@ sub main my %opts; my %convert_opts; my $input; - my $output; Getopt::Long::Configure("no_ignore_case", "bundling", "gnu_compat", "no_getopt_compat"); @@ -73,9 +72,7 @@ sub main convert($ARGV[0], $opts{'o'}, %convert_opts); } else { for $input (@ARGV) { - $output = $input; - $output =~ s/\.bdf$/.c/; - convert($input, $output, %convert_opts); + convert($input, undef, %convert_opts); } } } @@ -133,7 +130,6 @@ sub convert { my ($input, $output, %opts) = @_; my $input_fh; - my $output_fh; my $line; my $font; @@ -148,13 +144,6 @@ sub convert error(4, "%s: %s", $input, $!); } } - if ($output eq "-") { - $output_fh = *STDOUT; - } else { - if (not open($output_fh, ">", $output . "~")) { - error(4, "%s: %s", $output . "~", $!); - } - } $font = init_font(%opts); $line = readline($input_fh); @@ -163,17 +152,12 @@ sub convert } else { error(4, "Unsupported input format"); } - write_fbcon($output_fh, $font); if ($input ne "-") { close($input_fh); } - if ($output ne "-") { - close($output_fh); - if (not rename($output . "~", $output)) { - error(4, "%s: %s", $output, $!); - } - } + + write_fbcon($output, $font); } sub init_font @@ -302,8 +286,9 @@ sub parse_bdf_2_1 sub write_fbcon { - my ($output_fh, $font) = @_; + my ($output, $font) = @_; my $bytes_x; + my $output_fh; my $i; my $char; my $j; @@ -322,6 +307,17 @@ sub write_fbcon $font->{'idx'} .= '_' . $font->{'width'} . 'x' . $font->{'height'}; $font->{'name'} .= '_' . $font->{'width'} . 'x' . $font->{'height'}; + if (not defined ($output)) { + $output = 'font_' . $font->{'id'} . '.c'; + } + if ($output eq "-") { + $output_fh = *STDOUT; + } else { + if (not open($output_fh, ">", $output . "~")) { + error(4, "%s: %s", $output . "~", $!); + } + } + for (@{$font->{'comments'}}) { printf($output_fh "/* %s */\n", $_); } @@ -362,6 +358,13 @@ sub write_fbcon printf($output_fh "\t.data\t= fontdata_%s,\n", $font->{'id'}); printf($output_fh "\t.pref\t= %d,\n", $font->{'pref'}); printf($output_fh "};\n"); + + if ($output ne "-") { + close($output_fh); + if (not rename($output . "~", $output)) { + error(4, "%s: %s", $output, $!); + } + } } main(); |