All of lore.kernel.org
 help / color / mirror / Atom feed
From: aurelien@aurel32.net (Aurelien Jarno)
To: lm-sensors@vger.kernel.org
Subject: [PATCH] sensors: print the degree sign in the terminal's current
Date: Thu, 19 May 2005 06:24:48 +0000	[thread overview]
Message-ID: <20040321133822.GA19334@pc.aurel32.private> (raw)
In-Reply-To: <20040321013630.GA28378@pc.aurel32.private>

On Sun, Mar 21, 2004 at 02:36:30AM +0100, Aurelien Jarno wrote:
> Hi all,
> 
> To print the degree sign, sensors lookups the current locale, outputs it
> in UTF-8 if the locale is in UTF-8, and in latin-1 otherwise. However
> some people are using other locales. Moreover, it is rather irritating
> for people using a Japanese locale, as the character code 176 is a start
> of sequence of characters for EUC terminals.

Please find attached a new patch, I hope less ugly than the previous
one. I made it using the advice Jean Delvare give me on IRC.

Aurelien

-- 
  .''`.  Aurelien Jarno	              GPG: 1024D/F1BCDB73
 : :' :  Debian GNU/Linux developer | Electrical Engineering Student 
 `. `'   aurel32@debian.org         | aurelien@aurel32.net
   `-    people.debian.org/~aurel32 | www.aurel32.net
-------------- next part --------------
Index: prog/sensors/main.c
=================================RCS file: /home/cvs/lm_sensors2/prog/sensors/main.c,v
retrieving revision 1.90
diff -u -1 -b -p -r1.90 main.c
--- lm_sensors2.orig/prog/sensors/main.c	29 Feb 2004 18:43:53 -0000	1.90
+++ lm_sensors2/prog/sensors/main.c	21 Mar 2004 12:15:33 -0000
@@ -26,2 +26,3 @@
 #include <langinfo.h>
+#include <iconv.h>
 
@@ -156,2 +157,25 @@ void close_config_file(void)
 
+static void set_degstr(void)
+{
+  /* Size hardcoded for better performance. Don't forget to count \0 !!! */
+  size_t deg_latin1_size = 3;
+  char *deg_latin1_text[2] = {"\260C", "\260F"};
+  const char *deg_default_text[2] = {" C", " F"};
+  size_t nconv;
+  size_t degstr_size = sizeof(degstr);
+  char *degstr_ptr = degstr;
+
+  iconv_t cd = iconv_open(nl_langinfo(CODESET), "ISO-8859-1");
+  if (cd != (iconv_t) -1) {
+    nconv = iconv(cd, &(deg_latin1_text[fahrenheit]), &deg_latin1_size, &degstr_ptr, &degstr_size);
+    iconv_close(cd);
+    
+    if (nconv > 0) 
+      return;	   
+  }
+
+  /* There was an error during the conversion, use the default text */
+  strcpy(degstr, deg_default_text[fahrenheit]);
+}
+
 int main (int argc, char *argv[])
@@ -255,11 +279,3 @@ int main (int argc, char *argv[])
   /* build the degrees string */
-  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 {
-    strcat(degstr, "C");
-  }
+  set_degstr();
 

  reply	other threads:[~2005-05-19  6:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-19  6:24 [PATCH] sensors: print the degree sign in the terminal's current Aurelien Jarno
2005-05-19  6:24 ` Aurelien Jarno [this message]
2005-05-19  6:24 ` [PATCH] sensors: print the degree sign in the terminal's Jean Delvare

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040321133822.GA19334@pc.aurel32.private \
    --to=aurelien@aurel32.net \
    --cc=lm-sensors@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.