test-ly-files: Display symlink creation, add `-v` to `ln`
[sunny256-utils.git] / ustr
blob9295043bc034c79c4ba92d681f07969223604ff7
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 except
8 # 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 file for
13 # 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 'delete' => 0,
27 'help' => 0,
28 'quiet' => 0,
29 'space' => 0,
30 'strikethrough' => 0,
31 'verbose' => 0,
32 'version' => 0,
36 our $progname = $0;
37 $progname =~ s/^.*\/(.*?)$/$1/;
38 our $VERSION = '0.3.1';
40 Getopt::Long::Configure('bundling');
41 GetOptions(
43 'delete|d' => \$Opt{'delete'},
44 'help|h' => \$Opt{'help'},
45 'quiet|q+' => \$Opt{'quiet'},
46 'space|S' => \$Opt{'space'},
47 'strikethrough|s' => \$Opt{'strikethrough'},
48 'verbose|v+' => \$Opt{'verbose'},
49 'version' => \$Opt{'version'},
51 ) || die("$progname: Option error. Use -h for help.\n");
53 $Opt{'verbose'} -= $Opt{'quiet'};
54 $Opt{'help'} && usage(0);
55 if ($Opt{'version'}) {
56 print_version();
57 exit(0);
60 exit(main());
62 sub main {
63 my $Retval = 0;
64 my $combchar = "\x{0332}";
65 my $space = $Opt{'space'} ? "" : " ";
67 if ($Opt{'strikethrough'}) {
68 $combchar = "\x{0336}";
70 if ($Opt{'delete'}) {
71 while (<>) {
72 s/$combchar//g;
73 print;
75 } else {
76 while (<>) {
77 s/([^\x00-\x1F$space])/$1$combchar/g;
78 print;
82 return $Retval;
85 sub print_version {
86 # Print program version
87 print("$progname $VERSION\n");
88 return;
91 sub usage {
92 # Send the help message to stdout
93 my $Retval = shift;
95 if ($Opt{'verbose'}) {
96 print("\n");
97 print_version();
99 print(<<"END");
101 Usage: $progname [options] [file [files [...]]]
103 Options:
105 -h, --help
106 Show this help.
107 -q, --quiet
108 Be more quiet. Can be repeated to increase silence.
109 -s, --strikethrough
110 Use strikethrough (U+0336, '1̶2̶3̶ a̶b̶c̶') instead of underline.
111 -v, --verbose
112 Increase level of verbosity. Can be repeated.
113 -S, --space
114 Also underline/overstrike space characters (U+0020).
115 --version
116 Print version information.
119 exit($Retval);
122 sub msg {
123 # Print a status message to stderr based on verbosity level
124 my ($verbose_level, $Txt) = @_;
126 $verbose_level > $Opt{'verbose'} && return;
127 print(STDERR "$progname: $Txt\n");
128 return;
131 __END__
133 # This program is free software; you can redistribute it and/or modify it under
134 # the terms of the GNU General Public License as published by the Free Software
135 # Foundation; either version 2 of the License, or (at your option) any later
136 # version.
138 # This program is distributed in the hope that it will be useful, but WITHOUT
139 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
140 # FOR A PARTICULAR PURPOSE.
141 # See the GNU General Public License for more details.
143 # You should have received a copy of the GNU General Public License along with
144 # this program.
145 # If not, see L<http://www.gnu.org/licenses/>.
147 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :