1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: adc_cl.cxx,v $
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 ************************************************************************/
35 // NOT FULLY DEFINED SERVICES
38 #include <cosv/file.hxx>
39 #include <cosv/tpl/tpltools.hxx>
40 #include <ary/ary.hxx>
41 #include <tools/tkpchars.hxx>
42 #include <adc_msg.hxx>
43 #include "adc_cmds.hxx"
44 #include "adc_cmd_parse.hxx"
45 #include "cmd_sincedata.hxx"
51 CommandLine
* CommandLine::pTheInstance_
= 0;
53 const char * const C_sUserGuide
=
55 " General Use of Autodoc\n"
56 " ----------------------\n"
60 " -html <OutputDirectory> -name \"UDK 3.x anything\" -lg c++\n"
61 " -p <ProjName> <ProjectRootDirectory>\n"
62 " -t <SourceDir_relativeToProjectRoot>\n"
64 " There may be several projects specified by -p.\n"
69 " -html <OutputDirectory> -name \"UDK 3.x anything\" -lg idl\n"
70 " -t <SourceDir1> <SourceDir2>\n"
72 " For both languages, instead of or in addition to -t may be\n"
73 " used -d (no subdirectories) or -f (just one file). There can\n"
74 " be multiple arguments after each of these options (-t -d -f).\n"
77 " Replacing @since Tag Content\n"
78 " ----------------------------\n"
80 " In both languages you can give a transformation file to replace\n"
81 " entries in @since tags by different entries.\n"
82 " This file is given by the option\n"
83 " -sincefile <TransformationFilePath>\n"
84 " This option has to appear between the -html and the -lg option.\n"
86 " -html <OutputDirectory> -sincefile replacesince.txt\n"
87 " -name \"UDK 3.x anything\" -lg idl -t <SourceDir>\n"
99 " Autodoc may perform different tasks.\n"
101 " Possible tasks are\n"
102 " - parsing source code\n"
103 " - creating HTML-output.\n"
104 " On the command line each task starts with a specific\n"
106 " '-parse' for parsing source code,\n"
107 " '-html' for creating HTML.\n"
108 " All command line options, related to one task, have to follow before\n"
109 " the starting option of the next task.\n"
111 " Within the task '-parse', there may be defined different projects.\n"
112 " A project definition is started with '-p'.\n"
113 " All not project specific options within the task '-parse' have to\n"
114 " appear in front of the first '-p'.\n"
115 " There can be no project at all. Then all options, available for\n"
116 " projects, can be used like for one nameless default project, without using\n"
117 " '-p', but these options still have to appear behind all other\n"
118 " options of the task '-parse'.\n"
123 " <SomeText> Describes an argument.\n"
124 " 'SomeText' Within '...' is the literal value of an argument.\n"
125 " + There can be multiple arguments.\n"
126 " | Separator for alternative literal values of an argument.\n"
132 " -name <RepositoryName>]\n"
134 " -extg <AdditonalExtensions>+\n"
136 " -p <ProjectName> <ProjectRootDir>\n"
138 " -ext <AdditonalExtensions>+\n"
140 " -d <SourceDir_relative2ProjectRootDir_nosubdirs>+\n"
141 " -t <SourceTree_relative2ProjectRootDir>+\n"
142 " -f <SourceFile_relative2ProjectRootDir>+\n"
143 " -html <OutputDir>\n"
144 " -xlinks <Namespace> <ExternLinksRootDir>\n"
145 " -i <CommandFilePath>\n"
149 " Detailed Options Description:\n"
151 " Option Arguments\n"
152 " ----------------------------------------------------------\n"
155 " Starts the task \"Parse source code\".\n"
156 " May be omitted, if it would be the first option on the\n"
159 " -name <RepositoryName>\n\n"
160 " This name is used for naming the repository in\n"
161 " human readable output. In future it may be used also for\n"
162 " identifiing a repository in searches.\n"
164 " -lg 'c++|'idl'\n\n"
165 " Identifies the programming language to be parsed.\n"
167 " Files with extensions '.h', '.hxx' are parsed.\n"
169 " Files with extensions '.idl' are parsed.\n"
170 " Here the language is set globally for all projects.\n"
171 " A project can override this by using '-l'.\n"
173 " -extg <.AdditionalExtension>+\n\n"
174 " Has to follow immediately behind '-lg'.\n"
175 " Specifies additional extensions, that will be recognised as\n"
176 " source code files of the previously specified programming\n"
177 " language. Each extension has to start with '.'.\n"
178 " It is possible to include extensionless files, too,\n"
179 " by the argument '.'\n"
180 " Here these extensions are set globally for all projects.\n"
181 " A project can override this by using '-l' and '-ext'.\n"
183 " -docg 'html'|'nohtml'\n\n"
184 " Specifies the default for all comments in source code, so \n"
185 " that HTML-tags are interpreted as such or else treated as\n"
187 " Without this option, the default is 'nohtml'.\n"
188 " Here the default is set globally for all projects.\n"
189 " A project can override this by using '-doc'.\n"
191 " -p <ProjectName> <ProjectRootDirectory>\n\n"
192 " ProjectName is used in output as human readable identifier\n"
193 " for the project. ProjectRootDirectory is the path,\n"
194 " where the arguments of '-d', '-t' and '-f' are relative to.\n"
195 " This option can be omitted, then there is no project name\n"
196 " and all paths are relative to the current working directory.\n"
199 " Overrides -lg and -extg for the current project, which is\n"
200 " specified by the last previous '-p'.\n"
201 " For details see at option '-lg'.\n"
203 " -ext <.AdditionalExtension>+\n\n"
204 " Can be used only immediately behind '-l'.\n"
205 " Overrides -extg for the current project, which is\n"
206 " specified by the last previous '-p'.\n"
207 " For details see at option '-extg'.\n"
209 " -doc 'html'|'nohtml'\n\n"
210 " Overrides -docg for the current project, which is\n"
211 " specified by the last previous '-p'.\n"
212 " For details see at option '-docg'.\n"
214 " -d <SourceDir_relative2ProjectRootDir_nosubdirs>+\n\n"
215 " For the current project all files in the given\n"
216 " directories are parsed, which have valid extensions.\n"
217 " Subdirectories are NOT parsed.\n"
219 " -t <SourceTree_relative2ProjectRootDir>+\n\n"
220 " For the current project all files in the given\n"
221 " directories AND its subdirectories are parsed, which\n"
222 " have valid extensions.\n"
224 " -f <SourceFile_relative2ProjectRootDir>+\n\n"
225 " For the current project and language the given files\n"
226 " are parsed. It doesn't matter, if their extensions match\n"
227 " the valid extensions.\n"
229 " -html <OutputRootDir>\n\n"
230 " Starts the task \"Create HTML output\".\n"
232 " -xlinks <Namespace> <ExternLinksRootDir>\n\n"
233 " This option allows, to create links to external\n"
235 " For all source code objects (like classes or functions)\n"
236 " which belong in the given namespace, the given root\n"
237 " directory is used as a base for links to them.\n"
238 " Presently, this works only for C++-mappings of IDL-items.\n"
239 " The given namespace has to be absolute.\n"
241 " -i <CommandFilePath>\n\n"
242 " This option is replaced by the contents of the given\n"
243 " file. The file has to be ASCII and each option\n"
244 " has to start in the first column of a new line.\n"
245 " So each valid line starts with a '-'.\n"
246 " Empty lines are allowed.\n"
247 " Comment lines have to start with '#'\n"
249 " -v <VerboseNumber>\n\n"
250 " Show details during parsing:\n"
251 " 2 shows each parsed letter,\n"
252 " 4 shows stored objects.\n"
253 " 1 shows recognised tokens.\n"
254 " These bit-values can be combined.\n"
255 " This option suppresses errors, because of\n"
256 " missing output options (no '-html').\n";
260 CommandLine::CommandLine()
262 pSinceTransformator(new command::SinceTagTransformationData
),
265 pCommand_CreateHtml(0),
266 pReposy( & ary::Repository::Create_() ),
270 csv_assert(pTheInstance_
== 0);
271 pTheInstance_
= this;
274 CommandLine::~CommandLine()
276 csv::erase_container_of_heap_ptrs(aCommands
);
281 CommandLine::Run() const
283 Cout() << "\nAutodoc version 2.2.5"
284 << "\n---------------------"
289 for ( CommandList::const_iterator it
= aCommands
.begin();
290 ok AND it
!= aCommands
.end();
296 if (pCommand_CreateHtml
!= 0)
298 StreamStr
aDiagnosticMessagesFile(700);
299 aDiagnosticMessagesFile
300 << pCommand_CreateHtml
->OutputDir()
301 << csv::ploc::Delimiter()
302 << "Autodoc_DiagnosticMessages.txt";
303 TheMessages().WriteFile(aDiagnosticMessagesFile
.c_str());
312 csv_assert(pTheInstance_
!= 0);
313 return *pTheInstance_
;
317 CommandLine::DoesTransform_SinceTag() const
319 return pSinceTransformator
->DoesTransform();
323 //CommandLine::Strip_SinceTagText( String & io_sSinceTagValue ) const
325 // return pSinceTransformator->StripSinceTagText(io_sSinceTagValue);
329 CommandLine::DisplayOf_SinceTagValue( const String
& i_sVersionNumber
) const
331 return pSinceTransformator
->DisplayOf(i_sVersionNumber
);
335 CommandLine::do_Init( int argc
,
341 StringVector aParameters
;
343 char * * itpEnd
= &argv
[0] + argc
;
344 for ( char * * itp
= &argv
[1]; itp
!= itpEnd
; ++itp
)
346 if ( strncmp(*itp
, "-I:", 3) != 0 )
347 aParameters
.push_back(String(*itp
));
349 load_IncludedCommands(aParameters
, (*itp
)+3);
352 StringVector::const_iterator itEnd
= aParameters
.end();
353 for ( StringVector::const_iterator it
= aParameters
.begin();
357 if ( *it
== command::C_opt_Verbose
)
358 do_clVerbose(it
,itEnd
);
359 else if ( *it
== command::C_opt_LangAll
360 OR
*it
== command::C_opt_Name
361 OR
*it
== command::C_opt_DevmanFile
)
362 do_clParse(it
,itEnd
);
363 else if (*it
== command::C_opt_CreateHtml
)
364 do_clCreateHtml(it
,itEnd
);
365 else if (*it
== command::C_opt_SinceFile
)
366 do_clSinceFile(it
,itEnd
);
367 else if (*it
== command::C_opt_ExternNamespace
)
369 sExternNamespace
= *(++it
);
371 if ( strncmp(sExternNamespace
.c_str(), "::", 2) != 0)
373 throw command::X_CommandLine(
374 "-extnsp needs an absolute qualified namespace, starting with \"::\"."
378 else if (*it
== command::C_opt_ExternRoot
)
382 if ( csv::compare(*it
, 0, "http://", 7) != 0 )
384 sl() << "http://" << *it
;
386 if ( *(sl().end()-1) != '/')
388 sExternRoot
= sl().c_str();
392 // else if (*it == command::C_opt_CreateXml)
393 // do_clCreateXml(it,itEnd);
394 // else if (command::C_opt_Load)
395 // do_clLoad(it,itEnd);
396 // else if (*it == command::C_opt_Save)
397 // do_clSave(it,itEnd);
398 else if (*it
== "-h" OR
*it
== "-?" OR
*it
== "?")
399 // Leads to displaying help, because bInitOk stays on false.
401 else if ( *it
== command::C_opt_Parse
)
402 // Only for backwards compatibility.
403 // Just ignore "-parse".
408 throw command::X_CommandLine(
409 sl() << "Unknown commandline option \""
420 catch ( command::X_CommandLine
& xxx
)
422 xxx
.Report( Cerr() );
424 catch ( csv::Exception
& xxx
)
426 xxx
.GetInfo( Cerr() );
431 CommandLine::do_PrintUse() const
433 Cout() << C_sUserGuide
<< Endl();
437 CommandLine::inq_CheckParameters() const
439 if (NOT bInitOk OR aCommands
.size() == 0)
445 CommandLine::load_IncludedCommands( StringVector
& out
,
446 const char * i_filePath
)
451 aFile(i_filePath
, csv::CFM_READ
);
452 if (NOT aFile
.open())
454 Cerr() << "Command include file \""
458 throw command::X_CommandLine("Invalid file in option -I:<command-file>.");
460 aIncludedCommands
.LoadText(aFile
);
463 bool bInToken
= false;
464 StreamLock
aTransmit(200);
465 for ( ; NOT aIncludedCommands
.IsFinished(); aIncludedCommands
.MoveOn() )
469 if (aIncludedCommands
.CurChar() <= 32)
472 pToken
= aIncludedCommands
.CutToken();
475 if ( strncmp(pToken
, "-I:", 3) != 0 )
477 aTransmit().seekp(0);
478 aTransmit() << pToken
;
479 aTransmit().replace_all('\\', *csv::ploc::Delimiter());
480 aTransmit().replace_all('/', *csv::ploc::Delimiter());
481 out
.push_back(String(aTransmit().c_str()));
484 load_IncludedCommands(out
, pToken
+3);
489 if (aIncludedCommands
.CurChar() > 32)
491 aIncludedCommands
.CutToken();
494 } // endif (bInToken) else
502 v_nr(StringVector::const_iterator it
)
504 return int( *(*it
).c_str() ) - int('0');
506 } // anonymous namespace
509 CommandLine::do_clVerbose( opt_iter
& it
,
513 if ( it
== itEnd
? true : v_nr(it
) < 0 OR
v_nr(it
) > 7 )
514 throw command::X_CommandLine( "Missing or invalid number in -v option." );
515 nDebugStyle
= v_nr(it
);
520 CommandLine::do_clParse( opt_iter
& it
,
524 pCmd_Parse
= new command::Parse
;
525 pCmd_Parse
->Init(it
, itEnd
);
526 aCommands
.push_back(pCmd_Parse
);
530 CommandLine::do_clCreateHtml( opt_iter
& it
,
533 pCommand_CreateHtml
= new command::CreateHtml
;
534 pCommand_CreateHtml
->Init(it
, itEnd
);
535 aCommands
.push_back(pCommand_CreateHtml
);
539 CommandLine::do_clSinceFile( opt_iter
& it
,
542 pSinceTransformator
->Init(it
, itEnd
);
549 struct Less_RunningRank
552 const command::Command
* const &
554 const command::Command
* const &
556 { return i1
->RunningRank() < i2
->RunningRank(); }
559 } // anonymous namespace
564 CommandLine::sort_Commands()
566 std::sort( aCommands
.begin(),
568 Less_RunningRank() );
571 } // namespace autodoc