#
# FCGenerateSDKClass.pl
#
# $g_ExpClasses = ('FCObjDynabase');				## _xZkqqHx_iPgPjHmNiDeOiDiJiDfIjGlMiBeC_xHqqkZx_

local(%l_ClassHash);
## _xZkqqHx_iDgOiDgCiDfGiDiFiCmJiPgPjHmNiLjGiJmCiDeOiDiJiDfIiCpAiLeMjIfOiBeC_xHqqkZx_
foreach $i (@g_ExpClasses)
{
	$l_ClassHash{$i} = '1';
}

local($dd_fin_h) = "${g_FileName}.h";
local($sdk_fout_h) = "../MolipSDK/FC${g_FileName}.h";
local($sdk_fout_h_old) = $sdk_fout_h.'.old';
local($sdk_fout_h_new) = $sdk_fout_h.'.new';
local($sdk_fin_h_new) = $sdk_fout_h_new;
open(SDK_FOUT_H_NEW, ">${sdk_fout_h_new}") || die "Cannot open ${sdk_fout_h_new}\n";

########################################################################
# _xZkqqHx_iCnMiClIiBeB_xHqqkZx_FC${g_FileName}.h _xZkqqHx_iCmMiDhHiDgCiDfPjFjEjFkKiCpAiPjBiCkLiPgPiClHiBeC_xHqqkZx_
########################################################################

print SDK_FOUT_H_NEW << "EndOfText";
//
// _xZkqqHx_iClBiCmMiDhEiDeAiDeDiDiLiCmNiBeB_xHqqkZx_FC${g_FileName}.pl_xZkqqHx_iCkJiCoHiOkJjDkOiNoMjAkMiClDiCoKiCnMiClHiBeC_xHqqkZx_
// _xZkqqHx_iClBiCmMiDhEiDeAiDeDiDiLiCpAjFnCiPfHiClFiCmEiCmNiCkCiCkPiCnMiClJiCpBiBeC_xHqqkZx_
//
#ifndef __FC${g_FileName}_h
#define __FC${g_FileName}_h

${hheaddesc}

EndOfText

########################################################################
# _xZkqqHx_iOjPiCmJiBeBiKgFiDeOiDiJiDfIiCkJiCoHjFeLjHhGiCmIiDiBiDjDiDgPiCpAjElCiCkLiPgPiClHiBeC_xHqqkZx_
########################################################################

print "Extract from ${dd_fin_h} ....";
open(DD_FIN_H, "${dd_fin_h}") || die "Cannot open ${dd_fin_h}\n";
local($l_OutClassName) = "";
local($l_bIsRawMode) = "0";
local($l_ClassDef) = "";
local($l_OutFuncMode) = "0";
local($l_line) = "0";
WID:while (<DD_FIN_H>)
{
	# _xZkqqHx_iNhDjEnEiNiGiJmBiOfKiBeC_xHqqkZx_
	$l_line++;

	if ($l_bIsRawMode eq "1")
	#----- _xZkqqHx_jAiCiCoKjHkMiClFiDiCiBfLiDgIiCmMiPoKiNiH_xHqqkZx_ -----
	{
		if (/<\/EXPORT TO SDK>/)
		#----- _xZkqqHx_jAiCiCoKjHkMiClFiDiCiBfLiDgIiPeJjHlJiCmMiPoKiNiH_xHqqkZx_ -----
		{
			$l_bIsRawMode = "0";
		}
		elsif (/<EXPORT TO SDK>/)
		#----- _xZkqqHx_jAiCiCoKjHkMiClFiDiCiBfLiDgIiKeKiOgOiCmMiPoKiNiH_xHqqkZx_ -----
		{
			print FDOUT "Error ($l_line):<EXPORT TO SDK>_xZkqqHx_iCmMiOjPiCmJ_xHqqkZx_<EXPORT TO SDK>_xZkqqHx_iCkKiCkAiCoIiCnMiClHiBeC_xHqqkZx_\n";
			last WID;
		}
		else
		{
			print SDK_FOUT_H_NEW;
		}
		# _xZkqqHx_iOjPiCmMiDiLiBfLiDhGiCnGiBeC_xHqqkZx_
		next WID;
	}

	#----- _xZkqqHx_jAiCiCoKjHkMiClFiDiCiBfLiDgIiCmFiCmNiCmIiCkCiPoKiNiH_xHqqkZx_ -----

	if (/<EXPORT TO SDK>/)
	#----- _xZkqqHx_jAiCiCoKjHkMiClFiDiCiBfLiDgIiKeKiOgOiCmMiPoKiNiH_xHqqkZx_ -----
	{
		$l_bIsRawMode = "1";
		# _xZkqqHx_iOjPiCmMiDiLiBfLiDhGiCnGiBeC_xHqqkZx_
		next WID;
	}

	if (/<\/EXPORT TO SDK>/)
	#----- _xZkqqHx_jAiCiCoKjHkMiClFiDiCiBfLiDgIiPeJjHlJiCmMiPoKiNiH_xHqqkZx_ -----
	{
		print FDOUT "Error ($l_line):<\/EXPORT TO SDK>_xZkqqHx_iCmMiOjPiCmJ_xHqqkZx_<\/EXPORT TO SDK>_xZkqqHx_iCkKiCkAiCoIiCnMiClHiBeC_xHqqkZx_\n";
		last WID;
	}

	if ($l_OutClassName eq "")
	#----- _xZkqqHx_iPgPjHmNiDeOiDiJiDfIiCkKjAnNjCoIiClDiCoKiCmEiCkCiCmIiCkCiPoKiNiH_xHqqkZx_ -----
	{
		if (/^class\s+([\w_]+)\s*$/ or
			/^class\s+([\w_]+)\s*\/\// or
			/^class\s+([\w_]+)\s*:\s*public/ or
			/^template\s*<class\s+[\w_]+>\s*class\s+([\w_]+)\b[^;]*$/)
		#----- _xZkqqHx_iPgPjHmNiDeOiDiJiDfIiCmMjCoIiLgAjFjEjFkKiCmMiPoKiNiH_xHqqkZx_ -----
		{
			if ($l_ClassHash{$1} eq "1")
			{
				$l_OutClassName = $1;
				$l_ClassDef = $_;
				chop $l_ClassDef;
			}
		}
		if ($l_OutClassName ne "")
		#----- _xZkqqHx_iPgPjHmNiDeOiDiJiDfIiCkKjAnNjCoIiClDiCoKiClNiPoKiNiH_xHqqkZx_ -----
		{
			print SDK_FOUT_H_NEW << "EndOfText";

${l_ClassDef}
{
public:

EndOfText
		}
		# _xZkqqHx_iOjPiCmMiDiLiBfLiDhGiCnGiBeC_xHqqkZx_
		next WID;
	}

	#----- _xZkqqHx_iPgPjHmNiDeOiDiJiDfIiCkKjAnNjCoIiClDiCoKiCmEiCkCiCoJiPoKiNiH_xHqqkZx_ -----

	if (/^}\s*;\s*\/\/\s*class\s+${l_OutClassName}/)
	#----- _xZkqqHx_iDeOiDiJiDfIjCoIiLgAiCmMiPeJjHlJiCmMiPoKiNiH_xHqqkZx_ -----
	{
		$l_OutClassName = "";
		print SDK_FOUT_H_NEW << "EndOfText";

}; // ${l_ClassDef}.

EndOfText
		# _xZkqqHx_iOjPiCmMiDiLiBfLiDhGiCnGiBeC_xHqqkZx_
		next WID;
	}

	if (/^(\s*#.*)$/)
	#----- _xZkqqHx_iDhNiDeOiDiNjCoIiLgAiBgJ_xHqqkZx_#ifdef_xZkqqHx_jDjJiBgKiCmMiPoKiNiH_xHqqkZx_ -----
	{
		print SDK_FOUT_H_NEW "$1\n";
		# _xZkqqHx_iOjPiCmMiDiLiBfLiDhGiCnGiBeC_xHqqkZx_
		next WID;
	}

	if (${l_OutFuncMode} eq "0")
	#----- _xZkqqHx_iJlMjBhKiKnGjAjEiPgPjHmNiDiCiBfLiDgIiCkK_xHqqkZx_0_xZkqqHx_iCmMiPoKiNiH_xHqqkZx_ -----
	{
##----- 06.04.03 Fukushiro M. _xZkqqHx_jFmPiNfIjBeP_xHqqkZx_ ()-----
##		if (/^\s*virtual\s*[\w_][\s\w_\&\*]*\s+[\w_]+\s*\(.*$/ or
##			/^\s*virtual\s+~[\w_]+\s*\(.*$/)
##----- 06.04.03 Fukushiro M. _xZkqqHx_jFmPiNfIiMoD_xHqqkZx_ ()-----
		if (/^\s*virtual\s*[\w_][\s\w_\&\*\<\>\,]*\s+[\w_]+\s*\(.*$/ or
			/^\s*virtual\s+~[\w_]+\s*\(.*$/)
##----- 06.04.03 Fukushiro M. _xZkqqHx_jFmPiNfIiPeJ_xHqqkZx_ ()-----
		#----- _xZkqqHx_iJlMjBhKiKnGjAjEiCmMjCoIiLgAjFjEjFkKiCmMiPoKiNiH_xHqqkZx_ -----
		{
			# _xZkqqHx_iJlMjBhKiKnGjAjEiPgPjHmNiDiCiBfLiDgIiCmJ_xHqqkZx_1_xZkqqHx_iCpAjAnNjCoIiBeC_xHqqkZx_
			$l_OutFuncMode = "1";
		} elsif (/^\s*virtual\s*[\w_][\s\w_\&\*]*\s+operator\b/)
		#----- _xZkqqHx_iJlMjBhKiKnGjAjE_xHqqkZx_(operator)_xZkqqHx_iCmMjCoIiLgAjFjEjFkKiCmMiPoKiNiH_xHqqkZx_ -----
		{
			# _xZkqqHx_iJlMjBhKiKnGjAjEiPgPjHmNiDiCiBfLiDgIiCmJ_xHqqkZx_1_xZkqqHx_iCpAjAnNjCoIiBeC_xHqqkZx_
			$l_OutFuncMode = "1";
		}
	}
	if (${l_OutFuncMode} eq "1")
	#----- _xZkqqHx_iJlMjBhKiKnGjAjEiPgPjHmNiDiCiBfLiDgIiCkK_xHqqkZx_1_xZkqqHx_iCmMiPoKiNiH_xHqqkZx_ -----
	{
		if (/^(.*);\s*$/ or /^(.*);\s*\/\/.*$/)
		#----- _xZkqqHx_iJlMjBhKiKnGjAjEiCmMjCoIiLgAiCmMiPeJjHlJiCmMiPoKiNiH_xHqqkZx_ -----
		{
			if (not /\s*=\s*0\s*;\s*$/)
			{
#				# _xZkqqHx_iJlMjBhKiKnGjAjEiCmMiNmFiMoDiCmJ_xHqqkZx_ = 0_xZkqqHx_iCpAjAnNjCoIiBeC_xHqqkZx_
#				$_ = "$1 = 0;\n";
				# _xZkqqHx_iJlMjBhKiKnGjAjEiCmMiNmFiMoDiCmJiJpMiNhDiCpAjAnNjCoIiBeC_xHqqkZx_
				$_ = "$1;\n";
			}
			# _xZkqqHx_iJlMjBhKiKnGjAjEiPgPjHmNiDiCiBfLiDgIiCmJ_xHqqkZx_2_xZkqqHx_iCpAjAnNjCoIiBeC_xHqqkZx_
			$l_OutFuncMode = "2";
		}
	}

	if (${l_OutFuncMode} ne "0")
	{
		print SDK_FOUT_H_NEW;
	}
	if (${l_OutFuncMode} eq "2")
	{
		$l_OutFuncMode = "0";
	}
}
close DD_FIN_H;

print SDK_FOUT_H_NEW << "EndOfText";

#endif//__FC${g_FileName}_h

EndOfText

close SDK_FOUT_H_NEW;

rename($sdk_fout_h, $sdk_fout_h_old);

# sdk_fin_h_new is EUC.
open(SDK_FIN_H_NEW, "${sdk_fin_h_new}") || die "Cannot open ${sdk_fin_h_new}\n";
open(SDK_FOUT_H, ">${sdk_fout_h}") || die "Cannot open ${sdk_fout_h}\n";
while (<SDK_FIN_H_NEW>)
{
	s/\bCOleDateTime\b/MfcOleDateTime/g;
	s/\bCBitmap\b/MfcBitmap/g;
	s/\bCFont\b/MfcFont/g;
	s/\bCPen\b/MfcPen/g;
	s/\bCBrush\b/MfcBrush/g;
	s/\bCPalette\b/MfcPalette/g;
	s/\bCRect\b/MfcRect/g;
	s/\bCGdiObject\b/MfcGdiObject/g;
	s/\bCRgn\b/MfcRgn/g;
	s/\bCPoint\b/MfcPoint/g;
	s/\bCPropertyPage\b/MfcPropertyPage/g;
	s/\bCOleClientItem\b/MfcOleClientItem/g;
	s/\bCCmdUI\b/MfcCmdUI/g;
	s/\bCPrintInfo\b/MfcPrintInfo/g;
	s/\bCDumpContext\b/MfcDumpContext/g;
	s/\bCPreviewView\b/MfcPreviewView/g;
	s/\bCCreateContext\b/MfcCreateContext/g;
	s/\bCOleServerItem\b/MfcOleServerItem/g;
	s/\bCOleDataObject\b/MfcOleDataObject/g;
	s/\bCRuntimeClass\b/MfcRuntimeClass/g;
	s/\bCArchive\b/MfcArchive/g;
	s/\bAFX_CMDHANDLERINFO\b/AFX_MFC_CMDHANDLERINFO/g;
	s/\bCTypeLibCache\b/MfcTypeLibCache/g;
	s/\bAFX_MSGMAP\b/AFX_MFC_MSGMAP/g;
	s/\bAFX_OLECMDMAP\b/AFX_MFC_OLECMDMAP/g;
	s/\bAFX_DISPMAP\b/AFX_MFC_DISPMAP/g;
	s/\bAFX_CONNECTIONMAP\b/AFX_MFC_CONNECTIONMAP/g;
	s/\bAFX_INTERFACEMAP\b/AFX_MFC_INTERFACEMAP/g;
	s/\bAFX_EVENTSINKMAP\b/AFX_MFC_EVENTSINKMAP/g;
	s/\bCPtrArray\b/MfcPtrArray/g;
	s/\bCScrollBar\b/MfcScrollBar/g;
	s/\bCDataExchange\b/MfcDataExchange/g;
	s/\bCOleControlSite\b/MfcOleControlSite/g;
	s/\bCSize\b/MfcSize/g;
	s/\bCDC\b/MfcDC/g;
	s/\bCFrameWnd\b/MfcFrameWnd/g;
	s/\bCMenu\b/MfcMenu/g;
	s/\bCWnd\b/MfcWnd/g;
	s/\bCException\b/MfcException/g;
	s/\bCFile\b/MfcFile/g;
	s/\bCMemFile\b/MfcMemFile/g;
	s/\bCFileException\b/MfcFileException/g;
	s/\bCDocItem\b/MfcDocItem/g;
	s/\bCDocObjectServer\b/MfcDocObjectServer/g;
	s/\bCOleIPFrameWnd\b/MfcOleIPFrameWnd/g;
	s/\bCString\b/MfcString/g;
	s/\bCCmdUI\b/MfcCmdUI/g;
	s/\bCObject\b/MfcObject/g;
	s/\bCCmdTarget\b/MfcCmdTarget/g;
	s/\bCWnd\b/MfcWnd/g;
	s/\bCView\b/MfcView/g;
	s/\bCDocument\b/MfcDocument/g;
	s/\bCOleDocument\b/MfcOleDocument/g;
	s/\bCOleLinkingDoc\b/MfcOleLinkingDoc/g;
	s/\bCOleServerDoc\b/MfcOleServerDoc/g;
	s/\bCPrintPreviewState\b/MfcPrintPreviewState/g;
	s/\bCToolBar\b/MfcToolBar/g;
	s/\bCEdit\b/MfcEdit/g;
	s/\bCComboBox\b/MfcComboBox/g;
	s/\bCPropertySheet\b/MfcPropertySheet/g;
	s/\bCWaitCursor\b/MfcWaitCursor/g;
	s/\bPOSITION\b/MFC_POSITION/g;

	s/\bset</vc6_set</g;
	s/\bbasic_string\b/vc6_basic_string/g;
	s/\bwstring\b/vc6_wstring/g;
	s/\bauto_ptr\b/vc6_auto_ptr/g;
	s/\bvector\b/vc6_vector/g;
	s/\bpair\b/vc6_pair/g;
	s/\bset\b/vc6_set/g;
	s/\bmap\b/vc6_map/g;

	s/\bCRectVector\b/MfcRectVector/g;
	s/\bCPointVector\b/MfcPointVector/g;
	s/\bCPropertyPageVector\b/MfcPropertyPageVector/g;
	s/\bCOleClientItemPVector\b/MfcOleClientItemPVector/g;

	#----- _xZkqqHx_iOmAiNhDiCpAiLnGiOhOiClDiCoKiClNiKnGjAjE_xHqqkZx_ ------
	s/\bCmdCreate1Obj\b/Prohibited00/g;
	s/\bCmdDelete1Obj\b/Prohibited01/g;

	print SDK_FOUT_H;
}
close SDK_FIN_H_NEW;
close SDK_FOUT_H;

unlink $sdk_fin_h_new;

print "Succeeded\n";

1;
