| 1 |
// RexxFileRecognizer.cpp |
| 2 |
// |
| 3 |
// Copyright (c) 1997-1999 Symbian Ltd. All rights reserved. |
| 4 |
// Copyright (c) 2001 Mark Hessling |
| 5 |
// |
| 6 |
|
| 7 |
#include <apmrec.h> |
| 8 |
#include <apmstd.h> |
| 9 |
#include "RexxFileRecognizer.h" |
| 10 |
|
| 11 |
const TInt KMimeRexxRecognizerValue=0x101F401F; |
| 12 |
const TUid KUidMimeRexxRecognizer={0x101F401F}; |
| 13 |
const TInt KMinBufferLength=42; // minimum amount of file needed to determine a text file IF it's not called .TXT |
| 14 |
const TInt KMaxBufferLength=1024; // maximum amount of buffer space we will ever use |
| 15 |
_LIT8(KDataTypeTextRexx,"text/rexx"); |
| 16 |
|
| 17 |
CApaTextRecognizer::CApaTextRecognizer() |
| 18 |
:CApaDataRecognizerType(KUidMimeRexxRecognizer,CApaDataRecognizerType::ELow) |
| 19 |
// Rexx files are low recognition - they don't have a clear signature |
| 20 |
{ |
| 21 |
iCountDataTypes=1; |
| 22 |
} |
| 23 |
|
| 24 |
TUint CApaTextRecognizer::PreferredBufSize() |
| 25 |
{ |
| 26 |
return KMaxBufferLength; |
| 27 |
} |
| 28 |
|
| 29 |
TDataType CApaTextRecognizer::SupportedDataTypeL(TInt aIndex) const |
| 30 |
{ |
| 31 |
__ASSERT_DEBUG(aIndex==0,User::Invariant()); |
| 32 |
return TDataType(KDataTypeTextRexx); |
| 33 |
} |
| 34 |
|
| 35 |
void CApaTextRecognizer::DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer) |
| 36 |
{ |
| 37 |
TBool nameRecognized = EFalse; |
| 38 |
TBool validChars = EFalse; |
| 39 |
TUint chr1,chr2; |
| 40 |
// Check file names |
| 41 |
if ( aName.Length() > 5 ) |
| 42 |
{ |
| 43 |
if ( aName.Right(5).CompareF(_L(".rexx")) == 0 ) |
| 44 |
nameRecognized = ETrue; |
| 45 |
} |
| 46 |
if ( aName.Length() > 4 && !nameRecognized ) |
| 47 |
{ |
| 48 |
if ( aName.Right(4).CompareF(_L(".rex")) == 0 ) |
| 49 |
nameRecognized = ETrue; |
| 50 |
} |
| 51 |
// Now determine if the file starts with a Rexx Comment |
| 52 |
TInt length = aBuffer.Length(); |
| 53 |
if (length < KMinBufferLength && !nameRecognized) |
| 54 |
return; |
| 55 |
|
| 56 |
chr1=aBuffer[0]; |
| 57 |
chr2=aBuffer[1]; |
| 58 |
if ( chr1 == '/' && chr2 == '*' ) |
| 59 |
validChars=ETrue; |
| 60 |
// Determine how confident we are that this is a Rexx program |
| 61 |
if ( !nameRecognized && !validChars ) |
| 62 |
return; |
| 63 |
if ( !nameRecognized && validChars ) |
| 64 |
iConfidence=EPossible; |
| 65 |
if ( nameRecognized && !validChars ) |
| 66 |
iConfidence=EProbable; |
| 67 |
if ( nameRecognized && validChars ) |
| 68 |
iConfidence = ECertain; |
| 69 |
iDataType = TDataType(KDataTypeTextRexx); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
EXPORT_C CApaDataRecognizerType* CreateRecognizer() |
| 75 |
// The gate function - ordinal 1 |
| 76 |
// |
| 77 |
{ |
| 78 |
CApaDataRecognizerType* thing=new CApaTextRecognizer(); |
| 79 |
return thing; // NULL if new failed |
| 80 |
} |
| 81 |
|
| 82 |
GLDEF_C TInt E32Dll(TDllReason /*aReason*/) |
| 83 |
// |
| 84 |
// DLL entry point |
| 85 |
// |
| 86 |
{ |
| 87 |
return KErrNone; |
| 88 |
} |