update credits
[LibreOffice.git] / codemaker / source / cppumaker / cppuoptions.cxx
blob3446134ab5d2b03311699c48255177bec771cd48
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 sal_Bool CppuOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile)
38 throw( IllegalArgument )
40 sal_Bool ret = sal_True;
41 sal_uInt16 i=0;
43 if (!bCmdFile)
45 bCmdFile = sal_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 = sal_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 'T':
98 if (av[i][2] == '\0')
100 if (i < ac - 1 && av[i+1][0] != '-')
102 i++;
103 s = av[i];
105 else
107 OString tmp("'-T', please check");
108 if (i <= ac - 1)
110 tmp += " your input '" + OString(av[i+1]) + "'";
113 throw IllegalArgument(tmp);
116 else
118 s = av[i] + 2;
121 if (m_options.count("-T") > 0)
123 OString tmp(m_options["-T"]);
124 tmp = tmp + ";" + s;
125 m_options["-T"] = tmp;
127 else
129 m_options["-T"] = OString(s);
131 break;
132 case 'L':
133 if (av[i][2] != '\0')
135 OString tmp("'-L', please check");
136 if (i <= ac - 1)
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("");
150 break;
151 case 'C':
152 if (av[i][2] == 'S')
154 if (av[i][3] != '\0')
156 OString tmp("'-CS', please check");
157 if (i <= ac - 1)
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("");
171 break;
173 else if (av[i][2] != '\0')
175 OString tmp("'-C', please check");
176 if (i <= ac - 1)
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("");
190 break;
191 case 'G':
192 if (av[i][2] == 'c')
194 if (av[i][3] != '\0')
196 OString tmp("'-Gc', please check");
197 if (i <= ac - 1)
199 tmp += " your input '" + OString(av[i]) + "'";
202 throw IllegalArgument(tmp);
205 m_options["-Gc"] = OString("");
206 break;
208 else if (av[i][2] != '\0')
210 OString tmp("'-G', please check");
211 if (i <= ac - 1)
213 tmp += " your input '" + OString(av[i]) + "'";
216 throw IllegalArgument(tmp);
219 m_options["-G"] = OString("");
220 break;
221 case 'X': // support for eXtra type rdbs
223 if (av[i][2] == '\0')
225 if (i < ac - 1 && av[i+1][0] != '-')
227 i++;
228 s = av[i];
230 else
232 OString tmp("'-X', please check");
233 if (i <= ac - 1)
235 tmp += " your input '" + OString(av[i+1]) + "'";
238 throw IllegalArgument(tmp);
241 else
243 s = av[i] + 2;
246 m_extra_input_files.push_back( s );
247 break;
250 default:
251 throw IllegalArgument("the option is unknown" + OString(av[i]));
253 } else
255 if (av[i][0] == '@')
257 FILE* cmdFile = fopen(av[i]+1, "r");
258 if( cmdFile == NULL )
260 fprintf(stderr, "%s", prepareHelp().getStr());
261 ret = sal_False;
263 else
265 int rargc=0;
266 char* rargv[512];
267 char buffer[512];
269 while ( fscanf(cmdFile, "%s", buffer) != EOF )
271 rargv[rargc]= strdup(buffer);
272 rargc++;
274 fclose(cmdFile);
276 ret = initOptions(rargc, rargv, bCmdFile);
278 for (long j=0; j < rargc; j++)
280 free(rargv[j]);
284 else
286 if (bCmdFile)
288 m_inputFiles.push_back(av[i]);
290 else
292 OUString system_filepath;
293 if (osl_getCommandArg( i-1, &system_filepath.pData )
294 != osl_Process_E_None)
296 OSL_ASSERT(false);
298 m_inputFiles.push_back(OUStringToOString(system_filepath, osl_getThreadTextEncoding()));
304 return ret;
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();
329 return help;
332 OString CppuOptions::prepareVersion()
334 OString version(m_program);
335 version += " Version 2.0\n\n";
336 return version;
341 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */