fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / codemaker / source / cppumaker / cppuoptions.cxx
blob3414a533ee53bdd8bbf471fe6aa4838e83e5a692
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::OUString;
28 using ::rtl::OUStringToOString;
29 using ::rtl::OString;
31 #ifdef SAL_UNX
32 #define SEPARATOR '/'
33 #else
34 #define SEPARATOR '\\'
35 #endif
37 bool CppuOptions::initOptions(int ac, char* av[], bool bCmdFile)
38 throw( IllegalArgument )
40 bool ret = true;
41 sal_uInt16 i=0;
43 if (!bCmdFile)
45 bCmdFile = true;
47 OString name(av[0]);
48 sal_Int32 index = name.lastIndexOf(SEPARATOR);
49 m_program = name.copy((index > 0 ? index+1 : 0));
51 if (ac < 2)
53 fprintf(stderr, "%s", prepareHelp().getStr());
54 ret = false;
57 i = 1;
59 else
61 i = 0;
64 char *s=NULL;
65 for( ; i < ac; i++)
67 if (av[i][0] == '-')
69 switch (av[i][1])
71 case 'O':
72 if (av[i][2] == '\0')
74 if (i < ac - 1 && av[i+1][0] != '-')
76 i++;
77 s = av[i];
79 else
81 OString tmp("'-O', please check");
82 if (i <= ac - 1)
84 tmp += " your input '" + OString(av[i+1]) + "'";
87 throw IllegalArgument(tmp);
90 else
92 s = av[i] + 2;
95 m_options["-O"] = OString(s);
96 break;
97 case 'n':
98 if (av[i][2] != 'D' || av[i][3] != '\0')
100 OString tmp("'-nD', please check");
101 tmp += " your input '" + OString(av[i]) + "'";
102 throw IllegalArgument(tmp);
105 m_options["-nD"] = OString("");
106 break;
107 case 'T':
108 if (av[i][2] == '\0')
110 if (i < ac - 1 && av[i+1][0] != '-')
112 i++;
113 s = av[i];
115 else
117 OString tmp("'-T', please check");
118 if (i <= ac - 1)
120 tmp += " your input '" + OString(av[i+1]) + "'";
123 throw IllegalArgument(tmp);
126 else
128 s = av[i] + 2;
131 if (m_options.count("-T") > 0)
133 OString tmp(m_options["-T"]);
134 tmp = tmp + ";" + s;
135 m_options["-T"] = tmp;
137 else
139 m_options["-T"] = OString(s);
141 break;
142 case 'L':
143 if (av[i][2] != '\0')
145 OString tmp("'-L', please check");
146 if (i <= ac - 1)
148 tmp += " your input '" + OString(av[i]) + "'";
151 throw IllegalArgument(tmp);
154 if (isValid("-C") || isValid("-CS"))
156 OString tmp("'-L' could not be combined with '-C' or '-CS' option");
157 throw IllegalArgument(tmp);
159 m_options["-L"] = OString("");
160 break;
161 case 'C':
162 if (av[i][2] == 'S')
164 if (av[i][3] != '\0')
166 OString tmp("'-CS', please check");
167 if (i <= ac - 1)
169 tmp += " your input '" + OString(av[i]) + "'";
172 throw IllegalArgument(tmp);
175 if (isValid("-L") || isValid("-C"))
177 OString tmp("'-CS' could not be combined with '-L' or '-C' option");
178 throw IllegalArgument(tmp);
180 m_options["-CS"] = OString("");
181 break;
183 else if (av[i][2] != '\0')
185 OString tmp("'-C', please check");
186 if (i <= ac - 1)
188 tmp += " your input '" + OString(av[i]) + "'";
191 throw IllegalArgument(tmp);
194 if (isValid("-L") || isValid("-CS"))
196 OString tmp("'-C' could not be combined with '-L' or '-CS' option");
197 throw IllegalArgument(tmp);
199 m_options["-C"] = OString("");
200 break;
201 case 'G':
202 if (av[i][2] == 'c')
204 if (av[i][3] != '\0')
206 OString tmp("'-Gc', please check");
207 if (i <= ac - 1)
209 tmp += " your input '" + OString(av[i]) + "'";
212 throw IllegalArgument(tmp);
215 m_options["-Gc"] = OString("");
216 break;
218 else if (av[i][2] != '\0')
220 OString tmp("'-G', please check");
221 if (i <= ac - 1)
223 tmp += " your input '" + OString(av[i]) + "'";
226 throw IllegalArgument(tmp);
229 m_options["-G"] = OString("");
230 break;
231 case 'X': // support for eXtra type rdbs
233 if (av[i][2] == '\0')
235 if (i < ac - 1 && av[i+1][0] != '-')
237 i++;
238 s = av[i];
240 else
242 OString tmp("'-X', please check");
243 if (i <= ac - 1)
245 tmp += " your input '" + OString(av[i+1]) + "'";
248 throw IllegalArgument(tmp);
251 else
253 s = av[i] + 2;
256 m_extra_input_files.push_back( s );
257 break;
260 default:
261 throw IllegalArgument("the option is unknown" + OString(av[i]));
263 } else
265 if (av[i][0] == '@')
267 FILE* cmdFile = fopen(av[i]+1, "r");
268 if( cmdFile == NULL )
270 fprintf(stderr, "%s", prepareHelp().getStr());
271 ret = false;
273 else
275 int rargc=0;
276 char* rargv[512];
277 char buffer[512];
279 while (fscanf(cmdFile, "%511s", buffer) != EOF && rargc < 512)
281 rargv[rargc]= strdup(buffer);
282 rargc++;
284 fclose(cmdFile);
286 ret = initOptions(rargc, rargv, bCmdFile);
288 for (long j=0; j < rargc; j++)
290 free(rargv[j]);
294 else
296 m_inputFiles.push_back(av[i]);
301 return ret;
304 OString CppuOptions::prepareHelp()
306 OString help("\nusing: ");
307 help += m_program + " [-options] file_1 ... file_n\nOptions:\n";
308 help += " -O<path> = path describes the root directory for the generated output.\n";
309 help += " The output directory tree is generated under this directory.\n";
310 help += " -T<name> = name specifies a type or a list of types. The output for this\n";
311 help += " [t1;...] type is generated. If no '-T' option is specified,\n";
312 help += " then output for all types is generated.\n";
313 help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
314 help += " -L = UNO type functions are generated lightweight, that means only\n";
315 help += " the name and typeclass are given and everything else is retrieved\n";
316 help += " from the type library dynamically. The default is that UNO type\n";
317 help += " functions provides enough type information for bootstrapping C++.\n";
318 help += " '-L' should be the default for external components.\n";
319 help += " -C = UNO type functions are generated comprehensive that means all\n";
320 help += " necessary information is available for bridging the type in UNO.\n";
321 help += " -nD = no dependent types are generated.\n";
322 help += " -G = generate only target files which does not exists.\n";
323 help += " -Gc = generate only target files which content will be changed.\n";
324 help += " -X<file> = extra types which will not be taken into account for generation.\n\n";
325 help += prepareVersion();
327 return help;
330 OString CppuOptions::prepareVersion()
332 OString version(m_program);
333 version += " Version 2.0\n\n";
334 return version;
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */