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 :
27 : #ifdef SAL_UNX
28 : #define SEPARATOR '/'
29 : #else
30 : #define SEPARATOR '\\'
31 : #endif
32 :
33 0 : bool JavaOptions::initOptions(int ac, char* av[], bool bCmdFile)
34 : throw( IllegalArgument )
35 : {
36 0 : bool ret = true;
37 0 : sal_uInt16 i=0;
38 :
39 0 : if (!bCmdFile)
40 : {
41 0 : bCmdFile = true;
42 :
43 0 : OString name(av[0]);
44 0 : sal_Int32 index = name.lastIndexOf(SEPARATOR);
45 0 : m_program = name.copy((index > 0 ? index+1 : 0));
46 :
47 0 : if (ac < 2)
48 : {
49 0 : fprintf(stderr, "%s", prepareHelp().getStr());
50 0 : ret = false;
51 : }
52 :
53 0 : i = 1;
54 : }
55 :
56 0 : char *s=NULL;
57 0 : for( ; i < ac; i++)
58 : {
59 0 : if (av[i][0] == '-')
60 : {
61 0 : switch (av[i][1])
62 : {
63 : case 'O':
64 0 : if (av[i][2] == '\0')
65 : {
66 0 : if (i < ac - 1 && av[i+1][0] != '-')
67 : {
68 0 : i++;
69 0 : s = av[i];
70 : } else
71 : {
72 0 : OString tmp("'-O', please check");
73 0 : if (i <= ac - 1)
74 : {
75 0 : tmp += " your input '" + OString(av[i+1]) + "'";
76 : }
77 :
78 0 : throw IllegalArgument(tmp);
79 : }
80 : } else
81 : {
82 0 : s = av[i] + 2;
83 : }
84 :
85 0 : m_options["-O"] = OString(s);
86 0 : break;
87 : case 'n':
88 0 : if (av[i][2] != 'D' || av[i][3] != '\0')
89 : {
90 0 : OString tmp("'-nD', please check");
91 0 : tmp += " your input '" + OString(av[i]) + "'";
92 0 : throw IllegalArgument(tmp);
93 : }
94 :
95 0 : m_options["-nD"] = OString("");
96 0 : break;
97 : case 'T':
98 0 : if (av[i][2] == '\0')
99 : {
100 0 : if (i < ac - 1 && av[i+1][0] != '-')
101 : {
102 0 : i++;
103 0 : s = av[i];
104 : } else
105 : {
106 0 : OString tmp("'-T', please check");
107 0 : if (i <= ac - 1)
108 : {
109 0 : tmp += " your input '" + OString(av[i+1]) + "'";
110 : }
111 :
112 0 : throw IllegalArgument(tmp);
113 : }
114 : } else
115 : {
116 0 : s = av[i] + 2;
117 : }
118 :
119 0 : if (m_options.count("-T") > 0)
120 : {
121 0 : OString tmp(m_options["-T"]);
122 0 : tmp = tmp + ";" + s;
123 0 : m_options["-T"] = tmp;
124 : } else
125 : {
126 0 : m_options["-T"] = OString(s);
127 : }
128 0 : break;
129 : case 'G':
130 0 : if (av[i][2] == 'c')
131 : {
132 0 : if (av[i][3] != '\0')
133 : {
134 0 : OString tmp("'-Gc', please check");
135 0 : if (i <= ac - 1)
136 : {
137 0 : tmp += " your input '" + OString(av[i]) + "'";
138 : }
139 :
140 0 : throw IllegalArgument(tmp);
141 : }
142 :
143 0 : m_options["-Gc"] = OString("");
144 0 : break;
145 0 : } else if (av[i][2] != '\0')
146 : {
147 0 : OString tmp("'-G', please check");
148 0 : if (i <= ac - 1)
149 : {
150 0 : tmp += " your input '" + OString(av[i]) + "'";
151 : }
152 :
153 0 : throw IllegalArgument(tmp);
154 : }
155 :
156 0 : m_options["-G"] = OString("");
157 0 : break;
158 : case 'X': // support for eXtra type rdbs
159 : {
160 0 : if (av[i][2] == '\0')
161 : {
162 0 : if (i < ac - 1 && av[i+1][0] != '-')
163 : {
164 0 : i++;
165 0 : s = av[i];
166 : } else
167 : {
168 0 : OString tmp("'-X', please check");
169 0 : if (i <= ac - 1)
170 : {
171 0 : tmp += " your input '" + OString(av[i+1]) + "'";
172 : }
173 :
174 0 : throw IllegalArgument(tmp);
175 : }
176 : } else
177 : {
178 0 : s = av[i] + 2;
179 : }
180 :
181 0 : m_extra_input_files.push_back( s );
182 0 : break;
183 : }
184 :
185 : default:
186 0 : throw IllegalArgument("the option is unknown" + OString(av[i]));
187 : }
188 : } else
189 : {
190 0 : if (av[i][0] == '@')
191 : {
192 0 : FILE* cmdFile = fopen(av[i]+1, "r");
193 0 : if( cmdFile == NULL )
194 : {
195 0 : fprintf(stderr, "%s", prepareHelp().getStr());
196 0 : ret = false;
197 : } else
198 : {
199 0 : int rargc=0;
200 : char* rargv[512];
201 : char buffer[512];
202 :
203 0 : while ( fscanf(cmdFile, "%s", buffer) != EOF )
204 : {
205 0 : rargv[rargc]= strdup(buffer);
206 0 : rargc++;
207 : }
208 0 : fclose(cmdFile);
209 :
210 0 : ret = initOptions(rargc, rargv, bCmdFile);
211 :
212 0 : for (long j=0; j < rargc; j++)
213 : {
214 0 : free(rargv[j]);
215 : }
216 : }
217 : } else
218 : {
219 0 : m_inputFiles.push_back(av[i]);
220 : }
221 : }
222 : }
223 :
224 0 : return ret;
225 : }
226 :
227 0 : OString JavaOptions::prepareHelp()
228 : {
229 0 : OString help("\nusing: ");
230 0 : help += m_program + " [-options] file_1 ... file_n -Xfile_n+1 -Xfile_n+2\nOptions:\n";
231 0 : help += " -O<path> = path describes the root directory for the generated output.\n";
232 0 : help += " The output directory tree is generated under this directory.\n";
233 0 : help += " -T<name> = name specifies a type or a list of types. The output for this\n";
234 0 : help += " [t1;...] type and all dependent types are generated. If no '-T' option is\n";
235 0 : help += " specified, then output for all types is generated.\n";
236 0 : help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
237 0 : help += " -nD = no dependent types are generated.\n";
238 0 : help += " -G = generate only target files which does not exists.\n";
239 0 : help += " -Gc = generate only target files which content will be changed.\n";
240 0 : help += " -X<file> = extra types which will not be taken into account for generation.\n\n";
241 0 : help += prepareVersion();
242 :
243 0 : return help;
244 : }
245 :
246 0 : OString JavaOptions::prepareVersion()
247 : {
248 0 : OString version(m_program);
249 0 : version += " Version 2.0\n\n";
250 0 : return version;
251 : }
252 :
253 :
254 :
255 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|