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