|
1 // sbrec.cpp |
|
2 // |
|
3 // Copyright (c) 2007 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 // Description: |
|
14 // Recognizes files that begin with a "shebang" ("#!"). |
|
15 |
|
16 #include <e32debug.h> |
|
17 #include <apmrec.h> |
|
18 #include <apmstd.h> |
|
19 #include <implementationproxy.h> |
|
20 #include <fshell/common.mmh> |
|
21 #include "sbrec.h" |
|
22 |
|
23 |
|
24 // |
|
25 // Constants. |
|
26 // |
|
27 |
|
28 const TUid KShebangRecognizerUid = {FSHELL_UID_SBREC}; |
|
29 const TInt KShebangRecognizerImplementationUidValue = {0x102835C1}; |
|
30 _LIT8(KShebang, "#!"); |
|
31 _LIT8(KShebangDataType, "X-Symbian-Shebang"); |
|
32 |
|
33 #ifdef FSHELL_PATCHABLE_CONSTANTS_SUPPORT |
|
34 EXPORT_C extern const TBool KAutoStartFshell; // from patchdata.cpp |
|
35 #endif |
|
36 |
|
37 // |
|
38 // CShebangRecognizer. |
|
39 // |
|
40 |
|
41 CShebangRecognizer::CShebangRecognizer() |
|
42 : CApaDataRecognizerType(KShebangRecognizerUid, CApaDataRecognizerType::EHigh) |
|
43 { |
|
44 iCountDataTypes = 1; |
|
45 } |
|
46 |
|
47 TUint CShebangRecognizer::PreferredBufSize() |
|
48 { |
|
49 return 2; |
|
50 } |
|
51 |
|
52 TDataType CShebangRecognizer::SupportedDataTypeL(TInt /*aIndex*/) const |
|
53 { |
|
54 return TDataType(KShebangDataType); |
|
55 } |
|
56 |
|
57 void CShebangRecognizer::DoRecognizeL(const TDesC& /*aName*/, const TDesC8& aBuffer) |
|
58 { |
|
59 if ((aBuffer.Length() >= 2) && (aBuffer.Left(2) == KShebang)) |
|
60 { |
|
61 iDataType = TDataType(KShebangDataType); |
|
62 iConfidence = ECertain; |
|
63 } |
|
64 } |
|
65 |
|
66 CApaDataRecognizerType* CShebangRecognizer::CreateRecognizerL() |
|
67 { |
|
68 #ifdef FSHELL_PATCHABLE_CONSTANTS_SUPPORT |
|
69 if (KAutoStartFshell) |
|
70 { |
|
71 _LIT(KFshell, "fshell.exe"); |
|
72 _LIT(KArgs, "autostart.script"); |
|
73 RProcess proc; |
|
74 TInt err = proc.Create(KFshell, KArgs); |
|
75 if (err) |
|
76 { |
|
77 RDebug::Printf("Couldn't start fshell, err=%d", err); |
|
78 } |
|
79 else |
|
80 { |
|
81 proc.Resume(); |
|
82 proc.Close(); |
|
83 } |
|
84 } |
|
85 #endif |
|
86 return new (ELeave) CShebangRecognizer(); |
|
87 } |
|
88 |
|
89 |
|
90 // |
|
91 // ECOM boiler-plate. |
|
92 // |
|
93 |
|
94 const TImplementationProxy ImplementationTable[] = |
|
95 { |
|
96 IMPLEMENTATION_PROXY_ENTRY(KShebangRecognizerImplementationUidValue, CShebangRecognizer::CreateRecognizerL) |
|
97 }; |
|
98 |
|
99 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) |
|
100 { |
|
101 aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); |
|
102 return ImplementationTable; |
|
103 } |
|
104 |
|
105 GLDEF_C TInt E32Dll() |
|
106 { |
|
107 return KErrNone; |
|
108 } |