std sh til-kron
[sunny256-utils.git] / txt2grave
blob27f0cb8bbe97dc3e92b69614a29a8fa6dd04122f
1 #!/usr/bin/env perl
3 #==============================================================================
4 # txt2grave
5 # File ID: bbc53b64-0648-11ee-88e1-83850402c3ce
7 # [Description]
9 # Character set: UTF-8
10 # ©opyleft 2023– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of file for
12 # legal stuff.
13 #==============================================================================
15 use strict;
16 use warnings;
17 use Getopt::Long;
19 local $| = 1;
21 our %Opt = (
23 'help' => 0,
24 'quiet' => 0,
25 'verbose' => 0,
26 'version' => 0,
30 our $progname = $0;
31 $progname =~ s/^.*\/(.*?)$/$1/;
32 our $VERSION = '0.0.0';
34 Getopt::Long::Configure('bundling');
35 GetOptions(
37 'help|h' => \$Opt{'help'},
38 'quiet|q+' => \$Opt{'quiet'},
39 'verbose|v+' => \$Opt{'verbose'},
40 'version' => \$Opt{'version'},
42 ) || die("$progname: Option error. Use -h for help.\n");
44 $Opt{'verbose'} -= $Opt{'quiet'};
45 $Opt{'help'} && usage(0);
46 if ($Opt{'version'}) {
47 print_version();
48 exit(0);
51 exit(main());
53 sub main {
54 my $Retval = 0;
56 while (<>) {
57 if (!length($_)) {
58 print;
59 next;
61 s/\\/\\\\/g;
62 s/\`/\\\`/g;
63 s/^( +)/tograve($1)/ge;
64 s/^/\`/;
65 s/$/\`\\/;
66 print;
69 return $Retval;
72 sub tograve {
73 my $txt = shift;
74 $txt =~ s/ / /g;
75 return $txt;
78 sub print_version {
79 # Print program version
80 print("$progname $VERSION\n");
81 return;
84 sub usage {
85 # Send the help message to stdout
86 my $Retval = shift;
88 if ($Opt{'verbose'}) {
89 print("\n");
90 print_version();
92 print(<<"END");
94 Usage: $progname [options] [file [files [...]]]
96 Options:
98 -h, --help
99 Show this help.
100 -q, --quiet
101 Be more quiet. Can be repeated to increase silence.
102 -v, --verbose
103 Increase level of verbosity. Can be repeated.
104 --version
105 Print version information.
108 exit($Retval);
111 sub msg {
112 # Print a status message to stderr based on verbosity level
113 my ($verbose_level, $Txt) = @_;
115 $verbose_level > $Opt{'verbose'} && return;
116 print(STDERR "$progname: $Txt\n");
117 return;
120 __END__
122 # This program is free software; you can redistribute it and/or modify it under
123 # the terms of the GNU General Public License as published by the Free Software
124 # Foundation; either version 2 of the License, or (at your option) any later
125 # version.
127 # This program is distributed in the hope that it will be useful, but WITHOUT
128 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
129 # FOR A PARTICULAR PURPOSE.
130 # See the GNU General Public License for more details.
132 # You should have received a copy of the GNU General Public License along with
133 # this program.
134 # If not, see L<http://www.gnu.org/licenses/>.
136 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :