/*
* Copyright (c) 1987, Fujitsu LTD. (Itaru ICHIKAWA).
- * Copyright (c) 1996-2013, The nkf Project.
+ * Copyright (c) 1996-2018, The nkf Project.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
*
* 3. This notice may not be removed or altered from any source distribution.
*/
-#define NKF_VERSION "2.1.3"
-#define NKF_RELEASE_DATE "2013-02-20"
+#define NKF_VERSION "2.1.5"
+#define NKF_RELEASE_DATE "2018-12-15"
#define COPY_RIGHT \
"Copyright (C) 1987, FUJITSU LTD. (I.Ichikawa).\n" \
- "Copyright (C) 1996-2013, The nkf Project."
+ "Copyright (C) 1996-2018, The nkf Project."
#include "config.h"
#include "nkf.h"
#ifdef DEFAULT_CODE_LOCALE
static const char*
-nkf_locale_charmap()
+nkf_locale_charmap(void)
{
#ifdef HAVE_LANGINFO_H
return nl_langinfo(CODESET);
}
static nkf_encoding*
-nkf_locale_encoding()
+nkf_locale_encoding(void)
{
nkf_encoding *enc = 0;
const char *encname = nkf_locale_charmap();
#endif /* DEFAULT_CODE_LOCALE */
static nkf_encoding*
-nkf_utf8_encoding()
+nkf_utf8_encoding(void)
{
return &nkf_encoding_table[UTF_8];
}
static nkf_encoding*
-nkf_default_encoding()
+nkf_default_encoding(void)
{
nkf_encoding *enc = 0;
#ifdef DEFAULT_CODE_LOCALE
(*oconv)(0, '\\');
c &= VALUE_MASK;
if(!nkf_char_unicode_bmp_p(c)){
- (*oconv)(0, 'U');
- (*oconv)(0, '0');
- (*oconv)(0, '0');
- (*oconv)(0, bin2hex(c>>20));
- (*oconv)(0, bin2hex(c>>16));
+ int high = (c >> 10) + NKF_INT32_C(0xD7C0); /* high surrogate */
+ int low = (c & 0x3FF) + NKF_INT32_C(0xDC00); /* low surrogate */
+ (*oconv)(0, 'u');
+ (*oconv)(0, bin2hex(high>>12));
+ (*oconv)(0, bin2hex(high>> 8));
+ (*oconv)(0, bin2hex(high>> 4));
+ (*oconv)(0, bin2hex(high ));
+ (*oconv)(0, '\\');
+ (*oconv)(0, 'u');
+ (*oconv)(0, bin2hex(low>>12));
+ (*oconv)(0, bin2hex(low>> 8));
+ (*oconv)(0, bin2hex(low>> 4));
+ (*oconv)(0, bin2hex(low ));
}else{
(*oconv)(0, 'u');
+ (*oconv)(0, bin2hex(c>>12));
+ (*oconv)(0, bin2hex(c>> 8));
+ (*oconv)(0, bin2hex(c>> 4));
+ (*oconv)(0, bin2hex(c ));
}
- (*oconv)(0, bin2hex(c>>12));
- (*oconv)(0, bin2hex(c>> 8));
- (*oconv)(0, bin2hex(c>> 4));
- (*oconv)(0, bin2hex(c ));
return;
}
ret = unicode_to_jis_common2(c1, c0, ppp[c2 - 0xE0], sizeof_utf8_to_euc_C2, p2, p1);
}else return -1;
#ifdef SHIFTJIS_CP932
- if (!ret && !cp932inv_f && is_eucg3(*p2)) {
- nkf_char s2, s1;
- if (e2s_conv(*p2, *p1, &s2, &s1) == 0) {
- s2e_conv(s2, s1, p2, p1);
- }else{
- ret = 1;
+ if (!ret&& is_eucg3(*p2)) {
+ if (cp932inv_f) {
+ if (encode_fallback) ret = 1;
+ }
+ else {
+ nkf_char s2, s1;
+ if (e2s_conv(*p2, *p1, &s2, &s1) == 0) {
+ s2e_conv(s2, s1, p2, p1);
+ }else{
+ ret = 1;
+ }
}
}
#endif
check_bom(FILE *f)
{
int c2;
+ input_bom_f = FALSE;
switch(c2 = (*i_getc)(f)){
case 0x00:
if((c2 = (*i_getc)(f)) == 0x00){
f_prev = c1;
f_line = 0;
fold_state = CR;
- } else if ((f_prev == c1 && !fold_preserve_f)
- || (f_prev == LF && fold_preserve_f)
+ } else if ((f_prev == c1)
+ || (f_prev == LF)
) { /* duplicate newline */
if (f_line) {
f_line = 0;
static nkf_char
mime_getc_buf(FILE *f)
{
- /* we don't keep eof of mime_input_buf, becase it contains ?= as
+ /* we don't keep eof of mime_input_buf, because it contains ?= as
a terminator. It was checked in mime_integrity. */
return ((mimebuf_f)?
(*i_mgetc_buf)(f):mime_input_buf(mime_input_state.input++));
mimeout_state.buf[mimeout_state.count++] = (char)c;
if (mimeout_state.count>MIMEOUT_BUF_LENGTH) {
eof_mime();
- for (i=0;i<mimeout_state.count;i++) {
- (*o_mputc)(mimeout_state.buf[i]);
+ for (j=0;j<mimeout_state.count;j++) {
+ (*o_mputc)(mimeout_state.buf[j]);
base64_count++;
}
mimeout_state.count = 0;
size_t input_buffer_size;
char *output_buffer;
size_t output_buffer_size;
-}
+};
static nkf_iconv_t
nkf_iconv_new(char *tocode, char *fromcode)
if (nkf_enc_unicode_p(output_encoding))
output_mode = UTF_8;
- if (x0201_f == NKF_UNSPECIFIED) {
- x0201_f = X0201_DEFAULT;
- }
+ if (x0201_f == NKF_UNSPECIFIED) {
+ x0201_f = X0201_DEFAULT;
+ }
- /* replace continucation module, from output side */
+ /* replace continuation module, from output side */
- /* output redicrection */
+ /* output redirection */
#ifdef CHECK_OPTION
if (noout_f || guess_f){
o_putc = no_putc;
i_getc = std_getc;
i_ungetc = std_ungetc;
- /* input redicrection */
+ /* input redirection */
#ifdef INPUT_OPTION
if (cap_f){
i_cgetc = i_getc; i_getc = cap_getc;
/* in case of 8th bit is on */
if (!estab_f&&!mime_decode_mode) {
/* in case of not established yet */
- /* It is still ambiguious */
+ /* It is still ambiguous */
if (h_conv(f, c2, c1)==EOF) {
LAST;
}
continue;
#endif
case SP:
- /* module muliple options in a string are allowed for Perl moudle */
+ /* module multiple options in a string are allowed for Perl module */
while(*cp && *cp++!='-');
continue;
default: