Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <stdio.h>
21 :
22 : #include "codemaker/global.hxx"
23 : #include "rtl/ustring.hxx"
24 : #include "rtl/process.h"
25 : #include "unodevtools/options.hxx"
26 :
27 : namespace unodevtools {
28 :
29 :
30 : #if OSL_DEBUG_LEVEL > 1
31 : static void out( const sal_Char * pText )
32 : {
33 : fprintf( stderr, pText );
34 : }
35 : #endif
36 :
37 :
38 0 : bool readOption( OUString * pValue, const sal_Char * pOpt,
39 : sal_uInt32 * pnIndex, const OUString & aArg)
40 : {
41 0 : const OUString dash = "-";
42 0 : if(aArg.indexOf(dash) != 0)
43 0 : return false;
44 :
45 0 : OUString aOpt = OUString::createFromAscii( pOpt );
46 :
47 0 : if (aArg.getLength() < aOpt.getLength())
48 0 : return false;
49 :
50 0 : if (aOpt.equalsIgnoreAsciiCase( aArg.copy(1) )) {
51 : // take next argument
52 0 : ++(*pnIndex);
53 :
54 0 : rtl_getAppCommandArg(*pnIndex, &pValue->pData);
55 0 : if (*pnIndex >= rtl_getAppCommandArgCount() ||
56 0 : pValue->copy(1).equals(dash))
57 : {
58 : throw CannotDumpException(
59 0 : "incomplete option \"-" + aOpt + "\" given!");
60 : } else {
61 : #if OSL_DEBUG_LEVEL > 1
62 : out( "\n> identified option -" );
63 : out( pOpt );
64 : out( " = " );
65 : OString tmp = OUStringToOString(*pValue, RTL_TEXTENCODING_ASCII_US);
66 : out( tmp.getStr() );
67 : #endif
68 0 : ++(*pnIndex);
69 0 : return true;
70 : }
71 0 : } else if (aArg.indexOf(aOpt) == 1) {
72 0 : *pValue = aArg.copy(1 + aOpt.getLength());
73 : #if OSL_DEBUG_LEVEL > 1
74 : out( "\n> identified option -" );
75 : out( pOpt );
76 : out( " = " );
77 : OString tmp = OUStringToOString(*pValue, RTL_TEXTENCODING_ASCII_US);
78 : out( tmp.getStr() );
79 : #endif
80 0 : ++(*pnIndex);
81 :
82 0 : return true;
83 : }
84 0 : return false;
85 : }
86 :
87 :
88 0 : bool readOption( sal_Bool * pbOpt, const sal_Char * pOpt,
89 : sal_uInt32 * pnIndex, const OUString & aArg)
90 : {
91 0 : const OUString dashdash("--");
92 0 : const OUString dash("-");
93 0 : OUString aOpt = OUString::createFromAscii(pOpt);
94 :
95 0 : if((aArg.startsWith(dash) && aOpt.equalsIgnoreAsciiCase(aArg.copy(1))) ||
96 0 : (aArg.startsWith(dashdash) && aOpt.equalsIgnoreAsciiCase(aArg.copy(2))) )
97 : {
98 0 : ++(*pnIndex);
99 0 : *pbOpt = sal_True;
100 : #if OSL_DEBUG_LEVEL > 1
101 : out( "\n> identified option --" );
102 : out( pOpt );
103 : #endif
104 0 : return true;
105 : }
106 0 : return false;
107 : }
108 :
109 : } // end of namespace unodevtools
110 :
111 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|