From 87d92227466ffb3796d1186e01a0aa2d7a5c6d2b Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sat, 29 Jun 2019 19:30:26 -0400 Subject: Define functions before use --- (limited to 'bin') diff --git a/bin/bdf2fbcon b/bin/bdf2fbcon index de01179..53ecf18 100755 --- a/bin/bdf2fbcon +++ b/bin/bdf2fbcon @@ -21,96 +21,6 @@ use constant { my $VERSION; $VERSION = '0.1.0'; -sub main -{ - my %opts; - my %convert_opts; - my $input; - - Getopt::Long::Configure("no_ignore_case", "bundling", "gnu_compat", - "no_getopt_compat"); - if (not GetOptions(\%opts, - "o=s", - "n=s", - "s=s", - "p=s", - "h|help", - "V|version", - )) { - usage(*STDERR); - exit(4); - } - - if (exists($opts{'h'})) { - help(*STDOUT); - exit(0); - } - if (exists($opts{'V'})) { - version(*STDOUT); - exit(0); - } - if (exists($opts{'n'})) { - $convert_opts{'n'} = $opts{'n'}; - } - if (exists($opts{'s'})) { - $convert_opts{'w'} = $convert_opts{'h'} = $opts{'s'}; - $convert_opts{'w'} =~ s/x.*//; - $convert_opts{'h'} =~ s/.*x//; - } - if (exists($opts{'p'})) { - $convert_opts{'p'} = $opts{'p'}; - } - - if ($#ARGV lt 0) { - error(4, "No input files\n"); - } - - if (exists($opts{'o'})) { - if ($#ARGV gt 0) { - error(4, "Cannot specify -o with multiple files\n"); - } - convert($ARGV[0], $opts{'o'}, %convert_opts); - } else { - for $input (@ARGV) { - convert($input, undef, %convert_opts); - } - } -} - -sub usage -{ - my ($fh) = @_; - - printf($fh "Usage: %s [-o ] ...\n", $0); -} - -sub help -{ - my ($fh) = @_; - - usage($fh); - print($fh "Options:\n"); - print($fh " -o Place the output into \n"); - print($fh " -n Set the font name to \n"); - print($fh " -s x Override the font size\n"); - print($fh " -p Set the font's preference to \n"); - print($fh " -h, --help Display this information\n"); - print($fh " -V, --version Display version information\n"); -} - -sub version -{ - my ($fh) = @_; - - printf($fh "bdf2fbcon %s\n", $VERSION); - print($fh "Copyright (C) 2013, 2014 Patrick \"P. J.\" McDermott\n"); - print($fh "License GPLv3+: GNU GPL version 3 or later " . - ".\n"); - print($fh "This is free software: you are free to change and " . - "redistribute it.\n"); - print($fh "There is NO WARRANTY, to the extent permitted by law.\n"); -} - sub warning { my ($fmt, @args) = @_; @@ -126,40 +36,6 @@ sub error exit($status); } -sub convert -{ - my ($input, $output, %opts) = @_; - my $input_fh; - my $line; - my $font; - - if ($input eq $output and $input ne "-") { - warning("Input and output files are equal"); - } - - if ($input eq "-") { - $input_fh = *STDIN; - } else { - if (not open($input_fh, "<", $input)) { - error(4, "%s: %s", $input, $!); - } - } - - $font = init_font(%opts); - $line = readline($input_fh); - if ($line =~ m/^STARTFONT 2.[12]$/) { - parse_bdf_2_1($input_fh, $font); - } else { - error(4, "Unsupported input format"); - } - - if ($input ne "-") { - close($input_fh); - } - - write_fbcon($output, $font); -} - sub init_font { my (%opts) = @_; @@ -372,6 +248,130 @@ sub write_fbcon } } +sub convert +{ + my ($input, $output, %opts) = @_; + my $input_fh; + my $line; + my $font; + + if ($input eq $output and $input ne "-") { + warning("Input and output files are equal"); + } + + if ($input eq "-") { + $input_fh = *STDIN; + } else { + if (not open($input_fh, "<", $input)) { + error(4, "%s: %s", $input, $!); + } + } + + $font = init_font(%opts); + $line = readline($input_fh); + if ($line =~ m/^STARTFONT 2.[12]$/) { + parse_bdf_2_1($input_fh, $font); + } else { + error(4, "Unsupported input format"); + } + + if ($input ne "-") { + close($input_fh); + } + + write_fbcon($output, $font); +} + +sub usage +{ + my ($fh) = @_; + + printf($fh "Usage: %s [-o ] ...\n", $0); +} + +sub help +{ + my ($fh) = @_; + + usage($fh); + print($fh "Options:\n"); + print($fh " -o Place the output into \n"); + print($fh " -n Set the font name to \n"); + print($fh " -s x Override the font size\n"); + print($fh " -p Set the font's preference to \n"); + print($fh " -h, --help Display this information\n"); + print($fh " -V, --version Display version information\n"); +} + +sub version +{ + my ($fh) = @_; + + printf($fh "bdf2fbcon %s\n", $VERSION); + print($fh "Copyright (C) 2013, 2014 Patrick \"P. J.\" McDermott\n"); + print($fh "License GPLv3+: GNU GPL version 3 or later " . + ".\n"); + print($fh "This is free software: you are free to change and " . + "redistribute it.\n"); + print($fh "There is NO WARRANTY, to the extent permitted by law.\n"); +} + +sub main +{ + my %opts; + my %convert_opts; + my $input; + + Getopt::Long::Configure("no_ignore_case", "bundling", "gnu_compat", + "no_getopt_compat"); + if (not GetOptions(\%opts, + "o=s", + "n=s", + "s=s", + "p=s", + "h|help", + "V|version", + )) { + usage(*STDERR); + exit(4); + } + + if (exists($opts{'h'})) { + help(*STDOUT); + exit(0); + } + if (exists($opts{'V'})) { + version(*STDOUT); + exit(0); + } + if (exists($opts{'n'})) { + $convert_opts{'n'} = $opts{'n'}; + } + if (exists($opts{'s'})) { + $convert_opts{'w'} = $convert_opts{'h'} = $opts{'s'}; + $convert_opts{'w'} =~ s/x.*//; + $convert_opts{'h'} =~ s/.*x//; + } + if (exists($opts{'p'})) { + $convert_opts{'p'} = $opts{'p'}; + } + + if ($#ARGV lt 0) { + error(4, "No input files\n"); + } + + if (exists($opts{'o'})) { + if ($#ARGV gt 0) { + error(4, "Cannot specify -o with multiple files\n"); + } + convert($ARGV[0], $opts{'o'}, %convert_opts); + } else { + for $input (@ARGV) { + convert($input, undef, %convert_opts); + } + } +} + main(); __END__ -- cgit v0.9.1