linklayerprotocols/pppnif/tsrc/Tcfgfile.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 26 Jan 2010 15:23:49 +0200
changeset 0 af10295192d8
permissions -rw-r--r--
Revision: 201004

// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of "Eclipse Public License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
//
// Initial Contributors:
// Nokia Corporation - initial contribution.
//
// Contributors:
//
// Description:
// TESTUTL.CPP
// 
//

#include "tcfgfile.h"
#include <f32file.h>

//PhilippeG 15/05/2000
//New object to load and parse the test parameters file
CConfigParams* CConfigParams::NewL(const TDesC &aCfgFileName)
	{
	CConfigParams *f;
	f=new (ELeave) CConfigParams();
	CleanupStack::PushL(f);
	//A leave during the ConstrucL is not fatal, just means there's no param file
	TRAPD(err,f->ConstructL(aCfgFileName));
	CleanupStack::Pop();
	return f;
	}
void CConfigParams::ConstructL(const TDesC &aCfgFileName)
	{
	//Find the config file
	TAutoClose<RFs> fs;
	User::LeaveIfError(fs.iObj.Connect());
	fs.PushL();
	//Location for the test parameter config file
	_LIT(KTinetConfigFilePaths,"\\testdata\\configs\\ppp\\;\\;\\system\\data\\");
	TFindFile filePath(fs.iObj);
	User::LeaveIfError(filePath.FindByPath(aCfgFileName,&KTinetConfigFilePaths));
	//read the content of the file
	TAutoClose<RFile> fl;
	fl.PushL();
	User::LeaveIfError(fl.iObj.Open(fs.iObj,filePath.File(),EFileShareExclusive));
	User::LeaveIfError(fl.iObj.Read(iConfigParamBuf8));
	iConfigParamBuf.Copy(iConfigParamBuf8);
	CleanupStack::Pop(2);
	iFileExist = ETrue;
	}

const TPtrC CConfigParams::FindAlphaVar(const TDesC &aVarName, const TDesC &aDefault)
	{
	if(!iFileExist)
		return TPtrC(aDefault);
	TInt pos=iConfigParamBuf.Find(aVarName);
	if (pos==KErrNotFound)
		return TPtrC(aDefault);
	TLex lex(iConfigParamBuf.Mid(pos));
	lex.SkipCharacters();
	lex.SkipSpaceAndMark();		// Should be at the start of the data
	lex.SkipCharacters();
	return TPtrC(lex.MarkedToken().Ptr(),lex.MarkedToken().Length());
	}
const TInt CConfigParams::FindNumVar(const TDesC &aVarName, const TInt aDefault)
	{
	TInt result;
	TPtrC ptr = FindAlphaVar(aVarName,KNullDesC);
	if(ptr.Length())
		{
		TLex lex(ptr);
		if (lex.Val(result)==KErrNone)
			return result;
		}
	return aDefault;
	}