1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: options.cxx,v $
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_idlc.hxx"
35 #include /*MSVC trouble: <cstring>*/ <string.h>
36 #include <idlc/options.hxx>
40 Options::Options(): m_stdin(false)
48 sal_Bool
Options::initOptions(int ac
, char* av
[], sal_Bool bCmdFile
)
49 throw( IllegalArgument
)
51 sal_Bool ret
= sal_True
;
62 fprintf(stderr
, "%s", prepareHelp().getStr());
82 if (j
< ac
- 1 && av
[j
+1][0] != '-')
88 OString
tmp("'-O', please check");
91 tmp
+= " your input '" + OString(av
[j
+1]) + "'";
94 throw IllegalArgument(tmp
);
101 m_options
["-O"] = OString(s
);
105 if (av
[j
][2] == '\0')
107 if (j
< ac
- 1 && av
[j
+1][0] != '-')
113 OString
tmp("'-I', please check");
116 tmp
+= " your input '" + OString(av
[j
+1]) + "'";
119 throw IllegalArgument(tmp
);
127 if ( inc
.indexOf(';') > 0 )
130 sal_Int32 nIndex
= 0;
132 do inc
= inc
+ " -I\"" + tmp
.getToken( 0, ';', nIndex
) +"\""; while( nIndex
!= -1 );
134 inc
= OString("-I\"") + s
+ "\"";
136 if (m_options
.count("-I") > 0)
138 OString
tmp(m_options
["-I"]);
139 tmp
= tmp
+ " " + inc
;
140 m_options
["-I"] = tmp
;
143 m_options
["-I"] = inc
;
148 if (av
[j
][2] == '\0')
150 if (j
< ac
- 1 && av
[j
+1][0] != '-')
156 OString
tmp("'-D', please check");
159 tmp
+= " your input '" + OString(av
[j
+1]) + "'";
162 throw IllegalArgument(tmp
);
169 if (m_options
.count("-D") > 0)
171 OString
tmp(m_options
["-D"]);
173 m_options
["-D"] = tmp
;
175 m_options
["-D"] = OString(s
);
178 if (av
[j
][2] != '\0')
180 throw IllegalArgument(OString(av
[j
]) + ", please check your input");
182 if (m_options
.count("-C") == 0)
183 m_options
["-C"] = OString(av
[j
]);
186 if (av
[j
][2] == 'i' && av
[j
][3] == 'd' && av
[j
][4] == '\0')
188 if (m_options
.count("-cid") == 0)
189 m_options
["-cid"] = OString(av
[j
]);
191 throw IllegalArgument(OString(av
[j
]) + ", please check your input");
194 if (av
[j
][2] == 'e' && av
[j
][3] == '\0') {
195 if (m_options
.count("-we") == 0)
196 m_options
["-we"] = OString(av
[j
]);
198 if (av
[j
][2] == '\0') {
199 if (m_options
.count("-w") == 0)
200 m_options
["-w"] = OString(av
[j
]);
202 throw IllegalArgument(OString(av
[j
]) + ", please check your input");
207 if (av
[j
][2] != '\0')
209 throw IllegalArgument(OString(av
[j
]) + ", please check your input");
212 fprintf(stdout
, "%s", prepareHelp().getStr());
216 if (/*MSVC trouble: std::*/strcmp(&av
[j
][2], "tdin") == 0)
223 throw IllegalArgument("the option is unknown" + OString(av
[j
]));
229 FILE* cmdFile
= fopen(av
[j
]+1, "r");
230 if( cmdFile
== NULL
)
232 fprintf(stderr
, "%s", prepareHelp().getStr());
243 while ( fscanf(cmdFile
, "%c", &c
) != EOF
)
253 if (c
!=13 && c
!=10) {
254 if (found
|| c
!=' ') {
265 rargv
[rargc
]= strdup(buffer
);
269 if (buffer
[0] != '\0') {
271 rargv
[rargc
]= strdup(buffer
);
276 ret
= initOptions(rargc
, rargv
, bCmdFile
);
279 for (ii
=0; ii
< rargc
; ii
++)
287 name
= name
.toAsciiLowerCase();
288 if ( name
.lastIndexOf(".idl") != (name
.getLength() - 4) )
290 throw IllegalArgument("'" + OString(av
[j
]) +
291 "' is not a valid input file, only '*.idl' files will be accepted");
293 m_inputFiles
.push_back(av
[j
]);
301 OString
Options::prepareHelp()
303 OString
help("\nusing: ");
305 + " [-options] <file_1> ... <file_n> | @<filename> | -stdin\n";
306 help
+= " <file_n> = file_n specifies one or more idl files.\n";
307 help
+= " Only files with the extension '.idl' are valid.\n";
308 help
+= " @<filename> = filename specifies the name of a command file.\n";
309 help
+= " -stdin = read idl file from standard input.\n";
310 help
+= " Options:\n";
311 help
+= " -O<path> = path specifies the output directory.\n";
312 help
+= " The generated output is a registry file with\n";
313 help
+= " the same name as the idl input file (or 'stdin'\n";
314 help
+= " for -stdin).\n";
315 help
+= " -I<path> = path specifies a directory where include\n";
316 help
+= " files will be searched by the preprocessor.\n";
317 help
+= " Multiple directories can be combined with ';'.\n";
318 help
+= " -D<name> = name defines a macro for the preprocessor.\n";
319 help
+= " -C = generate complete type information, including\n";
320 help
+= " documentation.\n";
321 help
+= " -cid = check if identifiers fulfill the UNO naming\n";
322 help
+= " requirements.\n";
323 help
+= " -w = display warning messages.\n";
324 help
+= " -we = treat warnings as errors.\n";
325 help
+= " -h|-? = print this help message and exit.\n";
326 help
+= prepareVersion();
331 OString
Options::prepareVersion()
333 OString
version("\nSun Microsystems (R) ");
334 version
+= m_program
+ " Version 1.1\n\n";
338 const OString
& Options::getProgramName() const
343 sal_Bool
Options::isValid(const OString
& option
)
345 return (m_options
.count(option
) > 0);
348 const OString
Options::getOption(const OString
& option
)
349 throw( IllegalArgument
)
351 if (m_options
.count(option
) > 0)
353 return m_options
[option
];
356 throw IllegalArgument("Option is not valid or currently not set.");