From 72f72d64a422d6628c4796f5c0bf2e508f134214 Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Wed, 4 May 2011 16:05:14 +0900 Subject: Adding upstream version 0.5.1 --- scripts/w3mman/hlink.cgi | 97 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 scripts/w3mman/hlink.cgi (limited to 'scripts/w3mman/hlink.cgi') diff --git a/scripts/w3mman/hlink.cgi b/scripts/w3mman/hlink.cgi new file mode 100644 index 0000000..a92ac1d --- /dev/null +++ b/scripts/w3mman/hlink.cgi @@ -0,0 +1,97 @@ +#!/usr/local/bin/perl + +$SCRIPT_NAME = $ENV{'SCRIPT_NAME'} || $0; +$CGI = "file://$SCRIPT_NAME?"; + +if ($ENV{'QUERY_STRING'}) { + $file = $ENV{'QUERY_STRING'}; +} else { + $file = $ARGV[0]; +} +$file = &cleanup($file); + +if (-d $file) { + print <$file +$_ +EOF + exit 1; +} + +$file = &html_quote($file); +($dir = $file) =~ s@[^/]*$@@; + +print <$file +
+EOF
+while () {
+  $_ = &html_quote($_);
+
+  s/^(\#\s*include\s+)(\".*\"|\<\;.*\>\;)/$1 . &header_ref($2)/ge;
+
+  print;
+}
+close(FILE);
+print "
\n"; + +sub header_ref { + local($_) = @_; + local($d); + + if (s/^\"//) { + s/\"$//; + return ""$_""; + } + s/^\<\;//; + s/\>\;$//; + + for $d ( + "/usr/include", + "/usr/local/include", + "/usr/X11R6/include", + "/usr/X11/include", + "/usr/X/include", + "/usr/include/X11" + ) { + -f "$d/$_" && return "<$_>"; + } + return $_; +} + + +sub html_quote { + local($_) = @_; + local(%QUOTE) = ( + '<', '<', + '>', '>', + '&', '&', + '"', '"', + ); + s/[<>&"]/$QUOTE{$&}/g; + return $_; +} + +sub cleanup { + local($_) = @_; + + s@//+@/@g; + s@/\./@/@g; + while(m@/\.\./@) { + s@^/(\.\./)+@/@; + s@/[^/]+/\.\./@/@; + } + return $_; +} -- cgit v1.2.3