merge the formfield patch from ooo-build
[ooovba.git] / autodoc / source / exes / adc_uni / adc_cl.cxx
blob8d2fa877457d7cd439880ad1a6006ce5e658b8ca
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: adc_cl.cxx,v $
10 * $Revision: 1.14 $
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 ************************************************************************/
31 #include <precomp.h>
32 #include <adc_cl.hxx>
35 // NOT FULLY DEFINED SERVICES
36 #include <algorithm>
37 #include <cosv/x.hxx>
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"
48 namespace autodoc
51 CommandLine * CommandLine::pTheInstance_ = 0;
53 const char * const C_sUserGuide =
54 "\n\n\n"
55 " General Use of Autodoc\n"
56 " ----------------------\n"
57 "\n"
58 " Example for C++:\n"
59 "\n"
60 " -html <OutputDirectory> -name \"UDK 3.x anything\" -lg c++\n"
61 " -p <ProjName> <ProjectRootDirectory>\n"
62 " -t <SourceDir_relativeToProjectRoot>\n"
63 "\n"
64 " There may be several projects specified by -p.\n"
65 "\n"
66 "\n"
67 " Example for IDL:\n"
68 "\n"
69 " -html <OutputDirectory> -name \"UDK 3.x anything\" -lg idl\n"
70 " -t <SourceDir1> <SourceDir2>\n"
71 "\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"
75 "\n"
76 "\n"
77 " Replacing @since Tag Content\n"
78 " ----------------------------\n"
79 "\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"
85 " Example:\n"
86 " -html <OutputDirectory> -sincefile replacesince.txt\n"
87 " -name \"UDK 3.x anything\" -lg idl -t <SourceDir>\n"
88 "\n"
89 "\n";
92 #if 0 // FUTURE
93 "\n\n\n"
94 " Use of Autodoc\n"
95 " --------------\n"
96 "\n"
97 " Basics:\n"
98 "\n"
99 " Autodoc may perform different tasks.\n"
100 "\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"
105 " option:\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"
110 "\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"
119 "\n"
120 "\n"
121 " Legend:\n"
122 "\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"
127 "\n"
128 "\n"
129 " Syntax:\n"
130 "\n"
131 " -parse\n"
132 " -name <RepositoryName>]\n"
133 " -lg 'c++'|'idl'\n"
134 " -extg <AdditonalExtensions>+\n"
135 " -docg 'usehtml'\n"
136 " -p <ProjectName> <ProjectRootDir>\n"
137 " -l 'c++'|'idl'\n"
138 " -ext <AdditonalExtensions>+\n"
139 " -doc 'usehtml'\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"
146 " -v <VerboseNr>\n"
147 "\n"
148 "\n"
149 " Detailed Options Description:\n"
150 "\n"
151 " Option Arguments\n"
152 " ----------------------------------------------------------\n"
153 "\n"
154 " -parse \n\n"
155 " Starts the task \"Parse source code\".\n"
156 " May be omitted, if it would be the first option on the\n"
157 " command line.\n"
158 "\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"
163 "\n"
164 " -lg 'c++|'idl'\n\n"
165 " Identifies the programming language to be parsed.\n"
166 " 'c++': C++\n"
167 " Files with extensions '.h', '.hxx' are parsed.\n"
168 " 'idl': UNO-IDL\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"
172 "\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"
182 "\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"
186 " regular text.\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"
190 "\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"
197 "\n"
198 " -l 'c++|'idl'\n\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"
202 "\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"
208 "\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"
213 "\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"
218 "\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"
223 "\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"
228 "\n"
229 " -html <OutputRootDir>\n\n"
230 " Starts the task \"Create HTML output\".\n"
231 "\n"
232 " -xlinks <Namespace> <ExternLinksRootDir>\n\n"
233 " This option allows, to create links to external\n"
234 " HTML-documents.\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"
240 "\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"
248 "\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";
257 #endif // 0, FUTURE
260 CommandLine::CommandLine()
261 : nDebugStyle(0),
262 pSinceTransformator(new command::SinceTagTransformationData),
263 aCommands(),
264 bInitOk(false),
265 pCommand_CreateHtml(0),
266 pReposy( & ary::Repository::Create_() ),
267 bCpp(false),
268 bIdl(false)
270 csv_assert(pTheInstance_ == 0);
271 pTheInstance_ = this;
274 CommandLine::~CommandLine()
276 csv::erase_container_of_heap_ptrs(aCommands);
277 pTheInstance_ = 0;
281 CommandLine::Run() const
283 Cout() << "\nAutodoc version 2.2.5"
284 << "\n---------------------"
285 << "\n" << Endl();
287 bool
288 ok = true;
289 for ( CommandList::const_iterator it = aCommands.begin();
290 ok AND it != aCommands.end();
291 ++it )
293 ok = (*it)->Run();
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());
306 return ok ? 0 : 1;
309 CommandLine &
310 CommandLine::Get_()
312 csv_assert(pTheInstance_ != 0);
313 return *pTheInstance_;
316 bool
317 CommandLine::DoesTransform_SinceTag() const
319 return pSinceTransformator->DoesTransform();
322 //bool
323 //CommandLine::Strip_SinceTagText( String & io_sSinceTagValue ) const
325 // return pSinceTransformator->StripSinceTagText(io_sSinceTagValue);
328 const String &
329 CommandLine::DisplayOf_SinceTagValue( const String & i_sVersionNumber ) const
331 return pSinceTransformator->DisplayOf(i_sVersionNumber);
334 void
335 CommandLine::do_Init( int argc,
336 char * argv[] )
340 bInitOk = false;
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));
348 else
349 load_IncludedCommands(aParameters, (*itp)+3);
352 StringVector::const_iterator itEnd = aParameters.end();
353 for ( StringVector::const_iterator it = aParameters.begin();
354 it != itEnd;
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);
370 ++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)
380 ++it;
381 StreamLock sl(1000);
382 if ( csv::compare(*it, 0, "http://", 7) != 0 )
384 sl() << "http://" << *it;
386 if ( *(sl().end()-1) != '/')
387 sl() << '/';
388 sExternRoot = sl().c_str();
390 ++it;
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.
400 return;
401 else if ( *it == command::C_opt_Parse )
402 // Only for backwards compatibility.
403 // Just ignore "-parse".
404 ++it;
405 else
407 StreamLock sl(200);
408 throw command::X_CommandLine(
409 sl() << "Unknown commandline option \""
410 << *it
411 << "\"."
412 << c_str );
414 } // end for
415 sort_Commands();
417 bInitOk = true;
419 } // end try
420 catch ( command::X_CommandLine & xxx )
422 xxx.Report( Cerr() );
424 catch ( csv::Exception & xxx )
426 xxx.GetInfo( Cerr() );
430 void
431 CommandLine::do_PrintUse() const
433 Cout() << C_sUserGuide << Endl();
436 bool
437 CommandLine::inq_CheckParameters() const
439 if (NOT bInitOk OR aCommands.size() == 0)
440 return false;
441 return true;
444 void
445 CommandLine::load_IncludedCommands( StringVector & out,
446 const char * i_filePath )
448 CharacterSource
449 aIncludedCommands;
450 csv::File
451 aFile(i_filePath, csv::CFM_READ);
452 if (NOT aFile.open())
454 Cerr() << "Command include file \""
455 << i_filePath
456 << "\" not found."
457 << Endl();
458 throw command::X_CommandLine("Invalid file in option -I:<command-file>.");
460 aIncludedCommands.LoadText(aFile);
461 aFile.close();
463 bool bInToken = false;
464 StreamLock aTransmit(200);
465 for ( ; NOT aIncludedCommands.IsFinished(); aIncludedCommands.MoveOn() )
467 if (bInToken)
469 if (aIncludedCommands.CurChar() <= 32)
471 const char *
472 pToken = aIncludedCommands.CutToken();
473 bInToken = false;
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()));
483 else
484 load_IncludedCommands(out, pToken+3);
487 else
489 if (aIncludedCommands.CurChar() > 32)
491 aIncludedCommands.CutToken();
492 bInToken = true;
494 } // endif (bInToken) else
496 } // end while()
499 namespace
501 inline int
502 v_nr(StringVector::const_iterator it)
504 return int( *(*it).c_str() ) - int('0');
506 } // anonymous namespace
508 void
509 CommandLine::do_clVerbose( opt_iter & it,
510 opt_iter itEnd )
512 ++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);
516 ++it;
519 void
520 CommandLine::do_clParse( opt_iter & it,
521 opt_iter itEnd )
523 command::Command *
524 pCmd_Parse = new command::Parse;
525 pCmd_Parse->Init(it, itEnd);
526 aCommands.push_back(pCmd_Parse);
529 void
530 CommandLine::do_clCreateHtml( opt_iter & it,
531 opt_iter itEnd )
533 pCommand_CreateHtml = new command::CreateHtml;
534 pCommand_CreateHtml->Init(it, itEnd);
535 aCommands.push_back(pCommand_CreateHtml);
538 void
539 CommandLine::do_clSinceFile( opt_iter & it,
540 opt_iter itEnd )
542 pSinceTransformator->Init(it, itEnd);
546 namespace
549 struct Less_RunningRank
551 bool operator()(
552 const command::Command * const &
554 const command::Command * const &
555 i2 ) const
556 { return i1->RunningRank() < i2->RunningRank(); }
559 } // anonymous namespace
563 void
564 CommandLine::sort_Commands()
566 std::sort( aCommands.begin(),
567 aCommands.end(),
568 Less_RunningRank() );
571 } // namespace autodoc