1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_codemaker.hxx"
26 #include <stdio.h>
27
28 #include "idloptions.hxx"
29
30 using namespace rtl;
31
initOptions(int ac,char * av[],sal_Bool bCmdFile)32 sal_Bool IdlOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile)
33 throw( IllegalArgument )
34 {
35 sal_Bool ret = sal_True;
36 sal_uInt16 i=0;
37
38 if (!bCmdFile)
39 {
40 bCmdFile = sal_True;
41
42 m_program = av[0];
43
44 if (ac < 2)
45 {
46 fprintf(stderr, "%s", prepareHelp().getStr());
47 ret = sal_False;
48 }
49
50 i = 1;
51 } else
52 {
53 i = 0;
54 }
55
56 char *s=NULL;
57 for (i; i < ac; i++)
58 {
59 if (av[i][0] == '-')
60 {
61 switch (av[i][1])
62 {
63 case 'O':
64 if (av[i][2] == '\0')
65 {
66 if (i < ac - 1 && av[i+1][0] != '-')
67 {
68 i++;
69 s = av[i];
70 } else
71 {
72 OString tmp("'-O', please check");
73 if (i <= ac - 1)
74 {
75 tmp += " your input '" + OString(av[i+1]) + "'";
76 }
77
78 throw IllegalArgument(tmp);
79 }
80 } else
81 {
82 s = av[i] + 2;
83 }
84
85 m_options["-O"] = OString(s);
86 break;
87 case 'B':
88 if (av[i][2] == '\0')
89 {
90 if (i < ac - 1 && av[i+1][0] != '-')
91 {
92 i++;
93 s = av[i];
94 } else
95 {
96 OString tmp("'-B', please check");
97 if (i <= ac - 1)
98 {
99 tmp += " your input '" + OString(av[i+1]) + "'";
100 }
101
102 throw IllegalArgument(tmp);
103 }
104 } else
105 {
106 s = av[i] + 2;
107 }
108
109 m_options["-B"] = OString(s);
110 break;
111 case 'T':
112 if (av[i][2] == '\0')
113 {
114 if (i < ac - 1 && av[i+1][0] != '-')
115 {
116 i++;
117 s = av[i];
118 } else
119 {
120 OString tmp("'-T', please check");
121 if (i <= ac - 1)
122 {
123 tmp += " your input '" + OString(av[i+1]) + "'";
124 }
125
126 throw IllegalArgument(tmp);
127 }
128 } else
129 {
130 s = av[i] + 2;
131 }
132
133 if (m_options.count("-T") > 0)
134 {
135 OString tmp(m_options["-T"]);
136 tmp = tmp + ";" + s;
137 m_options["-T"] = tmp;
138 } else
139 {
140 m_options["-T"] = OString(s);
141 }
142 break;
143 case 'G':
144 if (av[i][2] == 'c')
145 {
146 if (av[i][3] != '\0')
147 {
148 OString tmp("'-Gc', please check");
149 if (i <= ac - 1)
150 {
151 tmp += " your input '" + OString(av[i]) + "'";
152 }
153
154 throw IllegalArgument(tmp);
155 }
156
157 m_options["-Gc"] = OString("");
158 break;
159 } else
160 if (av[i][2] != '\0')
161 {
162 OString tmp("'-G', please check");
163 if (i <= ac - 1)
164 {
165 tmp += " your input '" + OString(av[i]) + "'";
166 }
167
168 throw IllegalArgument(tmp);
169 }
170
171 m_options["-G"] = OString("");
172 break;
173 default:
174 throw IllegalArgument("the option is unknown" + OString(av[i]));
175 break;
176 }
177 } else
178 {
179 if (av[i][0] == '@')
180 {
181 FILE* cmdFile = fopen(av[i]+1, "r");
182 if( cmdFile == NULL )
183 {
184 fprintf(stderr, "%s", prepareHelp().getStr());
185 ret = sal_False;
186 } else
187 {
188 int rargc=0;
189 char* rargv[512];
190 char buffer[512];
191
192 while ( fscanf(cmdFile, "%s", buffer) != EOF )
193 {
194 rargv[rargc]= strdup(buffer);
195 rargc++;
196 }
197 fclose(cmdFile);
198
199 ret = initOptions(rargc, rargv, bCmdFile);
200
201 for (long i=0; i < rargc; i++)
202 {
203 free(rargv[i]);
204 }
205 }
206 } else
207 {
208 m_inputFiles.push_back(av[i]);
209 }
210 }
211 }
212
213 return ret;
214 }
215
prepareHelp()216 OString IdlOptions::prepareHelp()
217 {
218 OString help("\nusing: ");
219 help += m_program + " [-options] file_1 ... file_n\nOptions:\n";
220 help += " -O<path> = path describes the root directory for the generated output.\n";
221 help += " The output directory tree is generated under this directory.\n";
222 help += " -T<name> = name specifies a type or a list of types. The output for this\n";
223 help += " [t1;...] type is generated. If no '-T' option is specified,\n";
224 help += " then output for all types is generated.\n";
225 help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
226 help += " -B<name> = name specifies the base node. All types are searched under this\n";
227 help += " node. Default is the root '/' of the registry files.\n";
228 help += " -G = generate only target files which does not exists.\n";
229 help += " -Gc = generate only target files which content will be changed.\n";
230 help += "IMPORTANT: You lose enum values and struct, exception inheritance!\n";
231 help += " Parameter name Object is translated to _Object!\n";
232 help += " The type type is translated to CORBA::TypeCode!\n";
233 help += " Sequences are expanded to a typedef name Sequence_..._\"name\"!\n";
234 help += prepareVersion();
235
236 return help;
237 }
238
prepareVersion()239 OString IdlOptions::prepareVersion()
240 {
241 OString version(m_program);
242 version += " Version 2.0\n\n";
243 return version;
244 }
245
246
247