diff options
author | Norbert Preining <norbert@preining.info> | 2020-10-12 03:04:00 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2020-10-12 03:04:00 +0000 |
commit | 0ce40abb18ec02ec6fd6bcc5f21612c88daa7578 (patch) | |
tree | 416289fe1448873fd8ca33051f50ad85bffa8aaa /support/dktools/dk4strmo32.c | |
parent | fdb18507cd80dc17f5a5256153d34668b4f4e61c (diff) |
CTAN sync 202010120303
Diffstat (limited to 'support/dktools/dk4strmo32.c')
-rw-r--r-- | support/dktools/dk4strmo32.c | 296 |
1 files changed, 0 insertions, 296 deletions
diff --git a/support/dktools/dk4strmo32.c b/support/dktools/dk4strmo32.c deleted file mode 100644 index 83ba2a9290..0000000000 --- a/support/dktools/dk4strmo32.c +++ /dev/null @@ -1,296 +0,0 @@ -/* -Copyright (C) 2015-2020, Dirk Krause -SPDX-License-Identifier: BSD-3-Clause -*/ - -/* - WARNING: This file was generated by the dkct program (see - http://dktools.sourceforge.net/ for details). - Changes you make here will be lost if dkct is run again! - You should modify the original source and run dkct on it. - Original source: dk4strmo32.ctr -*/ - -/** @file dk4strmo32.c The dk4strmo32 module. -*/ - - -#line 110 "dk4strmo32.ctr" - -#include "dk4conf.h" -#include "dk4strmo32.h" -#include "dk4mem.h" -#include "dk4ansi.h" -#include "dk4utf8.h" -#include "dk4utf16.h" -#include "dk4enc.h" -#include "dk4rec26.h" - -#if DK4_HAVE_ASSERT_H -#ifndef ASSERT_H_INCLUDED -#include <assert.h> -#define ASSERT_H_INCLUDED 1 -#endif -#endif - - - - -#line 129 "dk4strmo32.ctr" - - - -void -dk4stream_set_output_encoding(dk4_stream_t *strm, int oe) -{ - - -#line 136 "dk4strmo32.ctr" -#if DK4_USE_ASSERT - assert(NULL != strm); -#endif - if (NULL != strm) { - switch (oe) { - case DK4_FILE_ENCODING_PLAIN: - case DK4_FILE_ENCODING_WIN1252: - case DK4_FILE_ENCODING_UTF8: - case DK4_FILE_ENCODING_UTF16_LE: - case DK4_FILE_ENCODING_UTF16_BE: - case DK4_FILE_ENCODING_32_LE: - case DK4_FILE_ENCODING_32_BE: - { - strm->oenc = oe; - } break; - } - } - -#line 153 "dk4strmo32.ctr" -} - - - -int -dk4stream_c32_putc(dk4_stream_t *strm, dk4_c32_t c32, dk4_er_t *erp) -{ - unsigned char buf[16]; - dk4_c16_t b16[4]; - size_t sz; - int back = 0; - - -#line 165 "dk4strmo32.ctr" -#if DK4_USE_ASSERT - assert(NULL != strm); -#endif - if (NULL != strm) { - -#line 169 "dk4strmo32.ctr" - if (0 != ((strm->fl) & DK4_STREAM_WRITE)) { - -#line 170 "dk4strmo32.ctr" - switch (strm->oenc) { - case DK4_FILE_ENCODING_PLAIN: { - -#line 172 "dk4strmo32.ctr" - if (dkC32(0x00000100) > c32) { - back = dk4stream_write_byte(strm, (unsigned char)c32, erp); - } else { - dk4error_set_simple_error_code(erp, DK4_E_ENCODING_FAILED); - } - } break; - case DK4_FILE_ENCODING_WIN1252: { - -#line 179 "dk4strmo32.ctr" - if (0 != dk4ansi_encode(buf, c32)) { - back = dk4stream_write_byte(strm, buf[0], erp); - } else { - dk4error_set_simple_error_code(erp, DK4_E_ENCODING_FAILED); - } - } break; - case DK4_FILE_ENCODING_UTF8: { - -#line 186 "dk4strmo32.ctr" - sz = sizeof(buf); - if (0 != dk4utf8_encode(buf, &sz, c32, NULL)) { - back = dk4stream_write(strm, (void *)buf, sz, erp); - } else { - dk4error_set_simple_error_code(erp, DK4_E_ENCODING_FAILED); - } - } break; - case DK4_FILE_ENCODING_UTF16_LE: { - -#line 194 "dk4strmo32.ctr" - sz = DK4_SIZEOF(b16,dk4_c16_t); - if (0 != dk4utf16_encode(b16, &sz, c32, erp)) { - -#line 196 "dk4strmo32.ctr" - if ((1 == sz) || (2 == sz)) { - buf[0] = (unsigned char)( b16[0] & 0x00FF); - buf[1] = (unsigned char)((b16[0] >> 8) & 0x00FF); - if (2 == sz) { - -#line 200 "dk4strmo32.ctr" - buf[2] = (unsigned char)( b16[1] & 0x00FF); - buf[3] = (unsigned char)((b16[1] >> 8) & 0x00FF); - - -#line 203 "dk4strmo32.ctr" - back = dk4stream_write(strm, (void *)buf, 4, erp); - } else { - -#line 205 "dk4strmo32.ctr" - - -#line 206 "dk4strmo32.ctr" - back = dk4stream_write(strm, (void *)buf, 2, erp); - } - } else { - dk4error_set_simple_error_code(erp, DK4_E_ENCODING_FAILED); - } - } else { - -#line 212 "dk4strmo32.ctr" - dk4error_set_simple_error_code(erp, DK4_E_ENCODING_FAILED); - } - } break; - case DK4_FILE_ENCODING_UTF16_BE: { - -#line 216 "dk4strmo32.ctr" - sz = DK4_SIZEOF(b16,dk4_c16_t); - if (0 != dk4utf16_encode(b16, &sz, c32, erp)) { - -#line 218 "dk4strmo32.ctr" - if ((1 == sz) || (2 == sz)) { - buf[1] = (unsigned char)( b16[0] & 0x00FF); - buf[0] = (unsigned char)((b16[0] >> 8) & 0x00FF); - if (2 == sz) { - -#line 222 "dk4strmo32.ctr" - buf[3] = (unsigned char)( b16[1] & 0x00FF); - buf[2] = (unsigned char)((b16[1] >> 8) & 0x00FF); - back = dk4stream_write(strm, (void *)buf, 4, erp); - } else { - -#line 226 "dk4strmo32.ctr" - back = dk4stream_write(strm, (void *)buf, 2, erp); - } - } else { - -#line 229 "dk4strmo32.ctr" - dk4error_set_simple_error_code(erp, DK4_E_ENCODING_FAILED); - } - } else { - -#line 232 "dk4strmo32.ctr" - dk4error_set_simple_error_code(erp, DK4_E_ENCODING_FAILED); - } - } break; - case DK4_FILE_ENCODING_32_LE: { - -#line 236 "dk4strmo32.ctr" - buf[0] = (unsigned char)( c32 & dkC32(0x000000FF)); - buf[1] = (unsigned char)((c32 >> 8) & dkC32(0x000000FF)); - buf[2] = (unsigned char)((c32 >> 16) & dkC32(0x000000FF)); - buf[3] = (unsigned char)((c32 >> 24) & dkC32(0x000000FF)); - back = dk4stream_write(strm, (void *)buf, 4, erp); - } break; - case DK4_FILE_ENCODING_32_BE: { - -#line 243 "dk4strmo32.ctr" - buf[3] = (unsigned char)( c32 & dkC32(0x000000FF)); - buf[2] = (unsigned char)((c32 >> 8) & dkC32(0x000000FF)); - buf[1] = (unsigned char)((c32 >> 16) & dkC32(0x000000FF)); - buf[0] = (unsigned char)((c32 >> 24) & dkC32(0x000000FF)); - back = dk4stream_write(strm, (void *)buf, 4, erp); - } break; - default: { - dk4error_set_simple_error_code(erp, DK4_E_BUG); - } break; - } - } else{ - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - } - } else { - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - } - -#line 259 "dk4strmo32.ctr" - return back; -} - - - -int -dk4stream_c32_puts(dk4_stream_t *strm, const dk4_c32_t *txt, dk4_er_t *erp) -{ - int back = 0; -#if DK4_USE_ASSERT - assert(NULL != strm); - assert(NULL != txt); -#endif - if ((NULL != strm) && (NULL != txt)) { - if (0 != ((strm->fl) & DK4_STREAM_WRITE)) { - back = 1; - while ((dkC32(0) != *txt) && (1 == back)) { - if (0 == dk4stream_c32_putc(strm, *(txt++), erp)) { - back = 0; - } - } - } else { - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - } - } else { - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - } - return back; -} - - - -int -dk4stream_write_bom_if_necessary(dk4_stream_t *strm, dk4_er_t *erp) -{ - int back = 0; - - -#line 296 "dk4strmo32.ctr" -#if DK4_USE_ASSERT - assert(NULL != strm); -#endif - if (NULL != strm) { - if (0 != ((strm->fl) & DK4_STREAM_WRITE)) { - switch (strm->oenc) { -#if VERSION_BEFORE_20141218 - /* For UTF-8 files most text editors do not handle - the BOM correctly, they show a glyph for unrepresentable - characters. - So I decided to write a BOM only for 16 bit and 32 bit - character output. - */ - case DK4_FILE_ENCODING_UTF8: -#endif - case DK4_FILE_ENCODING_UTF16_LE: - case DK4_FILE_ENCODING_UTF16_BE: - case DK4_FILE_ENCODING_32_LE: - case DK4_FILE_ENCODING_32_BE: - { - -#line 316 "dk4strmo32.ctr" - back = dk4stream_c32_putc(strm, dkC32(0x0000FEFF), erp); - } break; - default: { - back = 1; - } break; - } - } else { - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - } - } else { - dk4error_set_simple_error_code(erp, DK4_E_INVALID_ARGUMENTS); - } - -#line 328 "dk4strmo32.ctr" - return back; -} - - |