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.6 - (hide annotations) (download) (as text)
Sat Aug 28 12:23:08 2004 UTC (19 years, 7 months ago) by hirami
Branch: MAIN
CVS Tags: Tombo1_12, V20041017, V20040828, V20041121, V20040915
Changes since 1.5: +68 -3 lines
File MIME type: text/x-perl
RDF support

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     next unless ($file =~ /\.tmpl/);
23     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     include_headline(OUT);
61     }
62 hirami 1.1 print OUT "$_\n";
63     }
64     close(BODY);
65     close(OUT);
66     }
67    
68     sub include_top()
69     {
70     my ($stream) = @_;
71     open(TOP, "$srcdir/$topfile") || die;
72     while(<TOP>) {
73     print $stream $_;
74     }
75     close(TOP);
76     }
77    
78     sub include_header()
79     {
80     my($stream) = @_;
81     open(HEADER, "$srcdir/$headerfile") || die;
82     while(<HEADER>) {
83     print $stream $_;
84     }
85     close(HEADER);
86     }
87    
88     sub include_menu()
89     {
90     my($stream) = @_;
91     print $stream '<table width="100%"><tr valign="top">'."\n";
92     print $stream '<td width="20%" bgcolor="#FAF0E6"'."\n";
93    
94     open(MENU, "$srcdir/$menufile") || die;
95     while(<MENU>) {
96 hirami 1.4 s/_PJHOME_/$pjhome/g;
97     s/_BASE_/$base/g;
98 hirami 1.1 print $stream $_;
99     }
100     close(MENU);
101    
102     print $stream '</td>'."\n";
103     print $stream '<td width="2%">'."\n";
104     print $stream '<td width="78%" bgcolor="#FFFFFF">'."\n";
105     }
106    
107     sub include_footer()
108     {
109     my($stream, $lastupd) = @_;
110     print $stream <<"HTML_FOOTER";
111     </td>
112     </tr>
113     </table>
114     <hr>
115     <table width="100%">
116 hirami 1.2 Copyright (C) 2000-2003, Tomohisa Hirami All rights reserved.<br>
117 hirami 1.3 Copyright (C) 2004, TOMBO maintainers All rights reserved.<br>
118 hirami 1.1 Last-Update: $lastupd
119     </table>
120     </body>
121     </html>
122     HTML_FOOTER
123     }
124 hirami 1.6
125     sub include_headline()
126     {
127     my ($stream) = @_;
128     opendir(DIR, "$srcdir/news") || die;
129     my @l = sort({$b <=> $a } readdir(DIR));
130     closedir(DIR);
131    
132     my $f, $d, $t, $sec, $headline, $dum;
133     $i = 0;
134     foreach $f(@l) {
135     next if ($f eq "." || $f eq "..");
136     next unless ($f =~ /^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})\.txt$/);
137     last if ($i > $num_headlines);
138     $d = "$1/$2/$3";
139     $t = "$4:$5";
140     $sec = "$1$2$3$4$5";
141    
142     open(F, "$srcdir/news/$f") || die;
143    
144     $headline = <F>;
145     chop($headline);
146    
147     print $stream " <li><a href=\"history.html#$sec\">$headline</a> ($d)</li>\n";
148    
149     close(F);
150     $i++;
151     }
152     }
153    
154     sub include_history()
155     {
156     my ($stream) = @_;
157     opendir(DIR, "$srcdir/news") || die;
158     my @l = sort( { $b <=> $a } readdir(DIR));
159     closedir(DIR);
160    
161     my $f, $d, $t, $sec, $headline, $dum;
162     foreach $f (@l) {
163     next if ($f eq "." || $f eq "..");
164     next unless ($f =~ /^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})\.txt$/);
165     $d = "$1-$2-$3";
166     $t = "$4:$5";
167     $sec = "$1$2$3$4$5";
168    
169     open(F, "$srcdir/news/$f") || die;
170    
171     $headline = <F>;
172     chop($headline);
173    
174     $dum = <F>; # skip blank line
175    
176     print $stream "<a name=\"$sec\" />\n";
177     print $stream "<h3>$d $headline</h3>\n";
178     while(<F>) {
179     print $stream $_;
180     }
181     close(F);
182     }
183    
184     }

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