4 # artemus - HTML (and other things) Preprocessor
6 # Copyright (C) 2000/2009 Angel Ortega <angel@triptico.com>
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 # http://www.triptico.com
30 # substitution variables
33 # substitution functions
36 # source and destination files
41 $config_file = 'artemus.conf';
43 # local configuration file
44 $local_config_file = 'local-artemus.conf';
49 # use cr/lf instead of lf
52 # append instead of overwrite output file
55 # send files using ftp
64 # inverse substitutions
65 $inverse_config_file = 'artemus-inv.conf';
71 # include debugging info
74 # unresolved templates
77 #####################################################################
79 # special utility functions
80 $funcs{'filesize'} = sub { -s
$_[0] };
81 $funcs{'shell'} = sub { $_=`$_[0]`; chomp; return $_ };
84 $VERSION = $Artemus::VERSION
;
85 $artemus_id = "Artemus $VERSION";
87 usage
() if (!GetOptions
('i|input=s' => \
$src,
88 'o|output=s' => \
$dst,
89 'c|conf=s' => \
$config_file,
90 'p|paragraph=s' => \
$para_sep,
91 'm|msdos' => \
$use_cr_lf,
92 'a|append' => \
$append,
93 'v|version-only' => \
$version_only,
95 'l|include-path=s' => \
$include_path,
97 'h|help' => \
$help) or $help);
99 $dst = '>-' if $dst eq '-';
106 # read the configuration files
107 if (-f
$config_file) {
108 read_config
($config_file);
111 if (-f
$local_config_file) {
112 read_config
($local_config_file);
115 if (-f
$inverse_config_file) {
116 read_config
($inverse_config_file, 1);
119 open F
, $src or die "can't open '$src'";
122 $data = join('', <F
>);
125 # create the Artemus handle
126 $ah = Artemus
->new('paragraph-separator' => $para_sep,
128 'inv-vars' => \
%inv_vars,
130 'include-path' => $include_path,
131 'use-cr-lf' => $use_cr_lf,
132 'unresolved' => \
@unresolved,
137 $data = $ah->process($data);
141 open F
, ($append ?
'>' : '') . ">$dst" or die "can't write '$dst'";
145 foreach my $t (@unresolved) {
146 print STDERR
"Artemus: unresolved '$t'\n";
150 foreach my $c (@
{$ah->{call_stack
}}) {
151 my ($t, $level, $full_line, $ret) = @
{$c};
154 $full_line =~ s/\n/\\n/g;
156 print STDERR
(' ' x
$level),
157 '{-', $full_line, '} -> ',
166 ######################################################################
170 my ($conf, $inverse) = @_;
174 unless (open F
, $conf) {
179 die "'$conf' bad config file";
188 unless (/^#/ or /^$/) {
189 ($key, $val) = split("=", $_, 2);
191 if ($val =~ s/^\|//) {
195 elsif ($val eq ('<<' . 'EOF')) {
196 # 'document here' construction
205 elsif ($key eq "\\INCLUDE") {
213 $inv_vars{$key} = $val;
224 print("$artemus_id - HTML (and other things) Preprocessor\n");
225 print("Copyright (C) 2000/2009 Angel Ortega <angel\@triptico.com>\n\n");
228 print(" artemus -i|--input={input file} -o|--output={output file}\n");
229 print(" [-c|--conf={config file}]\n");
230 print(" [-l|--include-path={path to includes}]\n");
231 print(" [-p|--paragraph={paragraph_separator}]\n");
232 print(" [-q|--quiet]\n");
233 print(" [-m|--msdos] [-a|--append] [-d|--debug]\n\n");