summaryrefslogtreecommitdiff
path: root/symbian/PerlRecog.cpp
blob: d2db54491b671549fd316b0026b73d05e6cefde5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* Copyright (c) 2004-2005 Nokia. All rights reserved. */
 
/* The PerlRecog application is licensed under the same terms as Perl itself. */

#include <apmrec.h>
#include <apmstd.h>
#include <f32file.h>

const TUid KUidPerlRecog = { 0x102015F7 };
_LIT8(KPerlMimeType, "x-application/x-perl");
_LIT8(KPerlSig, "#!/usr/bin/perl");
const TInt KPerlSigLen = 15;

class CApaPerlRecognizer : public CApaDataRecognizerType {
  public:
    CApaPerlRecognizer():CApaDataRecognizerType(KUidPerlRecog, EHigh) {
        iCountDataTypes = 1;
    }
    virtual TUint PreferredBufSize() { return KPerlSigLen; }
    virtual TDataType SupportedDataTypeL(TInt /* aIndex */) const {
        return TDataType(KPerlMimeType);
    }
  private:
    virtual void DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer);
};

void CApaPerlRecognizer::DoRecognizeL(const TDesC& aName, const TDesC8& aBuffer)
{
    iConfidence = ENotRecognized;

    if (aBuffer.Length() >= KPerlSigLen &&
        aBuffer.Left(KPerlSigLen).Compare(KPerlSig) == 0) {
        iConfidence = ECertain;
        iDataType   = TDataType(KPerlMimeType);
    } else {
        TParsePtrC p(aName);

        if ((p.Ext().CompareF(_L(".pl"))  == 0) ||
            (p.Ext().CompareF(_L(".pm"))  == 0)) {
            iConfidence = ECertain;
            iDataType = TDataType(KPerlMimeType);
        }
    }
}

EXPORT_C CApaDataRecognizerType* CreateRecognizer()
{
    return new CApaPerlRecognizer;
}

GLDEF_C TInt E32Dll(TDllReason /* aReason */)
{
    return KErrNone;
}