]> git.cworth.org Git - sup/commitdiff
fixes for ruby1.9
authorRich Lane <rlane@club.cc.cmu.edu>
Fri, 12 Jun 2009 19:35:52 +0000 (12:35 -0700)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Mon, 15 Jun 2009 15:31:11 +0000 (11:31 -0400)
Change colons in case statements to 'then'
Fix a block that didn't take enough arguments
Rename variables to avoid shadowing warnings
Use String.ord (and define it for 1.8)
Use DL::Importer on 1.9
Make require 'fastthread' optional
Copy in RE_UTF8

bin/sup
lib/sup.rb
lib/sup/index.rb
lib/sup/keymap.rb
lib/sup/message-chunks.rb
lib/sup/message.rb
lib/sup/modes/edit-message-mode.rb
lib/sup/util.rb

diff --git a/bin/sup b/bin/sup
index 0af3d11ecfea671bc299342f6ca410d6cb83bf12..2ea39c6d07499a2c06e59c35827d5a6ce5ae04b9 100755 (executable)
--- a/bin/sup
+++ b/bin/sup
@@ -5,7 +5,6 @@ require 'ncurses'
 require 'curses'
 require 'fileutils'
 require 'trollop'
-require 'fastthread'
 require "sup"
 
 BIN_VERSION = "git"
@@ -89,7 +88,7 @@ end
 ## BSD users: if libc.so.6 is not found, try installing compat6x.
 require 'dl/import'
 module LibC
-  extend DL::Importable
+  extend DL.const_defined?(:Importer) ? DL::Importer : DL::Importable
   setlocale_lib = case Config::CONFIG['arch']
     when /darwin/; "libc.dylib"
     when /cygwin/; "cygwin1.dll"
@@ -203,7 +202,7 @@ begin
     end
   end unless $opts[:no_initial_poll]
   
-  imode.load_threads :num => ibuf.content_height, :when_done => lambda { reporting_thread("poll after loading inbox") { sleep 1; PollManager.poll } unless $opts[:no_threads] || $opts[:no_initial_poll] }
+  imode.load_threads :num => ibuf.content_height, :when_done => lambda { |num| reporting_thread("poll after loading inbox") { sleep 1; PollManager.poll } unless $opts[:no_threads] || $opts[:no_initial_poll] }
 
   if $opts[:compose]
     ComposeMode.spawn_nicely :to_default => $opts[:compose]
index 7444df0912ceefc9e2b36622802f184d2eaae0af..991bd2dc6f0b35f756f38a1154b04de789d83c0a 100644 (file)
@@ -5,6 +5,10 @@ require 'thread'
 require 'fileutils'
 require 'gettext'
 require 'curses'
+begin
+  require 'fastthread'
+rescue LoadError
+end
 
 class Object
   ## this is for debugging purposes because i keep calling #id on the
index e403570a74b39774d7ceefa046722d3dae3c12bb..ca01ee76cc89c118933c5122b616b4b6f45a59bb 100644 (file)
@@ -2,7 +2,6 @@
 
 require 'fileutils'
 require 'ferret'
-require 'fastthread'
 
 begin
   require 'chronic'
index 76c7139f45eb9478a627e49ac7c87eea81d0ee5d..cb039e44788f164e30f8851ce1fe10803a65f566 100644 (file)
@@ -9,22 +9,22 @@ class Keymap
 
   def self.keysym_to_keycode k
     case k
-    when :down: Curses::KEY_DOWN
-    when :up: Curses::KEY_UP
-    when :left: Curses::KEY_LEFT
-    when :right: Curses::KEY_RIGHT
-    when :page_down: Curses::KEY_NPAGE
-    when :page_up: Curses::KEY_PPAGE
-    when :backspace: Curses::KEY_BACKSPACE
-    when :home: Curses::KEY_HOME
-    when :end: Curses::KEY_END
-    when :ctrl_l: "\f"[0]
-    when :ctrl_g: "\a"[0]
-    when :tab: "\t"[0]
-    when :enter, :return: 10 #Curses::KEY_ENTER
+    when :down then Curses::KEY_DOWN
+    when :up then Curses::KEY_UP
+    when :left then Curses::KEY_LEFT
+    when :right then Curses::KEY_RIGHT
+    when :page_down then Curses::KEY_NPAGE
+    when :page_up then Curses::KEY_PPAGE
+    when :backspace then Curses::KEY_BACKSPACE
+    when :home then Curses::KEY_HOME
+    when :end then Curses::KEY_END
+    when :ctrl_l then "\f".ord
+    when :ctrl_g then "\a".ord
+    when :tab then "\t".ord
+    when :enter, :return then 10 #Curses::KEY_ENTER
     else
       if k.is_a?(String) && k.length == 1
-        k[0]
+        k.ord
       else
         raise ArgumentError, "unknown key name '#{k}'"
       end
@@ -33,18 +33,18 @@ class Keymap
 
   def self.keysym_to_string k
     case k
-    when :down: "<down arrow>"
-    when :up: "<up arrow>"
-    when :left: "<left arrow>"
-    when :right: "<right arrow>"
-    when :page_down: "<page down>"
-    when :page_up: "<page up>"
-    when :backspace: "<backspace>"
-    when :home: "<home>"
-    when :end: "<end>"
-    when :enter, :return: "<enter>"
-    when :tab: "tab"
-    when " ": "<space>"
+    when :down then "<down arrow>"
+    when :up then "<up arrow>"
+    when :left then "<left arrow>"
+    when :right then "<right arrow>"
+    when :page_down then "<page down>"
+    when :page_up then "<page up>"
+    when :backspace then "<backspace>"
+    when :home then "<home>"
+    when :end then "<end>"
+    when :enter, :return then "<enter>"
+    when :tab then "tab"
+    when " " then "<space>"
     else
       Curses::keyname(keysym_to_keycode(k))
     end
index e817744f262352d134e483c3d8fcc63ee2e90198..0d742d99e746a9ce96a4c11eddcd57506fcae22f 100644 (file)
@@ -240,8 +240,8 @@ EOS
 
     def patina_color
       case status
-      when :valid: :cryptosig_valid_color
-      when :invalid: :cryptosig_invalid_color
+      when :valid then :cryptosig_valid_color
+      when :invalid then :cryptosig_invalid_color
       else :cryptosig_unknown_color
       end
     end
index 5372fc7d5e6e23f5632a7406add7409a6cf86306..ded577aa4f9d953a8e7cacd44708b626f51d00ec 100644 (file)
@@ -405,8 +405,8 @@ private
         elsif m.header["Content-Type"] && m.header["Content-Type"] !~ /^text\/plain/
           extension =
             case m.header["Content-Type"]
-            when /text\/html/: "html"
-            when /image\/(.*)/: $1
+            when /text\/html/ then "html"
+            when /image\/(.*)/ then $1
             end
 
           ["sup-attachment-#{Time.now.to_i}-#{rand 10000}", extension].join(".")
index d7bd41c692f55a7fe7f23f0ebb608e506f938f06..74bdfb72b2324a9dbcc18fdbf71c9ce11e8844a5 100644 (file)
@@ -2,7 +2,10 @@ require 'tempfile'
 require 'socket' # just for gethostname!
 require 'pathname'
 require 'rmail'
-require 'jcode' # for RE_UTF8
+
+# from jcode.rb, not included in ruby 1.9
+PATTERN_UTF8 = '[\xc0-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf][\x80-\xbf]'
+RE_UTF8 = Regexp.new(PATTERN_UTF8, 0, 'n')
 
 module Redwood
 
index ece52babe4cb1e8ea3f2970d290ab10f4a64fc1a..8f60cc43216979aaa207696324f117ba7025cbdd 100644 (file)
@@ -133,8 +133,8 @@ class Object
   ## clone of java-style whole-method synchronization
   ## assumes a @mutex variable
   ## TODO: clean up, try harder to avoid namespace collisions
-  def synchronized *meth
-    meth.each do
+  def synchronized *methods
+    methods.each do |meth|
       class_eval <<-EOF
         alias unsynchronized_#{meth} #{meth}
         def #{meth}(*a, &b)
@@ -144,8 +144,8 @@ class Object
     end
   end
 
-  def ignore_concurrent_calls *meth
-    meth.each do
+  def ignore_concurrent_calls *methods
+    methods.each do |meth|
       mutex = "@__concurrent_protector_#{meth}"
       flag = "@__concurrent_flag_#{meth}"
       oldmeth = "__unprotected_#{meth}"
@@ -213,7 +213,7 @@ class String
     region_start = 0
     while pos <= length
       newpos = case state
-        when :escaped_instring, :escaped_outstring: pos
+        when :escaped_instring, :escaped_outstring then pos
         else index(/[,"\\]/, pos)
       end 
       
@@ -227,26 +227,26 @@ class String
       case char
       when ?"
         state = case state
-          when :outstring: :instring
-          when :instring: :outstring
-          when :escaped_instring: :instring
-          when :escaped_outstring: :outstring
+          when :outstring then :instring
+          when :instring then :outstring
+          when :escaped_instring then :instring
+          when :escaped_outstring then :outstring
         end
       when ?,, nil
         state = case state
-          when :outstring, :escaped_outstring:
+          when :outstring, :escaped_outstring then
             ret << self[region_start ... newpos].gsub(/^\s+|\s+$/, "")
             region_start = newpos + 1
             :outstring
-          when :instring: :instring
-          when :escaped_instring: :instring
+          when :instring then :instring
+          when :escaped_instring then :instring
         end
       when ?\\
         state = case state
-          when :instring: :escaped_instring
-          when :outstring: :escaped_outstring
-          when :escaped_instring: :instring
-          when :escaped_outstring: :outstring
+          when :instring then :escaped_instring
+          when :outstring then :escaped_outstring
+          when :escaped_instring then :instring
+          when :escaped_outstring then :outstring
         end
       end
       pos = newpos + 1
@@ -282,6 +282,12 @@ class String
     gsub(/\t/, "    ").gsub(/\r/, "")
   end
 
+  if not defined? ord
+    def ord
+      self[0]
+    end
+  end
+
   ## takes a space-separated list of words, and returns an array of symbols.
   ## typically used in Sup for translating Ferret's representation of a list
   ## of labels (a string) to an array of label symbols.
@@ -636,10 +642,10 @@ class Iconv
   def self.easy_decode target, charset, text
     return text if charset =~ /^(x-unknown|unknown[-_ ]?8bit|ascii[-_ ]?7[-_ ]?bit)$/i
     charset = case charset
-      when /UTF[-_ ]?8/i: "utf-8"
-      when /(iso[-_ ])?latin[-_ ]?1$/i: "ISO-8859-1"
-      when /iso[-_ ]?8859[-_ ]?15/i: 'ISO-8859-15'
-      when /unicode[-_ ]1[-_ ]1[-_ ]utf[-_]7/i: "utf-7"
+      when /UTF[-_ ]?8/i then "utf-8"
+      when /(iso[-_ ])?latin[-_ ]?1$/i then "ISO-8859-1"
+      when /iso[-_ ]?8859[-_ ]?15/i then 'ISO-8859-15'
+      when /unicode[-_ ]1[-_ ]1[-_ ]utf[-_]7/i then "utf-7"
       else charset
     end