cURL: follow redirects
[LibreOffice.git] / codemaker / source / javamaker / javaoptions.cxx
blobbdfa4ebd78d188e7b2ab897339d99aac09f245de
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>
22 #include "javaoptions.hxx"
23 #include "osl/process.h"
24 #include "osl/thread.h"
27 #ifdef SAL_UNX
28 #define SEPARATOR '/'
29 #else
30 #define SEPARATOR '\\'
31 #endif
33 bool JavaOptions::initOptions(int ac, char* av[], bool bCmdFile)
34 throw( IllegalArgument )
36 bool ret = true;
37 sal_uInt16 i=0;
39 if (!bCmdFile)
41 bCmdFile = true;
43 OString name(av[0]);
44 sal_Int32 index = name.lastIndexOf(SEPARATOR);
45 m_program = name.copy((index > 0 ? index+1 : 0));
47 if (ac < 2)
49 fprintf(stderr, "%s", prepareHelp().getStr());
50 ret = false;
53 i = 1;
56 char *s=nullptr;
57 for( ; i < ac; i++)
59 if (av[i][0] == '-')
61 switch (av[i][1])
63 case 'O':
64 if (av[i][2] == '\0')
66 if (i < ac - 1 && av[i+1][0] != '-')
68 i++;
69 s = av[i];
70 } else
72 OString tmp("'-O', please check");
73 if (i <= ac - 1)
75 tmp += " your input '" + OString(av[i+1]) + "'";
78 throw IllegalArgument(tmp);
80 } else
82 s = av[i] + 2;
85 m_options["-O"] = OString(s);
86 break;
87 case 'n':
88 if (av[i][2] != 'D' || av[i][3] != '\0')
90 OString tmp("'-nD', please check");
91 tmp += " your input '" + OString(av[i]) + "'";
92 throw IllegalArgument(tmp);
95 m_options["-nD"] = OString("");
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];
104 } else
106 OString tmp("'-T', please check");
107 if (i <= ac - 1)
109 tmp += " your input '" + OString(av[i+1]) + "'";
112 throw IllegalArgument(tmp);
114 } else
116 s = av[i] + 2;
119 if (m_options.count("-T") > 0)
121 OString tmp(m_options["-T"]);
122 tmp = tmp + ";" + s;
123 m_options["-T"] = tmp;
124 } else
126 m_options["-T"] = OString(s);
128 break;
129 case 'G':
130 if (av[i][2] == 'c')
132 if (av[i][3] != '\0')
134 OString tmp("'-Gc', please check");
135 if (i <= ac - 1)
137 tmp += " your input '" + OString(av[i]) + "'";
140 throw IllegalArgument(tmp);
143 m_options["-Gc"] = OString("");
144 break;
145 } else if (av[i][2] != '\0')
147 OString tmp("'-G', please check");
148 if (i <= ac - 1)
150 tmp += " your input '" + OString(av[i]) + "'";
153 throw IllegalArgument(tmp);
156 m_options["-G"] = OString("");
157 break;
158 case 'X': // support for eXtra type rdbs
160 if (av[i][2] == '\0')
162 if (i < ac - 1 && av[i+1][0] != '-')
164 i++;
165 s = av[i];
166 } else
168 OString tmp("'-X', please check");
169 if (i <= ac - 1)
171 tmp += " your input '" + OString(av[i+1]) + "'";
174 throw IllegalArgument(tmp);
176 } else
178 s = av[i] + 2;
181 m_extra_input_files.push_back( s );
182 break;
185 default:
186 throw IllegalArgument("the option is unknown" + OString(av[i]));
188 } else
190 if (av[i][0] == '@')
192 FILE* cmdFile = fopen(av[i]+1, "r");
193 if( cmdFile == nullptr )
195 fprintf(stderr, "%s", prepareHelp().getStr());
196 ret = false;
197 } else
199 int rargc=0;
200 char* rargv[512];
201 char buffer[512];
203 while (fscanf(cmdFile, "%511s", buffer) != EOF && rargc < 512)
205 rargv[rargc]= strdup(buffer);
206 rargc++;
208 fclose(cmdFile);
210 ret = initOptions(rargc, rargv, bCmdFile);
212 for (long j=0; j < rargc; j++)
214 free(rargv[j]);
217 } else
219 m_inputFiles.push_back(av[i]);
224 return ret;
227 OString JavaOptions::prepareHelp()
229 OString help("\nusing: ");
230 help += m_program + " [-options] file_1 ... file_n -Xfile_n+1 -Xfile_n+2\nOptions:\n"
231 " -O<path> = path describes the root directory for the generated output.\n"
232 " The output directory tree is generated under this directory.\n"
233 " -T<name> = name specifies a type or a list of types. The output for this\n"
234 " [t1;...] type and all dependent types are generated. If no '-T' option is\n"
235 " specified, then output for all types is generated.\n"
236 " Example: 'com.sun.star.uno.XInterface' is a valid type.\n"
237 " -nD = no dependent types are generated.\n"
238 " -G = generate only target files which does not exists.\n"
239 " -Gc = generate only target files which content will be changed.\n"
240 " -X<file> = extra types which will not be taken into account for generation.\n\n";
241 help += prepareVersion();
243 return help;
246 OString JavaOptions::prepareVersion()
248 OString version(m_program);
249 version += " Version 2.0\n\n";
250 return version;
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */