|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "cscriptfileprocessor.h" |
|
17 |
|
18 CScriptFileProcessor* CScriptFileProcessor::NewLC(const TDesC& aScriptFile) |
|
19 { |
|
20 CScriptFileProcessor* self=new (ELeave)CScriptFileProcessor; |
|
21 CleanupStack::PushL(self); |
|
22 self->ConstructL(aScriptFile); |
|
23 return self; |
|
24 } |
|
25 |
|
26 |
|
27 CScriptFileProcessor* CScriptFileProcessor::NewL(const TDesC& aScriptFile) |
|
28 { |
|
29 CScriptFileProcessor* self=CScriptFileProcessor::NewLC(aScriptFile); |
|
30 CleanupStack::Pop(self); |
|
31 return self; |
|
32 } |
|
33 |
|
34 void CScriptFileProcessor::ConstructL(const TDesC& aScriptFile) |
|
35 { |
|
36 User::LeaveIfError(iFSession.Connect()); |
|
37 User::LeaveIfError(iFile.Open(iFSession, aScriptFile, EFileRead)); |
|
38 iFileReadStream.Attach(iFile); |
|
39 } |
|
40 |
|
41 CScriptFileProcessor::CScriptFileProcessor() |
|
42 {//nothing to do here |
|
43 } |
|
44 |
|
45 CScriptFileProcessor::~CScriptFileProcessor() |
|
46 { |
|
47 iFile.Close(); |
|
48 iFileReadStream.Close(); |
|
49 iFSession.Close(); |
|
50 } |
|
51 |
|
52 CScriptFileProcessor::TDataDirection CScriptFileProcessor::DataDirection() const |
|
53 { |
|
54 return iDataDirection; |
|
55 } |
|
56 |
|
57 TInt CScriptFileProcessor::ProcessLine(TDes8& aLine) |
|
58 { |
|
59 //get the direction of the data |
|
60 const TInt KSpecifierLength=3; |
|
61 _LIT8(KFromServer,"<< "); |
|
62 _LIT8(KFromClient,">> "); |
|
63 |
|
64 //if the data is from the server then the line will contain "<<" else ">>" |
|
65 TInt pos; |
|
66 pos=aLine.Find(KFromServer); |
|
67 |
|
68 if(pos==KErrNotFound) |
|
69 { |
|
70 pos=aLine.Find(KFromClient); |
|
71 if(pos==KErrNotFound) |
|
72 { |
|
73 //there has been an error, the specifier was not found |
|
74 return KErrNotFound; |
|
75 } |
|
76 else |
|
77 { |
|
78 iDataDirection=EFromClient; |
|
79 } |
|
80 } |
|
81 else |
|
82 { |
|
83 iDataDirection=EFromServer; |
|
84 } |
|
85 |
|
86 //extract from the specifier to the end of the line |
|
87 aLine=aLine.Mid(KSpecifierLength+pos); |
|
88 //trim off trailing \r\n |
|
89 aLine.TrimRight(); |
|
90 return KErrNone; |
|
91 } |
|
92 |
|
93 |
|
94 TInt CScriptFileProcessor::ReadLine(TDes8& aLine) |
|
95 { |
|
96 aLine.Zero(); |
|
97 //new line |
|
98 const TChar KDelimiter=0x0A; |
|
99 //read the line |
|
100 TRAPD(err, iFileReadStream.ReadL(aLine, KDelimiter)); |
|
101 if (err == KErrNone) |
|
102 { |
|
103 err=ProcessLine(aLine); |
|
104 } |
|
105 return err; |
|
106 } |
|
107 |