File: global.asa

package info (click to toggle)
libapache-asp-perl 2.63-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,120 kB
  • sloc: perl: 6,044; php: 409; sh: 62; lisp: 22; makefile: 10
file content (253 lines) | stat: -rw-r--r-- 6,297 bytes parent folder | download | duplicates (2)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253

use Data::Dumper;
use vars qw(%FILES %ALIASES %LINKS $ASP $DOCINIT $DUMP $Site $LINKS_MATCH $VAR1);
use Time::HiRes;
use Data::Dumper;
use Digest::MD5 qw( md5_hex );
use SiteTags;
use strict;

$DUMP = "/tmp/aspbuilddumpdata";
%FILES = ('index' => 'INTRO',
	  'install' => 'INSTALL',
	  'changes' => 'CHANGES',
	  'config' => 'CONFIG',
	  'sessions' => 'SESSIONS',
	  'syntax' => 'SYNTAX',
          'style' => 'STYLE GUIDE',
	  'events' => 'EVENTS',
	  'objects' => 'OBJECTS',
	  'resources' => 'RESOURCES',
	  'ssi' => 'SSI',
	  'cgi' => 'CGI',
	  'perlscript' => 'PERLSCRIPT',
	  'faq' => 'FAQ',
	  'tuning' => 'TUNING',
	  'kudos' => 'CREDITS',
	  'support' => 'SUPPORT',
	  'sites' => 'SITES USING',
	  'todo' => 'TODO',
	  'xml' => 'XML/XSLT',
	  'license' => 'LICENSE',
	  'testimonials' => 'TESTIMONIALS',
	 );

%ALIASES = (
	    'DESCRIPTION' => 'INTRO',
#	    'INSTALL' => 'DOWNLOAD',
	    'NOTES' => 'CREDITS',
	   );

# auto link these key words, includes %FILES inverted
%LINKS = (
	  'Apache Web Server' => 'http://www.apache.org',
	  'mod_perl' => 'http://perl.apache.org',
	  'CGI.pm' => 'http://stein.cshl.org/WWW/software/CGI/cgi_docs.html',
	  'PerlScript' => 'http://www.activestate.com/ActivePerl/',
	  'NT/IIS' => 'http://www.microsoft.com/iis/',
	  'XML::XSLT' => 'http://xmlxslt.sourceforge.net/',
	  'LRN' => 'http://www.lrn.com',
	 );

# purify files and add as links
for(keys %FILES) {
    delete($FILES{$_}) unless -e "$_.html";
    $LINKS{$FILES{$_}} = "$_.html";
}

$LINKS_MATCH = join('|', keys %LINKS);

#exit;

sub Script_OnStart {
    unless ($DOCINIT++) {
	doc_init();
    }
    if($Request->QueryString('site')) {
	$Site = 1;
    }
}

sub Script_OnEnd {
    $Response->Write("\n");
}

sub dmp {
    Data::Dumper->Dump([@_]);
}

sub dbg {
    $Response->Debug(@_);
}

sub doc_init {
    local $/ = undef;
    open(DUMP, $DUMP);
    my $dump = <DUMP>;
    close DUMP;
    my $dump_data;
    if ($dump) {
	$Response->Debug("evaling compiled ASP data");
	$dump_data = eval $dump;
    }
    $dump_data ||= {};
    $Response->Debug("past eval");
    
    open(ASP, "../ASP.pm") || die("can't open ASP.pm: $!");
    my $data = <ASP>;
    close ASP;
    
    my $self_data;
    open(ASP, $0);
    $self_data = <ASP>;
    close ASP;

    $data =~ s/^.*\n__END__//s;
    my $new_checksum = md5_hex($data.$self_data.(join('', %ALIASES)));
    if ($new_checksum eq $dump_data->{checksum}) {
	$Response->Debug("matched old compiled ASP doc $dump_data->{checksum}");
	$ASP = $dump_data->{ASP};
	return;
    }
    
    $ASP = { name => 'ASP', stack => [], level => 0};
    my @levels;
    unshift(@levels, $ASP);
    
    my $count = 0;
    my $level = 0;
    my $time = Time::HiRes::time;
    $data =~ s/\n=(over|back|begin|end)[^\n]*\n/\n/sg;
    while($data =~ s/^.*?\n=(head\d|item) ([^\n]*)\n(.*?)(\n\=|$)/$4/is) {
	my($type, $name, $body) = ($1,$2,$3);
	$body =~ s/\s+$//s;

	$name = $ALIASES{$name} || $name;
	# warn time." ----------- $type :: $name :: $body ----------- \n\n";
	#    warn substr($data, 0, 200)."\n";
	#    $body =~ s/\n=over\s*$//s;
	my $item = { 
		    name => $name,
		    unique => substr($name, 0, 12).(length($name) > 12 ? substr(md5_hex($name.$body),0,8) : ''),
		    body => $body,
		    stack => [],
		    level => ($level + 1),
		   };
	
	if($type =~ /^head(\d)/) {
	    my $current = $1;		
	    $item->{level} = $current;
#	    dbg("$current current level $name");
	    while($current <= $levels[0]->{level}) {
#		dbg("shifting $levels[0]->{name}");
		shift(@levels);
	    }
	    push(@{$levels[0]->{stack}}, $item);
#	    dbg("$level unshifting $item->{name}");
	    unshift(@levels, $item);
	    $level = $item->{level};
	} else {
	    push(@{$levels[0]->{stack}}, $item);	
	}

#	last if $count++ > 20;
    }

#    warn(Time::HiRes::time - $time);
    open(DUMP, ">$DUMP");
    print DUMP Data::Dumper->Dump([{ checksum => $new_checksum, ASP => $ASP}]);
    close DUMP;
    
    dbg(dmp($ASP));
}

sub pod2html {
    my($body, $title, $depth) = @_;

    if($title) {
	$depth ||= 1;
	my $size = 2 - $depth;
	$size = ($size > -1) ? "+$size" : $size;
	
	$title = "<font class=title size=$size color=#555555><b>$title</b></font>\n";
    }

    if (($body =~ /^(.*?)(<(a|table)[^\<\>]*>.*?<\/(\3)>)(.*)$/is)) {
	my($pre,$html,$post) = ($1, $2, $5);
#	$html =~ s/\s+/ /isg;
	$body = $Server->HTMLEncode($pre).$html.$Server->HTMLEncode($post);
    } else {
	$body = $Server->HTMLEncode($body);
    }
    $body =~ s/(\<\%|\%\>)/$Server->HTMLEncode($1);/esg;

    my @lines = split(/\n/, $body);
    my $pre = 0;
    my @newlines;
    for(@lines) {
	my $pre_tag = '';
	if(/^\s+[^\s]/ || /^\s*$/) {
	    if(! $pre) {
		#			$_ = "<pre>$_";
		$pre_tag = "<font face=\"courier new\" size=3><pre>";
		$pre = 1;
	    }
	} else {
	    if($pre) {
		#			$_ = "</pre>$_";	
		$pre_tag = "</pre></font>";
		$pre = 0;
	    }
	}
#	if($pre) {
#	$_ =~ s/\s*$//;
#	    $_ = $Server->HTMLEncode($_);	    
#	}

#	} 

	$_ = $pre_tag . $_;
	push(@newlines, $_);
    }
    $body = join("\n", @newlines);
    $pre and $body .= "\n</pre>";

    $body =~ s,\n\s+(([^:\n\s]{5}|[A-Z])[^\n]*?)\s*\n\s+(http://[^\n\s]+)\s*?\n,\n  <a href="$3">$1</a>\n,sg;
#print STDERR $body;

    #$body =~ s/\n\s*\n+/<p>/isg;
    $body =~ s/([^\=\"])((http|ftp):\/\/[\w\.\/\-]+\.[\w\.\/\-\#\,\%]+[^\.\s\)])/$1<a href=$2>$2<\/a>/sg;
#    $1 && warn "link: $1\n";
    $body =~ s|(http://localhost[\S]*[^\.\s\,]?)|<tt>$1</tt>|sg;
    $body =~ s|([\w\-]+\@[\w\.\,\@\-]+)(\?[\w\=\:]+)?|'<b>'.&html_encode_hide($1).'</b>'|esg;
    $body =~ s|(\./site/)(eg/[\w\.]+[^\.\s])|<a href=$2>$1$2</a>|sg;

    $body =~ s|\n\n</pre>|\n</pre>|isg;
#    my $match_links = join('|', keys %LINKS);

    my %matched;
    $body =~ s:([^\n]*?)\b($LINKS_MATCH)(?=[^<])\b:
    {
	my($head, $match) = ($1, $2);

#print STDERR "***** $head $match\n";
	if(! $matched{$match}++ and $head !~ /\>$/ and $head !~ /^\s+/ and $LINKS{$match}) {
	    "$head<a href=$LINKS{$match}><font size=-1 face=verdana><b>$match<\/b><\/font><\/a>";
	} else	 {
	    $head.$match;
	}
    }
    :sgex;

    '<font face=verdana>'.$title.$body.'</font>';
}

# we use this to mask email addresses in the documentation
sub html_encode_hide {
    my $word = shift;
    join('',
	 map{
	     sprintf(qq(&#%03d;),ord($_))
	 } split(//, $word)
	);
}