15 $SIG{'__WARN__'} = \&warning;
17 Getopt::Long::Configure("no_ignore_case", "bundling", "gnu_compat",
19 if (not GetOptions(\%opts,
30 if (exists($opts{'h'})) {
34 if (exists($opts{'V'})) {
40 error(4, "No input files\n");
42 if (exists($opts{'o'})) {
44 error(4, "Cannot specify -o with multiple files\n");
46 compile($ARGV[0], $opts{'o'}, $opts{'D'}, $opts{'I'});
50 $output =~ s/\.[^.]+$/.html/;
51 compile($input, $output, $opts{'D'}, $opts{'I'});
60 printf($fh "Usage: %s [-o <output>] <input> ...\n", $0);
69 print(" -D <name>=<value> Set the variable <name> to <value>\n");
70 print(" -I <directory> Set the document root to <directory>\n");
71 print(" -o <output> Place the output into <output>\n");
72 print(" -h, --help Display this information\n");
73 print(" -V, --version Display compiler version information\n");
80 print("ssic 0.1.0\n");
81 print("Copyright (C) 2013 Patrick \"P. J.\" McDermott\n");
82 print("License GPLv3+: GNU GPL version 3 or later " .
83 "<http://gnu.org/licenses/gpl.html>.\n");
84 print("This is free software: you are free to change and " .
85 "redistribute it.\n");
86 print("There is NO WARRANTY, to the extent permitted by law.\n");
91 my ($fmt, @args) = @_;
93 printf("ssic: Warning: " . $fmt, @args);
98 my ($status, $fmt, @args) = @_;
100 printf("ssic: Error: " . $fmt, @args);
106 my ($input, $output, $vars, $root) = @_;
114 if ($input eq $output and $input ne "-") {
115 warning("Input and output files are equal\n");
120 $input_abs = File::Spec->rel2abs(".");
122 if (not open($input_fh, "<", $input)) {
123 error(4, "%s: %s\n", $input, $!);
125 $input_abs = File::Spec->rel2abs($input);
127 if ($output eq "-") {
128 $output_fh = *STDOUT;
130 if (not open($output_fh, ">", $output . "~")) {
131 error(4, "%s: %s\n", $output . "~", $!);
135 # CGI::SSI uses SCRIPT_FILENAME to determine the value of LAST_MODIFIED.
137 "DOCUMENT_NAME" => $input,
138 "DOCUMENT_URI" => $input,
139 "DOCUMENT_ROOT" => $root,
140 "SCRIPT_FILENAME" => $input_abs,
143 $CGI::SSI::DEBUG = 0;
144 $ssi = CGI::SSI->new(
145 "DOCUMENT_NAME" => $input,
146 "DOCUMENT_URI" => $input,
147 "DOCUMENT_ROOT" => $root,
150 while (($var_name, $var_value) = each(%{$vars})) {
151 $ssi->set($var_name => $var_value);
154 print($output_fh $ssi->process(<$input_fh>));
159 if ($output ne "-") {
163 if (not rename($output . "~", $output)) {
164 error(4, "%s: %s\n", $output, $!);