summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-06-29 19:30:26 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-06-29 19:30:26 (EDT)
commit87d92227466ffb3796d1186e01a0aa2d7a5c6d2b (patch)
tree5e9adf1452e9a8d1b3059413a7f73e9400d2f577
parent0aaf1f20817cace6162a12ead9d74f99d38dff6a (diff)
Define functions before use
-rwxr-xr-xbin/bdf2fbcon248
1 files changed, 124 insertions, 124 deletions
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 <output>] <input> ...\n", $0);
-}
-
-sub help
-{
- my ($fh) = @_;
-
- usage($fh);
- print($fh "Options:\n");
- print($fh " -o <output> Place the output into <output>\n");
- print($fh " -n <name> Set the font name to <name>\n");
- print($fh " -s <w>x<h> Override the font size\n");
- print($fh " -p <pref> Set the font's preference to <pref>\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 " .
- "<http://gnu.org/licenses/gpl.html>.\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 <output>] <input> ...\n", $0);
+}
+
+sub help
+{
+ my ($fh) = @_;
+
+ usage($fh);
+ print($fh "Options:\n");
+ print($fh " -o <output> Place the output into <output>\n");
+ print($fh " -n <name> Set the font name to <name>\n");
+ print($fh " -s <w>x<h> Override the font size\n");
+ print($fh " -p <pref> Set the font's preference to <pref>\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 " .
+ "<http://gnu.org/licenses/gpl.html>.\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__