From b541c27b8e75f3d80e56114304ba1236d13e56cf Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sat, 29 Jun 2019 19:39:00 -0400 Subject: Return, not exit, on errors --- diff --git a/bin/bdf2fbcon b/bin/bdf2fbcon index 53ecf18..5511c3c 100755 --- a/bin/bdf2fbcon +++ b/bin/bdf2fbcon @@ -26,14 +26,17 @@ sub warning my ($fmt, @args) = @_; printf(STDERR "bdf2fbcon: Warning: " . $fmt . "\n", @args); + + return; } sub error { - my ($status, $fmt, @args) = @_; + my ($fmt, @args) = @_; printf(STDERR "bdf2fbcon: Error: " . $fmt . "\n", @args); - exit($status); + + return; } sub init_font @@ -163,6 +166,8 @@ sub parse_bdf_2_1 } warning("Missing end of font") unless ($found_end); + + return 1; } sub write_fbcon @@ -195,7 +200,8 @@ sub write_fbcon $output_fh = *STDOUT; } else { if (not open($output_fh, ">", $output . "~")) { - error(4, "%s: %s", $output . "~", $!); + error("%s: %s", $output . "~", $!); + return; } } @@ -243,9 +249,12 @@ sub write_fbcon if ($output ne "-") { close($output_fh); if (not rename($output . "~", $output)) { - error(4, "%s: %s", $output, $!); + error("%s: %s", $output, $!); + return; } } + + return 1; } sub convert @@ -263,7 +272,8 @@ sub convert $input_fh = *STDIN; } else { if (not open($input_fh, "<", $input)) { - error(4, "%s: %s", $input, $!); + error("%s: %s", $input, $!); + return; } } @@ -272,14 +282,19 @@ sub convert if ($line =~ m/^STARTFONT 2.[12]$/) { parse_bdf_2_1($input_fh, $font); } else { - error(4, "Unsupported input format"); + error("Unsupported input format"); + return; } if ($input ne "-") { close($input_fh); } - write_fbcon($output, $font); + if (not write_fbcon($output, $font)) { + return; + } + + return 1; } sub usage @@ -287,6 +302,8 @@ sub usage my ($fh) = @_; printf($fh "Usage: %s [-o ] ...\n", $0); + + return; } sub help @@ -301,6 +318,8 @@ sub help 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"); + + return; } sub version @@ -314,6 +333,8 @@ sub version 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"); + + return; } sub main @@ -333,16 +354,16 @@ sub main "V|version", )) { usage(*STDERR); - exit(4); + return 4; } if (exists($opts{'h'})) { help(*STDOUT); - exit(0); + return 0; } if (exists($opts{'V'})) { version(*STDOUT); - exit(0); + return 0; } if (exists($opts{'n'})) { $convert_opts{'n'} = $opts{'n'}; @@ -357,22 +378,30 @@ sub main } if ($#ARGV lt 0) { - error(4, "No input files\n"); + error("No input files\n"); + return 4; } if (exists($opts{'o'})) { if ($#ARGV gt 0) { - error(4, "Cannot specify -o with multiple files\n"); + error("Cannot specify -o with multiple files\n"); + return 4; + } + if (not convert($ARGV[0], $opts{'o'}, %convert_opts)) { + return 4; } - convert($ARGV[0], $opts{'o'}, %convert_opts); } else { for $input (@ARGV) { - convert($input, undef, %convert_opts); + if (not convert($input, undef, %convert_opts)) { + return 4; + } } } + + return 0; } -main(); +exit(main()); __END__ -- cgit v0.9.1