update dev300-m58
[ooovba.git] / codemaker / source / idlmaker / idloptions.cxx
blob1aa97911daa38fe1fcb9e0fcc781d8a9ff774aa5
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: idloptions.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 "idloptions.hxx"
37 using namespace rtl;
39 sal_Bool IdlOptions::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 'B':
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("'-B', 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["-B"] = OString(s);
117 break;
118 case 'T':
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("'-T', 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 if (m_options.count("-T") > 0)
142 OString tmp(m_options["-T"]);
143 tmp = tmp + ";" + s;
144 m_options["-T"] = tmp;
145 } else
147 m_options["-T"] = OString(s);
149 break;
150 case 'G':
151 if (av[i][2] == 'c')
153 if (av[i][3] != '\0')
155 OString tmp("'-Gc', please check");
156 if (i <= ac - 1)
158 tmp += " your input '" + OString(av[i]) + "'";
161 throw IllegalArgument(tmp);
164 m_options["-Gc"] = OString("");
165 break;
166 } else
167 if (av[i][2] != '\0')
169 OString tmp("'-G', please check");
170 if (i <= ac - 1)
172 tmp += " your input '" + OString(av[i]) + "'";
175 throw IllegalArgument(tmp);
178 m_options["-G"] = OString("");
179 break;
180 default:
181 throw IllegalArgument("the option is unknown" + OString(av[i]));
182 break;
184 } else
186 if (av[i][0] == '@')
188 FILE* cmdFile = fopen(av[i]+1, "r");
189 if( cmdFile == NULL )
191 fprintf(stderr, "%s", prepareHelp().getStr());
192 ret = sal_False;
193 } else
195 int rargc=0;
196 char* rargv[512];
197 char buffer[512];
199 while ( fscanf(cmdFile, "%s", buffer) != EOF )
201 rargv[rargc]= strdup(buffer);
202 rargc++;
204 fclose(cmdFile);
206 ret = initOptions(rargc, rargv, bCmdFile);
208 for (long i=0; i < rargc; i++)
210 free(rargv[i]);
213 } else
215 m_inputFiles.push_back(av[i]);
220 return ret;
223 OString IdlOptions::prepareHelp()
225 OString help("\nusing: ");
226 help += m_program + " [-options] file_1 ... file_n\nOptions:\n";
227 help += " -O<path> = path describes the root directory for the generated output.\n";
228 help += " The output directory tree is generated under this directory.\n";
229 help += " -T<name> = name specifies a type or a list of types. The output for this\n";
230 help += " [t1;...] type is generated. If no '-T' option is specified,\n";
231 help += " then output for all types is generated.\n";
232 help += " Example: 'com.sun.star.uno.XInterface' is a valid type.\n";
233 help += " -B<name> = name specifies the base node. All types are searched under this\n";
234 help += " node. Default is the root '/' of the registry files.\n";
235 help += " -G = generate only target files which does not exists.\n";
236 help += " -Gc = generate only target files which content will be changed.\n";
237 help += "IMPORTANT: You lose enum values and struct, exception inheritance!\n";
238 help += " Parameter name Object is translated to _Object!\n";
239 help += " The type type is translated to CORBA::TypeCode!\n";
240 help += " Sequences are expanded to a typedef name Sequence_..._\"name\"!\n";
241 help += prepareVersion();
243 return help;
246 OString IdlOptions::prepareVersion()
248 OString version("\nSun Microsystems (R) ");
249 version += m_program + " Version 2.0\n\n";
251 return version;