lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / codemaker / source / javamaker / javaoptions.cxx
blob612b3d6b2d97dfd7254190b4cd3e31e09a5b4c20
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)
35 bool ret = true;
36 int i=0;
38 if (!bCmdFile)
40 bCmdFile = true;
42 OString name(av[0]);
43 sal_Int32 index = name.lastIndexOf(SEPARATOR);
44 m_program = name.copy(index > 0 ? index+1 : 0);
46 if (ac < 2)
48 fprintf(stderr, "%s", prepareHelp().getStr());
49 ret = false;
52 i = 1;
55 char *s=nullptr;
56 for( ; i < ac; i++)
58 if (av[i][0] == '-')
60 switch (av[i][1])
62 case 'O':
63 if (av[i][2] == '\0')
65 if (i < ac - 1 && av[i+1][0] != '-')
67 i++;
68 s = av[i];
69 } else
71 OString tmp("'-O', please check");
72 if (i <= ac - 1)
74 tmp += " your input '" + OString(av[i+1]) + "'";
77 throw IllegalArgument(tmp);
79 } else
81 s = av[i] + 2;
84 m_options["-O"] = OString(s);
85 break;
86 case 'n':
87 if (av[i][2] != 'D' || av[i][3] != '\0')
89 OString tmp("'-nD', please check");
90 tmp += " your input '" + OString(av[i]) + "'";
91 throw IllegalArgument(tmp);
94 m_options["-nD"] = OString();
95 break;
96 case 'T':
97 if (av[i][2] == '\0')
99 if (i < ac - 1 && av[i+1][0] != '-')
101 i++;
102 s = av[i];
103 } else
105 OString tmp("'-T', please check");
106 if (i <= ac - 1)
108 tmp += " your input '" + OString(av[i+1]) + "'";
111 throw IllegalArgument(tmp);
113 } else
115 s = av[i] + 2;
118 if (m_options.count("-T") > 0)
120 OString tmp(m_options["-T"]);
121 tmp = tmp + ";" + s;
122 m_options["-T"] = tmp;
123 } else
125 m_options["-T"] = OString(s);
127 break;
128 case 'G':
129 if (av[i][2] == 'c')
131 if (av[i][3] != '\0')
133 OString tmp("'-Gc', please check");
134 if (i <= ac - 1)
136 tmp += " your input '" + OString(av[i]) + "'";
139 throw IllegalArgument(tmp);
142 m_options["-Gc"] = OString();
143 break;
144 } else if (av[i][2] != '\0')
146 OString tmp("'-G', please check");
147 if (i <= ac - 1)
149 tmp += " your input '" + OString(av[i]) + "'";
152 throw IllegalArgument(tmp);
155 m_options["-G"] = OString();
156 break;
157 case 'X': // support for eXtra type rdbs
159 if (av[i][2] == '\0')
161 if (i < ac - 1 && av[i+1][0] != '-')
163 i++;
164 s = av[i];
165 } else
167 OString tmp("'-X', please check");
168 if (i <= ac - 1)
170 tmp += " your input '" + OString(av[i+1]) + "'";
173 throw IllegalArgument(tmp);
175 } else
177 s = av[i] + 2;
180 m_extra_input_files.emplace_back(s );
181 break;
184 default:
185 throw IllegalArgument("the option is unknown" + OString(av[i]));
187 } else
189 if (av[i][0] == '@')
191 FILE* cmdFile = fopen(av[i]+1, "r");
192 if( cmdFile == nullptr )
194 fprintf(stderr, "%s", prepareHelp().getStr());
195 ret = false;
196 } else
198 int rargc=0;
199 char* rargv[512];
200 char buffer[512];
202 while (fscanf(cmdFile, "%511s", buffer) != EOF && rargc < 512)
204 rargv[rargc]= strdup(buffer);
205 rargc++;
207 fclose(cmdFile);
209 ret = initOptions(rargc, rargv, bCmdFile);
211 for (int j=0; j < rargc; j++)
213 free(rargv[j]);
216 } else
218 m_inputFiles.emplace_back(av[i]);
223 return ret;
226 OString JavaOptions::prepareHelp()
228 OString help("\nusing: ");
229 help += m_program + " [-options] file_1 ... file_n -Xfile_n+1 -Xfile_n+2\nOptions:\n"
230 " -O<path> = path describes the root directory for the generated output.\n"
231 " The output directory tree is generated under this directory.\n"
232 " -T<name> = name specifies a type or a list of types. The output for this\n"
233 " [t1;...] type and all dependent types are generated. If no '-T' option is\n"
234 " specified, then output for all types is generated.\n"
235 " Example: 'com.sun.star.uno.XInterface' is a valid type.\n"
236 " -nD = no dependent types are generated.\n"
237 " -G = generate only target files which does not exists.\n"
238 " -Gc = generate only target files which content will be changed.\n"
239 " -X<file> = extra types which will not be taken into account for generation.\n\n";
240 help += prepareVersion();
242 return help;
245 OString JavaOptions::prepareVersion() const
247 OString version(m_program);
248 version += " Version 2.0\n\n";
249 return version;
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */