Skip to content

Commit

Permalink
Updates and fixes for oficonv.
Browse files Browse the repository at this point in the history
Merged updates and fixes from current FreeBSD source
tree (as of January 2022) into oficonv.
  • Loading branch information
Marco Eichelberg committed Jun 9, 2022
1 parent a555f78 commit bcf036b
Show file tree
Hide file tree
Showing 38 changed files with 252 additions and 413 deletions.
21 changes: 19 additions & 2 deletions oficonv/include/dcmtk/oficonv/iconv.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ iconv_t OFiconv_open(const char *, const char *);
* depends on the destination codeset, e.g., ‘?’, and the conversion is
* continued. iconv() returns the number of such “invalid conversions”.
*/
size_t OFiconv(iconv_t cd, const char ** __restrict src, size_t * __restrict srcleft, char ** __restrict dst, size_t * __restrict dstleft);
size_t OFiconv(iconv_t cd, char ** __restrict src, size_t * __restrict srcleft, char ** __restrict dst, size_t * __restrict dstleft);

/**
* close the specified converter cd
Expand Down Expand Up @@ -115,7 +115,7 @@ void OF__iconv_free_list(char **, size_t);
* __ICONV_F_HIDE_INVALID
* Skip invalid characters, instead of returning with an error.
*/
size_t OF__iconv(iconv_t, const char **, size_t *, char **, size_t *, __uint32_t, size_t *);
size_t OF__iconv(iconv_t, char **, size_t *, char **, size_t *, __uint32_t, size_t *);

#define __ICONV_F_HIDE_INVALID 0x0001

Expand Down Expand Up @@ -193,6 +193,23 @@ int OFiconv_open_into(const char *, const char *, iconv_allocation_t *);
*/
#define ICONV_SET_FALLBACKS 6

/*
* Determines if a character in the input buffer that is valid, but for
* which an identical character does not exist in the target codeset
* returns EILSEQ or not. The answer is stored in argument, which is of
* int *. It will be set to 1 if this feature is enabled or set to 0 otherwise.
*/
#define ICONV_GET_ILSEQ_INVALID 128

/*
* Sets whether a character in the input buffer that is valid, but for
* which an identical character does not exist in the target codeset
* returns EILSEQ or not. If argument, which is of int * is set to 1 it
* will be enabled, and if argument is set to 0 it will be disabled.
*/

#define ICONV_SET_ILSEQ_INVALID 129

typedef void (*iconv_unicode_char_hook) (unsigned int mbr, void *data);
typedef void (*iconv_wide_char_hook) (wchar_t wc, void *data);

Expand Down
4 changes: 2 additions & 2 deletions oficonv/libsrc/citrus_bcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const char *
_citrus_bcs_skip_ws_len(const char * __restrict p, size_t * __restrict len)
{

while (*p && *len > 0 && _citrus_bcs_isspace(*p)) {
while (*len > 0 && *p && _citrus_bcs_isspace(*p)) {
p++;
(*len)--;
}
Expand All @@ -116,7 +116,7 @@ const char *
_citrus_bcs_skip_nonws_len(const char * __restrict p, size_t * __restrict len)
{

while (*p && *len > 0 && !_citrus_bcs_isspace(*p)) {
while (*len > 0 && *p && !_citrus_bcs_isspace(*p)) {
p++;
(*len)--;
}
Expand Down
17 changes: 8 additions & 9 deletions oficonv/libsrc/citrus_big5.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ _citrus_BIG5_check_excludes(_BIG5EncodingInfo *ei, wint_t c)
}

static int
_citrus_BIG5_fill_rowcol(void ** __restrict ctx, const char * __restrict s,
_citrus_BIG5_fill_rowcol(void * __restrict ctx, const char * __restrict s,
uint64_t start, uint64_t end)
{
_BIG5EncodingInfo *ei;
Expand All @@ -188,7 +188,7 @@ _citrus_BIG5_fill_rowcol(void ** __restrict ctx, const char * __restrict s,

static int
/*ARGSUSED*/
_citrus_BIG5_fill_excludes(void ** __restrict ctx,
_citrus_BIG5_fill_excludes(void * __restrict ctx,
const char * __restrict s __unused, uint64_t start, uint64_t end)
{
_BIG5EncodingInfo *ei;
Expand Down Expand Up @@ -234,7 +234,6 @@ static int
_citrus_BIG5_encoding_module_init(_BIG5EncodingInfo * __restrict ei,
const void * __restrict var, size_t lenvar)
{
void *ctx = (void *)ei;
const char *s;
int err;

Expand All @@ -256,9 +255,9 @@ _citrus_BIG5_encoding_module_init(_BIG5EncodingInfo * __restrict ei,
}

/* fallback Big5-1984, for backward compatibility. */
_citrus_BIG5_fill_rowcol((void **)&ctx, "row", 0xA1, 0xFE);
_citrus_BIG5_fill_rowcol((void **)&ctx, "col", 0x40, 0x7E);
_citrus_BIG5_fill_rowcol((void **)&ctx, "col", 0xA1, 0xFE);
_citrus_BIG5_fill_rowcol(ei, "row", 0xA1, 0xFE);
_citrus_BIG5_fill_rowcol(ei, "col", 0x40, 0x7E);
_citrus_BIG5_fill_rowcol(ei, "col", 0xA1, 0xFE);

return (0);
}
Expand All @@ -267,12 +266,12 @@ static int
/*ARGSUSED*/
_citrus_BIG5_mbrtowc_priv(_BIG5EncodingInfo * __restrict ei,
wchar_t * __restrict pwc,
const char ** __restrict s, size_t n,
char ** __restrict s, size_t n,
_BIG5State * __restrict psenc,
size_t * __restrict nresult)
{
wchar_t wchar;
const char *s0;
char *s0;
int c, chlenbak;

s0 = *s;
Expand Down Expand Up @@ -356,7 +355,7 @@ _citrus_BIG5_wcrtomb_priv(_BIG5EncodingInfo * __restrict ei,
size_t n, wchar_t wc, _BIG5State * __restrict psenc __unused,
size_t * __restrict nresult)
{
unsigned char l;
size_t l;
int ret;

/* check invalid sequence */
Expand Down
1 change: 1 addition & 0 deletions oficonv/libsrc/citrus_csmapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ find_best_pivot_pvdb(const char *src, const char *dst, char *pivot,
if (ret)
goto quit3;
if (_citrus_db_lookup_by_string(db3, dst, &r2, NULL) != 0)
/* don't break the loop, test all src/dst pairs. */
goto quit4;
/* r2: norm among pivot and dst */
ret = get32(&r2, &val32);
Expand Down
2 changes: 1 addition & 1 deletion oficonv/libsrc/citrus_csmapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

#ifndef _CITRUS_CSMAPPER_H_
#define _CITRUS_CSMAPPER_H
#define _CITRUS_CSMAPPER_H_

#include "dcmtk/config/osconfig.h"
#include <stdint.h>
Expand Down
13 changes: 1 addition & 12 deletions oficonv/libsrc/citrus_db_factory.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,6 @@ put8(struct _citrus_region *r, size_t *rofs, uint8_t val)
*rofs += 1;
}

static __inline void
put16(struct _citrus_region *r, size_t *rofs, uint16_t val)
{

val = htons(val);
memcpy(_citrus_region_offset(r, *rofs), &val, 2);
*rofs += 2;
}

static __inline void
put32(struct _citrus_region *r, size_t *rofs, uint32_t val)
{
Expand Down Expand Up @@ -281,11 +272,9 @@ _citrus_db_factory_serialize(struct _citrus_db_factory *df, const char *magic,
return (0);
}
/* allocate hash table */
depp = malloc(sizeof(*depp) * df->df_num_entries);
depp = calloc(df->df_num_entries, sizeof(*depp));
if (depp == NULL)
return (-1);
for (i = 0; i < df->df_num_entries; i++)
depp[i] = NULL;

/* step1: store the entries which are not conflicting */
STAILQ_FOREACH(de, &df->df_entries, de_entry) {
Expand Down
4 changes: 2 additions & 2 deletions oficonv/libsrc/citrus_dechanyu.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ is_94charset(int c)
static int
/*ARGSUSED*/
_citrus_DECHanyu_mbrtowc_priv(_DECHanyuEncodingInfo * __restrict ei,
wchar_t * __restrict pwc, const char ** __restrict s, size_t n,
wchar_t * __restrict pwc, char ** __restrict s, size_t n,
_DECHanyuState * __restrict psenc, size_t * __restrict nresult)
{
const char *s0;
char *s0;
wchar_t wc;
int ch;

Expand Down
7 changes: 5 additions & 2 deletions oficonv/libsrc/citrus_esdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,16 @@ _citrus_esdb_get_list(char ***rlist, size_t *rnum, bool sorted)

/* get alias entries */
while ((ret = _citrus_lookup_seq_next(cla, &key, &data)) == 0) {
#if 0
/* this code fragment is disabled in FreeBSD */
if (sorted)
snprintf(buf, sizeof(buf), "%.*s/%.*s",
(int)_citrus_region_size(&data),
(const char *)_citrus_region_head(&data),
(int)_citrus_region_size(&key),
(const char *)_citrus_region_head(&key));
else
#endif
snprintf(buf, sizeof(buf), "%.*s/%.*s",
(int)_citrus_region_size(&data),
(const char *)_citrus_region_head(&data),
Expand Down Expand Up @@ -326,7 +329,7 @@ _citrus_esdb_get_list(char ***rlist, size_t *rnum, bool sorted)
(int)_citrus_region_size(&data),
(const char *)_citrus_region_head(&data));
if ((p = strchr(buf1, '/')) != NULL)
memcpy(buf1, p + 1, strlen(p) - 1);
memmove(buf1, p + 1, strlen(p) - 1);
if ((p = strstr(buf1, ".esdb")) != NULL)
*p = '\0';

Expand Down Expand Up @@ -369,7 +372,7 @@ _citrus_esdb_get_list(char ***rlist, size_t *rnum, bool sorted)
ret = 0;
/* XXX: why reallocing the list space posteriorly?
shouldn't be done earlier? */
q = realloc(list, num * sizeof(char *));
q = reallocarray(list, num, sizeof(char *));
if (!q) {
ret = ENOMEM;
goto quit3;
Expand Down
22 changes: 2 additions & 20 deletions oficonv/libsrc/citrus_euc.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,31 +168,13 @@ _citrus_EUC_init_state(_EUCEncodingInfo *ei __unused, _EUCState *s)
memset(s, 0, sizeof(*s));
}

static __inline void
/*ARGSUSED*/
_citrus_EUC_pack_state(_EUCEncodingInfo *ei __unused, void *pspriv,
const _EUCState *s)
{

memcpy(pspriv, (const void *)s, sizeof(*s));
}

static __inline void
/*ARGSUSED*/
_citrus_EUC_unpack_state(_EUCEncodingInfo *ei __unused, _EUCState *s,
const void *pspriv)
{

memcpy((void *)s, pspriv, sizeof(*s));
}

static int
_citrus_EUC_mbrtowc_priv(_EUCEncodingInfo *ei, wchar_t *pwc, const char **s,
_citrus_EUC_mbrtowc_priv(_EUCEncodingInfo *ei, wchar_t *pwc, char **s,
size_t n, _EUCState *psenc, size_t *nresult)
{
wchar_t wchar;
int c, chlenbak, cs, len;
const char *s0, *s1 = NULL;
char *s0, *s1 = NULL;

s0 = *s;

Expand Down
24 changes: 3 additions & 21 deletions oficonv/libsrc/citrus_euctw.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ _citrus_EUCTW_count(int cs)
case 1:
/*FALLTHROUGH*/
case 2:
return (2^cs);
return (1 << cs);
case 3:
abort();
/*NOTREACHED*/
Expand All @@ -135,24 +135,6 @@ _citrus_EUCTW_init_state(_EUCTWEncodingInfo * __restrict ei __unused,
memset(s, 0, sizeof(*s));
}

static __inline void
/*ARGSUSED*/
_citrus_EUCTW_pack_state(_EUCTWEncodingInfo * __restrict ei __unused,
void * __restrict pspriv, const _EUCTWState * __restrict s)
{

memcpy(pspriv, (const void *)s, sizeof(*s));
}

static __inline void
/*ARGSUSED*/
_citrus_EUCTW_unpack_state(_EUCTWEncodingInfo * __restrict ei __unused,
_EUCTWState * __restrict s, const void * __restrict pspriv)
{

memcpy((void *)s, pspriv, sizeof(*s));
}

static int
/*ARGSUSED*/
_citrus_EUCTW_encoding_module_init(_EUCTWEncodingInfo * __restrict ei,
Expand All @@ -173,10 +155,10 @@ _citrus_EUCTW_encoding_module_uninit(_EUCTWEncodingInfo *ei __unused)

static int
_citrus_EUCTW_mbrtowc_priv(_EUCTWEncodingInfo * __restrict ei,
wchar_t * __restrict pwc, const char ** __restrict s,
wchar_t * __restrict pwc, char ** __restrict s,
size_t n, _EUCTWState * __restrict psenc, size_t * __restrict nresult)
{
const char *s0;
char *s0;
wchar_t wchar;
int c, chlenbak, cs;

Expand Down
22 changes: 2 additions & 20 deletions oficonv/libsrc/citrus_gbk2k.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,6 @@ _citrus_GBK2K_init_state(_GBK2KEncodingInfo * __restrict ei __unused,
memset(s, 0, sizeof(*s));
}

static __inline void
/*ARGSUSED*/
_citrus_GBK2K_pack_state(_GBK2KEncodingInfo * __restrict ei __unused,
void * __restrict pspriv, const _GBK2KState * __restrict s)
{

memcpy(pspriv, (const void *)s, sizeof(*s));
}

static __inline void
/*ARGSUSED*/
_citrus_GBK2K_unpack_state(_GBK2KEncodingInfo * __restrict ei __unused,
_GBK2KState * __restrict s, const void * __restrict pspriv)
{

memcpy((void *)s, pspriv, sizeof(*s));
}

static __inline bool
_mb_singlebyte(int c)
{
Expand Down Expand Up @@ -146,10 +128,10 @@ _mb_count(wchar_t v)

static int
_citrus_GBK2K_mbrtowc_priv(_GBK2KEncodingInfo * __restrict ei,
wchar_t * __restrict pwc, const char ** __restrict s, size_t n,
wchar_t * __restrict pwc, char ** __restrict s, size_t n,
_GBK2KState * __restrict psenc, size_t * __restrict nresult)
{
const char *s0, *s1;
char *s0, *s1;
wchar_t wc;
int chlenbak, len;

Expand Down
Loading

0 comments on commit bcf036b

Please sign in to comment.