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 :
26 : using namespace ::rtl;
27 :
28 : namespace unodevtools {
29 :
30 : //-------------------------------------------------------------------------------
31 : #if OSL_DEBUG_LEVEL > 1
32 : static void out( const sal_Char * pText )
33 : {
34 : fprintf( stderr, pText );
35 : }
36 : #endif
37 :
38 : //-------------------------------------------------------------------------------
39 0 : sal_Bool readOption( OUString * pValue, const sal_Char * pOpt,
40 : sal_uInt32 * pnIndex, const OUString & aArg)
41 : {
42 0 : const OUString dash = OUString("-");
43 0 : if(aArg.indexOf(dash) != 0)
44 0 : return sal_False;
45 :
46 0 : OUString aOpt = OUString::createFromAscii( pOpt );
47 :
48 0 : if (aArg.getLength() < aOpt.getLength())
49 0 : return sal_False;
50 :
51 0 : if (aOpt.equalsIgnoreAsciiCase( aArg.copy(1) )) {
52 : // take next argument
53 0 : ++(*pnIndex);
54 :
55 0 : rtl_getAppCommandArg(*pnIndex, &pValue->pData);
56 0 : if (*pnIndex >= rtl_getAppCommandArgCount() ||
57 0 : pValue->copy(1).equals(dash))
58 : {
59 : throw CannotDumpException(
60 0 : "incomplete option \"-" + aOpt + "\" given!");
61 : } else {
62 : #if OSL_DEBUG_LEVEL > 1
63 : out( "\n> identified option -" );
64 : out( pOpt );
65 : out( " = " );
66 : OString tmp = OUStringToOString(*pValue, RTL_TEXTENCODING_ASCII_US);
67 : out( tmp.getStr() );
68 : #endif
69 0 : ++(*pnIndex);
70 0 : return sal_True;
71 : }
72 0 : } else if (aArg.indexOf(aOpt) == 1) {
73 0 : *pValue = aArg.copy(1 + aOpt.getLength());
74 : #if OSL_DEBUG_LEVEL > 1
75 : out( "\n> identified option -" );
76 : out( pOpt );
77 : out( " = " );
78 : OString tmp = OUStringToOString(*pValue, RTL_TEXTENCODING_ASCII_US);
79 : out( tmp.getStr() );
80 : #endif
81 0 : ++(*pnIndex);
82 :
83 0 : return sal_True;
84 : }
85 0 : return sal_False;
86 : }
87 :
88 : //-------------------------------------------------------------------------------
89 0 : sal_Bool readOption( sal_Bool * pbOpt, const sal_Char * pOpt,
90 : sal_uInt32 * pnIndex, const OUString & aArg)
91 : {
92 0 : const OUString dashdash("--");
93 0 : const OUString dash("-");
94 0 : OUString aOpt = OUString::createFromAscii(pOpt);
95 :
96 0 : if((aArg.indexOf(dash) == 0 && aOpt.equalsIgnoreAsciiCase(aArg.copy(1))) ||
97 0 : (aArg.indexOf(dashdash) == 0 && aOpt.equalsIgnoreAsciiCase(aArg.copy(2))) )
98 : {
99 0 : ++(*pnIndex);
100 0 : *pbOpt = sal_True;
101 : #if OSL_DEBUG_LEVEL > 1
102 : out( "\n> identified option --" );
103 : out( pOpt );
104 : #endif
105 0 : return sal_True;
106 : }
107 0 : return sal_False;
108 : }
109 :
110 : } // end of namespace unodevtools
111 :
112 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|