Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / codemaker / source / javamaker / javaoptions.cxx
blob4db26c1bbd2345e7c6aa5f81acf25ae06a5bc0b7
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"_ostr);
72 if (i <= ac - 1)
74 tmp += OString::Concat(" your input '") + av[i+1] + "'";
77 throw IllegalArgument(tmp);
79 } else
81 s = av[i] + 2;
84 m_options["-O"_ostr] = OString(s);
85 break;
86 case 'n':
87 if (av[i][2] != 'D' || av[i][3] != '\0')
89 OString tmp(OString::Concat("'-nD', please check your input '") + av[i] + "'");
90 throw IllegalArgument(tmp);
93 m_options["-nD"_ostr] = OString();
94 break;
95 case 'T':
96 if (av[i][2] == '\0')
98 if (i < ac - 1 && av[i+1][0] != '-')
100 i++;
101 s = av[i];
102 } else
104 OString tmp("'-T', please check"_ostr);
105 if (i <= ac - 1)
107 tmp += OString::Concat(" your input '") + av[i+1] + "'";
110 throw IllegalArgument(tmp);
112 } else
114 s = av[i] + 2;
117 if (m_options.count("-T"_ostr) > 0)
119 OString tmp = m_options["-T"_ostr] + ";" + s;
120 m_options["-T"_ostr] = tmp;
121 } else
123 m_options["-T"_ostr] = OString(s);
125 break;
126 case 'G':
127 if (av[i][2] == 'c')
129 if (av[i][3] != '\0')
131 OString tmp("'-Gc', please check"_ostr);
132 if (i <= ac - 1)
134 tmp += OString::Concat(" your input '") + av[i] + "'";
137 throw IllegalArgument(tmp);
140 m_options["-Gc"_ostr] = OString();
141 break;
142 } else if (av[i][2] != '\0')
144 OString tmp("'-G', please check"_ostr);
145 if (i <= ac - 1)
147 tmp += OString::Concat(" your input '") + av[i] + "'";
150 throw IllegalArgument(tmp);
153 m_options["-G"_ostr] = OString();
154 break;
155 case 'X': // support for eXtra type rdbs
157 if (av[i][2] == '\0')
159 if (i < ac - 1 && av[i+1][0] != '-')
161 i++;
162 s = av[i];
163 } else
165 OString tmp("'-X', please check"_ostr);
166 if (i <= ac - 1)
168 tmp += OString::Concat(" your input '") + av[i+1] + "'";
171 throw IllegalArgument(tmp);
173 } else
175 s = av[i] + 2;
178 m_extra_input_files.emplace_back(s );
179 break;
182 default:
183 throw IllegalArgument(OString::Concat("the option is unknown") + av[i]);
185 } else
187 if (av[i][0] == '@')
189 FILE* cmdFile = fopen(av[i]+1, "r");
190 if( cmdFile == nullptr )
192 fprintf(stderr, "%s", prepareHelp().getStr());
193 ret = false;
194 } else
196 int rargc=0;
197 char* rargv[512];
198 char buffer[512];
200 while (fscanf(cmdFile, "%511s", buffer) != EOF && rargc < 512)
202 rargv[rargc]= strdup(buffer);
203 rargc++;
205 fclose(cmdFile);
207 ret = initOptions(rargc, rargv, bCmdFile);
209 for (int j=0; j < rargc; j++)
211 free(rargv[j]);
214 } else
216 m_inputFiles.emplace_back(av[i]);
221 return ret;
224 OString JavaOptions::prepareHelp()
226 OString help = "\nusing: " +
227 m_program + " [-options] file_1 ... file_n -Xfile_n+1 -Xfile_n+2\nOptions:\n"
228 " -O<path> = path describes the root directory for the generated output.\n"
229 " The output directory tree is generated under this directory.\n"
230 " -T<name> = name specifies a type or a list of types. The output for this\n"
231 " [t1;...] type and all dependent types are generated. If no '-T' option is\n"
232 " specified, then output for all types is generated.\n"
233 " Example: 'com.sun.star.uno.XInterface' is a valid type.\n"
234 " -nD = no dependent types are generated.\n"
235 " -G = generate only target files which does not exists.\n"
236 " -Gc = generate only target files which content will be changed.\n"
237 " -X<file> = extra types which will not be taken into account for generation.\n\n" +
238 prepareVersion();
240 return help;
243 OString JavaOptions::prepareVersion() const
245 return m_program + " Version 2.0\n\n";
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */