5 ssic - Server Side Includes Compiler
22 $SIG{'__WARN__'} = \&warning;
24 Getopt::Long::Configure("no_ignore_case", "bundling", "gnu_compat",
26 if (not GetOptions(\%opts,
37 if (exists($opts{'h'})) {
41 if (exists($opts{'V'})) {
47 error(4, "No input files\n");
50 $ssi = init_compiler($opts{'D'}, $opts{'I'});
52 if (exists($opts{'o'})) {
54 error(4, "Cannot specify -o with multiple files\n");
56 compile($ssi, $ARGV[0], $opts{'o'});
60 $output =~ s/\.[^.]+$/.html/;
61 compile($ssi, $input, $output);
72 printf($fh "Usage: %s [-o <output>] <input> ...\n", $0);
81 print(" -D <name>=<value> Set the variable <name> to <value>\n");
82 print(" -I <directory> Set the document root to <directory>\n");
83 print(" -o <output> Place the output into <output>\n");
84 print(" -h, --help Display this information\n");
85 print(" -V, --version Display compiler version information\n");
92 print("ssic 0.1.0\n");
93 print("Copyright (C) 2013 Patrick \"P. J.\" McDermott\n");
94 print("License GPLv3+: GNU GPL version 3 or later " .
95 "<http://gnu.org/licenses/gpl.html>.\n");
96 print("This is free software: you are free to change and " .
97 "redistribute it.\n");
98 print("There is NO WARRANTY, to the extent permitted by law.\n");
103 my ($fmt, @args) = @_;
105 printf(STDERR "ssic: Warning: " . $fmt, @args);
110 my ($status, $fmt, @args) = @_;
112 printf(STDERR "ssic: Error: " . $fmt, @args);
118 my ($vars, $root) = @_;
124 "DOCUMENT_ROOT" => $root,
127 $CGI::SSI::DEBUG = 0;
128 $ssi = CGI::SSI->new();
130 $ssi->set("DOCUMENT_ROOT" => $root);
132 while (($var_name, $var_value) = each(%{$vars})) {
133 $ssi->set($var_name => $var_value);
141 my ($ssi, $input, $output) = @_;
146 if ($input eq $output and $input ne "-") {
147 warning("Input and output files are equal\n");
152 $input_abs = File::Spec->rel2abs(".");
154 if (not open($input_fh, "<", $input)) {
155 error(4, "%s: %s\n", $input, $!);
157 $input_abs = File::Spec->rel2abs($input);
159 if ($output eq "-") {
160 $output_fh = *STDOUT;
162 if (not open($output_fh, ">", $output . "~")) {
163 error(4, "%s: %s\n", $output . "~", $!);
167 # CGI::SSI uses SCRIPT_FILENAME to determine the value of LAST_MODIFIED.
168 $ENV{"DOCUMENT_NAME"} = $input;
169 $ENV{"DOCUMENT_URI"} = $input;
170 $ENV{"SCRIPT_FILENAME"} = $input_abs;
172 # Reset config tags to default values.
173 $ssi->config("errmsg",
174 "[an error occurred while processing this directive]");
175 $ssi->config("sizefmt", "abbrev");
176 $ssi->config("timefmt", undef);
178 $ssi->set("DOCUMENT_NAME" => $input);
179 $ssi->set("DOCUMENT_URI" => $input);
181 print($output_fh $ssi->process(<$input_fh>));
186 if ($output ne "-") {
188 if (not rename($output . "~", $output)) {
189 error(4, "%s: %s\n", $output, $!);
203 [B<-D> I<name>=I<value> ...]
208 B<ssic> processes HTML documents with SSI directives formatted as SGML comments.
209 It can be used to process documents without an HTTP server for local browsing or
210 to generate static HTML documents to be efficiently served by an HTTP server.
211 Documents could even be preprocessed, e.g. by a Markdown processor, before being
218 =item B<-o> I<output>
220 Place the output into I<output>.
222 =item B<-I> I<directory>
224 Set the document root to I<directory>.
226 =item B<-D> I<name>=I<value>
228 Set the variable I<name> to I<value>.
230 =item B<-h>, B<--help>
232 Display help information.
234 =item B<-V>, B<--version>
236 Display compiler version information.
242 Copyright (C) 2013 Patrick "P. J." McDermott
244 This program is free software: you can redistribute it and/or modify
245 it under the terms of the GNU General Public License as published by
246 the Free Software Foundation, either version 3 of the License, or
247 (at your option) any later version.
249 This program is distributed in the hope that it will be useful,
250 but WITHOUT ANY WARRANTY; without even the implied warranty of
251 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
252 GNU General Public License for more details.
254 You should have received a copy of the GNU General Public License
255 along with this program. If not, see <http://www.gnu.org/licenses/>.
261 NCSA HTTPd SSI documentation:
262 L<http://web.archive.org/web/19971210170837/http://hoohoo.ncsa.uiuc.edu/docs/tutorials/includes.html>
264 Apache HTTPd mod_include documentation:
265 L<http://httpd.apache.org/docs/current/mod/mod_include.html>