update dev300-m58
[ooovba.git] / codemaker / source / javamaker / javaoptions.cxx
blobf8bef03e34b7da1b76745c88bfabdca2eb6281f9
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: javaoptions.cxx,v $
10 * $Revision: 1.12 $
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>
34 #include <string.h>
35 #include "javaoptions.hxx"
36 #include "osl/process.h"
37 #include "osl/thread.h"
39 using namespace rtl;
41 sal_Bool JavaOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile)
42 throw( IllegalArgument )
44 sal_Bool ret = sal_True;
45 sal_uInt16 i=0;
47 if (!bCmdFile)
49 bCmdFile = sal_True;
51 m_program = av[0];
53 if (ac < 2)
55 fprintf(stderr, "%s", prepareHelp().getStr());
56 ret = sal_False;
59 i = 1;
60 } else
62 i = 0;
65 char *s=NULL;
66 for( ; i < ac; i++)
68 if (av[i][0] == '-')
70 switch (av[i][1])
72 case 'O':
73 if (av[i][2] == '\0')
75 if (i < ac - 1 && av[i+1][0] != '-')
77 i++;
78 s = av[i];
79 } else
81 OString tmp("'-O', 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] + 2;
94 m_options["-O"] = OString(s);
95 break;
96 case 'B':
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("'-B', 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["-B"] = OString(s);
119 break;
120 case 'n':
121 if (av[i][2] != 'D' || av[i][3] != '\0')
123 OString tmp("'-nD', please check");
124 tmp += " your input '" + OString(av[i]) + "'";
125 throw IllegalArgument(tmp);
128 m_options["-nD"] = OString("");
129 break;
130 case 'T':
131 if (av[i][2] == '\0')
133 if (i < ac - 1 && av[i+1][0] != '-')
135 i++;
136 s = av[i];
137 } else
139 OString tmp("'-T', please check");
140 if (i <= ac - 1)
142 tmp += " your input '" + OString(av[i+1]) + "'";
145 throw IllegalArgument(tmp);
147 } else
149 s = av[i] + 2;
152 if (m_options.count("-T") > 0)
154 OString tmp(m_options["-T"]);
155 tmp = tmp + ";" + s;
156 m_options["-T"] = tmp;
157 } else
159 m_options["-T"] = OString(s);
161 break;
162 case 'G':
163 if (av[i][2] == 'c')
165 if (av[i][3] != '\0')
167 OString tmp("'-Gc', please check");
168 if (i <= ac - 1)
170 tmp += " your input '" + OString(av[i]) + "'";
173 throw IllegalArgument(tmp);
176 m_options["-Gc"] = OString("");
177 break;
178 } else
179 if (av[i][2] != '\0')
181 OString tmp("'-G', please check");
182 if (i <= ac - 1)
184 tmp += " your input '" + OString(av[i]) + "'";
187 throw IllegalArgument(tmp);
190 m_options["-G"] = OString("");
191 break;
192 case 'X': // support for eXtra type rdbs
194 if (av[i][2] == '\0')
196 if (i < ac - 1 && av[i+1][0] != '-')
198 i++;
199 s = av[i];
200 } else
202 OString tmp("'-X', please check");
203 if (i <= ac - 1)
205 tmp += " your input '" + OString(av[i+1]) + "'";
208 throw IllegalArgument(tmp);
210 } else
212 s = av[i] + 2;
215 m_extra_input_files.push_back( s );
216 break;
219 default:
220 throw IllegalArgument("the option is unknown" + OString(av[i]));
222 } else
224 if (av[i][0] == '@')
226 FILE* cmdFile = fopen(av[i]+1, "r");
227 if( cmdFile == NULL )
229 fprintf(stderr, "%s", prepareHelp().getStr());
230 ret = sal_False;
231 } else
233 int rargc=0;
234 char* rargv[512];
235 char buffer[512];
237 while ( fscanf(cmdFile, "%s", buffer) != EOF )
239 rargv[rargc]= strdup(buffer);
240 rargc++;
242 fclose(cmdFile);
244 ret = initOptions(rargc, rargv, bCmdFile);
246 for (long j=0; j < rargc; j++)
248 free(rargv[j]);
251 } else
253 if (bCmdFile)
255 m_inputFiles.push_back(av[i]);
256 } else
258 OUString system_filepath;
259 if (osl_getCommandArg( i-1, &system_filepath.pData )
260 != osl_Process_E_None)
262 OSL_ASSERT(false);
264 m_inputFiles.push_back(OUStringToOString(system_filepath, osl_getThreadTextEncoding()));
270 return ret;
273 OString JavaOptions::prepareHelp()
275 OString help("\nusing: ");
276 help += m_program + " [-options] file_1 ... file_n -Xfile_n+1 -Xfile_n+2\nOptions:\n";
277 help += " -O<path> = path describes the root directory for the generated output.\n";
278 help += " The output directory tree is generated under this directory.\n";
279 help += " -T<name> = name specifies a type or a list of types. The output for this\n";
280 help += " [t1;...] type and all dependent types are generated. If no '-T' option is \n";
281 help += " specified, then output for all types is generated.\n";
282 help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
283 help += " -B<name> = name specifies the base node. All types are searched under this\n";
284 help += " node. Default is the root '/' of the registry files.\n";
285 help += " -nD = no dependent types are generated.\n";
286 help += " -G = generate only target files which does not exists.\n";
287 help += " -Gc = generate only target files which content will be changed.\n";
288 help += " -X<file> = extra types which will not be taken into account for generation.\n";
289 help += prepareVersion();
291 return help;
294 OString JavaOptions::prepareVersion()
296 OString version("\nSun Microsystems (R) ");
297 version += m_program + " Version 2.0\n\n";
299 return version;