|
1 /* |
|
2 * Copyright (c) 2006 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: Implementation of MifToCdlIndex tool. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // disable "identifier was truncated to '255' characters in the browser information" warning |
|
21 #pragma warning (disable:4786) |
|
22 |
|
23 // disable "decorated name length exceeded, name was truncated" warning |
|
24 #pragma warning (disable:4503) |
|
25 |
|
26 |
|
27 #include <string> |
|
28 #include <vector> |
|
29 #include <algorithm> |
|
30 #include <iostream> |
|
31 #include <CdlCompilerToolkit/CdlTkUtil.h> |
|
32 #include "MifHandler.h" |
|
33 #include "DllCreator.h" |
|
34 |
|
35 using namespace std; |
|
36 using namespace CdlCompilerToolkit; |
|
37 |
|
38 |
|
39 // In debug builds, we want the debugger to catch exceptions. In release mode we want |
|
40 // to report exceptions to the command line user. |
|
41 // The EXCEPTION_HANDLING macro flag controls this behavior in main() |
|
42 #ifndef _DEBUG |
|
43 #define EXCEPTION_HANDLING |
|
44 #endif |
|
45 |
|
46 class MainArgsErr : public CdlCompilerToolkitErr |
|
47 { |
|
48 void Show(ostream& aStream) const; |
|
49 }; |
|
50 |
|
51 void MainArgsErr::Show(ostream& stream) const |
|
52 { |
|
53 stream << endl; |
|
54 stream << "MifToCdlIndex [<options>] <MifFile> <DllName> <DllUid>" << endl; |
|
55 stream << " <options> are:" << endl; |
|
56 stream << " -p<output path>" << endl; |
|
57 stream << " -s write instance source code only, no DLL source" << endl; |
|
58 } |
|
59 |
|
60 int DoMain(int argc, char* argv[]) |
|
61 { |
|
62 CdlTkUtil::SetCommandLine(argc, argv); |
|
63 |
|
64 vector<string> args; |
|
65 copy(argv, argv+argc, back_inserter(args)); |
|
66 |
|
67 if (args.size() < 2) |
|
68 { |
|
69 throw MainArgsErr(); |
|
70 } |
|
71 |
|
72 args.erase(args.begin()); |
|
73 |
|
74 bool writeDll = true; |
|
75 while (args[0].size() >= 2 && args[0][0] == '-') |
|
76 { |
|
77 switch (args[0][1]) |
|
78 { |
|
79 case 'p': |
|
80 CdlTkUtil::SetOutputPath(args[0].substr(2)); |
|
81 break; |
|
82 |
|
83 case 's': |
|
84 writeDll = false; |
|
85 break; |
|
86 |
|
87 default: |
|
88 throw MainArgsErr(); |
|
89 break; |
|
90 } |
|
91 |
|
92 args.erase(args.begin()); |
|
93 } |
|
94 |
|
95 if (args.size() != 3) |
|
96 { |
|
97 throw MainArgsErr(); |
|
98 } |
|
99 |
|
100 string& mifName = args[0]; |
|
101 string& dllName = args[1]; |
|
102 string& dllUid = args[2]; |
|
103 |
|
104 MifHandler mif; |
|
105 mif.Read(mifName); |
|
106 const MifIndex& index = mif.Index(); |
|
107 mif.Modify(dllUid); |
|
108 mif.Write(mifName); |
|
109 |
|
110 DllCreator dll; |
|
111 dll.SetNameAndUid(dllName, dllUid); |
|
112 dll.SetIndex(index); |
|
113 dll.WriteSource(); |
|
114 if (writeDll) |
|
115 dll.WriteDll(); |
|
116 |
|
117 return 0; |
|
118 } |
|
119 |
|
120 |
|
121 int main(int argc, char* argv[]) |
|
122 { |
|
123 #ifdef EXCEPTION_HANDLING |
|
124 try |
|
125 { |
|
126 #endif |
|
127 return DoMain(argc, argv); |
|
128 #ifdef EXCEPTION_HANDLING |
|
129 } |
|
130 catch (const CdlCompilerToolkitErr& aErr) |
|
131 { |
|
132 aErr.Show(cerr); |
|
133 } |
|
134 |
|
135 return 0; |
|
136 #endif |
|
137 } |