Develop and Download Open Source Software

Browse CVS Repository

Annotation of /tombo/htdocs/pagegen.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (hide annotations) (download) (as text)
Mon Sep 11 17:18:55 2006 UTC (17 years, 7 months ago) by hirami
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +26 -2 lines
File MIME type: text/x-perl
beta 3

1 hirami 1.1 #! /usr/bin/perl
2    
3 hirami 1.5 #$base ="http://tombo.sourceforge.jp";
4 hirami 1.4 $pjhome="http://sourceforge.jp/projects/tombo";
5    
6 hirami 1.1 $menufile = "menu.txt";
7     $topfile = "title.txt";
8     $headerfile = "header.txt";
9 hirami 1.6 $num_headlines = 5;
10 hirami 1.4
11 hirami 1.5 if ($#ARGV != 2 || !-d $ARGV[0] || !-d $ARGV[1]) {
12     print "Usage : pagegen.pl <TMPLDIR> <OUTDIR> <BASE>\n";
13 hirami 1.1 exit 1;
14     }
15    
16     $srcdir = $ARGV[0];
17     $dstdir = $ARGV[1];
18 hirami 1.5 $base = $ARGV[2];
19 hirami 1.1
20     opendir(DIR_S, $srcdir) || die;
21     while($file = readdir(DIR_S)) {
22 hirami 1.9 next unless ($file =~ /\.tmpl$/);
23 hirami 1.1 pagegen($file);
24     }
25     closedir(DIR_S);
26     exit 0;
27    
28     sub pagegen() {
29     my ($file) = @_;
30    
31     my ($outfile) = $file;
32    
33     $outfile =~ s/\.tmpl$/\.html/;
34    
35     open(OUT, ">$dstdir/$outfile") || die "$dstdir/$outfile : $!";
36    
37     open(BODY, "$srcdir/$file") || die;
38     while(<BODY>) {
39     chop;
40     if (/^<!-- TOP -->$/) {
41     include_top(OUT);
42     next;
43     }
44     if (/^<!-- MENU -->$/) {
45     include_menu(OUT);
46     next;
47     }
48     if (/^<!-- HEADER -->$/) {
49     include_header(OUT);
50     next;
51     }
52     if (/^<!-- FOOTER +(\$.+\$) +-->$/) {
53     include_footer(OUT, $1);
54     next;
55     }
56 hirami 1.6 if (/^<!-- HISTORY -->$/) {
57     include_history(OUT);
58     }
59     if (/^<!-- HEADLINE -->$/) {
60 hirami 1.9 include_headline(OUT);
61     }
62     # if (/^<!-- DL\(([0-9a-zA-Z_]+), +([0-9]+)\) -->$/) {
63     if (/^<!-- DL\(([0-9a-zA-Z_]+), *([0-9]+)\) -->$/) {
64     expand_dl(OUT, $1, $2);
65 hirami 1.6 }
66 hirami 1.1 print OUT "$_\n";
67     }
68     close(BODY);
69     close(OUT);
70     }
71    
72 hirami 1.9 sub expand_dl()
73     {
74     my ($stream, $prefix, $dlid) = @_;
75     my ($rs, $disp, $arch, $suffix);
76     open(DL, "$srcdir/download.conf") || die;
77     while(<DL>) {
78     chop;
79     next if (/^#/);
80     ($rs, $disp, $arch, $suffix, $path, $cmt) = split(/ /);
81     if ($rs eq "") {
82     print $stream "<tr><td>$disp<td>$arch<td><a href=\"http://prdownloads.sourceforge.jp/tombo/$dlid/$prefix"."_$suffix.zip\">$prefix"."_$suffix.zip</a><td>$path<td>$cmt\n"
83     } elsif ($rs ne "c") {
84     print $stream "<tr><td rowspan=\"$rs\">$disp<td>$arch<td><a href=\"http://prdownloads.sourceforge.jp/tombo/$dlid/$prefix"."_$suffix.zip\">$prefix"."_$suffix.zip</a><td>$path<td>$cmt\n";
85     } else {
86     print $stream "<tr><td>$arch<td><a href=\"http://prdownloads.sourceforge.jp/tombo/$dlid/$prefix"."_$suffix.zip\">$prefix"."_$suffix.zip</a><td>$path<td>$cmt\n";
87     }
88     }
89     close(DL);
90     }
91    
92 hirami 1.1 sub include_top()
93     {
94     my ($stream) = @_;
95     open(TOP, "$srcdir/$topfile") || die;
96     while(<TOP>) {
97     print $stream $_;
98     }
99     close(TOP);
100     }
101    
102     sub include_header()
103     {
104     my($stream) = @_;
105     open(HEADER, "$srcdir/$headerfile") || die;
106     while(<HEADER>) {
107     print $stream $_;
108     }
109     close(HEADER);
110     }
111    
112     sub include_menu()
113     {
114     my($stream) = @_;
115     print $stream '<table width="100%"><tr valign="top">'."\n";
116     print $stream '<td width="20%" bgcolor="#FAF0E6"'."\n";
117    
118     open(MENU, "$srcdir/$menufile") || die;
119     while(<MENU>) {
120 hirami 1.4 s/_PJHOME_/$pjhome/g;
121     s/_BASE_/$base/g;
122 hirami 1.1 print $stream $_;
123     }
124     close(MENU);
125    
126     print $stream '</td>'."\n";
127     print $stream '<td width="2%">'."\n";
128     print $stream '<td width="78%" bgcolor="#FFFFFF">'."\n";
129     }
130    
131     sub include_footer()
132     {
133     my($stream, $lastupd) = @_;
134     print $stream <<"HTML_FOOTER";
135     </td>
136     </tr>
137     </table>
138     <hr>
139     <table width="100%">
140 hirami 1.2 Copyright (C) 2000-2003, Tomohisa Hirami All rights reserved.<br>
141 hirami 1.8 Copyright (C) 2004-2006, TOMBO maintainers All rights reserved.<br>
142 hirami 1.1 Last-Update: $lastupd
143     </table>
144     </body>
145     </html>
146     HTML_FOOTER
147     }
148 hirami 1.6
149     sub include_headline()
150     {
151     my ($stream) = @_;
152     opendir(DIR, "$srcdir/news") || die;
153     my @l = sort({$b <=> $a } readdir(DIR));
154     closedir(DIR);
155    
156     my $f, $d, $t, $sec, $headline, $dum;
157     $i = 0;
158     foreach $f(@l) {
159     next if ($f eq "." || $f eq "..");
160     next unless ($f =~ /^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})\.txt$/);
161     last if ($i > $num_headlines);
162     $d = "$1/$2/$3";
163     $t = "$4:$5";
164     $sec = "$1$2$3$4$5";
165    
166     open(F, "$srcdir/news/$f") || die;
167    
168     $headline = <F>;
169     chop($headline);
170    
171     print $stream " <li><a href=\"history.html#$sec\">$headline</a> ($d)</li>\n";
172    
173     close(F);
174     $i++;
175     }
176     }
177    
178     sub include_history()
179     {
180     my ($stream) = @_;
181     opendir(DIR, "$srcdir/news") || die;
182     my @l = sort( { $b <=> $a } readdir(DIR));
183     closedir(DIR);
184    
185     my $f, $d, $t, $sec, $headline, $dum;
186     foreach $f (@l) {
187     next if ($f eq "." || $f eq "..");
188     next unless ($f =~ /^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})\.txt$/);
189     $d = "$1-$2-$3";
190     $t = "$4:$5";
191     $sec = "$1$2$3$4$5";
192    
193     open(F, "$srcdir/news/$f") || die;
194    
195     $headline = <F>;
196     chop($headline);
197    
198     $dum = <F>; # skip blank line
199    
200     print $stream "<a name=\"$sec\" />\n";
201     print $stream "<h3>$d $headline</h3>\n";
202     while(<F>) {
203     print $stream $_;
204     }
205     close(F);
206     }
207    
208     }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26