1.9でtDiary動いた

cgi.rbを大分使いやすく改造しているのですが、
ようやくtDiaryが動いたのでお披露目します。

右下に1.9.0と出ているのがお分かりでしょうか?
さて、tDiaryも無修正で動く訳ではなく、
ある程度の修正は必要です。
とりあえず、表示できて、書き込みができるところまでです。
現時点のdiffを置きます。

Index: update.rb
===================================================================
--- update.rb	(revision 32)
+++ update.rb	(working copy)
@@ -1,12 +1,13 @@
 #!/usr/bin/env ruby
+# vim:set fileencoding=euc-jp:
 #
 # update.rb $Revision: 1.21 $
 #
 # Copyright (C) 2001-2003, TADA Tadashi <sho@spc.gr.jp>
 # You can redistribute it and/or modify it under GPL2.
 #
-BEGIN { $defout.binmode }
-$KCODE = 'n'
+BEGIN { $defout.binmode if RUBY_VERSION<"1.9"}
+$KCODE = 'n' if RUBY_VERSION < "1.9"
 
 begin
 	if FileTest::symlink?( __FILE__ ) then 
Index: index.rb
===================================================================
--- index.rb	(revision 32)
+++ index.rb	(working copy)
@@ -1,12 +1,13 @@
 #!/usr/bin/env ruby
+# vim:set fileencoding=euc-jp:
 #
 # index.rb $Revision: 1.35 $
 #
 # Copyright (C) 2001-2006, TADA Tadashi <sho@spc.gr.jp>
 # You can redistribute it and/or modify it under GPL2.
 #
-BEGIN { $defout.binmode }
-$KCODE = 'n'
+BEGIN { $defout.binmode if RUBY_VERSION<"1.9"}
+$KCODE = 'n' if RUBY_VERSION<"1.9"
 
 begin
 	if FileTest::symlink?( __FILE__ ) then
@@ -17,6 +18,7 @@
 	$:.unshift( org_path.untaint )
 	require 'tdiary'
 
+  CGI.accept_charset="EUC-JP" if RUBY_VERSION>"1.9"
 	@cgi = CGI::new
 	conf = TDiary::Config::new(@cgi)
 	tdiary = nil
@@ -68,7 +70,7 @@
 			if @cgi.mobile_agent? then
 				body = conf.to_mobile( tdiary.eval_rhtml( 'i.' ) )
 				head['charset'] = conf.mobile_encoding
-				head['Content-Length'] = body.size.to_s
+				head['Content-Length'] = body.bytesize.to_s
 			else
 				require 'digest/md5'
 				body = tdiary.eval_rhtml
@@ -78,7 +80,7 @@
 					body = ''
 				else
 					head['charset'] = conf.encoding
-					head['Content-Length'] = body.size.to_s
+					head['Content-Length'] = RUBY_VERSION<"1.9" ? body.size.to_s : body.bytesize.to_s
 				end
 				head['Pragma'] = 'no-cache'
 				head['Cache-Control'] = 'no-cache'
@@ -86,6 +88,7 @@
 			head['cookie'] = tdiary.cookies if tdiary.cookies.size > 0
 			print @cgi.header( head )
 			print body
+      #@cgi.out(head){body}
 		end
 	rescue TDiary::ForceRedirect
 		head = {
Index: tdiary/lang/ja.rb
===================================================================
--- tdiary/lang/ja.rb	(revision 32)
+++ tdiary/lang/ja.rb	(working copy)
@@ -1,3 +1,4 @@
+# vim:set fileencoding=euc-jp:
 #
 # tDiary language setup: Japanese(ja)
 #
@@ -5,7 +6,7 @@
 # You can redistribute it and/or modify it under GPL2.
 #
 
-$KCODE = 'e'
+$KCODE = 'e' if RUBY_VERSION<"1.9"
 
 def html_lang
 	'ja-JP'
Index: tdiary/wiki_style.rb
===================================================================
--- tdiary/wiki_style.rb	(revision 32)
+++ tdiary/wiki_style.rb	(working copy)
@@ -222,12 +222,12 @@
 			unless body1.empty?
 				current_section = @sections.pop
 				if current_section then
-					body1 = "#{current_section.body.sub( /\n+\Z/, '' )}\n\n#{body1}"
+					body1 = "#{current_section.body.sub( /\n+\Z/, '' )}\n\n#{body1.force_encoding("EUC-JP")}"
 				end
 				@sections << WikiSection::new( body1, author )
 			end
 			section = nil
-			body2.each do |l|
+			body2.each_line do |l|
 				case l
 				when /^\![^!]/
 					@sections << WikiSection::new( section, author ) if section
Index: tdiary/defaultio.rb
===================================================================
--- tdiary/defaultio.rb	(revision 32)
+++ tdiary/defaultio.rb	(working copy)
@@ -13,7 +13,7 @@
 		header, body = data.split( /\r?\n\r?\n/, 2 )
 		headers = {}
 		if header then
-			header.each do |l|
+			header.each_line do |l|
 				l.chomp!
 				key, val = l.scan( /([^:]*):\s*(.*)/ )[0]
 				headers[key] = val ? val.chomp : nil
Index: tdiary/tdiary_style.rb
===================================================================
--- tdiary/tdiary_style.rb	(revision 32)
+++ tdiary/tdiary_style.rb	(working copy)
@@ -1,3 +1,4 @@
+# vim:set fileencoding=euc-jp:
 #
 # tdiary_style.rb: tDiary style class for tDiary 2.x format. $Revision: 1.13 $
 #
Index: plugin/05referer.rb
===================================================================
--- plugin/05referer.rb	(revision 32)
+++ plugin/05referer.rb	(working copy)
@@ -1,3 +1,4 @@
+# vim:set fileencoding=euc-jp:
 #
 # 01referer.rb: load/save and show today's referer plugin
 # $Revision: 1.17 $
@@ -159,7 +160,7 @@
 
 def referer_add_to_diary( diary, body )
 	return unless body
-	body.each do |r|
+	body.each_line do |r|
 		count, ref = r.chomp.split( / /, 2 )
 		next unless ref
 		diary.add_referer( ref.chomp, count.to_i )
Index: plugin/00default.rb
===================================================================
--- plugin/00default.rb	(revision 32)
+++ plugin/00default.rb	(working copy)
@@ -655,7 +655,7 @@
 	mail_header = (@conf['comment_mail.header'] || '').dup
 	mail_header << ":#{@conf.date_format}" unless /%[a-zA-Z%]/ =~ mail_header
 	mail_header = @date.strftime( mail_header )
-	mail_header = comment_mail_mime( @conf.to_mail( mail_header ) ).join( "\n " ) if /[\x80-\xff]/ =~ mail_header
+	mail_header = comment_mail_mime( @conf.to_mail( mail_header ) ).join( "\n " )# if /[\x80-\xff]/ =~ mail_header
 
 	rmail = ''
 	begin
Index: plugin/10spamfilter.rb
===================================================================
--- plugin/10spamfilter.rb	(revision 32)
+++ plugin/10spamfilter.rb	(working copy)
@@ -1,3 +1,5 @@
+# vim:set fileencoding=euc-jp:
+#
 # Copyright (C) 2005  akira yamada
 # You can redistribute it and/or modify it under GPL2.
 
Index: plugin/50sp.rb
===================================================================
--- plugin/50sp.rb	(revision 32)
+++ plugin/50sp.rb	(working copy)
@@ -1,3 +1,5 @@
+# vim:set fileencoding=euc-jp:
+#
 # 01sp.rb - select-plugins plugin $Revision: 1.5 $
 
 SP_PREFIX = 'sp'
Index: plugin/ja/05referer.rb
===================================================================
--- plugin/ja/05referer.rb	(revision 32)
+++ plugin/ja/05referer.rb	(working copy)
@@ -1,3 +1,4 @@
+# vim:set fileencoding=euc-jp:
 #
 # 05referer.rb: Japanese resource of referer plugin
 #
@@ -31,7 +32,7 @@
 	<p>→<a href="#{h @update}?referer=volatile" target="referer">既存設定はこちら</a></p>
 	<p><textarea name="only_volatile" cols="70" rows="10">#{h @conf.only_volatile2.join( "\n" )}</textarea></p>
 	<h3 class="subtitle">#{label_referer_table}</h3>
-	#{"<p>リンク元リストのURLを、特定の文字列に変換する対応表を指定できます。1件につき、URLと表示文字列を空白で区切って指定します。正規表現が使えるので、URL中に現れた「(〜)」は、置換文字列中で「\\1」のような「\数字」で利用できます。</p>" unless @conf.mobile_agent?}
+	#{"<p>リンク元リストのURLを、特定の文字列に変換する対応表を指定できます。1件につき、URLと表示文字列を空白で区切って指定します。正規表現が使えるので、URL中に現れた「(〜)」は、置換文字列中で「\\1」のような「\\数字」で利用できます。</p>" unless @conf.mobile_agent?}
 	<p>→<a href="#{h @update}?referer=table" target="referer">既存設定はこちら</a></p>
 	<p><textarea name="referer_table" cols="70" rows="10">#{h @conf.referer_table2.collect{|a|a.join( " " )}.join( "\n" )}</textarea></p>
 	HTML
Index: plugin/ja/00default.rb
===================================================================
--- plugin/ja/00default.rb	(revision 32)
+++ plugin/ja/00default.rb	(working copy)
@@ -1,3 +1,4 @@
+# vim:set fileencoding=euc-jp:
 #
 # ja/00default.rb: Japanese resources of 00default.rb.
 #
Index: plugin/ja/10spamfilter.rb
===================================================================
--- plugin/ja/10spamfilter.rb	(revision 32)
+++ plugin/ja/10spamfilter.rb	(working copy)
@@ -1,3 +1,4 @@
+# vim:set fileencoding=euc-jp:
 #
 # ja/spamfilter.rb: resource of ja $Revision: 1.17 $
 #
Index: plugin/ja/50sp.rb
===================================================================
--- plugin/ja/50sp.rb	(revision 32)
+++ plugin/ja/50sp.rb	(working copy)
@@ -1,3 +1,5 @@
+# vim:set fileencoding=euc-jp:
+#
 # Japanese resources of 01sp.rb $Revision: 1.2 $
 
 =begin
Index: skel/footer.rhtml
===================================================================
--- skel/footer.rhtml	(revision 32)
+++ skel/footer.rhtml	(working copy)
@@ -1,7 +1,7 @@
 <%# footer.rhtml $Revision: 1.8 $ %>
 <%%=footer_proc%>
 <div class="footer">
-Generated by <a href="http://www.tdiary.org/">tDiary</a> version <%=h TDIARY_VERSION %><br>
+Generated by <a href="http://www.tdiary.org/">tDiary</a> version <%=h TDIARY_VERSION %><br />
 Powered by <a href="http://www.ruby-lang.org/">Ruby</a> version <%=h RUBY_VERSION %><% if /ruby/i =~ @cgi.gateway_interface %> with <a href="http://www.modruby.net/">mod_ruby</a><% end %>
 </div>
 </body>
Index: tdiary.rb
===================================================================
--- tdiary.rb	(revision 32)
+++ tdiary.rb	(working copy)
@@ -1,3 +1,4 @@
+# vim:set fileencoding=euc-jp:
 =begin
 == NAME
 tDiary: the "tsukkomi-able" web diary system.
@@ -12,6 +13,7 @@
 $:.insert( 1, File::dirname( __FILE__ ) + '/misc/lib' )
 
 require 'cgi'
+CGI.accept_charset="EUC-JP" if RUBY_VERSION>"1.9"
 require 'uri'
 begin
 	require 'erb_fast'
@@ -465,7 +467,8 @@
 			@cgi = cgi
 			load
 
-			instance_variables.each do |v|
+			instance_variables.each do |str|
+           v=str.to_s
 				v.sub!( /@/, '' )
 				instance_eval( <<-SRC
 					def #{v}

そんなにいっぱいはありません。

  • マジックコメントの埋め込み
  • accept_charsetの指定
  • String#eachをString#each_line
  • その他細かい修正(diffを見てください)

※ 注意があります。
ruby1.9へEncoding.default_externalをEUC-JPにするように
#!/usr/local/bin/ruby1.9 -Eeucjp
みたいにして、起動してください。
以上、だんだんまともにだんだん動くようになってきた
ruby-1.9のcgi.rbでした。