-
Notifications
You must be signed in to change notification settings - Fork 1
/
swl.pl
executable file
·162 lines (143 loc) · 2.93 KB
/
swl.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env perl
################################################################################
#
#
# SWL - Short Web Language
# by Kris Kowal
# Version 2.9
# 2004-10-02-21-15 PDT
#
# SWL may be distributed under the terms of this General Public License.
#
# converts text/swl to text/html using swl.pm
#
################################################################################
sub version {
print << "END";
SWL (Short Web Language) Version $SWL::VERSION
(C) Copyright 2001-2004 by Kris Kowal
END
}
sub usage {
version;
print << "END";
Usage: swl [[-fFr] input [-o output] ...] ...]
input is the name of an input file like moo.swl
output is the name of an output file like moo.html
-f forces all following files to be written even if the input is
older than the output
-F stops forcing (default)
-r same as "-f ."
-o overrides the default output file name
-q quiet
-v verbose (default)
input and output can be '-' to use standard io instead of files
END
}
require lib;
for my $path (
#PATH#
'/usr/local/share/swl',
#/PATH#
) {
if ( -e $path ) {
import lib $path;
last;
}
}
require swl;
my @args = @ARGV;
if ( @args == 0 ) {
@args = ( '.' );
}
my $force = 0;
my $recur = 0;
my $verbose = 1;
while ( my $arg = shift @args ) {
if ( $arg =~ /^--(.*)/ ) {
$1 eq 'version' and do {
$verbose and version();
exit;
};
$1 eq 'help' and do {
$verbose and usage();
exit;
};
$verbose and print STDERR "Invalid switch: $1\n";
} elsif ( $arg =~ /^-(.+)/ ) {
for $arg ( split '', $1 ) {
$arg eq 'f' and do {
$force = 1;
next;
};
$arg eq 'F' and do {
$force = 0;
next;
};
$arg eq 'r' and do {
unshift @args, '.';
next;
};
$arg eq 'h' and do {
$verbose and usage();
next;
};
$arg eq 'q' and do {
$verbose = 0;
next;
};
$arg eq 'Q' and do {
$verbose = 1;
next;
};
$arg eq 'v' and do {
$verbose = 1;
next;
};
$arg eq 'V' and do {
$verbose = 0;
next;
};
$verbose and print STDERR "Invalid switch: $arg\n";
}
next;
}
# todo: use glob instead
my @files = ( $arg );
while ( my $in = shift @files ) {
next if $in eq '';
# construct the default output
my $out;
if ( $in ne '-' ) {
$in = SWL::Grok( $in );
$out = $in;
$out =~ s/\.[^\.]*$//;
$out .= ".html" if $out !~ /\./;
} else {
$out = '-';
}
# check whether an output override follows
my $next = shift @args;
if ( $next eq '-o' ) {
$out = shift @args;
} else {
unshift @args, $next;
}
if ( $in ne '-' and -d $in ) {
push @files, grep { -d $_; } glob("$in/*");
push @files, glob("$in/*.swl");
} elsif (
$force or
$out eq '-' or
not -e $out or
( stat "$in" )[9] > ( stat "$out" )[9]
) {
if ( $verbose and $out ne '-' ) {
print "$out\n";
}
SWL::File( "$in", "$out" ) or
$verbose and print STDERR "Error: Could not compile '$in'\n";
}
}
}
exit;