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), m_verbose(false), m_quiet(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 ( 0 == strcmp( &av
[j
][1], "verbose" ) )
199 throw IllegalArgument(OString(av
[j
]) + ", please check your input");
202 if ( 0 == strcmp( &av
[j
][1], "quiet" ) )
207 throw IllegalArgument(OString(av
[j
]) + ", please check your input");
210 if (av
[j
][2] == 'e' && av
[j
][3] == '\0') {
211 if (m_options
.count("-we") == 0)
212 m_options
["-we"] = OString(av
[j
]);
214 if (av
[j
][2] == '\0') {
215 if (m_options
.count("-w") == 0)
216 m_options
["-w"] = OString(av
[j
]);
218 throw IllegalArgument(OString(av
[j
]) + ", please check your input");
223 if (av
[j
][2] != '\0')
225 throw IllegalArgument(OString(av
[j
]) + ", please check your input");
228 fprintf(stdout
, "%s", prepareHelp().getStr());
232 if (/*MSVC trouble: std::*/strcmp(&av
[j
][2], "tdin") == 0)
239 throw IllegalArgument("the option is unknown" + OString(av
[j
]));
245 FILE* cmdFile
= fopen(av
[j
]+1, "r");
246 if( cmdFile
== NULL
)
248 fprintf(stderr
, "%s", prepareHelp().getStr());
259 while ( fscanf(cmdFile
, "%c", &c
) != EOF
)
269 if (c
!=13 && c
!=10) {
270 if (found
|| c
!=' ') {
281 rargv
[rargc
]= strdup(buffer
);
285 if (buffer
[0] != '\0') {
287 rargv
[rargc
]= strdup(buffer
);
292 ret
= initOptions(rargc
, rargv
, bCmdFile
);
295 for (ii
=0; ii
< rargc
; ii
++)
303 name
= name
.toAsciiLowerCase();
304 if ( name
.lastIndexOf(".idl") != (name
.getLength() - 4) )
306 throw IllegalArgument("'" + OString(av
[j
]) +
307 "' is not a valid input file, only '*.idl' files will be accepted");
309 m_inputFiles
.push_back(av
[j
]);
317 OString
Options::prepareHelp()
319 OString
help("\nusing: ");
321 + " [-options] <file_1> ... <file_n> | @<filename> | -stdin\n";
322 help
+= " <file_n> = file_n specifies one or more idl files.\n";
323 help
+= " Only files with the extension '.idl' are valid.\n";
324 help
+= " @<filename> = filename specifies the name of a command file.\n";
325 help
+= " -stdin = read idl file from standard input.\n";
326 help
+= " Options:\n";
327 help
+= " -O<path> = path specifies the output directory.\n";
328 help
+= " The generated output is a registry file with\n";
329 help
+= " the same name as the idl input file (or 'stdin'\n";
330 help
+= " for -stdin).\n";
331 help
+= " -I<path> = path specifies a directory where include\n";
332 help
+= " files will be searched by the preprocessor.\n";
333 help
+= " Multiple directories can be combined with ';'.\n";
334 help
+= " -D<name> = name defines a macro for the preprocessor.\n";
335 help
+= " -C = generate complete type information, including\n";
336 help
+= " documentation.\n";
337 help
+= " -cid = check if identifiers fulfill the UNO naming\n";
338 help
+= " requirements.\n";
339 help
+= " -w = display warning messages.\n";
340 help
+= " -we = treat warnings as errors.\n";
341 help
+= " -h|-? = print this help message and exit.\n";
342 help
+= prepareVersion();
347 OString
Options::prepareVersion()
349 OString
version("\nSun Microsystems (R) ");
350 version
+= m_program
+ " Version 1.1\n\n";
354 const OString
& Options::getProgramName() const
359 sal_Bool
Options::isValid(const OString
& option
)
361 return (m_options
.count(option
) > 0);
364 const OString
Options::getOption(const OString
& option
)
365 throw( IllegalArgument
)
367 if (m_options
.count(option
) > 0)
369 return m_options
[option
];
372 throw IllegalArgument("Option is not valid or currently not set.");