]> git.notmuchmail.org Git - sup/commitdiff
improve dlload of setlocale() and include cygwin
authorWilliam Morgan <wmorgan-sup@masanjin.net>
Thu, 9 Apr 2009 19:23:55 +0000 (15:23 -0400)
committerWilliam Morgan <wmorgan-sup@masanjin.net>
Thu, 9 Apr 2009 19:23:55 +0000 (15:23 -0400)
Now we catch errors instead of dying completely, and also add
the correct path for cygwin.

bin/sup
lib/sup.rb

diff --git a/bin/sup b/bin/sup
index d8eee0e3215fff5cc52470a4695aef3c561e60d4..e4b28d8c826f1caa5f3000cd713c36ebd5dab92e 100644 (file)
--- a/bin/sup
+++ b/bin/sup
@@ -81,6 +81,33 @@ global_keymap = Keymap.new do |k|
   k.add :recall_draft, "Edit most recent draft message", 'R'
 end
 
+## the following magic enables wide characters when used with a ruby
+## ncurses.so that's been compiled against libncursesw. (note the w.) why
+## this works, i have no idea. much like pretty much every aspect of
+## dealing with curses.  cargo cult programming at its best.
+##
+## BSD users: if libc.so.6 is not found, try installing compat6x.
+require 'dl/import'
+module LibC
+  extend DL::Importable
+  setlocale_lib = case Config::CONFIG['arch']
+    when /darwin/; "libc.dylib"
+    when /cygwin/; "cygwin1.dll"
+    else; "libc.so.6"
+  end
+
+  Redwood::log "dyamically loading setlocale() from #{setlocale_lib}"
+  begin
+    dlload setlocale_lib
+    extern "void setlocale(int, const char *)"
+    Redwood::log "setting locale..."
+    LibC.setlocale(6, "")  # LC_ALL == 6
+  rescue RuntimeError => e
+    Redwood::log "cannot dlload setlocale(); ncurses wide character support probably broken."
+    Redwood::log "dlload error was #{e.class}: #{e.message}"
+  end
+end
+
 def start_cursing
   Ncurses.initscr
   Ncurses.noecho
index 92ace7d8f0c3072dbb2a98393fe7fd8484945b4d..64e8cba5dfdf201fef311c6e17b1002becf8a8f4 100644 (file)
@@ -6,19 +6,6 @@ require 'fileutils'
 require 'gettext'
 require 'curses'
 
-## the following magic enables wide characters when used with a ruby
-## ncurses.so that's been compiled against libncursesw. (note the w.) why
-## this works, i have no idea. much like pretty much every aspect of
-## dealing with curses.  cargo cult programming at its best.
-
-require 'dl/import'
-module LibC
-  extend DL::Importable
-  dlload Config::CONFIG['arch'] =~ /darwin/ ? "libc.dylib" : "libc.so.6"
-  extern "void setlocale(int, const char *)"
-end
-LibC.setlocale(6, "")  # LC_ALL == 6
-
 class Object
   ## this is for debugging purposes because i keep calling #id on the
   ## wrong object and i want it to throw an exception