Newsgroups: fj.sources
From: kono@csl.sony.co.jp (Shinji Kono)
Subject: nkf, Network Kanji Filter Version 1.5 with MIME patch 1 ('95.3.1)
Message-ID: <1995Mar1.101502.1412@nntp.csl.sony.co.jp>
Sender: daemon@nntp.csl.sony.co.jp (The devil himself)
Reply-To: kono@csl.sony.co.jp
Organization: Sony Computer Science Laboratory, Inc.
Distribution: fj
Date: Wed, 1 Mar 1995 10:15:02 GMT
Lines: 342

$B2OLn(B@CSL.Sony$B$G$9!#(B

nkf 1.15 $B$N(B patch level 1 $B$G$9!#(B 

"=$B!W(B"$B$H$$$&AH$_9g$o$;$,(BMIME decode$B$HAH$_9g$o$;$k$H$^$:$+$C$?!#(B
-i? -o? $B$N(B?$B$,>JN,$5$l$?>l9g$r9MN8$7$?!#(B
Fold $B5!G=$GB?=E2~9T$r2~9T0l$D$K$9$k$3$H$r$d$a$?!#(B
rot47$B$,0lIt$&$^$/F0:n$7$J$+$C$?!#(B

$B;XE&$7$F$/$l$?9u9>L@I'!wBgF|K\0u:~$5$s!"(B
Kimihiko Sato$B$5$s!"$I$&$b$"$j$,$H$&$4$6$$$^$7$?!#(B

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 ****
   **  ohta@src.ricoh.co.jp (Junn Ohta)
   **  inouet@strl.nhk.or.jp (Tomoyuki Inoue)
   **  kiri@pulser.win.or.jp (Tetsuaki Kiriyama)
!  **  a_kuroe@hoffman.cc.sophia.ac.jp (Akihiko Kuroe)
   **  kono@csl.sony.co.jp (Shinji Kono)
   **
   ** $B:G=*99?7F|(B
--- 1475,1482 ----
   **  ohta@src.ricoh.co.jp (Junn Ohta)
   **  inouet@strl.nhk.or.jp (Tomoyuki Inoue)
   **  kiri@pulser.win.or.jp (Tetsuaki Kiriyama)
!  **  Kimihiko Sato <sato@sail.t.u-tokyo.ac.jp>
!  **  a_kuroe@kuroe.aoba.yokohama.jp (Akihiko Kuroe)
   **  kono@csl.sony.co.jp (Shinji Kono)
   **
   ** $B:G=*99?7F|(B
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$B2>L>$O(Brot47$B$5$l$J$$!#(B
  
+ 
  ========
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                              kono@csl.sony.co.jp
$B2OLn??<#(B Sony Computer Science Laboratory, Inc,Japan


