From mboxrd@z Thu Jan 1 00:00:00 1970 From: wmorgan-sup@masanjin.net (William Morgan) Date: Wed, 09 Jan 2008 10:00:53 -0800 Subject: [sup-talk] the proper way of determining the encoding In-Reply-To: <1199695733-sup-2741@clarabella.clarabella> References: <1199569265-sup-4567@clarabella.clarabella> <1199685831-sup-2011@south> <1199695733-sup-2741@clarabella.clarabella> Message-ID: <1199901555-sup-2661@south> Excerpts from Giorgio Lando's message of Mon Jan 07 00:51:08 -0800 2008: > I understand. May be the encoding problems are so intricate and > heterogeneous that they could be worth a configuration option, so the > user can in anyway force a certain encoding if needed/desired? I'm certainly happy to allow users to force a certain encoding, but I think largely issue of encoding problems HAS been solved (at least on Unixes) by locale and all the LC_* environment variables. I'm certainly not an export on this stuff, though. I just committed the following terrible patch to next, which should properly find everyone's locale, if they have a locale. Mac users, I'd love to know if this actually works for you. commit 6af3048fe82f48f0368a619ea785f0a394b0bbd4 Author: William Morgan Date: Wed Jan 9 08:30:30 2008 -0800 detect character set correctly (but unix-centrically) diff --git a/lib/sup.rb b/lib/sup.rb index 25809dd..5bb27ba 100644 --- a/lib/sup.rb +++ b/lib/sup.rb @@ -49,16 +49,6 @@ module Redwood YAML_DOMAIN = "masanjin.net" YAML_DATE = "2006-10-01" -## determine encoding and character set -## probably a better way to do this - $ctype = ENV["LC_CTYPE"] || ENV["LANG"] || "en-US.utf-8" - $encoding = - if $ctype =~ /\.(.*)?/ - $1 - else - "utf-8" - end - ## record exceptions thrown in threads nicely def reporting_thread name if $opts[:no_threads] @@ -235,6 +225,16 @@ module Redwood module_function :log end +## determine encoding and character set. there MUST be a better way to +## do this. + $encoding = `locale -c LC_CTYPE|head -6|tail -1`.chomp + if $encoding + Redwood::log "using character set encoding #{$encoding.inspect}" + else + Redwood::log "warning: can't find character set by using locale, defaulting + $encoding = "utf-8" + end + ## now everything else (which can feel free to call Redwood::log at load time) require "sup/update" require "sup/suicide" -- William