terrloc.cpp

来自「在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己」· C++ 代码 · 共 118 行

CPP
118
字号
// TERRLOC.CPP
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

// Translator error location testing


#include <e32test.h>
#include <f32file.h>
#include <opltran.h>

LOCAL_D RTest test(_L("Translator Error Location"));
struct TErrorText
	{
	TOplTranslateError iError;
	const TText *iText; // Uses ^ as a marker for where the error should be - removed before translating 
	};

class CErrorTextSystem : public CBase, public MTextSourceSystem, public MTextSource
	{
public:
	static CErrorTextSystem* CErrorTextSystem::NewLC();
	~CErrorTextSystem();
	TInt SetTextFindErrorPosL(const TText* aProc); // Returns the position of the error characterr
	TInt OpenSource(TDes& aFileName, MTextSource*& aTextSource);
	TInt Read(TDes& aBuf,TInt aPos);
	TInt Read(TDes& aBuf);
	void Close();
private:
	void ConstructL();
private:
	TInt iPos;
	CBufFlat *iBuf;
	};

TInt CErrorTextSystem::SetTextFindErrorPosL(const TText *aProc)
//
// Takes a zero terminated bit of text, finds the ^ character which
// marks where the error should be
//
//	
	{

	Close();
	TPtrC input(aProc);
	TInt offset=input.Locate(TChar('^'));
	TPtr8 ptr((TUint8*)input.Ptr(),input.Size());
	ptr.SetLength(input.Size());
	iBuf->InsertL(0,ptr.Left(offset<<1));
	iBuf->InsertL(offset<<1,ptr.Mid((offset+1)<<1));
	return offset;
	}


CErrorTextSystem* CErrorTextSystem::NewLC()
	{

	CErrorTextSystem *pTs=new(ELeave) CErrorTextSystem;
	CleanupStack::PushL(pTs);
	pTs->ConstructL();
	return pTs;
	}

CErrorTextSystem::~CErrorTextSystem()
	{
	delete iBuf;
	}

TInt CErrorTextSystem::OpenSource(TDes& /*aFileName*/,MTextSource*& aTextSource)
	{
	aTextSource=this;
	return KErrNone;
	}

TInt CErrorTextSystem::Read(TDes& aBuf, TInt aPos)
	{
	iPos=aPos*sizeof(TText);
	return Read(aBuf);
	}

TInt CErrorTextSystem::Read(TDes& aBuf)
	{
	
	TInt length=iBuf->Size()-iPos;
	if (length<=0)
		return KErrEof;
	if (length>aBuf.MaxLength())
		length=aBuf.MaxLength();
	TPtr8 ptr((TUint8*)aBuf.Ptr(),aBuf.MaxLength()<<1);
	iBuf->Read(iPos,ptr,length);
	aBuf.SetLength(length>>1);
	iPos+=length;
	return KErrNone;
	}

void CErrorTextSystem::Close()
	{
	iPos=0;
	iBuf->Reset();
	}

void CErrorTextSystem::ConstructL()
	{
	
	iBuf=CBufFlat::NewL(0x20);
	}

#ifdef ___OPL1993
LOCAL_D TErrorText opl1993Tests[]=
	{
	{ EErrBadLogicalDevice,_S("PROC junk:\x2029 ^i.c=5\x2029 ENDP\x2029 ")}, // bad field va
	{ EErrIdentifierTooLong,_S("PROC junk:\x2029 abcdefgh=3\x2029 ^abcdefghi=4\x2029 ENDP\x2029 ")}, // name too long
	{ EErrIdentifierTooLong,_S("PROC junk:\x2029 abcdefg$=\"a\"\x2029 ^abcdefgh$=\"a\"\x2029 abcdefghi$=\"b\"\x2029 ENDP\x2029 ")}, // name too long
#if defined(_UNICODE) // K.K Japanese Visual C++ expect correct character code that exists in JIS code table!!!!
	{ EErrIdentifierTooLong,_S("PROC junk:\x2029 CCCCCCCC=3\x2029 ^AAAAAAAAEE4\x2029 ENDP\x2029 ")},
#else
 	{ EErrIdentifierTooLong,_S("PROC junk:\x2029 珑珑珑珑=3\x2029 ^骀骀骀骀

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?