19f73e17bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
39f73e17bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
49f73e17bSAndrew Rist * or more contributor license agreements. See the NOTICE file
59f73e17bSAndrew Rist * distributed with this work for additional information
69f73e17bSAndrew Rist * regarding copyright ownership. The ASF licenses this file
79f73e17bSAndrew Rist * to you under the Apache License, Version 2.0 (the
89f73e17bSAndrew Rist * "License"); you may not use this file except in compliance
99f73e17bSAndrew Rist * with the License. You may obtain a copy of the License at
109f73e17bSAndrew Rist *
119f73e17bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
129f73e17bSAndrew Rist *
139f73e17bSAndrew Rist * Unless required by applicable law or agreed to in writing,
149f73e17bSAndrew Rist * software distributed under the License is distributed on an
159f73e17bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169f73e17bSAndrew Rist * KIND, either express or implied. See the License for the
179f73e17bSAndrew Rist * specific language governing permissions and limitations
189f73e17bSAndrew Rist * under the License.
199f73e17bSAndrew Rist *
209f73e17bSAndrew Rist *************************************************************/
219f73e17bSAndrew Rist
229f73e17bSAndrew Rist
23cdf0e10cSrcweir #include <stdio.h>
24cdf0e10cSrcweir #include <string.h>
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include "rdboptions.hxx"
27cdf0e10cSrcweir
28cdf0e10cSrcweir using namespace rtl;
29cdf0e10cSrcweir
initOptions(int ac,char * av[],sal_Bool bCmdFile)30cdf0e10cSrcweir sal_Bool RdbOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile)
31cdf0e10cSrcweir throw( IllegalArgument )
32cdf0e10cSrcweir {
33cdf0e10cSrcweir sal_Bool ret = sal_True;
34cdf0e10cSrcweir sal_uInt16 i=0;
35cdf0e10cSrcweir
36cdf0e10cSrcweir if (!bCmdFile)
37cdf0e10cSrcweir {
38cdf0e10cSrcweir bCmdFile = sal_True;
39cdf0e10cSrcweir
40cdf0e10cSrcweir m_program = av[0];
41cdf0e10cSrcweir
42cdf0e10cSrcweir if (ac < 2)
43cdf0e10cSrcweir {
44cdf0e10cSrcweir fprintf(stderr, "%s", prepareHelp().getStr());
45cdf0e10cSrcweir ret = sal_False;
46cdf0e10cSrcweir }
47cdf0e10cSrcweir
48cdf0e10cSrcweir i = 1;
49cdf0e10cSrcweir } else
50cdf0e10cSrcweir {
51cdf0e10cSrcweir i = 0;
52cdf0e10cSrcweir }
53cdf0e10cSrcweir
54cdf0e10cSrcweir char *s=NULL;
55cdf0e10cSrcweir for (; i < ac; i++)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir if (av[i][0] == '-')
58cdf0e10cSrcweir {
59cdf0e10cSrcweir switch (av[i][1])
60cdf0e10cSrcweir {
61cdf0e10cSrcweir case 'O':
62cdf0e10cSrcweir if (av[i][2] == '\0')
63cdf0e10cSrcweir {
64cdf0e10cSrcweir if (i < ac - 1 && av[i+1][0] != '-')
65cdf0e10cSrcweir {
66cdf0e10cSrcweir i++;
67cdf0e10cSrcweir s = av[i];
68cdf0e10cSrcweir } else
69cdf0e10cSrcweir {
70cdf0e10cSrcweir OString tmp("'-O', please check");
71cdf0e10cSrcweir if (i <= ac - 1)
72cdf0e10cSrcweir {
73cdf0e10cSrcweir tmp += " your input '" + OString(av[i+1]) + "'";
74cdf0e10cSrcweir }
75cdf0e10cSrcweir
76cdf0e10cSrcweir throw IllegalArgument(tmp);
77cdf0e10cSrcweir }
78cdf0e10cSrcweir } else
79cdf0e10cSrcweir {
80cdf0e10cSrcweir s = av[i] + 2;
81cdf0e10cSrcweir }
82cdf0e10cSrcweir
83cdf0e10cSrcweir m_options["-O"] = OString(s);
84cdf0e10cSrcweir break;
85cdf0e10cSrcweir case 'X':
86cdf0e10cSrcweir if (av[i][2] == '\0')
87cdf0e10cSrcweir {
88cdf0e10cSrcweir if (i < ac - 1 && av[i+1][0] != '-')
89cdf0e10cSrcweir {
90cdf0e10cSrcweir i++;
91cdf0e10cSrcweir s = av[i];
92cdf0e10cSrcweir } else
93cdf0e10cSrcweir {
94cdf0e10cSrcweir OString tmp("'-X', please check");
95cdf0e10cSrcweir if (i <= ac - 1)
96cdf0e10cSrcweir {
97cdf0e10cSrcweir tmp += " your input '" + OString(av[i+1]) + "'";
98cdf0e10cSrcweir }
99cdf0e10cSrcweir
100cdf0e10cSrcweir throw IllegalArgument(tmp);
101cdf0e10cSrcweir }
102cdf0e10cSrcweir } else
103cdf0e10cSrcweir {
104cdf0e10cSrcweir s = av[i] + 2;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir
107cdf0e10cSrcweir m_options["-X"] = OString(s);
108cdf0e10cSrcweir break;
109cdf0e10cSrcweir case 'R':
110cdf0e10cSrcweir if (av[i][2] == '\0')
111cdf0e10cSrcweir {
112cdf0e10cSrcweir if (i < ac - 1 && av[i+1][0] != '-')
113cdf0e10cSrcweir {
114cdf0e10cSrcweir i++;
115cdf0e10cSrcweir s = av[i];
116cdf0e10cSrcweir } else
117cdf0e10cSrcweir {
118cdf0e10cSrcweir OString tmp("'-R', please check");
119cdf0e10cSrcweir if (i <= ac - 1)
120cdf0e10cSrcweir {
121cdf0e10cSrcweir tmp += " your input '" + OString(av[i+1]) + "'";
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir throw IllegalArgument(tmp);
125cdf0e10cSrcweir }
126cdf0e10cSrcweir } else
127cdf0e10cSrcweir {
128cdf0e10cSrcweir s = av[i] + 2;
129cdf0e10cSrcweir }
130cdf0e10cSrcweir
131cdf0e10cSrcweir m_options["-R"] = OString(s);
132cdf0e10cSrcweir break;
133cdf0e10cSrcweir case 'B':
134cdf0e10cSrcweir if (av[i][2] == '\0')
135cdf0e10cSrcweir {
136cdf0e10cSrcweir if (i < ac - 1 && av[i+1][0] != '-')
137cdf0e10cSrcweir {
138cdf0e10cSrcweir i++;
139cdf0e10cSrcweir s = av[i];
140cdf0e10cSrcweir } else
141cdf0e10cSrcweir {
142cdf0e10cSrcweir OString tmp("'-B', please check");
143cdf0e10cSrcweir if (i <= ac - 1)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir tmp += " your input '" + OString(av[i+1]) + "'";
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
148cdf0e10cSrcweir throw IllegalArgument(tmp);
149cdf0e10cSrcweir }
150cdf0e10cSrcweir } else
151cdf0e10cSrcweir {
152cdf0e10cSrcweir s = av[i] + 2;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir
155cdf0e10cSrcweir m_options["-B"] = OString(s);
156cdf0e10cSrcweir break;
157cdf0e10cSrcweir case 'b':
158cdf0e10cSrcweir if (av[i][2] == '\0')
159cdf0e10cSrcweir {
160cdf0e10cSrcweir if (i < ac - 1 && av[i+1][0] != '-')
161cdf0e10cSrcweir {
162cdf0e10cSrcweir i++;
163cdf0e10cSrcweir s = av[i];
164cdf0e10cSrcweir } else
165cdf0e10cSrcweir {
166cdf0e10cSrcweir OString tmp("'-b', please check");
167cdf0e10cSrcweir if (i <= ac - 1)
168cdf0e10cSrcweir {
169cdf0e10cSrcweir tmp += " your input '" + OString(av[i+1]) + "'";
170cdf0e10cSrcweir }
171cdf0e10cSrcweir
172cdf0e10cSrcweir throw IllegalArgument(tmp);
173cdf0e10cSrcweir }
174cdf0e10cSrcweir } else
175cdf0e10cSrcweir {
176cdf0e10cSrcweir s = av[i] + 2;
177cdf0e10cSrcweir }
178cdf0e10cSrcweir
179cdf0e10cSrcweir m_options["-b"] = OString(s);
180cdf0e10cSrcweir break;
181cdf0e10cSrcweir case 'T':
182cdf0e10cSrcweir if (av[i][2] == '\0')
183cdf0e10cSrcweir {
184cdf0e10cSrcweir if (i < ac - 1 && av[i+1][0] != '-')
185cdf0e10cSrcweir {
186cdf0e10cSrcweir i++;
187cdf0e10cSrcweir s = av[i];
188cdf0e10cSrcweir } else
189cdf0e10cSrcweir {
190cdf0e10cSrcweir OString tmp("'-T', please check");
191cdf0e10cSrcweir if (i <= ac - 1)
192cdf0e10cSrcweir {
193cdf0e10cSrcweir tmp += " your input '" + OString(av[i+1]) + "'";
194cdf0e10cSrcweir }
195cdf0e10cSrcweir
196cdf0e10cSrcweir throw IllegalArgument(tmp);
197cdf0e10cSrcweir }
198cdf0e10cSrcweir } else
199cdf0e10cSrcweir {
200cdf0e10cSrcweir s = av[i] + 2;
201cdf0e10cSrcweir }
202cdf0e10cSrcweir
203cdf0e10cSrcweir if (m_options.count("-T") > 0)
204cdf0e10cSrcweir {
205cdf0e10cSrcweir OString tmp(m_options["-T"]);
206cdf0e10cSrcweir tmp = tmp + ";" + s;
207cdf0e10cSrcweir m_options["-T"] = tmp;
208cdf0e10cSrcweir } else
209cdf0e10cSrcweir {
210cdf0e10cSrcweir m_options["-T"] = OString(s);
211cdf0e10cSrcweir }
212cdf0e10cSrcweir break;
213cdf0e10cSrcweir case 'F':
214cdf0e10cSrcweir if (av[i][2] == 'T')
215cdf0e10cSrcweir {
216cdf0e10cSrcweir if (av[i][3] == '\0')
217cdf0e10cSrcweir {
218cdf0e10cSrcweir if (i < ac - 1 && av[i+1][0] != '-')
219cdf0e10cSrcweir {
220cdf0e10cSrcweir i++;
221cdf0e10cSrcweir s = av[i];
222cdf0e10cSrcweir } else
223cdf0e10cSrcweir {
224cdf0e10cSrcweir OString tmp("'-FT', please check");
225cdf0e10cSrcweir if (i <= ac - 1)
226cdf0e10cSrcweir {
227cdf0e10cSrcweir tmp += " your input '" + OString(av[i+1]) + "'";
228cdf0e10cSrcweir }
229cdf0e10cSrcweir
230cdf0e10cSrcweir throw IllegalArgument(tmp);
231cdf0e10cSrcweir }
232cdf0e10cSrcweir } else
233cdf0e10cSrcweir {
234cdf0e10cSrcweir s = av[i] + 3;
235cdf0e10cSrcweir }
236cdf0e10cSrcweir
237cdf0e10cSrcweir if (m_options.count("-FT") > 0)
238cdf0e10cSrcweir {
239cdf0e10cSrcweir OString tmp(m_options["-FT"]);
240cdf0e10cSrcweir tmp = tmp + ";" + s;
241cdf0e10cSrcweir m_options["-FT"] = tmp;
242cdf0e10cSrcweir } else
243cdf0e10cSrcweir {
244cdf0e10cSrcweir m_options["-FT"] = OString(s);
245cdf0e10cSrcweir }
246cdf0e10cSrcweir } else
247cdf0e10cSrcweir {
248cdf0e10cSrcweir if (av[i][2] == '\0')
249cdf0e10cSrcweir {
250cdf0e10cSrcweir if (i < ac - 1 && av[i+1][0] != '-')
251cdf0e10cSrcweir {
252cdf0e10cSrcweir i++;
253cdf0e10cSrcweir s = av[i];
254cdf0e10cSrcweir } else
255cdf0e10cSrcweir {
256cdf0e10cSrcweir OString tmp("'-F', please check");
257cdf0e10cSrcweir if (i <= ac - 1)
258cdf0e10cSrcweir {
259cdf0e10cSrcweir tmp += " your input '" + OString(av[i+1]) + "'";
260cdf0e10cSrcweir }
261cdf0e10cSrcweir
262cdf0e10cSrcweir throw IllegalArgument(tmp);
263cdf0e10cSrcweir }
264cdf0e10cSrcweir } else
265cdf0e10cSrcweir {
266cdf0e10cSrcweir s = av[i] + 2;
267cdf0e10cSrcweir }
268cdf0e10cSrcweir
269cdf0e10cSrcweir m_options["-F"] = OString(s);
270cdf0e10cSrcweir }
271cdf0e10cSrcweir break;
272cdf0e10cSrcweir case 'L':
273cdf0e10cSrcweir if (av[i][2] != '\0')
274cdf0e10cSrcweir {
275cdf0e10cSrcweir OString tmp("'-L', please check");
276cdf0e10cSrcweir if (i <= ac - 1)
277cdf0e10cSrcweir {
278cdf0e10cSrcweir tmp += " your input '" + OString(av[i+1]) + "'";
279cdf0e10cSrcweir }
280cdf0e10cSrcweir
281cdf0e10cSrcweir throw IllegalArgument(tmp);
282cdf0e10cSrcweir }
283cdf0e10cSrcweir
284cdf0e10cSrcweir m_options["-L"] = OString();
285cdf0e10cSrcweir m_generateTypeList = sal_True;
286cdf0e10cSrcweir break;
287cdf0e10cSrcweir default:
288cdf0e10cSrcweir throw IllegalArgument("the option is unknown" + OString(av[i]));
289cdf0e10cSrcweir }
290cdf0e10cSrcweir } else
291cdf0e10cSrcweir {
292cdf0e10cSrcweir if (av[i][0] == '@')
293cdf0e10cSrcweir {
294cdf0e10cSrcweir FILE* cmdFile = fopen(av[i]+1, "r");
295cdf0e10cSrcweir if( cmdFile == NULL )
296cdf0e10cSrcweir {
297cdf0e10cSrcweir fprintf(stderr, "%s", prepareHelp().getStr());
298cdf0e10cSrcweir ret = sal_False;
299cdf0e10cSrcweir } else
300cdf0e10cSrcweir {
301cdf0e10cSrcweir int rargc=0;
302cdf0e10cSrcweir char* rargv[512];
303cdf0e10cSrcweir char buffer[512];
304cdf0e10cSrcweir
305cdf0e10cSrcweir while ( fscanf(cmdFile, "%s", buffer) != EOF )
306cdf0e10cSrcweir {
307cdf0e10cSrcweir rargv[rargc]= strdup(buffer);
308cdf0e10cSrcweir rargc++;
309cdf0e10cSrcweir }
310cdf0e10cSrcweir fclose(cmdFile);
311cdf0e10cSrcweir
312cdf0e10cSrcweir ret = initOptions(rargc, rargv, bCmdFile);
313cdf0e10cSrcweir
314cdf0e10cSrcweir for (long j=0; j < rargc; j++)
315cdf0e10cSrcweir {
316cdf0e10cSrcweir free(rargv[j]);
317cdf0e10cSrcweir }
318cdf0e10cSrcweir }
319cdf0e10cSrcweir } else
320cdf0e10cSrcweir {
321cdf0e10cSrcweir m_inputFiles.push_back(av[i]);
322cdf0e10cSrcweir }
323cdf0e10cSrcweir }
324cdf0e10cSrcweir }
325cdf0e10cSrcweir
326cdf0e10cSrcweir return ret;
327cdf0e10cSrcweir }
328cdf0e10cSrcweir
prepareHelp()329cdf0e10cSrcweir OString RdbOptions::prepareHelp()
330cdf0e10cSrcweir {
331cdf0e10cSrcweir OString help("\nusing: ");
332cdf0e10cSrcweir help += m_program + " [-options] (-R<regname> | file_1 [... file_n])\n";
333cdf0e10cSrcweir help += "The rdbmaker supports 2 modes:\n";
334cdf0e10cSrcweir help += " 1. using the internal UNO type description manager -> use -R<regname>\n"
335cdf0e10cSrcweir " where regname specifies the type library used by the UNO type description manager\n"
336cdf0e10cSrcweir " after UNO is bootstrapped. This option disables the use of any other type libraries.\n"
337*3a4108e5SJohn Bampton " The type library must be a valid product type library which means that all types are\n"
338cdf0e10cSrcweir " stored under the global base node UCR (Uno Core Reflection data).\n";
339cdf0e10cSrcweir help += " 2. using one or more type library files -> use file_1 ... file_n\n"
340cdf0e10cSrcweir " file_1 .. file_n specifies one or more valid type library files which are used to\n"
341cdf0e10cSrcweir " find the needed type information. The used type libraries have to support the same base\n"
342cdf0e10cSrcweir " node (-B option).\n";
343cdf0e10cSrcweir help += "Options:\n";
344cdf0e10cSrcweir help += " -O<filename> = filename specifies the name of the generated registry\n";
345cdf0e10cSrcweir help += " or text file.\n";
346cdf0e10cSrcweir help += " -L = specifies that only a text file is generated with the\n";
347cdf0e10cSrcweir help += " names of the specified types and their dependencies.\n";
348cdf0e10cSrcweir help += " Default is that a registry file will be created\n";
349cdf0e10cSrcweir // help += " -X<xmlfile> = xmlfile specifies the name of an xml description where\n";
350cdf0e10cSrcweir // help += " all types are specified which will be generated.\n";
351cdf0e10cSrcweir help += " -T<name> = name specifies a type or a list of types. The output for\n";
352cdf0e10cSrcweir help += " [t1;...] this type is generated.\n";
353cdf0e10cSrcweir help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
354cdf0e10cSrcweir help += " -FT<name> = name specifies a type or a list of types. For this types\n";
355cdf0e10cSrcweir help += " [t1;...] nothing will be generated.\n";
356cdf0e10cSrcweir help += " |F<file> = file specifies an text file. For the specified types in\n" ;
357cdf0e10cSrcweir help += " this file nothing will be generated.\n";
358cdf0e10cSrcweir help += " -B<name> = name specifies the base node. All types are searched under\n";
359cdf0e10cSrcweir help += " this node. Default is the root '/' of the registry files.\n";
360cdf0e10cSrcweir help += " This option takes effect using run mode 2 only.\n";
361cdf0e10cSrcweir help += " -b<name> = name specifies the base node of the output registry. All\n";
362cdf0e10cSrcweir help += " types will be generated under this node. Default is the\n";
363cdf0e10cSrcweir help += " root '/' of the registry file.\n";
364cdf0e10cSrcweir help += prepareVersion();
365cdf0e10cSrcweir
366cdf0e10cSrcweir return help;
367cdf0e10cSrcweir }
368cdf0e10cSrcweir
prepareVersion()369cdf0e10cSrcweir OString RdbOptions::prepareVersion()
370cdf0e10cSrcweir {
371cdf0e10cSrcweir OString version("\nSun Microsystems (R) ");
372cdf0e10cSrcweir version += m_program + " Version 2.0\n\n";
373cdf0e10cSrcweir
374cdf0e10cSrcweir return version;
375cdf0e10cSrcweir }
376cdf0e10cSrcweir
377cdf0e10cSrcweir
378