1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
23 #include "cppuoptions.hxx"
24 #include <osl/thread.h>
25 #include <osl/process.h>
32 #define SEPARATOR '\\'
35 bool CppuOptions::initOptions(int ac
, char* av
[], bool bCmdFile
)
45 sal_Int32 index
= name
.lastIndexOf(SEPARATOR
);
46 m_program
= name
.copy(index
> 0 ? index
+1 : 0);
50 fprintf(stderr
, "%s", prepareHelp().getStr());
71 if (i
< ac
- 1 && av
[i
+1][0] != '-')
78 OString
tmp("'-O', please check");
81 tmp
+= " your input '" + OString(av
[i
+1]) + "'";
84 throw IllegalArgument(tmp
);
92 m_options
["-O"] = OString(s
);
95 if (av
[i
][2] != 'D' || av
[i
][3] != '\0')
97 OString tmp
= "'-nD', please check your input '" + OString(av
[i
]) + "'";
98 throw IllegalArgument(tmp
);
101 m_options
["-nD"] = OString();
104 if (av
[i
][2] == '\0')
106 if (i
< ac
- 1 && av
[i
+1][0] != '-')
113 OString
tmp("'-T', please check");
116 tmp
+= " your input '" + OString(av
[i
+1]) + "'";
119 throw IllegalArgument(tmp
);
127 if (m_options
.count("-T") > 0)
129 OString
tmp(m_options
["-T"]);
131 m_options
["-T"] = tmp
;
135 m_options
["-T"] = OString(s
);
139 if (av
[i
][2] != '\0')
141 OString
tmp("'-L', please check");
144 tmp
+= " your input '" + OString(av
[i
]) + "'";
147 throw IllegalArgument(tmp
);
150 if (isValid("-C") || isValid("-CS"))
152 throw IllegalArgument("'-L' could not be combined with '-C' or '-CS' option");
154 m_options
["-L"] = OString();
159 if (av
[i
][3] != '\0')
161 OString
tmp("'-CS', please check");
164 tmp
+= " your input '" + OString(av
[i
]) + "'";
167 throw IllegalArgument(tmp
);
170 if (isValid("-L") || isValid("-C"))
172 throw IllegalArgument("'-CS' could not be combined with '-L' or '-C' option");
174 m_options
["-CS"] = OString();
177 else if (av
[i
][2] != '\0')
179 OString
tmp("'-C', please check");
182 tmp
+= " your input '" + OString(av
[i
]) + "'";
185 throw IllegalArgument(tmp
);
188 if (isValid("-L") || isValid("-CS"))
190 throw IllegalArgument("'-C' could not be combined with '-L' or '-CS' option");
192 m_options
["-C"] = OString();
197 if (av
[i
][3] != '\0')
199 OString
tmp("'-Gc', please check");
202 tmp
+= " your input '" + OString(av
[i
]) + "'";
205 throw IllegalArgument(tmp
);
208 m_options
["-Gc"] = OString();
211 else if (av
[i
][2] != '\0')
213 OString
tmp("'-G', please check");
216 tmp
+= " your input '" + OString(av
[i
]) + "'";
219 throw IllegalArgument(tmp
);
222 m_options
["-G"] = OString();
224 case 'X': // support for eXtra type rdbs
226 if (av
[i
][2] == '\0')
228 if (i
< ac
- 1 && av
[i
+1][0] != '-')
235 OString
tmp("'-X', please check");
238 tmp
+= " your input '" + OString(av
[i
+1]) + "'";
241 throw IllegalArgument(tmp
);
249 m_extra_input_files
.emplace_back(s
);
254 throw IllegalArgument("the option is unknown" + OString(av
[i
]));
260 FILE* cmdFile
= fopen(av
[i
]+1, "r");
261 if( cmdFile
== nullptr )
263 fprintf(stderr
, "%s", prepareHelp().getStr());
272 while (fscanf(cmdFile
, "%511s", buffer
) != EOF
&& rargc
< 512)
274 rargv
[rargc
]= strdup(buffer
);
279 ret
= initOptions(rargc
, rargv
, bCmdFile
);
281 for (int j
=0; j
< rargc
; j
++)
289 m_inputFiles
.emplace_back(av
[i
]);
297 OString
CppuOptions::prepareHelp()
299 OString
help("\nusing: ");
300 help
+= m_program
+ " [-options] file_1 ... file_n\nOptions:\n"
301 " -O<path> = path describes the root directory for the generated output.\n"
302 " The output directory tree is generated under this directory.\n"
303 " -T<name> = name specifies a type or a list of types. The output for this\n"
304 " [t1;...] type is generated. If no '-T' option is specified,\n"
305 " then output for all types is generated.\n"
306 " Example: 'com.sun.star.uno.XInterface' is a valid type.\n"
307 " -L = UNO type functions are generated lightweight, that means only\n"
308 " the name and typeclass are given and everything else is retrieved\n"
309 " from the type library dynamically. The default is that UNO type\n"
310 " functions provides enough type information for bootstrapping C++.\n"
311 " '-L' should be the default for external components.\n"
312 " -C = UNO type functions are generated comprehensive that means all\n"
313 " necessary information is available for bridging the type in UNO.\n"
314 " -nD = no dependent types are generated.\n"
315 " -G = generate only target files which does not exists.\n"
316 " -Gc = generate only target files which content will be changed.\n"
317 " -X<file> = extra types which will not be taken into account for generation.\n\n";
318 help
+= prepareVersion();
323 OString
CppuOptions::prepareVersion() const
325 OString version
= m_program
+ " Version 2.0\n\n";
330 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */