-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcreate_new
executable file
·262 lines (189 loc) · 5.2 KB
/
create_new
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/usr/bin/env perl
#=======================================================================
# create_new
# File ID: 5dad39ac-f742-11dd-a5bf-000475e441b9
# Creates various pristine setups for all kind of things — documents,
# source code and so on.
#
# Character set: UTF-8
# ©opyleft 2006– Øyvind A. Holm <[email protected]>
# License: GNU General Public License version 2 or later, see end of
# file for legal stuff.
#=======================================================================
use strict;
use warnings;
use Getopt::Long;
$| = 1;
our $Debug = 0;
our %Opt = (
'debug' => 0,
'help' => 0,
'no-svn' => 0,
'verbose' => 0,
'version' => 0,
);
our $progname = $0;
$progname =~ s/^.*\/(.*?)$/$1/;
our $VERSION = "0.00";
my $CMD_SVN = "svn";
my $CMD_STD = "$ENV{'HOME'}/bin/std";
my $CMD_KEYW = "$ENV{'HOME'}/bin/keyw";
Getopt::Long::Configure("bundling");
GetOptions(
"debug" => \$Opt{'debug'},
"help|h" => \$Opt{'help'},
"no-svn|n" => \$Opt{'no-svn'},
"verbose|v+" => \$Opt{'verbose'},
"version" => \$Opt{'version'},
) || die("$progname: Option error. Use -h for help.\n");
$Opt{'debug'} && ($Debug = 1);
$Opt{'help'} && usage(0);
if ($Opt{'version'}) {
print_version();
exit(0);
}
if (!defined($ARGV[1])) {
die("$progname: Not enough parameters, use -h for help.\n");
}
my ($Type, $Name) = (shift, shift);
if ($Type =~ /^article$/) {
mkdir($Name) || die("$progname: mkdir $Name: $!\n");
system("$CMD_STD db-article >$Name/$Name.xml");
if (open(OutFP, ">", "$Name/Makefile")) {
my $svn_str_update = !$Opt{'no-svn'} && "\tsvn update \$(HTML_TARGET)\n" || "";
print(OutFP <<END);
#!/usr/bin/make
# \$Id\$
SHELL = /bin/bash
XSLTPROC = xsltproc
XSLTOPTS =
XHTML_XSL = \$(HOME)/xsl/xhtml/docbook.xsl
HTML_TARGET = $Name.html
all:
\t\$(MAKE) \$(HTML_TARGET)
\$(HTML_TARGET): $Name.xml
\t\$(XSLTPROC) -o \$(HTML_TARGET) \$(XSLTOPTS) \$(XHTML_XSL) $Name.xml
\txmllint --format --encode UTF-8 \$(HTML_TARGET) >$Name.tmp
\tmv $Name.tmp \$(HTML_TARGET)
check:
\t\@(for _f in *.xml; do \\
\t\techo ==== \$\$_f ====; \\
\t\txmllint --valid --noout \$\$_f; \\
\t\tdone \\
\t)
htmlclean:
\trm -f \$(HTML_TARGET)
$svn_str_update
clean:
\t\$(MAKE) htmlclean
valid:
\t\$(MAKE) check
END
close(OutFP);
} else {
warn("$progname: $Name/Makefile: Cannot create file: $!\n");
}
$Opt{'no-svn'} || my_system($CMD_SVN, "add", $Name);
$Opt{'no-svn'} || my_system($CMD_KEYW, "$Name/Makefile", "$Name/$Name.xml");
} else {
die("$progname: $Type: Unknown type\n");
}
sub my_system {
my @Cmd = @_;
my $cmd_txt = join(" ", @Cmd);
print("======== $progname: Executing \"$cmd_txt\"... ========\n");
system(@Cmd);
return;
}
sub print_version {
# Print program version {{{
print("$progname v$VERSION\n");
# }}}
} # print_version()
sub usage {
# Send the help message to stdout {{{
my $Retval = shift;
if ($Opt{'verbose'}) {
print("\n");
print_version();
}
print(<<END);
Usage: $progname type directory
Options:
-h, --help
Show this help.
-n, --no-svn
Don’t use Subversion commands (svn add, etc)
-v, --verbose
Increase level of verbosity. Can be repeated.
--version
Print version information.
--debug
Print debugging messages.
Supported types:
article
DocBook article.
END
exit($Retval);
# }}}
} # usage()
sub msg {
# Print a status message to stderr based on verbosity level {{{
my ($verbose_level, $Txt) = @_;
if ($Opt{'verbose'} >= $verbose_level) {
print(STDERR "$progname: $Txt\n");
}
# }}}
} # msg()
sub D {
# Print a debugging message {{{
$Debug || return;
my @call_info = caller;
chomp(my $Txt = shift);
my $File = $call_info[1];
$File =~ s#\\#/#g;
$File =~ s#^.*/(.*?)$#$1#;
print(STDERR "$File:$call_info[2] $$ $Txt\n");
return("");
# }}}
} # D()
__END__
# Plain Old Documentation (POD) {{{
=pod
=head1 NAME
=head1 SYNOPSIS
[options] [file [files [...]]]
=head1 DESCRIPTION
=head1 OPTIONS
=over 4
=item B<-h>, B<--help>
Print a brief help summary.
=item B<-v>, B<--verbose>
Increase level of verbosity. Can be repeated.
=item B<--version>
Print version information.
=item B<--debug>
Print debugging messages.
=back
=head1 BUGS
=head1 AUTHOR
Made by Øyvind A. Holm S<E<lt>[email protected]<gt>>.
=head1 COPYRIGHT
Copyleft © Øyvind A. Holm E<lt>[email protected]<gt>
This is free software; see the file F<COPYING> for legalese stuff.
=head1 LICENCE
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation, either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program.
If not, see L<http://www.gnu.org/licenses/>.
=head1 SEE ALSO
=cut
# }}}
# vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :