xref: /AOO41X/main/idlc/source/options.cxx (revision 3b906df9eded92e7581356bd984de614f1b459db)
12fe1ca3dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
32fe1ca3dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
42fe1ca3dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
52fe1ca3dSAndrew Rist  * distributed with this work for additional information
62fe1ca3dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
72fe1ca3dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
82fe1ca3dSAndrew Rist  * "License"); you may not use this file except in compliance
92fe1ca3dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
112fe1ca3dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
132fe1ca3dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
142fe1ca3dSAndrew Rist  * software distributed under the License is distributed on an
152fe1ca3dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
162fe1ca3dSAndrew Rist  * KIND, either express or implied.  See the License for the
172fe1ca3dSAndrew Rist  * specific language governing permissions and limitations
182fe1ca3dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
202fe1ca3dSAndrew Rist  *************************************************************/
212fe1ca3dSAndrew Rist 
222fe1ca3dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_idlc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "idlc/options.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "osl/diagnose.h"
30cdf0e10cSrcweir #include "rtl/string.hxx"
31cdf0e10cSrcweir #include "rtl/strbuf.hxx"
32cdf0e10cSrcweir 
33*3b906df9SJuergen Schmidt #include "rtl/ustring.hxx"
34*3b906df9SJuergen Schmidt #include "osl/file.hxx"
35*3b906df9SJuergen Schmidt 
36*3b906df9SJuergen Schmidt #ifdef WNT
37*3b906df9SJuergen Schmidt #   include <windows.h>
38*3b906df9SJuergen Schmidt #endif
39*3b906df9SJuergen Schmidt 
40*3b906df9SJuergen Schmidt /*
41*3b906df9SJuergen Schmidt #ifndef WIN32_LEAN_AND_MEAN
42*3b906df9SJuergen Schmidt #   define WIN32_LEAN_AND_MEAN
43*3b906df9SJuergen Schmidt # ifdef _MSC_VER
44*3b906df9SJuergen Schmidt #   pragma warning(push,1)
45*3b906df9SJuergen Schmidt # endif
46*3b906df9SJuergen Schmidt #   include <windows.h>
47*3b906df9SJuergen Schmidt # ifdef _MSC_VER
48*3b906df9SJuergen Schmidt #   pragma warning(pop)
49*3b906df9SJuergen Schmidt # endif
50*3b906df9SJuergen Schmidt #   include <tchar.h>
51*3b906df9SJuergen Schmidt #   undef WIN32_LEAN_AND_MEAN
52*3b906df9SJuergen Schmidt #endif
53*3b906df9SJuergen Schmidt */
54*3b906df9SJuergen Schmidt 
55cdf0e10cSrcweir #include <stdio.h>
56cdf0e10cSrcweir #include <string.h>
57cdf0e10cSrcweir 
58cdf0e10cSrcweir using rtl::OString;
59cdf0e10cSrcweir using rtl::OStringBuffer;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir #ifdef SAL_UNX
62cdf0e10cSrcweir #define SEPARATOR '/'
63cdf0e10cSrcweir #else
64cdf0e10cSrcweir #define SEPARATOR '\\'
65cdf0e10cSrcweir #endif
66cdf0e10cSrcweir 
Options(char const * progname)67cdf0e10cSrcweir Options::Options(char const * progname)
68cdf0e10cSrcweir     : m_program(progname), m_stdin(false), m_verbose(false), m_quiet(false)
69cdf0e10cSrcweir {
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
~Options()72cdf0e10cSrcweir Options::~Options()
73cdf0e10cSrcweir {
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir // static
checkArgument(std::vector<std::string> & rArgs,char const * arg,size_t len)77cdf0e10cSrcweir bool Options::checkArgument (std::vector< std::string > & rArgs, char const * arg, size_t len)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir     bool result = ((arg != 0) && (len > 0));
80cdf0e10cSrcweir     OSL_PRECOND(result, "idlc::Options::checkArgument(): invalid arguments");
81cdf0e10cSrcweir     if (result)
82cdf0e10cSrcweir     {
83cdf0e10cSrcweir         switch(arg[0])
84cdf0e10cSrcweir         {
85cdf0e10cSrcweir         case '@':
86cdf0e10cSrcweir             if ((result = (len > 1)) == true)
87cdf0e10cSrcweir             {
88cdf0e10cSrcweir                 // "@<cmdfile>"
89cdf0e10cSrcweir                 result = Options::checkCommandFile (rArgs, &(arg[1]));
90cdf0e10cSrcweir             }
91cdf0e10cSrcweir             break;
92cdf0e10cSrcweir         case '-':
93cdf0e10cSrcweir             if ((result = (len > 1)) == true)
94cdf0e10cSrcweir             {
95cdf0e10cSrcweir                 // "-<option>"
96cdf0e10cSrcweir                 switch (arg[1])
97cdf0e10cSrcweir                 {
98cdf0e10cSrcweir                 case 'O':
99cdf0e10cSrcweir                 case 'I':
100cdf0e10cSrcweir                 case 'D':
101cdf0e10cSrcweir                 {
102cdf0e10cSrcweir                     // "-<option>[<param>]
103cdf0e10cSrcweir                     std::string option(&(arg[0]), 2);
104cdf0e10cSrcweir                     rArgs.push_back(option);
105cdf0e10cSrcweir                     if (len > 2)
106cdf0e10cSrcweir                     {
107cdf0e10cSrcweir                         // "-<option><param>"
108cdf0e10cSrcweir                         std::string param(&(arg[2]), len - 2);
109cdf0e10cSrcweir                         rArgs.push_back(param);
110cdf0e10cSrcweir                     }
111cdf0e10cSrcweir                     break;
112cdf0e10cSrcweir                 }
113cdf0e10cSrcweir                 default:
114cdf0e10cSrcweir                     // "-<option>" ([long] option, w/o param)
115cdf0e10cSrcweir                     rArgs.push_back(std::string(arg, len));
116cdf0e10cSrcweir                     break;
117cdf0e10cSrcweir                 }
118cdf0e10cSrcweir             }
119cdf0e10cSrcweir             break;
120cdf0e10cSrcweir         default:
121cdf0e10cSrcweir             // "<param>"
122cdf0e10cSrcweir             rArgs.push_back(std::string(arg, len));
123cdf0e10cSrcweir             break;
124cdf0e10cSrcweir         }
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir     return (result);
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir // static
checkCommandFile(std::vector<std::string> & rArgs,char const * filename)130cdf0e10cSrcweir bool Options::checkCommandFile (std::vector< std::string > & rArgs, char const * filename)
131cdf0e10cSrcweir {
132cdf0e10cSrcweir     FILE * fp = fopen(filename, "r");
133cdf0e10cSrcweir     if (fp == 0)
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         fprintf(stderr, "ERROR: can't open command file \"%s\"\n", filename);
136cdf0e10cSrcweir         return (false);
137cdf0e10cSrcweir     }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     std::string buffer;
140cdf0e10cSrcweir     buffer.reserve(256);
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     bool quoted = false;
143cdf0e10cSrcweir     int c = EOF;
144cdf0e10cSrcweir     while ((c = fgetc(fp)) != EOF)
145cdf0e10cSrcweir     {
146cdf0e10cSrcweir         switch(c)
147cdf0e10cSrcweir         {
148cdf0e10cSrcweir         case '\"':
149cdf0e10cSrcweir             quoted = !quoted;
150cdf0e10cSrcweir             break;
151cdf0e10cSrcweir         case ' ':
152cdf0e10cSrcweir         case '\t':
153cdf0e10cSrcweir         case '\r':
154cdf0e10cSrcweir         case '\n':
155cdf0e10cSrcweir             if (!quoted)
156cdf0e10cSrcweir             {
157cdf0e10cSrcweir                 if (!buffer.empty())
158cdf0e10cSrcweir                 {
159cdf0e10cSrcweir                     // append current argument.
160cdf0e10cSrcweir                     if (!Options::checkArgument(rArgs, buffer.c_str(), buffer.size()))
161cdf0e10cSrcweir                     {
162cdf0e10cSrcweir                         (void) fclose(fp);
163cdf0e10cSrcweir                         return (false);
164cdf0e10cSrcweir                     }
165cdf0e10cSrcweir                     buffer.clear();
166cdf0e10cSrcweir                 }
167cdf0e10cSrcweir                 break;
168cdf0e10cSrcweir             }
169cdf0e10cSrcweir         default:
170cdf0e10cSrcweir             // quoted white-space fall through
171cdf0e10cSrcweir             buffer.push_back(sal::static_int_cast<char>(c));
172cdf0e10cSrcweir             break;
173cdf0e10cSrcweir         }
174cdf0e10cSrcweir     }
175cdf0e10cSrcweir     if (!buffer.empty())
176cdf0e10cSrcweir     {
177cdf0e10cSrcweir         // append unterminated argument.
178cdf0e10cSrcweir         if (!Options::checkArgument(rArgs, buffer.c_str(), buffer.size()))
179cdf0e10cSrcweir         {
180cdf0e10cSrcweir             (void) fclose(fp);
181cdf0e10cSrcweir             return (false);
182cdf0e10cSrcweir         }
183cdf0e10cSrcweir         buffer.clear();
184cdf0e10cSrcweir     }
185cdf0e10cSrcweir     return (fclose(fp) == 0);
186cdf0e10cSrcweir }
187cdf0e10cSrcweir 
badOption(char const * reason,std::string const & rArg)188cdf0e10cSrcweir bool Options::badOption(char const * reason, std::string const & rArg) throw(IllegalArgument)
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     OStringBuffer message;
191cdf0e10cSrcweir     if (reason != 0)
192cdf0e10cSrcweir     {
193cdf0e10cSrcweir         message.append(reason); message.append(" option '"); message.append(rArg.c_str()); message.append("'");
194cdf0e10cSrcweir         throw IllegalArgument(message.makeStringAndClear());
195cdf0e10cSrcweir     }
196cdf0e10cSrcweir     return false;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
setOption(char const * option,std::string const & rArg)199cdf0e10cSrcweir bool Options::setOption(char const * option, std::string const & rArg)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir     bool result = (0 == strcmp(option, rArg.c_str()));
202cdf0e10cSrcweir     if (result)
203cdf0e10cSrcweir         m_options[rArg.c_str()] = OString(rArg.c_str(), rArg.size());
204cdf0e10cSrcweir     return (result);
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
207*3b906df9SJuergen Schmidt #ifdef WNT
208*3b906df9SJuergen Schmidt /* Helper functiopn to convert windows paths including spaces, brackets etc. into
209*3b906df9SJuergen Schmidt    a windows short Url. The ucpp preprocessor has problems with such paths and returns
210*3b906df9SJuergen Schmidt    with error.
211*3b906df9SJuergen Schmidt */
convertIncPathtoShortWindowsPath(const OString & incPath)212*3b906df9SJuergen Schmidt OString convertIncPathtoShortWindowsPath(const OString& incPath) {
213*3b906df9SJuergen Schmidt 	rtl::OUString path = OStringToOUString(incPath, RTL_TEXTENCODING_UTF8);
214*3b906df9SJuergen Schmidt 
215*3b906df9SJuergen Schmidt 	std::vector<sal_Unicode> vec(path.getLength() + 1);
216*3b906df9SJuergen Schmidt     //GetShortPathNameW only works if the file can be found!
217*3b906df9SJuergen Schmidt     const DWORD len = GetShortPathNameW(
218*3b906df9SJuergen Schmidt 		reinterpret_cast<LPCWSTR>(path.getStr()), reinterpret_cast<LPWSTR>(&vec[0]), path.getLength() + 1);
219*3b906df9SJuergen Schmidt 
220*3b906df9SJuergen Schmidt 	rtl::OUString ret = rtl::OUString(&vec[0], len);
221*3b906df9SJuergen Schmidt 
222*3b906df9SJuergen Schmidt 	if (len > 0)
223*3b906df9SJuergen Schmidt 		return OUStringToOString(ret, RTL_TEXTENCODING_UTF8);
224*3b906df9SJuergen Schmidt 
225*3b906df9SJuergen Schmidt 	return incPath;
226*3b906df9SJuergen Schmidt }
227*3b906df9SJuergen Schmidt #endif
228*3b906df9SJuergen Schmidt 
initOptions(std::vector<std::string> & rArgs)229cdf0e10cSrcweir bool Options::initOptions(std::vector< std::string > & rArgs) throw(IllegalArgument)
230cdf0e10cSrcweir {
231cdf0e10cSrcweir     std::vector< std::string >::const_iterator first = rArgs.begin(), last = rArgs.end();
232cdf0e10cSrcweir     for (; first != last; ++first)
233cdf0e10cSrcweir     {
234cdf0e10cSrcweir         if ((*first)[0] != '-')
235cdf0e10cSrcweir         {
236cdf0e10cSrcweir             OString filename((*first).c_str(), (*first).size());
237cdf0e10cSrcweir             OString tmp(filename.toAsciiLowerCase());
238cdf0e10cSrcweir             if (tmp.lastIndexOf(".idl") != (tmp.getLength() - 4))
239cdf0e10cSrcweir             {
240cdf0e10cSrcweir                 throw IllegalArgument("'" + filename + "' is not a valid input file, only '*.idl' files will be accepted");
241cdf0e10cSrcweir             }
242cdf0e10cSrcweir             m_inputFiles.push_back(filename);
243cdf0e10cSrcweir             continue;
244cdf0e10cSrcweir         }
245cdf0e10cSrcweir 
246cdf0e10cSrcweir         std::string const option(*first);
247cdf0e10cSrcweir         switch((*first)[1])
248cdf0e10cSrcweir         {
249cdf0e10cSrcweir         case 'O':
250cdf0e10cSrcweir         {
251cdf0e10cSrcweir             if (!((++first != last) && ((*first)[0] != '-')))
252cdf0e10cSrcweir             {
253cdf0e10cSrcweir                 return badOption("invalid", option);
254cdf0e10cSrcweir             }
255cdf0e10cSrcweir             OString param((*first).c_str(), (*first).size());
256cdf0e10cSrcweir             m_options["-O"] = param;
257cdf0e10cSrcweir             break;
258cdf0e10cSrcweir         }
259cdf0e10cSrcweir         case 'I':
260cdf0e10cSrcweir         {
261cdf0e10cSrcweir             if (!((++first != last) && ((*first)[0] != '-')))
262cdf0e10cSrcweir             {
263cdf0e10cSrcweir                 return badOption("invalid", option);
264cdf0e10cSrcweir             }
265cdf0e10cSrcweir             OString param((*first).c_str(), (*first).size());
266cdf0e10cSrcweir             {
267cdf0e10cSrcweir                 // quote param token(s).
268cdf0e10cSrcweir                 OStringBuffer buffer;
269cdf0e10cSrcweir                 sal_Int32 k = 0;
270cdf0e10cSrcweir                 do
271cdf0e10cSrcweir                 {
272*3b906df9SJuergen Schmidt                     OStringBuffer token;
273*3b906df9SJuergen Schmidt                     token.append("-I");
274*3b906df9SJuergen Schmidt #ifdef WNT
275*3b906df9SJuergen Schmidt 					rtl::OString incpath = convertIncPathtoShortWindowsPath(param.getToken(0, ';', k));
276*3b906df9SJuergen Schmidt #else
277*3b906df9SJuergen Schmidt 					rtl::OString incpath = param.getToken(0, ';', k);
278*3b906df9SJuergen Schmidt #endif
279*3b906df9SJuergen Schmidt 					token.append(incpath);
280*3b906df9SJuergen Schmidt                     //token.append(param.getToken(0, ';', k));
281cdf0e10cSrcweir                     if (buffer.getLength() > 0)
282cdf0e10cSrcweir                         buffer.append(' ');
283cdf0e10cSrcweir                     buffer.append(token);
284cdf0e10cSrcweir                 } while (k != -1);
285cdf0e10cSrcweir                 param = buffer.makeStringAndClear();
286cdf0e10cSrcweir             }
287cdf0e10cSrcweir             if (m_options.count("-I") > 0)
288cdf0e10cSrcweir             {
289cdf0e10cSrcweir                 // append param.
290cdf0e10cSrcweir                 OStringBuffer buffer(m_options["-I"]);
291cdf0e10cSrcweir                 buffer.append(' '); buffer.append(param);
292cdf0e10cSrcweir                 param = buffer.makeStringAndClear();
293cdf0e10cSrcweir             }
294cdf0e10cSrcweir             m_options["-I"] = param;
295cdf0e10cSrcweir             break;
296cdf0e10cSrcweir         }
297cdf0e10cSrcweir         case 'D':
298cdf0e10cSrcweir         {
299cdf0e10cSrcweir             if (!((++first != last) && ((*first)[0] != '-')))
300cdf0e10cSrcweir             {
301cdf0e10cSrcweir                 return badOption("invalid", option);
302cdf0e10cSrcweir             }
303cdf0e10cSrcweir             OString param("-D"); param += OString((*first).c_str(), (*first).size());
304cdf0e10cSrcweir             if (m_options.count("-D") > 0)
305cdf0e10cSrcweir             {
306cdf0e10cSrcweir                 OStringBuffer buffer(m_options["-D"]);
307cdf0e10cSrcweir                 buffer.append(' '); buffer.append(param);
308cdf0e10cSrcweir                 param = buffer.makeStringAndClear();
309cdf0e10cSrcweir             }
310cdf0e10cSrcweir             m_options["-D"] = param;
311cdf0e10cSrcweir             break;
312cdf0e10cSrcweir         }
313cdf0e10cSrcweir         case 'C':
314cdf0e10cSrcweir         {
315cdf0e10cSrcweir             if (!setOption("-C", option))
316cdf0e10cSrcweir             {
317cdf0e10cSrcweir                 return badOption("invalid", option);
318cdf0e10cSrcweir             }
319cdf0e10cSrcweir             break;
320cdf0e10cSrcweir         }
321cdf0e10cSrcweir         case 'c':
322cdf0e10cSrcweir         {
323cdf0e10cSrcweir             if (!setOption("-cid", option))
324cdf0e10cSrcweir             {
325cdf0e10cSrcweir                 return badOption("invalid", option);
326cdf0e10cSrcweir             }
327cdf0e10cSrcweir             break;
328cdf0e10cSrcweir         }
329cdf0e10cSrcweir         case 'q':
330cdf0e10cSrcweir         {
331cdf0e10cSrcweir             if (!setOption("-quiet", option))
332cdf0e10cSrcweir             {
333cdf0e10cSrcweir                 return badOption("invalid", option);
334cdf0e10cSrcweir             }
335cdf0e10cSrcweir             m_quiet = true;
336cdf0e10cSrcweir             break;
337cdf0e10cSrcweir         }
338cdf0e10cSrcweir         case 'v':
339cdf0e10cSrcweir         {
340cdf0e10cSrcweir             if (!setOption("-verbose", option))
341cdf0e10cSrcweir             {
342cdf0e10cSrcweir                 return badOption("invalid", option);
343cdf0e10cSrcweir             }
344cdf0e10cSrcweir             m_verbose = true;
345cdf0e10cSrcweir             break;
346cdf0e10cSrcweir         }
347cdf0e10cSrcweir         case 'w':
348cdf0e10cSrcweir         {
349cdf0e10cSrcweir             if (!(setOption("-w", option) || setOption("-we", option)))
350cdf0e10cSrcweir             {
351cdf0e10cSrcweir                 return badOption("invalid", option);
352cdf0e10cSrcweir             }
353cdf0e10cSrcweir             break;
354cdf0e10cSrcweir         }
355cdf0e10cSrcweir         case 'h':
356cdf0e10cSrcweir         case '?':
357cdf0e10cSrcweir         {
358cdf0e10cSrcweir             if (!(setOption("-h", option) || setOption("-?", option)))
359cdf0e10cSrcweir             {
360cdf0e10cSrcweir                 return badOption("invalid", option);
361cdf0e10cSrcweir             }
362cdf0e10cSrcweir             {
363cdf0e10cSrcweir                 (void) fprintf(stdout, "%s", prepareHelp().getStr());
364cdf0e10cSrcweir                 return (false);
365cdf0e10cSrcweir             }
366cdf0e10cSrcweir             // break; // Unreachable
367cdf0e10cSrcweir         }
368cdf0e10cSrcweir         case 's':
369cdf0e10cSrcweir         {
370cdf0e10cSrcweir             if (!setOption("-stdin", option))
371cdf0e10cSrcweir             {
372cdf0e10cSrcweir                 return badOption("invalid", option);
373cdf0e10cSrcweir             }
374cdf0e10cSrcweir             m_stdin = true;
375cdf0e10cSrcweir             break;
376cdf0e10cSrcweir         }
377cdf0e10cSrcweir         default:
378cdf0e10cSrcweir             return badOption("unknown", option);
379cdf0e10cSrcweir         }
380cdf0e10cSrcweir     }
381cdf0e10cSrcweir     return (true);
382cdf0e10cSrcweir }
383cdf0e10cSrcweir 
prepareHelp()384cdf0e10cSrcweir OString	Options::prepareHelp()
385cdf0e10cSrcweir {
386cdf0e10cSrcweir 	OString help("\nusing: ");
3875979ef3cSJürgen Schmidt 	help += m_program + " [-options] <file_1> ... <file_n> | @<filename> | -stdin\n";
388cdf0e10cSrcweir 	help += "    <file_n>    = file_n specifies one or more idl files.\n";
389cdf0e10cSrcweir 	help += "                  Only files with the extension '.idl' are valid.\n";
390cdf0e10cSrcweir 	help += "    @<filename> = filename specifies the name of a command file.\n";
391cdf0e10cSrcweir     help += "    -stdin      = read idl file from standard input.\n";
392cdf0e10cSrcweir 	help += "  Options:\n";
393cdf0e10cSrcweir 	help += "    -O<path>    = path specifies the output directory.\n";
394cdf0e10cSrcweir 	help += "                  The generated output is a registry file with\n";
395cdf0e10cSrcweir 	help += "                  the same name as the idl input file (or 'stdin'\n";
396cdf0e10cSrcweir     help += "                  for -stdin).\n";
397cdf0e10cSrcweir 	help += "    -I<path>    = path specifies a directory where include\n";
398cdf0e10cSrcweir 	help += "                  files will be searched by the preprocessor.\n";
399cdf0e10cSrcweir 	help += "                  Multiple directories can be combined with ';'.\n";
400cdf0e10cSrcweir 	help += "    -D<name>    = name defines a macro for the preprocessor.\n";
401cdf0e10cSrcweir 	help += "    -C          = generate complete type information, including\n";
402cdf0e10cSrcweir 	help += "                  documentation.\n";
403cdf0e10cSrcweir 	help += "    -cid        = check if identifiers fulfill the UNO naming\n";
404cdf0e10cSrcweir     help += "                  requirements.\n";
405cdf0e10cSrcweir 	help += "    -w          = display warning messages.\n";
406cdf0e10cSrcweir 	help += "    -we         = treat warnings as errors.\n";
407cdf0e10cSrcweir 	help += "    -h|-?       = print this help message and exit.\n\n";
408cdf0e10cSrcweir 	help += prepareVersion();
409cdf0e10cSrcweir 
410cdf0e10cSrcweir 	return help;
411cdf0e10cSrcweir }
412cdf0e10cSrcweir 
prepareVersion()413cdf0e10cSrcweir OString	Options::prepareVersion()
414cdf0e10cSrcweir {
415cdf0e10cSrcweir 	OString version(m_program);
416cdf0e10cSrcweir 	version += " Version 1.1\n\n";
417cdf0e10cSrcweir 	return version;
418cdf0e10cSrcweir }
419cdf0e10cSrcweir 
getProgramName() const420cdf0e10cSrcweir const OString& Options::getProgramName() const
421cdf0e10cSrcweir {
422cdf0e10cSrcweir 	return m_program;
423cdf0e10cSrcweir }
424cdf0e10cSrcweir 
isValid(const OString & option)425cdf0e10cSrcweir bool Options::isValid(const OString& option)
426cdf0e10cSrcweir {
427cdf0e10cSrcweir 	return (m_options.count(option) > 0);
428cdf0e10cSrcweir }
429cdf0e10cSrcweir 
getOption(const OString & option)430cdf0e10cSrcweir const OString& Options::getOption(const OString& option)
431cdf0e10cSrcweir 	throw( IllegalArgument )
432cdf0e10cSrcweir {
433cdf0e10cSrcweir 	if (!isValid(option))
434cdf0e10cSrcweir 	{
435cdf0e10cSrcweir 		throw IllegalArgument("Option is not valid or currently not set.");
436cdf0e10cSrcweir 	}
437cdf0e10cSrcweir     return m_options[option];
438cdf0e10cSrcweir }
439cdf0e10cSrcweir /* vi:set tabstop=4 shiftwidth=4 expandtab: */
440