Allow overriding the newline conversion for EBCDIC encodings.
commit19b6af5e5efe306bc1b2da87ba054b7391360ca2
authorBruno Haible <bruno@clisp.org>
Mon, 3 Apr 2023 02:12:01 +0000 (3 04:12 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 3 Apr 2023 10:19:29 +0000 (3 12:19 +0200)
tree3fb524d4812ac6d16803d834adcb0ac8663fa556
parentaf6ae1c592215f12bbf97df3ace70e01d804c64a
Allow overriding the newline conversion for EBCDIC encodings.

Reported by Mike Fulton <mikefultonpersonal@gmail.com> in
<https://lists.gnu.org/archive/html/bug-gnu-libiconv/2023-04/msg00009.html>.

* include/iconv.h.in (ICONV_SURFACE_NONE,
ICONV_SURFACE_EBCDIC_ZOS_UNIX): New macros.
(ICONV_GET_FROM_SURFACE, ICONV_SET_FROM_SURFACE, ICONV_GET_TO_SURFACE,
ICONV_SET_TO_SURFACE): New macros.
* lib/converters.h (struct conv_struct): Add the fields isurface,
osurface.
(swap_x15_x25): New macro.
* lib/iconv.c (iconv_open, iconv_open_into): Add local variables
from_surface, to_surface.
(ALL_SURFACES): New macro.
(iconvctl): Adjust ICONV_TRIVIALP implementation. Implement the
ICONV_{GET,SET}_{FROM,TO}_SURFACE requests.
* lib/iconv_open1.h: Parse a /ZOS_UNIX surface specifier. Set
from_surface, to_surface.
* lib/iconv_open2.h: Copy the values of from_surface, to_surface into
the conversion descriptor.
* lib/ebcdic*.h (*_mbtowc): Test the isurface. If requested, call
swap_x15_x25 right after fetching an input byte.
(*_wctomb): Test the osurface. If requested, call swap_x15_x25 right
before storing an output byte.
* man/iconvctl.3 (REQUEST VALUES): Document the
ICONV_{GET,SET}_{FROM,TO}_SURFACE requests.
* src/iconv.c (main): If ICONV_EBCDIC_ZOS_UNIX is set, set the from/to
surfaces accordingly.
* man/iconv.1 (ENVIRONMENT): New section.
* tests/check-ebcdic: New file.
* tests/Makefile.in (check): Invoke it.
(SOURCE_FILES): Add it.
* NEWS: Mention the new functionality.
65 files changed:
ChangeLog
NEWS
include/iconv.h.in
lib/converters.h
lib/ebcdic037.h
lib/ebcdic1025.h
lib/ebcdic1026.h
lib/ebcdic1047.h
lib/ebcdic1097.h
lib/ebcdic1112.h
lib/ebcdic1122.h
lib/ebcdic1123.h
lib/ebcdic1130.h
lib/ebcdic1132.h
lib/ebcdic1137.h
lib/ebcdic1140.h
lib/ebcdic1141.h
lib/ebcdic1142.h
lib/ebcdic1143.h
lib/ebcdic1144.h
lib/ebcdic1145.h
lib/ebcdic1146.h
lib/ebcdic1147.h
lib/ebcdic1148.h
lib/ebcdic1149.h
lib/ebcdic1153.h
lib/ebcdic1154.h
lib/ebcdic1155.h
lib/ebcdic1156.h
lib/ebcdic1157.h
lib/ebcdic1158.h
lib/ebcdic1160.h
lib/ebcdic1164.h
lib/ebcdic1165.h
lib/ebcdic1166.h
lib/ebcdic12712.h
lib/ebcdic16804.h
lib/ebcdic273.h
lib/ebcdic277.h
lib/ebcdic278.h
lib/ebcdic280.h
lib/ebcdic282.h
lib/ebcdic284.h
lib/ebcdic285.h
lib/ebcdic297.h
lib/ebcdic423.h
lib/ebcdic424.h
lib/ebcdic425.h
lib/ebcdic4971.h
lib/ebcdic500.h
lib/ebcdic838.h
lib/ebcdic870.h
lib/ebcdic871.h
lib/ebcdic875.h
lib/ebcdic880.h
lib/ebcdic905.h
lib/ebcdic924.h
lib/iconv.c
lib/iconv_open1.h
lib/iconv_open2.h
man/iconv.1
man/iconvctl.3
src/iconv.c
tests/Makefile.in
tests/check-ebcdic [new file with mode: 0755]