[PATCH] UTF-8 fix

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Jan 31, 2004 at 11:33:26AM +0100, Jean Delvare wrote:
> > sensors doesn't print degree sign correctly on utf-8 console. This
> > patch fixes it.
> 
> Hi Sebek,
> 
> Interesting patch. I'm not using UTF-8 but believe many people do and
> will appreciate the change you propose.
> 
> I took a look at the patch itself and I won't accept it as is, because
> of the code duplication it adds. First because there are three places
> where you have to "intercept" temperature prints (common, lm92 and lm80,
> which you forgot BTW). Second because you have to handle both Celcius
> and Farhenheit each time. I of course do not blame you, but ourselves,
> for that, since this is the base code that is bad.
> 
> I changed that by centralizing the construction of the "degrees" string
> in a single place (in main.c, because it is in no way chip dependant). I
> just commited the change to CVS.
> 
> I would appreciate it much if you could checkout our CVS code (module
> lm_sensors2) and submit a new patch based on it. You should only need to
> intervene in one place (where degstr is built, in main.c), which will
> make the patch much cleaner IMHO.
> 
> I don't do it myself because 1* I'd like you to test the change I just
> made and 2* I couldn't test the UTF-8 thing, so your help is needed
> anyway.
> 
> Thanks.
> 

OK, here's new patch against latest CVS tree.


diff -urN lm_sensors2/CHANGES lm_sensors2-new/CHANGES
--- lm_sensors2/CHANGES	2004-01-24 14:51:11.000000000 +0100
+++ lm_sensors2-new/CHANGES	2004-01-31 11:42:30.000000000 +0100
@@ -31,6 +31,7 @@
                    Drop linux 2.2 support
                    Add w83627hf
   Program sensors: Do not show algorithm by default
+                   Fix output to UTF-8 console
   Program sensors-detect: Fix PATH issues
   
 
diff -urN lm_sensors2/prog/sensors/main.c lm_sensors2-new/prog/sensors/main.c
--- lm_sensors2/prog/sensors/main.c	2004-01-31 11:27:48.000000000 +0100
+++ lm_sensors2-new/prog/sensors/main.c	2004-01-31 11:41:49.000000000 +0100
@@ -22,6 +22,8 @@
 #include <getopt.h>
 #include <string.h>
 #include <errno.h>
+#include <locale.h>
+#include <langinfo.h>
 
 #include "lib/sensors.h" 
 #include "lib/error.h"
@@ -169,6 +171,8 @@
     { 0,0,0,0 }
   };
 
+  setlocale(LC_CTYPE, "");
+
   do_unknown = 0;
   do_sets = 0;
   show_algorithm = 0;
@@ -248,7 +252,10 @@
   close_config_file();
 
   /* build the degrees string */
-  sprintf(degstr, "%c", 176);
+  if (strcmp(nl_langinfo(CODESET), "UTF-8") == 0)
+    sprintf(degstr, "%c%c", 0xc2, 0xb0);
+  else
+    sprintf(degstr, "%c", 176);
   if (fahrenheit) {
     strcat(degstr, "F");
   } else {

-- 
Marcel Sebek
jabber: sebek at jabber.cz                     ICQ: 279852819
linux user number: 307850                 GPG ID: 5F88735E
GPG FP: 0F01 BAB8 3148 94DB B95D  1FCA 8B63 CA06 5F88 735E



[Index of Archives]     [Linux Kernel]     [Linux Hardware Monitoring]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux