Bump for 3.6-28
[LibreOffice.git] / autodoc / source / exes / adc_uni / adc_cl.cxx
blob4c5624fb0068e06ff29db11fdccf517be5b6529b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <precomp.h>
30 #include <adc_cl.hxx>
33 // NOT FULLY DEFINED SERVICES
34 #include <algorithm>
35 #include <cosv/x.hxx>
36 #include <cosv/file.hxx>
37 #include <cosv/tpl/tpltools.hxx>
38 #include <ary/ary.hxx>
39 #include <tools/tkpchars.hxx>
40 #include <adc_msg.hxx>
41 #include "adc_cmds.hxx"
42 #include "adc_cmd_parse.hxx"
43 #include "cmd_sincedata.hxx"
46 namespace autodoc
49 CommandLine * CommandLine::pTheInstance_ = 0;
51 const char * const C_sUserGuide =
52 "\n\n\n"
53 " General Use of Autodoc\n"
54 " ----------------------\n"
55 "\n"
56 " Example for IDL:\n"
57 "\n"
58 " -html <OutputDirectory> -name \"UDK 3.x anything\" -lg idl\n"
59 " -t <SourceDir1> <SourceDir2>\n"
60 "\n"
61 " Instead of or in addition to -t may be\n"
62 " used -d (no subdirectories) or -f (just one file). There can\n"
63 " be multiple arguments after each of these options (-t -d -f).\n"
64 "\n"
65 "\n"
66 " Replacing @since Tag Content\n"
67 " ----------------------------\n"
68 "\n"
69 " You can give a transformation file to replace\n"
70 " entries in @since tags by different entries.\n"
71 " This file is given by the option\n"
72 " -sincefile <TransformationFilePath>\n"
73 " This option has to appear between the -html and the -lg option.\n"
74 " Example:\n"
75 " -html <OutputDirectory> -sincefile replacesince.txt\n"
76 " -name \"UDK 3.x anything\" -lg idl -t <SourceDir>\n"
77 "\n"
78 "\n";
80 CommandLine::CommandLine()
81 : nDebugStyle(0),
82 pSinceTransformator(new command::SinceTagTransformationData),
83 aCommands(),
84 bInitOk(false),
85 pCommand_CreateHtml(0),
86 pReposy( & ary::Repository::Create_() ),
87 bIdl(false)
89 csv_assert(pTheInstance_ == 0);
90 pTheInstance_ = this;
93 CommandLine::~CommandLine()
95 csv::erase_container_of_heap_ptrs(aCommands);
96 pTheInstance_ = 0;
99 int
100 CommandLine::Run() const
102 Cout() << "\nAutodoc version 2.2.5"
103 << "\n---------------------"
104 << "\n" << Endl();
106 bool
107 ok = true;
108 for ( CommandList::const_iterator it = aCommands.begin();
109 ok AND it != aCommands.end();
110 ++it )
112 ok = (*it)->Run();
115 if (pCommand_CreateHtml != 0)
117 StreamStr aDiagnosticMessagesFile(700);
118 aDiagnosticMessagesFile
119 << pCommand_CreateHtml->OutputDir()
120 << csv::ploc::Delimiter()
121 << "Autodoc_DiagnosticMessages.txt";
122 TheMessages().WriteFile(aDiagnosticMessagesFile.c_str());
125 return ok ? 0 : 1;
128 CommandLine &
129 CommandLine::Get_()
131 csv_assert(pTheInstance_ != 0);
132 return *pTheInstance_;
135 bool
136 CommandLine::DoesTransform_SinceTag() const
138 return pSinceTransformator->DoesTransform();
141 //bool
142 //CommandLine::Strip_SinceTagText( String & io_sSinceTagValue ) const
144 // return pSinceTransformator->StripSinceTagText(io_sSinceTagValue);
147 const String &
148 CommandLine::DisplayOf_SinceTagValue( const String & i_sVersionNumber ) const
150 return pSinceTransformator->DisplayOf(i_sVersionNumber);
153 void
154 CommandLine::do_Init( int argc,
155 char * argv[] )
159 bInitOk = false;
160 StringVector aParameters;
162 char * * itpEnd = &argv[0] + argc;
163 for ( char * * itp = &argv[1]; itp != itpEnd; ++itp )
165 if ( strncmp(*itp, "-I:", 3) != 0 )
166 aParameters.push_back(String(*itp));
167 else
168 load_IncludedCommands(aParameters, (*itp)+3);
171 StringVector::const_iterator itEnd = aParameters.end();
172 for ( StringVector::const_iterator it = aParameters.begin();
173 it != itEnd;
176 if ( *it == command::C_opt_Verbose )
177 do_clVerbose(it,itEnd);
178 else if ( *it == command::C_opt_LangAll
179 OR *it == command::C_opt_Name
180 OR *it == command::C_opt_DevmanFile )
181 do_clParse(it,itEnd);
182 else if (*it == command::C_opt_CreateHtml)
183 do_clCreateHtml(it,itEnd);
184 else if (*it == command::C_opt_SinceFile)
185 do_clSinceFile(it,itEnd);
186 else if (*it == command::C_opt_ExternNamespace)
188 sExternNamespace = *(++it);
189 ++it;
190 if ( strncmp(sExternNamespace.c_str(), "::", 2) != 0)
192 throw command::X_CommandLine(
193 "-extnsp needs an absolute qualified namespace, starting with \"::\"."
197 else if (*it == command::C_opt_ExternRoot)
199 ++it;
200 StreamLock sl(1000);
201 if ( csv::compare(*it, 0, "http://", 7) != 0 )
203 sl() << "http://" << *it;
205 if ( *(sl().end()-1) != '/')
206 sl() << '/';
207 sExternRoot = sl().c_str();
209 ++it;
211 // else if (*it == command::C_opt_CreateXml)
212 // do_clCreateXml(it,itEnd);
213 // else if (command::C_opt_Load)
214 // do_clLoad(it,itEnd);
215 // else if (*it == command::C_opt_Save)
216 // do_clSave(it,itEnd);
217 else if (*it == "-h" OR *it == "-?" OR *it == "?")
218 // Leads to displaying help, because bInitOk stays on false.
219 return;
220 else if ( *it == command::C_opt_Parse )
221 // Only for backwards compatibility.
222 // Just ignore "-parse".
223 ++it;
224 else
226 StreamLock sl(200);
227 throw command::X_CommandLine(
228 sl() << "Unknown commandline option \""
229 << *it
230 << "\"."
231 << c_str );
233 } // end for
234 sort_Commands();
236 bInitOk = true;
238 } // end try
239 catch ( command::X_CommandLine & xxx )
241 xxx.Report( Cerr() );
243 catch ( csv::Exception & xxx )
245 xxx.GetInfo( Cerr() );
249 void
250 CommandLine::do_PrintUse() const
252 Cout() << C_sUserGuide << Endl();
255 bool
256 CommandLine::inq_CheckParameters() const
258 if (NOT bInitOk OR aCommands.empty())
259 return false;
260 return true;
263 void
264 CommandLine::load_IncludedCommands( StringVector & out,
265 const char * i_filePath )
267 CharacterSource
268 aIncludedCommands;
269 csv::File
270 aFile(i_filePath, csv::CFM_READ);
271 if (NOT aFile.open())
273 Cerr() << "Command include file \""
274 << i_filePath
275 << "\" not found."
276 << Endl();
277 throw command::X_CommandLine("Invalid file in option -I:<command-file>.");
279 aIncludedCommands.LoadText(aFile);
280 aFile.close();
282 bool bInToken = false;
283 StreamLock aTransmit(200);
284 for ( ; NOT aIncludedCommands.IsFinished(); aIncludedCommands.MoveOn() )
286 if (bInToken)
288 if (aIncludedCommands.CurChar() <= 32)
290 const char *
291 pToken = aIncludedCommands.CutToken();
292 bInToken = false;
294 if ( strncmp(pToken, "-I:", 3) != 0 )
296 aTransmit().seekp(0);
297 aTransmit() << pToken;
298 aTransmit().replace_all('\\', *csv::ploc::Delimiter());
299 aTransmit().replace_all('/', *csv::ploc::Delimiter());
300 out.push_back(String(aTransmit().c_str()));
302 else
303 load_IncludedCommands(out, pToken+3);
306 else
308 if (aIncludedCommands.CurChar() > 32)
310 aIncludedCommands.CutToken();
311 bInToken = true;
313 } // endif (bInToken) else
315 } // end while()
318 namespace
320 inline int
321 v_nr(StringVector::const_iterator it)
323 return int( *(*it).c_str() ) - int('0');
325 } // anonymous namespace
327 void
328 CommandLine::do_clVerbose( opt_iter & it,
329 opt_iter itEnd )
331 ++it;
332 if ( it == itEnd ? true : v_nr(it) < 0 OR v_nr(it) > 7 )
333 throw command::X_CommandLine( "Missing or invalid number in -v option." );
334 nDebugStyle = v_nr(it);
335 ++it;
338 void
339 CommandLine::do_clParse( opt_iter & it,
340 opt_iter itEnd )
342 command::Command *
343 pCmd_Parse = new command::Parse;
344 pCmd_Parse->Init(it, itEnd);
345 aCommands.push_back(pCmd_Parse);
348 void
349 CommandLine::do_clCreateHtml( opt_iter & it,
350 opt_iter itEnd )
352 pCommand_CreateHtml = new command::CreateHtml;
353 pCommand_CreateHtml->Init(it, itEnd);
354 aCommands.push_back(pCommand_CreateHtml);
357 void
358 CommandLine::do_clSinceFile( opt_iter & it,
359 opt_iter itEnd )
361 pSinceTransformator->Init(it, itEnd);
365 namespace
368 struct Less_RunningRank
370 bool operator()(
371 const command::Command * const &
373 const command::Command * const &
374 i2 ) const
375 { return i1->RunningRank() < i2->RunningRank(); }
378 } // anonymous namespace
382 void
383 CommandLine::sort_Commands()
385 std::sort( aCommands.begin(),
386 aCommands.end(),
387 Less_RunningRank() );
390 } // namespace autodoc
392 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */