Update ooo320-m1
[ooovba.git] / xml2cmp / source / support / cmdline.cxx
blob240d8a50d467ed1fafe3cb9eaa8ad1daf3d260cb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cmdline.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "cmdline.hxx"
33 #include <ctype.h>
34 #include <string.h>
35 #include <stdlib.h>
36 #include <iostream>
39 char C_sUseText[] = "Use: xml2cmp.exe \n"
40 " [-func funcFile] \n"
41 " [-html htmlFile] \n"
42 " [-types typeFile] \n"
43 " [-idlpath idlPath] \n"
44 " Xml_FileName\n"
45 " or: xml2cmp.exe \n"
46 " -ix \n"
47 " sourceDirectory \n"
48 " outputDirectory \n"
49 " [-idlpath idlPath] \n"
50 " tagname [tagname ...]";
53 char C_sCmdFunc[] = "-func";
54 char C_sCmdHtml[] = "-html";
55 char C_sCmdType[] = "-types";
56 char C_sCmdIndex[] = "-ix";
57 char C_sCmdIdlPath[] = "-idlpath";
61 bool GetParameter( Simstr & o_rMemory, int & io_nCountArg, int argc, char * argv[] );
64 CommandLine::CommandLine( int argc,
65 char * argv[] )
66 : bIsOk(true)
68 bool bDisplayUse = false;
70 /* Check command line: */
71 if ( argc < 2 )
72 bDisplayUse = true;
73 else if ( argc == 2 && ! isalnum(argv[1][0]) )
74 bDisplayUse = true;
75 else if ( strcmp( argv[1], C_sCmdIndex ) == 0 && argc < 5 )
76 bDisplayUse = true;
78 if (bDisplayUse)
80 std::cout << C_sUseText << std::endl;
81 bIsOk = false;
82 exit(0);
85 if ( strcmp( argv[1], C_sCmdIndex ) == 0 )
87 ParseIndexCommand(argc,argv);
89 else
91 ParseSingleFileCommand(argc,argv);
94 if ( sXmlSourceFile.l() == 0
95 && sXmlSourceDirectory.l() == 0 )
97 bIsOk = false;
99 else if ( sXmlSourceFile.l() > 0
100 && sXmlSourceDirectory.l() > 0 )
102 bIsOk = false;
104 else if ( sIndexFile.l() > 0
105 && ( sXmlSourceDirectory.l() == 0
106 || aTagsInIndex.size() == 0
110 bIsOk = false;
115 CommandLine::~CommandLine()
120 const char *
121 CommandLine::ErrorText() const
123 static char cOut[] = "Error: Command line was incorrect. Probably there was a flag without\n"
124 " the corresponding parameter. Or there was no XML-sourcefile specified.\n";
125 return cOut;
128 bool
129 GetParameter( Simstr & o_pMemory,
130 int & io_pCountArg,
131 int argc,
132 char * argv[] )
134 io_pCountArg++;
135 if( io_pCountArg < argc )
137 o_pMemory = argv[io_pCountArg];
138 return true;
140 return false;
144 void
145 CommandLine::ParseIndexCommand( int argc,
146 char * argv[] )
148 int nCountArg = 1;
149 bIsOk = GetParameter(
150 sXmlSourceDirectory,
151 nCountArg,
152 argc,
153 argv );
154 if (bIsOk)
155 bIsOk = GetParameter(
156 sOutputDirectory,
157 nCountArg,
158 argc,
159 argv );
160 if (bIsOk && strcmp( argv[nCountArg+1], C_sCmdIdlPath ) == 0 )
161 bIsOk = GetParameter(
162 sIdlRootPath,
163 ++nCountArg,
164 argc,
165 argv );
167 sIndexFile = sOutputDirectory;
168 #if defined(WNT) || defined(OS2)
169 sIndexFile+= "\\xmlindex.html";
170 #elif defined(UNX)
171 sIndexFile+= "/xmlindex.html";
172 #endif
174 for ( ++nCountArg; nCountArg < argc; ++nCountArg )
176 Simstr sElementName(argv[nCountArg]);
177 aTagsInIndex.push_back( sElementName );
182 void
183 CommandLine::ParseSingleFileCommand( int argc,
184 char * argv[] )
186 for ( int nCountArg = 1; nCountArg < argc && bIsOk; ++nCountArg )
188 if ( strcmp( argv[nCountArg], C_sCmdFunc ) == 0 )
190 bIsOk = GetParameter(
191 sFuncFile,
192 nCountArg,
193 argc,
194 argv );
196 else if ( strcmp( argv[nCountArg], C_sCmdHtml ) == 0 )
198 bIsOk = GetParameter(
199 sHtmlFile,
200 nCountArg,
201 argc,
202 argv );
204 else if ( strcmp( argv[nCountArg], C_sCmdType ) == 0 )
206 bIsOk = GetParameter(
207 sTypeInfoFile,
208 nCountArg,
209 argc,
210 argv );
212 else if ( strcmp( argv[nCountArg], C_sCmdIdlPath ) == 0 )
214 bIsOk = GetParameter(
215 sIdlRootPath,
216 nCountArg,
217 argc,
218 argv );
220 else
222 sXmlSourceFile = argv[nCountArg];
224 } /* end for */