bump product version to 4.1.6.2
[LibreOffice.git] / autodoc / source / exes / adc_uni / adc_cl.cxx
blob142bcdfa7b094148cd0cd200c5e151c4934a3a06
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <precomp.h>
21 #include <adc_cl.hxx>
24 // NOT FULLY DEFINED SERVICES
25 #include <algorithm>
26 #include <cosv/x.hxx>
27 #include <cosv/file.hxx>
28 #include <cosv/tpl/tpltools.hxx>
29 #include <ary/ary.hxx>
30 #include <tools/tkpchars.hxx>
31 #include <adc_msg.hxx>
32 #include "adc_cmds.hxx"
33 #include "adc_cmd_parse.hxx"
34 #include "cmd_sincedata.hxx"
37 namespace autodoc
40 CommandLine * CommandLine::pTheInstance_ = 0;
42 const char * const C_sUserGuide =
43 "\n\n\n"
44 " General Use of Autodoc\n"
45 " ----------------------\n"
46 "\n"
47 " Example for IDL:\n"
48 "\n"
49 " -html <OutputDirectory> -name \"UDK 3.x anything\" -lg idl\n"
50 " -t <SourceDir1> <SourceDir2>\n"
51 "\n"
52 " Instead of or in addition to -t may be\n"
53 " used -d (no subdirectories) or -f (just one file). There can\n"
54 " be multiple arguments after each of these options (-t -d -f).\n"
55 "\n"
56 "\n"
57 " Replacing @since Tag Content\n"
58 " ----------------------------\n"
59 "\n"
60 " You can give a transformation file to replace\n"
61 " entries in @since tags by different entries.\n"
62 " This file is given by the option\n"
63 " -sincefile <TransformationFilePath>\n"
64 " This option has to appear between the -html and the -lg option.\n"
65 " Example:\n"
66 " -html <OutputDirectory> -sincefile replacesince.txt\n"
67 " -name \"UDK 3.x anything\" -lg idl -t <SourceDir>\n"
68 "\n"
69 "\n";
71 CommandLine::CommandLine()
72 : nDebugStyle(0),
73 pSinceTransformator(new command::SinceTagTransformationData),
74 aCommands(),
75 bInitOk(false),
76 pCommand_CreateHtml(0),
77 pReposy( & ary::Repository::Create_() ),
78 bIdl(false)
80 csv_assert(pTheInstance_ == 0);
81 pTheInstance_ = this;
84 CommandLine::~CommandLine()
86 csv::erase_container_of_heap_ptrs(aCommands);
87 pTheInstance_ = 0;
90 int
91 CommandLine::Run() const
93 Cout() << "\nAutodoc version 2.2.5"
94 << "\n---------------------"
95 << "\n" << Endl();
97 bool
98 ok = true;
99 for ( CommandList::const_iterator it = aCommands.begin();
100 ok AND it != aCommands.end();
101 ++it )
103 ok = (*it)->Run();
106 if (pCommand_CreateHtml != 0)
108 StreamStr aDiagnosticMessagesFile(700);
109 aDiagnosticMessagesFile
110 << pCommand_CreateHtml->OutputDir()
111 << csv::ploc::Delimiter()
112 << "Autodoc_DiagnosticMessages.txt";
113 TheMessages().WriteFile(aDiagnosticMessagesFile.c_str());
116 return ok ? 0 : 1;
119 CommandLine &
120 CommandLine::Get_()
122 csv_assert(pTheInstance_ != 0);
123 return *pTheInstance_;
126 bool
127 CommandLine::DoesTransform_SinceTag() const
129 return pSinceTransformator->DoesTransform();
132 //bool
133 //CommandLine::Strip_SinceTagText( String & io_sSinceTagValue ) const
135 // return pSinceTransformator->StripSinceTagText(io_sSinceTagValue);
138 const String &
139 CommandLine::DisplayOf_SinceTagValue( const String & i_sVersionNumber ) const
141 return pSinceTransformator->DisplayOf(i_sVersionNumber);
144 void
145 CommandLine::do_Init( int argc,
146 char * argv[] )
150 bInitOk = false;
151 StringVector aParameters;
153 char * * itpEnd = &argv[0] + argc;
154 for ( char * * itp = &argv[1]; itp != itpEnd; ++itp )
156 if ( strncmp(*itp, "-I:", 3) != 0 )
157 aParameters.push_back(String(*itp));
158 else
159 load_IncludedCommands(aParameters, (*itp)+3);
162 StringVector::const_iterator itEnd = aParameters.end();
163 for ( StringVector::const_iterator it = aParameters.begin();
164 it != itEnd;
167 if ( *it == command::C_opt_Verbose )
168 do_clVerbose(it,itEnd);
169 else if ( *it == command::C_opt_LangAll
170 OR *it == command::C_opt_Name
171 OR *it == command::C_opt_DevmanFile )
172 do_clParse(it,itEnd);
173 else if (*it == command::C_opt_CreateHtml)
174 do_clCreateHtml(it,itEnd);
175 else if (*it == command::C_opt_SinceFile)
176 do_clSinceFile(it,itEnd);
177 else if (*it == command::C_opt_ExternNamespace)
179 sExternNamespace = *(++it);
180 ++it;
181 if ( strncmp(sExternNamespace.c_str(), "::", 2) != 0)
183 throw command::X_CommandLine(
184 "-extnsp needs an absolute qualified namespace, starting with \"::\"."
188 else if (*it == command::C_opt_ExternRoot)
190 ++it;
191 StreamLock sl(1000);
192 if ( csv::compare(*it, 0, "http://", 7) != 0 )
194 sl() << "http://" << *it;
196 if ( *(sl().end()-1) != '/')
197 sl() << '/';
198 sExternRoot = sl().c_str();
200 ++it;
202 // else if (*it == command::C_opt_CreateXml)
203 // do_clCreateXml(it,itEnd);
204 // else if (command::C_opt_Load)
205 // do_clLoad(it,itEnd);
206 // else if (*it == command::C_opt_Save)
207 // do_clSave(it,itEnd);
208 else if (*it == "-h" OR *it == "-?" OR *it == "?")
209 // Leads to displaying help, because bInitOk stays on false.
210 return;
211 else if ( *it == command::C_opt_Parse )
212 // Only for backwards compatibility.
213 // Just ignore "-parse".
214 ++it;
215 else
217 StreamLock sl(200);
218 throw command::X_CommandLine(
219 sl() << "Unknown commandline option \""
220 << *it
221 << "\"."
222 << c_str );
224 } // end for
225 sort_Commands();
227 bInitOk = true;
229 } // end try
230 catch ( command::X_CommandLine & xxx )
232 xxx.Report( Cerr() );
234 catch ( csv::Exception & xxx )
236 xxx.GetInfo( Cerr() );
240 void
241 CommandLine::do_PrintUse() const
243 Cout() << C_sUserGuide << Endl();
246 bool
247 CommandLine::inq_CheckParameters() const
249 if (NOT bInitOk OR aCommands.empty())
250 return false;
251 return true;
254 void
255 CommandLine::load_IncludedCommands( StringVector & out,
256 const char * i_filePath )
258 CharacterSource
259 aIncludedCommands;
260 csv::File
261 aFile(i_filePath, csv::CFM_READ);
262 if (NOT aFile.open())
264 Cerr() << "Command include file \""
265 << i_filePath
266 << "\" not found."
267 << Endl();
268 throw command::X_CommandLine("Invalid file in option -I:<command-file>.");
270 aIncludedCommands.LoadText(aFile);
271 aFile.close();
273 bool bInToken = false;
274 StreamLock aTransmit(200);
275 for ( ; NOT aIncludedCommands.IsFinished(); aIncludedCommands.MoveOn() )
277 if (bInToken)
279 if (aIncludedCommands.CurChar() <= 32)
281 const char *
282 pToken = aIncludedCommands.CutToken();
283 bInToken = false;
285 if ( strncmp(pToken, "-I:", 3) != 0 )
287 aTransmit().seekp(0);
288 aTransmit() << pToken;
289 aTransmit().replace_all('\\', *csv::ploc::Delimiter());
290 aTransmit().replace_all('/', *csv::ploc::Delimiter());
291 out.push_back(String(aTransmit().c_str()));
293 else
294 load_IncludedCommands(out, pToken+3);
297 else
299 if (aIncludedCommands.CurChar() > 32)
301 aIncludedCommands.CutToken();
302 bInToken = true;
304 } // endif (bInToken) else
306 } // end while()
309 namespace
311 inline int
312 v_nr(StringVector::const_iterator it)
314 return int( *(*it).c_str() ) - int('0');
316 } // anonymous namespace
318 void
319 CommandLine::do_clVerbose( opt_iter & it,
320 opt_iter itEnd )
322 ++it;
323 if ( it == itEnd ? true : v_nr(it) < 0 OR v_nr(it) > 7 )
324 throw command::X_CommandLine( "Missing or invalid number in -v option." );
325 nDebugStyle = v_nr(it);
326 ++it;
329 void
330 CommandLine::do_clParse( opt_iter & it,
331 opt_iter itEnd )
333 command::Command *
334 pCmd_Parse = new command::Parse;
335 pCmd_Parse->Init(it, itEnd);
336 aCommands.push_back(pCmd_Parse);
339 void
340 CommandLine::do_clCreateHtml( opt_iter & it,
341 opt_iter itEnd )
343 pCommand_CreateHtml = new command::CreateHtml;
344 pCommand_CreateHtml->Init(it, itEnd);
345 aCommands.push_back(pCommand_CreateHtml);
348 void
349 CommandLine::do_clSinceFile( opt_iter & it,
350 opt_iter itEnd )
352 pSinceTransformator->Init(it, itEnd);
356 namespace
359 struct Less_RunningRank
361 bool operator()(
362 const command::Command * const &
364 const command::Command * const &
365 i2 ) const
366 { return i1->RunningRank() < i2->RunningRank(); }
369 } // anonymous namespace
373 void
374 CommandLine::sort_Commands()
376 std::sort( aCommands.begin(),
377 aCommands.end(),
378 Less_RunningRank() );
381 } // namespace autodoc
383 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */