// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie // SPDX-License-Identifier: MIT //! Dumps what this library does with every input of a given shape, so that //! something else can be asked the same questions. //! //! The tables here are generated from the index files, so a test written //! against those tables proves only that the generator and the codecs agree. //! What is worth knowing is whether the codecs agree with an implementation //! that was written from the same standards by somebody else, and Python's //! `codecs` module is one: `tools/crosscheck.py` drives this and diffs the //! two, encoding by encoding. //! //! Errors are fatal here rather than replaced, so that a disagreement about //! whether something is an error shows up as one instead of being smoothed //! into a U+FFFD that both sides happen to produce. //! //! ``` //! zig build crosscheck -- windows-1252 decode1 //! zig build crosscheck -- shift_jis decode2 //! zig build crosscheck -- big5 encode //! zig build crosscheck -- glibc:CP932 decode2 //! zig build crosscheck -- glibc members //! ``` //! //! A `glibc:` target is one of glibc's charsets, named as glibc names it, and //! goes through `convertGlibcAlloc` to and from UTF-8, which is exactly what //! a caller wanting glibc's answers uses. `tools/crosscheck_glibc.py` is the //! driver that asks glibc the same questions. const std = @import("std"); const charset = @import("charset"); /// What is being dumped: one of the standard's encodings, or one of the /// EBCDIC code pages or Korean encodings, which are reached by different /// functions. const Target = union(enum) { standard: charset.Encoding, ebcdic: charset.Ebcdic, korean: charset.Korean, glibc: charset.Glibc, }; /// Printed instead of a dump when an encoding has no encoder. The driver /// looks for exactly this. pub const decode_only_marker = "# decode-only"; const Mode = enum { /// Every one-byte input. decode1, /// Every two-byte input. decode2, /// Every scalar value. encode, /// Wansung only: every eight-byte sequence of the filler and three row 4 /// positions, which is how KS X 1001 spells a syllable it has no code /// for. syllables, /// Inputs read from standard input, one to a line, in hexadecimal. decodehex, /// glibc only: UTF-8 read from standard input, one text to a line in /// hexadecimal, and encoded as a whole. encodehex, }; pub fn main(init: std.process.Init) !void { const gpa = init.gpa; var args = init.minimal.args.iterate(); _ = args.next(); const label = args.next() orelse fatal("usage: crosscheck