merge the formfield patch from ooo-build
[ooovba.git] / codemaker / source / bonobowrappermaker / corbaoptions.cxx
blob733ba6939782d7b45583ca84aa543f2fec77c9a7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: corbaoptions.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_codemaker.hxx"
33 #include <stdio.h>
35 #include "corbaoptions.hxx"
37 using namespace rtl;
39 sal_Bool CorbaOptions::initOptions(int ac, char* av[], sal_Bool bCmdFile)
40 throw( IllegalArgument )
42 sal_Bool ret = sal_True;
43 sal_uInt16 i=0;
45 if (!bCmdFile)
47 bCmdFile = sal_True;
49 m_program = av[0];
51 if (ac < 2)
53 fprintf(stderr, "%s", prepareHelp().getStr());
54 ret = sal_False;
57 i = 1;
58 } else
60 i = 0;
63 char *s=NULL;
64 for (i; i < ac; i++)
66 if (av[i][0] == '-')
68 switch (av[i][1])
70 case 'O':
71 if (av[i][2] == '\0')
73 if (i < ac - 1 && av[i+1][0] != '-')
75 i++;
76 s = av[i];
77 } else
79 OString tmp("'-O', please check");
80 if (i <= ac - 1)
82 tmp += " your input '" + OString(av[i+1]) + "'";
85 throw IllegalArgument(tmp);
87 } else
89 s = av[i] + 2;
92 m_options["-O"] = OString(s);
93 break;
94 case 'H':
95 if (av[i][2] == '\0')
97 if (i < ac - 1 && av[i+1][0] != '-')
99 i++;
100 s = av[i];
101 } else
103 OString tmp("'-H', please check");
104 if (i <= ac - 1)
106 tmp += " your input '" + OString(av[i+1]) + "'";
109 throw IllegalArgument(tmp);
111 } else
113 s = av[i] + 2;
116 m_options["-H"] = OString(s);
117 break;
118 case 'B':
119 if (av[i][2] == '\0')
121 if (i < ac - 1 && av[i+1][0] != '-')
123 i++;
124 s = av[i];
125 } else
127 OString tmp("'-B', please check");
128 if (i <= ac - 1)
130 tmp += " your input '" + OString(av[i+1]) + "'";
133 throw IllegalArgument(tmp);
135 } else
137 s = av[i] + 2;
140 m_options["-B"] = OString(s);
141 break;
142 case 'T':
143 if (av[i][2] == '\0')
145 if (i < ac - 1 && av[i+1][0] != '-')
147 i++;
148 s = av[i];
149 } else
151 OString tmp("'-T', please check");
152 if (i <= ac - 1)
154 tmp += " your input '" + OString(av[i+1]) + "'";
157 throw IllegalArgument(tmp);
159 } else
161 s = av[i] + 2;
164 if (m_options.count("-T") > 0)
166 OString tmp(m_options["-T"]);
167 tmp = tmp + ";" + s;
168 m_options["-T"] = tmp;
169 } else
171 m_options["-T"] = OString(s);
173 break;
174 case 'G':
175 if (av[i][2] != '\0')
177 OString tmp("'-G', please check");
178 if (i <= ac - 1)
180 tmp += " your input '" + OString(av[i]) + "'";
183 throw IllegalArgument(tmp);
186 m_options["-G"] = OString("");
187 break;
188 default:
189 throw IllegalArgument("the option is unknown" + OString(av[i]));
190 break;
192 } else
194 if (av[i][0] == '@')
196 FILE* cmdFile = fopen(av[i]+1, "r");
197 if( cmdFile == NULL )
199 fprintf(stderr, "%s", prepareHelp().getStr());
200 ret = sal_False;
201 } else
203 int rargc=0;
204 char* rargv[512];
205 char buffer[512];
207 while ( fscanf(cmdFile, "%s", buffer) != EOF )
209 rargv[rargc]= strdup(buffer);
210 rargc++;
212 fclose(cmdFile);
214 ret = initOptions(rargc, rargv, bCmdFile);
216 for (long i=0; i < rargc; i++)
218 free(rargv[i]);
221 } else
223 m_inputFiles.push_back(av[i]);
227 printf("-T: %s\n", m_options["-T"].getStr());
229 return ret;
232 OString CorbaOptions::prepareHelp()
234 OString help("\nusing: ");
235 help += m_program + " [-options] file_1 ... file_n\nOptions:\n";
236 help += " -O<file> = file name for the generated output.\n";
237 help += " The output directory tree is generated under this directory.\n";
238 help += " -T<name> = name specifies a type or a list of types. The output for this\n";
239 help += " [t1;...] type is generated. If no '-T' option is specified,\n";
240 help += " then output for all types is generated.\n";
241 help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
242 help += " -B<name> = name specifies the base node. All types are searched under this\n";
243 help += " node. Default is the root '/' of the registry files.\n";
244 help += " -G = generate only target files which does not exists.\n";
245 help += " -H<header> = include CORBA generated <header>.\n";
246 help += prepareVersion();
248 return help;
251 OString CorbaOptions::prepareVersion()
253 OString version("\nSun Microsystems (R) ");
254 version += m_program + " Version 2.0\n\n";
256 return version;