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