Bump version to 24.04.3.4
[LibreOffice.git] / codemaker / source / cppumaker / cppuoptions.cxx
blob548b4d369a8e06158c4b80da37c5103759c3ead2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <stdio.h>
21 #include <string.h>
23 #include "cppuoptions.hxx"
25 #ifdef SAL_UNX
26 #define SEPARATOR '/'
27 #else
28 #define SEPARATOR '\\'
29 #endif
31 bool CppuOptions::initOptions(int ac, char* av[], bool bCmdFile)
33 bool ret = true;
34 int i=0;
36 if (!bCmdFile)
38 bCmdFile = true;
40 OString name(av[0]);
41 sal_Int32 index = name.lastIndexOf(SEPARATOR);
42 m_program = name.copy(index > 0 ? index+1 : 0);
44 if (ac < 2)
46 fprintf(stderr, "%s", prepareHelp().getStr());
47 ret = false;
50 i = 1;
52 else
54 i = 0;
57 char *s=nullptr;
58 for( ; i < ac; i++)
60 if (av[i][0] == '-')
62 switch (av[i][1])
64 case 'O':
65 if (av[i][2] == '\0')
67 if (i < ac - 1 && av[i+1][0] != '-')
69 i++;
70 s = av[i];
72 else
74 OString tmp("'-O', please check"_ostr);
75 if (i <= ac - 1)
77 tmp += OString::Concat(" your input '") + av[i+1] + "'";
80 throw IllegalArgument(tmp);
83 else
85 s = av[i] + 2;
88 m_options["-O"_ostr] = OString(s);
89 break;
90 case 'n':
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();
98 break;
99 case 'T':
100 if (av[i][2] == '\0')
102 if (i < ac - 1 && av[i+1][0] != '-')
104 i++;
105 s = av[i];
107 else
109 OString tmp("'-T', please check"_ostr);
110 if (i <= ac - 1)
112 tmp += OString::Concat(" your input '") + av[i+1] + "'";
115 throw IllegalArgument(tmp);
118 else
120 s = av[i] + 2;
123 if (m_options.count("-T"_ostr) > 0)
125 OString tmp = m_options["-T"_ostr] + ";" + s;
126 m_options["-T"_ostr] = tmp;
128 else
130 m_options["-T"_ostr] = OString(s);
132 break;
133 case 'L':
134 if (av[i][2] != '\0')
136 OString tmp("'-L', please check"_ostr);
137 if (i <= ac - 1)
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();
150 break;
151 case 'C':
152 if (av[i][2] == 'S')
154 if (av[i][3] != '\0')
156 OString tmp("'-CS', please check"_ostr);
157 if (i <= ac - 1)
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();
170 break;
172 else if (av[i][2] != '\0')
174 OString tmp("'-C', please check"_ostr);
175 if (i <= ac - 1)
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();
188 break;
189 case 'G':
190 if (av[i][2] == 'c')
192 if (av[i][3] != '\0')
194 OString tmp("'-Gc', please check"_ostr);
195 if (i <= ac - 1)
197 tmp += OString::Concat(" your input '") + av[i] + "'";
200 throw IllegalArgument(tmp);
203 m_options["-Gc"_ostr] = OString();
204 break;
206 else if (av[i][2] != '\0')
208 OString tmp("'-G', please check"_ostr);
209 if (i <= ac - 1)
211 tmp += OString::Concat(" your input '") + av[i] + "'";
214 throw IllegalArgument(tmp);
217 m_options["-G"_ostr] = OString();
218 break;
219 case 'W': // generate embind javascript bindings for LOWA
220 if (av[i][2] != '\0')
222 OString tmp("'-W', please check"_ostr);
223 if (i <= ac - 1)
225 tmp += OString::Concat(" your input '") + av[i] + "'";
228 throw IllegalArgument(tmp);
231 if (!isValid("-C"_ostr) && !isValid("-CS"_ostr) && !isValid("-L"_ostr))
233 throw IllegalArgument("'-W' requires '-C' or '-CS' or '-L' option"_ostr);
235 m_options["-W"_ostr] = OString();
236 break;
237 case 'X': // support for eXtra type rdbs
239 if (av[i][2] == '\0')
241 if (i < ac - 1 && av[i+1][0] != '-')
243 i++;
244 s = av[i];
246 else
248 OString tmp("'-X', please check"_ostr);
249 if (i <= ac - 1)
251 tmp += OString::Concat(" your input '") + av[i+1] + "'";
254 throw IllegalArgument(tmp);
257 else
259 s = av[i] + 2;
262 m_extra_input_files.emplace_back(s );
263 break;
266 default:
267 throw IllegalArgument(OString::Concat("the option is unknown") + av[i]);
269 } else
271 if (av[i][0] == '@')
273 FILE* cmdFile = fopen(av[i]+1, "r");
274 if( cmdFile == nullptr )
276 fprintf(stderr, "%s", prepareHelp().getStr());
277 ret = false;
279 else
281 int rargc=0;
282 char* rargv[512];
283 char buffer[512];
285 while (fscanf(cmdFile, "%511s", buffer) != EOF && rargc < 512)
287 rargv[rargc]= strdup(buffer);
288 rargc++;
290 fclose(cmdFile);
292 ret = initOptions(rargc, rargv, bCmdFile);
294 for (int j=0; j < rargc; j++)
296 free(rargv[j]);
300 else
302 m_inputFiles.emplace_back(av[i]);
307 return ret;
310 OString CppuOptions::prepareHelp()
312 OString help = "\nusing: " +
313 m_program + " [-options] file_1 ... file_n\nOptions:\n"
314 " -O<path> = path describes the root directory for the generated output.\n"
315 " The output directory tree is generated under this directory.\n"
316 " -T<name> = name specifies a type or a list of types. The output for this\n"
317 " [t1;...] type is generated. If no '-T' option is specified,\n"
318 " then output for all types is generated.\n"
319 " Example: 'com.sun.star.uno.XInterface' is a valid type.\n"
320 " -L = UNO type functions are generated lightweight, that means only\n"
321 " the name and typeclass are given and everything else is retrieved\n"
322 " from the type library dynamically. The default is that UNO type\n"
323 " functions provides enough type information for bootstrapping C++.\n"
324 " '-L' should be the default for external components.\n"
325 " -C = UNO type functions are generated comprehensive that means all\n"
326 " necessary information is available for bridging the type in UNO.\n"
327 " -nD = no dependent types are generated.\n"
328 " -G = generate only target files which does not exists.\n"
329 " -Gc = generate only target files which content will be changed.\n"
330 " -X<file> = extra types which will not be taken into account for generation.\n\n" +
331 prepareVersion();
333 return help;
336 OString CppuOptions::prepareVersion() const
338 OString version = m_program + " Version 2.0\n\n";
339 return version;
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */