|
1 /* |
|
2 * Copyright (c) 2002-2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // disable "identifier was truncated to '255' characters in the browser information" warning |
|
22 #pragma warning (disable:4786) |
|
23 |
|
24 #include "Script.h" |
|
25 #include "LayoutCompilerErr.h" |
|
26 #include <iostream> |
|
27 #include <fstream> |
|
28 using namespace std; |
|
29 using namespace CdlCompilerToolkit; |
|
30 |
|
31 typedef LayoutProcessArgsErr<AknLayoutCompilerScript> AknLayoutCompilerScriptArgsErr; |
|
32 |
|
33 |
|
34 class ScriptErr : public LayoutCompilerErr |
|
35 { |
|
36 public: |
|
37 ScriptErr(const string& aLine, const string& aMsg) : iLine(aLine), iMsg(aMsg) {} |
|
38 private: |
|
39 void Show(ostream& aStream) const; |
|
40 private: |
|
41 string iLine; |
|
42 string iMsg; |
|
43 }; |
|
44 |
|
45 void ScriptErr::Show(ostream& aStream) const |
|
46 { |
|
47 aStream << iLine << endl; |
|
48 aStream << iMsg << endl; |
|
49 } |
|
50 |
|
51 |
|
52 int AknLayoutCompilerScript::Process(const vector<string>& args) |
|
53 { |
|
54 if (args.size() != 2) |
|
55 throw AknLayoutCompilerScriptArgsErr(); |
|
56 |
|
57 ifstream in; |
|
58 CdlTkUtil::OpenInput(in, args[1].substr(1)); |
|
59 |
|
60 AknLayoutCompilerScript script(in); |
|
61 script.Process(); |
|
62 |
|
63 in.close(); |
|
64 |
|
65 return 0; |
|
66 } |
|
67 |
|
68 void AknLayoutCompilerScript::ShowHelp(ostream& /*stream*/) |
|
69 { |
|
70 } |
|
71 |
|
72 AknLayoutCompilerScript::AknLayoutCompilerScript(istream& aIn) |
|
73 : iIn(aIn) |
|
74 { |
|
75 } |
|
76 |
|
77 void AknLayoutCompilerScript::Process() |
|
78 { |
|
79 // while (!iIn.eof()) |
|
80 // { |
|
81 // string line; |
|
82 // getline(iIn, line); |
|
83 // ProcessLine(line); |
|
84 // } |
|
85 } |
|
86 |
|
87 void AknLayoutCompilerScript::ProcessLine(string& aLine) |
|
88 { |
|
89 CdlTkUtil::StripLeadingAndTrailingWhitespace(aLine); |
|
90 if (aLine.empty()) |
|
91 return; |
|
92 |
|
93 int paramStart = aLine.find_first_of('('); |
|
94 int paramEnd = aLine.find_first_of(')'); |
|
95 if (paramStart == string::npos || paramEnd == string::npos) |
|
96 throw ScriptErr(aLine, "Must be of form \"[result=] func(params)\""); |
|
97 |
|
98 int eqPos = aLine.find_first_of('='); |
|
99 string result; |
|
100 if (eqPos > 0) |
|
101 { |
|
102 result = aLine.substr(0, eqPos-1); |
|
103 CdlTkUtil::StripLeadingAndTrailingWhitespace(result); |
|
104 } |
|
105 |
|
106 string func = aLine.substr(eqPos+1, paramStart-(eqPos+1)); |
|
107 CdlTkUtil::StripLeadingAndTrailingWhitespace(func); |
|
108 func = CdlTkUtil::ToLower(func); |
|
109 |
|
110 paramStart++; |
|
111 string params = aLine.substr(paramStart, paramEnd-paramStart); |
|
112 vector<string> paramList; |
|
113 int p = 0; |
|
114 while (p != string::npos) |
|
115 { |
|
116 int n = params.find_first_of(','); |
|
117 string param(params.substr(0, n)); |
|
118 CdlTkUtil::StripLeadingAndTrailingWhitespace(param); |
|
119 if (param.size()) |
|
120 paramList.push_back(param); |
|
121 p = n; |
|
122 if (p!=string::npos) |
|
123 params = params.substr(p+1); |
|
124 } |
|
125 |
|
126 Process(func, paramList, result); |
|
127 } |
|
128 |
|
129 void AknLayoutCompilerScript::Process(const string& aFunc, const vector<string>& aParamList, const string& aResult) |
|
130 { |
|
131 // use a map of name -> name, type and value |
|
132 cout << aFunc << "[" << aParamList.size() << "|" << aResult << "]" << endl; |
|
133 } |