xref: /AOO41X/main/codemaker/source/cunomaker/cunooptions.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_codemaker.hxx"
30*cdf0e10cSrcweir #include 	<stdio.h>
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include	"cunooptions.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir using namespace rtl;
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir sal_Bool CunoOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile)
37*cdf0e10cSrcweir 	throw( IllegalArgument )
38*cdf0e10cSrcweir {
39*cdf0e10cSrcweir 	sal_Bool 	ret = sal_True;
40*cdf0e10cSrcweir 	sal_uInt16	i=0;
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir 	if (!bCmdFile)
43*cdf0e10cSrcweir 	{
44*cdf0e10cSrcweir 		bCmdFile = sal_True;
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir 		m_program = av[0];
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir 		if (ac < 2)
49*cdf0e10cSrcweir 		{
50*cdf0e10cSrcweir 			fprintf(stderr, "%s", prepareHelp().getStr());
51*cdf0e10cSrcweir 			ret = sal_False;
52*cdf0e10cSrcweir 		}
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir 		i = 1;
55*cdf0e10cSrcweir 	} else
56*cdf0e10cSrcweir 	{
57*cdf0e10cSrcweir 		i = 0;
58*cdf0e10cSrcweir 	}
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 	char	*s=NULL;
61*cdf0e10cSrcweir 	for (i; i < ac; i++)
62*cdf0e10cSrcweir 	{
63*cdf0e10cSrcweir 		if (av[i][0] == '-')
64*cdf0e10cSrcweir 		{
65*cdf0e10cSrcweir 			switch (av[i][1])
66*cdf0e10cSrcweir 			{
67*cdf0e10cSrcweir 				case 'O':
68*cdf0e10cSrcweir 					if (av[i][2] == 'C')
69*cdf0e10cSrcweir 					{
70*cdf0e10cSrcweir 						if (av[i][3] == '\0')
71*cdf0e10cSrcweir 						{
72*cdf0e10cSrcweir 							if (i < ac - 1 && av[i+1][0] != '-')
73*cdf0e10cSrcweir 							{
74*cdf0e10cSrcweir 								i++;
75*cdf0e10cSrcweir 								s = av[i];
76*cdf0e10cSrcweir 							} else
77*cdf0e10cSrcweir 							{
78*cdf0e10cSrcweir 								OString tmp("'-OC', please check");
79*cdf0e10cSrcweir 								if (i <= ac - 1)
80*cdf0e10cSrcweir 								{
81*cdf0e10cSrcweir 									tmp += " your input '" + OString(av[i+1]) + "'";
82*cdf0e10cSrcweir 								}
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 								throw IllegalArgument(tmp);
85*cdf0e10cSrcweir 							}
86*cdf0e10cSrcweir 						} else
87*cdf0e10cSrcweir 						{
88*cdf0e10cSrcweir 							s = av[i] + 3;
89*cdf0e10cSrcweir 						}
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 						m_options["-OC"] = OString(s);
92*cdf0e10cSrcweir 						break;
93*cdf0e10cSrcweir 					} else
94*cdf0e10cSrcweir 					if (av[i][2] == '\0')
95*cdf0e10cSrcweir 					{
96*cdf0e10cSrcweir 						if (i < ac - 1 && av[i+1][0] != '-')
97*cdf0e10cSrcweir 						{
98*cdf0e10cSrcweir 							i++;
99*cdf0e10cSrcweir 							s = av[i];
100*cdf0e10cSrcweir 						} else
101*cdf0e10cSrcweir 						{
102*cdf0e10cSrcweir 							OString tmp("'-O', please check");
103*cdf0e10cSrcweir 							if (i <= ac - 1)
104*cdf0e10cSrcweir 							{
105*cdf0e10cSrcweir 								tmp += " your input '" + OString(av[i+1]) + "'";
106*cdf0e10cSrcweir 							}
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 							throw IllegalArgument(tmp);
109*cdf0e10cSrcweir 						}
110*cdf0e10cSrcweir 					} else
111*cdf0e10cSrcweir 					{
112*cdf0e10cSrcweir 						s = av[i] + 2;
113*cdf0e10cSrcweir 					}
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 					m_options["-O"] = OString(s);
116*cdf0e10cSrcweir 					break;
117*cdf0e10cSrcweir 				case 'B':
118*cdf0e10cSrcweir 					if (av[i][2] == '\0')
119*cdf0e10cSrcweir 					{
120*cdf0e10cSrcweir 						if (i < ac - 1 && av[i+1][0] != '-')
121*cdf0e10cSrcweir 						{
122*cdf0e10cSrcweir 							i++;
123*cdf0e10cSrcweir 							s = av[i];
124*cdf0e10cSrcweir 						} else
125*cdf0e10cSrcweir 						{
126*cdf0e10cSrcweir 							OString tmp("'-B', please check");
127*cdf0e10cSrcweir 							if (i <= ac - 1)
128*cdf0e10cSrcweir 							{
129*cdf0e10cSrcweir 								tmp += " your input '" + OString(av[i+1]) + "'";
130*cdf0e10cSrcweir 							}
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 							throw IllegalArgument(tmp);
133*cdf0e10cSrcweir 						}
134*cdf0e10cSrcweir 					} else
135*cdf0e10cSrcweir 					{
136*cdf0e10cSrcweir 						s = av[i] + 2;
137*cdf0e10cSrcweir 					}
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 					m_options["-B"] = OString(s);
140*cdf0e10cSrcweir 					break;
141*cdf0e10cSrcweir 				case 'T':
142*cdf0e10cSrcweir 					if (av[i][2] == '\0')
143*cdf0e10cSrcweir 					{
144*cdf0e10cSrcweir 						if (i < ac - 1 && av[i+1][0] != '-')
145*cdf0e10cSrcweir 						{
146*cdf0e10cSrcweir 							i++;
147*cdf0e10cSrcweir 							s = av[i];
148*cdf0e10cSrcweir 						} else
149*cdf0e10cSrcweir 						{
150*cdf0e10cSrcweir 							OString tmp("'-T', please check");
151*cdf0e10cSrcweir 							if (i <= ac - 1)
152*cdf0e10cSrcweir 							{
153*cdf0e10cSrcweir 								tmp += " your input '" + OString(av[i+1]) + "'";
154*cdf0e10cSrcweir 							}
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 							throw IllegalArgument(tmp);
157*cdf0e10cSrcweir 						}
158*cdf0e10cSrcweir 					} else
159*cdf0e10cSrcweir 					{
160*cdf0e10cSrcweir 						s = av[i] + 2;
161*cdf0e10cSrcweir 					}
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 					if (m_options.count("-T") > 0)
164*cdf0e10cSrcweir 					{
165*cdf0e10cSrcweir 						OString tmp(m_options["-T"]);
166*cdf0e10cSrcweir 						tmp = tmp + ";" + s;
167*cdf0e10cSrcweir 						m_options["-T"] = tmp;
168*cdf0e10cSrcweir 					} else
169*cdf0e10cSrcweir 					{
170*cdf0e10cSrcweir 						m_options["-T"] = OString(s);
171*cdf0e10cSrcweir 					}
172*cdf0e10cSrcweir 					break;
173*cdf0e10cSrcweir 				case 'U':
174*cdf0e10cSrcweir 					if (av[i][2] != '\0')
175*cdf0e10cSrcweir 					{
176*cdf0e10cSrcweir 						OString tmp("'-U', please check");
177*cdf0e10cSrcweir 						if (i <= ac - 1)
178*cdf0e10cSrcweir 						{
179*cdf0e10cSrcweir 							tmp += " your input '" + OString(av[i]) + "'";
180*cdf0e10cSrcweir 						}
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 						throw IllegalArgument(tmp);
183*cdf0e10cSrcweir 					}
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 					m_options["-U"] = OString("");
186*cdf0e10cSrcweir 					break;
187*cdf0e10cSrcweir /*
188*cdf0e10cSrcweir 				case 'L':
189*cdf0e10cSrcweir 					if (av[i][2] != '\0')
190*cdf0e10cSrcweir 					{
191*cdf0e10cSrcweir 						OString tmp("'-L', please check");
192*cdf0e10cSrcweir 						if (i <= ac - 1)
193*cdf0e10cSrcweir 						{
194*cdf0e10cSrcweir 							tmp += " your input '" + OString(av[i]) + "'";
195*cdf0e10cSrcweir 						}
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 						throw IllegalArgument(tmp);
198*cdf0e10cSrcweir 					}
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 					if (isValid("-C") || isValid("-CS"))
201*cdf0e10cSrcweir 					{
202*cdf0e10cSrcweir 						OString tmp("'-L' could not be combined with '-C' or '-CS' option");
203*cdf0e10cSrcweir 						throw IllegalArgument(tmp);
204*cdf0e10cSrcweir 					}
205*cdf0e10cSrcweir 					m_options["-L"] = OString("");
206*cdf0e10cSrcweir 					break;
207*cdf0e10cSrcweir */
208*cdf0e10cSrcweir 				case 'C':
209*cdf0e10cSrcweir 					if (av[i][2] != '\0')
210*cdf0e10cSrcweir 					{
211*cdf0e10cSrcweir 						OString tmp("'-C', please check");
212*cdf0e10cSrcweir 						if (i <= ac - 1)
213*cdf0e10cSrcweir 						{
214*cdf0e10cSrcweir 							tmp += " your input '" + OString(av[i]) + "'";
215*cdf0e10cSrcweir 						}
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 						throw IllegalArgument(tmp);
218*cdf0e10cSrcweir 					}
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 					if (isValid("-L") || isValid("-CS"))
221*cdf0e10cSrcweir 					{
222*cdf0e10cSrcweir 						OString tmp("'-C' could not be combined with '-L' or '-CS' option");
223*cdf0e10cSrcweir 						throw IllegalArgument(tmp);
224*cdf0e10cSrcweir 					}
225*cdf0e10cSrcweir 					m_options["-C"] = OString("");
226*cdf0e10cSrcweir 					break;
227*cdf0e10cSrcweir 				case 'G':
228*cdf0e10cSrcweir 					if (av[i][2] == 'c')
229*cdf0e10cSrcweir 					{
230*cdf0e10cSrcweir 						if (av[i][3] != '\0')
231*cdf0e10cSrcweir 						{
232*cdf0e10cSrcweir 							OString tmp("'-Gc', please check");
233*cdf0e10cSrcweir 							if (i <= ac - 1)
234*cdf0e10cSrcweir 							{
235*cdf0e10cSrcweir 								tmp += " your input '" + OString(av[i]) + "'";
236*cdf0e10cSrcweir 							}
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir 							throw IllegalArgument(tmp);
239*cdf0e10cSrcweir 						}
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir 						m_options["-Gc"] = OString("");
242*cdf0e10cSrcweir 						break;
243*cdf0e10cSrcweir 					} else
244*cdf0e10cSrcweir 					if (av[i][2] != '\0')
245*cdf0e10cSrcweir 					{
246*cdf0e10cSrcweir 						OString tmp("'-G', please check");
247*cdf0e10cSrcweir 						if (i <= ac - 1)
248*cdf0e10cSrcweir 						{
249*cdf0e10cSrcweir 							tmp += " your input '" + OString(av[i]) + "'";
250*cdf0e10cSrcweir 						}
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 						throw IllegalArgument(tmp);
253*cdf0e10cSrcweir 					}
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir 					m_options["-G"] = OString("");
256*cdf0e10cSrcweir 					break;
257*cdf0e10cSrcweir 				default:
258*cdf0e10cSrcweir 					throw IllegalArgument("the option is unknown" + OString(av[i]));
259*cdf0e10cSrcweir 					break;
260*cdf0e10cSrcweir 			}
261*cdf0e10cSrcweir 		} else
262*cdf0e10cSrcweir 		{
263*cdf0e10cSrcweir 			if (av[i][0] == '@')
264*cdf0e10cSrcweir 			{
265*cdf0e10cSrcweir 				FILE* cmdFile = fopen(av[i]+1, "r");
266*cdf0e10cSrcweir 		  		if( cmdFile == NULL )
267*cdf0e10cSrcweir       			{
268*cdf0e10cSrcweir 					fprintf(stderr, "%s", prepareHelp().getStr());
269*cdf0e10cSrcweir 					ret = sal_False;
270*cdf0e10cSrcweir 				} else
271*cdf0e10cSrcweir 				{
272*cdf0e10cSrcweir 					int rargc=0;
273*cdf0e10cSrcweir 					char* rargv[512];
274*cdf0e10cSrcweir 					char  buffer[512];
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir 					while ( fscanf(cmdFile, "%s", buffer) != EOF )
277*cdf0e10cSrcweir 					{
278*cdf0e10cSrcweir 						rargv[rargc]= strdup(buffer);
279*cdf0e10cSrcweir 						rargc++;
280*cdf0e10cSrcweir 					}
281*cdf0e10cSrcweir 					fclose(cmdFile);
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir 					ret = initOptions(rargc, rargv, bCmdFile);
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir 					for (long i=0; i < rargc; i++)
286*cdf0e10cSrcweir 					{
287*cdf0e10cSrcweir 						free(rargv[i]);
288*cdf0e10cSrcweir 					}
289*cdf0e10cSrcweir 				}
290*cdf0e10cSrcweir 			} else
291*cdf0e10cSrcweir 			{
292*cdf0e10cSrcweir 				m_inputFiles.push_back(av[i]);
293*cdf0e10cSrcweir 			}
294*cdf0e10cSrcweir 		}
295*cdf0e10cSrcweir 	}
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir 	return ret;
298*cdf0e10cSrcweir }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir OString	CunoOptions::prepareHelp()
301*cdf0e10cSrcweir {
302*cdf0e10cSrcweir 	OString help("\nusing: ");
303*cdf0e10cSrcweir 	help += m_program + " [-options] file_1 ... file_n\nOptions:\n";
304*cdf0e10cSrcweir 	help += "    -O<path>   = path describes the root directory for the generated output.\n";
305*cdf0e10cSrcweir 	help += "                 The output directory tree is generated under this directory.\n";
306*cdf0e10cSrcweir 	help += "    -T<name>   = name specifies a type or a list of types. The output for this\n";
307*cdf0e10cSrcweir 	help += "      [t1;...]   type is generated. If no '-T' option is specified,\n";
308*cdf0e10cSrcweir 	help += "                 then output for all types is generated.\n";
309*cdf0e10cSrcweir 	help += "                 Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
310*cdf0e10cSrcweir 	help += "    -B<name>   = name specifies the base node. All types are searched under this\n";
311*cdf0e10cSrcweir 	help += "                 node. Default is the root '/' of the registry files.\n";
312*cdf0e10cSrcweir 	help += "    -U         = activate the generating of a getCppuType_<name> function.\n";
313*cdf0e10cSrcweir //	help += "    -L         = getCppuType function with a known leak.\n";
314*cdf0e10cSrcweir 	help += "    -C         = getCppuType_<name> function keeps comprehensive type information.\n";
315*cdf0e10cSrcweir 	help += "    -G         = generate only target files which does not exists.\n";
316*cdf0e10cSrcweir 	help += "    -Gc        = generate only target files which content will be changed.\n";
317*cdf0e10cSrcweir 	help += prepareVersion();
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir 	return help;
320*cdf0e10cSrcweir }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir OString	CunoOptions::prepareVersion()
323*cdf0e10cSrcweir {
324*cdf0e10cSrcweir 	OString version(m_program);
325*cdf0e10cSrcweir 	version += " Version 1.0\n\n";
326*cdf0e10cSrcweir 	return version;
327*cdf0e10cSrcweir }
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir 
330