5 ssic - Server Side Includes Compiler
25 $SIG{'__WARN__'} = \&warning;
27 Getopt::Long::Configure("no_ignore_case", "bundling", "gnu_compat",
29 if (not GetOptions(\%opts,
40 if (exists($opts{'h'})) {
44 if (exists($opts{'V'})) {
50 error(4, "No input files\n");
53 $ssi = init_compiler($opts{'D'}, $opts{'I'});
55 if (exists($opts{'o'})) {
57 error(4, "Cannot specify -o with multiple files\n");
59 compile($ssi, $ARGV[0], $opts{'o'});
63 $output =~ s/\.[^.]+$/.html/;
64 compile($ssi, $input, $output);
75 printf($fh "Usage: %s [-o <output>] <input> ...\n", $0);
84 print(" -o <output> Place the output into <output>\n");
85 print(" -I <directory> Set the document root to <directory>\n");
86 print(" -D <name>=<value> Set the variable <name> to <value>\n");
87 print(" -h, --help Display this information\n");
88 print(" -V, --version Display compiler version information\n");
95 printf("ssic %s\n", $VERSION);
96 print("Copyright (C) 2013 Patrick \"P. J.\" McDermott\n");
97 print("License GPLv3+: GNU GPL version 3 or later " .
98 "<http://gnu.org/licenses/gpl.html>.\n");
99 print("This is free software: you are free to change and " .
100 "redistribute it.\n");
101 print("There is NO WARRANTY, to the extent permitted by law.\n");
106 my ($fmt, @args) = @_;
108 printf(STDERR "ssic: Warning: " . $fmt, @args);
113 my ($status, $fmt, @args) = @_;
115 printf(STDERR "ssic: Error: " . $fmt, @args);
121 my ($vars, $root) = @_;
127 "DOCUMENT_ROOT" => $root,
130 $CGI::SSI::DEBUG = 0;
131 $ssi = CGI::SSI->new();
133 $ssi->set("DOCUMENT_ROOT" => $root);
135 while (($var_name, $var_value) = each(%{$vars})) {
136 $ssi->set($var_name => $var_value);
144 my ($ssi, $input, $output) = @_;
149 if ($input eq $output and $input ne "-") {
150 warning("Input and output files are equal\n");
155 $input_abs = File::Spec->rel2abs(".");
157 if (not open($input_fh, "<", $input)) {
158 error(4, "%s: %s\n", $input, $!);
160 $input_abs = File::Spec->rel2abs($input);
162 if ($output eq "-") {
163 $output_fh = *STDOUT;
165 if (not open($output_fh, ">", $output . "~")) {
166 error(4, "%s: %s\n", $output . "~", $!);
170 # CGI::SSI uses SCRIPT_FILENAME to determine the value of LAST_MODIFIED.
171 $ENV{"DOCUMENT_NAME"} = $input;
172 $ENV{"DOCUMENT_URI"} = $input;
173 $ENV{"SCRIPT_FILENAME"} = $input_abs;
175 # Reset config tags to default values.
176 $ssi->config("errmsg",
177 "[an error occurred while processing this directive]");
178 $ssi->config("sizefmt", "abbrev");
179 $ssi->config("timefmt", undef);
181 $ssi->set("DOCUMENT_NAME" => $input);
182 $ssi->set("DOCUMENT_URI" => $input);
184 print($output_fh $ssi->process(<$input_fh>));
189 if ($output ne "-") {
191 if (not rename($output . "~", $output)) {
192 error(4, "%s: %s\n", $output, $!);
206 [B<-D> I<name>=I<value> ...]
211 B<ssic> processes HTML documents with SSI directives formatted as SGML comments.
212 It can be used to process documents without an HTTP server for local browsing or
213 to generate static HTML documents to be efficiently served by an HTTP server.
214 Documents could even be preprocessed, e.g. by a Markdown processor, before being
221 =item B<-o> I<output>
223 Place the output into I<output>.
225 =item B<-I> I<directory>
227 Set the document root to I<directory>.
229 =item B<-D> I<name>=I<value>
231 Set the variable I<name> to I<value>.
233 =item B<-h>, B<--help>
235 Display help information.
237 =item B<-V>, B<--version>
239 Display compiler version information.
245 Copyright (C) 2013 Patrick "P. J." McDermott
247 This program is free software: you can redistribute it and/or modify
248 it under the terms of the GNU General Public License as published by
249 the Free Software Foundation, either version 3 of the License, or
250 (at your option) any later version.
252 This program is distributed in the hope that it will be useful,
253 but WITHOUT ANY WARRANTY; without even the implied warranty of
254 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
255 GNU General Public License for more details.
257 You should have received a copy of the GNU General Public License
258 along with this program. If not, see <http://www.gnu.org/licenses/>.
264 NCSA HTTPd SSI documentation:
265 L<http://web.archive.org/web/19971210170837/http://hoohoo.ncsa.uiuc.edu/docs/tutorials/includes.html>
267 Apache HTTPd mod_include documentation:
268 L<http://httpd.apache.org/docs/current/mod/mod_include.html>