update dev300-m58
[ooovba.git] / codemaker / source / cunomaker / cunooptions.cxx
blob7e897937635c358d1e44386ef01c6fa9dd25e953
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cunooptions.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_codemaker.hxx"
33 #include <stdio.h>
35 #include "cunooptions.hxx"
37 using namespace rtl;
39 sal_Bool CunoOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile)
40 throw( IllegalArgument )
42 sal_Bool ret = sal_True;
43 sal_uInt16 i=0;
45 if (!bCmdFile)
47 bCmdFile = sal_True;
49 m_program = av[0];
51 if (ac < 2)
53 fprintf(stderr, "%s", prepareHelp().getStr());
54 ret = sal_False;
57 i = 1;
58 } else
60 i = 0;
63 char *s=NULL;
64 for (i; i < ac; i++)
66 if (av[i][0] == '-')
68 switch (av[i][1])
70 case 'O':
71 if (av[i][2] == 'C')
73 if (av[i][3] == '\0')
75 if (i < ac - 1 && av[i+1][0] != '-')
77 i++;
78 s = av[i];
79 } else
81 OString tmp("'-OC', please check");
82 if (i <= ac - 1)
84 tmp += " your input '" + OString(av[i+1]) + "'";
87 throw IllegalArgument(tmp);
89 } else
91 s = av[i] + 3;
94 m_options["-OC"] = OString(s);
95 break;
96 } else
97 if (av[i][2] == '\0')
99 if (i < ac - 1 && av[i+1][0] != '-')
101 i++;
102 s = av[i];
103 } else
105 OString tmp("'-O', please check");
106 if (i <= ac - 1)
108 tmp += " your input '" + OString(av[i+1]) + "'";
111 throw IllegalArgument(tmp);
113 } else
115 s = av[i] + 2;
118 m_options["-O"] = OString(s);
119 break;
120 case 'B':
121 if (av[i][2] == '\0')
123 if (i < ac - 1 && av[i+1][0] != '-')
125 i++;
126 s = av[i];
127 } else
129 OString tmp("'-B', please check");
130 if (i <= ac - 1)
132 tmp += " your input '" + OString(av[i+1]) + "'";
135 throw IllegalArgument(tmp);
137 } else
139 s = av[i] + 2;
142 m_options["-B"] = OString(s);
143 break;
144 case 'T':
145 if (av[i][2] == '\0')
147 if (i < ac - 1 && av[i+1][0] != '-')
149 i++;
150 s = av[i];
151 } else
153 OString tmp("'-T', please check");
154 if (i <= ac - 1)
156 tmp += " your input '" + OString(av[i+1]) + "'";
159 throw IllegalArgument(tmp);
161 } else
163 s = av[i] + 2;
166 if (m_options.count("-T") > 0)
168 OString tmp(m_options["-T"]);
169 tmp = tmp + ";" + s;
170 m_options["-T"] = tmp;
171 } else
173 m_options["-T"] = OString(s);
175 break;
176 case 'U':
177 if (av[i][2] != '\0')
179 OString tmp("'-U', please check");
180 if (i <= ac - 1)
182 tmp += " your input '" + OString(av[i]) + "'";
185 throw IllegalArgument(tmp);
188 m_options["-U"] = OString("");
189 break;
191 case 'L':
192 if (av[i][2] != '\0')
194 OString tmp("'-L', please check");
195 if (i <= ac - 1)
197 tmp += " your input '" + OString(av[i]) + "'";
200 throw IllegalArgument(tmp);
203 if (isValid("-C") || isValid("-CS"))
205 OString tmp("'-L' could not be combined with '-C' or '-CS' option");
206 throw IllegalArgument(tmp);
208 m_options["-L"] = OString("");
209 break;
211 case 'C':
212 if (av[i][2] != '\0')
214 OString tmp("'-C', please check");
215 if (i <= ac - 1)
217 tmp += " your input '" + OString(av[i]) + "'";
220 throw IllegalArgument(tmp);
223 if (isValid("-L") || isValid("-CS"))
225 OString tmp("'-C' could not be combined with '-L' or '-CS' option");
226 throw IllegalArgument(tmp);
228 m_options["-C"] = OString("");
229 break;
230 case 'G':
231 if (av[i][2] == 'c')
233 if (av[i][3] != '\0')
235 OString tmp("'-Gc', please check");
236 if (i <= ac - 1)
238 tmp += " your input '" + OString(av[i]) + "'";
241 throw IllegalArgument(tmp);
244 m_options["-Gc"] = OString("");
245 break;
246 } else
247 if (av[i][2] != '\0')
249 OString tmp("'-G', please check");
250 if (i <= ac - 1)
252 tmp += " your input '" + OString(av[i]) + "'";
255 throw IllegalArgument(tmp);
258 m_options["-G"] = OString("");
259 break;
260 default:
261 throw IllegalArgument("the option is unknown" + OString(av[i]));
262 break;
264 } else
266 if (av[i][0] == '@')
268 FILE* cmdFile = fopen(av[i]+1, "r");
269 if( cmdFile == NULL )
271 fprintf(stderr, "%s", prepareHelp().getStr());
272 ret = sal_False;
273 } else
275 int rargc=0;
276 char* rargv[512];
277 char buffer[512];
279 while ( fscanf(cmdFile, "%s", buffer) != EOF )
281 rargv[rargc]= strdup(buffer);
282 rargc++;
284 fclose(cmdFile);
286 ret = initOptions(rargc, rargv, bCmdFile);
288 for (long i=0; i < rargc; i++)
290 free(rargv[i]);
293 } else
295 m_inputFiles.push_back(av[i]);
300 return ret;
303 OString CunoOptions::prepareHelp()
305 OString help("\nusing: ");
306 help += m_program + " [-options] file_1 ... file_n\nOptions:\n";
307 help += " -O<path> = path describes the root directory for the generated output.\n";
308 help += " The output directory tree is generated under this directory.\n";
309 help += " -T<name> = name specifies a type or a list of types. The output for this\n";
310 help += " [t1;...] type is generated. If no '-T' option is specified,\n";
311 help += " then output for all types is generated.\n";
312 help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
313 help += " -B<name> = name specifies the base node. All types are searched under this\n";
314 help += " node. Default is the root '/' of the registry files.\n";
315 help += " -U = activate the generating of a getCppuType_<name> function.\n";
316 // help += " -L = getCppuType function with a known leak.\n";
317 help += " -C = getCppuType_<name> function keeps comprehensive type information.\n";
318 help += " -G = generate only target files which does not exists.\n";
319 help += " -Gc = generate only target files which content will be changed.\n";
320 help += prepareVersion();
322 return help;
325 OString CunoOptions::prepareVersion()
327 OString version("\nSun Microsystems (R) ");
328 version += m_program + " Version 1.0\n\n";
330 return version;