std.c: Improve some comments
[sunny256-utils.git] / xml2html
blob9e15c059b25610ae4fd2441303e06c991d750e53
1 #!/usr/bin/env perl
3 #=======================================================================
4 # xml2html
5 # File ID: 63b7d30a-f744-11dd-9507-000475e441b9
6 # Generates .html file from DocBook source. It Works On My Machine™ and
7 # then it’s good enough. ☺
9 # Character set: UTF-8
10 # ©opyleft 2006– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
15 use strict;
16 use warnings;
17 use Getopt::Long;
19 $| = 1;
21 our $Debug = 0;
23 our %Opt = (
25 'debug' => 0,
26 'format' => 0,
27 'help' => 0,
28 'verbose' => 0,
29 'version' => 0,
33 our $progname = $0;
34 $progname =~ s/^.*\/(.*?)$/$1/;
35 our $VERSION = "0.00";
37 Getopt::Long::Configure("bundling");
38 GetOptions(
40 "debug" => \$Opt{'debug'},
41 "format" => \$Opt{'format'},
42 "help|h" => \$Opt{'help'},
43 "verbose|v+" => \$Opt{'verbose'},
44 "version" => \$Opt{'version'},
46 ) || die("$progname: Option error. Use -h for help.\n");
48 $Opt{'debug'} && ($Debug = 1);
49 $Opt{'help'} && usage(0);
50 if ($Opt{'version'}) {
51 print_version();
52 exit(0);
55 for my $Curr (@ARGV) {
56 my $Basename = $Curr;
57 my $tmp_file = "$Curr.xml2html.tmp";
58 $Curr =~ /^(.*)\.xml$/ && ($Basename = $1);
59 my $html_file = "$Basename.html";
60 my_system("xsltproc -o $Basename.html ~/xsl/xhtml/docbook.xsl $Curr");
61 if ($Opt{'format'}) {
62 my_system("xmllint --format --encode UTF-8 $html_file >$tmp_file");
63 my_system("mv $tmp_file $html_file");
67 sub my_system {
68 my @Cmd = @_;
69 my $cmd_txt = join(" ", @Cmd);
70 print("$progname: Executing \"$cmd_txt\"...\n");
71 system(@Cmd);
72 return;
75 sub print_version {
76 # Print program version {{{
77 print("$progname v$VERSION\n");
78 # }}}
79 } # print_version()
81 sub usage {
82 # Send the help message to stdout {{{
83 my $Retval = shift;
85 if ($Opt{'verbose'}) {
86 print("\n");
87 print_version();
89 print(<<END);
91 Usage: $progname [options] file [files [...]]
93 Options:
95 --format
96 Filter the HTML through xmllint --format to make it prettier. Some
97 things are likely to be fucked up by this, for example <personname>.
98 -h, --help
99 Show this help.
100 -v, --verbose
101 Increase level of verbosity. Can be repeated.
102 --version
103 Print version information.
104 --debug
105 Print debugging messages.
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 # }}}
120 } # msg()
122 sub D {
123 # Print a debugging message {{{
124 $Debug || return;
125 my @call_info = caller;
126 chomp(my $Txt = shift);
127 my $File = $call_info[1];
128 $File =~ s#\\#/#g;
129 $File =~ s#^.*/(.*?)$#$1#;
130 print(STDERR "$File:$call_info[2] $$ $Txt\n");
131 return("");
132 # }}}
133 } # D()
135 __END__
137 # Plain Old Documentation (POD) {{{
139 =pod
141 =head1 NAME
145 =head1 SYNOPSIS
147 [options] [file [files [...]]]
149 =head1 DESCRIPTION
153 =head1 OPTIONS
155 =over 4
157 =item B<-h>, B<--help>
159 Print a brief help summary.
161 =item B<-v>, B<--verbose>
163 Increase level of verbosity. Can be repeated.
165 =item B<--version>
167 Print version information.
169 =item B<--debug>
171 Print debugging messages.
173 =back
175 =head1 BUGS
179 =head1 AUTHOR
181 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
183 =head1 COPYRIGHT
185 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
186 This is free software; see the file F<COPYING> for legalese stuff.
188 =head1 LICENCE
190 This program is free software: you can redistribute it and/or modify it
191 under the terms of the GNU General Public License as published by the
192 Free Software Foundation, either version 2 of the License, or (at your
193 option) any later version.
195 This program is distributed in the hope that it will be useful, but
196 WITHOUT ANY WARRANTY; without even the implied warranty of
197 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
198 See the GNU General Public License for more details.
200 You should have received a copy of the GNU General Public License along
201 with this program.
202 If not, see L<http://www.gnu.org/licenses/>.
204 =head1 SEE ALSO
206 =cut
208 # }}}
210 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :