Branch data 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 "cmdline.hxx"
21 : :
22 : : #include <ctype.h>
23 : : #include <string.h>
24 : : #include <stdlib.h>
25 : : #include <iostream>
26 : :
27 : :
28 : : char C_sUseText[] = "Use: xml2cmp.exe \n"
29 : : " [-dep <xml-component-descriptions-root-directory> \n"
30 : : " [-func funcFile] \n"
31 : : " [-html htmlFile] \n"
32 : : " [-types typeFile] \n"
33 : : " [-idlpath idlPath] \n"
34 : : " Xml_FileName\n";
35 : :
36 : :
37 : : char C_sCmdFunc[] = "-func";
38 : : char C_sCmdDep[] = "-dep";
39 : : char C_sCmdHtml[] = "-html";
40 : : char C_sCmdType[] = "-types";
41 : : char C_sCmdIdlPath[] = "-idlpath";
42 : :
43 : :
44 : :
45 : : bool GetParameter( Simstr & o_rMemory, int & io_nCountArg, int argc, char * argv[] );
46 : :
47 : :
48 : 2 : CommandLine::CommandLine( int argc,
49 : : char * argv[] )
50 [ + - ][ + - ]: 2 : : bIsOk(true)
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
51 : : {
52 : 2 : bool bDisplayUse = false;
53 : :
54 : : /* Check command line: */
55 [ - + ]: 2 : if ( argc < 2 )
56 : 0 : bDisplayUse = true;
57 [ - + ][ # # ]: 2 : else if ( argc == 2 && ! isalnum(argv[1][0]) )
58 : 0 : bDisplayUse = true;
59 : :
60 [ - + ]: 2 : if (bDisplayUse)
61 : : {
62 [ # # ][ # # ]: 0 : std::cout << C_sUseText << std::endl;
63 : 0 : bIsOk = false;
64 : 0 : exit(0);
65 : : }
66 : :
67 [ + - ]: 2 : ParseSingleFileCommand(argc,argv);
68 : :
69 [ - + # # ]: 2 : if ( sXmlSourceFile.l() == 0
[ - + ]
70 : 0 : && sXmlSourceDirectory.l() == 0 )
71 : : {
72 : 0 : bIsOk = false;
73 : : }
74 [ + - - + ]: 4 : else if ( sXmlSourceFile.l() > 0
[ - + ]
75 : 2 : && sXmlSourceDirectory.l() > 0 )
76 : : {
77 : 0 : bIsOk = false;
78 : : }
79 : 2 : }
80 : :
81 [ + - ][ + - ]: 2 : CommandLine::~CommandLine()
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
82 : : {
83 : 2 : }
84 : :
85 : :
86 : : const char *
87 : 0 : CommandLine::ErrorText() const
88 : : {
89 : : static char cOut[] = "Error: Command line was incorrect. Probably there was a flag without\n"
90 : : " the corresponding parameter. Or there was no XML-sourcefile specified.\n";
91 : 0 : return cOut;
92 : : }
93 : :
94 : : bool
95 : 2 : GetParameter( Simstr & o_pMemory,
96 : : int & io_pCountArg,
97 : : int argc, char * argv[] )
98 : : {
99 : 2 : io_pCountArg++;
100 [ + - ]: 2 : if( io_pCountArg < argc )
101 : : {
102 [ + - ]: 2 : o_pMemory = argv[io_pCountArg];
103 : 2 : return true;
104 : : }
105 : 2 : return false;
106 : : }
107 : :
108 : : void
109 : 2 : CommandLine::ParseSingleFileCommand( int argc,
110 : : char * argv[] )
111 : : {
112 [ + + ][ + - ]: 6 : for ( int nCountArg = 1; nCountArg < argc && bIsOk; ++nCountArg )
[ + + ]
113 : : {
114 [ - + ]: 4 : if ( strcmp( argv[nCountArg], C_sCmdFunc ) == 0 )
115 : : {
116 : : bIsOk = GetParameter(
117 : : sFuncFile,
118 : : nCountArg,
119 : : argc,
120 [ # # ]: 0 : argv );
121 : : }
122 [ - + ]: 4 : else if ( strcmp( argv[nCountArg], C_sCmdHtml ) == 0 )
123 : : {
124 : : bIsOk = GetParameter(
125 : : sHtmlFile,
126 : : nCountArg,
127 : : argc,
128 [ # # ]: 0 : argv );
129 : : }
130 [ + + ]: 4 : else if ( strcmp( argv[nCountArg], C_sCmdType ) == 0 )
131 : : {
132 : : bIsOk = GetParameter(
133 : : sTypeInfoFile,
134 : : nCountArg,
135 : : argc,
136 [ + - ]: 2 : argv );
137 : : }
138 [ - + ]: 2 : else if ( strcmp( argv[nCountArg], C_sCmdIdlPath ) == 0 )
139 : : {
140 : : bIsOk = GetParameter(
141 : : sIdlRootPath,
142 : : nCountArg,
143 : : argc,
144 [ # # ]: 0 : argv );
145 : : }
146 [ - + ]: 2 : else if ( strcmp( argv[nCountArg], C_sCmdDep ) == 0 )
147 : : {
148 : : bIsOk = GetParameter(
149 : : sDepPath,
150 : : nCountArg,
151 : : argc,
152 [ # # ]: 0 : argv );
153 : : }
154 : : else
155 : : {
156 [ + - ][ + - ]: 2 : sXmlSourceFile = argv[nCountArg];
[ + - ]
157 : : }
158 : : } /* end for */
159 [ + - ][ + - ]: 8 : }
160 : :
161 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|