* \e$B8=:_!"\e(Bnkf \e$B$O\e(B SorceForge \e$B$K$F%a%s%F%J%s%9$,B3$1$i$l$F$$$^$9!#\e(B
* http://sourceforge.jp/projects/nkf/
***********************************************************************/
-/* $Id: nkf.c,v 1.153 2007/12/18 03:04:10 naruse Exp $ */
+/* $Id: nkf.c,v 1.154 2007/12/18 18:20:16 naruse Exp $ */
#define NKF_VERSION "2.0.8"
-#define NKF_RELEASE_DATE "2007-12-18"
+#define NKF_RELEASE_DATE "2007-12-19"
#define COPY_RIGHT \
"Copyright (C) 1987, FUJITSU LTD. (I.Ichikawa),2000 S. Kono, COW\n" \
"Copyright (C) 2002-2007 Kono, Furukawa, Naruse, mastodon"
#define X0201_DEFAULT TRUE
#endif
+#if DEFAULT_NEWLINE == 0x0D0A
+#define PUT_NEWLINE(func) do {\
+ func(0x0D);\
+ func(0x0A);\
+} while (0)
+#define OCONV_NEWLINE(func) do {\
+ func(0, 0x0D);\
+ func(0, 0x0A);\
+} while (0)
+#elif DEFAULT_NEWLINE == 0x0D
+#define PUT_NEWLINE(func) func(0x0D)
+#define OCONV_NEWLINE(func) func(0, 0x0D)
+#else
+#define DEFAULT_NEWLINE 0x0A
+#define PUT_NEWLINE(func) func(0x0A)
+#define OCONV_NEWLINE(func) func(0, 0x0A)
+#endif
+
#if (defined(__TURBOC__) || defined(_MSC_VER) || defined(LSI_C) || defined(__MINGW32__) || defined(__EMX__) || defined(__MSDOS__) || defined(__WINDOWS__) || defined(__DOS__) || defined(__OS2__)) && !defined(MSDOS)
#define MSDOS
#if (defined(__Win32__) || defined(_WIN32)) && !defined(__WIN32__)
static char *input_codename = NULL; /* NULL: unestablished, "": BINARY */
-#ifndef PERL_XS
-static const char *CopyRight = COPY_RIGHT;
-#endif
#if !defined(PERL_XS) && !defined(WIN32DLL)
static nkf_char noconvert(FILE *f);
#endif
else if (!input_newline) input_newline = CR;
else if (input_newline != CR) input_newline = EOF;
}
- if (prev_cr || c2 == 0 && c1 == LF) {
+ if (prev_cr || (c2 == 0 && c1 == LF)) {
prev_cr = 0;
if (nlmode_f != LF) (*o_nlconv)(0, CR);
if (nlmode_f != CR) (*o_nlconv)(0, LF);
/* terminator process */
switch(fold_state) {
case LF:
- (*o_fconv)(0,LF);
+ OCONV_NEWLINE((*o_fconv));
(*o_fconv)(c2,c1);
break;
case 0:
return;
case CR:
- (*o_fconv)(0,LF);
+ OCONV_NEWLINE((*o_fconv));
break;
case TAB:
case SP:
#if !defined(PERL_XS) && !defined(WIN32DLL)
void print_guessed_code(char *filename)
{
- char *codename = "BINARY";
- char *str_nlmode = NULL;
if (filename != NULL) printf("%s: ", filename);
if (input_codename && !*input_codename) {
printf("BINARY\n");
(*o_mputc)(mimeout_buf[i]);
i++;
}
- (*o_mputc)(LF);
+ PUT_NEWLINE((*o_mputc));
(*o_mputc)(SP);
base64_count = 1;
if (mimeout_buf_count>0
if (c2 == EOF){
if (base64_count + mimeout_buf_count/3*4> 73){
(*o_base64conv)(EOF,0);
- (*o_base64conv)(0,LF);
+ OCONV_NEWLINE((*o_base64conv));
(*o_base64conv)(0,SP);
base64_count = 1;
}
} else {
if (base64_count + mimeout_buf_count/3*4> 66) {
(*o_base64conv)(EOF,0);
- (*o_base64conv)(0,LF);
+ OCONV_NEWLINE((*o_base64conv));
(*o_base64conv)(0,SP);
base64_count = 1;
mimeout_mode = -1;
mimeout_mode = (output_mode==ASCII ||output_mode == ISO8859_1) ? 'Q' : 'B';
open_mime(output_mode);
(*o_base64conv)(EOF,0);
- (*o_base64conv)(0,LF);
+ OCONV_NEWLINE((*o_base64conv));
(*o_base64conv)(0,SP);
base64_count = 1;
mimeout_mode = -1;
if (base64_count > 71){
if (c!=CR && c!=LF) {
(*o_mputc)('=');
- (*o_mputc)(LF);
+ PUT_NEWLINE((*o_mputc));
}
base64_count = 0;
}
}else{
if (base64_count > 71){
eof_mime();
- (*o_mputc)(LF);
+ PUT_NEWLINE((*o_mputc));
base64_count = 0;
}
if (c == EOF) { /* c==EOF */
} else if (c <= SP) {
close_mime();
if (base64_count > 70) {
- (*o_mputc)(LF);
+ PUT_NEWLINE((*o_mputc));
base64_count = 0;
}
if (!nkf_isblank(c)) {
} else {
if (base64_count > 70) {
close_mime();
- (*o_mputc)(LF);
+ PUT_NEWLINE((*o_mputc));
(*o_mputc)(SP);
base64_count = 1;
open_mime(output_mode);
if (base64_count > 1
&& base64_count + mimeout_buf_count > 76
&& mimeout_buf[0] != CR && mimeout_buf[0] != LF){
- (*o_mputc)(LF);
+ PUT_NEWLINE((*o_mputc));
base64_count = 0;
if (!nkf_isspace(mimeout_buf[0])){
(*o_mputc)(SP);
"UNKOWN"
#endif
"\n");
+ fprintf(stderr, " Default output newline: "
+#if DEFAULT_NEWLINE == CR
+ "CR"
+#elif DEFAULT_NEWLINE == CRLF
+ "CRLF"
+#else
+ "LF"
+#endif
+ "\n");
fprintf(stderr, " Decode MIME encoded string: "
#if MIME_DECODE_DEFAULT
"ON"