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"
28 #define SEPARATOR '\\'
31 bool CppuOptions::initOptions(int ac
, char* av
[], bool bCmdFile
)
41 sal_Int32 index
= name
.lastIndexOf(SEPARATOR
);
42 m_program
= name
.copy(index
> 0 ? index
+1 : 0);
46 fprintf(stderr
, "%s", prepareHelp().getStr());
67 if (i
< ac
- 1 && av
[i
+1][0] != '-')
74 OString
tmp("'-O', please check"_ostr
);
77 tmp
+= OString::Concat(" your input '") + av
[i
+1] + "'";
80 throw IllegalArgument(tmp
);
88 m_options
["-O"_ostr
] = OString(s
);
91 if (av
[i
][2] != 'D' || av
[i
][3] != '\0')
93 OString tmp
= OString::Concat("'-nD', please check your input '") + av
[i
] + "'";
94 throw IllegalArgument(tmp
);
97 m_options
["-nD"_ostr
] = OString();
100 if (av
[i
][2] == '\0')
102 if (i
< ac
- 1 && av
[i
+1][0] != '-')
109 OString
tmp("'-T', please check"_ostr
);
112 tmp
+= OString::Concat(" your input '") + av
[i
+1] + "'";
115 throw IllegalArgument(tmp
);
123 if (m_options
.count("-T"_ostr
) > 0)
125 OString tmp
= m_options
["-T"_ostr
] + ";" + s
;
126 m_options
["-T"_ostr
] = tmp
;
130 m_options
["-T"_ostr
] = OString(s
);
134 if (av
[i
][2] != '\0')
136 OString
tmp("'-L', please check"_ostr
);
139 tmp
+= OString::Concat(" your input '") + av
[i
] + "'";
142 throw IllegalArgument(tmp
);
145 if (isValid("-C"_ostr
) || isValid("-CS"_ostr
))
147 throw IllegalArgument("'-L' could not be combined with '-C' or '-CS' option"_ostr
);
149 m_options
["-L"_ostr
] = OString();
154 if (av
[i
][3] != '\0')
156 OString
tmp("'-CS', please check"_ostr
);
159 tmp
+= OString::Concat(" your input '") + av
[i
] + "'";
162 throw IllegalArgument(tmp
);
165 if (isValid("-L"_ostr
) || isValid("-C"_ostr
))
167 throw IllegalArgument("'-CS' could not be combined with '-L' or '-C' option"_ostr
);
169 m_options
["-CS"_ostr
] = OString();
172 else if (av
[i
][2] != '\0')
174 OString
tmp("'-C', please check"_ostr
);
177 tmp
+= OString::Concat(" your input '") + av
[i
] + "'";
180 throw IllegalArgument(tmp
);
183 if (isValid("-L"_ostr
) || isValid("-CS"_ostr
))
185 throw IllegalArgument("'-C' could not be combined with '-L' or '-CS' option"_ostr
);
187 m_options
["-C"_ostr
] = OString();
192 if (av
[i
][3] != '\0')
194 OString
tmp("'-Gc', please check"_ostr
);
197 tmp
+= OString::Concat(" your input '") + av
[i
] + "'";
200 throw IllegalArgument(tmp
);
203 m_options
["-Gc"_ostr
] = OString();
206 else if (av
[i
][2] != '\0')
208 OString
tmp("'-G', please check"_ostr
);
211 tmp
+= OString::Concat(" your input '") + av
[i
] + "'";
214 throw IllegalArgument(tmp
);
217 m_options
["-G"_ostr
] = OString();
219 case 'X': // support for eXtra type rdbs
221 if (av
[i
][2] == '\0')
223 if (i
< ac
- 1 && av
[i
+1][0] != '-')
230 OString
tmp("'-X', please check"_ostr
);
233 tmp
+= OString::Concat(" your input '") + av
[i
+1] + "'";
236 throw IllegalArgument(tmp
);
244 m_extra_input_files
.emplace_back(s
);
249 throw IllegalArgument(OString::Concat("the option is unknown") + av
[i
]);
255 FILE* cmdFile
= fopen(av
[i
]+1, "r");
256 if( cmdFile
== nullptr )
258 fprintf(stderr
, "%s", prepareHelp().getStr());
267 while (fscanf(cmdFile
, "%511s", buffer
) != EOF
&& rargc
< 512)
269 rargv
[rargc
]= strdup(buffer
);
274 ret
= initOptions(rargc
, rargv
, bCmdFile
);
276 for (int j
=0; j
< rargc
; j
++)
284 m_inputFiles
.emplace_back(av
[i
]);
292 OString
CppuOptions::prepareHelp()
294 OString help
= "\nusing: " +
295 m_program
+ " [-options] file_1 ... file_n\nOptions:\n"
296 " -O<path> = path describes the root directory for the generated output.\n"
297 " The output directory tree is generated under this directory.\n"
298 " -T<name> = name specifies a type or a list of types. The output for this\n"
299 " [t1;...] type is generated. If no '-T' option is specified,\n"
300 " then output for all types is generated.\n"
301 " Example: 'com.sun.star.uno.XInterface' is a valid type.\n"
302 " -L = UNO type functions are generated lightweight, that means only\n"
303 " the name and typeclass are given and everything else is retrieved\n"
304 " from the type library dynamically. The default is that UNO type\n"
305 " functions provides enough type information for bootstrapping C++.\n"
306 " '-L' should be the default for external components.\n"
307 " -C = UNO type functions are generated comprehensive that means all\n"
308 " necessary information is available for bridging the type in UNO.\n"
309 " -nD = no dependent types are generated.\n"
310 " -G = generate only target files which does not exists.\n"
311 " -Gc = generate only target files which content will be changed.\n"
312 " -X<file> = extra types which will not be taken into account for generation.\n\n" +
318 OString
CppuOptions::prepareVersion() const
320 OString version
= m_program
+ " Version 2.0\n\n";
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */