|
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 "scriptfileprocessor.h" |
|
17 |
|
18 |
|
19 const TChar KDelimiter=0x0A; |
|
20 // |
|
21 //CScriptFileProcessor |
|
22 // |
|
23 |
|
24 CScriptFileProcessor* CScriptFileProcessor::NewLC(const TDesC& aScriptFile) |
|
25 { |
|
26 CScriptFileProcessor* self=new (ELeave)CScriptFileProcessor; |
|
27 CleanupStack::PushL(self); |
|
28 self->ConstructL(aScriptFile); |
|
29 return self; |
|
30 } |
|
31 |
|
32 |
|
33 CScriptFileProcessor* CScriptFileProcessor::NewL(const TDesC& aScriptFile) |
|
34 { |
|
35 CScriptFileProcessor* self=CScriptFileProcessor::NewLC(aScriptFile); |
|
36 CleanupStack::Pop(self); |
|
37 return self; |
|
38 } |
|
39 |
|
40 void CScriptFileProcessor::ConstructL(const TDesC& aScriptFile) |
|
41 { |
|
42 User::LeaveIfError(iFSession.Connect()); |
|
43 User::LeaveIfError(iFile.Open(iFSession, aScriptFile, EFileRead)); |
|
44 iFileReadStream.Attach(iFile); |
|
45 } |
|
46 |
|
47 CScriptFileProcessor::CScriptFileProcessor() |
|
48 { |
|
49 } |
|
50 CScriptFileProcessor::~CScriptFileProcessor() |
|
51 { |
|
52 iFile.Close(); |
|
53 iFileReadStream.Close(); |
|
54 iFSession.Close(); |
|
55 } |
|
56 |
|
57 // |
|
58 //DataDirection |
|
59 // |
|
60 |
|
61 CScriptFileProcessor::TDataDirection CScriptFileProcessor::DataDirection() const |
|
62 { |
|
63 return iDataDirection; |
|
64 } |
|
65 |
|
66 // |
|
67 //ProcessLine |
|
68 // |
|
69 |
|
70 TInt CScriptFileProcessor::ProcessLine(TDes8& aLine) |
|
71 { |
|
72 |
|
73 //get the direction of the data |
|
74 const TInt KSpecifierLength=3; |
|
75 _LIT8(KFromServer,"<< "); |
|
76 _LIT8(KFromClient,">> "); |
|
77 |
|
78 //if the data is from the server then the specifier should be at the begining of the line |
|
79 TInt pos; |
|
80 pos=aLine.Find(KFromServer); |
|
81 if(pos==0) |
|
82 { |
|
83 iDataDirection=EFromServer; |
|
84 } |
|
85 else |
|
86 { |
|
87 //if the data is from the client then the specifier should be at the begining of the line |
|
88 pos=aLine.Find(KFromClient); |
|
89 if(pos==0) |
|
90 { |
|
91 iDataDirection=EFromClient; |
|
92 } |
|
93 else |
|
94 { |
|
95 //there has been an error, the spefifier was not found |
|
96 return KErrNotFound; |
|
97 } |
|
98 } |
|
99 |
|
100 //trim the specifier from the start of the line |
|
101 aLine=aLine.Right(aLine.Length()-KSpecifierLength); |
|
102 //trim off trailing \r\n |
|
103 aLine.TrimRight(); |
|
104 |
|
105 return KErrNone; |
|
106 } |
|
107 |
|
108 // |
|
109 //ReadLine |
|
110 // |
|
111 |
|
112 TInt CScriptFileProcessor::ReadLine(TDes8& aLine) |
|
113 { |
|
114 |
|
115 aLine.Zero(); |
|
116 //read the line |
|
117 TRAPD(err, iFileReadStream.ReadL(aLine, KDelimiter)); |
|
118 if (err != KErrNone) |
|
119 { |
|
120 return err; |
|
121 } |
|
122 //process the line |
|
123 err=ProcessLine(aLine); |
|
124 |
|
125 // Haven't reached end of the file yet |
|
126 return err; |
|
127 } |
|
128 |