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 ************************************************************************/
33 // NOT FULLY DEFINED SERVICES
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"
49 CommandLine
* CommandLine::pTheInstance_
= 0;
51 const char * const C_sUserGuide
=
53 " General Use of Autodoc\n"
54 " ----------------------\n"
58 " -html <OutputDirectory> -name \"UDK 3.x anything\" -lg idl\n"
59 " -t <SourceDir1> <SourceDir2>\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"
66 " Replacing @since Tag Content\n"
67 " ----------------------------\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"
75 " -html <OutputDirectory> -sincefile replacesince.txt\n"
76 " -name \"UDK 3.x anything\" -lg idl -t <SourceDir>\n"
80 CommandLine::CommandLine()
82 pSinceTransformator(new command::SinceTagTransformationData
),
85 pCommand_CreateHtml(0),
86 pReposy( & ary::Repository::Create_() ),
89 csv_assert(pTheInstance_
== 0);
93 CommandLine::~CommandLine()
95 csv::erase_container_of_heap_ptrs(aCommands
);
100 CommandLine::Run() const
102 Cout() << "\nAutodoc version 2.2.5"
103 << "\n---------------------"
108 for ( CommandList::const_iterator it
= aCommands
.begin();
109 ok AND it
!= aCommands
.end();
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());
131 csv_assert(pTheInstance_
!= 0);
132 return *pTheInstance_
;
136 CommandLine::DoesTransform_SinceTag() const
138 return pSinceTransformator
->DoesTransform();
142 //CommandLine::Strip_SinceTagText( String & io_sSinceTagValue ) const
144 // return pSinceTransformator->StripSinceTagText(io_sSinceTagValue);
148 CommandLine::DisplayOf_SinceTagValue( const String
& i_sVersionNumber
) const
150 return pSinceTransformator
->DisplayOf(i_sVersionNumber
);
154 CommandLine::do_Init( int argc
,
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
));
168 load_IncludedCommands(aParameters
, (*itp
)+3);
171 StringVector::const_iterator itEnd
= aParameters
.end();
172 for ( StringVector::const_iterator it
= aParameters
.begin();
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
);
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
)
201 if ( csv::compare(*it
, 0, "http://", 7) != 0 )
203 sl() << "http://" << *it
;
205 if ( *(sl().end()-1) != '/')
207 sExternRoot
= sl().c_str();
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.
220 else if ( *it
== command::C_opt_Parse
)
221 // Only for backwards compatibility.
222 // Just ignore "-parse".
227 throw command::X_CommandLine(
228 sl() << "Unknown commandline option \""
239 catch ( command::X_CommandLine
& xxx
)
241 xxx
.Report( Cerr() );
243 catch ( csv::Exception
& xxx
)
245 xxx
.GetInfo( Cerr() );
250 CommandLine::do_PrintUse() const
252 Cout() << C_sUserGuide
<< Endl();
256 CommandLine::inq_CheckParameters() const
258 if (NOT bInitOk OR aCommands
.empty())
264 CommandLine::load_IncludedCommands( StringVector
& out
,
265 const char * i_filePath
)
270 aFile(i_filePath
, csv::CFM_READ
);
271 if (NOT aFile
.open())
273 Cerr() << "Command include file \""
277 throw command::X_CommandLine("Invalid file in option -I:<command-file>.");
279 aIncludedCommands
.LoadText(aFile
);
282 bool bInToken
= false;
283 StreamLock
aTransmit(200);
284 for ( ; NOT aIncludedCommands
.IsFinished(); aIncludedCommands
.MoveOn() )
288 if (aIncludedCommands
.CurChar() <= 32)
291 pToken
= aIncludedCommands
.CutToken();
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()));
303 load_IncludedCommands(out
, pToken
+3);
308 if (aIncludedCommands
.CurChar() > 32)
310 aIncludedCommands
.CutToken();
313 } // endif (bInToken) else
321 v_nr(StringVector::const_iterator it
)
323 return int( *(*it
).c_str() ) - int('0');
325 } // anonymous namespace
328 CommandLine::do_clVerbose( opt_iter
& 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
);
339 CommandLine::do_clParse( opt_iter
& it
,
343 pCmd_Parse
= new command::Parse
;
344 pCmd_Parse
->Init(it
, itEnd
);
345 aCommands
.push_back(pCmd_Parse
);
349 CommandLine::do_clCreateHtml( opt_iter
& it
,
352 pCommand_CreateHtml
= new command::CreateHtml
;
353 pCommand_CreateHtml
->Init(it
, itEnd
);
354 aCommands
.push_back(pCommand_CreateHtml
);
358 CommandLine::do_clSinceFile( opt_iter
& it
,
361 pSinceTransformator
->Init(it
, itEnd
);
368 struct Less_RunningRank
371 const command::Command
* const &
373 const command::Command
* const &
375 { return i1
->RunningRank() < i2
->RunningRank(); }
378 } // anonymous namespace
383 CommandLine::sort_Commands()
385 std::sort( aCommands
.begin(),
387 Less_RunningRank() );
390 } // namespace autodoc
392 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */