Upgrade yt-dlp from version stable@2023.07.06 to stable@2023.09.24
[sunny256-utils.git] / href
blob5919ad3b3be507decf49284d750d58d46a4df080
1 #!/usr/bin/env perl
3 #=======================================================================
4 # href
5 # File ID: 775685f4-9acf-11e2-a914-0016d364066c
6 # [Description]
8 # Character set: UTF-8
9 # ©opyleft 2013– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
14 use strict;
15 use warnings;
16 use Getopt::Long;
18 local $| = 1;
20 our $Debug = 0;
22 our %Opt = (
24 'debug' => 0,
25 'help' => 0,
26 'verbose' => 0,
27 'version' => 0,
28 'zero' => 0,
32 our $progname = $0;
33 $progname =~ s/^.*\/(.*?)$/$1/;
34 our $VERSION = '0.00';
36 Getopt::Long::Configure('bundling');
37 GetOptions(
39 'debug' => \$Opt{'debug'},
40 'help|h' => \$Opt{'help'},
41 'verbose|v+' => \$Opt{'verbose'},
42 'version' => \$Opt{'version'},
43 'zero|z' => \$Opt{'zero'},
45 ) || die("$progname: Option error. Use -h for help.\n");
47 $Opt{'debug'} && ($Debug = 1);
48 $Opt{'help'} && usage(0);
49 if ($Opt{'version'}) {
50 print_version();
51 exit(0);
54 exit(main(%Opt));
56 sub main {
57 # {{{
58 my %Opt = @_;
59 my $Retval = 0;
61 $Opt{'zero'} && ($/ = "\x00");
63 while (my $fname = <>) {
64 chomp($fname);
65 printf("<a href=\"%s\">%s</a><br />\n",
66 txt2html($fname), txt2html($fname));
69 return($Retval);
70 # }}}
71 } # main()
73 sub txt2html {
74 # {{{
75 my $str = shift;
76 $str =~ s/&/&amp;/g;
77 $str =~ s/</&lt;/g;
78 $str =~ s/>/&gt;/g;
79 $str =~ s/"/&quot;/g;
80 return($str);
81 # }}}
82 } # txt2html()
84 sub print_version {
85 # Print program version {{{
86 print("$progname v$VERSION\n");
87 return;
88 # }}}
89 } # print_version()
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 Read filenames from stdin or files specified on the command line and
102 turn them into <a href="FILE">FILE</a><br />.
104 Usage: $progname [options] [file [files [...]]]
106 Options:
108 -h, --help
109 Show this help.
110 -v, --verbose
111 Increase level of verbosity. Can be repeated.
112 -z, --zero
113 Filenames are separated with a null byte instead of linefeed.
114 --version
115 Print version information.
116 --debug
117 Print debugging messages.
120 exit($Retval);
121 # }}}
122 } # usage()
124 sub msg {
125 # Print a status message to stderr based on verbosity level {{{
126 my ($verbose_level, $Txt) = @_;
128 if ($Opt{'verbose'} >= $verbose_level) {
129 print(STDERR "$progname: $Txt\n");
131 return;
132 # }}}
133 } # msg()
135 sub D {
136 # Print a debugging message {{{
137 $Debug || return;
138 my @call_info = caller;
139 chomp(my $Txt = shift);
140 my $File = $call_info[1];
141 $File =~ s#\\#/#g;
142 $File =~ s#^.*/(.*?)$#$1#;
143 print(STDERR "$File:$call_info[2] $$ $Txt\n");
144 return('');
145 # }}}
146 } # D()
148 __END__
150 # Plain Old Documentation (POD) {{{
152 =pod
154 =head1 NAME
158 =head1 SYNOPSIS
160 [options] [file [files [...]]]
162 =head1 DESCRIPTION
166 =head1 OPTIONS
168 =over 4
170 =item B<-h>, B<--help>
172 Print a brief help summary.
174 =item B<-v>, B<--verbose>
176 Increase level of verbosity. Can be repeated.
178 =item B<--version>
180 Print version information.
182 =item B<--debug>
184 Print debugging messages.
186 =back
188 =head1 BUGS
192 =head1 AUTHOR
194 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
196 =head1 COPYRIGHT
198 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
199 This is free software; see the file F<COPYING> for legalese stuff.
201 =head1 LICENCE
203 This program is free software: you can redistribute it and/or modify it
204 under the terms of the GNU General Public License as published by the
205 Free Software Foundation, either version 2 of the License, or (at your
206 option) any later version.
208 This program is distributed in the hope that it will be useful, but
209 WITHOUT ANY WARRANTY; without even the implied warranty of
210 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
211 See the GNU General Public License for more details.
213 You should have received a copy of the GNU General Public License along
214 with this program.
215 If not, see L<http://www.gnu.org/licenses/>.
217 =head1 SEE ALSO
219 =cut
221 # }}}
223 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :