int main(int argc, char *argv[])
{
  struct Config_t config;
  GDFS_MAPDATA *Source_MapHead_p, *Source_MapTail_p;
  uint32 Noof_Source_Parameters = 0;
  int result = 0;

  memset(&config, 0x00, sizeof(struct Config_t));

  /* Parse the input argument and if not correct print info and exit */
  if (parseCmdline(argc, argv, &config) == -1)
  {
    result = -1;
    goto exit;
  }

  /* First we open the CSPSA area */
  if( InitCSPSA(&config) != 0)
  {
    result = -1;
    goto exit;
  }

  if(!ReadMapFile( config.MAP_FileName, &Noof_Source_Parameters, &Source_MapHead_p, &Source_MapTail_p)){
    fprintf(stderr, "CSPSA2MAP: Failed to open input map file.\n");
    result = -1;
    goto exit;
  }

  if(0 != write_parameters_to_cspsa(Source_MapHead_p, &config)){
    fprintf(stderr, "CSPSA2MAP: Failed to write parameters to CSPSA.\n");
    result = -1;
    goto exit;
  }

exit:

  /* Clean up and close any open files etc.. */
  if(config.CSPSA_Handle != 0x00){
    UnInit(&config);
  }

  return result;
}
bool CATDbgHelper::Open( const string& sParameter, const unsigned long iLong )
{
	LOG_FUNC_ENTRY("CATDbgHelper::Open");
	// Verify that file exits. Version 5.1.2600.5512 of dbghelp.dll does not correctly
	// return error code if missing image file. This can lead upto applicaton crash.
	if ( ! CATBase::FileExists( sParameter.c_str() ) )
	{
		LOG_STRING( "Missing image file: " << sParameter );
		return false;
	}

	// Is it urel try read map?
	if ( sParameter.find( "\\urel\\" ) != string::npos )
	{
		string sMapFile = sParameter;
		sMapFile.append( ".map" );
		ReadMapFile( sMapFile );
	}

	// Set base address used
	m_BaseAddress = iLong + AT_VIRTUAL_OFFSET_DBGHELPER;
	// Binary file (also referred as symbol).
	size_t length = sParameter.length();
	if ( length == 0 )
	{
		LOG_STRING("DbgHelp:Invalid binary parameter.");
		return false;
	}

	char* pChar = new char[ sParameter.length()+1 ];
	strcpy( pChar, sParameter.c_str() );
	// Have to be casted to PSTR before using dbg api. Even tho its typedef same.
	// This will avoid access violations bug.
	// Note pChar is not deleted because its the member pointer just casted its
	// memory allocation freed in destructor.
	if ( m_pBinaryFile )
		delete[] m_pBinaryFile;

	m_pBinaryFile = (PSTR) pChar;

	// Initialize dbghelper if not done only once.
	if ( ! CDBGHELPER_OPEN )
	{
		// Set symbol options
		SymSetOptions( SYMOPT_LOAD_LINES | SYMOPT_DEBUG | SYMOPT_UNDNAME | SYMOPT_LOAD_ANYTHING );
		if ( !SymInitialize( GetCurrentProcess(), NULL, TRUE ) )
		{
			LOG_STRING("DbgHelp:Error initializing dbghelper " << (int) GetLastError());
			return false;
		}
		LOG_STRING("DbgHelp:dbghelper opened.");
		CDBGHELPER_OPEN = true;
	}

	// Set symbol search path.
	if ( !SymSetSearchPath( GetCurrentProcess(), NULL ) )
	{
		LOG_STRING("DbgHelp:Error setting symbol search path " << (int) GetLastError());
		return false;
	}

	// Load module.
	DWORD64 ret;
	ret = SymLoadModule64( GetCurrentProcess(), NULL, m_pBinaryFile, NULL, m_BaseAddress, NULL ); // 5.1 api version.
	if ( ret != m_BaseAddress  && ret != 0)
	{
		LOG_STRING("Dbghelp:Module load failed " << (int) GetLastError());
		return false;
	}
	CDBGHELPER_CLIENTS++;
	return true;
}