|
// MacroFileReader.cpp: implementation of the CMacroFileReader class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CPPCWiz.h"
#include "MacroFileReader.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMacroFileReader::CMacroFileReader()
{
m_strFileMacro = "";
m_strFileData = "";
m_strMacroStart = "#@";
m_strMacroEnd = "@#";
}
CMacroFileReader::~CMacroFileReader()
{
}
VOID CMacroFileReader::ReadAndParseFile(CString fileName,CStringArray &arrMacro,CStringArray &arrMacroRepl)
{
ASSERT(fileName!="");
/*
* Check Status Of File - Wheather it is readable or not.
*/
CFileStatus OStatus;
BOOL bCanRead = CFile::GetStatus(fileName,OStatus);
if( bCanRead )
{
/*
* Read Whole File To CString Object ( strFileContent )
*/
m_strMacroFile.Format("%s",OStatus.m_szFullName);
m_strFileMacro = CString(OStatus.m_szFullName);
CFile OFileToRead(fileName,CFile::modeRead);
INT iFileLength = OFileToRead.GetLength();
OFileToRead.ReadHuge(m_strFileData.GetBuffer(iFileLength),iFileLength);
m_strFileData.ReleaseBuffer(iFileLength);
OFileToRead.Close();
}
else
{
return;
}
arrMacro.RemoveAll();
arrMacroRepl.RemoveAll();
//////////////////////////////////////////////////////////////////////////
// Parse File.
INT iMacroStart = m_strFileData.Find(m_strMacroStart,0);
INT iMacroEnd = iMacroStart+1;
CString retStrComment;
CString strTempMacro;
CString strTempMacroRepl;
while( iMacroStart >= 0 )
{
iMacroStart = iMacroStart + m_strMacroStart.GetLength();
iMacroEnd = m_strFileData.Find(m_strMacroEnd,iMacroStart);
if( iMacroEnd > iMacroStart)
{
retStrComment = m_strFileData.Mid(iMacroStart, (iMacroEnd - iMacroStart) );
DiffMacroAndReplaceString(retStrComment,strTempMacro, strTempMacroRepl);
if(strTempMacro != "")
{
arrMacro.Add(strTempMacro);
arrMacroRepl.Add(strTempMacroRepl);
}
}
else
{
retStrComment = "NOT FOUND IN FILE";
}
iMacroStart = m_strFileData.Find(m_strMacroStart,iMacroEnd);
}
}
VOID CMacroFileReader::DiffMacroAndReplaceString(CString data, CString ¯o, CString ¯oRepl)
{
data.TrimLeft();
data.TrimRight();
INT iPos = 0;
iPos = data.Find("=",iPos);
if(iPos < 0)
return;
macro = data.Mid(0,iPos);
//iPos = data.Find("=",iPos);
macroRepl = data.Mid(iPos+1,data.GetLength()-iPos+1);
macro.TrimLeft();
macroRepl.TrimLeft();
macro.TrimRight();
macroRepl.TrimRight();
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
A 8 or something in .NET, living in Ahmedabad, India owned IntelliPro Solutions Pvt. Ltd..
Currently working on .NET technologies, MVC and Silverlight.
My little blog is for helping community with the solution for problems or helping them to understand new technology. You can reach to my blog at http://maniish.wordpress.com.
To contact me, post comment here or email me at manish AT iprospl.com