New build path variable
[freeradius.git] / doc / rfc / rewrite.pl
1 #!/usr/bin/env perl
2
3 #
4 #   Read in the references, and put into an associative array
5 #
6 open FILE, "<refs" || die "Error opening refs: $!\n";
7 while (<FILE>) {
8     chop;
9     split;
10     
11     $refs{$_[1]} = $_[0];
12 }
13 close FILE;
14
15 #
16 #  now loop over the input RFC's.
17 #
18 foreach $file (@ARGV) {
19     open FILE, "<$file" || die "Error opening $file: $!\n";
20
21     $attribute = "zzzzz";
22
23     # get the current reference
24     $ref = $file;
25     $ref =~ s/\..*//g;
26         
27     open OUTPUT, ">$ref.html" || die "Error creating $ref.html: $!\n";
28
29     #
30     #  Print out the HTML header
31     #
32     print OUTPUT <<EOF;
33 <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
34 <HTML>
35 <head>
36    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
37    <meta name="GENERATOR" content="Perl">
38    <title>$ref.html</title>
39 </head>
40 <body>
41 <PRE>
42
43 EOF
44
45     #  loop over the input file
46     while (<FILE>) {
47         # html-ize it
48         s/&/&amp;/g;
49         s/</&lt;/g;
50         s/>/&gt;/g;
51         
52         if (/\[Page/) {
53             print OUTPUT;
54             next;
55         }
56         
57         if (/^RFC \d+/) {
58             print OUTPUT;
59             next;
60         }
61         
62         chop;
63         
64         #
65         #  Attribute name header.
66         #
67         if (/^\d+\./ && !/\d$/) {
68             split;
69
70             if ($refs{$_[1]} ne "") {
71                 $attribute = $_[1];
72                 
73                 print OUTPUT "<A NAME=\"$attribute\"><H2>$_</H2></a>\n";
74                 
75             } else {
76                 print OUTPUT "<H2>$_</H2>\n";
77                 $attribute = "zzzz";
78             }
79             next;
80         }
81
82         #
83         #  Mark these up special.
84         #
85         if ((/^   Description/) ||
86             (/^   Type/) ||
87             (/^   Length/) ||
88             (/^   Value/)) {
89             print OUTPUT "<B>$_</B>\n";
90             next;
91         }
92         
93         # Make the current attribute name bold
94         s/$attribute/<B>$attribute<\/B>/g;
95
96         split;
97
98         #
99         #  Re-write the output with links to where-ever
100         #
101         foreach $word (@_) {
102             $word =~ s/[^-a-zA-Z]//g;
103
104             if ($refs{$word} ne "") {
105                 if ($refs{$word} eq $ref) {
106                     s/$word/<A HREF="#$word">$word<\/A>/g;
107                 } else {
108                     s/$word/<A HREF="$refs{$word}.html#$word">$word<\/A>/g;
109                 }
110             }
111         }
112
113         print OUTPUT $_, "\n";
114     }
115
116     print OUTPUT "</PRE>\n";
117     print OUTPUT "</BODY>\n";
118     close OUTPUT;
119     close FILE;
120 }
121
122 #
123 #  And finally, create the index.
124 #
125 open OUTPUT, ">attributes.html" || die "Error creating attributes.html: $!\n";
126
127 #
128 #  Print out the HTML header
129 #
130 print OUTPUT <<EOF;
131 <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
132 <HTML>
133 <head>
134    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
135    <meta name="GENERATOR" content="Perl">
136    <title>$ref.html</title>
137 </head>
138 <body>
139
140 <H2>RADIUS Attribute List</H2>
141 EOF
142
143 $letter = "@";
144
145 foreach $key (sort keys %refs) {
146     if (substr($key,0,1) ne $letter) {
147         print OUTPUT "</UL>\n" if ($letter ne "@");
148         $letter = substr($key,0,1);
149         print OUTPUT "\n<H3>$letter</H3>\n\n";
150         print OUTPUT "<UL>\n";
151     }
152     
153     print OUTPUT "<A HREF=\"$refs{$key}.html#$key\">$key</A><BR>\n";
154 }
155
156 print OUTPUT "</UL>\n";
157
158 print OUTPUT "</BODY>\n";
159 close OUTPUT;