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 sal_Bool
CppuOptions::initOptions(int ac
, char* av
[], sal_Bool bCmdFile
)
38 throw( IllegalArgument
)
40 sal_Bool ret
= sal_True
;
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
);
100 if (i
< ac
- 1 && av
[i
+1][0] != '-')
107 OString
tmp("'-T', please check");
110 tmp
+= " your input '" + OString(av
[i
+1]) + "'";
113 throw IllegalArgument(tmp
);
121 if (m_options
.count("-T") > 0)
123 OString
tmp(m_options
["-T"]);
125 m_options
["-T"] = tmp
;
129 m_options
["-T"] = OString(s
);
133 if (av
[i
][2] != '\0')
135 OString
tmp("'-L', please check");
138 tmp
+= " your input '" + OString(av
[i
]) + "'";
141 throw IllegalArgument(tmp
);
144 if (isValid("-C") || isValid("-CS"))
146 OString
tmp("'-L' could not be combined with '-C' or '-CS' option");
147 throw IllegalArgument(tmp
);
149 m_options
["-L"] = OString("");
154 if (av
[i
][3] != '\0')
156 OString
tmp("'-CS', please check");
159 tmp
+= " your input '" + OString(av
[i
]) + "'";
162 throw IllegalArgument(tmp
);
165 if (isValid("-L") || isValid("-C"))
167 OString
tmp("'-CS' could not be combined with '-L' or '-C' option");
168 throw IllegalArgument(tmp
);
170 m_options
["-CS"] = OString("");
173 else if (av
[i
][2] != '\0')
175 OString
tmp("'-C', please check");
178 tmp
+= " your input '" + OString(av
[i
]) + "'";
181 throw IllegalArgument(tmp
);
184 if (isValid("-L") || isValid("-CS"))
186 OString
tmp("'-C' could not be combined with '-L' or '-CS' option");
187 throw IllegalArgument(tmp
);
189 m_options
["-C"] = OString("");
194 if (av
[i
][3] != '\0')
196 OString
tmp("'-Gc', please check");
199 tmp
+= " your input '" + OString(av
[i
]) + "'";
202 throw IllegalArgument(tmp
);
205 m_options
["-Gc"] = OString("");
208 else if (av
[i
][2] != '\0')
210 OString
tmp("'-G', please check");
213 tmp
+= " your input '" + OString(av
[i
]) + "'";
216 throw IllegalArgument(tmp
);
219 m_options
["-G"] = OString("");
221 case 'X': // support for eXtra type rdbs
223 if (av
[i
][2] == '\0')
225 if (i
< ac
- 1 && av
[i
+1][0] != '-')
232 OString
tmp("'-X', please check");
235 tmp
+= " your input '" + OString(av
[i
+1]) + "'";
238 throw IllegalArgument(tmp
);
246 m_extra_input_files
.push_back( s
);
251 throw IllegalArgument("the option is unknown" + OString(av
[i
]));
257 FILE* cmdFile
= fopen(av
[i
]+1, "r");
258 if( cmdFile
== NULL
)
260 fprintf(stderr
, "%s", prepareHelp().getStr());
269 while ( fscanf(cmdFile
, "%s", buffer
) != EOF
)
271 rargv
[rargc
]= strdup(buffer
);
276 ret
= initOptions(rargc
, rargv
, bCmdFile
);
278 for (long j
=0; j
< rargc
; j
++)
288 m_inputFiles
.push_back(av
[i
]);
292 OUString system_filepath
;
293 if (osl_getCommandArg( i
-1, &system_filepath
.pData
)
294 != osl_Process_E_None
)
298 m_inputFiles
.push_back(OUStringToOString(system_filepath
, osl_getThreadTextEncoding()));
307 OString
CppuOptions::prepareHelp()
309 OString
help("\nusing: ");
310 help
+= m_program
+ " [-options] file_1 ... file_n\nOptions:\n";
311 help
+= " -O<path> = path describes the root directory for the generated output.\n";
312 help
+= " The output directory tree is generated under this directory.\n";
313 help
+= " -T<name> = name specifies a type or a list of types. The output for this\n";
314 help
+= " [t1;...] type is generated. If no '-T' option is specified,\n";
315 help
+= " then output for all types is generated.\n";
316 help
+= " Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
317 help
+= " -L = UNO type functions are generated lightweight, that means only\n";
318 help
+= " the name and typeclass are given and everything else is retrieved\n";
319 help
+= " from the type library dynamically. The default is that UNO type\n";
320 help
+= " functions provides enough type information for boostrapping C++.\n";
321 help
+= " '-L' should be the default for external components.\n";
322 help
+= " -C = UNO type functions are generated comprehensive that means all\n";
323 help
+= " necessary information is available for bridging the type in UNO.\n";
324 help
+= " -G = generate only target files which does not exists.\n";
325 help
+= " -Gc = generate only target files which content will be changed.\n";
326 help
+= " -X<file> = extra types which will not be taken into account for generation.\n\n";
327 help
+= prepareVersion();
332 OString
CppuOptions::prepareVersion()
334 OString
version(m_program
);
335 version
+= " Version 2.0\n\n";
341 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */