Subject: nkf, Network Kanji Filter Version 1.5 with MIME patch 1 ('95.3.1)
From: [email-masked] (Shinji Kono)
Date: Wed, 1 Mar 1995 10:15:02 GMT
Newsgroups: fj.sources

[email-masked]。

nkf 1.15 の patch level 1 です。 

"=」"という組み合わせがMIME decodeと組み合わせるとまずかった。
-i? -o? の?が省略された場合を考慮した。
Fold 機能で多重改行を改行一つにすることをやめた。
rot47が一部うまく動作しなかった。

指摘してくれた黒江明彦＠大日本印刷さん、
Kimihiko Satoさん、どうもありがとうございました。

diff -c ../nkf15k.org/nkf.c ./nkf.c
*** ../nkf15k.org/nkf.c	Wed Dec 21 22:00:15 1994
--- ./nkf.c	Wed Mar  1 19:07:35 1995
***************
*** 19,25 ****
  static char *Version =
        "1.5";
  static char *Patchlevel =
!       "0/9412/Shinji Kono";
  
  /*
  **
--- 19,25 ----
  static char *Version =
        "1.5";
  static char *Patchlevel =
!       "1/9503/Shinji Kono";
  
  /*
  **
***************
*** 255,264 ****
  		input_f = LATIN1_INPUT;
  		continue;
  	    case 'i':		/* Kanji IN ESC-$-@/B */
! 		kanji_intro = *cp++;
  		continue;
  	    case 'o':		/* ASCII IN ESC-(-J/B */
! 		ascii_intro = *cp++;
  		continue;
  	    case 'r':
  		rot_f = TRUE;
--- 255,264 ----
  		input_f = LATIN1_INPUT;
  		continue;
  	    case 'i':		/* Kanji IN ESC-$-@/B */
! 		if(*cp) kanji_intro = *cp++;
  		continue;
  	    case 'o':		/* ASCII IN ESC-(-J/B */
! 		if(*cp) ascii_intro = *cp++;
  		continue;
  	    case 'r':
  		rot_f = TRUE;
***************
*** 455,461 ****
  	    /* first byte */
  	    if (c1 > DEL) {
  		/* 8 bit code */
! 		if (!estab_f) {
  		    /* not established yet */
  		    if (c1 < SSP) {
  			/* it seems to be MS Kanji */
--- 455,461 ----
  	    /* first byte */
  	    if (c1 > DEL) {
  		/* 8 bit code */
! 		if (!estab_f && !iso8859_f) {
  		    /* not established yet */
  		    if (c1 < SSP) {
  			/* it seems to be MS Kanji */
***************
*** 471,477 ****
  		    c2 = c1;
  		    NEXT;
  		} else { /* estab_f==TRUE */
! 		    if(input_f==LATIN1_INPUT) {
  			SEND;
  		    } else if(SSP<=c1 && c1<0xe0 && iconv == s_iconv) {
  			/* SJIS X0201 Case... */
--- 471,477 ----
  		    c2 = c1;
  		    NEXT;
  		} else { /* estab_f==TRUE */
! 		    if(iso8859_f) {
  			SEND;
  		    } else if(SSP<=c1 && c1<0xe0 && iconv == s_iconv) {
  			/* SJIS X0201 Case... */
***************
*** 621,627 ****
  			    NEXT;
  		    } else {
  			(*oconv) (0, '=');
! 			SEND;
  		    }
  		} else if(c1 == '$' && broken_f && !mime_mode) {
  		    /* try to recover missing escape */
--- 621,628 ----
  			    NEXT;
  		    } else {
  			(*oconv) (0, '=');
! 			ungetc(c1,f);
! 			NEXT;
  		    }
  		} else if(c1 == '$' && broken_f && !mime_mode) {
  		    /* try to recover missing escape */
***************
*** 860,868 ****
  	putchar(c1);
      } else {
  	if((c1<0x20 || 0x7e<c1) ||
! 	   (c2<0x20 || 0x75<c2)) {
  	    estab_f = FALSE;
! 	    return; /* too late to resque this char */
  	}
  	putchar(c2 | 0x080);
  	putchar(c1 | 0x080);
--- 861,869 ----
  	putchar(c1);
      } else {
  	if((c1<0x20 || 0x7e<c1) ||
! 	   (c2<0x20 || 0x7e<c2)) {
  	    estab_f = FALSE;
! 	    return; /* too late to rescue this char */
  	}
  	putchar(c2 | 0x080);
  	putchar(c1 | 0x080);
***************
*** 898,906 ****
  	putchar(c1);
      } else {
  	if((c1<0x20 || 0x7e<c1) ||
! 	   (c2<0x20 || 0x75<c2)) {
  	    estab_f = FALSE;
! 	    return; /* too late to resque this char */
  	}
  	putchar((((c2 - 1) >> 1) + ((c2 <= 0x5e) ? 0x71 : 0xb1)));
  	putchar((c1 + ((c2 & 1) ? ((c1 < 0x60) ? 0x1f : 0x20) : 0x7e)));
--- 899,907 ----
  	putchar(c1);
      } else {
  	if((c1<0x20 || 0x7e<c1) ||
! 	   (c2<0x20 || 0x7e<c2)) {
  	    estab_f = FALSE;
! 	    return; /* too late to rescue this char */
  	}
  	putchar((((c2 - 1) >> 1) + ((c2 <= 0x5e) ? 0x71 : 0xb1)));
  	putchar((c1 + ((c2 & 1) ? ((c1 < 0x60) ? 0x1f : 0x20) : 0x7e)));
***************
*** 1026,1032 ****
      if(c1=='\r') 
  	return 0;		/* ignore cr */
      if(c1== 8) {
! 	line--;
  	return 1;
      }
      if(c2==EOF && line != 0)    /* close open last line */
--- 1027,1033 ----
      if(c1=='\r') 
  	return 0;		/* ignore cr */
      if(c1== 8) {
! 	if(line>0) line--;
  	return 1;
      }
      if(c2==EOF && line != 0)    /* close open last line */
***************
*** 1034,1044 ****
      /* new line */
      if(c1=='\n') {
  	if(prev == c1) {     	/* duplicate newline */
! 	    if(line != 0) {
  		line = 0;
  		return '\n'; 	/* output two newline */
  	    } else {
! 		return 0;    	/* ignore more duplicate newlines */
  	    }
  	} else  {
  	    if(prev&0x80) { 	/* Japanese? */
--- 1035,1046 ----
      /* new line */
      if(c1=='\n') {
  	if(prev == c1) {     	/* duplicate newline */
! 	    if(line) {
  		line = 0;
  		return '\n'; 	/* output two newline */
  	    } else {
! 		line = 0;
! 		return 1;
  	    }
  	} else  {
  	    if(prev&0x80) { 	/* Japanese? */
***************
*** 1260,1274 ****
  /* Quickly programmed by I.Ichikawa (( )) 1994, Dec. */
  /* You may freely use this, unless you pretend you build this */
  
! struct mime_encode {
!    unsigned char *pattern;
!    int      encode;
! } mime_encodes[] = {
!    {"=?ISO-8859-1?Q?", 'Q'},    /* this have to be sorted in length */
!    {"=?ISO-2022-JP?B?", 'B'},
!    {NULL, 0}
  };
  
  int
  mime_begin(f)
  FILE *f;
--- 1262,1281 ----
  /* Quickly programmed by I.Ichikawa (( )) 1994, Dec. */
  /* You may freely use this, unless you pretend you build this */
  
! unsigned char *mime_pattern[] = {
!    (unsigned char *)"=?ISO-8859-1?Q?",
!    (unsigned char *)"=?ISO-2022-JP?B?",
!    NULL
  };
  
+ int      mime_encode[] = {
+     'Q',
+     'B',
+     0
+ };
+ 
+ int iso8859_f_save;
+ 
  int
  mime_begin(f)
  FILE *f;
***************
*** 1280,1291 ****
      mime_mode = FALSE;
      /* =? has been checked */
      j = 0;
!     p = mime_encodes[j].pattern;
  
      for(i=2;p[i]>' ';i++) {
  	if( ((c1 = getc(f))==EOF) || c1 != p[i] ) {
  	    q = p;
! 	    while (p = mime_encodes[++j].pattern) {
  		for(k=2;k<i;k++)          /* assume length(p) > i */
  		    if(p[k]!=q[k]) break;
  		if(k==i && c1==p[k]) break;
--- 1287,1298 ----
      mime_mode = FALSE;
      /* =? has been checked */
      j = 0;
!     p = mime_pattern[j];
  
      for(i=2;p[i]>' ';i++) {
  	if( ((c1 = getc(f))==EOF) || c1 != p[i] ) {
  	    q = p;
! 	    while (p = mime_pattern[++j]) {
  		for(k=2;k<i;k++)          /* assume length(p) > i */
  		    if(p[k]!=q[k]) break;
  		if(k==i && c1==p[k]) break;
***************
*** 1298,1304 ****
  	    return c1;
  	}
      }
!     mime_mode = mime_encodes[j].encode;
      return c1;
  }
  
--- 1305,1315 ----
  	    return c1;
  	}
      }
!     iso8859_f_save = iso8859_f;
!     if(j==0) {
! 	iso8859_f = TRUE;
!     }
!     mime_mode = mime_encode[j];
      return c1;
  }
  
***************
*** 1319,1324 ****
--- 1330,1336 ----
  	if ((c2 = getc(f)) == EOF) return (EOF);
  	if(c1=='?'&&c2=='=') {
  	    /* end Q encoding */
+ 	    iso8859_f = iso8859_f_save;
  	    mime_mode = 0; return getc(f);
  	}
  	if ((c3 = getc(f)) == EOF) return (EOF);
***************
*** 1463,1469 ****
   **  [email-masked] (Junn Ohta)
   **  [email-masked] (Tomoyuki Inoue)
   **  [email-masked] (Tetsuaki Kiriyama)
!  **  [email-masked] (Akihiko Kuroe)
   **  [email-masked] (Shinji Kono)
   **
   ** 最終更新日
--- 1475,1482 ----
   **  [email-masked] (Junn Ohta)
   **  [email-masked] (Tomoyuki Inoue)
   **  [email-masked] (Tetsuaki Kiriyama)
!  **  Kimihiko Sato <[email-masked]>
!  **  [email-masked] (Akihiko Kuroe)
   **  [email-masked] (Shinji Kono)
   **
   ** 最終更新日
diff -c ../nkf15k.org/nkf.doc ./nkf.doc
*** ../nkf15k.org/nkf.doc	Wed Dec 21 22:05:25 1994
--- ./nkf.doc	Wed Mar  1 19:04:01 1995
***************
*** 132,135 ****
--- 132,136 ----
  
  X0201仮名はrot47されない。
  
+ 
  ========
diff -c ../nkf15k.org/nkf_test.pl ./nkf_test.pl
*** ../nkf15k.org/nkf_test.pl	Wed Dec 21 20:12:00 1994
--- ./nkf_test.pl	Tue Feb 14 18:52:47 1995
***************
*** 22,28 ****
      local ($nkf,$in,$ans,$detail) = @_;
      local ($result);
  
!     # This may not work on MSDOS. Is temporal file works?
      $result = '';
      if (open(IN,"-|")) {
          print STDERR "INPUT:   ",$in  if ($detail || $detail_all);
--- 22,28 ----
      local ($nkf,$in,$ans,$detail) = @_;
      local ($result);
  
!     # This may not work on MSDOS.
      $result = '';
      if (open(IN,"-|")) {
          print STDERR "INPUT:   ",$in  if ($detail || $detail_all);

---
Shinji Kono                              [email-masked]
河野真治 Sony Computer Science Laboratory, Inc,Japan