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"
27 using ::rtl::OUString
;
28 using ::rtl::OUStringToOString
;
34 #define SEPARATOR '\\'
37 bool CppuOptions::initOptions(int ac
, char* av
[], bool bCmdFile
)
38 throw( IllegalArgument
)
48 sal_Int32 index
= name
.lastIndexOf(SEPARATOR
);
49 m_program
= name
.copy((index
> 0 ? index
+1 : 0));
53 fprintf(stderr
, "%s", prepareHelp().getStr());
74 if (i
< ac
- 1 && av
[i
+1][0] != '-')
81 OString
tmp("'-O', please check");
84 tmp
+= " your input '" + OString(av
[i
+1]) + "'";
87 throw IllegalArgument(tmp
);
95 m_options
["-O"] = OString(s
);
98 if (av
[i
][2] != 'D' || av
[i
][3] != '\0')
100 OString
tmp("'-nD', please check");
101 tmp
+= " your input '" + OString(av
[i
]) + "'";
102 throw IllegalArgument(tmp
);
105 m_options
["-nD"] = OString("");
108 if (av
[i
][2] == '\0')
110 if (i
< ac
- 1 && av
[i
+1][0] != '-')
117 OString
tmp("'-T', please check");
120 tmp
+= " your input '" + OString(av
[i
+1]) + "'";
123 throw IllegalArgument(tmp
);
131 if (m_options
.count("-T") > 0)
133 OString
tmp(m_options
["-T"]);
135 m_options
["-T"] = tmp
;
139 m_options
["-T"] = OString(s
);
143 if (av
[i
][2] != '\0')
145 OString
tmp("'-L', please check");
148 tmp
+= " your input '" + OString(av
[i
]) + "'";
151 throw IllegalArgument(tmp
);
154 if (isValid("-C") || isValid("-CS"))
156 OString
tmp("'-L' could not be combined with '-C' or '-CS' option");
157 throw IllegalArgument(tmp
);
159 m_options
["-L"] = OString("");
164 if (av
[i
][3] != '\0')
166 OString
tmp("'-CS', please check");
169 tmp
+= " your input '" + OString(av
[i
]) + "'";
172 throw IllegalArgument(tmp
);
175 if (isValid("-L") || isValid("-C"))
177 OString
tmp("'-CS' could not be combined with '-L' or '-C' option");
178 throw IllegalArgument(tmp
);
180 m_options
["-CS"] = OString("");
183 else if (av
[i
][2] != '\0')
185 OString
tmp("'-C', please check");
188 tmp
+= " your input '" + OString(av
[i
]) + "'";
191 throw IllegalArgument(tmp
);
194 if (isValid("-L") || isValid("-CS"))
196 OString
tmp("'-C' could not be combined with '-L' or '-CS' option");
197 throw IllegalArgument(tmp
);
199 m_options
["-C"] = OString("");
204 if (av
[i
][3] != '\0')
206 OString
tmp("'-Gc', please check");
209 tmp
+= " your input '" + OString(av
[i
]) + "'";
212 throw IllegalArgument(tmp
);
215 m_options
["-Gc"] = OString("");
218 else if (av
[i
][2] != '\0')
220 OString
tmp("'-G', please check");
223 tmp
+= " your input '" + OString(av
[i
]) + "'";
226 throw IllegalArgument(tmp
);
229 m_options
["-G"] = OString("");
231 case 'X': // support for eXtra type rdbs
233 if (av
[i
][2] == '\0')
235 if (i
< ac
- 1 && av
[i
+1][0] != '-')
242 OString
tmp("'-X', please check");
245 tmp
+= " your input '" + OString(av
[i
+1]) + "'";
248 throw IllegalArgument(tmp
);
256 m_extra_input_files
.push_back( s
);
261 throw IllegalArgument("the option is unknown" + OString(av
[i
]));
267 FILE* cmdFile
= fopen(av
[i
]+1, "r");
268 if( cmdFile
== NULL
)
270 fprintf(stderr
, "%s", prepareHelp().getStr());
279 while (fscanf(cmdFile
, "%511s", buffer
) != EOF
&& rargc
< 512)
281 rargv
[rargc
]= strdup(buffer
);
286 ret
= initOptions(rargc
, rargv
, bCmdFile
);
288 for (long j
=0; j
< rargc
; j
++)
296 m_inputFiles
.push_back(av
[i
]);
304 OString
CppuOptions::prepareHelp()
306 OString
help("\nusing: ");
307 help
+= m_program
+ " [-options] file_1 ... file_n\nOptions:\n";
308 help
+= " -O<path> = path describes the root directory for the generated output.\n";
309 help
+= " The output directory tree is generated under this directory.\n";
310 help
+= " -T<name> = name specifies a type or a list of types. The output for this\n";
311 help
+= " [t1;...] type is generated. If no '-T' option is specified,\n";
312 help
+= " then output for all types is generated.\n";
313 help
+= " Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
314 help
+= " -L = UNO type functions are generated lightweight, that means only\n";
315 help
+= " the name and typeclass are given and everything else is retrieved\n";
316 help
+= " from the type library dynamically. The default is that UNO type\n";
317 help
+= " functions provides enough type information for bootstrapping C++.\n";
318 help
+= " '-L' should be the default for external components.\n";
319 help
+= " -C = UNO type functions are generated comprehensive that means all\n";
320 help
+= " necessary information is available for bridging the type in UNO.\n";
321 help
+= " -nD = no dependent types are generated.\n";
322 help
+= " -G = generate only target files which does not exists.\n";
323 help
+= " -Gc = generate only target files which content will be changed.\n";
324 help
+= " -X<file> = extra types which will not be taken into account for generation.\n\n";
325 help
+= prepareVersion();
330 OString
CppuOptions::prepareVersion()
332 OString
version(m_program
);
333 version
+= " Version 2.0\n\n";
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */