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("__SSIC__" => 1);
134 $ssi->set("DOCUMENT_ROOT" => $root);
136 while (($var_name, $var_value) = each(%{$vars})) {
137 $ssi->set($var_name => $var_value);
145 my ($ssi, $input, $output) = @_;
150 if ($input eq $output and $input ne "-") {
151 warning("Input and output files are equal\n");
156 $input_abs = File::Spec->rel2abs(".");
158 if (not open($input_fh, "<", $input)) {
159 error(4, "%s: %s\n", $input, $!);
161 $input_abs = File::Spec->rel2abs($input);
163 if ($output eq "-") {
164 $output_fh = *STDOUT;
166 if (not open($output_fh, ">", $output . "~")) {
167 error(4, "%s: %s\n", $output . "~", $!);
171 # CGI::SSI uses SCRIPT_FILENAME to determine the value of LAST_MODIFIED.
172 $ENV{"DOCUMENT_NAME"} = $input;
173 $ENV{"DOCUMENT_URI"} = $input;
174 $ENV{"SCRIPT_FILENAME"} = $input_abs;
176 # Reset config tags to default values.
177 $ssi->config("errmsg",
178 "[an error occurred while processing this directive]");
179 $ssi->config("sizefmt", "abbrev");
180 $ssi->config("timefmt", undef);
182 $ssi->set("DOCUMENT_NAME" => $input);
183 $ssi->set("DOCUMENT_URI" => $input);
185 print($output_fh $ssi->process(<$input_fh>));
190 if ($output ne "-") {
192 if (not rename($output . "~", $output)) {
193 error(4, "%s: %s\n", $output, $!);
207 [B<-D> I<name>=I<value> ...]
212 B<ssic> processes HTML documents with SSI directives formatted as SGML comments.
213 It can be used to process documents without an HTTP server for local browsing or
214 to generate static HTML documents to be efficiently served by an HTTP server.
215 Documents could even be preprocessed, e.g. by a Markdown processor, before being
222 =item B<-o> I<output>
224 Place the output into I<output>.
226 =item B<-I> I<directory>
228 Set the document root to I<directory>.
230 =item B<-D> I<name>=I<value>
232 Set the variable I<name> to I<value>.
234 =item B<-h>, B<--help>
236 Display help information.
238 =item B<-V>, B<--version>
240 Display compiler version information.
246 Copyright (C) 2013 Patrick "P. J." McDermott
248 This program is free software: you can redistribute it and/or modify
249 it under the terms of the GNU General Public License as published by
250 the Free Software Foundation, either version 3 of the License, or
251 (at your option) any later version.
253 This program is distributed in the hope that it will be useful,
254 but WITHOUT ANY WARRANTY; without even the implied warranty of
255 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
256 GNU General Public License for more details.
258 You should have received a copy of the GNU General Public License
259 along with this program. If not, see <http://www.gnu.org/licenses/>.
265 NCSA HTTPd SSI documentation:
266 L<http://web.archive.org/web/19971210170837/http://hoohoo.ncsa.uiuc.edu/docs/tutorials/includes.html>
268 Apache HTTPd mod_include documentation:
269 L<http://httpd.apache.org/docs/current/mod/mod_include.html>