This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

an error message in the iconv program


Here is an improvement for iconv's error message when one of the two encoding
names is wrong. Many users are confused when an error message tells them that
one of two encoding names is wrong, but not which one.


2002-09-22  Bruno Haible  <bruno@clisp.org>

	* iconv/iconv_prog.c (main): Provide an error message that identifies
	the wrong encoding.

--- glibc-20020828/iconv/iconv_prog.c.bak	Mon Aug 26 15:49:36 2002
+++ glibc-20020828/iconv/iconv_prog.c	Sun Sep 22 23:23:14 2002
@@ -28,6 +28,7 @@
 #include <langinfo.h>
 #include <locale.h>
 #include <search.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -216,10 +217,47 @@
       if (cd == (iconv_t) -1)
 	{
 	  if (errno == EINVAL)
-	    error (EXIT_FAILURE, 0,
-		   _("conversion from `%s' to `%s' not supported"),
-		   from_code[0] ? from_code : nl_langinfo (CODESET),
-		   orig_to_code[0] ? orig_to_code : nl_langinfo (CODESET));
+	    {
+	      /* Try to be nice with the user and tell her which of the
+		 two encoding names is wrong.  This is possible because
+		 all supported encodings can be converted from/to Unicode,
+		 in other words, because the graph of encodings is
+		 connected.  */
+	      bool from_wrong =
+		(iconv_open ("UTF-8", from_code) == (iconv_t) -1
+		 && errno == EINVAL);
+	      bool to_wrong =
+		(iconv_open (to_code, "UTF-8") == (iconv_t) -1
+		 && errno == EINVAL);
+	      const char *from_pretty =
+		(from_code[0] ? from_code : nl_langinfo (CODESET));
+	      const char *to_pretty =
+		(orig_to_code[0] ? orig_to_code : nl_langinfo (CODESET));
+
+	      if (from_wrong)
+		{
+		  if (to_wrong)
+		    error (EXIT_FAILURE, 0,
+			   _("\
+conversions from `%s' and to `%s' are not supported"),
+			   from_pretty, to_pretty);
+		  else
+		    error (EXIT_FAILURE, 0,
+			   _("conversion from `%s' is not supported"),
+			   from_pretty);
+		}
+	      else
+		{
+		  if (to_wrong)
+		    error (EXIT_FAILURE, 0,
+			   _("conversion to `%s' is not supported"),
+			   to_pretty);
+		  else
+		    error (EXIT_FAILURE, 0,
+			   _("conversion from `%s' to `%s' is not supported"),
+			   from_pretty, to_pretty);
+		}
+	    }
 	  else
 	    error (EXIT_FAILURE, errno,
 		   _("failed to start conversion processing"));


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]