]> diplodocus.org Git - nmh/commitdiff
Merge sbr/norm_charmap.c into sbr/check_charset.c.
authorRalph Corderoy <ralph@inputplus.co.uk>
Tue, 16 May 2017 10:35:49 +0000 (11:35 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Tue, 16 May 2017 10:35:49 +0000 (11:35 +0100)
Alter norm_charmap() to be static now its only caller is in the same
file.  I've checked the upstream cam.ac.uk source and it's still the
same and hasn't changed in years, so I don't think there's much benefit
from having it standalone to ease checking.

Makefile.am
sbr/check_charset.c
sbr/norm_charmap.c [deleted file]

index 5ac9ea545a668aec614d6ef695e0eb5303e6808f..f32d98bb6ff8f253f720bfc8c4b151ec40dc7f69 100644 (file)
@@ -1002,7 +1002,6 @@ sbr_libmh_a_SOURCES = \
     sbr/mime_type.c \
     sbr/mts.c \
     sbr/netsec.c \
-    sbr/norm_charmap.c \
     sbr/oauth.c \
     sbr/oauth_prof.c \
     sbr/path.c \
index 545aab46c8312bf9e88ae2b7e83070aecba899e6..e67b4e3dcc716151cbd206d9a0d686eb1a99b133 100644 (file)
@@ -7,11 +7,10 @@
 
 #include <h/mh.h>
 
+#include <string.h>
 #include <langinfo.h>
 
-/* Only get_charset() should use norm_charmap(), so hide its
-   declaration here. */
-char *norm_charmap(char *);
+static char *norm_charmap(char *name);
 
 /*
  * Get the current character set
@@ -80,3 +79,113 @@ write_charset_8bit (void)
 
     return mm_charset;
 }
+
+/* The Single Unix Specification function nl_langinfo(CODESET)
+ * returns the name of the encoding used by the currently selected
+ * locale:
+ *
+ *   http://www.opengroup.org/onlinepubs/7908799/xsh/langinfo.h.html
+ *
+ * Unfortunately the encoding names are not yet standardized.
+ * This function knows about the encoding names used on many
+ * different systems and converts them where possible into
+ * the corresponding MIME charset name registered in
+ *
+ *   http://www.iana.org/assignments/character-sets
+ *
+ * Please extend it as needed and suggest improvements to the author.
+ *
+ * Markus.Kuhn@cl.cam.ac.uk -- 2002-03-11
+ * Permission to use, copy, modify, and distribute this software
+ * for any purpose and without fee is hereby granted. The author
+ * disclaims all warranties with regard to this software.
+ *
+ * Latest version:
+ *
+ *   http://www.cl.cam.ac.uk/~mgk25/ucs/norm_charmap.c
+ */
+
+#define digit(x) ((x) >= '0' && (x) <= '9')
+
+static char buf[16];
+
+static char *
+norm_charmap(char *name)
+{
+  char *p;
+  
+  if (!name)
+    return name;
+  
+  /* Many need no remapping, but they are listed here so you
+   * can see what output to expect, and modify for your needs
+   * as necessary. */
+  if (!strcmp(name, "UTF-8"))
+    return "UTF-8";
+  if (!strcmp(name, "EUC-JP"))
+    return "EUC-JP";
+  if (!strcmp(name, "EUC-KR"))
+    return "EUC-KR";
+  if (!strcmp(name, "EUC-TW"))
+    return "EUC-TW";
+  if (!strcmp(name, "KOI8-R"))
+    return "KOI8-R";
+  if (!strcmp(name, "KOI8-U"))
+    return "KOI8-U";
+  if (!strcmp(name, "GBK"))
+    return "GBK";
+  if (!strcmp(name, "GB2312"))
+    return "GB2312";
+  if (!strcmp(name, "GB18030"))
+    return "GB18030";
+  if (!strcmp(name, "VSCII"))
+    return "VSCII";
+  
+  /* ASCII comes in many names */
+  if (!strcmp(name, "ASCII") ||
+      !strcmp(name, "US-ASCII") ||
+      !strcmp(name, "ANSI_X3.4-1968") ||
+      !strcmp(name, "646") ||
+      !strcmp(name, "ISO646") ||
+      !strcmp(name, "ISO_646.IRV"))
+    return "US-ASCII";
+
+  /* ISO 8859 will be converted to "ISO-8859-x" */
+  if ((p = strstr(name, "8859-"))) {
+    memcpy(buf, "ISO-8859-\0\0", 12);
+    p += 5;
+    if (digit(*p)) {
+      buf[9] = *p++;
+      if (digit(*p)) buf[10] = *p++;
+      return buf;
+    }
+  }
+
+  /* Windows code pages will be converted to "WINDOWS-12xx" */
+  if ((p = strstr(name, "CP12"))) {
+    memcpy(buf, "WINDOWS-12\0\0", 13);
+    p += 4;
+    if (digit(*p)) {
+      buf[10] = *p++;
+      if (digit(*p)) buf[11] = *p++;
+      return buf;
+    }
+  }
+
+  /* TIS-620 comes in at least the following two forms */
+  if (!strcmp(name, "TIS-620") ||
+      !strcmp(name, "TIS620.2533"))
+    return "ISO-8859-11";
+
+  /* For some, uppercase/lowercase might differ */
+  if (!strcmp(name, "Big5") || !strcmp(name, "BIG5"))
+    return "Big5";
+  if (!strcmp(name, "Big5HKSCS") || !strcmp(name, "BIG5HKSCS"))
+    return "Big5HKSCS";
+
+  /* I don't know of any implementation of nl_langinfo(CODESET) out
+   * there that returns anything else (and I'm not even certain all of
+   * the above occur in the wild), but just in case, as a fallback,
+   * return the unmodified name. */
+  return name;
+}
diff --git a/sbr/norm_charmap.c b/sbr/norm_charmap.c
deleted file mode 100644 (file)
index b10cde3..0000000
+++ /dev/null
@@ -1,113 +0,0 @@
-/* norm_charmap.c -- map locale's encoding to MIME charset.
- *
- * The Single Unix Specification function nl_langinfo(CODESET)
- * returns the name of the encoding used by the currently selected
- * locale:
- *
- *   http://www.opengroup.org/onlinepubs/7908799/xsh/langinfo.h.html
- *
- * Unfortunately the encoding names are not yet standardized.
- * This function knows about the encoding names used on many
- * different systems and converts them where possible into
- * the corresponding MIME charset name registered in
- *
- *   http://www.iana.org/assignments/character-sets
- *
- * Please extend it as needed and suggest improvements to the author.
- *
- * Markus.Kuhn@cl.cam.ac.uk -- 2002-03-11
- * Permission to use, copy, modify, and distribute this software
- * for any purpose and without fee is hereby granted. The author
- * disclaims all warranties with regard to this software.
- *
- * Latest version:
- *
- *   http://www.cl.cam.ac.uk/~mgk25/ucs/norm_charmap.c
- */
-
-#include <string.h>
-
-#define digit(x) ((x) >= '0' && (x) <= '9')
-
-static char buf[16];
-
-char *
-norm_charmap(char *name)
-{
-  char *p;
-  
-  if (!name)
-    return name;
-  
-  /* Many need no remapping, but they are listed here so you
-   * can see what output to expect, and modify for your needs
-   * as necessary. */
-  if (!strcmp(name, "UTF-8"))
-    return "UTF-8";
-  if (!strcmp(name, "EUC-JP"))
-    return "EUC-JP";
-  if (!strcmp(name, "EUC-KR"))
-    return "EUC-KR";
-  if (!strcmp(name, "EUC-TW"))
-    return "EUC-TW";
-  if (!strcmp(name, "KOI8-R"))
-    return "KOI8-R";
-  if (!strcmp(name, "KOI8-U"))
-    return "KOI8-U";
-  if (!strcmp(name, "GBK"))
-    return "GBK";
-  if (!strcmp(name, "GB2312"))
-    return "GB2312";
-  if (!strcmp(name, "GB18030"))
-    return "GB18030";
-  if (!strcmp(name, "VSCII"))
-    return "VSCII";
-  
-  /* ASCII comes in many names */
-  if (!strcmp(name, "ASCII") ||
-      !strcmp(name, "US-ASCII") ||
-      !strcmp(name, "ANSI_X3.4-1968") ||
-      !strcmp(name, "646") ||
-      !strcmp(name, "ISO646") ||
-      !strcmp(name, "ISO_646.IRV"))
-    return "US-ASCII";
-
-  /* ISO 8859 will be converted to "ISO-8859-x" */
-  if ((p = strstr(name, "8859-"))) {
-    memcpy(buf, "ISO-8859-\0\0", 12);
-    p += 5;
-    if (digit(*p)) {
-      buf[9] = *p++;
-      if (digit(*p)) buf[10] = *p++;
-      return buf;
-    }
-  }
-
-  /* Windows code pages will be converted to "WINDOWS-12xx" */
-  if ((p = strstr(name, "CP12"))) {
-    memcpy(buf, "WINDOWS-12\0\0", 13);
-    p += 4;
-    if (digit(*p)) {
-      buf[10] = *p++;
-      if (digit(*p)) buf[11] = *p++;
-      return buf;
-    }
-  }
-
-  /* TIS-620 comes in at least the following two forms */
-  if (!strcmp(name, "TIS-620") ||
-      !strcmp(name, "TIS620.2533"))
-    return "ISO-8859-11";
-
-  /* For some, uppercase/lowercase might differ */
-  if (!strcmp(name, "Big5") || !strcmp(name, "BIG5"))
-    return "Big5";
-  if (!strcmp(name, "Big5HKSCS") || !strcmp(name, "BIG5HKSCS"))
-    return "Big5HKSCS";
-
-  /* I don't know of any implementation of nl_langinfo(CODESET) out
-   * there that returns anything else (and I'm not even certain all of
-   * the above occur in the wild), but just in case, as a fallback,
-   * return the unmodified name. */
-  return name;
-}