Commit | Line | Data |
27da23d5 |
1 | /* Copyright (c) 2004-2005 Nokia. All rights reserved. */ |
2 | |
3 | /* The PerlRecog application is licensed under the same terms as Perl itself. */ |
4 | |
5 | #include <apmrec.h> |
6 | #include <apmstd.h> |
7 | #include <f32file.h> |
8 | |
9 | const TUid KUidPerlRecog = { 0x102015F7 }; |
10 | _LIT8(KPerlMimeType, "x-application/x-perl"); |
11 | _LIT8(KPerlSig, "#!/usr/bin/perl"); |
12 | const TInt KPerlSigLen = 15; |
13 | |
14 | class CApaPerlRecognizer : public CApaDataRecognizerType { |
15 | public: |
16 | CApaPerlRecognizer():CApaDataRecognizerType(KUidPerlRecog, EHigh) { |
17 | iCountDataTypes = 1; |
18 | } |
19 | virtual TUint PreferredBufSize() { return KPerlSigLen; } |
20 | virtual TDataType SupportedDataTypeL(TInt /* aIndex */) const { |
21 | return TDataType(KPerlMimeType); |
22 | } |
23 | private: |
24 | virtual void DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer); |
25 | }; |
26 | |
27 | void CApaPerlRecognizer::DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer) |
28 | { |
29 | iConfidence = ENotRecognized; |
30 | |
31 | if (aBuffer.Length() >= KPerlSigLen && |
32 | aBuffer.Left(KPerlSigLen).Compare(KPerlSig) == 0) { |
33 | iConfidence = ECertain; |
34 | iDataType = TDataType(KPerlMimeType); |
35 | } else { |
36 | TParsePtrC p(aName); |
37 | |
38 | if ((p.Ext().CompareF(_L(".pl")) == 0) || |
39 | (p.Ext().CompareF(_L(".pm")) == 0)) { |
40 | iConfidence = ECertain; |
41 | iDataType = TDataType(KPerlMimeType); |
42 | } |
43 | } |
44 | } |
45 | |
46 | EXPORT_C CApaDataRecognizerType* CreateRecognizer() |
47 | { |
48 | return new CApaPerlRecognizer; |
49 | } |
50 | |
51 | GLDEF_C TInt E32Dll(TDllReason /* aReason */) |
52 | { |
53 | return KErrNone; |
54 | } |
55 | |
56 | |
57 | |