dbcs_class(unsigned lead, unsigned trail)
{
    switch (enc_dbcs)
    {
	// please add classify routine for your language in here

	case DBCS_JPNU:	// ?
	case DBCS_JPN:
	    {
		// JIS code classification
		unsigned char lb = lead;
		unsigned char tb = trail;

		// convert process code to JIS
# if defined(MSWIN) || defined(WIN32UNIX) || defined(MACOS_X)
		// process code is SJIS
		if (lb <= 0x9f)
		    lb = (lb - 0x81) * 2 + 0x21;
		else
		    lb = (lb - 0xc1) * 2 + 0x21;
		if (tb <= 0x7e)
		    tb -= 0x1f;
		else if (tb <= 0x9e)
		    tb -= 0x20;
		else
		{
		    tb -= 0x7e;
		    lb += 1;
		}
# else
		/*
		 * XXX: Code page identification can not use with all
		 *	    system! So, some other encoding information
		 *	    will be needed.
		 *	    In japanese: SJIS,EUC,UNICODE,(JIS)
		 *	    Note that JIS-code system don't use as
		 *	    process code in most system because it uses
		 *	    escape sequences(JIS is context depend encoding).
		 */
		// assume process code is JAPANESE-EUC
		lb &= 0x7f;
		tb &= 0x7f;
# endif
		// exceptions
		switch (lb << 8 | tb)
		{
		    case 0x2121: // ZENKAKU space
			return 0;
		    case 0x2122: // TOU-TEN (Japanese comma)
		    case 0x2123: // KU-TEN (Japanese period)
		    case 0x2124: // ZENKAKU comma
		    case 0x2125: // ZENKAKU period
			return 1;
		    case 0x213c: // prolongedsound handled as KATAKANA
			return 13;
		}
		// sieved by KU code
		switch (lb)
		{
		    case 0x21:
		    case 0x22:
			// special symbols
			return 10;
		    case 0x23:
			// alphanumeric
			return 11;
		    case 0x24:
			// hiragana
			return 12;
		    case 0x25:
			// katakana
			return 13;
		    case 0x26:
			// greek
			return 14;
		    case 0x27:
			// russian
			return 15;
		    case 0x28:
			// lines
			return 16;
		    default:
			// kanji
			return 17;
		}
	    }

	case DBCS_KORU:	// ?
	case DBCS_KOR:
	    {
		// KS code classification
		unsigned char c1 = lead;
		unsigned char c2 = trail;

		/*
		 * 20 : Hangul
		 * 21 : Hanja
		 * 22 : Symbols
		 * 23 : Alphanumeric/Roman Letter (Full width)
		 * 24 : Hangul Letter(Alphabet)
		 * 25 : Roman Numeral/Greek Letter
		 * 26 : Box Drawings
		 * 27 : Unit Symbols
		 * 28 : Circled/Parenthesized Letter
		 * 29 : Hiragana/Katakana
		 * 30 : Cyrillic Letter
		 */

		if (c1 >= 0xB0 && c1 <= 0xC8)
		    // Hangul
		    return 20;
#if defined(MSWIN) || defined(WIN32UNIX)
		else if (c1 <= 0xA0 || c2 <= 0xA0)
		    // Extended Hangul Region : MS UHC(Unified Hangul Code)
		    // c1: 0x81-0xA0 with c2: 0x41-0x5A, 0x61-0x7A, 0x81-0xFE
		    // c1: 0xA1-0xC6 with c2: 0x41-0x5A, 0x61-0x7A, 0x81-0xA0
		    return 20;
#endif

		else if (c1 >= 0xCA && c1 <= 0xFD)
		    // Hanja
		    return 21;
		else switch (c1)
		{
		    case 0xA1:
		    case 0xA2:
			// Symbols
			return 22;
		    case 0xA3:
			// Alphanumeric
			return 23;
		    case 0xA4:
			// Hangul Letter(Alphabet)
			return 24;
		    case 0xA5:
			// Roman Numeral/Greek Letter
			return 25;
		    case 0xA6:
			// Box Drawings
			return 26;
		    case 0xA7:
			// Unit Symbols
			return 27;
		    case 0xA8:
		    case 0xA9:
			if (c2 <= 0xAF)
			    return 25;  // Roman Letter
			else if (c2 >= 0xF6)
			    return 22;  // Symbols
			else
			    // Circled/Parenthesized Letter
			    return 28;
		    case 0xAA:
		    case 0xAB:
			// Hiragana/Katakana
			return 29;
		    case 0xAC:
			// Cyrillic Letter
			return 30;
		}
	    }
	default:
	    break;
    }
    return 3;
}
dbcs_class(unsigned lead, unsigned trail)
{
    switch (enc_dbcs)
    {
	 

	case DBCS_JPNU:	 
	case DBCS_JPN:
	    {
		 
		unsigned char lb = lead;
		unsigned char tb = trail;

		 
# if defined(MSWIN) || defined(WIN32UNIX) || defined(MACOS_X)
		 
		if (lb <= 0x9f)
		    lb = (lb - 0x81) * 2 + 0x21;
		else
		    lb = (lb - 0xc1) * 2 + 0x21;
		if (tb <= 0x7e)
		    tb -= 0x1f;
		else if (tb <= 0x9e)
		    tb -= 0x20;
		else
		{
		    tb -= 0x7e;
		    lb += 1;
		}
# else
		 
		 
		lb &= 0x7f;
		tb &= 0x7f;
# endif
		 
		switch (lb << 8 | tb)
		{
		    case 0x2121:  
			return 0;
		    case 0x2122:  
		    case 0x2123:  
		    case 0x2124:  
		    case 0x2125:  
			return 1;
		    case 0x213c:  
			return 13;
		}
		 
		switch (lb)
		{
		    case 0x21:
		    case 0x22:
			 
			return 10;
		    case 0x23:
			 
			return 11;
		    case 0x24:
			 
			return 12;
		    case 0x25:
			 
			return 13;
		    case 0x26:
			 
			return 14;
		    case 0x27:
			 
			return 15;
		    case 0x28:
			 
			return 16;
		    default:
			 
			return 17;
		}
	    }

	case DBCS_KORU:	 
	case DBCS_KOR:
	    {
		 
		unsigned char c1 = lead;
		unsigned char c2 = trail;

		 

		if (c1 >= 0xB0 && c1 <= 0xC8)
		     
		    return 20;
#if defined(MSWIN) || defined(WIN32UNIX)
		else if (c1 <= 0xA0 || c2 <= 0xA0)
		     
		     
		     
		    return 20;
#endif

		else if (c1 >= 0xCA && c1 <= 0xFD)
		     
		    return 21;
		else switch (c1)
		{
		    case 0xA1:
		    case 0xA2:
			 
			return 22;
		    case 0xA3:
			 
			return 23;
		    case 0xA4:
			 
			return 24;
		    case 0xA5:
			 
			return 25;
		    case 0xA6:
			 
			return 26;
		    case 0xA7:
			 
			return 27;
		    case 0xA8:
		    case 0xA9:
			if (c2 <= 0xAF)
			    return 25;   
			else if (c2 >= 0xF6)
			    return 22;   
			else
			     
			    return 28;
		    case 0xAA:
		    case 0xAB:
			 
			return 29;
		    case 0xAC:
			 
			return 30;
		}
	    }
	default:
	    break;
    }
    return 3;
}