1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
24 // NOT FULLY DEFINED SERVICES
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"
40 CommandLine
* CommandLine::pTheInstance_
= 0;
42 const char * const C_sUserGuide
=
44 " General Use of Autodoc\n"
45 " ----------------------\n"
49 " -html <OutputDirectory> -name \"UDK 3.x anything\" -lg idl\n"
50 " -t <SourceDir1> <SourceDir2>\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"
57 " Replacing @since Tag Content\n"
58 " ----------------------------\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"
66 " -html <OutputDirectory> -sincefile replacesince.txt\n"
67 " -name \"UDK 3.x anything\" -lg idl -t <SourceDir>\n"
71 CommandLine::CommandLine()
73 pSinceTransformator(new command::SinceTagTransformationData
),
76 pCommand_CreateHtml(0),
77 pReposy( & ary::Repository::Create_() ),
80 csv_assert(pTheInstance_
== 0);
84 CommandLine::~CommandLine()
86 csv::erase_container_of_heap_ptrs(aCommands
);
91 CommandLine::Run() const
93 Cout() << "\nAutodoc version 2.2.5"
94 << "\n---------------------"
99 for ( CommandList::const_iterator it
= aCommands
.begin();
100 ok AND it
!= aCommands
.end();
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());
122 csv_assert(pTheInstance_
!= 0);
123 return *pTheInstance_
;
127 CommandLine::DoesTransform_SinceTag() const
129 return pSinceTransformator
->DoesTransform();
133 //CommandLine::Strip_SinceTagText( String & io_sSinceTagValue ) const
135 // return pSinceTransformator->StripSinceTagText(io_sSinceTagValue);
139 CommandLine::DisplayOf_SinceTagValue( const String
& i_sVersionNumber
) const
141 return pSinceTransformator
->DisplayOf(i_sVersionNumber
);
145 CommandLine::do_Init( int argc
,
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
));
159 load_IncludedCommands(aParameters
, (*itp
)+3);
162 StringVector::const_iterator itEnd
= aParameters
.end();
163 for ( StringVector::const_iterator it
= aParameters
.begin();
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
);
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
)
192 if ( csv::compare(*it
, 0, "http://", 7) != 0 )
194 sl() << "http://" << *it
;
196 if ( *(sl().end()-1) != '/')
198 sExternRoot
= sl().c_str();
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.
211 else if ( *it
== command::C_opt_Parse
)
212 // Only for backwards compatibility.
213 // Just ignore "-parse".
218 throw command::X_CommandLine(
219 sl() << "Unknown commandline option \""
230 catch ( command::X_CommandLine
& xxx
)
232 xxx
.Report( Cerr() );
234 catch ( csv::Exception
& xxx
)
236 xxx
.GetInfo( Cerr() );
241 CommandLine::do_PrintUse() const
243 Cout() << C_sUserGuide
<< Endl();
247 CommandLine::inq_CheckParameters() const
249 if (NOT bInitOk OR aCommands
.empty())
255 CommandLine::load_IncludedCommands( StringVector
& out
,
256 const char * i_filePath
)
261 aFile(i_filePath
, csv::CFM_READ
);
262 if (NOT aFile
.open())
264 Cerr() << "Command include file \""
268 throw command::X_CommandLine("Invalid file in option -I:<command-file>.");
270 aIncludedCommands
.LoadText(aFile
);
273 bool bInToken
= false;
274 StreamLock
aTransmit(200);
275 for ( ; NOT aIncludedCommands
.IsFinished(); aIncludedCommands
.MoveOn() )
279 if (aIncludedCommands
.CurChar() <= 32)
282 pToken
= aIncludedCommands
.CutToken();
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()));
294 load_IncludedCommands(out
, pToken
+3);
299 if (aIncludedCommands
.CurChar() > 32)
301 aIncludedCommands
.CutToken();
304 } // endif (bInToken) else
312 v_nr(StringVector::const_iterator it
)
314 return int( *(*it
).c_str() ) - int('0');
316 } // anonymous namespace
319 CommandLine::do_clVerbose( opt_iter
& 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
);
330 CommandLine::do_clParse( opt_iter
& it
,
334 pCmd_Parse
= new command::Parse
;
335 pCmd_Parse
->Init(it
, itEnd
);
336 aCommands
.push_back(pCmd_Parse
);
340 CommandLine::do_clCreateHtml( opt_iter
& it
,
343 pCommand_CreateHtml
= new command::CreateHtml
;
344 pCommand_CreateHtml
->Init(it
, itEnd
);
345 aCommands
.push_back(pCommand_CreateHtml
);
349 CommandLine::do_clSinceFile( opt_iter
& it
,
352 pSinceTransformator
->Init(it
, itEnd
);
359 struct Less_RunningRank
362 const command::Command
* const &
364 const command::Command
* const &
366 { return i1
->RunningRank() < i2
->RunningRank(); }
369 } // anonymous namespace
374 CommandLine::sort_Commands()
376 std::sort( aCommands
.begin(),
378 Less_RunningRank() );
381 } // namespace autodoc
383 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */