File: menu.pl

package info (click to toggle)
asc 2.4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 75,080 kB
  • ctags: 24,943
  • sloc: cpp: 155,023; sh: 8,829; ansic: 6,890; makefile: 650; perl: 138
file content (230 lines) | stat: -rwxr-xr-x 6,258 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/perl

#***************************************************************************
#*      MenuGen 0.3                                                        *
#*                                                                         *
#*      copyright (C) 2003 by Martin Bickel (mail@martin-bickel.de         *
#***************************************************************************
#*                                                                         *
#*   This program is free software; you can redistribute it and/or modify  *
#*   it under the terms of the GNU General Public License as published by  *
#*   the Free Software Foundation; either version 2 of the License, or     *
#*   (at your option) any later version.                                   *
#*                                                                         *
#***************************************************************************



# Some terminology. Consider this menu
#  
#  groupname  
#    link1
#    link2
#  another group  
#    link3
#
#
#  The gropus open a new page in the menu frame which contain the links of that group 
#  The links themselfs open a page in the main frame showing the content 
#  Both groups and links are entries.


use Getopt::Long;


# counts the number of leading dots 
sub countdot {
  my $cnt = 0;
  while ($_[0] =~ /^\./ ) {
     $_[0] =~ s/^\.//;
     ++$cnt;
  }
  return $cnt;  
}


# parses the menu file
# parameters: 
#    0 filename
#    1 initial depth
sub parsefile {
   my ( @data );
   $depth_ = $_[1];
   my $fn = $_[0];
   open $fn, $fn || die "cannot open $_[0] !\n";
   
   while( <$fn> ) {
     if ( !/^;/ ) {
	if ( /^\.*#/ ) {
           $filename = $_;
           $depth_ = countdot($_);
	   $depth_ += $_[1];
           $filename =~ s/\.*#(\w*)/$1/;
           &parsefile ($filename, $depth_);
	} else {
           ($name_,$style_,$link_)=split(/;/,$_);
           if ( /;/ ) {
              $ddepth_ = countdot($name_) + $_[1];
	      $link_ =~ s/&/&amp;/g;
              push (@name,$name_); 
              push (@depth,$ddepth_); 
              push (@style,$style_); 
              push (@link,$link_); 
           }
	}
     }
   }
   close INP;
}


# outputs a single menu line
# parameters:
#        0           : menu item no. 
#        1 (optional): if '1' then group entries don't have links. This used for the noframes menu
sub printLine {
   my $i = $_[0];
   my $suppressMenuLinks = $_[1];
   $returnvalue = "<tr>";
   
   for ( $einr = 0; $einr < $depth[$i]; $einr++ ) {
      $returnvalue .= "<td style=\"width:10px\"></td>";
   }
   $width= $maxdepth - $depth[$i] + 1;
   $returnvalue .= "<td colspan=\"$width\" class=\"menu\"> ";
   
   if ( $link[$i] =~ /^-$/ ) {  
      # this is a group entry
      if ( $suppressMenuLinks == 1 ) {
         $returnvalue .= "<b>$name[$i]</b>"; 
      } else {
         if ( $menuopen==1 ) {
	    $u = $tree[$actdepth-1];
            $returnvalue .= "<b><A HREF=\"menu$u.html\" class=\"navi\">$name[$i] <IMG SRC=\"pfeil_zu.gif\" alt=\"[-]\"></A></b>"; 
	 } else {
            $returnvalue .= "<b><A HREF=\"menu$i.html\" class=\"navi\">$name[$i] <IMG SRC=\"pfeil_auf.gif\" alt=\"[+]\"></A></b>"; 
	 }   
      }
      
   } else {  
      # this is a link entry
      $returnvalue .= "<A HREF=$link[$i] class=\"navi\">$name[$i]</A>";
   }
   $returnvalue .= " </td></tr>\n";
   return $returnvalue;
}


# main program
# parameters:
#     0 (optional)           : prefix directory for menu files
#     1 (even more optiona�) : prefix directory for the noframes menu


my $prefix = "";
my $idxprefix = "";
my $filename = "entries.txt";


GetOptions ('prefix=s' => \$prefix, 
            'idxprefix=s' => \$idxprefix,
            'input=s' => \$filename );



parsefile($filename, 0);



$length = @name;

$maxdepth = 0;
for ( $counter = 0; $counter < $length; $counter++ ) {
   if ( $depth[$counter] > $maxdepth ) {
      $maxdepth = $depth[$counter];
   }
}      

unshift(@link, "-" );
unshift(@depth, -1 );
unshift(@name, "root" );
unshift(@style, $style[0] );
++$length;

print "Number of entries: $length \n";

$counter = 0;
for ( $counter = 0; $counter < $length; $counter++ ) {

   if ( $link[$counter] =~ /^-$/ || $counter == 0 ) {
      $d = $depth[$counter];
      open DATEI, ">${prefix}menu$counter.html";
      print DATEI <<END_OF_HEADER;

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">

<TITLE>Menu</TITLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="$style[$counter]">
<link rel="shortcut icon" href="favicon.ico">
</HEAD>
<BODY class="navi">
<table border="0" cellspacing="0" cellpadding="0">
END_OF_HEADER

      $blockopen = 0;  
      
      # tree contains the entry numbers that are opened groups.
      # A tree of (0,1,4,19) means that the entry #1 is the first open group (level 0), 
      #   entry #4 is the open group that opens level 1 
      #   entry #19 is the open group that opens level 2, which is the currently processed entry
      
      @tree = ($counter);
      # We are building the tree in reverses order, so we are first pushing the current entry
      
      $actdepth = $depth[$counter];
      for ( $i = $counter; $i >= 0; $i-- ) {
         # we are going up from the current entry and look for groups that open the levels of depth
	 if ( $depth[$i] < $actdepth ) {
            unshift ( @tree, $i );
            $actdepth = $depth[$i];
	 }
      }
      push ( @tree, $length+10 );

      $treepos = 0;
      $actdepth = -1;  
      for ( $i = 0; $i < $length; ++$i ) {
	 if ( $tree[$treepos] == $i ) {
            $actdepth++;
            $treepos++;
            $menuopen=1;
	 } else {
            $menuopen=0;
            if ( $depth[$i] < $actdepth ) {
               $actdepth = $depth[$i];
            }
	 }

	 if ( $depth[$i] <= $actdepth && $depth[$i] >= 0 ) {
            print DATEI printLine( $i );
	 }

      }
      print DATEI "</table></BODY></HTML>";
      close DATEI;
   }
}



 
open DATEI, ">${idxprefix}noframes.inc";
for ( $i = 0; $i < $length; ++$i ) {
   $_ = printLine( $i, 1 );
   s/target="\w+"//g;
   print DATEI $_;
}
close DATEI;