opl16gen.cpp
来自「在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己」· C++ 代码 · 共 2,125 行 · 第 1/5 页
CPP
2,125 行
EgIdentity=0x2B,
EgX=0x2C,
EgY=0x2D,
EgWidth=0x2E,
EgHeight=0x2F,
EgOriginX=0x30,
EgOriginY=0x31,
EgTWidth=0x32,
EgPrintClip=0x33,
ETestEvent=0x34,
EOs=0x35,
EMenu=0x36,
EDialog=0x37,
EAlert=0x38,
EGreyCreate=0x39,
EMenuX=0x3A,
ECreateSprite=0x3B,
ELoadLib=0x3C,
EUnloadLib=0x3D,
EFindLib=0x3E,
EGetLibH=0x3F,
EDays=0x40,
EIAbs=0x41,
EInt=0x42,
EPeekL=0x43,
ESpace=0x44,
EDateToSecs=0x45,
ENewObj=0x46,
ENewObjH=0x47,
ESend=0x48,
EEnterSend=0x49,
EEnterSend0=0x4A,
EAlloc=0x4B,
EReAlloc=0x4C,
EAdjustAlloc=0x4D,
ELenAlloc=0x4E,
EIoc=0x4F,
EUAdd=0x50,
EUSub=0x51,
EIoCancel=0x52,
EStatWinInfo=0x53,
EFindField=0x54,
EBookMark=0x55,
EGetEventC=0x56,
EInTrans=0x57,
EMPopup=0x58,
EAbs=0x80,
EACos=0x81,
EASin=0x82,
EATan=0x83,
ECos=0x84,
EDeg=0x85,
EExp=0x86,
EFlt=0x87,
EIntF=0x88,
ELn=0x89,
ELog=0x8A,
EPeekF=0x8B,
EPi=0x8C,
ERad=0x8D,
ERnd=0x8E,
ESin=0x8F,
ESqr=0x90,
ETan=0x91,
EVal=0x92,
EMax=0x93,
EMean=0x94,
EMin=0x95,
EStd=0x96,
ESum=0x97,
EVar=0x98,
EEval=0x99,
EChrS=0xC0,
EDatim=0xC1,
EDayNameS=0xC2,
EDirS=0xC3,
EErrS=0xC4,
EFixS=0xC5,
EGenS=0xC6,
EGetS=0xC7,
EHexS=0xC8,
EKeyS=0xC9,
ELeftS=0xCA,
ELowerS=0xCB,
EMidS=0xCC,
EMonthS=0xCD,
ENumS=0xCE,
EPeekS=0xCF,
EReptS=0xD0,
ERightS=0xD1,
ESciS=0xD2,
EUpperS=0xD3,
EUserS=0xD4,
EGetCmdS=0xD5,
ECmdS=0xD6,
EParseS=0xD7,
EErrxS=0xD8,
EGetDocS=0xD9,
ESize=0xDA
};
void ExternalizeL(RWriteStream& aStream) const;
private:
TUint iCode;
};
void TQcode16::ExternalizeL(RWriteStream& aStream) const
//
// Adds the Qcode to the stream
//
{
TInt code=iCode;
if (code&KOpl16ExtendedQcodeFlag)
{
code&=~KOpl16ExtendedQcodeFlag;
aStream.WriteUint8L(EExtended);
}
aStream.WriteUint8L(code);
}
/////////////////////////////////////////////////////////////////
//
// TLbc - class for externalizing descriptors to E16 Lbcs
//
/////////////////////////////////////////////////////////////////
class TLbc
{
public:
TLbc(const TDesC& aDes) : iDes(aDes) {}
void ExternalizeL(RWriteStream& aStream) const;
private:
const TDesC& iDes;
};
void TLbc::ExternalizeL(RWriteStream& aStream) const
//
// Adds the Lbc to the stream
//
{
TUint len=iDes.Length();
if (len>TInt(KMaxTUint8))
User::Leave(EErrBadStringLength);
// Write the len as 16-bit, even though only 8 bits are used for the length.
aStream.WriteUint16L(len);
// Just to avoid 256 bytes on the stack
TBuf8<KMaxTUint8*sizeof(TText)> *tempBuf=new(ELeave) TBuf8<KMaxTUint8*sizeof(TText)>;
CleanupStack::PushL(tempBuf);
TUint8* d=(TUint8*)tempBuf->Ptr();
TUint16* s=(TUint16*)iDes.Ptr();
for(TUint i=0;i<len;++i)
{
TUint16 c=*s++;
*d++=(TUint8)(c&0xff);
*d++=(TUint8)(c>>8);
}
aStream.WriteL(tempBuf->Ptr(),len<<1);
CleanupStack::PopAndDestroy();
// format: len pad lo0 hi0 lo1 hi1 ... LenInBytes
}
GLDEF_C void Panic(TOpl16BackEndPanic aPanicNumber)
//
// Panic which identifies that it came from OPL16 back end
//
{
_LIT(KOpltPanic,"OPL16 Backend");
User::Panic(KOpltPanic,aPanicNumber);
}
///////////////////////////////////////////////////////////////////////
//
// COpl16App : App parsing
//
///////////////////////////////////////////////////////////////////////
// Real maximum sizes
const TInt KOpl16AppMaxExtLen=3;
const TInt KOpl16AppMaxNameLen=8;
const TInt KOpl16AppMaxPathLen=19;
// Size of the data in the file - includes zero terminators
const TInt KOpl16AppNameExtBufLen=14;
const TInt KOpl16AppPathBufLen=20;
const TInt KOpl16AppDataLen=KOpl16AppNameExtBufLen+KOpl16AppPathBufLen+sizeof(TUint16); // Total size of data in the file.
const TInt KOpl16AppMaxIconSize=KMaxTInt16;
const TUint KOpl16AppSupportsNewFile=0x0001; // App not in Shell's new file list
const TUint KOpl16AppIsHidden=0x0002; // App not in Extras bar etc
const TUint KOpl16AppFlagsMask=KOpl16AppSupportsNewFile|KOpl16AppIsHidden;
const TUint KOpl16AppNameFlag=0x00000001;
const TUint KOpl16AppTypeFlag=0x00000002;
const TUint KOpl16AppExtFlag =0x00000004;
const TUint KOpl16AppPathFlag=0x00000008;
const TUint KOpl16AppIconFlag=0x00000010;
const TUint KOpl16AppCaptionFlag=0x00000020;
const TUint KOpl16MaxIconReadBufSize=0x400; // 1K - plenty big enough for most ICON files
class COpl16App : public COplParseApp
{
public:
void ParseL(COpl16ModuleBackEnd& aBackEnd,TBool aLocatingError);
private:
friend class COpl16ModuleBackEnd;
friend class COpl16Opl1993BackEnd;
friend class COpl16Opler1BackEnd;
COpl16App(TOplTranTarget aTarget,COplLexerBase& aLexer);
inline TUint Flags() const {return iFlags;}
inline TUint Type() const { return iType;}
inline TInt32 Id() const {return iD;}
inline TFileName& IconFile() { return iIconName;}
inline TDes& NameAndExt() { return iNameAndExt;}
inline TInt MaxNameAndExtLength() { return iMaxNameAndExtLength;}
inline TDes& Path() { return iPath;}
void TestFlagTokenAndTypeL(TUint aFlag,TOplToken aToken,TOplToken::TType aType);
const CCnvCharacterSetConverter* LoadUnicodeConverterLC();
void FromUnicodeL(TPtrC16& aUnicode,TPtr8& aNarrow);
private:
TOplTranTarget iTarget;
TInt32 iD;
TUint iType;
TUint iFlags; // flag what's been done already
COplLexerBase& iLexer;
TApaAppCaption iNameAndExt;
TInt iMaxNameAndExtLength; // more allowed on Opler1
TBuf<KOpl16AppPathBufLen> iPath;
TFileName iIconName;
TBool iNormalFlag; // opler1 only
};
void COpl16App::ParseL(COpl16ModuleBackEnd& aBackEnd,TBool aLocatingError)
//
// Only public method - does the parsing and generates AIF file for opler1 apps
//
// AppDefinition:= APP appName opler1-stuff EOS
// [app-entry EOS]*
// ENDA EOS
//
// opler1-stuff := // NULL for OPL1993 machines
// | , long-integer // , APP UID on Opler1
//
// app-entry:= [TYPE number] |
// [EXT string-constant] |
// [ICON icon file ] |
// [PATH pathdetails] |
// [CAPTION captioninfo] |
// [MIME priority,datatype]
//
// There is a semantic rule that says TYPE, EXT, PATH may only appear once.
// But ICON can appear more than once on Opler1, where the filename is an MBM
// The MIME entry can also occur more than once.
//
{
TInt maxNameLength=KApaMaxAppCaption; // assume Opler1
if (iTarget==EOplTargetER1)
iMaxNameAndExtLength=KApaMaxAppCaption;
else
{
maxNameLength=KOpl16AppMaxNameLen;
iMaxNameAndExtLength=KOpl16AppNameExtBufLen;
}
// APP appName [opler1-stuff] EOS //
TestFlagTokenAndTypeL(KOpl16AppNameFlag,TOplToken::ESimple,TOplToken::EReal);
TPtrC name=iLexer.MarkedToken(); // Get it raw as case is significant
if (name.Length()>maxNameLength)
User::Leave(EErrBadStringLength);
iNameAndExt.Insert(0,name);
// opler1-stuff
CApaAppInfoFileWriter* appInfoFileWriter=NULL;
TApaAppCapability capability;
capability.iSupportsNewFile=EFalse; // doesn't support new files by default
capability.iEmbeddability=TApaAppCapability::ENotEmbeddable;
capability.iAppIsHidden=EFalse; // not hidden by default
TParse aifName;
RFs fs;
User::LeaveIfError(fs.Connect());
CleanupClosePushL(fs);
if (iTarget==EOplTargetER1)
{
iLexer.LexL(TOplToken::EComma);
iLexer.LexL(TOplToken::EConstant);
iD=iLexer.Constant().AsLongL();
aifName.SetNoWild(KAppInfoFileExtension,&(aBackEnd.OutputName()),NULL); // path same as APP
appInfoFileWriter=CApaAppInfoFileWriter::NewLC(fs,aifName.FullName(),TUid::Uid(iD));
}
// EOS
iLexer.LexL(TOplToken::EEos);
// [app-entry EOS]*
// ENDA EOS
TBool iconSeen=EFalse;
CApaMaskedBitmap* maskedBitmap=NULL;
TBool bitmapOnCleanup=EFalse;
for (TBool endSeen=EFalse;!endSeen;)
{
// app-entry | ENDA
TOplToken next;
do
{
next=iLexer.LexL();
} while (next==TOplToken::EEos);
switch (next)
{
case TOplToken::EFlags: // same as TYPE but for Opler1
TestFlagTokenAndTypeL(KOpl16AppTypeFlag,TOplToken::EConstant,TOplToken::EWord);
iType=iLexer.Constant().AsWordL();
if (!iType || (iType & (~KOpl16AppFlagsMask)))
User::Leave(EErrSyntax);
capability.iSupportsNewFile=iType&KOpl16AppSupportsNewFile;
capability.iAppIsHidden=iType&KOpl16AppIsHidden;
break;
case TOplToken::EType:
TestFlagTokenAndTypeL(KOpl16AppTypeFlag,TOplToken::EConstant,TOplToken::EWord);
iType=iLexer.Constant().AsWordL();
break;
case TOplToken::EExt:
{ // because of declaration of 'ext'
TestFlagTokenAndTypeL(KOpl16AppExtFlag,TOplToken::EConstant,TOplToken::EString);
TPtrC ext=iLexer.Constant().AsStringL();
if (ext.Length()>KOpl16AppMaxExtLen)
User::Leave(EErrBadStringLength);
iNameAndExt.Append('.');
iNameAndExt.Append(ext); // !! - AppendF ??
iNameAndExt.UpperCase();
}
break;
case TOplToken::ECaption:
{
TestFlagTokenAndTypeL(0,TOplToken::EConstant,TOplToken::EString);
iFlags|=KOpl16AppCaptionFlag;
TPtrC capt=iLexer.Constant().AsStringL();
if (capt.Length()>maxNameLength)
User::Leave(EErrBadStringLength);
TApaAppCaption captBuf=capt;
iLexer.LexL(TOplToken::EComma);
iLexer.LexL(TOplToken::EConstant);
if (iLexer.Type()!=TOplToken::EWord)
User::Leave(EErrSyntax);
TLanguage lang=TLanguage(iLexer.Constant().AsWordL());
if (aLocatingError)
break;
appInfoFileWriter->AddCaptionL(lang,captBuf);
}
break;
case TOplToken::EMime:
{ // MIME priority, Type
TestFlagTokenAndTypeL(0,TOplToken::EConstant,TOplToken::EWord);
TDataTypePriority priority=iLexer.Constant().AsWordL();
iLexer.LexL(TOplToken::EComma);
iLexer.LexL(TOplToken::EConstant);
// Convert to 8-bit for TDataType
TPtrC mime16=iLexer.Constant().AsStringL();
TInt len=mime16.Length(); // in characters.
TPtr8 mime((TText8*)User::AllocLC(len),len);
FromUnicodeL(mime16,mime);
if (mime.Length()==0) // length of narrow string
User::Leave(EErrSyntax);
if (mime.Length()>KMaxDataTypeLength)
User::Leave(EErrBadStringLength);
TDataTypeWithPriority dataType(mime,priority);
appInfoFileWriter->AddDataTypeL(dataType);
CleanupStack::PopAndDestroy(); // mime string
}
break;
case TOplToken::EIcon:
{
iconSeen=ETrue;
// hp: don't restrict to one icon file for Opler1
TUint flag=0;
if (iTarget!=EOplTargetER1)
flag=KOpl16AppIconFlag;
TestFlagTokenAndTypeL(flag,TOplToken::EConstant,TOplToken::EString);
TFileName fileName=iLexer.Constant().AsStringL();
if (fileName.Length()>KMaxFileName)
User::Leave(EErrBadStringLength);
if (flag) // if Opl1993
{
iIconName.Copy(fileName);
break;
}
// definitely Opler1 if reaches here
if (aLocatingError)
break;
TInt err;
TInt index=0;
COpl16Opler1BackEnd& opler1BackEnd=STATIC_CAST(COpl16Opler1BackEnd&,aBackEnd);
TParse parser;
parser.Set(fileName,opler1BackEnd.SourceName(),NULL);
fileName=parser.FullName();
iIconName.Copy(fileName);
FOREVER
{
if (iNormalFlag) // doing normal
{
maskedBitmap=CApaMaskedBitmap::NewLC();
err=maskedBitmap->Load(fileName,index++);
if (err!=KErrEof)
bitmapOnCleanup=ETrue;
else
{
// failed to load bitmap from this file
CleanupStack::PopAndDestroy();
bitmapOnCleanup=EFalse;
break;
}
if (err)
User::Leave(err);
iNormalFlag=EFalse;
}
else
{
err=(maskedBitmap->Mask())->Load(fileName,index++);
if (err==KErrEof)
break; // failed to load mask from this file
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?