Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include <stdio.h>
21 : : #include <string.h>
22 : : #include "javaoptions.hxx"
23 : : #include "osl/process.h"
24 : : #include "osl/thread.h"
25 : :
26 : : using ::rtl::OUString;
27 : : using ::rtl::OString;
28 : : using ::rtl::OUStringToOString;
29 : :
30 : : #ifdef SAL_UNX
31 : : #define SEPARATOR '/'
32 : : #else
33 : : #define SEPARATOR '\\'
34 : : #endif
35 : :
36 : 6 : sal_Bool JavaOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile)
37 : : throw( IllegalArgument )
38 : : {
39 : 6 : sal_Bool ret = sal_True;
40 : 6 : sal_uInt16 i=0;
41 : :
42 [ + - ]: 6 : if (!bCmdFile)
43 : : {
44 : 6 : bCmdFile = sal_True;
45 : :
46 : 6 : OString name(av[0]);
47 : 6 : sal_Int32 index = name.lastIndexOf(SEPARATOR);
48 [ + - ]: 6 : m_program = name.copy((index > 0 ? index+1 : 0));
49 : :
50 [ - + ]: 6 : if (ac < 2)
51 : : {
52 [ # # ][ # # ]: 0 : fprintf(stderr, "%s", prepareHelp().getStr());
53 : 0 : ret = sal_False;
54 : : }
55 : :
56 : 6 : i = 1;
57 : : } else
58 : : {
59 : 0 : i = 0;
60 : : }
61 : :
62 : 6 : char *s=NULL;
63 [ + + ]: 30 : for( ; i < ac; i++)
64 : : {
65 [ + + ]: 24 : if (av[i][0] == '-')
66 : : {
67 [ + + + - : 18 : switch (av[i][1])
- + - ]
68 : : {
69 : : case 'O':
70 [ - + ]: 6 : if (av[i][2] == '\0')
71 : : {
72 [ # # ][ # # ]: 0 : if (i < ac - 1 && av[i+1][0] != '-')
73 : : {
74 : 0 : i++;
75 : 0 : s = av[i];
76 : : } else
77 : : {
78 : 0 : OString tmp("'-O', please check");
79 [ # # ]: 0 : if (i <= ac - 1)
80 : : {
81 : 0 : tmp += " your input '" + OString(av[i+1]) + "'";
82 : : }
83 : :
84 : 0 : throw IllegalArgument(tmp);
85 : : }
86 : : } else
87 : : {
88 : 6 : s = av[i] + 2;
89 : : }
90 : :
91 [ + - ]: 6 : m_options["-O"] = OString(s);
92 : 6 : break;
93 : : case 'B':
94 [ - + ]: 6 : if (av[i][2] == '\0')
95 : : {
96 [ # # ][ # # ]: 0 : if (i < ac - 1 && av[i+1][0] != '-')
97 : : {
98 : 0 : i++;
99 : 0 : s = av[i];
100 : : } else
101 : : {
102 : 0 : OString tmp("'-B', please check");
103 [ # # ]: 0 : if (i <= ac - 1)
104 : : {
105 : 0 : tmp += " your input '" + OString(av[i+1]) + "'";
106 : : }
107 : :
108 : 0 : throw IllegalArgument(tmp);
109 : : }
110 : : } else
111 : : {
112 : 6 : s = av[i] + 2;
113 : : }
114 : :
115 [ + - ]: 6 : m_options["-B"] = OString(s);
116 : 6 : break;
117 : : case 'n':
118 [ + - ][ - + ]: 2 : if (av[i][2] != 'D' || av[i][3] != '\0')
119 : : {
120 : 0 : OString tmp("'-nD', please check");
121 : 0 : tmp += " your input '" + OString(av[i]) + "'";
122 : 0 : throw IllegalArgument(tmp);
123 : : }
124 : :
125 [ + - ]: 2 : m_options["-nD"] = OString("");
126 : 2 : break;
127 : : case 'T':
128 [ # # ]: 0 : if (av[i][2] == '\0')
129 : : {
130 [ # # ][ # # ]: 0 : if (i < ac - 1 && av[i+1][0] != '-')
131 : : {
132 : 0 : i++;
133 : 0 : s = av[i];
134 : : } else
135 : : {
136 : 0 : OString tmp("'-T', please check");
137 [ # # ]: 0 : if (i <= ac - 1)
138 : : {
139 : 0 : tmp += " your input '" + OString(av[i+1]) + "'";
140 : : }
141 : :
142 : 0 : throw IllegalArgument(tmp);
143 : : }
144 : : } else
145 : : {
146 : 0 : s = av[i] + 2;
147 : : }
148 : :
149 [ # # ][ # # ]: 0 : if (m_options.count("-T") > 0)
150 : : {
151 [ # # ]: 0 : OString tmp(m_options["-T"]);
152 : 0 : tmp = tmp + ";" + s;
153 [ # # ]: 0 : m_options["-T"] = tmp;
154 : : } else
155 : : {
156 [ # # ]: 0 : m_options["-T"] = OString(s);
157 : : }
158 : 0 : break;
159 : : case 'G':
160 [ # # ]: 0 : if (av[i][2] == 'c')
161 : : {
162 [ # # ]: 0 : if (av[i][3] != '\0')
163 : : {
164 : 0 : OString tmp("'-Gc', please check");
165 [ # # ]: 0 : if (i <= ac - 1)
166 : : {
167 : 0 : tmp += " your input '" + OString(av[i]) + "'";
168 : : }
169 : :
170 : 0 : throw IllegalArgument(tmp);
171 : : }
172 : :
173 [ # # ]: 0 : m_options["-Gc"] = OString("");
174 : 0 : break;
175 : : } else
176 [ # # ]: 0 : if (av[i][2] != '\0')
177 : : {
178 : 0 : OString tmp("'-G', please check");
179 [ # # ]: 0 : if (i <= ac - 1)
180 : : {
181 : 0 : tmp += " your input '" + OString(av[i]) + "'";
182 : : }
183 : :
184 : 0 : throw IllegalArgument(tmp);
185 : : }
186 : :
187 [ # # ]: 0 : m_options["-G"] = OString("");
188 : 0 : break;
189 : : case 'X': // support for eXtra type rdbs
190 : : {
191 [ - + ]: 4 : if (av[i][2] == '\0')
192 : : {
193 [ # # ][ # # ]: 0 : if (i < ac - 1 && av[i+1][0] != '-')
194 : : {
195 : 0 : i++;
196 : 0 : s = av[i];
197 : : } else
198 : : {
199 : 0 : OString tmp("'-X', please check");
200 [ # # ]: 0 : if (i <= ac - 1)
201 : : {
202 : 0 : tmp += " your input '" + OString(av[i+1]) + "'";
203 : : }
204 : :
205 : 0 : throw IllegalArgument(tmp);
206 : : }
207 : : } else
208 : : {
209 : 4 : s = av[i] + 2;
210 : : }
211 : :
212 [ + - ]: 4 : m_extra_input_files.push_back( s );
213 : 4 : break;
214 : : }
215 : :
216 : : default:
217 : 18 : throw IllegalArgument("the option is unknown" + OString(av[i]));
218 : : }
219 : : } else
220 : : {
221 [ - + ]: 6 : if (av[i][0] == '@')
222 : : {
223 [ # # ]: 0 : FILE* cmdFile = fopen(av[i]+1, "r");
224 [ # # ]: 0 : if( cmdFile == NULL )
225 : : {
226 [ # # ][ # # ]: 0 : fprintf(stderr, "%s", prepareHelp().getStr());
227 : 0 : ret = sal_False;
228 : : } else
229 : : {
230 : 0 : int rargc=0;
231 : : char* rargv[512];
232 : : char buffer[512];
233 : :
234 [ # # ][ # # ]: 0 : while ( fscanf(cmdFile, "%s", buffer) != EOF )
235 : : {
236 : 0 : rargv[rargc]= strdup(buffer);
237 : 0 : rargc++;
238 : : }
239 [ # # ]: 0 : fclose(cmdFile);
240 : :
241 [ # # ]: 0 : ret = initOptions(rargc, rargv, bCmdFile);
242 : :
243 [ # # ]: 0 : for (long j=0; j < rargc; j++)
244 : : {
245 : 0 : free(rargv[j]);
246 : : }
247 : : }
248 : : } else
249 : : {
250 [ + - ]: 6 : if (bCmdFile)
251 : : {
252 [ + - ]: 6 : m_inputFiles.push_back(av[i]);
253 : : } else
254 : : {
255 : 0 : OUString system_filepath;
256 [ # # ]: 0 : if (osl_getCommandArg( i-1, &system_filepath.pData )
257 : : != osl_Process_E_None)
258 : : {
259 : : OSL_ASSERT(false);
260 : : }
261 [ # # ][ # # ]: 0 : m_inputFiles.push_back(OUStringToOString(system_filepath, osl_getThreadTextEncoding()));
[ # # ]
262 : : }
263 : : }
264 : : }
265 : : }
266 : :
267 : 6 : return ret;
268 : : }
269 : :
270 : 0 : OString JavaOptions::prepareHelp()
271 : : {
272 : 0 : OString help("\nusing: ");
273 : 0 : help += m_program + " [-options] file_1 ... file_n -Xfile_n+1 -Xfile_n+2\nOptions:\n";
274 : 0 : help += " -O<path> = path describes the root directory for the generated output.\n";
275 : 0 : help += " The output directory tree is generated under this directory.\n";
276 : 0 : help += " -T<name> = name specifies a type or a list of types. The output for this\n";
277 : 0 : help += " [t1;...] type and all dependent types are generated. If no '-T' option is \n";
278 : 0 : help += " specified, then output for all types is generated.\n";
279 : 0 : help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
280 : 0 : help += " -B<name> = name specifies the base node. All types are searched under this\n";
281 : 0 : help += " node. Default is the root '/' of the registry files.\n";
282 : 0 : help += " -nD = no dependent types are generated.\n";
283 : 0 : help += " -G = generate only target files which does not exists.\n";
284 : 0 : help += " -Gc = generate only target files which content will be changed.\n";
285 : 0 : help += " -X<file> = extra types which will not be taken into account for generation.\n\n";
286 [ # # ]: 0 : help += prepareVersion();
287 : :
288 : 0 : return help;
289 : : }
290 : :
291 : 0 : OString JavaOptions::prepareVersion()
292 : : {
293 : 0 : OString version(m_program);
294 : 0 : version += " Version 2.0\n\n";
295 : 0 : return version;
296 : : }
297 : :
298 : :
299 : :
300 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|