sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit b01769eac491d02d566a4516509f1a4985cf4f86
parent e93167f4b73635d28d88226fdbba7ac42373d3df
Author: William Morgan <wmorgan-sup@masanjin.net>
Date:   Thu,  9 Apr 2009 15:23:55 -0400

improve dlload of setlocale() and include cygwin

Now we catch errors instead of dying completely, and also add
the correct path for cygwin.

Diffstat:
M bin/sup | 27 +++++++++++++++++++++++++++
M lib/sup.rb | 13 -------------
2 files changed, 27 insertions(+), 13 deletions(-)
diff --git 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
diff --git a/lib/sup.rb b/lib/sup.rb
@@ -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