Add UTF-8 support
Index: file-kanji-1.1/file2.c
===================================================================
--- file-kanji-1.1.orig/file2.c	2012-03-31 00:00:13.000000000 +0900
+++ file-kanji-1.1/file2.c	2012-03-31 00:01:06.000000000 +0900
@@ -25,6 +25,7 @@
 #define SJIS      3
 #define JIS       4
 #define EMPTY     5
+#define UTF8      6
 #define UNKNOWN   99
 
 /* 漢字インのコード */
@@ -104,6 +105,8 @@
 	    f = "empty"; break;
         case UNKNOWN:
 	    f = "UNKNOWN"; break;
+        case UTF8:
+	    f = "UTF-8 text"; break;
         }
     }
     else if ( stat_buff.st_mode & S_IFLNK )  f = "symbolic link";
@@ -119,6 +122,7 @@
     if ( size==0 ) return(EMPTY);
     if ( is_jis_file(buff, size) ) return(JIS);
     if ( is_ascii_file(buff, size) ) return(ASCII);
+    if ( is_utf8_file(buff, size) ) return(UTF8);
     if ( is_euc_file(buff, size) ) return(EUC);
     if ( is_sjis_file(buff, size) ) return(SJIS);
     return(UNKNOWN);
@@ -273,3 +277,63 @@
     }
     return(FALSE);
 }
+
+int is_utf8_file( buff, size)
+uchar buff[];
+int   size;
+{
+    int  i;
+    if ( size<=1 ) return(FALSE);
+    if ( size==2 && is_utf8_2_byte_char(buff[0], buff[1])) return(TRUE);
+    if ( size==3 && ( is_utf8_2_byte_char(buff[0], buff[1]) || is_utf8_2_byte_char(buff[1], buff[2]) || is_utf8_3_byte_char(buff[0], buff[1], buff[2]) ) ) return(TRUE);
+    for ( i=0; i<size-3; i++) {
+	if ( is_ascii_char(buff[i]) ) continue;
+	if ( is_utf8_2_byte_char(buff[i], buff[i+1]) ) {
+	    i++;
+	    continue;
+	}
+	if ( is_utf8_3_byte_char(buff[i], buff[i+1], buff[i+2]) ) {
+	    i += 2;
+	    continue;
+	}
+	if (is_utf8_4_byte_char(buff[i], buff[i+1], buff[i+2], buff[i+3]) ) {
+	    i += 3;
+	    continue;
+	}
+	return(FALSE);
+    }
+    return(TRUE);
+}
+
+int is_utf8_2_byte_char(c1, c2)
+uchar c1,c2;
+{
+    if ( c1>=0xc0 && c1<=0xdf ) {
+	if ( c2>=0x80 && c2<=0xbf ) return(TRUE);
+    }
+    return(FALSE);
+}
+
+int is_utf8_3_byte_char(c1, c2, c3)
+uchar c1,c2,c3;
+{
+    if ( c1>=0xe0 && c1<=0xef ) {
+    	if ( c2>=0x80 && c2<=0xbf ) {
+	    if (c3>=0x80 && c3<=0xbf ) return(TRUE);
+	}
+    }
+    return(FALSE);
+}
+
+int is_utf8_4_byte_char(c1, c2, c3, c4)
+uchar c1,c2,c3,c4;
+{
+    if ( c1>=0xf0 && c1<=0xf7 ) {
+	if ( c2>=0x80 && c2<=0xbf ) {
+	    if (c3>=0x80 && c3<=0xbf ) {
+		if (c4>=0x80 && c4<=0xbf ) return(TRUE);
+	    }
+	}
+    }
+    return(FALSE);
+}
