• R/O
  • HTTP
  • SSH
  • HTTPS

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Loweynet


File Info

Révision 2bf85c03c1e059a2f75dbd48ef73be5961e12414
Taille 37,560 octets
l'heure 2011-09-01 13:44:19
Auteur hylom
Message de Log

initial commit from 1.97b zip archive

Content

/*=============================================================================
*
*							Š¿ŽšƒR[ƒh•ÏŠ·^‰üsƒR[ƒh•ÏŠ·
*
===============================================================================
/ Copyright (C) 1997-2007 Sota. All rights reserved.
/
/ Redistribution and use in source and binary forms, with or without 
/ modification, are permitted provided that the following conditions 
/ are met:
/
/  1. Redistributions of source code must retain the above copyright 
/     notice, this list of conditions and the following disclaimer.
/  2. Redistributions in binary form must reproduce the above copyright 
/     notice, this list of conditions and the following disclaimer in the 
/     documentation and/or other materials provided with the distribution.
/
/ THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 
/ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
/ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
/ IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 
/ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
/ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 
/ USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
/ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
/ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 
/ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/============================================================================*/

#define	STRICT
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winsock.h>
#include <mbstring.h>
#include <windowsx.h>

#include "common.h"
#include "resource.h"



#define CONV_ASCII		0		/* ASCII•¶Žšˆ—’† */
#define CONV_KANJI		1		/* Š¿Žšˆ—’† */
#define CONV_KANA		2		/* ”¼ŠpƒJƒ^ƒJƒiˆ—’† */


/*===== ƒvƒƒgƒ^ƒCƒv =====*/

static char *ConvEUCtoSJISkanaProc(CODECONVINFO *cInfo, char Dt, char *Put);
static char *ConvJIStoSJISkanaProc(CODECONVINFO *cInfo, char Dt, char *Put);
static char *ConvSJIStoEUCkanaProc(CODECONVINFO *cInfo, char Dt, char *Put);
static char *ConvSJIStoJISkanaProc(CODECONVINFO *cInfo, char Dt, char *Put);
static int HanKataToZen(char Ch);
static int AskDakuon(char Ch, char Daku);

static int CheckOnSJIS(uchar *Pos, uchar *Btm);
static int CheckOnEUC(uchar *Pos, uchar *Btm);
static int ConvertIBMExtendedChar(int code);



#if 0
/*----- Š¿ŽšƒR[ƒh•ÏŠ·‚̃eƒXƒgƒvƒƒOƒ‰ƒ€ ------------------------------------*/

void CodeCnvTest(void)
{
	#define BUFBUF	43
	#define BUFBUF2	BUFBUF+3

	CODECONVINFO cInfo;
	char Buf[BUFBUF];
	char Buf2[BUFBUF2];
	FILE *Strm1;
	FILE *Strm2;
	int Byte;
	int Continue;

//	DoPrintf("---START ZEN");

	Strm1 = fopen("in.txt", "rb");
	Strm2 = fopen("out_zen.txt", "wb");

	InitCodeConvInfo(&cInfo);
	cInfo.KanaCnv = YES;


	while((Byte = fread(Buf, 1, BUFBUF, Strm1)) != 0)
	{
		cInfo.Str = Buf;
		cInfo.StrLen = Byte;
		cInfo.Buf = Buf2;
		cInfo.BufSize = BUFBUF2;

//		DoPrintf("READ %d", Byte);

		do
		{
//			Continue = ConvEUCtoSJIS(&cInfo);
//			Continue = ConvJIStoSJIS(&cInfo);
//			Continue = ConvSJIStoEUC(&cInfo);
//			Continue = ConvSJIStoJIS(&cInfo);
			Continue = ConvSMBtoSJIS(&cInfo);
//			Continue = ConvSJIStoSMB_HEX(&cInfo);
//			Continue = ConvSJIStoSMB_CAP(&cInfo);

			fwrite(Buf2, cInfo.OutLen, 1, Strm2);
//			DoPrintf("WRITE %d", cInfo.OutLen);

		}
		while(Continue == YES);
	}

	cInfo.Buf = Buf2;
	cInfo.BufSize = BUFBUF2;
	FlushRestData(&cInfo);
	fwrite(Buf2, cInfo.OutLen, 1, Strm2);
//	DoPrintf("WRITE %d", cInfo.OutLen);


	fclose(Strm1);
	fclose(Strm2);


//	DoPrintf("---START HAN");

	Strm1 = fopen("in.txt", "rb");
	Strm2 = fopen("out_han.txt", "wb");

	InitCodeConvInfo(&cInfo);
	cInfo.KanaCnv = NO;


	while((Byte = fread(Buf, 1, BUFBUF, Strm1)) != 0)
	{
		cInfo.Str = Buf;
		cInfo.StrLen = Byte;
		cInfo.Buf = Buf2;
		cInfo.BufSize = BUFBUF2;

//		DoPrintf("READ %d", Byte);

		do
		{
//			Continue = ConvEUCtoSJIS(&cInfo);
//			Continue = ConvJIStoSJIS(&cInfo);
//			Continue = ConvSJIStoEUC(&cInfo);
//			Continue = ConvSJIStoJIS(&cInfo);
			Continue = ConvSMBtoSJIS(&cInfo);
//			Continue = ConvSJIStoSMB_HEX(&cInfo);
//			Continue = ConvSJIStoSMB_CAP(&cInfo);
			fwrite(Buf2, cInfo.OutLen, 1, Strm2);
//			DoPrintf("WRITE %d", cInfo.OutLen);

		}
		while(Continue == YES);
	}

	cInfo.Buf = Buf2;
	cInfo.BufSize = BUFBUF2;
	FlushRestData(&cInfo);
	fwrite(Buf2, cInfo.OutLen, 1, Strm2);
//	DoPrintf("WRITE %d", cInfo.OutLen);

	fclose(Strm1);
	fclose(Strm2);

//	DoPrintf("---END");

	return;
}
#endif



#if 0
/*----- ‰üsƒR[ƒh•ÏŠ·‚̃eƒXƒgƒvƒƒOƒ‰ƒ€ ------------------------------------*/

void TermCodeCnvTest(void)
{
	#define BUFBUF	10
	#define BUFBUF2	BUFBUF

	TERMCODECONVINFO cInfo;
	char Buf[BUFBUF];
	char Buf2[BUFBUF2];
	FILE *Strm1;
	FILE *Strm2;
	int Byte;
	int Continue;

//	DoPrintf("---START");

	Strm1 = fopen("in.txt", "rb");
	Strm2 = fopen("out.txt", "wb");

	InitTermCodeConvInfo(&cInfo);

	while((Byte = fread(Buf, 1, BUFBUF, Strm1)) != 0)
	{
		cInfo.Str = Buf;
		cInfo.StrLen = Byte;
		cInfo.Buf = Buf2;
		cInfo.BufSize = BUFBUF2;

//		DoPrintf("READ %d", Byte);

		do
		{
			Continue = ConvTermCodeToCRLF(&cInfo);

			fwrite(Buf2, cInfo.OutLen, 1, Strm2);
//			DoPrintf("WRITE %d", cInfo.OutLen);

		}
		while(Continue == YES);
	}

	cInfo.Buf = Buf2;
	cInfo.BufSize = BUFBUF2;
	FlushRestTermCodeConvData(&cInfo);
	fwrite(Buf2, cInfo.OutLen, 1, Strm2);
//	DoPrintf("WRITE %d", cInfo.OutLen);

	fclose(Strm1);
	fclose(Strm2);

//	DoPrintf("---END");

	return;
}
#endif












/*----- ‰üsƒR[ƒh•ÏŠ·î•ñ‚ð‰Šú‰» --------------------------------------------
*
*	Parameter
*		TERMCODECONVINFO *cInfo : ‰üsƒR[ƒh•ÏŠ·î•ñ
*
*	Return Value
*		‚È‚µ
*----------------------------------------------------------------------------*/

void InitTermCodeConvInfo(TERMCODECONVINFO *cInfo)
{
	cInfo->Term = 0;
	return;
}


/*----- ‰üsƒR[ƒh•ÏŠ·‚ÌŽc‚èî•ñ‚ðo—Í ----------------------------------------
*
*	Parameter
*		TERMCODECONVINFO *cInfo : ‰üsƒR[ƒh•ÏŠ·î•ñ
*
*	Return Value
*		int ‚­‚è•Ô‚µƒtƒ‰ƒO (=NO)
*
*	Note
*		‰üsƒR[ƒh•ÏŠ·‚̍Ōã‚ɌĂԎ–
*----------------------------------------------------------------------------*/

int FlushRestTermCodeConvData(TERMCODECONVINFO *cInfo)
{
	char *Put;

	Put = cInfo->Buf;

	if(cInfo->Term == 0x0D)
		*Put++ = 0x0A;

	cInfo->OutLen = Put - cInfo->Buf;

	return(NO);
}


/*----- ‰üsƒR[ƒh‚ðCRLF‚É•ÏŠ· -------------------------------------------------
*
*	Parameter
*		TERMCODECONVINFO *cInfo : ‰üsƒR[ƒh•ÏŠ·î•ñ
*
*	Return Value
*		int ‚­‚è•Ô‚µƒtƒ‰ƒO (YES/NO)
*
*	Note
*		‚­‚è•Ô‚µƒtƒ‰ƒO‚ªYES‚ÌŽž‚́AcInfo‚Ì“à—e‚ð•Ï‚¦‚¸‚É‚à‚¤ˆê“xŒÄ‚Ô‚±‚Æ
*----------------------------------------------------------------------------*/

int ConvTermCodeToCRLF(TERMCODECONVINFO *cInfo)
{
	char *Str;
	char *Put;
	char *Limit;
	int Continue;

	Continue = NO;
	Str = cInfo->Str;
	Put = cInfo->Buf;
	Limit = cInfo->Buf + cInfo->BufSize - 1;

	for(; cInfo->StrLen > 0; cInfo->StrLen--)
	{
		if(Put >= Limit)
		{
			Continue = YES;
			break;
		}

		if(*Str == 0x0D)
		{
			if(cInfo->Term == 0x0D)
				*Put++ = 0x0A;
			*Put++ = 0x0D;
			cInfo->Term = *Str++;
		}
		else
		{
			if(*Str == 0x0A)
			{
				if(cInfo->Term != 0x0D)
					*Put++ = 0x0D;
			}
			else
			{
				if(cInfo->Term == 0x0D)
					*Put++ = 0x0A;
			}
			cInfo->Term = 0;
			*Put++ = *Str++;
		}
	}

	cInfo->Str = Str;
	cInfo->OutLen = Put - cInfo->Buf;

	return(Continue);
}


/*----- Š¿ŽšƒR[ƒh•ÏŠ·î•ñ‚ð‰Šú‰» --------------------------------------------
*
*	Parameter
*		CODECONVINFO *cInfo : Š¿ŽšƒR[ƒh•ÏŠ·î•ñ
*
*	Return Value
*		‚È‚µ
*----------------------------------------------------------------------------*/

void InitCodeConvInfo(CODECONVINFO *cInfo)
{
	cInfo->KanaCnv = YES;

	cInfo->EscProc = 0;
	cInfo->KanjiMode = CONV_ASCII;
	cInfo->KanjiFst = 0;
	cInfo->KanaPrev = 0;
	cInfo->KanaProc = NULL;
	return;
}


/*----- Š¿ŽšƒR[ƒh•ÏŠ·‚ÌŽc‚èî•ñ‚ðo—Í ----------------------------------------
*
*	Parameter
*		CODECONVINFO *cInfo : Š¿ŽšƒR[ƒh•ÏŠ·î•ñ
*
*	Return Value
*		int ‚­‚è•Ô‚µƒtƒ‰ƒO (=NO)
*
*	Note
*		Š¿ŽšƒR[ƒh•ÏŠ·‚̍Ōã‚ɌĂԎ–
*----------------------------------------------------------------------------*/

int FlushRestData(CODECONVINFO *cInfo)
{
	char *Put;

	Put = cInfo->Buf;

	if(cInfo->KanaProc != NULL)
		Put = (cInfo->KanaProc)(cInfo, 0, Put);

	if(cInfo->KanjiFst != 0)
		*Put++ = cInfo->KanjiFst;
	if(cInfo->EscProc >= 1)
		*Put++ = cInfo->EscCode[0];
	if(cInfo->EscProc == 2)
		*Put++ = cInfo->EscCode[1];

	cInfo->OutLen = Put - cInfo->Buf;

	return(NO);
}


/*----- EUCŠ¿ŽšƒR[ƒh‚ðSHIFT-JISŠ¿ŽšƒR[ƒh‚É•ÏŠ· ------------------------------
*
*	Parameter
*		CODECONVINFO *cInfo : Š¿ŽšƒR[ƒh•ÏŠ·î•ñ
*
*	Return Value
*		int ‚­‚è•Ô‚µƒtƒ‰ƒO (YES/NO)
*
*	Note
*		‚­‚è•Ô‚µƒtƒ‰ƒO‚ªYES‚ÌŽž‚́AcInfo‚Ì“à—e‚ð•Ï‚¦‚¸‚É‚à‚¤ˆê“xŒÄ‚Ô‚±‚Æ
*----------------------------------------------------------------------------*/

int ConvEUCtoSJIS(CODECONVINFO *cInfo)
{
	int Kcode;
	char *Str;
	char *Put;
	char *Limit;
	int Continue;

	cInfo->KanaProc = &ConvEUCtoSJISkanaProc;

	Continue = NO;
	Str = cInfo->Str;
	Put = cInfo->Buf;
	Limit = cInfo->Buf + cInfo->BufSize - 2;

	for(; cInfo->StrLen > 0; cInfo->StrLen--)
	{
		if(Put >= Limit)
		{
			Continue = YES;
			break;
		}

		if((*Str & 0x80) != 0)
		{
			if(cInfo->KanjiFst == 0)
				cInfo->KanjiFst = *Str++;
			else
			{
				if((uchar)cInfo->KanjiFst == (uchar)0x8E)	/* ”¼ŠpƒJƒ^ƒJƒi */
				{
					Put = ConvEUCtoSJISkanaProc(cInfo, *Str++, Put);
				}
				else
				{
					Put = ConvEUCtoSJISkanaProc(cInfo, 0, Put);

					Kcode = _mbcjistojms(((cInfo->KanjiFst & 0x7F) * 0x100) + (*Str++ & 0x7F));
					*Put++ = HIGH8(Kcode);
					*Put++ = LOW8(Kcode);
				}
				cInfo->KanjiFst = 0;
			}
		}
		else
		{
			Put = ConvEUCtoSJISkanaProc(cInfo, 0, Put);

			if(cInfo->KanjiFst != 0)
			{
				*Put++ = cInfo->KanjiFst;
				cInfo->KanjiFst = 0;
			}
			*Put++ = *Str++;
		}
	}

	cInfo->Str = Str;
	cInfo->OutLen = Put - cInfo->Buf;

	return(Continue);
}


/*----- EUC-->SHIFT-JISŠ¿ŽšƒR[ƒh‚É•ÏŠ·‚Ì”¼ŠpƒJƒ^ƒJƒi‚̏ˆ— -------------------
*
*	Parameter
*		CODECONVINFO *cInfo : Š¿ŽšƒR[ƒh•ÏŠ·î•ñ
*		char Dt : •¶Žš
*		char *Put : ƒf[ƒ^ƒZƒbƒgˆÊ’u
*
*	Return Value
*		char *ŽŸ‚̃f[ƒ^ƒZƒbƒgˆÊ’u
*----------------------------------------------------------------------------*/

static char *ConvEUCtoSJISkanaProc(CODECONVINFO *cInfo, char Dt, char *Put)
{
	int Kcode;
	int Daku;

	if(cInfo->KanaCnv == NO)
	{
		if(Dt != 0)
			*Put++ = Dt;
	}
	else
	{
		if(cInfo->KanaPrev != 0)
		{
			Daku = AskDakuon(cInfo->KanaPrev, Dt);

			Kcode = _mbcjistojms(HanKataToZen(cInfo->KanaPrev)) + Daku;
			*Put++ = HIGH8(Kcode);
			*Put++ = LOW8(Kcode);

			if(Daku == 0)
				cInfo->KanaPrev = Dt;
			else
				cInfo->KanaPrev = 0;
		}
		else
			cInfo->KanaPrev = Dt;
	}
	return(Put);
}


/*----- JISŠ¿ŽšƒR[ƒh‚ðSHIFT-JISŠ¿ŽšƒR[ƒh‚É•ÏŠ· ------------------------------
*
*	Parameter
*		CODECONVINFO *cInfo : Š¿ŽšƒR[ƒh•ÏŠ·î•ñ
*
*	Return Value
*		int ‚­‚è•Ô‚µƒtƒ‰ƒO (YES/NO)
*
*	Note
*		‚­‚è•Ô‚µƒtƒ‰ƒO‚ªYES‚ÌŽž‚́AcInfo‚Ì“à—e‚ð•Ï‚¦‚¸‚É‚à‚¤ˆê“xŒÄ‚Ô‚±‚Æ
*
*		ƒGƒXƒP[ƒvƒR[ƒh‚́AŽŸ‚Ì‚à‚̂ɑΉž‚µ‚Ä‚¢‚é
*			Š¿ŽšŠJŽn		<ESC>$B		<ESC>$@
*			”¼ŠpƒJƒiŠJŽn	<ESC>(I
*			Š¿ŽšI—¹		<ESC>(B		<ESC>(J		<ESC>(H
*----------------------------------------------------------------------------*/

int ConvJIStoSJIS(CODECONVINFO *cInfo)
{
	int Kcode;
	char *Str;
	char *Put;
	char *Limit;
	int Continue;

	cInfo->KanaProc = &ConvJIStoSJISkanaProc;

	Continue = NO;
	Str = cInfo->Str;
	Put = cInfo->Buf;
	Limit = cInfo->Buf + cInfo->BufSize - 3;

	for(; cInfo->StrLen > 0; cInfo->StrLen--)
	{
		if(Put >= Limit)
		{
			Continue = YES;
			break;
		}

		if(cInfo->EscProc == 0)
		{
			if(*Str == 0x1B)
			{
				if(cInfo->KanjiFst != 0)
				{
					*Put++ = cInfo->KanjiFst;
					cInfo->KanjiFst = 0;
				}
				Put = ConvJIStoSJISkanaProc(cInfo, 0, Put);

				cInfo->EscCode[cInfo->EscProc] = *Str++;
				cInfo->EscProc++;
			}
			else
			{
				if(cInfo->KanjiMode == CONV_KANA)
				{
					if(cInfo->KanjiFst != 0)
					{
						*Put++ = cInfo->KanjiFst;
						cInfo->KanjiFst = 0;
					}

					if((*Str >= 0x21) && (*Str <= 0x5F))
					{
						Put = ConvJIStoSJISkanaProc(cInfo, *Str++, Put);
					}
					else
					{
						Put = ConvJIStoSJISkanaProc(cInfo, 0, Put);
						*Put++ = *Str++;
					}
				}
				else if(cInfo->KanjiMode == CONV_KANJI)
				{
					Put = ConvJIStoSJISkanaProc(cInfo, 0, Put);
					if((*Str >= 0x21) && (*Str <= 0x7E))
					{
						if(cInfo->KanjiFst == 0)
							cInfo->KanjiFst = *Str++;
						else
						{
							Kcode = _mbcjistojms((cInfo->KanjiFst * 0x100) + *Str++);
							*Put++ = HIGH8(Kcode);
							*Put++ = LOW8(Kcode);
							cInfo->KanjiFst = 0;
						}
					}
					else
					{
						if(cInfo->KanjiFst == 0)
							*Put++ = *Str++;
						else
						{
							*Put++ = cInfo->KanjiFst;
							*Put++ = *Str++;
							cInfo->KanjiFst = 0;
						}
					}
				}
				else
				{
					Put = ConvJIStoSJISkanaProc(cInfo, 0, Put);
					*Put++ = *Str++;
				}
			}
		}
		else if(cInfo->EscProc == 1)
		{
			if((*Str == '$') || (*Str == '('))
			{
				cInfo->EscCode[cInfo->EscProc] = *Str++;
				cInfo->EscProc++;
			}
			else
			{
				*Put++ = cInfo->EscCode[0];
				*Put++ = *Str++;
				cInfo->EscProc = 0;
			}
		}
		else if(cInfo->EscProc == 2)
		{
			if((cInfo->EscCode[1] == '$') && ((*Str == 'B') || (*Str == '@')))
				cInfo->KanjiMode = CONV_KANJI;
			else if((cInfo->EscCode[1] == '(') && (*Str == 'I'))
				cInfo->KanjiMode = CONV_KANA;
			else if((cInfo->EscCode[1] == '(') && ((*Str == 'B') || (*Str == 'J') || (*Str == 'H')))
				cInfo->KanjiMode = CONV_ASCII;
			else
			{
				*Put++ = cInfo->EscCode[0];
				*Put++ = cInfo->EscCode[1];
				if((cInfo->KanjiMode == CONV_KANJI) && ((*Str >= 0x21) && (*Str <= 0x7E)))
					cInfo->KanjiFst = *Str;
				else
					*Put++ = *Str;
			}
			Str++;
			cInfo->EscProc = 0;
		}
	}

	cInfo->Str = Str;
	cInfo->OutLen = Put - cInfo->Buf;

	return(Continue);
}


/*----- JIS-->SHIFT-JISŠ¿ŽšƒR[ƒh‚É•ÏŠ·‚Ì”¼ŠpƒJƒ^ƒJƒi‚̏ˆ— -------------------
*
*	Parameter
*		CODECONVINFO *cInfo : Š¿ŽšƒR[ƒh•ÏŠ·î•ñ
*		char Dt : •¶Žš
*		char *Put : ƒf[ƒ^ƒZƒbƒgˆÊ’u
*
*	Return Value
*		char *ŽŸ‚̃f[ƒ^ƒZƒbƒgˆÊ’u
*----------------------------------------------------------------------------*/

static char *ConvJIStoSJISkanaProc(CODECONVINFO *cInfo, char Dt, char *Put)
{
	int Kcode;
	int Daku;

	Dt = (uchar)Dt + (uchar)0x80;
	if(cInfo->KanaCnv == NO)
	{
		if((uchar)Dt != (uchar)0x80)
			*Put++ = Dt;
	}
	else
	{
		if(cInfo->KanaPrev != 0)
		{
			Daku = AskDakuon(cInfo->KanaPrev, Dt);
			Kcode = _mbcjistojms(HanKataToZen(cInfo->KanaPrev)) + Daku;
			*Put++ = HIGH8(Kcode);
			*Put++ = LOW8(Kcode);

			if((Daku == 0) && ((uchar)Dt != (uchar)0x80))
				cInfo->KanaPrev = Dt;
			else
				cInfo->KanaPrev = 0;
		}
		else if((uchar)Dt != (uchar)0x80)
			cInfo->KanaPrev = Dt;
	}
	return(Put);
}


/*----- Samba-HEX/Samba-CAPŠ¿ŽšƒR[ƒh‚ðSHIFT-JISŠ¿ŽšƒR[ƒh‚É•ÏŠ· --------------
*
*	Parameter
*		CODECONVINFO *cInfo : Š¿ŽšƒR[ƒh•ÏŠ·î•ñ
*
*	Return Value
*		int ‚­‚è•Ô‚µƒtƒ‰ƒO (YES/NO)
*
*	Note
*		‚­‚è•Ô‚µƒtƒ‰ƒO‚ªYES‚ÌŽž‚́AcInfo‚Ì“à—e‚ð•Ï‚¦‚¸‚É‚à‚¤ˆê“xŒÄ‚Ô‚±‚Æ
*		•ªŠ„‚³‚ꂽ“ü—Í•¶Žš—ñ‚Ì•ÏŠ·‚̓Tƒ|[ƒg‚µ‚Ä‚¢‚È‚¢
*		”¼ŠpƒJƒ^ƒJƒi‚Ì•ÏŠ·Ý’è‚ɂ͑Ήž‚µ‚Ä‚¢‚È‚¢
*----------------------------------------------------------------------------*/

int ConvSMBtoSJIS(CODECONVINFO *cInfo)
{
	char *Str;
	char *Put;
	char *Limit;
	int Continue;

	Continue = NO;
	Str = cInfo->Str;
	Put = cInfo->Buf;
	Limit = cInfo->Buf + cInfo->BufSize - 2;

	for(; cInfo->StrLen > 0; cInfo->StrLen--)
	{
		if(Put >= Limit)
		{
			Continue = YES;
			break;
		}

		if((*Str == SAMBA_HEX_TAG) && (cInfo->StrLen >= 3))
		{
			if(isxdigit(*(Str+1)) && isxdigit(*(Str+2)))
			{
				*Put++ = N2INT(hex2bin(*(Str+1)), hex2bin(*(Str+2)));
				Str += 3;
				cInfo->StrLen -= 2;
			}
			else
				*Put++ = *Str++;
		}
		else
			*Put++ = *Str++;
	}

	cInfo->Str = Str;
	cInfo->OutLen = Put - cInfo->Buf;

	return(Continue);
}


/*----- SHIFT-JISŠ¿ŽšƒR[ƒh‚ðEUCŠ¿ŽšƒR[ƒh‚É•ÏŠ· ------------------------------
*
*	Parameter
*		CODECONVINFO *cInfo : Š¿ŽšƒR[ƒh•ÏŠ·î•ñ
*
*	Return Value
*		int ‚­‚è•Ô‚µƒtƒ‰ƒO (YES/NO)
*
*	Note
*		‚­‚è•Ô‚µƒtƒ‰ƒO‚ªYES‚ÌŽž‚́AcInfo‚Ì“à—e‚ð•Ï‚¦‚¸‚É‚à‚¤ˆê“xŒÄ‚Ô‚±‚Æ
*----------------------------------------------------------------------------*/

int ConvSJIStoEUC(CODECONVINFO *cInfo)
{
	int Kcode;
	char *Str;
	char *Put;
	char *Limit;
	int Continue;

	cInfo->KanaProc = &ConvSJIStoEUCkanaProc;

	Continue = NO;
	Str = cInfo->Str;
	Put = cInfo->Buf;
	Limit = cInfo->Buf + cInfo->BufSize - 2;

	for(; cInfo->StrLen > 0; cInfo->StrLen--)
	{
		if(Put >= Limit)
		{
			Continue = YES;
			break;
		}

		if(cInfo->KanjiFst == 0)
		{
			if((((uchar)*Str >= (uchar)0x81) && ((uchar)*Str <= (uchar)0x9F)) ||
			   ((uchar)*Str >= (uchar)0xE0))
			{
				Put = ConvSJIStoEUCkanaProc(cInfo, 0, Put);
				cInfo->KanjiFst = *Str++;
			}
			else if(((uchar)*Str >= (uchar)0xA0) && ((uchar)*Str <= (uchar)0xDF))
			{
				Put = ConvSJIStoEUCkanaProc(cInfo, *Str++, Put);
			}
			else
			{
				Put = ConvSJIStoEUCkanaProc(cInfo, 0, Put);
				*Put++ = *Str++;
			}
		}
		else
		{
			if((uchar)*Str >= (uchar)0x40)
			{
				Kcode = ConvertIBMExtendedChar(((uchar)cInfo->KanjiFst * 0x100) + (uchar)*Str++);
				Kcode = _mbcjmstojis(Kcode);
				*Put++ = HIGH8(Kcode) | 0x80;
				*Put++ = LOW8(Kcode) | 0x80;
			}
			else
			{
				*Put++ = cInfo->KanjiFst;
				*Put++ = *Str++;
			}
			cInfo->KanjiFst = 0;
		}
	}

	cInfo->Str = Str;
	cInfo->OutLen = Put - cInfo->Buf;

	return(Continue);
}


/*----- SHIFT-JIS-->EUCŠ¿ŽšƒR[ƒh‚É•ÏŠ·‚Ì”¼ŠpƒJƒ^ƒJƒi‚̏ˆ— -------------------
*
*	Parameter
*		CODECONVINFO *cInfo : Š¿ŽšƒR[ƒh•ÏŠ·î•ñ
*		char Dt : •¶Žš
*		char *Put : ƒf[ƒ^ƒZƒbƒgˆÊ’u
*
*	Return Value
*		char *ŽŸ‚̃f[ƒ^ƒZƒbƒgˆÊ’u
*----------------------------------------------------------------------------*/

static char *ConvSJIStoEUCkanaProc(CODECONVINFO *cInfo, char Dt, char *Put)
{
	int Kcode;
	int Daku;

	if(cInfo->KanaCnv == NO)
	{
		if(Dt != 0)
		{
			Kcode = 0x8E00 + (uchar)Dt;
			*Put++ = HIGH8(Kcode) | 0x80;
			*Put++ = LOW8(Kcode) | 0x80;
		}
	}
	else
	{
		if(cInfo->KanaPrev != 0)
		{
			Daku = AskDakuon(cInfo->KanaPrev, Dt);
			Kcode = HanKataToZen(cInfo->KanaPrev) + Daku;
			*Put++ = HIGH8(Kcode) | 0x80;
			*Put++ = LOW8(Kcode) | 0x80;

			if(Daku == 0)
				cInfo->KanaPrev = Dt;
			else
				cInfo->KanaPrev = 0;
		}
		else
			cInfo->KanaPrev = Dt;
	}
	return(Put);
}


/*----- SHIFT-JISŠ¿ŽšƒR[ƒh‚ðJISŠ¿ŽšƒR[ƒh‚É•ÏŠ· ------------------------------
*
*	Parameter
*		CODECONVINFO *cInfo : Š¿ŽšƒR[ƒh•ÏŠ·î•ñ
*
*	Return Value
*		int ‚­‚è•Ô‚µƒtƒ‰ƒO (YES/NO)
*
*	Note
*		‚­‚è•Ô‚µƒtƒ‰ƒO‚ªYES‚ÌŽž‚́AcInfo‚Ì“à—e‚ð•Ï‚¦‚¸‚É‚à‚¤ˆê“xŒÄ‚Ô‚±‚Æ
*
*		ƒGƒXƒP[ƒvƒR[ƒh‚́AŽŸ‚Ì‚à‚Ì‚ðŽg—p‚·‚é
*			Š¿ŽšŠJŽn		<ESC>$B
*			”¼ŠpƒJƒiŠJŽn	<ESC>(I
*			Š¿ŽšI—¹		<ESC>(B
*----------------------------------------------------------------------------*/

int ConvSJIStoJIS(CODECONVINFO *cInfo)
{
	int Kcode;
	char *Str;
	char *Put;
	char *Limit;
	int Continue;

	cInfo->KanaProc = &ConvSJIStoJISkanaProc;

	Continue = NO;
	Str = cInfo->Str;
	Put = cInfo->Buf;
	Limit = cInfo->Buf + cInfo->BufSize - 5;

	for(; cInfo->StrLen > 0; cInfo->StrLen--)
	{
		if(Put >= Limit)
		{
			Continue = YES;
			break;
		}

		if(cInfo->KanjiFst == 0)
		{
			if((((uchar)*Str >= (uchar)0x81) && ((uchar)*Str <= (uchar)0x9F)) ||
			   ((uchar)*Str >= (uchar)0xE0))
			{
				Put = ConvSJIStoJISkanaProc(cInfo, 0, Put);
				cInfo->KanjiFst = *Str++;
			}
			else if(((uchar)*Str >= (uchar)0xA0) && ((uchar)*Str <= (uchar)0xDF))
			{
				Put = ConvSJIStoJISkanaProc(cInfo, *Str++, Put);
			}
			else
			{
				Put = ConvSJIStoJISkanaProc(cInfo, 0, Put);
				if(cInfo->KanjiMode != CONV_ASCII)
				{
					*Put++ = 0x1B;
					*Put++ = '(';
					*Put++ = 'B';
					cInfo->KanjiMode = CONV_ASCII;
				}
				*Put++ = *Str++;
			}
		}
		else
		{
			Put = ConvSJIStoJISkanaProc(cInfo, 0, Put);
			if((uchar)*Str >= (uchar)0x40)
			{
				if(cInfo->KanjiMode != CONV_KANJI)
				{
					*Put++ = 0x1B;
					*Put++ = '$';
					*Put++ = 'B';
					cInfo->KanjiMode = CONV_KANJI;
				}

				Kcode = ConvertIBMExtendedChar(((uchar)cInfo->KanjiFst * 0x100) + (uchar)*Str++);
				Kcode = _mbcjmstojis(Kcode);
				*Put++ = HIGH8(Kcode);
				*Put++ = LOW8(Kcode);
			}
			else
			{
				if(cInfo->KanjiMode != CONV_ASCII)
				{
					*Put++ = 0x1B;
					*Put++ = '(';
					*Put++ = 'B';
					cInfo->KanjiMode = CONV_ASCII;
				}
				*Put++ = cInfo->KanjiFst;
				*Put++ = *Str++;
			}
			cInfo->KanjiFst = 0;
		}
	}

	cInfo->Str = Str;
	cInfo->OutLen = Put - cInfo->Buf;

	return(Continue);
}


/*----- SHIFT-JIS-->JISŠ¿ŽšƒR[ƒh‚É•ÏŠ·‚Ì”¼ŠpƒJƒ^ƒJƒi‚̏ˆ— -------------------
*
*	Parameter
*		CODECONVINFO *cInfo : Š¿ŽšƒR[ƒh•ÏŠ·î•ñ
*		char Dt : •¶Žš
*		char *Put : ƒf[ƒ^ƒZƒbƒgˆÊ’u
*
*	Return Value
*		char *ŽŸ‚̃f[ƒ^ƒZƒbƒgˆÊ’u
*----------------------------------------------------------------------------*/

static char *ConvSJIStoJISkanaProc(CODECONVINFO *cInfo, char Dt, char *Put)
{
	int Kcode;
	int Daku;

	if(cInfo->KanaCnv == NO)
	{
		if(Dt != 0)
		{
			if(cInfo->KanjiMode != CONV_KANA)
			{
				*Put++ = 0x1B;
				*Put++ = '(';
				*Put++ = 'I';
				cInfo->KanjiMode = CONV_KANA;
			}
			*Put++ = (uchar)Dt - (uchar)0x80;
		}
	}
	else
	{
		if(cInfo->KanaPrev != 0)
		{
			if(cInfo->KanjiMode != CONV_KANJI)
			{
				*Put++ = 0x1B;
				*Put++ = '$';
				*Put++ = 'B';
				cInfo->KanjiMode = CONV_KANJI;
			}
			Daku = AskDakuon(cInfo->KanaPrev, Dt);
			Kcode = HanKataToZen(cInfo->KanaPrev) + Daku;
			*Put++ = HIGH8(Kcode);
			*Put++ = LOW8(Kcode);

			if(Daku == 0)
				cInfo->KanaPrev = Dt;
			else
				cInfo->KanaPrev = 0;
		}
		else
			cInfo->KanaPrev = Dt;
	}
	return(Put);
}


/*----- SHIFT-JISŠ¿ŽšƒR[ƒh‚ðSamba-HEXŠ¿ŽšƒR[ƒh‚É•ÏŠ· ------------------------
*
*	Parameter
*		CODECONVINFO *cInfo : Š¿ŽšƒR[ƒh•ÏŠ·î•ñ
*
*	Return Value
*		int ‚­‚è•Ô‚µƒtƒ‰ƒO (YES/NO)
*
*	Note
*		‚­‚è•Ô‚µƒtƒ‰ƒO‚ªYES‚ÌŽž‚́AcInfo‚Ì“à—e‚ð•Ï‚¦‚¸‚É‚à‚¤ˆê“xŒÄ‚Ô‚±‚Æ
*		•ªŠ„‚³‚ꂽ“ü—Í•¶Žš—ñ‚Ì•ÏŠ·‚̓Tƒ|[ƒg‚µ‚Ä‚¢‚È‚¢
*		”¼ŠpƒJƒ^ƒJƒi‚Ì•ÏŠ·Ý’è‚ɂ͑Ήž‚µ‚Ä‚¢‚È‚¢
*----------------------------------------------------------------------------*/

int ConvSJIStoSMB_HEX(CODECONVINFO *cInfo)
{
	char *Str;
	char *Put;
	char *Limit;
	int Continue;

	Continue = NO;
	Str = cInfo->Str;
	Put = cInfo->Buf;
	Limit = cInfo->Buf + cInfo->BufSize - 6;

	for(; cInfo->StrLen > 0; cInfo->StrLen--)
	{
		if(Put >= Limit)
		{
			Continue = YES;
			break;
		}

		if((cInfo->StrLen >= 2) &&
		   ((((uchar)*Str >= (uchar)0x81) && ((uchar)*Str <= (uchar)0x9F)) ||
		    ((uchar)*Str >= (uchar)0xE0)))
		{
			sprintf(Put, "%c%02x%c%02x", SAMBA_HEX_TAG, (uchar)*Str, SAMBA_HEX_TAG, (uchar)*(Str+1));
			Str += 2;
			Put += 6;
			cInfo->StrLen--;
		}
		else if((uchar)*Str >= (uchar)0x80)
		{
			sprintf(Put, "%c%02x", SAMBA_HEX_TAG, (uchar)*Str++);
			Put += 3;
		}
		else
			*Put++ = *Str++;
	}

	cInfo->Str = Str;
	cInfo->OutLen = Put - cInfo->Buf;

	return(Continue);
}


/*----- SHIFT-JISŠ¿ŽšƒR[ƒh‚ðSamba-CAPŠ¿ŽšƒR[ƒh‚É•ÏŠ· ------------------------
*
*	Parameter
*		CODECONVINFO *cInfo : Š¿ŽšƒR[ƒh•ÏŠ·î•ñ
*
*	Return Value
*		int ‚­‚è•Ô‚µƒtƒ‰ƒO (YES/NO)
*
*	Note
*		‚­‚è•Ô‚µƒtƒ‰ƒO‚ªYES‚ÌŽž‚́AcInfo‚Ì“à—e‚ð•Ï‚¦‚¸‚É‚à‚¤ˆê“xŒÄ‚Ô‚±‚Æ
*		•ªŠ„‚³‚ꂽ“ü—Í•¶Žš—ñ‚Ì•ÏŠ·‚̓Tƒ|[ƒg‚µ‚Ä‚¢‚È‚¢
*----------------------------------------------------------------------------*/

int ConvSJIStoSMB_CAP(CODECONVINFO *cInfo)
{
	char *Str;
	char *Put;
	char *Limit;
	int Continue;

	Continue = NO;
	Str = cInfo->Str;
	Put = cInfo->Buf;
	Limit = cInfo->Buf + cInfo->BufSize - 6;

	for(; cInfo->StrLen > 0; cInfo->StrLen--)
	{
		if(Put >= Limit)
		{
			Continue = YES;
			break;
		}

		if((uchar)*Str >= (uchar)0x80)
		{
			sprintf(Put, "%c%02x", SAMBA_HEX_TAG, (uchar)*Str++);
			Put += 3;
		}
		else
			*Put++ = *Str++;
	}

	cInfo->Str = Str;
	cInfo->OutLen = Put - cInfo->Buf;

	return(Continue);
}


/*----- ‚PƒoƒCƒgƒJƒ^ƒJƒi‚ðJISŠ¿ŽšƒR[ƒh‚É•ÏŠ· ---------------------------------
*
*	Parameter
*		char Ch : ‚PƒoƒCƒgƒJƒ^ƒJƒiƒR[ƒh
*
*	Return Value
*		int JISŠ¿ŽšƒR[ƒh
*----------------------------------------------------------------------------*/

static int HanKataToZen(char Ch)
{
	static const int Katakana[] = {
		0x2121, 0x2123, 0x2156, 0x2157, 0x2122, 0x2126, 0x2572, 0x2521, 
		0x2523, 0x2525, 0x2527, 0x2529, 0x2563, 0x2565, 0x2567, 0x2543, 
		0x213C, 0x2522, 0x2524, 0x2526, 0x2528, 0x252A, 0x252B, 0x252D, 
		0x252F, 0x2531, 0x2533, 0x2535, 0x2537, 0x2539, 0x253B, 0x253D, 
		0x253F, 0x2541, 0x2544, 0x2546, 0x2548, 0x254A, 0x254B, 0x254C, 
		0x254D, 0x254E, 0x254F, 0x2552, 0x2555, 0x2558, 0x255B, 0x255E, 
		0x255F, 0x2560, 0x2561, 0x2562, 0x2564, 0x2566, 0x2568, 0x2569, 
		0x256A, 0x256B, 0x256C, 0x256D, 0x256F, 0x2573, 0x212B, 0x212C
	};

	return(Katakana[(uchar)Ch - (uchar)0xA0]);
}


/*----- ‘÷‰¹^”¼‘÷‰¹‚ɂȂ镶Žš‚©ƒ`ƒFƒbƒN --------------------------------------
*
*	Parameter
*		char Ch : ‚PƒoƒCƒgƒJƒ^ƒJƒiƒR[ƒh
*		char Daku : ‘÷“_^”¼‘÷“_
*
*	Return Value
*		int •¶ŽšƒR[ƒh‚ɉÁ‚¦‚é’l (0=‘÷‰¹^”¼‘÷‰¹‚É‚È‚ç‚È‚¢)
*----------------------------------------------------------------------------*/

static int AskDakuon(char Ch, char Daku)
{
	int Ret;

	Ret = 0;
	if((uchar)Daku == (uchar)0xDE)
	{
		if((((uchar)Ch >= (uchar)0xB6) && ((uchar)Ch <= (uchar)0xC4)) ||
		   (((uchar)Ch >= (uchar)0xCA) && ((uchar)Ch <= (uchar)0xCE)))
		{
			Ret = 1;
		}
	}
	else if((uchar)Daku == (uchar)0xDF)
	{
		if(((uchar)Ch >= (uchar)0xCA) && ((uchar)Ch <= (uchar)0xCE))
		{
			Ret = 2;
		}
	}
	return(Ret);
}












/*----- •¶Žš—ñ‚ÌŠ¿ŽšƒR[ƒh‚𒲂ׁAShift-JIS‚É•ÏŠ· -----------------------------
*
*	Parameter
*		char *Text : •¶Žš—ñ
*		int Pref : SJIS/EUC‚Ì—DæŽw’è
–			KANJI_SJIS / KANJI_EUC / KANJI_NOCNV=SJIS/EUC‚̃`ƒFƒbƒN‚Í‚µ‚È‚¢
*
*	Return Value
*		‚È‚µ
*----------------------------------------------------------------------------*/

void ConvAutoToSJIS(char *Text, int Pref)
{
	int Code;
	char *Buf;
	CODECONVINFO cInfo;

	Code = CheckKanjiCode(Text, strlen(Text), Pref);
	if(Code != KANJI_SJIS)
	{
		Buf = malloc(strlen(Text)+1);
		if(Buf != NULL)
		{
			InitCodeConvInfo(&cInfo);
			cInfo.KanaCnv = NO;
			cInfo.Str = Text;
			cInfo.StrLen = strlen(Text);
			cInfo.Buf = Buf;
			cInfo.BufSize = strlen(Text);

			switch(Code)
			{
				case KANJI_JIS :
					ConvJIStoSJIS(&cInfo);
					break;

				case KANJI_EUC :
					ConvEUCtoSJIS(&cInfo);
					break;
			}

			*(Buf + cInfo.OutLen) = NUL;
			strcpy(Text, Buf);
			free(Buf);
		}
	}
	return;
}


/*----- Žg‚í‚ê‚Ä‚¢‚銿ŽšƒR[ƒh‚𒲂ׂé ----------------------------------------
*
*	Parameter
*		char *Text : •¶Žš—ñ
*		int Size : •¶Žš—ñ‚Ì’·‚³
*		int Pref : SJIS/EUC‚Ì—DæŽw’è
–			KANJI_SJIS / KANJI_EUC / KANJI_NOCNV=SJIS/EUC‚̃`ƒFƒbƒN‚Í‚µ‚È‚¢
*
*	Return Value
*		int Š¿ŽšƒR[ƒh (KANJI_xxx)
*----------------------------------------------------------------------------*/

int CheckKanjiCode(char *Text, int Size, int Pref)
{
	uchar *Pos;
	uchar *Btm;
	int Ret;
	int PointSJIS;
	int PointEUC;

	Ret = KANJI_SJIS;
	if(Size >= 2)
	{
		Ret = -1;
		Btm = Text + Size;

		/* JISŠ¿ŽšƒR[ƒh‚̃`ƒFƒbƒN */
		Pos = Text;
		while((Pos = memchr(Pos, 0x1b, Btm-Pos-2)) != NULL)
		{
			Pos++;
			if((memcmp(Pos, "$B", 2) == 0) ||	/* <ESC>$B */
			   (memcmp(Pos, "$@", 2) == 0) ||	/* <ESC>$@ */
			   (memcmp(Pos, "(I", 2) == 0))		/* <ESC>(I */
			{
				Ret = KANJI_JIS;
				break;
			}
		}

		/* EUC‚ÆSHIFT-JISŠ¿ŽšƒR[ƒh‚̃`ƒFƒbƒN */
		if(Ret == -1)
		{
			if(Pref != KANJI_NOCNV)
			{
				Ret = Pref;
				Pos = Text;
				while(Pos < Btm)
				{
					PointSJIS = CheckOnSJIS(Pos, Btm);
					PointEUC = CheckOnEUC(Pos, Btm);
					if(PointSJIS > PointEUC)
					{
						Ret = KANJI_SJIS;
						break;
					}
					if(PointSJIS < PointEUC)
					{
						Ret = KANJI_EUC;
						break;
					}
					if((Pos = memchr(Pos, '\n', Btm-Pos)) == NULL)
						break;
					Pos++;
				}
			}
			else
				Ret = KANJI_SJIS;
		}
	}
	return(Ret);
}


/*----- SHIFT-JISƒR[ƒh‚̉”\«‚ª‚ ‚é‚©ƒ`ƒFƒbƒN --------------------------------
*
*	Parameter
*		uchar *Pos : •¶Žš—ñ
*		uchar *Btm : •¶Žš—ñ‚Ì––”ö
*
*	Return Value
*		int “¾“_
*
*	Note
*		High	81-FF (A0-DF‚Í”¼Šp)	(EBˆÈ~‚Í‚Ù‚Æ‚ñ‚Ç–³‚¢)
*		Low		40-FC
*----------------------------------------------------------------------------*/

static int CheckOnSJIS(uchar *Pos, uchar *Btm)
{
	int FstOnTwo;
	int Point;

	FstOnTwo = NO;
	Point = 100;
	while((Point > 0) && (Pos < Btm) && (*Pos != '\n'))
	{
		if(FstOnTwo == YES)
		{
			if((*Pos < 0x40) || (*Pos > 0xFC))	/* 2ƒoƒCƒg–Ú‚Í 0x40`0xFC */
				Point = 0;
			FstOnTwo = NO;
		}
		else if(*Pos >= 0x81)
		{
			if((*Pos < 0xA0) || (*Pos > 0xDF))	/* ”¼ŠpƒJƒi‚Å‚È‚¯‚ê‚Î */
			{
				if(*Pos >= 0xEB)		/* 1ƒoƒCƒg–Ú‚Í0xEBˆÈ~‚Í‚Ù‚Æ‚ñ‚Ç–³‚¢ */
					Point -= 50;
				FstOnTwo = YES;
			}
		}
		Pos++;
	}
	if(FstOnTwo == YES)		/* ‚PƒoƒCƒg–ڂŏI‚í‚Á‚Ä‚¢‚é‚Ì‚Í‚¨‚©‚µ‚¢  */
		Point = 0;

	return(Point);
}


/*----- EUCƒR[ƒh‚̉”\«‚ª‚ ‚é‚©ƒ`ƒFƒbƒN -------------------------------------
*
*	Parameter
*		uchar *Pos : •¶Žš—ñ
*		uchar *Btm : •¶Žš—ñ‚Ì––”ö
*
*	Return Value
*		int “¾“_
*
*	Note
*		High	A1-FE , 8E
*		Low		A1-FE
*----------------------------------------------------------------------------*/

static int CheckOnEUC(uchar *Pos, uchar *Btm)
{
	int FstOnTwo;
	int Point;

	FstOnTwo = 0;
	Point = 100;
	while((Point > 0) && (Pos < Btm) && (*Pos != '\n'))
	{
		if(FstOnTwo == 1)
		{
			if((*Pos < 0xA1) || (*Pos > 0xFE))	/* 2ƒoƒCƒg–Ú‚Í 0xA1`0xFE */
				Point = 0;
			FstOnTwo = 0;
		}
		else if(FstOnTwo == 2)		/* ”¼ŠpƒJƒi */
		{
			if((*Pos < 0xA0) || (*Pos > 0xDF))	/* 2ƒoƒCƒg–Ú‚Í 0xA0`0xDF */
				Point = 0;
			FstOnTwo = 0;
		}
		else
		{
			if(*Pos == 0x8E)		/* 0x8E??‚Í”¼ŠpƒJƒi */
				FstOnTwo = 2;
			else if((*Pos >= 0xA1) && (*Pos <= 0xFE))
				FstOnTwo = 1;
		}
		Pos++;
	}
	if(FstOnTwo != 0)		/* ‚PƒoƒCƒg–ڂŏI‚í‚Á‚Ä‚¢‚é‚Ì‚Í‚¨‚©‚µ‚¢  */
		Point = 0;

	return(Point);
}


// UTF-8N‘Ήž ‚±‚±‚©‚火
/*----- UTF-8NŠ¿ŽšƒR[ƒh‚ðSHIFT-JISŠ¿ŽšƒR[ƒh‚É•ÏŠ· ------------------------------
*
*	Parameter
*		CODECONVINFO *cInfo : Š¿ŽšƒR[ƒh•ÏŠ·î•ñ
*
*	Return Value
*		int ‚­‚è•Ô‚µƒtƒ‰ƒO (YES/NO)
*
*	Note
*		‚­‚è•Ô‚µƒtƒ‰ƒO‚ªYES‚ÌŽž‚́AcInfo‚Ì“à—e‚ð•Ï‚¦‚¸‚É‚à‚¤ˆê“xŒÄ‚Ô‚±‚Æ
*----------------------------------------------------------------------------*/

int ConvUTF8NtoSJIS(CODECONVINFO *cInfo)
{
	int Continue;

	char temp_string[2048];
	int string_length;

	Continue = NO;

	// ¶¬‚³‚ê‚é’†ŠÔƒR[ƒh‚̃TƒCƒY‚𒲂ׂé
	string_length = MultiByteToWideChar(
						CP_UTF8,		// •ÏŠ·æ•¶ŽšƒR[ƒh
						0,				// ƒtƒ‰ƒO(0:‚È‚µ)
						cInfo->Str,		// •ÏŠ·Œ³•¶Žš—ñ
						-1,				// •ÏŠ·Œ³•¶Žš—ñƒoƒCƒg”(-1:Ž©“®)
						NULL,			// •ÏŠ·‚µ‚½•¶Žš—ñ‚ÌŠi”[æ
						0				// Ši”[æƒTƒCƒY
					);

	// ƒTƒCƒY0 or ƒoƒbƒtƒ@ƒTƒCƒY‚æ‚è‘å‚«‚¢ê‡‚Í
	// cInfo->Buf‚̍ŏ‰‚É'\0'‚ð“ü‚ê‚āA
	// cInfo->BufSize‚É0‚ð“ü‚ê‚Ä•Ô‚·B
	if( string_length == 0 ||
		string_length >= 1024 ){
		*(cInfo->Buf) = '\0';
		cInfo->BufSize = 0;
		return(Continue);
	}

	// ’†ŠÔƒR[ƒh(unicode)‚É•ÏŠ·
	MultiByteToWideChar(
		CP_UTF8,						// •ÏŠ·æ•¶ŽšƒR[ƒh
		0,								// ƒtƒ‰ƒO(0:‚È‚µ)
		cInfo->Str,						// •ÏŠ·Œ³•¶Žš—ñ
		-1,								// •ÏŠ·Œ³•¶Žš—ñƒoƒCƒg”(-1:Ž©“®)
		(unsigned short *)temp_string,	// •ÏŠ·‚µ‚½•¶Žš—ñ‚ÌŠi”[æ
		1024							// Ši”[æƒTƒCƒY
	);

	// ¶¬‚³‚ê‚éUTF-8ƒR[ƒh‚̃TƒCƒY‚𒲂ׂé
	string_length = WideCharToMultiByte(
						CP_ACP,			// •ÏŠ·æ•¶ŽšƒR[ƒh
						0,				// ƒtƒ‰ƒO(0:‚È‚µ)
						(unsigned short *)temp_string,	// •ÏŠ·Œ³•¶Žš—ñ
						-1,				// •ÏŠ·Œ³•¶Žš—ñƒoƒCƒg”(-1:Ž©“®)
						NULL,			// •ÏŠ·‚µ‚½•¶Žš—ñ‚ÌŠi”[æ
						0,				// Ši”[æƒTƒCƒY
						NULL,NULL
					);

	// ƒTƒCƒY0 or o—̓oƒbƒtƒ@ƒTƒCƒY‚æ‚è‘å‚«‚¢ê‡‚́A
	// cInfo->Buf‚̍ŏ‰‚É'\0'‚ð“ü‚ê‚āA
	// cInfo->BufSize‚É0‚ð“ü‚ê‚Ä•Ô‚·B
	if( string_length == 0 ||
		string_length >= cInfo->BufSize ){
		*(cInfo->Buf) = '\0';
		cInfo->BufSize = 0;
		return(Continue);
	}

	// o—̓TƒCƒY‚ðÝ’è
	cInfo->OutLen = string_length;

	// UTF-8ƒR[ƒh‚É•ÏŠ·
	WideCharToMultiByte(
		CP_ACP,							// •ÏŠ·æ•¶ŽšƒR[ƒh
		0,								// ƒtƒ‰ƒO(0:‚È‚µ)
		(unsigned short *)temp_string,	// •ÏŠ·Œ³•¶Žš—ñ
		-1,								// •ÏŠ·Œ³•¶Žš—ñƒoƒCƒg”(-1:Ž©“®)
		cInfo->Buf,						// •ÏŠ·‚µ‚½•¶Žš—ñ‚ÌŠi”[æ(BOM:3bytes)
		cInfo->BufSize,					// Ši”[æƒTƒCƒY
		NULL,NULL
	);

	return(Continue);
}

/*----- SHIFT-JISŠ¿ŽšƒR[ƒh‚ðUTF-8NŠ¿ŽšƒR[ƒh‚É•ÏŠ· ------------------------------
*
*	Parameter
*		CODECONVINFO *cInfo : Š¿ŽšƒR[ƒh•ÏŠ·î•ñ
*
*	Return Value
*		int ‚­‚è•Ô‚µƒtƒ‰ƒO (YES/NO)
*
*	Note
*		‚­‚è•Ô‚µƒtƒ‰ƒO‚ªYES‚ÌŽž‚́AcInfo‚Ì“à—e‚ð•Ï‚¦‚¸‚É‚à‚¤ˆê“xŒÄ‚Ô‚±‚Æ
*----------------------------------------------------------------------------*/
int ConvSJIStoUTF8N(CODECONVINFO *cInfo)
{
	int Continue;

	char temp_string[2048];
	int string_length;

	Continue = NO;

	// ¶¬‚³‚ê‚é’†ŠÔƒR[ƒh‚̃TƒCƒY‚𒲂ׂé
	string_length = MultiByteToWideChar(
						CP_ACP,			// •ÏŠ·æ•¶ŽšƒR[ƒh
						0,				// ƒtƒ‰ƒO(0:‚È‚µ)
						cInfo->Str,		// •ÏŠ·Œ³•¶Žš—ñ
						-1,				// •ÏŠ·Œ³•¶Žš—ñƒoƒCƒg”(-1:Ž©“®)
						NULL,			// •ÏŠ·‚µ‚½•¶Žš—ñ‚ÌŠi”[æ
						0				// Ši”[æƒTƒCƒY
					);

	// ƒTƒCƒY0 or ƒoƒbƒtƒ@ƒTƒCƒY‚æ‚è‘å‚«‚¢ê‡‚́A
	// cInfo->Buf‚̍ŏ‰‚É'\0'‚ð“ü‚ê‚āA
	// cInfo->BufSize‚É0‚ð“ü‚ê‚Ä•Ô‚·B
	if( string_length == 0 ||
		string_length >= 1024 ){
		*(cInfo->Buf) = '\0';
		cInfo->BufSize = 0;
		return(Continue);
	}

	// ’†ŠÔƒR[ƒh(unicode)‚É•ÏŠ·
	MultiByteToWideChar(
		CP_ACP,							// •ÏŠ·æ•¶ŽšƒR[ƒh
		0,								// ƒtƒ‰ƒO(0:‚È‚µ)
		cInfo->Str,						// •ÏŠ·Œ³•¶Žš—ñ
		-1,								// •ÏŠ·Œ³•¶Žš—ñƒoƒCƒg”(-1:Ž©“®)
		(unsigned short *)temp_string,	// •ÏŠ·‚µ‚½•¶Žš—ñ‚ÌŠi”[æ
		1024							// Ši”[æƒTƒCƒY
	);

	// ¶¬‚³‚ê‚éUTF-8ƒR[ƒh‚̃TƒCƒY‚𒲂ׂé
	string_length = WideCharToMultiByte(
						CP_UTF8,		// •ÏŠ·æ•¶ŽšƒR[ƒh
						0,				// ƒtƒ‰ƒO(0:‚È‚µ)
						(unsigned short *)temp_string,	// •ÏŠ·Œ³•¶Žš—ñ
						-1,				// •ÏŠ·Œ³•¶Žš—ñƒoƒCƒg”(-1:Ž©“®)
						NULL,			// •ÏŠ·‚µ‚½•¶Žš—ñ‚ÌŠi”[æ
						0,				// Ši”[æƒTƒCƒY
						NULL,NULL
					);

	// ƒTƒCƒY0 or o—̓oƒbƒtƒ@ƒTƒCƒY‚æ‚è‘å‚«‚¢ê‡‚́A
	// cInfo->Buf‚̍ŏ‰‚É'\0'‚ð“ü‚ê‚āA
	// cInfo->BufSize‚É0‚ð“ü‚ê‚Ä•Ô‚·B
	if( string_length == 0 ||
		string_length >= cInfo->BufSize ){
		*(cInfo->Buf) = '\0';
		cInfo->BufSize = 0;
		return(Continue);
	}

	// o—̓TƒCƒY‚ðÝ’è
	cInfo->OutLen = string_length;

	/*
	// «•t‚¯‚¿‚Ⴞ‚ß ƒRƒ}ƒ“ƒh‚É‚à’ljÁ‚³‚ê‚Ä‚µ‚Ü‚¤
	// o—Í•¶Žš—ñ‚̐擪‚ÉBOM(byte order mark)‚ð‚‚¯‚é
	*(cInfo->Buf) = (char)0xef;
	*(cInfo->Buf+1) = (char)0xbb;
	*(cInfo->Buf+2) = (char)0xbf;
	*/

	// UTF-8ƒR[ƒh‚É•ÏŠ·
	WideCharToMultiByte(
		CP_UTF8,						// •ÏŠ·æ•¶ŽšƒR[ƒh
		0,								// ƒtƒ‰ƒO(0:‚È‚µ)
		(unsigned short *)temp_string,	// •ÏŠ·Œ³•¶Žš—ñ
		-1,								// •ÏŠ·Œ³•¶Žš—ñƒoƒCƒg”(-1:Ž©“®)
		cInfo->Buf,					// •ÏŠ·‚µ‚½•¶Žš—ñ‚ÌŠi”[æ(BOM:3bytes)
		cInfo->BufSize,					// Ši”[æƒTƒCƒY
		NULL,NULL
	);

	return(Continue);
}
// UTF-8N‘Ήž ‚±‚±‚܂Łª


/*----- IBMŠg’£Š¿Žš‚ðNEC‘I’èIBMŠg’£Š¿Žš“™‚É•ÏŠ· -------------------------------
*
*	Parameter
*		code	Š¿ŽšƒR[ƒh
*
*	Return Value
*		int Š¿ŽšƒR[ƒh
*----------------------------------------------------------------------------*/
static int ConvertIBMExtendedChar(int code)
{
	if((code >= 0xfa40) && (code <= 0xfa49))		code -= (0xfa40 - 0xeeef);
	else if((code >= 0xfa4a) && (code <= 0xfa53))	code -= (0xfa4a - 0x8754);
	else if((code >= 0xfa54) && (code <= 0xfa57))	code -= (0xfa54 - 0xeef9);
	else if(code == 0xfa58)							code = 0x878a;
	else if(code == 0xfa59)							code = 0x8782;
	else if(code == 0xfa5a)							code = 0x8784;
	else if(code == 0xfa5b)							code = 0x879a;
	else if((code >= 0xfa5c) && (code <= 0xfa7e))	code -= (0xfa5c - 0xed40);
	else if((code >= 0xfa80) && (code <= 0xfa9b))	code -= (0xfa80 - 0xed63);
	else if((code >= 0xfa9c) && (code <= 0xfafc))	code -= (0xfa9c - 0xed80);
	else if((code >= 0xfb40) && (code <= 0xfb5b))	code -= (0xfb40 - 0xede1);
	else if((code >= 0xfb5c) && (code <= 0xfb7e))	code -= (0xfb5c - 0xee40);
	else if((code >= 0xfb80) && (code <= 0xfb9b))	code -= (0xfb80 - 0xee63);
	else if((code >= 0xfb9c) && (code <= 0xfbfc))	code -= (0xfb9c - 0xee80);
	else if((code >= 0xfc40) && (code <= 0xfc4b))	code -= (0xfc40 - 0xeee1);
	return code;
}