Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / codemaker / source / cppumaker / cppuoptions.cxx
blob01e5f8c033e42adb31c27b63403a1841b2055d34
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"
24 #include "osl/thread.h"
25 #include "osl/process.h"
27 using ::rtl::OString;
29 #ifdef SAL_UNX
30 #define SEPARATOR '/'
31 #else
32 #define SEPARATOR '\\'
33 #endif
35 bool CppuOptions::initOptions(int ac, char* av[], bool bCmdFile)
36 throw( IllegalArgument )
38 bool ret = true;
39 sal_uInt16 i=0;
41 if (!bCmdFile)
43 bCmdFile = true;
45 OString name(av[0]);
46 sal_Int32 index = name.lastIndexOf(SEPARATOR);
47 m_program = name.copy((index > 0 ? index+1 : 0));
49 if (ac < 2)
51 fprintf(stderr, "%s", prepareHelp().getStr());
52 ret = false;
55 i = 1;
57 else
59 i = 0;
62 char *s=nullptr;
63 for( ; i < ac; i++)
65 if (av[i][0] == '-')
67 switch (av[i][1])
69 case 'O':
70 if (av[i][2] == '\0')
72 if (i < ac - 1 && av[i+1][0] != '-')
74 i++;
75 s = av[i];
77 else
79 OString tmp("'-O', please check");
80 if (i <= ac - 1)
82 tmp += " your input '" + OString(av[i+1]) + "'";
85 throw IllegalArgument(tmp);
88 else
90 s = av[i] + 2;
93 m_options["-O"] = OString(s);
94 break;
95 case 'n':
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("");
104 break;
105 case 'T':
106 if (av[i][2] == '\0')
108 if (i < ac - 1 && av[i+1][0] != '-')
110 i++;
111 s = av[i];
113 else
115 OString tmp("'-T', please check");
116 if (i <= ac - 1)
118 tmp += " your input '" + OString(av[i+1]) + "'";
121 throw IllegalArgument(tmp);
124 else
126 s = av[i] + 2;
129 if (m_options.count("-T") > 0)
131 OString tmp(m_options["-T"]);
132 tmp = tmp + ";" + s;
133 m_options["-T"] = tmp;
135 else
137 m_options["-T"] = OString(s);
139 break;
140 case 'L':
141 if (av[i][2] != '\0')
143 OString tmp("'-L', please check");
144 if (i <= ac - 1)
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("");
158 break;
159 case 'C':
160 if (av[i][2] == 'S')
162 if (av[i][3] != '\0')
164 OString tmp("'-CS', please check");
165 if (i <= ac - 1)
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("");
179 break;
181 else if (av[i][2] != '\0')
183 OString tmp("'-C', please check");
184 if (i <= ac - 1)
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("");
198 break;
199 case 'G':
200 if (av[i][2] == 'c')
202 if (av[i][3] != '\0')
204 OString tmp("'-Gc', please check");
205 if (i <= ac - 1)
207 tmp += " your input '" + OString(av[i]) + "'";
210 throw IllegalArgument(tmp);
213 m_options["-Gc"] = OString("");
214 break;
216 else if (av[i][2] != '\0')
218 OString tmp("'-G', please check");
219 if (i <= ac - 1)
221 tmp += " your input '" + OString(av[i]) + "'";
224 throw IllegalArgument(tmp);
227 m_options["-G"] = OString("");
228 break;
229 case 'X': // support for eXtra type rdbs
231 if (av[i][2] == '\0')
233 if (i < ac - 1 && av[i+1][0] != '-')
235 i++;
236 s = av[i];
238 else
240 OString tmp("'-X', please check");
241 if (i <= ac - 1)
243 tmp += " your input '" + OString(av[i+1]) + "'";
246 throw IllegalArgument(tmp);
249 else
251 s = av[i] + 2;
254 m_extra_input_files.push_back( s );
255 break;
258 default:
259 throw IllegalArgument("the option is unknown" + OString(av[i]));
261 } else
263 if (av[i][0] == '@')
265 FILE* cmdFile = fopen(av[i]+1, "r");
266 if( cmdFile == nullptr )
268 fprintf(stderr, "%s", prepareHelp().getStr());
269 ret = false;
271 else
273 int rargc=0;
274 char* rargv[512];
275 char buffer[512];
277 while (fscanf(cmdFile, "%511s", buffer) != EOF && rargc < 512)
279 rargv[rargc]= strdup(buffer);
280 rargc++;
282 fclose(cmdFile);
284 ret = initOptions(rargc, rargv, bCmdFile);
286 for (long j=0; j < rargc; j++)
288 free(rargv[j]);
292 else
294 m_inputFiles.push_back(av[i]);
299 return ret;
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();
325 return help;
328 OString CppuOptions::prepareVersion()
330 OString version(m_program);
331 version += " Version 2.0\n\n";
332 return version;
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */