From fd807aff0645874b2984fc66c565d16a91df52c0 Mon Sep 17 00:00:00 2001
From: Reuben Thomas <rrt@sc3d.org>
Date: Tue, 23 Jan 2018 22:26:42 +0000
Subject: [PATCH] Remove built-in applemac module

Resolve differences with RFC 1345 code. They were caused simply by extra
characters in the latter missing from the former (I compared the two tables
character by character, by eye).
---
 doc/recode.texi    |  49 ++----------
 src/Makefile.am    |   4 +-
 src/applemac.c     | 187 ---------------------------------------------
 src/rfc1345.c      |  30 +++++---
 tests/t21_names.py |   3 +-
 5 files changed, 29 insertions(+), 244 deletions(-)
 delete mode 100644 src/applemac.c

diff --git a/doc/recode.texi b/doc/recode.texi
index 7b03b7a..c6c3f62 100644
--- a/doc/recode.texi
+++ b/doc/recode.texi
@@ -167,7 +167,7 @@ Charsets for CDC machines
 
 Other micro-computer charsets
 
-* Apple-Mac::           Apple's Macintosh code
+* Mac OS::              Apple's Macintosh code
 * AtariST::             Atari ST code
 
 Various other charsets
@@ -3632,35 +3632,14 @@ ASCII character.
 @chapter Other micro-computer charsets
 
 @menu
-* Apple-Mac::           Apple's Macintosh code
+* Mac OS::           Apple's Macintosh code
 * AtariST::             Atari ST code
 @end menu
 
-@node Apple-Mac, AtariST, Micros, Micros
+@node Mac OS, AtariST, Micros, Micros
 @section Apple's Macintosh code
 
-@tindex Apple-Mac
-@cindex Macintosh charset
-This charset is available in Recode under the name @code{Apple-Mac}.
-The shortest way of specifying it in Recode is @code{ap}.
-
-The charset is aimed towards a Macintosh micro-computer from Apple.
-This is an eight bit code.  The file is the data fork only.  This charset
-is fairly old in Recode, its tables were produced a long while ago
-by mere inspection of a printed chart of the Macintosh codes and glyph.
-
-@cindex CR surface, in Macintosh charsets
-It has @code{CR} as its implied surface.  This means that, if the original
-end of lines have to be preserved while going out of @code{Apple-Mac}, they
-should currently be added back through the usage of a surface on the other
-charset, or better, just never removed.  Here are examples for both cases:
-
-@example
-recode ap..l2/cr < @var{input} > @var{output}
-recode ap/..l2 < @var{input} > @var{output}
-@end example
-
-@w{RFC 1345} brings into Recode 2 other Macintosh charsets.  You can
+@w{RFC 1345} brings 2 Macintosh charsets.  You can
 discover them by using @code{grep} over the output of @samp{recode -l}:
 
 @example
@@ -3673,25 +3652,9 @@ recode -l | grep -i mac
 @tindex mac
 @tindex macce
 Charsets @code{macintosh} and @code{macintosh_ce}, as well as their aliases
-@code{mac} and @code{macce} also have @code{CR} as their implied surface.
-
-There are a few discrepancies between the @code{Apple-Mac} charset and
-the very similar @w{RFC 1345} charset @code{macintosh}, which have not been
-analysed yet, so the charsets are being kept separate for now.  This might
-change in the future, and the @code{Apple-Mac} charset might disappear.
-Wizards would be interested in comparing the output of these two commands:
-
-@example
-recode -vh Apple-Mac..Latin-1
-recode -vh macintosh..Latin-1
-@end example
-
-@noindent
-The first command use the charset prior to @w{RFC 1345} introduction.
-Both methods give different recodings.  These differences are annoying,
-the fuzziness will have to be explained and settle down one day.
+@code{mac} and @code{macce} have @code{CR} as their implied surface.
 
-@node AtariST,  , Apple-Mac, Micros
+@node AtariST,  , Mac OS, Micros
 @section Atari ST code
 
 @tindex AtariST
diff --git a/src/Makefile.am b/src/Makefile.am
index 7db1a48..66a8545 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -34,7 +34,7 @@ EXTRA_DIST = stamp-steps stamp-strip $(L_STEPS) mergelex.py $(MANS)
 
 CLEANFILES = iconvdecl.h
 
-C_STEPS = african.c afrtran.c applemac.c atarist.c bangbang.c cdcnos.c \
+C_STEPS = african.c afrtran.c atarist.c bangbang.c cdcnos.c \
 ebcdic.c ibmpc.c iconqnx.c lat1asci.c lat1iso5426.c lat1ansel.c \
 java.c mule.c strip-data.c testdump.c ucs.c utf16.c utf7.c utf8.c varia.c vn.c
 
@@ -125,7 +125,7 @@ iconvdecl.h: ../tables.py
 	perl -npe 's/{ put_byte \(//;s /, subtask\); }//;s%^\\%%' | \
 	perl -ne '($$a,$$b)=split; $$c=substr($$a,0,3);$$d=substr($$a,3);$$e = eval "0$$c"; next if $$b < 0200 ;printf("\t{%d, \"%c%s\"}, %s* %c *%s\n", $$b, $$e, $$d, "/", $$b, "/")' > $@
 
-african.lo afrtran.lo applemac.lo atarist.lo bangbang.lo cdcnos.lo \
+african.lo afrtran.lo atarist.lo bangbang.lo cdcnos.lo \
 ebcdic.lo ibmpc.lo iconqnx.lo lat1asci.lo lat1iso5426.lo lat1ansel.lo \
 java.lo mule.lo strip-data.lo testdump.lo ucs.lo utf16.lo utf7.lo utf8.lo \
 varia.lo vn.lo flat.lo html.lo lat1ltex.lo lat1txte.lo rfc1345.lo \
diff --git a/src/applemac.c b/src/applemac.c
deleted file mode 100644
index 20c8f04..0000000
--- a/src/applemac.c
+++ /dev/null
@@ -1,187 +0,0 @@
-/* Conversion of files between different charsets and surfaces.
-   Copyright © 1990, 93, 97, 98, 99, 00 Free Software Foundation, Inc.
-   Contributed by François Pinard <pinard@iro.umontreal.ca>, 1993.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public License
-   as published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
-
-   This library is distributed in the hope that it will be
-   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
-   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the Recode Library; see the file `COPYING.LIB'.
-   If not, write to the Free Software Foundation, Inc., 59 Temple Place -
-   Suite 330, Boston, MA 02111-1307, USA.  */
-
-#include "common.h"
-#include "decsteps.h"
-
-/* Previously, the LF surface was built-in.  It is now handled through a
-   separate, optional step.  An optimisation might use a flag to trigger old
-   built-in code.  For now, depend on a variable preset to false.  */
-static const bool auto_cr = false;
-
-/* Data for Apple Macintosh to ISO Latin-1 code conversions.  */
-
-static struct recode_known_pair known_pairs[] =
-  {
-    { 13,  10},			/* (recoding end of lines for Unix) */
-    /* The previous pair should be first, for being skippable.  */
-
-    {128, 196},			/* capital letter A diaeresis */
-    {129, 197},			/* capital letter A with ring above */
-    {130, 199},			/* capital letter C with cedilla */
-    {131, 201},			/* capital letter E with acute accent */
-    {132, 209},			/* capital letter N with tilde */
-    {133, 214},			/* capital letter O with diaeresis */
-    {134, 220},			/* capital letter U with diaeresis */
-    {135, 225},			/* small letter a with acute accent */
-    {136, 224},			/* small letter a with grave accent */
-    {137, 226},			/* small letter a with circumflex accent */
-    {138, 228},			/* small letter a with diaeresis */
-    {139, 227},			/* small letter a with tilde */
-    {140, 229},			/* small letter a with ring above */
-    {141, 231},			/* small letter c with cedilla */
-    {142, 233},			/* small letter e with acute accent */
-    {143, 232},			/* small letter e with grave accent */
-    {144, 234},			/* small letter e with circumflex accent */
-    {145, 235},			/* small letter e with diaeresis */
-    {146, 237},			/* small letter i with acute accent */
-    {147, 236},			/* small letter i with grave accent */
-    {148, 238},			/* small letter i with circumflex accent */
-    {149, 239},			/* small letter i with diaeresis */
-    {150, 241},			/* small letter n with tilde */
-    {151, 243},			/* small letter o with acute accent */
-    {152, 242},			/* small letter o with grave accent */
-    {153, 244},			/* small letter o with circumflex accent */
-    {154, 246},			/* small letter o with diaeresis */
-    {155, 245},			/* small letter o with tilde */
-    {156, 250},			/* small letter u with acute accent */
-    {157, 249},			/* small letter u with grave accent */
-    {158, 251},			/* small letter u with circumflex accent */
-    {159, 252},			/* small letter u with diaeresis */
-
-    {161, 176},			/* degree sign */
-    {162, 162},			/* cent sign */
-    {163, 163},			/* pound sign */
-    {164, 167},			/* paragraph sign, section sign */
-
-    {166, 182},			/* pilcrow sign */
-    {167, 223},			/* small german letter sharp s */
-    {168, 174},			/* registered trade mark sign */
-    {169, 169},			/* copyright sign */
-
-    {174, 198},			/* capital diphthong A with E */
-    {175, 216},			/* capital letter O with oblique stroke */
-
-    {177, 177},			/* plus-minus sign */
-
-    {180, 165},			/* yen sign */
-    {181, 181},			/* small greek letter mu, micro sign */
-
-    {187, 170},			/* feminine ordinal indicator */
-    {188, 186},			/* masculine ordinal indicator */
-
-    {190, 230},			/* small diphthong a with e */
-    {191, 248},			/* small letter o with oblique stroke */
-    {192, 191},			/* inverted question mark */
-    {193, 161},			/* inverted exclamation mark */
-    {194, 172},			/* not sign */
-
-    {199, 171},			/* left angle quotation mark */
-    {200, 187},			/* right angle quotation mark */
-
-    {203, 192},			/* capital letter A with grave accent */
-    {204, 195},			/* capital letter A with tilde */
-    {205, 213},			/* capital letter O with tilde */
-
-    {214, 247},			/* division sign */
-
-    {216, 255},			/* small letter y with diaeresis */
-    {217, 221},			/* capital letter Y with acute accent */
-
-    {229, 194},			/* capital letter A with circumflex accent */
-    {230, 202},			/* capital letter E with circumflex accent */
-    {231, 193},			/* capital letter A with acute accent */
-    {232, 203},			/* capital letter E with diaeresis */
-    {233, 200},			/* capital letter E with grave accent */
-    {234, 205},			/* capital letter I with acute accent */
-    {235, 206},			/* capital letter I with circumflex accent */
-    {236, 207},			/* capital letter I with diaeresis */
-    {237, 204},			/* capital letter I with grave accent */
-    {238, 211},			/* capital letter O with acute accent */
-    {239, 212},			/* capital letter O with circumflex accent */
-
-    {241, 210},			/* capital letter O with grave accent */
-    {242, 218},			/* capital letter U with acute accent */
-    {243, 219},			/* capital letter U with circumflex accent */
-    {244, 217},			/* capital letter U with grave accent */
-  };
-#define NUMBER_OF_PAIRS (sizeof (known_pairs) / sizeof (struct recode_known_pair))
-
-static bool
-init_latin1_applemac (RECODE_STEP step,
-		      RECODE_CONST_REQUEST request,
-		      RECODE_CONST_OPTION_LIST before_options,
-		      RECODE_CONST_OPTION_LIST after_options)
-{
-  if (before_options || after_options)
-    return false;
-
-  return auto_cr
-    ? complete_pairs (request->outer, step,
-		      known_pairs, NUMBER_OF_PAIRS, true, true)
-    : complete_pairs (request->outer, step,
-		      known_pairs + 1, NUMBER_OF_PAIRS - 1, true, true);
-}
-
-static bool
-init_applemac_latin1 (RECODE_STEP step,
-		      RECODE_CONST_REQUEST request,
-		      RECODE_CONST_OPTION_LIST before_options,
-		      RECODE_CONST_OPTION_LIST after_options)
-{
-  if (before_options || after_options)
-    return false;
-
-  return auto_cr
-    ? complete_pairs (request->outer, step,
-		      known_pairs, NUMBER_OF_PAIRS, true, false)
-    : complete_pairs (request->outer, step,
-		      known_pairs + 1, NUMBER_OF_PAIRS - 1, true, false);
-}
-
-bool
-module_applemac (RECODE_OUTER outer)
-{
-  RECODE_ALIAS alias;
-
-  if (!declare_single (outer, "Latin-1", "Apple-Mac",
-		       outer->quality_byte_to_variable,
-		       init_latin1_applemac, NULL))
-    return false;
-  if (!declare_single (outer, "Apple-Mac", "Latin-1",
-		       outer->quality_byte_to_variable,
-		       init_applemac_latin1, NULL))
-    return false;
-
-  if (alias = declare_alias (outer, "Apple-Mac", "Apple-Mac"), !alias)
-    return false;
-  if (!declare_implied_surface (outer, alias, outer->cr_surface))
-    return false;
-#if 0
-  /* FIXME!  */
-  if (!declare_alias (outer, "Apple-Mac", "macintosh"))
-    return false;
-#endif
-  return true;
-}
-
-_GL_ATTRIBUTE_CONST void
-delmodule_applemac (RECODE_OUTER outer _GL_UNUSED_PARAMETER)
-{
-}
diff --git a/src/rfc1345.c b/src/rfc1345.c
index dbfac2d..e2f3c0a 100644
--- a/src/rfc1345.c
+++ b/src/rfc1345.c
@@ -275,16 +275,26 @@ init_rfc1345_ucs2 (RECODE_STEP step,
 bool
 module_rfc1345 (RECODE_OUTER outer)
 {
-  return
-    declare_single (outer, "ISO-10646-UCS-2", "RFC1345",
-		    outer->quality_variable_to_variable,
-		    init_ucs2_rfc1345, transform_ucs2_rfc1345)
-    && declare_single (outer, "RFC1345", "ISO-10646-UCS-2",
-		       outer->quality_variable_to_variable,
-		       init_rfc1345_ucs2, transform_rfc1345_ucs2)
-
-    && declare_alias (outer, "1345", "RFC1345")
-    && declare_alias (outer, "mnemonic", "RFC1345");
+  RECODE_ALIAS alias;
+
+  if
+    (!declare_single (outer, "ISO-10646-UCS-2", "RFC1345",
+                      outer->quality_variable_to_variable,
+                      init_ucs2_rfc1345, transform_ucs2_rfc1345)
+     || !declare_single (outer, "RFC1345", "ISO-10646-UCS-2",
+                         outer->quality_variable_to_variable,
+                         init_rfc1345_ucs2, transform_rfc1345_ucs2)
+     || !declare_alias (outer, "1345", "RFC1345")
+     || !declare_alias (outer, "mnemonic", "RFC1345"))
+    return false;
+
+  /* Aliases for obsolete built-in encodings */
+  if (alias = declare_alias (outer, "Apple-Mac", "macintosh"), !alias)
+    return false;
+  if (!declare_implied_surface (outer, alias, outer->cr_surface))
+    return false;
+
+  return true;
 }
 
 _GL_ATTRIBUTE_CONST void
diff --git a/tests/t21_names.py b/tests/t21_names.py
index f5b49fa..6848b96 100644
--- a/tests/t21_names.py
+++ b/tests/t21_names.py
@@ -30,7 +30,6 @@ AFRL1-101-BPI_OCIL t-fra t-francais
 AFRLIN-104-BPI_OCIL lin lingala sango wolof
 AFRLIN-105-BPI_OCIL t-lin t-lingala t-sango t-wolof
 ANSI_X3.4-1968 367/CR-LF ANSI_X3.4-1986 ASCII CP367/CR-LF IBM367/CR-LF ISO646-US iso-ir-6 ISO_646.irv:1991 us US-ASCII
-Apple-Mac/CR
 ASCII-BS BS
 ASMO_449 arabic7 iso-ir-89 ISO_9036
 AtariST
@@ -197,7 +196,7 @@ LaTeX ltex TeX
 latin-greek iso-ir-19
 Latin-greek-1 iso-ir-27
 mac-is
-macintosh/CR mac/CR
+macintosh/CR Apple-Mac/CR mac/CR
 macintosh_ce/CR macce/CR
 MSZ_7795.3 hu ISO646-HU iso-ir-86
 Mule
-- 
2.40.0