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
)
36 throw( IllegalArgument
)
46 sal_Int32 index
= name
.lastIndexOf(SEPARATOR
);
47 m_program
= name
.copy((index
> 0 ? index
+1 : 0));
51 fprintf(stderr
, "%s", prepareHelp().getStr());
72 if (i
< ac
- 1 && av
[i
+1][0] != '-')
79 OString
tmp("'-O', please check");
82 tmp
+= " your input '" + OString(av
[i
+1]) + "'";
85 throw IllegalArgument(tmp
);
93 m_options
["-O"] = OString(s
);
96 if (av
[i
][2] != 'D' || av
[i
][3] != '\0')
98 OString
tmp("'-nD', please check");
99 tmp
+= " your input '" + OString(av
[i
]) + "'";
100 throw IllegalArgument(tmp
);
103 m_options
["-nD"] = OString("");
106 if (av
[i
][2] == '\0')
108 if (i
< ac
- 1 && av
[i
+1][0] != '-')
115 OString
tmp("'-T', please check");
118 tmp
+= " your input '" + OString(av
[i
+1]) + "'";
121 throw IllegalArgument(tmp
);
129 if (m_options
.count("-T") > 0)
131 OString
tmp(m_options
["-T"]);
133 m_options
["-T"] = tmp
;
137 m_options
["-T"] = OString(s
);
141 if (av
[i
][2] != '\0')
143 OString
tmp("'-L', please check");
146 tmp
+= " your input '" + OString(av
[i
]) + "'";
149 throw IllegalArgument(tmp
);
152 if (isValid("-C") || isValid("-CS"))
154 OString
tmp("'-L' could not be combined with '-C' or '-CS' option");
155 throw IllegalArgument(tmp
);
157 m_options
["-L"] = OString("");
162 if (av
[i
][3] != '\0')
164 OString
tmp("'-CS', please check");
167 tmp
+= " your input '" + OString(av
[i
]) + "'";
170 throw IllegalArgument(tmp
);
173 if (isValid("-L") || isValid("-C"))
175 OString
tmp("'-CS' could not be combined with '-L' or '-C' option");
176 throw IllegalArgument(tmp
);
178 m_options
["-CS"] = OString("");
181 else if (av
[i
][2] != '\0')
183 OString
tmp("'-C', please check");
186 tmp
+= " your input '" + OString(av
[i
]) + "'";
189 throw IllegalArgument(tmp
);
192 if (isValid("-L") || isValid("-CS"))
194 OString
tmp("'-C' could not be combined with '-L' or '-CS' option");
195 throw IllegalArgument(tmp
);
197 m_options
["-C"] = OString("");
202 if (av
[i
][3] != '\0')
204 OString
tmp("'-Gc', please check");
207 tmp
+= " your input '" + OString(av
[i
]) + "'";
210 throw IllegalArgument(tmp
);
213 m_options
["-Gc"] = OString("");
216 else if (av
[i
][2] != '\0')
218 OString
tmp("'-G', please check");
221 tmp
+= " your input '" + OString(av
[i
]) + "'";
224 throw IllegalArgument(tmp
);
227 m_options
["-G"] = OString("");
229 case 'X': // support for eXtra type rdbs
231 if (av
[i
][2] == '\0')
233 if (i
< ac
- 1 && av
[i
+1][0] != '-')
240 OString
tmp("'-X', please check");
243 tmp
+= " your input '" + OString(av
[i
+1]) + "'";
246 throw IllegalArgument(tmp
);
254 m_extra_input_files
.push_back( s
);
259 throw IllegalArgument("the option is unknown" + OString(av
[i
]));
265 FILE* cmdFile
= fopen(av
[i
]+1, "r");
266 if( cmdFile
== nullptr )
268 fprintf(stderr
, "%s", prepareHelp().getStr());
277 while (fscanf(cmdFile
, "%511s", buffer
) != EOF
&& rargc
< 512)
279 rargv
[rargc
]= strdup(buffer
);
284 ret
= initOptions(rargc
, rargv
, bCmdFile
);
286 for (long j
=0; j
< rargc
; j
++)
294 m_inputFiles
.push_back(av
[i
]);
302 OString
CppuOptions::prepareHelp()
304 OString
help("\nusing: ");
305 help
+= m_program
+ " [-options] file_1 ... file_n\nOptions:\n";
306 help
+= " -O<path> = path describes the root directory for the generated output.\n";
307 help
+= " The output directory tree is generated under this directory.\n";
308 help
+= " -T<name> = name specifies a type or a list of types. The output for this\n";
309 help
+= " [t1;...] type is generated. If no '-T' option is specified,\n";
310 help
+= " then output for all types is generated.\n";
311 help
+= " Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
312 help
+= " -L = UNO type functions are generated lightweight, that means only\n";
313 help
+= " the name and typeclass are given and everything else is retrieved\n";
314 help
+= " from the type library dynamically. The default is that UNO type\n";
315 help
+= " functions provides enough type information for bootstrapping C++.\n";
316 help
+= " '-L' should be the default for external components.\n";
317 help
+= " -C = UNO type functions are generated comprehensive that means all\n";
318 help
+= " necessary information is available for bridging the type in UNO.\n";
319 help
+= " -nD = no dependent types are generated.\n";
320 help
+= " -G = generate only target files which does not exists.\n";
321 help
+= " -Gc = generate only target files which content will be changed.\n";
322 help
+= " -X<file> = extra types which will not be taken into account for generation.\n\n";
323 help
+= prepareVersion();
328 OString
CppuOptions::prepareVersion()
330 OString
version(m_program
);
331 version
+= " Version 2.0\n\n";
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */