| 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
 | #!/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 <<EOF;
Location: file:$file
EOF
  exit;
}
if (! open(FILE, "< $file")) {
  $file = &html_quote($file);
  $_ = "$file: " . &html_quote($!);
  print <<EOF;
Content-Type: text/html
<head><title>$file</title></head>
<b>$_</b>
EOF
  exit 1;
}
$file = &html_quote($file);
($dir = $file) =~ s@[^/]*$@@;
print <<EOF;
Content-Type: text/html
<head><title>$file</title></head>
<pre>
EOF
while (<FILE>) {
  $_ = &html_quote($_);
  s/^(\#\s*include\s+)(\".*\"|\<\;.*\>\;)/$1 . &header_ref($2)/ge;
  print;
}
close(FILE);
print "</pre>\n";
sub header_ref {
  local($_) = @_;
  local($d);
  if (s/^\"//) {
    s/\"$//;
    return ""<a href=\"$CGI$dir$_\">$_</a>"";
  }
  s/^\<\;//;
  s/\>\;$//;
  for $d (
	"/usr/include",
	"/usr/local/include",
	"/usr/X11R6/include",
	"/usr/X11/include",
	"/usr/X/include",
	"/usr/include/X11"
  ) {
    -f "$d/$_" && return "<<a href=\"$CGI$d/$_\">$_</a>>";
  }
  return $_;
}
sub html_quote {
  local($_) = @_;
  local(%QUOTE) = (
    '<', '<',
    '>', '>',
    '&', '&',
    '"', '"',
  );
  s/[<>&"]/$QUOTE{$&}/g;
  return $_;
}
sub cleanup {
  local($_) = @_;
  s@//+@/@g;
  s@/\./@/@g;
  while(m@/\.\./@) {
    s@^/(\.\./)+@/@;
    s@/[^/]+/\.\./@/@;
  }
  return $_;
}
 |