* changed conf for BBBike
[chalow-eserte.git] / chalow
blobd490c2c37921de65a2741cec4bb99f9a0c529ca5
1 #!/usr/bin/perl
2 # $Id: chalow,v 1.1 2007-10-19 22:07:25+09 tatsuoyamashita Exp tatsuoyamashita $
4 # chalow - CHAngeLog On the Web - convert ChangeLog to HTML files
6 # This is free software with ABSOLUTELY NO WARRANTY.
7 # ̵½þ¡¦ÌµÊݾڡ¦Ãøºî¸¢Êü´þ (see http://nais.to/~yto/doc/zb/0002.html)
9 # chalow ¥Û¡¼¥à¥Ú¡¼¥¸: http://chalow.org/
10 use strict;
11 use Getopt::Long;
12 use POSIX qw(strftime ceil);
13 use Time::Local; # for ÍËÆü
14 use HTML::Template;
15 use ChangeLogReader;
17 my $version = '1.0';
19 # ¸½ºß»þ¹ï¤Î³ÍÆÀ
20 my $what_time_is_it_now = strftime "%Y-%m-%d %H:%M", localtime;
21 my $dcdate = strftime "%Y-%m-%dT%H:%M:%S+09:00", localtime;
22 my ($current_ym) = ($what_time_is_it_now =~ /^(\d+-\d+)/); # º£·î
24 ### ¥æ¡¼¥¶ÀßÄê¹àÌÜ obsolete
26 # ¼«Ê¬¤Î home page URL --- ÇÑ»ßͽÄê¡£¥Æ¥ó¥×¥ì¡¼¥È¤ËľÀܽñ¤¯Êý¿Ë¤Ç
27 my $home_page_url = "http://chalow.org/";
28 # ¼«Ê¬¤Î¥Û¡¼¥à¡¼¥Ú¡¼¥¸¤Î¸Æ¤Ó̾ --- ÇÑ»ßͽÄꡣƱ¾å
29 my $home_page_name = "chalow home page";
32 ### ¥æ¡¼¥¶ÀßÄê¹àÌÜ
33 ## ¥Ç¥Õ¥©¥ë¥ÈÀßÄê (¥æ¡¼¥¶ÀßÄê¥Õ¥¡¥¤¥ë̾¤¬»ØÄꤵ¤ì¤Æ¤Ê¤¤¤È¤­)
34 # Æüµ­¤Î̾Á°
35 my $changelog_name = "ChangeLog";
36 # ¼«Æ°Ê¸»úÎóÃÖ´¹
37 my $auto_replace = '
38 s!(<blockquote>)!</p>$1<p>!g;
39 s!(</blockquote>)!</p>$1<p>!g;
41 # CSS ¥Õ¥¡¥¤¥ë
42 my $css_file;
43 # RSS¥Õ¥¡¥¤¥ë̾
44 my $rss_filename = "cl.rdf";
45 # RSS¤ËºÇ¶á²¿Æüʬɽ¼¨¤¹¤ë¤«(0¤Î¾ì¹ç¤Ï $opt_topn ¤ÈƱ¤¸)
46 my $rss_topn = 0;
47 # ¥¤¥ó¥Ç¥Ã¥¯¥¹¥Ú¡¼¥¸(index.html)¤ÇºÇ¶á²¿Æüʬ¤òɽ¼¨¤¹¤ë¤«
48 my $opt_topn = 5;
49 # ÆüÉդθå¤ËÍËÆü(Mon, Tue, ...)¤òɽ¼¨¤¹¤ë¤« (1:yes or 0:no)
50 my $show_day_of_week = 1;
51 # ·î¥Ú¡¼¥¸¤Ç¡¢ÆüÉÕ¤ò¹ß½ç (¿·¤·¤¤ÆüÉÕ¤¬¾å) ¤Çɽ¼¨¤¹¤ë¤« (1:yes or 0:no)
52 my $reverse_order_days = 0;
54 # ¥¤¥ó¥Ç¥Ã¥¯¥¹¥Ú¡¼¥¸¤Î¥Æ¥ó¥×¥ì¡¼¥È
55 my $index_page_template = << "___INDEX_PAGE_TEMPLATE"
56 <html lang="ja"><head>
57 <meta http-equiv="Content-Type" content="text/html;charset=EUC-JP">
58 <TMPL_IF name=css_file>
59 <link rel=stylesheet href="<TMPL_VAR name=css_file>" media=all>
60 </TMPL_IF>
61 <link rel="alternate" type="application/rss+xml" title="RSS"
62 href="<TMPL_VAR name=rss_file>">
63 <title><TMPL_VAR name=cl_name></title>
64 </head><body>
65 <a href="<TMPL_VAR name=rss_file>">RSS</a>
66 <h1><a href="index.html"><TMPL_VAR name=cl_name></a></h1>
67 <p class="calendar"><TMPL_VAR name=ym> / <TMPL_VAR name=day_list></p>
68 <p>last update: <TMPL_VAR name=lastupdate></p>
69 <p class="calendar"><TMPL_VAR name=month_page_list></p>
70 <p>recent <TMPL_VAR name=ndays> days</p>
71 <TMPL_LOOP name=entries><TMPL_VAR name=content></TMPL_LOOP>
72 <TMPL_VAR name=signature>
73 </div></body></html>
74 ___INDEX_PAGE_TEMPLATE
77 # ·î¥Ú¡¼¥¸¤Î¥Æ¥ó¥×¥ì¡¼¥È
78 my $month_page_template = << "___MONTH_PAGE_TEMPLATE"
79 <html lang="ja"><head>
80 <meta http-equiv="Content-Type" content="text/html;charset=EUC-JP">
81 <TMPL_IF name=css_file>
82 <link rel=stylesheet href="<TMPL_VAR name=css_file>" media=all>
83 </TMPL_IF>
84 <link rel="alternate" type="application/rss+xml" title="RSS"
85 href="<TMPL_VAR name=rss_file>">
86 <title><TMPL_VAR name=cl_name> / <TMPL_VAR name=ym></title>
87 </head><body>
88 <TMPL_IF name=back><a href="<TMPL_VAR name=back>.html">Prev Month</a></TMPL_IF>
89 <TMPL_IF name=next> / <a href="<TMPL_VAR name=next>.html">Next Month</a></TMPL_IF>
90 <h1><a href="index.html"><TMPL_VAR name=cl_name></a> <TMPL_VAR name=ym></h1>
91 <p class="calendar"><TMPL_VAR name=day_list></p>
92 <p class="calendar"><TMPL_VAR name=month_page_list></p>
93 <TMPL_LOOP name=entries><TMPL_VAR name=content></TMPL_LOOP>
94 <p>last update: <TMPL_VAR name=lastupdate></p>
95 <TMPL_VAR name=signature>
96 </div></body></html>
97 ___MONTH_PAGE_TEMPLATE
100 # Æü¥Ú¡¼¥¸¤Î¥Æ¥ó¥×¥ì¡¼¥È
101 my $day_page_template = << "___DAY_PAGE_TEMPLATE"
102 <html lang="ja"><head>
103 <meta http-equiv="Content-Type" content="text/html;charset=EUC-JP">
104 <TMPL_IF name=css_file>
105 <link rel=stylesheet href="<TMPL_VAR name=css_file>" media=all>
106 </TMPL_IF>
107 <link rel="alternate" type="application/rss+xml" title="RSS"
108 href="<TMPL_VAR name=rss_file>">
109 <title><TMPL_VAR name=cl_name> / <TMPL_VAR name=ymd></title>
110 </head><body>
111 <TMPL_IF name=back><a href="<TMPL_VAR name=back>.html">Prev Day</a></TMPL_IF>
112 <TMPL_IF name=next> / <a href="<TMPL_VAR name=next>.html">Next Day</a></TMPL_IF>
113 <h1><a href="index.html"><TMPL_VAR name=cl_name></a></h1>
114 <TMPL_VAR name=content>
115 <p class="calendar"><a href="<TMPL_VAR name=ym>.html"><TMPL_VAR name=ym></a>
116 / <TMPL_VAR name=day_list></p>
117 <p class="calendar"><TMPL_VAR name=month_page_list></p>
118 <p>last update: <TMPL_VAR name=lastupdate></p>
119 <TMPL_VAR name=signature>
120 </div></body></html>
121 ___DAY_PAGE_TEMPLATE
124 # ¥¢¥¤¥Æ¥à¥Ú¡¼¥¸¤Î¥Æ¥ó¥×¥ì¡¼¥È
125 my $item_page_template = << "___PAGE_TEMPLATE"
126 <html lang="ja"><head>
127 <meta http-equiv="Content-Type" content="text/html;charset=EUC-JP">
128 <TMPL_IF name=css_file>
129 <link rel=stylesheet href="<TMPL_VAR name=css_file>" media=all>
130 </TMPL_IF>
131 <link rel="alternate" type="application/rss+xml" title="RSS"
132 href="<TMPL_VAR name=rss_file>">
133 <title><TMPL_VAR name=header_text></title>
134 </head><body>
135 <TMPL_IF name=back><a href="<TMPL_VAR name=back>.html">Prev</a></TMPL_IF>
136 <TMPL_IF name=next> / <a href="<TMPL_VAR name=next>.html">Next</a></TMPL_IF>
137 / <a href="index.html"><TMPL_VAR name=cl_name></a>
138 <h1><TMPL_VAR name=header><TMPL_VAR name=cat></h1>
139 <div class="day">
140 <a href="<TMPL_VAR name=ymd>.html"><TMPL_VAR name=ymd></a>
141 <div class="body">
142 <!-- start:<TMPL_VAR name=ymdi> -->
143 <div class="section">
144 <p><TMPL_VAR name=content></p>
145 <TMPL_IF name=referrer>
146 <div class="referer"><span>Referrer (Inside):
147 <TMPL_VAR name=referrer></span></div>
148 </TMPL_IF>
149 <p><a href="<TMPL_VAR name=ymdi>.html">permlink</a></p>
150 </div>
151 <!-- end:<TMPL_VAR name=ymdi> -->
152 </div></div>
153 <!--<p>last update: <TMPL_VAR name=lastupdate></p>-->
154 <TMPL_VAR name=signature>
155 </div></body></html>
156 ___PAGE_TEMPLATE
159 # ¥«¥Æ¥´¥ê¥Ú¡¼¥¸¤Î¥Æ¥ó¥×¥ì¡¼¥È
160 my $cat_page_template = << "TMPL"
161 <html lang="ja"><head>
162 <meta http-equiv="Content-Type" content="text/html;charset=EUC-JP">
163 <TMPL_IF name=css_file>
164 <link rel=stylesheet href="<TMPL_VAR name=css_file>" media=all>
165 </TMPL_IF>
166 <link rel="alternate" type="application/rss+xml" title="RSS"
167 href="<TMPL_VAR name=rss_file>">
168 <title><TMPL_VAR name=cat_name> / <TMPL_VAR name=cl_name></title>
169 </head><body>
170 <TMPL_IF name=page_list><TMPL_VAR name=page_list></TMPL_IF>
171 <h1><TMPL_VAR name=cat_name> -
172 <a href="index.html"><TMPL_VAR name=cl_name></a></h1>
173 <div>
174 <TMPL_LOOP name=entries>
175 <div class="day"><h2><span class="date"><TMPL_VAR name=eh></span></h2>
176 <div class="body"><TMPL_VAR name=cont></div></div>
177 </TMPL_LOOP>
178 <p>last update: <TMPL_VAR name=lastupdate></p>
179 <TMPL_VAR name=signature>
180 </div></body></html>
181 TMPL
184 # item ¤Î¥Æ¥ó¥×¥ì¡¼¥È
185 my $item_template = << "EACHITEM"
186 <!-- start:<TMPL_VAR name=ymdi> -->
187 <div class="section">
188 <p><TMPL_VAR name=header><TMPL_VAR name=cat><TMPL_VAR name=content></p>
189 <TMPL_IF name=referrer>
190 <div class="referer"><span>Referrer (Inside):
191 <TMPL_VAR name=referrer></span></div>
192 </TMPL_IF>
193 </div>
194 <!-- end:<TMPL_VAR name=ymdi> -->
195 EACHITEM
198 # entry (date) ¤Î¥Æ¥ó¥×¥ì¡¼¥È
199 my $entry_template = << "DAYENTRY"
200 <div class="day">
201 <h2><span class="date"><TMPL_VAR name=header></span></h2>
202 <div class="body">
203 <TMPL_IF name=message_top><TMPL_VAR name=message_top></TMPL_IF>
204 <TMPL_IF name=same_date><div class="calendar"><TMPL_VAR name=same_date></div>
205 </TMPL_IF>
206 <TMPL_VAR name=content>
207 <TMPL_IF name=referrer>
208 <div class="referer"><span>Referrer (Inside):
209 <TMPL_VAR name=referrer></span></div>
210 </TMPL_IF>
211 <TMPL_IF name=message_bottom><TMPL_VAR name=message_bottom></TMPL_IF>
212 </div>
213 </div>
214 DAYENTRY
217 # RSS¥Õ¥¡¥¤¥ë¤Î¥Æ¥ó¥×¥ì¡¼¥È
218 my $rss_template = << "RDFSTR"
219 <?xml version="1.0" encoding="utf-8"?>
220 <rdf:RDF
221 xmlns="http://purl.org/rss/1.0/"
222 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
223 xmlns:dc="http://purl.org/dc/elements/1.1/"
224 xmlns:content="http://purl.org/rss/1.0/modules/content/"
225 xmlns:admin="http://webns.net/mvcb/"
226 xml:lang="ja">
227 <channel rdf:about="<TMPL_VAR name=clog_url_pref><TMPL_VAR name=rss_file>">
228 <title><TMPL_VAR name=changelog_name></title>
229 <link><TMPL_VAR name=clog_url></link>
230 <description><TMPL_VAR name=changelog_description></description>
231 <dc:language>ja</dc:language>
232 <dc:date><TMPL_VAR name=dcdate></dc:date>
233 <admin:generatorAgent rdf:resource="<TMPL_VAR name=generatorAgent>"/>
234 <items>
235 <rdf:Seq><TMPL_LOOP name=items>
236 <rdf:li rdf:resource="<TMPL_VAR name=permlink>"/></TMPL_LOOP>
237 </rdf:Seq>
238 </items>
239 </channel>
240 <TMPL_LOOP name=items>
241 <item rdf:about="<TMPL_VAR name=permlink>">
242 <title><TMPL_VAR name=itemheader></title>
243 <link><TMPL_VAR name=permlink></link>
244 <description>
245 <TMPL_VAR name=itemcontent>
246 </description>
247 <dc:creator><TMPL_VAR name=itemauthor></dc:creator>
248 <dc:date><TMPL_VAR name=item_dcdate></dc:date>
249 <content:encoded>
250 <![CDATA[<TMPL_VAR name=itemcontentencoded>]]>
251 </content:encoded>
252 </item>
253 </TMPL_LOOP>
254 </rdf:RDF>
255 RDFSTR
258 # ɽ¼¨¤¹¤ë¤È¤­°úÍѵ­¹æ ('>' or '|') ¤ò¾Ã¤¹¤« (1:YES, 0:NO)
259 my $remove_quote_mark = 0;
261 # ÆüÉÕ°ìÍ÷¤ò¥«¥ì¥ó¥À¡¼É½¼¨¤Ë¤¹¤ë¤« (1:YES, 0:NO)
262 my $calendar_style = 0;
264 # ¥¢¥¤¥Æ¥à¥Ø¥Ã¥À¡¼¤Î¥Õ¥©¡¼¥Þ¥Ã¥È¤ò¤É¤¦¤¹¤ë¤«
265 # (0:"* HOGE:", 1:"* HOGE", 2:"HOGE:",3:"HOGE")
266 my $item_header_style = 0;
267 # item header ¤Ç h3 ¥¿¥°¤ò»È¤¦¤« (1:YES, 0:NO) - tDiary ¤È¤Î¸ß´¹À­¤Î¤¿¤á
268 my $use_h3_for_item_header = 0;
269 # item header ¤ÎÀèƬ¤Îµ­¹æ¤Ë¥¢¥ó¥«¡¼¤ò¤Ä¤±¤ë¤« (1:YES, 0:NO)
270 my $use_item_anchor = 1;
271 # item header ¤ÎÀèƬ¤Îµ­¹æ¤Î»ØÄê
272 # ¡ØÆüµ­¤Î¥»¥¯¥·¥ç¥ó¤ÎÀèƬ(¥µ¥Ö¥¿¥¤¥È¥ë¤Î¹ÔƬ)¤ËÁÞÆþ¤µ¤ì¤ë¡¢¥ê¥ó¥¯ÍѤÎ
273 # ¥¢¥ó¥«¡¼Ê¸»úÎó¤ò»ØÄꤷ¤Þ¤¹¡£¤Ê¤ª¡Ö<span class="panchor">_</span>¡×¤ò
274 # »ØÄꤹ¤ë¤È¡¢¥Æ¡¼¥Þ¤Ë¤è¤Ã¤Æ¤Ï¼«Æ°Åª¤Ë²èÁü¥¢¥ó¥«¡¼¤¬¤Ä¤¯¤è¤¦¤Ë¤Ê¤ê¤Þ
275 # ¤¹¡£¡Ù(tDiary ¤Î skel/conf.rhtml ¤è¤ê)
276 my $item_header_mark = '<span class="sanchor">*</span>';
278 # ¾¤Îǯ¤ÎƱ¤¸ÆüÉÕ (·îÆü) ¤Ø¤Î¥ê¥ó¥¯¤òÄ¥¤ë¤« (1:YES, 0:NO)
279 my $same_date_jump = 1;
280 # # ³Æ¥¢¥¤¥Æ¥à¤Ëµ­½Ò¼Ô̾¤òɽ¼¨¤¹¤ë¤« (1:YES, 0:NO)
281 # my $show_author_name = 0;
283 # RSS ¤ò½ÐÎϤ¹¤ë¤« (1:YES, 0:NO)
284 my $output_rss = 1;
285 # Æüµ­¤ÎÀâÌÀ for RSS : Îã: "Æü¡¹¤Î¤¢¤ì¤³¤ì¡£"
286 my $changelog_description = "";
287 # ChangeLog ¤ò¸ø³«¤¹¤ë URL (ÀäÂÎ URL ¤ò¶¯¤¯¿ä¾©) - RSS ¤Ëɬ¿Ü
288 #my $clog_url = "http://chalow.net/";
289 my $clog_url = "./";
291 # ¸¡º÷ÍÑ¥Õ¥¡¥¤¥ë (cl.itemlist) ¤òºî¤ë¤« (1:YES, 0:NO)
292 my $output_itemlist = 1;
293 # ¸«½Ð¤·°ìÍ÷ (JavaScript ¥Õ¥¡¥¤¥ë) ¤Ç½ÐÎϤ¹¤ëÆü¿ô
294 my $latest_titles_num = 10;
296 # Æü¤´¤È¤Ë¥Ú¡¼¥¸¤òºî¤ë¤« (0:NO, 1:YES) --- obsolete
297 my $day_page_mode = 0;
298 # ºîÀ®¤¹¤ë¥Ú¡¼¥¸¤Îñ°Ì¡áºÇ¾®¥Ú¡¼¥¸Ã±°Ì (0:·î, 1:Æü, 2:¥¢¥¤¥Æ¥à)
299 my $page_mode = 0;
301 # ¥«¥Æ¥´¥ê¥Ú¡¼¥¸¤òºî¤ë¤« (0:NO, 1:YES)
302 my $output_cat_pages = 1;
303 # ¥«¥Æ¥´¥ê¥Ú¡¼¥¸Ãæ¤Î¥¨¥ó¥È¥ê¿ô¤Î¾å¸Â
304 # ($output_cat_pages = 1 ¤Î¤È¤­¤Î¤ßÍ­¸ú)
305 my $cat_page_entry_max = 10;
306 # ¥«¥Æ¥´¥êÊÌitemɽ¼¨¤Î¤¿¤á¤ÎCGI¤ò»ØÄꤹ¤ë¡Ê¥«¥Æ¥´¥ê̾¤Ï %%CAT%% ¤ÇÃÖ¤­´¹¤¨¡Ë
307 # ($output_cat_pages = 0 ¤Î¤È¤­¤Î¤ßÍ­¸ú)
308 my $cat_page_cgi = "clsearch.cgi?cat=%%CAT%%";
309 #my $cat_page_cgi = "";
311 # ¥Õ¥¡¥¤¥ë¤ÎºÇ½é¤Ë½Ð¤Æ¤¯¤ë¡Ö<!-- ReplaceOnce -->¡×¤òÃÖ¤­´¹¤¨¤ëʸ»úÎó
312 my $replace_once = "";
314 # UTF8 mode (0:OFF, 1:ON)
315 my $utf8_mode = 0;
317 # Read More mode (0:OFF, 1:ON)
318 my $readmore_mode = 1;
319 # Read More tag
320 my $readmore_tag = "====";
322 ### chalow ÉáµÚ¤Î¤¿¤á HTML ¤Î°ìÈÖ²¼¤Ë¥ê¥ó¥¯¤òɽ¼¨¤¹¤ë¡£¤Ç¤­¤ì¤Ð¾Ã¤µ¤Ê¤¤¤Ç¡£
323 my $signature = qq(<p class="footer">Powered by
324 <a href="http://chalow.org/">chalow</a></p>);
326 ### ¥³¥Þ¥ó¥É¥é¥¤¥ó°ú¿ô
327 Getopt::Long::Configure('bundling');
328 my ($opt_topn_tmp, $outputdir, $quiet_mode, $opt_css_file, $debug_mode,
329 $update_by_size, $conf_file, $stop_date);
330 my $gor = GetOptions('n|top-n=n' => \$opt_topn_tmp,
331 'o|output-dir=s' => \$outputdir,
332 'c|configure-file=s' => \$conf_file,
333 's|stop-date=s' => \$stop_date,
334 'u|update-by-size' => \$update_by_size,
335 'C|css=s' => \$opt_css_file,
336 'q|quiet' => \$quiet_mode,
337 '8|utf8' => \$utf8_mode,
338 'd|debug' => \$debug_mode,
339 'name=s' => \$changelog_name,
342 if (@ARGV == 0 or $gor == 0) {
343 print << "USAGE";
344 usage: chalow [options] <file> [file]...
345 -n, --top-n=NUM write NUM days to "index.html"
346 -o, --output-dir=DIR directory to output
347 -c, --configure-file=FILE configure file
348 -s, --stop-date=DATE date to stop processing
349 -u, --update-by-size overwrite only if sizes are different
350 -C, --css=FILE css file
351 -q, --quiet quiet mode
352 -8, --utf8 utf8 mode
353 -d, --debug debug mode
354 USAGE
356 exit;
359 # ¥æ¡¼¥¶ÀßÄê¥Õ¥¡¥¤¥ë¤ÎÆɤ߹þ¤ß (¥Õ¥¡¥¤¥ë̾¤¬»ØÄꤵ¤ì¤Æ¤¿¤È¤­¤Î¤ß)
360 if ($conf_file ne "") {
361 open(CONF, $conf_file) or die "Can't open $conf_file : $!\n";
362 binmode(CONF);
363 my $conf = join('', <CONF>);
364 # $conf = Jcode->new($conf)->euc; # del 050412
365 eval $conf;
366 die qq(error in "$conf_file" (obsolete variable?): $@\n) if ($@);
369 $outputdir = "." if (not defined $outputdir);
371 # ¥æ¡¼¥¶ÀßÄê¥Õ¥¡¥¤¥ë¤è¤ê¥³¥Þ¥ó¥É¥é¥¤¥ó»ØÄê¤òÍ¥À褹¤ë½èÍý
372 $opt_topn = $opt_topn_tmp if (defined $opt_topn_tmp);
373 $css_file = $opt_css_file if (defined $opt_css_file);
375 # ½èÍýÄä»ßÆüÉÕ: ʸ»úÎó¤À¤Ã¤¿¤â¤Î¤ò¿ôÃͤˤ¹¤ë¡£¸å¤Ç¿ôÃͤȤ·¤ÆÆüÉÕ¤ÎÈæ³Ó
376 # ¤Ë»È¤¦¤«¤é¡£
377 $stop_date =~ s/-//g;
379 my $latest_item_list;
380 my $category_list;
382 my $clog_url_pref = $clog_url;
383 $clog_url_pref =~ s!/[^/]+html?$!/!;
384 $clog_url_pref .= "/" unless ($clog_url_pref =~ m!/$!);
385 # SPEC: $clog_url $clog_url_pref
386 # http://chalow.net/ -> http://chalow.net/
387 # http://chalow.net/index.html -> http://chalow.net/
388 # http://chalow.net -> http://chalow.net/
390 my %month_page; # ·îÊ̤Υڡ¼¥¸
391 my %category_item; # ¥«¥Æ¥´¥êÊÌ¥Ú¡¼¥¸ÍÑ item
392 my %inside_ref; # ÆüÉÕ¥ê¥ó¥¯¤Ë¤è¤ë¥ê¥Õ¥¡¥é¡¼
394 #my %all_entries; # hash for all ChangeLog entries
395 # {XXXX-XX-XX}{"eh"} - Entry header
396 # {XXXX-XX-XX}{1,2,3,...}{"ho"} - Item header (original text)
397 # {XXXX-XX-XX}{1,2,3,...}{"co"} - Item content (original text)
398 # {XXXX-XX-XX}{1,2,3,...}{"cat"} - Category (array)
399 # {XXXX-XX-XX}{1,2,3,...}{"a"} - Author
400 # {XXXX-XX-XX}{"message-top"} - Pragma item
401 # {XXXX-XX-XX}{"message-bottom"} - Pragma item
402 # {XXXX-XX-XX}{curid} - Item ID manager
403 # {XXXX-XX-XX}{1,2,3,...}{"h"} - ¥¢¥¤¥Æ¥à¥Ø¥Ã¥À
404 # {XXXX-XX-XX}{1,2,3,...}{"c"} - ÃæÌ£
406 my $cl = ChangeLogReader->new(stop_date => $stop_date);
408 for my $fname (@ARGV) {
409 print "reading \"$fname\"\n" if (!defined $quiet_mode);
410 $cl->store_changelog_file($fname);
413 print "done.\nconverting\n" if (!defined $quiet_mode);
415 foreach my $ymd (reverse sort keys %{$cl->{all}}) {
416 parse_entry($ymd, \%{$cl->{all}->{$ymd}});
419 print "done.\n" if (!defined $quiet_mode);
421 # ·îÊÌ°ìÍ÷¤òºîÀ®¤·¤Æ¤ª¤¯
422 my $month_page_list = make_month_page_list($cl->{STAT}->{ym});
424 # º£·î¤ÎÆüÉÕ°ìÍ÷¤òºîÀ®¤·¤Æ¤ª¤¯
425 my $current_day_list = make_day_list_str($current_ym);
427 ### À¸À®(1)
428 write_rss_file() if ($output_rss); # RSS ¥Õ¥¡¥¤¥ë¤òºî¤ë
429 write_itemlist_file() if ($output_itemlist); # ¸¡º÷ÍÑ¥Õ¥¡¥¤¥ë(itemlist)¤òºî¤ë
430 write_latest_item_list_file(); # ºÇ¶á¤ÎÏÃÂê°ìÍ÷¤òºî¤ë
431 write_category_list_file(); # ¥«¥Æ¥´¥ê°ìÍ÷¤òºî¤ë
433 ### HTML À¸À®¤Î¤¿¤á¤Î¥ë¡¼¥×
434 foreach my $ymd (sort keys %{$cl->{all}}) {
435 my $e = $cl->{all}->{$ymd};
436 my @items;
437 foreach my $i (sort {$b <=> $a} keys %{$e}) {
438 next if ($i !~ /^\d/);
439 push @items, make_item_html($e, $ymd, $i);
441 my ($y, $m, $d) = ($ymd =~ /^(\d{4})-(\d\d)-(\d\d)$/);
442 $month_page{"$y-$m"}{$ymd}{str} = make_entry_html($e, $ymd, \@items);
445 ### À¸À®(2) HTML ¥Õ¥¡¥¤¥ë¤Î½ÐÎÏ
446 write_index_page();
447 write_month_page();
448 write_day_page() if ($day_page_mode or $page_mode >= 1);
449 write_item_page() if ($page_mode == 2);
450 write_category_page() if ($output_cat_pages);
452 print "done.\n" if (!defined $quiet_mode);
454 exit;
457 ### ¥¨¥ó¥È¥ê¤ò¥Ñ¡¼¥º¤·¤Æ³ÊǼ¤¹¤ë
458 sub parse_entry {
459 my ($ymd, $ent) = @_;
460 for (my $i = $ent->{curid}; $i >= 1; $i--) {
461 my $c = $ent->{$i}->{co};
462 $c =~ s/^\s*\n//g if ($use_h3_for_item_header == 1);
463 $ent->{$i}{h} = okikae($ent->{$i}{ho}, $ymd, $i);
464 $ent->{$i}{c} = okikae($c, $ymd, $i);
469 ### ʸ»úÎó¤ÎÃÖ¤­´¹¤¨
470 sub okikae {
471 local ($_) = shift;
472 my ($ymd, $i) = @_; # ²¿¤«¤Ë»È¤¨¤ë¤«¤Ê?
474 escape_string(\$_);
476 # ÆüÉÕ¥ê¥ó¥¯¾ðÊó¤Î³ÊǼ - parse_entry ¤Ë¤¢¤Ã¤¿¤¬¡¢escape¸å¤Ë¹Ô¤Ê¤Ã
477 # ¤¿Êý¤¬¤è¤¤¤È»×¤Ã¤¿¤Î¤Ç¤³¤Á¤é¤Ë°ÜÆ°(5.1.19)
478 while (/\[((\d\d\d\d-\d\d)-\d\d(-\d+)?)\]/g) {
479 $inside_ref{$1}{"$ymd-$i"}++;
482 s/&/&amp;/go;
483 s/\]>/\]&gt;/go;
484 # s/>/&gt;/go; # > ¤¬ &.. ¤Ë¤Ê¤ë¤È¡¢URL ¤È¤«°úÍѤΥޥåÁ¶¸¤¦
485 # s/"/&quot;/go; # ";
486 ### "<" ¤ÏÃÖ¤­´¹¤¨¤ë¡£
487 s|<(/?[a-z!]+)|&lt;$1|gio;
488 # s|<(/?[a-z]+)|&lt;$1|gio; # ¥³¥á¥ó¥È (<!-- -->) ¤ò¤Î¤³¤·¤¿¤¤¾ì¹ç¤Ï¤³¤ì
489 # ¥«¥¹¥¿¥Þ¥¤¥º¤Î¥Ò¥ó¥È: <s></s> ¤ò»Ä¤¹¢ª
490 # s|<(/?[a-rt-z]+)|&lt;$1|gi; <b> ¤ò»Ä¤¹¢ª
491 # s|<(/?[ac-z]+)|&lt;$1|gi; (ÉûºîÍÑ = <br> ¤Ê¤É¤â»Ä¤ë)
493 ### Read More ###
494 s!^$readmore_tag$(.*)$!<div class="readmore">$1</div>!sm;
496 ### ʸ»ú½¤¾þ¤È¿åÊ¿Àþ¡£Hiki ¤Îµ­Ë¡¤òºÎÍÑ¡£
497 s!'''(.+?)'''!<strong>$1</strong>!gms;
498 s!''(.+?)''!<em>$1</em>!gms;
499 s!==(\S.+?)==!<s>$1</s>!gms;
500 s!^\-{4}!<hr>!gms;
502 ### URL¡£Hiki ¤Îµ­Ë¡¤òºÎÍÑ¡£
503 s!\[\[(.+?)\s*\|\s*(.+?)\]\]!get_link_str($1, $2)!gmse;
505 ### ɽ¡£Hiki ¤Îµ­Ë¡¤òºÎÍÑ¡£
506 s!(^(\|\|[^\n]+\n)+)!'<table><tr>'.
507 (join("<tr>", (map {join('<td>', split(/\|\|/ ,$_))} split(/\n/, $1))))
508 .'</table>'!gsme;
510 ### °úÍÑ (quote): ">>" ¤È "<<" ¤Ç°Ï¤à
511 s!^>>\n!<blockquote>!gm;
512 s!^<<\n!</blockquote>!gm;
514 ### °úÍÑ (quote): "| ..." ¤« "> ..."
515 if ($remove_quote_mark == 1) {
516 my $a;
517 s!((^((\||>)[^\n]*)\n)+)!'<blockquote>'.($a = $1,
518 $a =~ s{^(\||>)\s?}{}gm, $a).'</blockquote>'!gme;
519 } else {
520 s!((^((\||>)[^\n]*)\n)+)!<blockquote>$1</blockquote>!gmx;
523 ### ÆüÉդǻ²¾È¥ê¥ó¥¯
524 # date ref : [YYYY-MM-DD]
525 $_ = datestr2anchor($_);
527 ### URLɽµ­¤ò href ¤Ç
528 # URL : http://....
529 # Àµµ¬É½¸½¤Ï http://www.din.or.jp/~ohzaki/perl.htm#httpURL ¤è¤ê¡£
530 # ¥Ð¥Ã¥¯¥¹¥é¥Ã¥·¥å¤òÍѤ¤¤¿URLÃæ¤Ç¤Î²þ¹Ô¤ËÂбþ 021025
531 #my $URLCHARS = "[-_.!~*'()a-zA-Z0-9;/?:@&=+,%\#\$]";
532 my $URLCHARS = "[-_.!~*'a-zA-Z0-9;/?:@&=+,%\#\$]";
533 my $URLDELIM = "\\\\\\n *";
534 s{(?<![\"\=|])((s?https?|ftp)://($URLCHARS+)($URLDELIM($URLCHARS+))*)}
535 {'<a href="'.join('', split(/$URLDELIM/, $1)).'">'.
536 join('', split(/\\/, $1)).'</a>'}gem; #")};
538 ### ¹ÔƬ¤Î¥¹¥Ú¡¼¥¹¤Ï &nbsp; ¤ËÃÖ¤­´¹¤¨¤ë¡£
539 s!^( +)!{"&nbsp;" x length($1)}!gme;
540 s!^(</?blockquote>)( +)!{"$1" . ("&nbsp;" x length($2))}!gme;
542 ### ¼«Æ°Ê¸»úÎóÃÖ´¹Å¬ÍÑ
543 eval $auto_replace;
545 # ³Æ¹Ô¤Î¹ÔËö¤Ë <br> ¤òÉÕ¤±¤ë
546 # memo: ÀÎ¤Ï pre ¤Ç°Ï¤ó¤Ç¤¤¤¿¤¬¡¢v0.23 ¤«¤é¤ä¤á¤¿
547 #print "1[$_]\n";
548 s!$!<br>!gsm;
549 s!<br>$!!;
550 #print "2[$_]\n";
552 unescape_string(\$_); # ¥×¥é¥°¥¤¥ó¸Æ¤Ó½Ð¤·¤â¹Ô¤Ê¤¦
554 s!</pre><br>!</pre>!g; # ad hoc
556 return $_;
560 ### ¥¢¥¤¥Æ¥à¤òHTML¤ËÊÑ´¹
561 sub make_item_html {
562 my ($e, $ymd, $i) = @_;
564 ### item header
565 my $ih = make_item_header_html($e->{$i}{h}, $ymd."-".$i);
567 ### ¥«¥Æ¥´¥ê
568 my $catstr = make_cat_link_html($e->{$i}{cat});
570 ### ÆüÉÕ¥ê¥ó¥¯¤Ë¤è¤ë¥ê¥Õ¥¡¥é¡¼
571 my @inside_refs = get_inside_ref("$ymd-$i");
573 ### item ¤Î´ðÁþðÊó
574 my $item_url = datestr2url("$ymd-$i");
575 my $item_ymdi = $ymd."-".$i;
576 (my $item_id = $ymd.$i) =~ s/-//g; # Ex. "200309241"
578 ### item ¤ÎÁȤ߾夲
579 my $t = HTML::Template->new(scalarref => \$item_template,
580 die_on_bad_params => 0);
581 my $ccc = $e->{$i}{c};
582 if ($page_mode == 2 and $readmore_mode) {
583 if ($ccc =~ s!(<div class="readmore">.*</div>)$!!sm) {
584 my $readmore_str = $1;
585 $t->param(readmore => $readmore_str);
588 $t->param(content => $ccc);
589 $t->param(header => $ih);
590 $t->param(cat => $catstr);
591 $t->param(author => $e->{$i}{a});
592 $t->param(referrer => join(" ", @inside_refs));
593 $t->param(id => $item_id);
594 $t->param(ymdi => $item_ymdi);
595 $t->param(url => $item_url);
596 $t->param(rss_file => $rss_filename); # 050821
597 my $this_item = $t->output();
599 if ($output_cat_pages == 1) { # ¥«¥Æ¥´¥êÊÌ¥Ú¡¼¥¸¤ò½Ð¤¹¤È¤­¤Î½èÍý
600 my $ent_h = make_entry_header_html($e->{eh}, $ymd);
601 foreach (@{$e->{$i}{cat}}) {
602 # ¥«¥Æ¥´¥êÊÌ¥Ú¡¼¥¸¤Ï --stop-date ¤ÈÁêÀ­¤¬°­¤¤¤Î¤ÇÃí°Õ
603 push @{$category_item{$_}}, {eh=>$ent_h, cont=>$this_item};
606 return $this_item;
610 ### ¥¨¥ó¥È¥ê¤òHTML¤ËÊÑ´¹
611 sub make_entry_html {
612 my ($e, $ymd, $itemsp) = @_;
614 ### entry header
615 my $ent_h = make_entry_header_html($e->{eh}, $ymd);
617 my ($y, $m, $d) = ($ymd =~ /^(\d{4})-(\d\d)-(\d\d)$/);
619 ### ¾¤Îǯ¤ÎƱ¤¸ÆüÉÕ (·îÆü) ¤Ø¤Î¥ê¥ó¥¯¤òÄ¥¤ë
620 my @same_dates;
621 if ($same_date_jump == 1) {
622 if (defined $cl->{STAT}->{md}{"$m-$d"}) {
623 my @ys = sort keys %{$cl->{STAT}->{md}{"$m-$d"}};
624 @same_dates = map {"<a href=\"".datestr2url("$_-$m-$d").
625 "\">$_</a>"} grep {$_ != $y} @ys;
629 ### ÆüÉÕ¥ê¥ó¥¯¤Ë¤è¤ë¥ê¥Õ¥¡¥é¡¼
630 my @inside_refs = get_inside_ref("$ymd");
632 ### entry ¤Î´ðÁþðÊó
633 my $entry_url = datestr2url($ymd);
634 my $entry_ymd = $ymd;
635 # my $entry_id = $ymd; $entry_id =~ s/-//g; # Ex. "20030924"
636 (my $entry_id = $ymd) =~ s/-//g; # Ex. "20030924"
638 ### ¥¨¥ó¥È¥ê¤ÎÁȤ߾夲
639 my $t = HTML::Template->new(scalarref => \$entry_template,
640 die_on_bad_params => 0);
641 $t->param(header => $ent_h);
642 $t->param(message_top => $e->{"message-top"});
643 $t->param(message_bottom => $e->{"message-bottom"});
644 $t->param(referrer => join(" ", @inside_refs));
645 $t->param(same_date => join(" ", @same_dates));
646 $t->param(id => $entry_id);
647 $t->param(ymd => $entry_ymd);
648 $t->param(url => $entry_url);
649 $t->param(rss_file => $rss_filename); # 050821
650 $t->param(content => @{[join('', @{$itemsp})]});
651 return $t->output();
655 ### ¥«¥Æ¥´¥êÊÌ¥Ú¡¼¥¸(ex: cat_life.html)¤òºî¤ë¡£
656 sub write_category_page {
657 my @cat_list = keys %category_item;
659 foreach my $catname (@cat_list) {
661 my @ents = sort {$b->{eh} cmp $a->{eh}} @{$category_item{$catname}};
663 my $n = $cat_page_entry_max;
664 my $num_of_old_pages = int(@ents / $n);
666 my @fnames;
667 for (my $i = 0; $i <= $num_of_old_pages; $i++) {
668 $fnames[$i] = get_category_filename($catname);
669 my $suffix = ($i == 0) ? "" : "-".($i+1);
670 $fnames[$i] =~ s/\.html$/$suffix.html/;
673 for (my $i = 0; $i <= $num_of_old_pages; $i++) {
675 ### ¥Ú¡¼¥¸¤ÎÁȤ߾夲
676 my $t = HTML::Template->new(scalarref => \$cat_page_template,
677 loop_context_vars => 1,
678 die_on_bad_params => 0);
679 $t->param(cl_name => $changelog_name);
680 $t->param(css_file => $css_file);
681 $t->param(lastupdate => $what_time_is_it_now);
682 $t->param(signature => $signature);
684 $t->param(cat_name => $catname);
685 $t->param(ym => $current_ym);
686 $t->param(day_list => $current_day_list);
687 $t->param(latest_item_list => $latest_item_list);
688 $t->param(category_list => $category_list);
689 $t->param(rss_file => $rss_filename); # 050821
690 $t->param(entries => [grep /^.+$/, @ents[$i*$n...($i+1)*$n-1]]);
692 my @page_list;
693 my $back_page_url;
694 my $next_page_url;
695 if ($num_of_old_pages > 0) {
696 for (my $j = 0; $j <= $num_of_old_pages; $j++) {
697 $page_list[$j] = ($i == $j) ? $j+1 :
698 qq(<a href="$fnames[$j]">@{[$j+1]}</a>);
699 $back_page_url = $fnames[$j] if ($j == $i - 1);
700 $next_page_url = $fnames[$j] if ($j == $i + 1);
704 $t->param(page_list => join(" ",@page_list));
705 $t->param(first_page => $fnames[0]);
706 $t->param(back => $back_page_url);
707 $t->param(next => $next_page_url);
708 $t->param(page_id => $i + 1);
709 $t->param(page_num => $num_of_old_pages + 1);
711 my $ostr = $t->output();
713 ### ¥Õ¥¡¥¤¥ë¤Ë½ÐÎÏ
714 output_to_file("$outputdir/".$fnames[$i], \$ostr);
720 ### ¥¢¥¤¥Æ¥à¥Ú¡¼¥¸(ex: 2001-01-01-1.html)¤òºî¤ë¡£
721 sub write_item_page {
722 my @day_list = reverse sort keys %{$cl->{all}};
724 for (my $idx = 0; $idx < @day_list; $idx++) {
725 my ($ymd, $ym) = ($day_list[$idx] =~ /^((\d+-\d+)-\d+)/);
726 my $ent = $cl->{all}->{$ymd};
728 for (my $i = $ent->{curid}; $i >= 1; $i--) {
729 my $item = $ent->{$i};
730 my $ymdi = "$ymd-$i";
732 ### ¥«¥Æ¥´¥ê
733 my $catstr = make_cat_link_html($ent->{$i}{cat});
735 ### ÆüÉÕ¥ê¥ó¥¯¤Ë¤è¤ë¥ê¥Õ¥¡¥é¡¼
736 my @inside_refs = get_inside_ref("$ymdi");
738 ### item ¤Î´ðÁþðÊó
739 my $item_url = datestr2url("$ymdi");
740 my $item_ymdi = $ymdi;
741 my $item_id = $ymdi; $item_id =~ s/-//g; # Ex. "200309241"
743 # Á°¸å¤Î¥Ú¡¼¥¸
744 my $ymdi_before;
745 my $ymdi_after;
746 if ($i > 1) {
747 $ymdi_before = $ymd."-".($i-1);
748 } elsif ($idx < @day_list - 1) {
749 my $day_b = $day_list[$idx + 1];
750 $ymdi_before = $day_b."-".$cl->{all}->{$day_b}{curid};
752 if ($i != $ent->{curid}) {
753 $ymdi_after = $ymd."-".($i+1);
754 } elsif ($idx > 0) {
755 my $day_a = $day_list[$idx - 1];
756 $ymdi_after = $day_a."-1";
759 ### ¥Ú¡¼¥¸¤ÎÁȤ߾夲
760 my $t = HTML::Template->new(scalarref => \$item_page_template,
761 loop_context_vars => 1,
762 die_on_bad_params => 0);
764 $t->param(cl_name => $changelog_name);
765 $t->param(css_file => $css_file);
766 $t->param(lastupdate => $what_time_is_it_now);
767 $t->param(signature => $signature);
769 $t->param(ymd => $ymd);
770 $t->param(ym => $ym);
772 $t->param(month_page_list => $month_page_list);
773 $t->param(latest_item_list => $latest_item_list);
774 $t->param(category_list => $category_list);
775 $t->param(back => $ymdi_before);
776 $t->param(next => $ymdi_after);
778 my $ccc = $item->{c}; $ccc =~ s!^<br>!!g;# ad hoc
779 $t->param(content => $ccc);
780 $t->param(header_text => $item->{ho});
781 $t->param(header => $item->{h});
782 $t->param(cat => $catstr);
783 $t->param(author => $item->{a});
784 $t->param(referrer => join(" ", @inside_refs));
785 $t->param(id => $item_id); # 200101011
786 $t->param(ymdi => $item_ymdi); # 2001-01-01-1
787 $t->param(url => $item_url); # 2001-01-01-1.html
788 $t->param(rss_file => $rss_filename); # 050821
790 my $ostr = $t->output();
792 ### ¥Õ¥¡¥¤¥ë¤Ë½ÐÎÏ
793 output_to_file("$outputdir/$ymdi.html", \$ostr);
799 ### Æü¥Ú¡¼¥¸(ex: 2001-01-01.html)¤òºî¤ë¡£
800 sub write_day_page {
801 return if ($day_page_template eq ""); # tmpl¤¬¶õ¤Ê¤éºî¤é¤Ê¤¤»ÅÍÍ(5.1.19)
803 my @day_list = reverse sort keys %{$cl->{all}};
805 for (my $idx = 0; $idx < @day_list; $idx++) {
807 my ($ymd, $ym) = ($day_list[$idx] =~ /^((\d+-\d+)-\d+)/);
809 # Á°¸å¤ÎÆü¥Ú¡¼¥¸
810 my $day_before = $day_list[$idx + 1] if ($idx < @day_list - 1);
811 my $day_after = $day_list[$idx - 1] if ($idx > 0);
813 # Æü¤Ø¤Î¥ê¥ó¥¯ (ÆüÉÕ°ìÍ÷)
814 my $day_list = make_day_list_str($ym);
816 ### ¥Ú¡¼¥¸¤ÎÁȤ߾夲
817 my $t = HTML::Template->new(scalarref => \$day_page_template,
818 loop_context_vars => 1,
819 die_on_bad_params => 0);
820 $t->param(cl_name => $changelog_name);
821 $t->param(css_file => $css_file);
822 $t->param(lastupdate => $what_time_is_it_now);
823 $t->param(signature => $signature);
825 $t->param(ymd => $ymd);
826 $t->param(ym => $ym);
827 $t->param(day_list => $day_list);
828 $t->param(month_page_list => $month_page_list);
829 $t->param(latest_item_list => $latest_item_list);
830 $t->param(category_list => $category_list);
831 $t->param(rss_file => $rss_filename); # 050821
832 $t->param(back => $day_before);
833 $t->param(next => $day_after);
834 $t->param(content => $month_page{$ym}{$ymd}{str});
836 my $ostr = $t->output();
838 ### ¥Õ¥¡¥¤¥ë¤Ë½ÐÎÏ
839 output_to_file("$outputdir/$ymd.html", \$ostr);
844 ### ·î¥Ú¡¼¥¸(ex: 2001-01.html)¤òºî¤ë¡£
845 sub write_month_page {
846 return if ($month_page_template eq ""); # tmpl¤¬¶õ¤Ê¤éºî¤é¤Ê¤¤»ÅÍÍ(5.1.19)
848 my @month_list = reverse sort keys %month_page;
849 for (my $idx = 0; $idx < @month_list; $idx++) {
850 my $ym = $month_list[$idx];
852 # Á°¸å¤Î·î
853 my $m_before = $month_list[$idx + 1] if ($idx < @month_list - 1);
854 my $m_after = $month_list[$idx - 1] if ($idx > 0);
856 # ÆüÉÕ¥ê¥ó¥¯°ìÍ÷
857 my $day_list = make_day_list_str($ym);
859 ### Æü¡¹¤Î¥¨¥ó¥È¥êºîÀ®
860 my @cont;
861 if ($reverse_order_days) { # ¹ß½ç: ÆüÉդο·¤·¤¤¤Î¤¬¾å (¡Áv0.11 ¤ÈƱ¤¸)
862 @cont = reverse sort keys %{$month_page{$ym}};
863 } else { # ¾º½ç: ÆüÉդθŤ¤¤Î¤¬¾å
864 @cont = sort keys %{$month_page{$ym}};
866 my @contlist = map {{content => $month_page{$ym}{$_}{str}}} @cont;
868 ### ¥Ú¡¼¥¸¤ÎÁȤ߾夲
869 my $t = HTML::Template->new(scalarref => \$month_page_template,
870 loop_context_vars => 1,
871 die_on_bad_params => 0);
872 $t->param(cl_name => $changelog_name);
873 $t->param(css_file => $css_file);
874 $t->param(lastupdate => $what_time_is_it_now);
875 $t->param(signature => $signature);
877 $t->param(ym => $ym);
878 $t->param(day_list => $day_list);
879 $t->param(month_page_list => $month_page_list);
880 $t->param(latest_item_list => $latest_item_list);
881 $t->param(category_list => $category_list);
882 $t->param(rss_file => $rss_filename); # 050821
883 $t->param(back => $m_before);
884 $t->param(next => $m_after);
885 $t->param(entries => \@contlist);
887 my $ostr = $t->output();
889 output_to_file("$outputdir/$ym.html", \$ostr);
894 ### ¥¤¥ó¥Ç¥Ã¥¯¥¹¥Ú¡¼¥¸(index.html)¤òºî¤ë
895 sub write_index_page {
896 ### ºÇ¶á¤Î²¿Æü¤«¤À¤±¥¤¥ó¥Ç¥Ã¥¯¥¹¥Ú¡¼¥¸¤ËºÜ¤»¤ë¤¿¤á¤Î½èÍý
897 my @recent = (reverse sort keys %{$cl->{all}})[0..$opt_topn];
899 my @top_n_entries;
901 for (my $i = 0; $i < $opt_topn and $recent[$i]; $i++) {
902 my $ymd = $recent[$i];
903 my ($ym, $d) = ($ymd =~ /^(\d{4}-\d\d)-(\d\d)$/);
904 # $top_n_str .= $month_page{$ym}{$ymd}{str};
905 push @top_n_entries, {content => $month_page{$ym}{$ymd}{str}};
907 my ($ymd, $ym, $d) = ($recent[0] =~ /^((\d{4}-\d\d)-(\d\d))$/);
909 # ÆüÉÕ¥ê¥ó¥¯°ìÍ÷
910 my $day_list = make_day_list_str($ym);
912 ### ¥Ú¡¼¥¸¤ÎÁȤ߾夲
913 my $t = HTML::Template->new(scalarref => \$index_page_template,
914 loop_context_vars => 1,
915 die_on_bad_params => 0);
916 $t->param(cl_name => $changelog_name);
917 $t->param(css_file => $css_file);
918 $t->param(lastupdate => $what_time_is_it_now);
919 $t->param(signature => $signature);
921 $t->param(ymd => $ymd); # ºÇ¿·¥¨¥ó¥È¥ê¤ÎÆüÉÕ
922 $t->param(ym => $ym); # ºÇ¿·¥¨¥ó¥È¥ê¤Î·î
923 $t->param(ndays => $opt_topn);
924 $t->param(day_list => $day_list);
925 $t->param(month_page_list => $month_page_list);
926 $t->param(latest_item_list => $latest_item_list);
927 $t->param(category_list => $category_list);
928 $t->param(rss_file => $rss_filename); # 050821
929 $t->param(entries => \@top_n_entries);
931 my $ostr = $t->output();
933 output_to_file("$outputdir/index.html", \$ostr);
937 ### ·îÊÌ°ìÍ÷¤òºîÀ®
938 sub make_month_page_list {
939 my ($month_page) = @_;
940 my @month_list = sort keys %{$month_page};
941 my ($start_year) = ($month_list[0] =~ /^(\d\d\d\d)/);
942 my ($end_year) = ($month_list[$#month_list] =~ /^(\d\d\d\d)/);
943 my $month_page_list = "";
944 for (my $y = $end_year; $y >= $start_year; $y--) { # year loop
945 $month_page_list .= "$y : ";
946 for (my $m = 1; $m <= 12; $m++) { # month loop
947 my $m0 = sprintf "%02d", $m;
948 if (defined $month_page->{"$y-$m0"}) {
949 $month_page_list .= "<a href=\"$y-$m0.html\">$m0</a> ";
950 } else {
951 $month_page_list .= "$m0 ";
954 $month_page_list .= "<br>\n";
956 return $month_page_list;
960 ### ÆüÉÕ¥ê¥ó¥¯°ìÍ÷¤òºîÀ® - ʸ»úÎó¤òÊÖ¤¹
961 sub make_day_list_str {
962 my ($ym) = @_;
963 if ($calendar_style == 1) {
964 return make_calendar_table($ym, make_day_list($ym));
965 } else {
966 return join(" ", @{make_day_list($ym)});
970 # ÆüÉÕ¥ê¥ó¥¯°ìÍ÷¤òºîÀ® - ¥ê¥¹¥È¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹
971 my %daylist;
972 sub make_day_list {
973 my ($ym) = @_;
974 my $lday = get_last_day_of_month($ym);
975 return $daylist{$ym} if (defined $daylist{$ym}); # cache
976 for (my $d = 1; $d <= $lday; $d++) {
977 my $day = ($d < 10) ? "0".$d : $d;
978 if (defined $cl->{all}->{$ym."-".$day}) {
979 my $day_url = datestr2url($ym."-".$day);
980 push @{$daylist{$ym}}, qq(<a href="$day_url">$day</a>);
981 } else {
982 push @{$daylist{$ym}}, $day;
985 return $daylist{$ym};
988 # ÆüÉÕ°ìÍ÷¤òºîÀ® - ¥«¥ì¥ó¥À¡¼¥¹¥¿¥¤¥ë
989 sub make_calendar_table {
990 my ($ym, $dlistp) = @_;
991 my ($y, $m) = split("-", $ym);
992 my $offset = (localtime timelocal(0, 0, 0, 1, $m - 1, $y))[6];
994 my $week = 0;
995 my @cal;
996 for (my $i = 0; $i < 42; $i++) {
997 my $day = ($i < $offset) ? " " : $dlistp->[$i - $offset];
998 last if (not $day);
999 $day =~ s/^0//;
1000 $day =~ s/>0([1-9])</>$1</;
1001 $cal[$week] .= qq(<td align="center">$day</td>);
1002 $week++ if (($i + 1) % 7 == 0);
1005 my @wn = ("S", "M", "T", "W", "T", "F", "S");
1006 # my @wn = ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
1008 my $rv = << "CAL"
1009 <table>
1010 <caption><a href="$ym.html">$ym</a></caption>
1011 <tr>
1012 @{[join "", map {qq(<th align="center">$_</th>)} @wn]}
1013 </tr>
1014 @{[join "", map {"<tr>$_</tr>"} @cal]}
1015 </table>
1019 return $rv;
1023 ### anchor, img ¥¿¥°Ê¸»úÎó¤òÀ¸À®¡£
1024 sub get_link_str {
1025 my ($a, $b) = @_;
1026 if ($a =~ /\.(jpg|jpeg|png|gif)$/i) { # [[http://nais.to/|image/nais.jpg]]
1027 return qq(<a href="$b"><img src="$a" alt="²èÁü"></a>);
1028 } elsif ($b =~ /\.(jpg|jpeg|png|gif)$/i) { # [[¼«²èÁü|image/sp.jpg]]
1029 return qq(<img src="$b" alt="$a">);
1030 } else { # [[¥È¥Ã¥×¥Ú¡¼¥¸|http://nais.to/]]
1031 return qq(<a href="$b">$a</a>);
1036 ### ǯ·îÆü¤òÆþÎϤȤ·ÍËÆü¤ò½ÐÎϤ¹¤ë´Ø¿ô since 021001
1037 # RETURN VALUES
1038 # the text name of the day of the week. Mon, Tue, Wed, ...
1039 # EXAMPLES
1040 # get_day_of_week(1, 12, 2002), get_day_of_week("2002-12-01")
1041 sub get_day_of_week {
1042 my ($d, $m, $y) = @_;
1043 ($y, $m, $d) = split("-", $d) unless (defined $m);
1044 my $WEEKDAY = (localtime timelocal(0, 0, 0, $d, $m - 1, $y))[6];
1045 return ("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")[$WEEKDAY];
1049 ### ǯ·î¤òÆþÎϤȤ·¤½¤Î·î¤ÎºÇ½ªÆü¤ò½ÐÎϤ¹¤ë´Ø¿ô since 030105
1050 # EXAMPLES
1051 # get_last_day_of_month(12, 2002), get_last_day_of_month("2002-12")
1052 sub get_last_day_of_month {
1053 my ($m, $y) = @_;
1054 ($y, $m) = split("-", $m) unless (defined $y);
1055 return (31, ((($y % 4 == 0) and ($y % 100)) or ($y % 400 == 0)) ? 29 : 28,
1056 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)[$m - 1];
1060 ### RSS ¥Õ¥¡¥¤¥ë¤ò½ÐÎϤ¹¤ë
1061 sub write_rss_file {
1062 my $rdfseq;
1063 my $rdfitem;
1064 my $ctr = ($rss_topn > 0) ? $rss_topn : (($opt_topn > 7) ? 7 : $opt_topn);
1066 my @items;
1068 foreach my $ymd (sort {$b cmp $a} keys %{$cl->{all}}) {
1069 $ctr--;
1070 last if ($ctr < 0);
1071 my $e = $cl->{all}->{$ymd};
1072 foreach my $i (sort {$b <=> $a} keys %$e) {
1073 next if ($i !~ /^\d/);
1075 my $permlink = $clog_url_pref.datestr2url($ymd."-".$i);
1076 my ($ym) = ($ymd =~ /^(\d{4}-\d\d)-\d\d/);
1078 my $coen = $e->{$i}{c};
1079 $coen =~ s!<a href="(\d.+?)"!<a href="$clog_url_pref$1"!g;
1080 $coen =~ s!<img src="([^h].+?)"!<img src="$clog_url_pref$1"!g;
1082 my $cont = $e->{$i}{c};
1083 $cont = html2xmlstr($cont);
1084 if ($cont =~ s/^(([\x00-\x7F]|[\x80-\xFF]{2}){300}).+$/$1/sm) {
1085 $cont =~ s/&[^;]*$//g; # &gt...$ ¤ÇXML¥Ñ¡¼¥º¥¨¥é¡¼
1086 $cont .= "...";
1089 my $item_dcdate = # ($dcdate =~ /^$ymd/) ? $dcdate :
1090 $ymd."T23:59:59+09:00";
1092 push @items, {
1093 permlink => $permlink,
1094 itemheader => html2xmlstr($e->{$i}{h}),
1095 itemauthor => $e->{$i}{a},
1096 itemcontent => $cont,
1097 itemcontentencoded => $coen,
1098 item_dcdate => $item_dcdate
1102 my $t = HTML::Template->new(scalarref => \$rss_template,
1103 die_on_bad_params => 0, gloval_vars => 1);
1104 $t->param(items => \@items);
1105 $t->param(changelog_name => $changelog_name);
1106 $t->param(dcdate => $dcdate);
1107 $t->param(changelog_description => $changelog_description);
1108 $t->param(clog_url => $clog_url);
1109 $t->param(clog_url_pref => $clog_url_pref);
1110 $t->param(rss_file => $rss_filename); # 050821
1111 $t->param(generatoragent=>"http://chalow.org/?v=$version");
1112 my $ostr = $t->output();
1113 to_utf8_cl(\$ostr) if (not $utf8_mode);
1114 output_to_file("$outputdir/$rss_filename", \$ostr);
1118 sub html2xmlstr {
1119 local ($_) = @_;
1120 s/&nbsp;/ /g;
1121 s|<img.+?alt="(.*?)".*?>|[$1]|gosm;
1122 s/[\t\n]//g;
1123 s/[\x00-\x1f]+/ /g;
1124 s/\s\s+/ /g;
1125 s|<[^<>]+?>||gosm;
1126 s/&lt;/</go;
1127 s/&/&amp;/go; s/>/&gt;/go; s/</&lt;/go; s/\"/&quot;/go; # "¤¤¤Ä¤â¤Î£´¤Ä
1128 return $_;
1132 ### JavaScript feed ¥Õ¥¡¥¤¥ë¤ò½ÐÎϤ¹¤ë
1133 sub write_latest_item_list_file {
1135 ### ºÇ¶á¤Îµ­»ö
1136 my @lines;
1137 my $date;
1138 my $ctr = $latest_titles_num;
1139 foreach my $ymd (sort {$b cmp $a} keys %{$cl->{all}}) {
1140 $ctr--;
1141 last if ($ctr < 0);
1142 my $e = $cl->{all}->{$ymd};
1143 foreach my $i (sort {$b <=> $a} keys %$e) {
1144 next if ($i !~ /^\d/);
1145 my ($ym) = ($ymd =~ /^(\d{4}-\d\d)-\d\d/);
1146 my $c = $e->{$i}{h};
1147 $c =~ s/[\t\n]//g;
1148 $c =~ s/\s\s+/ /g;
1149 $c =~ s/\s*$//;
1150 $c =~ s/<.+?>//g;
1151 $c =~ s/^\*\s+//;
1152 # $c =~ s/\'/&\#x27;/g;
1154 if ($date ne $ymd) {
1155 push @lines, "<a href=\"".
1156 $clog_url_pref.datestr2url("$ymd")."\">$ymd</a><br>";
1157 $date = $ymd;
1159 push @lines, "- <a href=\"".
1160 $clog_url_pref.datestr2url("$ymd-$i")."\">$c</a><br>";
1164 my $ostr = join("\n", map {s/\'/&\#x27;/g; "document.writeln('".$_."');"}
1165 @lines);
1166 output_to_file("$outputdir/cl.js", \$ostr);
1168 $latest_item_list = join("\n", @lines);
1173 sub write_category_list_file {
1174 ### ¥«¥Æ¥´¥ê°ìÍ÷
1175 # return if ($output_cat_pages == 0 or $cat_page_cgi eq "");
1176 # return if ($output_cat_pages == 0);
1178 my @lines = ();
1179 foreach my $cat (sort keys %{$cl->{CAT}}) {
1180 my $n = $cl->{CAT}->{$cat};
1181 my $url;
1182 if ($output_cat_pages) {
1183 $url = get_category_filename($cat);
1184 $url = $clog_url_pref.$url;
1185 } else {
1186 $url = $cat_page_cgi;
1187 $url =~ s/%%CAT%%/urlencode($cat)/ge;
1188 $url = $clog_url_pref.$url if ($url !~ /^http/);
1190 push @lines, "- <a href=\"$url\">$cat</a> ($n)<br>";
1193 my $ostr = join("\n", map {s/\'/&\#x27;/g; "document.writeln('".$_."');"}
1194 @lines);
1196 $category_list = join("\n", @lines);
1197 if ($output_cat_pages == 1) {
1198 output_to_file("$outputdir/cl-cat.js", \$ostr);
1203 ### ¸¡º÷ÍÑ¥Õ¥¡¥¤¥ë¤ò½ÐÎϤ¹¤ë
1204 # clsearch.cgi ÍѤΥե¡¥¤¥ë¤òÀ¸À®
1205 sub write_itemlist_file {
1206 my $ostr;
1207 foreach my $ymd (sort {$b cmp $a} keys %{$cl->{all}}) {
1208 my $e = $cl->{all}->{$ymd};
1209 foreach my $i (sort {$b <=> $a} keys %$e) {
1210 next if ($i !~ /^\d/);
1211 my ($ym) = ($ymd =~ /^(\d{4}-\d\d)-\d\d/);
1212 my $h = $e->{$i}{h}.
1213 ((defined $e->{$i}{"cat"}) ?
1214 join('', map {"[$_]"} @{$e->{$i}{"cat"}}) : "");
1215 my $c = $h."\x01".$e->{$i}{c};
1216 $c =~ s|<img.+?alt="(.*?)".*?>|[$1]|gosm;
1217 $c =~ s/[\t\n]//g;
1218 $c =~ s/&nbsp;/ /g;
1219 $c =~ s/\s\s+/ /g;
1220 $c =~ s/<.+?>//g;
1221 $c =~ s/\x01/\t/; # Ķ ad hoc¡£¤ä¤Ð
1222 $ostr .= datestr2anchor("[$ymd-$i]")."\t$c\n";
1226 if (-e "$outputdir/cl.itemlist" and $stop_date != 0) { # º¹Ê¬¹¹¿·
1227 open(F, "$outputdir/cl.itemlist") or die;
1228 my $flag = 0;
1229 while (<F>) {
1230 if ($flag == 0) {
1231 (/\[(\d+)-(\d+)-(\d+)-/);
1232 my $cdate = $1 * 10000 + $2 * 100 + $3;
1233 $flag = 1 if ($stop_date > $cdate);
1235 $ostr .= $_ if ($flag);
1237 close F;
1238 print "update ";
1241 output_to_file("$outputdir/cl.itemlist", \$ostr);
1245 ### ÆüÉդǻ²¾È¥ê¥ó¥¯
1246 sub datestr2anchor {
1247 my ($d) = @_;
1248 if ($page_mode == 2) { # ¥¢¥¤¥Æ¥à¥â¡¼¥É
1249 $d =~ s!\[(\d{4}-\d\d-\d\d(-\d+)?)\]!<a href="$1.html">[$1]</a>!g;
1250 } elsif ($day_page_mode or $page_mode == 1) { # Æü¥â¡¼¥É
1251 $d =~ s!\[((\d{4}-\d\d-\d\d)(-\d+)?)\]!<a href="$2.html#$1">[$1]</a>!g;
1252 } else { # ·î¥â¡¼¥É
1253 $d =~ s!\[((\d{4}-\d\d)-\d\d(-\d+)?)\]!<a href="$2.html#$1">[$1]</a>!g;
1255 return $d;
1258 sub datestr2url {
1259 my ($d) = @_;
1260 if ($page_mode == 2) { # ¥¢¥¤¥Æ¥à¥â¡¼¥É
1261 $d =~ s!(\d{4}-\d\d-\d\d(-\d+)?)!$1.html!;
1262 } elsif ($day_page_mode or $page_mode ==1) { # Æü¥â¡¼¥É
1263 unless ($d =~ s!((\d{4}-\d\d-\d\d)-\d+)!$2.html\#$1!) {
1264 $d =~ s!(\d{4}-\d\d-\d\d)!$1.html!;
1266 } else { # ·î¥â¡¼¥É
1267 $d =~ s!((\d{4}-\d\d)-\d\d(-\d+)?)!$2.html#$1!;
1269 return $d;
1273 ### ʸ»úÎóÃÖ¤­´¹¤¨¤«¤é°ì»þŪ¤ËÂàÈò¤·¡¢¸å¤ËÉüµ¢¤µ¤»¤ë
1274 my $num_of_escaped_string;
1275 my %escaped_string;
1276 my $num_of_escaped_src;
1277 my %escaped_src;
1278 my $num_of_escaped_plugin;
1279 my %escaped_plugin;
1281 sub escape_string {
1282 my ($strp) = @_;
1284 ### HTML ¥¨¥¹¥±¡¼¥× - ʸ»úÎ󤽤ΤޤÞ
1285 my $btag = '_HTML_START_\n'; # ³«»Ï¥Þ¡¼¥¯
1286 my $atag = '_HTML_END_\n'; # ½ªÎ»¥Þ¡¼¥¯
1287 $num_of_escaped_string = 0;
1288 $$strp =~ s!$btag(.*?)$atag!
1289 $escaped_string{++$num_of_escaped_string} = $1,
1290 sprintf("\x5\x13%d\x3", $num_of_escaped_string)!gsmxe;
1291 $$strp =~ s!\[(literal|sic|esc)\](.*?)\[/\1\]!
1292 $escaped_string{++$num_of_escaped_string} = $2,
1293 sprintf("\x5\x13%d\x3", $num_of_escaped_string)!gsmxe;
1295 ### ¥½¡¼¥¹¥¨¥¹¥±¡¼¥× - "&" ¤ä "<" ¤Ê¤É¤òÃÖ´¹¤· pre ¤òÉÕ¤±¤ë
1296 $num_of_escaped_src = 0;
1297 $$strp =~ s!\[src\](.*?)\[/src\]!
1298 $escaped_src{++$num_of_escaped_src} = $1,
1299 $escaped_src{$num_of_escaped_src} =~ s/&/&amp;/g,
1300 $escaped_src{$num_of_escaped_src} =~ s/</&lt;/g,
1301 $escaped_src{$num_of_escaped_src} =~ s/>/&gt;/g,
1302 sprintf("\x6\x13%d\x3", $num_of_escaped_src)!gsmxe;
1304 ### ¥×¥é¥°¥¤¥ó¥¨¥¹¥±¡¼¥×
1305 $num_of_escaped_plugin = 0;
1306 $$strp =~ s!{{(.*?)}}!
1307 $escaped_plugin{++$num_of_escaped_plugin} = $1,
1308 sprintf("\x7\x13%d\x3", $num_of_escaped_plugin)!gsmxe;
1311 sub unescape_string {
1312 my ($strp) = @_;
1314 ### ¥×¥é¥°¥¤¥ó¥¢¥ó¥¨¥¹¥±¡¼¥× - ¼Â¹Ô¡ª
1315 $$strp =~ s|\x7\x13(\d+)\x3|eval($escaped_plugin{$1})|ge;
1316 ### ¥½¡¼¥¹¥¢¥ó¥¨¥¹¥±¡¼¥× - pre ÄɲÃ
1317 #$$strp =~ s|\x6\x13(\d+)\x3|<pre>$escaped_src{$1}</pre>|g;
1318 $$strp =~ s|\x6\x13(\d+)\x3|</p><pre>$escaped_src{$1}</pre><p>|g;
1319 ### HTML ¥¢¥ó¥¨¥¹¥±¡¼¥×
1320 $$strp =~ s|\x5\x13(\d+)\x3|$escaped_string{$1}|g;
1324 ### inside referrer ¤Î¥ê¥ó¥¯ºîÀ®
1325 sub get_inside_ref {
1326 my ($id) = @_;
1327 if (defined $inside_ref{"$id"}) {
1328 return map {datestr2anchor("[".$_."]")}
1329 (sort {$b cmp $a} keys %{$inside_ref{"$id"}});
1331 return ();
1335 ### ¥«¥Æ¥´¥ê¥Ú¡¼¥¸¤Î¥Õ¥¡¥¤¥ë̾¤òÀ¸À®
1336 sub get_category_filename {
1337 my ($cn) = @_;
1338 to_utf8_cl(\$cn) if (not $utf8_mode and $cn =~ /[\x80-\xff]/);
1339 $cn =~ s/([^0-9a-z_-])/unpack('H2', $1)/gei;
1340 $cn =~ tr/A-Z/a-z/;
1341 return "cat_$cn.html";
1345 ### ¥¨¥ó¥È¥ê¥Ø¥Ã¥À¡¼¤ÎÀ¸À®
1346 sub make_entry_header_html {
1347 my ($eh, $ymd) = @_;
1348 if ($show_day_of_week == 1) { ### ÆüÉդθå¤í¤ò¤É¤¦¤¹¤ë¤«?
1349 # ÍËÆü(Mon, Tue, ...)¤òÄɲÃ: "2000-10-19" --> "2000-10-19 Thu"
1350 $eh .= " ".get_day_of_week($ymd);
1352 return qq(<a name="$ymd" href="@{[datestr2url($ymd)]}">$eh</a>);
1356 ### ¥¢¥¤¥Æ¥à¥Ø¥Ã¥À¡¼¤ÎÀ¸À®
1357 sub make_item_header_html {
1358 my ($ih, $ymdi) = @_;
1359 # Á°¤Ë­¤¹¤â¤Î
1360 my $ihb = "";
1361 if ($item_header_style == 0 or $item_header_style == 1) {
1362 $ihb = $item_header_mark;
1363 if ($use_item_anchor == 1) {
1364 my $day_url = datestr2url($ymdi);
1365 $ihb = qq(<a name="$ymdi" href="$day_url">$ihb</a>);
1367 $ihb .= " ";
1370 # ¥¿¥°¤Ç°Ï¤à
1371 $ih = qq($ihb<span class="clitemheader">$ih</span>);
1372 # ¸å¤í¤Ë­¤¹¤â¤Î
1373 if ($item_header_style == 0 or $item_header_style == 2) {
1374 $ih .= ":";
1376 return $ih;
1380 ### make category link(anchor) string for item header
1381 sub make_cat_link_html {
1382 my ($catp) = @_;
1383 my $catstr;
1384 if (defined $catp) {
1385 if ($output_cat_pages) {
1386 $catstr =
1387 join("", map
1388 {"[<a href=\"".get_category_filename($_)."\">$_</a>]"}
1389 @$catp);
1390 } elsif ($cat_page_cgi eq "") {
1391 $catstr = join("", map {"[".$_."]"} @$catp);
1392 } else {
1393 $catstr =
1394 join("", map
1395 {my $tmp = $cat_page_cgi;
1396 $tmp =~ s/%%CAT%%/urlencode($_)/ge;
1397 "[<a href=\"$tmp\">$_</a>]"}
1398 @$catp);
1402 return $catstr;
1406 ### »ØÄꤵ¤ì¤¿¥Õ¥¡¥¤¥ë¤Øʸ»úÎó¤ò½ÐÎÏ
1407 sub output_to_file {
1408 my ($fname, $contp) = @_;
1409 $$contp =~ s/<!-- ReplaceOnce -->/$replace_once/;
1411 if ($update_by_size == 1 and -s $fname == length($$contp)) {
1412 return;
1415 if ($utf8_mode) { # ad hoc 050821
1416 $$contp =~ s/;charset=EUC-JP">/;charset=UTF-8">/;
1419 print "output to \"$fname\"\n" if (!defined $quiet_mode);
1420 open(F, "> $fname") || die "$fname: $!\n";
1421 binmode(F);
1422 print F $$contp;
1423 close(F);
1426 ### URL ENCODE
1427 sub urlencode {
1428 local ($_) = @_;
1429 s/([^ \n\.\*\-_A-Z0-9])/sprintf("%%%02lX",unpack("C",$1))/gie;
1430 s/ /+/g;
1431 return $_;
1434 # ### modularized for i18n
1435 # # delete content of this func,
1436 # # if you use utf8 file and don't use Jcode.
1437 # sub to_utf8_cl {
1438 # my ($sp) = @_;
1439 # use Jcode;
1440 # $$sp = Jcode->new($$sp)->utf8;