|
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 * Defines the entry point for the console application |
|
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 "Cdl2Lag.h" |
|
25 #include "LayoutCompilerErr.h" |
|
26 #include "CodeGenConsts.h" |
|
27 #include <fstream> |
|
28 using namespace std; |
|
29 using namespace CdlCompilerToolkit; |
|
30 |
|
31 typedef LayoutProcessArgsErr<CdlToLag> CdlToLagArgsErr; |
|
32 |
|
33 |
|
34 CdlToLag::CdlToLag(ofstream& aLag, const string& aLagName) |
|
35 : iLag(aLag), iLagName(aLagName) |
|
36 { |
|
37 } |
|
38 |
|
39 int CdlToLag::Process(const vector<string>& args) |
|
40 { |
|
41 if (args.size() < 4) |
|
42 throw CdlToLagArgsErr(); |
|
43 |
|
44 string lagName = args[2]; |
|
45 ofstream lag; |
|
46 CCdlTkFileCleanup temp; |
|
47 CdlTkUtil::OpenTempOutput(lag, temp); |
|
48 |
|
49 CdlToLag process(lag, lagName); |
|
50 process.Start(); |
|
51 |
|
52 for (int ii = 3; ii < args.size(); ii++) |
|
53 { |
|
54 string cdlName = args[ii]; |
|
55 CCdlTkCdlFileParser parser(cdlName); |
|
56 auto_ptr<CCdlTkInterface> iface(parser.LoadAndParse(true)); |
|
57 process.AddInterface(*iface); |
|
58 } |
|
59 |
|
60 process.Finish(); |
|
61 |
|
62 lag.close(); |
|
63 CdlTkUtil::ExportFile(temp, KDirEpocSysHeader+CdlTkUtil::StripPath(lagName)); |
|
64 |
|
65 return 0; |
|
66 } |
|
67 |
|
68 void CdlToLag::ShowHelp(ostream& stream) |
|
69 { |
|
70 stream << "Cdl2Lag <lagName> <CdlNames>" << endl; |
|
71 } |
|
72 |
|
73 void CdlToLag::Start() |
|
74 { |
|
75 WriteHeader(); |
|
76 } |
|
77 |
|
78 void CdlToLag::Finish() |
|
79 { |
|
80 WriteFooter(); |
|
81 } |
|
82 |
|
83 void CdlToLag::AddInterface(CCdlTkInterface& aInterface) |
|
84 { |
|
85 iInterface = &aInterface; |
|
86 WriteInclude(); |
|
87 CCdlTkApiList& list = iInterface->ApiList(); |
|
88 for (CCdlTkApiList::iterator pApi = list.begin(); pApi != list.end(); ++pApi) |
|
89 { |
|
90 WriteMacro(**pApi); |
|
91 } |
|
92 } |
|
93 |
|
94 void CdlToLag::WriteHeader() |
|
95 { |
|
96 iLag << "// " << iLagName << " generated by:" << endl; |
|
97 iLag << "// " << CdlTkUtil::CommandLine() << endl; |
|
98 string guardName = CdlTkUtil::ToUpper(CdlTkUtil::ToCpp(CdlTkUtil::StripPath(iLagName))); |
|
99 iLag << "#if !defined(" << guardName << ")" << endl; |
|
100 iLag << "#define " << guardName << endl; |
|
101 } |
|
102 |
|
103 void CdlToLag::WriteInclude() |
|
104 { |
|
105 iLag << "#include <" << CdlTkUtil::StripPath(iInterface->FileName()) << ".h>" << endl; |
|
106 } |
|
107 |
|
108 void CdlToLag::WriteMacro(CCdlTkApi& aApi) |
|
109 { |
|
110 string macro = "#define "; |
|
111 const string& name = aApi.Name(); |
|
112 string macroName = name; |
|
113 if (aApi.IsFunc() && aApi.AsFunc().Params().size() && aApi.AsFunc().Params()[0].Name() == KParamLineIndex) |
|
114 { |
|
115 macro += "AKN_LAYOUT_TABLE_"; |
|
116 } |
|
117 else if (aApi.ReturnType() == KTypeWindowLineLayout) |
|
118 { |
|
119 macro += "AKN_LAYOUT_WINDOW_"; |
|
120 } |
|
121 else if (aApi.ReturnType() == KTypeTextLineLayout) |
|
122 { |
|
123 macro += "AKN_LAYOUT_TEXT_"; |
|
124 } |
|
125 else if (aApi.ReturnType() == KTypeLayoutTableLimits) |
|
126 { |
|
127 macro += "AKN_LAYOUT_TABLE_LIMITS_"; |
|
128 } |
|
129 else |
|
130 { |
|
131 macro += "AKN_LAYOUT_MULTILINE_TEXT_"; |
|
132 macroName = macroName.substr(KFuncMultiline.length()); // remove "Multiline_" |
|
133 } |
|
134 |
|
135 macro += macroName + " " + iInterface->NamespaceName() + "::" + name; |
|
136 if (aApi.AsFunc().Params().size() == 0) // was once data only API |
|
137 macro += "()"; |
|
138 |
|
139 iLag << macro << endl; |
|
140 } |
|
141 |
|
142 void CdlToLag::WriteFooter() |
|
143 { |
|
144 iLag << "#endif" << endl; |
|
145 } |