Merge branch 'add-datefmt'
[sunny256-utils.git] / ustr
blob74ccfd39dccdea5a481bacb6523f4b206c2519f7
1 #!/usr/bin/env perl
3 #=======================================================================
4 # ustr
5 # File ID: 3c899bbc-5d49-11df-b62a-90e6ba3022ac
7 # Inserts a COMBINING LOW LINE (U+0332, "◌̲") after every character
8 # except newline (\n).
10 # Character set: UTF-8
11 # ©opyleft 2004– Øyvind A. Holm <sunny@sunbase.org>
12 # License: GNU General Public License version 2 or later, see end of
13 # file for legal stuff.
14 #=======================================================================
16 use strict;
17 use warnings;
18 use utf8;
19 use Getopt::Long;
20 use open ':std', ':encoding(UTF-8)';
22 local $| = 1;
24 our %Opt = (
26 'help' => 0,
27 'quiet' => 0,
28 'strikethrough' => 0,
29 'verbose' => 0,
30 'version' => 0,
34 our $progname = $0;
35 $progname =~ s/^.*\/(.*?)$/$1/;
36 our $VERSION = '0.1.0';
38 Getopt::Long::Configure('bundling');
39 GetOptions(
41 'help|h' => \$Opt{'help'},
42 'quiet|q+' => \$Opt{'quiet'},
43 'strikethrough|s' => \$Opt{'strikethrough'},
44 'verbose|v+' => \$Opt{'verbose'},
45 'version' => \$Opt{'version'},
47 ) || die("$progname: Option error. Use -h for help.\n");
49 $Opt{'verbose'} -= $Opt{'quiet'};
50 $Opt{'help'} && usage(0);
51 if ($Opt{'version'}) {
52 print_version();
53 exit(0);
56 exit(main());
58 sub main {
59 # {{{
60 my $Retval = 0;
61 my $combchar = "\x{0332}";
63 if ($Opt{'strikethrough'}) {
64 $combchar = "\x{0336}";
66 while (<>) {
67 s/([^\n])/$1$combchar/g;
68 print;
71 return $Retval;
72 # }}}
73 } # main()
75 sub print_version {
76 # Print program version {{{
77 print("$progname $VERSION\n");
78 return;
79 # }}}
80 } # print_version()
82 sub usage {
83 # Send the help message to stdout {{{
84 my $Retval = shift;
86 if ($Opt{'verbose'}) {
87 print("\n");
88 print_version();
90 print(<<"END");
92 Usage: $progname [options] [file [files [...]]]
94 Options:
96 -h, --help
97 Show this help.
98 -q, --quiet
99 Be more quiet. Can be repeated to increase silence.
100 -s, --strikethrough
101 Use strikethrough (U+0336, '1̶2̶3̶ ̶a̶b̶c̶') instead of underline.
102 -v, --verbose
103 Increase level of verbosity. Can be repeated.
104 --version
105 Print version information.
108 exit($Retval);
109 # }}}
110 } # usage()
112 sub msg {
113 # Print a status message to stderr based on verbosity level {{{
114 my ($verbose_level, $Txt) = @_;
116 if ($Opt{'verbose'} >= $verbose_level) {
117 print(STDERR "$progname: $Txt\n");
119 return;
120 # }}}
121 } # msg()
123 __END__
125 # This program is free software; you can redistribute it and/or modify
126 # it under the terms of the GNU General Public License as published by
127 # the Free Software Foundation; either version 2 of the License, or (at
128 # your option) any later version.
130 # This program is distributed in the hope that it will be useful, but
131 # WITHOUT ANY WARRANTY; without even the implied warranty of
132 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
133 # See the GNU General Public License for more details.
135 # You should have received a copy of the GNU General Public License
136 # along with this program.
137 # If not, see L<http://www.gnu.org/licenses/>.
139 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :