Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
THtml.cxx
Go to the documentation of this file.
1 // @(#)root/html:$Id$
2 // Author: Nenad Buncic (18/10/95), Axel Naumann (09/28/01)
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "THtml.h"
13 #include "RConfigure.h"
14 #include "Riostream.h"
15 #include "TBaseClass.h"
16 #include "TClass.h"
17 #include "TClassDocOutput.h"
18 #include "TClassEdit.h"
19 #include "TClassTable.h"
20 #include "TDataType.h"
21 #include "TDocInfo.h"
22 #include "TDocOutput.h"
23 #include "TEnv.h"
24 #include "TInterpreter.h"
25 #include "TObjString.h"
26 #include "TPRegexp.h"
27 #include "TRegexp.h"
28 #include "TROOT.h"
29 #include "TSystem.h"
30 #include "TThread.h"
31 
32 #include <stdlib.h>
33 #include <string.h>
34 #include <ctype.h>
35 #include <set>
36 #include <fstream>
37 
38 THtml *gHtml = 0;
39 
40 //______________________________________________________________________________
41 //______________________________________________________________________________
42 namespace {
43  class THtmlThreadInfo {
44  public:
45  THtmlThreadInfo(THtml* html, bool force): fHtml(html), fForce(force) {}
46  Bool_t GetForce() const {return fForce;}
47  THtml* GetHtml() const {return fHtml;}
48 
49  private:
50  THtml* fHtml;
51  Bool_t fForce;
52  };
53 };
54 
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// Helper's destructor.
58 /// Check that no THtml object is attached to the helper - it might still need it!
59 
60 THtml::THelperBase::~THelperBase()
61 {
62  if (fHtml) {
63  fHtml->HelperDeleted(this);
64  }
65 }
66 
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// Set the THtml object owning this object; if it's already set to
70 /// a different THtml object than issue an error message and signal to
71 /// the currently set object that we are not belonging to it anymore.
72 
73 void THtml::THelperBase::SetOwner(THtml* html) {
74  if (fHtml && html && html != fHtml) {
75  Error("SetOwner()", "Object already owned by an THtml instance!");
76  fHtml->HelperDeleted(this);
77  }
78  fHtml = html;
79 }
80 
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// Set out_modulename to cl's module name; return true if it's valid.
84 /// If applicable, the module contains super modules separated by "/".
85 ///
86 /// ROOT takes the directory part of cl's implementation file name
87 /// (or declaration file name, if the implementation file name is empty),
88 /// removes the last subdirectory if it is "src/" or "inc/", and interprets
89 /// the remaining path as the module hierarchy, converting it to upper case.
90 /// hist/histpainter/src/THistPainter.cxx thus becomes the module
91 /// HIST/HISTPAINTER. (Node: some ROOT packages get special treatment.)
92 /// If the file cannot be mapped into this scheme, the class's library
93 /// name (without directories, leading "lib" prefix or file extensions)
94 /// ius taken as the module name. If the module cannot be determined it is
95 /// set to "USER" and false is returned.
96 ///
97 /// If your software cannot be mapped into this scheme then derive your
98 /// own class from TModuleDefinition and pass it to THtml::SetModuleDefinition().
99 ///
100 /// The fse parameter is used to determine the relevant part of the path, i.e.
101 /// to not include parent directories of a TFileSysRoot.
102 
103 bool THtml::TModuleDefinition::GetModule(TClass* cl, TFileSysEntry* fse,
104  TString& out_modulename) const
105 {
106  out_modulename = "USER";
107  if (!cl) return false;
108 
109  // Filename: impl or decl?
110  TString filename;
111  if (fse) fse->GetFullName(filename, kFALSE);
112  else {
113  if (!GetOwner()->GetImplFileName(cl, kFALSE, filename))
114  if (!GetOwner()->GetDeclFileName(cl, kFALSE, filename))
115  return false;
116  }
117  TString inputdir = GetOwner()->GetInputPath();
118  TString tok;
119  Ssiz_t start = 0;
120  // For -Idir/sub and A.h in dir/sub/A.h, use sub as module name if
121  // it would eb empty otehrwise.
122  TString trailingInclude;
123  while (inputdir.Tokenize(tok, start, THtml::GetDirDelimiter())) {
124  if (filename.BeginsWith(tok)) {
125  if (tok.EndsWith("/") || tok.EndsWith("\\"))
126  tok.Remove(tok.Length() - 1);
127  trailingInclude = gSystem->BaseName(tok);
128  filename.Remove(0, tok.Length());
129  break;
130  }
131  }
132 
133  // take the directory name without "/" or leading "."
134  out_modulename = gSystem->DirName(filename);
135 
136  while (out_modulename[0] == '.')
137  out_modulename.Remove(0, 1);
138  out_modulename.ReplaceAll("\\", "/");
139  while (out_modulename[0] == '/')
140  out_modulename.Remove(0, 1);
141  while (out_modulename.EndsWith("/"))
142  out_modulename.Remove(out_modulename.Length() - 1);
143 
144  if (!out_modulename[0])
145  out_modulename = trailingInclude;
146 
147  if (!out_modulename[0])
148  out_modulename = trailingInclude;
149 
150  // remove "/src", "/inc"
151  if (out_modulename.EndsWith("/src")
152  || out_modulename.EndsWith("/inc"))
153  out_modulename.Remove(out_modulename.Length() - 4, 4);
154  else {
155  // remove "/src/whatever", "/inc/whatever"
156  Ssiz_t pos = out_modulename.Index("/src/");
157  if (pos == kNPOS)
158  pos = out_modulename.Index("/inc/");
159  if (pos != kNPOS)
160  out_modulename.Remove(pos);
161  }
162 
163  while (out_modulename.EndsWith("/"))
164  out_modulename.Remove(out_modulename.Length() - 1);
165 
166  // special treatment:
167  if (out_modulename == "MATH/GENVECTOR")
168  out_modulename = "MATHCORE";
169  else if (out_modulename == "MATH/MATRIX")
170  out_modulename = "SMATRIX";
171  else if (!out_modulename.Length()) {
172  const char* cname= cl->GetName();
173  if (strstr(cname, "::SMatrix<") || strstr(cname, "::SVector<"))
174  out_modulename = "SMATRIX";
175  else if (strstr(cname, "::TArrayProxy<") || strstr(cname, "::TClaArrayProxy<")
176  || strstr(cname, "::TImpProxy<") || strstr(cname, "::TClaImpProxy<"))
177  out_modulename = "TREEPLAYER";
178  else {
179  // determine the module name from the library name:
180  out_modulename = cl->GetSharedLibs();
181  Ssiz_t pos = out_modulename.Index(' ');
182  if (pos != kNPOS)
183  out_modulename.Remove(pos, out_modulename.Length());
184  if (out_modulename.BeginsWith("lib"))
185  out_modulename.Remove(0,3);
186  pos = out_modulename.Index('.');
187  if (pos != kNPOS)
188  out_modulename.Remove(pos, out_modulename.Length());
189 
190  if (!out_modulename.Length()) {
191  out_modulename = "USER";
192  return false;
193  }
194  }
195  }
196 
197  return true;
198 }
199 
200 ////////////////////////////////////////////////////////////////////////////////
201 /// Create all permutations of path and THtml's input path:
202 /// path being PP/ and THtml's input being .:include/:src/ gives
203 /// .:./PP/:include:include/PP/:src/:src/PP
204 
205 void THtml::TFileDefinition::ExpandSearchPath(TString& path) const
206 {
207  THtml* owner = GetOwner();
208  if (!owner) return;
209 
210  TString pathext;
211  TString inputdir = owner->GetInputPath();
212  TString tok;
213  Ssiz_t start = 0;
214  while (inputdir.Tokenize(tok, start, THtml::GetDirDelimiter())) {
215  if (pathext.Length())
216  pathext += GetDirDelimiter();
217  if (tok.EndsWith("\\"))
218  tok.Remove(tok.Length() - 1);
219  pathext += tok;
220  if (path.BeginsWith(tok))
221  pathext += GetDirDelimiter() + path;
222  else
223  pathext += GetDirDelimiter() + tok + "/" + path;
224  }
225  path = pathext;
226 
227 }
228 
229 ////////////////////////////////////////////////////////////////////////////////
230 /// Given a class name with a scope, split the class name into directory part
231 /// and file name: A::B::C becomes module B, filename C.
232 
233 void THtml::TFileDefinition::SplitClassIntoDirFile(const TString& clname, TString& dir,
234  TString& filename) const
235 {
236  TString token;
237  Ssiz_t from = 0;
238  filename = "";
239  dir = "";
240  while (clname.Tokenize(token, from, "::") ) {
241  dir = filename;
242  filename = token;
243  }
244 
245  // convert from Scope, class to module, filename.h
246  dir.ToLower();
247 }
248 
249 
250 ////////////////////////////////////////////////////////////////////////////////
251 /// Determine cl's declaration file name. Usually it's just
252 /// cl->GetDeclFileName(), but sometimes conversions need to be done
253 /// like include/ to abc/cde/inc/. If no declaration file name is
254 /// available, look for b/inc/C.h for class A::B::C. out_fsys will contain
255 /// the file system's (i.e. local machine's) full path name to the file.
256 /// The function returns false if the class's header file cannot be found.
257 ///
258 /// If your software cannot be mapped into this scheme then derive your
259 /// own class from TFileDefinition and pass it to THtml::SetFileDefinition().
260 
261 bool THtml::TFileDefinition::GetDeclFileName(const TClass* cl, TString& out_filename,
262  TString& out_fsys, TFileSysEntry** fse) const
263 {
264  return GetFileName(cl, true, out_filename, out_fsys, fse);
265 }
266 
267 ////////////////////////////////////////////////////////////////////////////////
268 /// Determine cl's implementation file name. Usually it's just
269 /// cl->GetImplFileName(), but sometimes conversions need to be done.
270 /// If no implementation file name is available look for b/src/C.cxx for
271 /// class A::B::C. out_fsys will contain the file system's (i.e. local
272 /// machine's) full path name to the file.
273 /// The function returns false if the class's source file cannot be found.
274 ///
275 /// If your software cannot be mapped into this scheme then derive your
276 /// own class from TFileDefinition and pass it to THtml::SetFileDefinition().
277 
278 bool THtml::TFileDefinition::GetImplFileName(const TClass* cl, TString& out_filename,
279  TString& out_fsys, TFileSysEntry** fse) const
280 {
281  return GetFileName(cl, false, out_filename, out_fsys, fse);
282 }
283 
284 
285 ////////////////////////////////////////////////////////////////////////////////
286 /// Remove "/./" and collapse "/subdir/../" to "/"
287 
288 void THtml::TFileDefinition::NormalizePath(TString& filename) const
289 {
290  static const char* delim[] = {"/", "\\\\"};
291  for (int i = 0; i < 2; ++i) {
292  const char* d = delim[i];
293  filename = filename.ReplaceAll(TString::Format("%c.%c", d[0], d[0]), TString(d[0]));
294  TPRegexp reg(TString::Format("%s[^%s]+%s\\.\\.%s", d, d, d, d));
295  while (reg.Substitute(filename, TString(d[0]), "", 0, 1)) {}
296  }
297  if (filename.BeginsWith("./") || filename.BeginsWith(".\\"))
298  filename.Remove(0,2);
299 }
300 
301 
302 ////////////////////////////////////////////////////////////////////////////////
303 /// Find filename in the list of system files; return the system file name
304 /// and change filename to the file name as included.
305 /// filename must be normalized (no "/./" etc) before calling.
306 
307 TString THtml::TFileDefinition::MatchFileSysName(TString& filename, TFileSysEntry** fse) const
308 {
309  const TList* bucket = GetOwner()->GetLocalFiles()->GetEntries().GetListForObject(gSystem->BaseName(filename));
310  TString filesysname;
311  if (bucket) {
312  TIter iFS(bucket);
313  TFileSysEntry* fsentry = 0;
314  while ((fsentry = (TFileSysEntry*) iFS())) {
315  if (!filename.EndsWith(fsentry->GetName()))
316  continue;
317  fsentry->GetFullName(filesysname, kTRUE); // get the short version
318  filename = filesysname;
319  if (!filename.EndsWith(filesysname)) {
320  // It's something - let's see whether we find something better
321  // else leave it as plan B. This helps finding Reflex sources.
322  //filesysname = "";
323  continue;
324  }
325  fsentry->GetFullName(filesysname, kFALSE); // get the long version
326  if (fse) *fse = fsentry;
327  break;
328  }
329  }
330  return filesysname;
331 }
332 
333 
334 ////////////////////////////////////////////////////////////////////////////////
335 /// Common implementation for GetDeclFileName(), GetImplFileName()
336 
337 bool THtml::TFileDefinition::GetFileName(const TClass* cl, bool decl,
338  TString& out_filename, TString& out_fsys,
339  TFileSysEntry** fse) const
340 {
341  out_fsys = "";
342 
343  if (!cl) {
344  out_filename = "";
345  return false;
346  }
347 
348  TString possibleFileName;
349  TString possiblePath;
350  TString filesysname;
351 
352  TString clfile = decl ? cl->GetDeclFileName() : cl->GetImplFileName();
353  NormalizePath(clfile);
354 
355  out_filename = clfile;
356  if (clfile.Length()) {
357  // check that clfile doesn't start with one of the include paths;
358  // that's not what we want (include/TObject.h), we want the actual file
359  // if it exists (core/base/inc/TObject.h)
360 
361  // special case for TMath namespace:
362  if (clfile == "include/TMathBase.h") {
363  clfile = "math/mathcore/inc/TMath.h";
364  out_filename = clfile;
365  }
366 
367  TString inclDir;
368  TString inclPath(GetOwner()->GetPathInfo().fIncludePath);
369  Ssiz_t pos = 0;
370  Ssiz_t longestMatch = kNPOS;
371  while (inclPath.Tokenize(inclDir, pos, GetOwner()->GetDirDelimiter())) {
372  if (clfile.BeginsWith(inclDir) && (longestMatch == kNPOS || inclDir.Length() > longestMatch))
373  longestMatch = inclDir.Length();
374  }
375  if (longestMatch != kNPOS) {
376  clfile.Remove(0, longestMatch);
377  if (clfile.BeginsWith("/") || clfile.BeginsWith("\\"))
378  clfile.Remove(0, 1);
379  TString asincl(clfile);
380  GetOwner()->GetPathDefinition().GetFileNameFromInclude(asincl, clfile);
381  out_filename = clfile;
382  } else {
383  // header file without a -Iinclude-dir prefix
384  filesysname = MatchFileSysName(out_filename, fse);
385  if (filesysname[0]) {
386  clfile = out_filename;
387  }
388  }
389  } else {
390  // check for a file named like the class:
391  filesysname = cl->GetName();
392  int templateLevel = 0;
393  Ssiz_t end = filesysname.Length();
394  Ssiz_t start = end - 1;
395  for (; start >= 0 && (templateLevel || filesysname[start] != ':'); --start) {
396  if (filesysname[start] == '>')
397  ++templateLevel;
398  else if (filesysname[start] == '<') {
399  --templateLevel;
400  if (!templateLevel)
401  end = start;
402  }
403  }
404  filesysname = filesysname(start + 1, end - start - 1);
405  if (decl)
406  filesysname += ".h";
407  else
408  filesysname += ".cxx";
409  out_filename = filesysname;
410  filesysname = MatchFileSysName(out_filename, fse);
411  if (filesysname[0]) {
412  clfile = out_filename;
413  }
414  }
415 
416  if (!decl && !clfile.Length()) {
417  // determine possible impl file name from the decl file name,
418  // replacing ".whatever" by ".cxx", and looking for it in the known
419  // file names
420  TString declSysFileName;
421  if (GetFileName(cl, true, filesysname, declSysFileName)) {
422  filesysname = gSystem->BaseName(filesysname);
423  Ssiz_t posExt = filesysname.Last('.');
424  if (posExt != kNPOS)
425  filesysname.Remove(posExt);
426  filesysname += ".cxx";
427  out_filename = filesysname;
428  filesysname = MatchFileSysName(out_filename, fse);
429  if (filesysname[0]) {
430  clfile = out_filename;
431  }
432  }
433  }
434 
435  if (clfile.Length() && !decl) {
436  // Do not return the source file for these packages, even though we can find them.
437  // THtml needs to have the class description in the source file if it finds the
438  // source file, and these classes have their class descriptions in the header files.
439  // THtml needs to be improved to collect all of a class' documentation before writing
440  // it out, so it can take the class doc from the header even though a source exists.
441  static const char* vetoClasses[] = {"math/mathcore/", "math/mathmore/", "math/genvector/",
442  "math/minuit2/", "math/smatrix/"};
443  for (unsigned int i = 0; i < sizeof(vetoClasses) / sizeof(char*); ++i) {
444  if (clfile.Contains(vetoClasses[i])) {
445  // of course there are exceptions from the exceptions:
446  // TComplex and TRandom, TRandom1,...
447  if (strcmp(cl->GetName(), "TComplex")
448  && strcmp(cl->GetName(), "TMath")
449  && strncmp(cl->GetName(), "TKDTree", 7)
450  && strcmp(cl->GetName(), "TVirtualFitter")
451  && strncmp(cl->GetName(), "TRandom", 7)) {
452  out_filename = "";
453  return false;
454  } else break;
455  }
456  }
457  }
458 
459 
460  if (!clfile.Length()) {
461  // determine possible decl file name from class + scope name:
462  // A::B::C::myclass will result in possible file name myclass.h
463  // in directory C/inc/
464  out_filename = cl->GetName();
465  if (!out_filename.Contains("::")) {
466  out_filename = "";
467  return false;
468  }
469  SplitClassIntoDirFile(out_filename, possiblePath, possibleFileName);
470 
471  // convert from Scope, class to module, filename.h
472  if (possibleFileName.Length()) {
473  if (decl)
474  possibleFileName += ".h";
475  else
476  possibleFileName += ".cxx";
477  }
478  if (possiblePath.Length())
479  possiblePath += "/";
480  if (decl)
481  possiblePath += "inc/";
482  else
483  possiblePath += "src/";
484  out_filename = possiblePath + "/" + possibleFileName;
485  } else {
486  possiblePath = gSystem->DirName(clfile);
487  possibleFileName = gSystem->BaseName(clfile);
488  }
489 
490  if (possiblePath.Length())
491  ExpandSearchPath(possiblePath);
492  else possiblePath=".";
493 
494  out_fsys = gSystem->FindFile(possiblePath, possibleFileName, kReadPermission);
495  if (out_fsys.Length()) {
496  NormalizePath(out_fsys);
497  return true;
498  }
499  out_filename = "";
500  return false;
501 }
502 
503 ////////////////////////////////////////////////////////////////////////////////
504 /// Determine the path to look for macros (see TDocMacroDirective) for
505 /// classes from a given module. If the path was sucessfully determined return true.
506 /// For ROOT, this directory is the "doc/macros" subdirectory of the module
507 /// directory; the path returned is GetDocDir(module) + "/macros".
508 ///
509 /// If your software cannot be mapped into this scheme then derive your
510 /// own class from TPathDefinition and pass it to THtml::SetPathDefinition().
511 
512 bool THtml::TPathDefinition::GetMacroPath(const TString& module, TString& out_dir) const
513 {
514  TString moduledoc;
515  if (!GetDocDir(module, moduledoc))
516  return false;
517  if (moduledoc.EndsWith("\\"))
518  moduledoc.Remove(moduledoc.Length() - 1);
519 
520  TString macropath(GetOwner()->GetMacroPath());
521  TString macrodirpart;
522  out_dir = "";
523  Ssiz_t pos = 0;
524  while (macropath.Tokenize(macrodirpart, pos, ":")) {
525  out_dir += moduledoc + "/" + macrodirpart + ":";
526  }
527  return true;
528 }
529 
530 
531 ////////////////////////////////////////////////////////////////////////////////
532 /// Determine the module's documentation directory. If module is empty,
533 /// set doc_dir to the product's documentation directory.
534 /// If the path was sucessfuly determined return true.
535 /// For ROOT, this directory is the subdir "doc/" in the
536 /// module's path; the directory returned is module + "/doc".
537 ///
538 /// If your software cannot be mapped into this scheme then derive your
539 /// own class from TPathDefinition and pass it to THtml::SetPathDefinition().
540 
541 bool THtml::TPathDefinition::GetDocDir(const TString& module, TString& doc_dir) const
542 {
543  doc_dir = "";
544  if (GetOwner()->GetProductName() == "ROOT") {
545  doc_dir = "$ROOTSYS";
546  gSystem->ExpandPathName(doc_dir);
547  doc_dir += "/";
548  }
549 
550  if (module.Length())
551  doc_dir += module + "/";
552  doc_dir += GetOwner()->GetPathInfo().fDocPath;
553  return true;
554 }
555 
556 
557 ////////////////////////////////////////////////////////////////////////////////
558 /// Determine the path and filename used in an include statement for the
559 /// header file of the given class. E.g. the class ROOT::Math::Boost is
560 /// meant to be included as "Math/Genvector/Boost.h" - which is what
561 /// out_dir is set to. GetIncludeAs() returns whether the include
562 /// statement's path was successfully determined.
563 ///
564 /// Any leading directory part that is part of fIncludePath (see SetIncludePath)
565 /// will be removed. For ROOT, leading "include/" is removed; everything after
566 /// is the include path.
567 ///
568 /// If your software cannot be mapped into this scheme then derive your
569 /// own class from TPathDefinition and pass it to THtml::SetPathDefinition().
570 
571 bool THtml::TPathDefinition::GetIncludeAs(TClass* cl, TString& out_dir) const
572 {
573  out_dir = "";
574  if (!cl || !GetOwner()) return false;
575 
576  TString hdr;
577  if (!GetOwner()->GetDeclFileName(cl, kFALSE, hdr))
578  return false;
579 
580  out_dir = hdr;
581  bool includePathMatches = false;
582  TString tok;
583  Ssiz_t pos = 0;
584  while (!includePathMatches && GetOwner()->GetPathInfo().fIncludePath.Tokenize(tok, pos, THtml::GetDirDelimiter()))
585  if (out_dir.BeginsWith(tok)) {
586  out_dir = hdr(tok.Length(), hdr.Length());
587  if (out_dir[0] == '/' || out_dir[0] == '\\')
588  out_dir.Remove(0, 1);
589  includePathMatches = true;
590  }
591 
592  if (!includePathMatches) {
593  // We probably have a file super/module/inc/optional/filename.h.
594  // That gets translated into optional/filename.h.
595  // Assume that only one occurrence of "/inc/" exists in hdr.
596  // If /inc/ is not part of the include file name then
597  // just return the full path.
598  // If we have matched any include path then this ROOT-only
599  // algorithm is skipped!
600  Ssiz_t posInc = hdr.Index("/inc/");
601  if (posInc == kNPOS) return true;
602  hdr.Remove(0, posInc + 5);
603  out_dir = hdr;
604  }
605 
606  return (out_dir.Length());
607 }
608 
609 
610 ////////////////////////////////////////////////////////////////////////////////
611 /// Set out_fsname to the full pathname corresponding to a file
612 /// included as "included". Return false if this file cannot be determined
613 /// or found. For ROOT, out_fsname corresponds to included prepended with
614 /// "include"; only THtml prefers to work on the original files, e.g.
615 /// core/base/inc/TObject.h instead of include/TObject.h, so the
616 /// default implementation searches the TFileSysDB for an entry with
617 /// basename(included) and with matching directory part, setting out_fsname
618 /// to the TFileSysEntry's path.
619 
620 bool THtml::TPathDefinition::GetFileNameFromInclude(const char* included, TString& out_fsname) const
621 {
622  if (!included) return false;
623 
624  out_fsname = included;
625 
626  TString incBase(gSystem->BaseName(included));
627  const TList* bucket = GetOwner()->GetLocalFiles()->GetEntries().GetListForObject(incBase);
628  if (!bucket) return false;
629 
630  TString alldir(gSystem->DirName(included));
631  TObjArray* arrSubDirs = alldir.Tokenize("/");
632  TIter iEntry(bucket);
633  TFileSysEntry* entry = 0;
634  while ((entry = (TFileSysEntry*) iEntry())) {
635  if (incBase != entry->GetName()) continue;
636  // find entry with matching enclosing directory
637  THtml::TFileSysDir* parent = entry->GetParent();
638  for (int i = arrSubDirs->GetEntries() - 1; parent && i >= 0; --i) {
639  const TString& subdir(((TObjString*)(*arrSubDirs)[i])->String());
640  if (!subdir.Length() || subdir == ".")
641  continue;
642  if (subdir == parent->GetName())
643  parent = parent->GetParent();
644  else parent = 0;
645  }
646  if (parent) {
647  // entry found!
648  entry->GetFullName(out_fsname, kFALSE);
649  delete arrSubDirs;
650  return true;
651  }
652  }
653  delete arrSubDirs;
654  return false;
655 }
656 
657 ////////////////////////////////////////////////////////////////////////////////
658 /// Recursively fill entries by parsing the contents of path.
659 
660 void THtml::TFileSysDir::Recurse(TFileSysDB* db, const char* path)
661 {
662  TString dir(path);
663  if (gDebug > 0 || GetLevel() < 2)
664  Info("Recurse", "scanning %s...", path);
665  TPMERegexp regexp(db->GetIgnore());
666  dir += "/";
667  void* hDir = gSystem->OpenDirectory(dir);
668  const char* direntry = 0;
669  while ((direntry = gSystem->GetDirEntry(hDir))) {
670  if (!direntry[0] || direntry[0] == '.' || regexp.Match(direntry)) continue;
671  TString entryPath(dir + direntry);
672  if (gSystem->AccessPathName(entryPath, kReadPermission))
673  continue;
674  FileStat_t buf;
675  if (!gSystem->GetPathInfo(entryPath, buf)) {
676  if (R_ISDIR(buf.fMode)) {
677  // skip if we would nest too deeply, and skip soft links:
678  if (GetLevel() > db->GetMaxLevel()
679 #ifndef R__WIN32
680  || db->GetMapIno().GetValue(buf.fIno)
681 #endif
682  ) continue;
683  TFileSysDir* subdir = new TFileSysDir(direntry, this);
684  fDirs.Add(subdir);
685 #ifndef R__WIN32
686  db->GetMapIno().Add(buf.fIno, (Long_t)subdir);
687 #endif
688  subdir->Recurse(db, entryPath);
689  } else {
690  int delen = strlen(direntry);
691  // only .cxx and .h, .hxx are taken
692  if (strcmp(direntry + delen - 4, ".cxx")
693  && strcmp(direntry + delen - 2, ".h")
694  && strcmp(direntry + delen - 4, ".hxx"))
695  continue;
696  TFileSysEntry* entry = new TFileSysEntry(direntry, this);
697  db->GetEntries().Add(entry);
698  fFiles.Add(entry);
699  }
700  } // if !gSystem->GetPathInfo()
701  } // while dir entry
702  gSystem->FreeDirectory(hDir);
703 }
704 
705 
706 ////////////////////////////////////////////////////////////////////////////////
707 /// Recursively fill entries by parsing the path specified in GetName();
708 /// can be a THtml::GetDirDelimiter() delimited list of paths.
709 
710 void THtml::TFileSysDB::Fill()
711 {
712  TString dir;
713  Ssiz_t posPath = 0;
714  while (fName.Tokenize(dir, posPath, THtml::GetDirDelimiter())) {
715  gSystem->ExpandPathName(dir);
716  if (gSystem->AccessPathName(dir, kReadPermission)) {
717  Warning("Fill", "Cannot read InputPath \"%s\"!", dir.Data());
718  continue;
719  }
720  FileStat_t buf;
721  if (!gSystem->GetPathInfo(dir, buf) && R_ISDIR(buf.fMode)) {
722 #ifndef R__WIN32
723  TFileSysRoot* prevroot = (TFileSysRoot*) (Long_t)GetMapIno().GetValue(buf.fIno);
724  if (prevroot != 0) {
725  Warning("Fill", "InputPath \"%s\" already present as \"%s\"!", dir.Data(), prevroot->GetName());
726  continue;
727  }
728 #endif
729  TFileSysRoot* root = new TFileSysRoot(dir, this);
730  fDirs.Add(root);
731 #ifndef R__WIN32
732  GetMapIno().Add(buf.fIno, (Long_t)root);
733 #endif
734  root->Recurse(this, dir);
735  } else {
736  Warning("Fill", "Cannot read InputPath \"%s\"!", dir.Data());
737  }
738  }
739 }
740 
741 
742 ////////////////////////////////////////////////////////////////////////////////
743 /* BEGIN_HTML
744 <p>The THtml class is designed to easily document
745 classes, code, and code related text files (like change logs). It generates HTML
746 pages conforming to the XHTML 1.0 transitional specifications; an example of
747 these pages is ROOT's own <a href="http://root.cern.ch/root/html/ClassIndex.html">
748 reference guide</a>. This page was verified to be valid XHTML 1.0 transitional,
749 which proves that all pages generated by THtml can be valid, as long as the user
750 provided XHTML (documentation, header, etc) is valid. You can check the current
751 THtml by clicking this icon:
752 <a href="http://validator.w3.org/check?uri=referer"><img
753  src="http://www.w3.org/Icons/valid-xhtml10"
754  alt="Valid XHTML 1.0 Transitional" height="31" width="88" style="border: none;"/></a></p>
755 Overview:
756 <ol style="list-style-type: upper-roman;">
757  <li><a href="#usage">Usage</a></li>
758  <li><a href="#conf">Configuration</a>
759  <ol><li><a href="#conf:input">Input files</a></li>
760  <li><a href="#conf:output">Output directory</a></li>
761  <li><a href="#conf:liblink">Linking other documentation</a></li>
762  <li><a href="#conf:classdoc">Recognizing class documentation</a></li>
763  <li><a href="#conf:tags">Author, copyright, etc.</a></li>
764  <li><a href="#conf:header">Header and footer</a></li>
765  <li><a href="#conf:search">Links to searches, home page, ViewVC</a></li>
766  <li><a href="#conf:charset">HTML Charset</a></li>
767  </ol></li>
768  <li><a href="#syntax">Documentation syntax</a>
769  <ol><li><a href="#syntax:classdesc">Class description</a></li>
770  <li><a href="#syntax:classidx">Class index</a></li>
771  <li><a href="#syntax:meth">Method documentation</a></li>
772  <li><a href="#syntax:datamem">Data member documentation</a></li>
773  </ol></li>
774  <li><a href="#directive">Documentation directives</a>
775  <ol><li><a href="#directive:html"><tt>BEGIN<!-- -->_HTML</tt> <tt>END<!-- -->_HTML</tt>: include 'raw' HTML</a></li>
776  <li><a href="#directive:macro"><tt>BEGIN<!-- -->_MACRO</tt> <tt>END<!-- -->_MACRO</tt>: include a picture generated by a macro</a></li>
777  <li><a href="#directive:latex"><tt>BEGIN<!-- -->_LATEX</tt> <tt>END<!-- -->_LATEX</tt>: include a latex picture</a></li>
778  </ol></li>
779  <li><a href="#index">Product and module index</a></li>
780  <li><a href="#aux">Auxiliary files: style sheet, JavaScript, help page</a></li>
781  <li><a href="#charts">Class Charts</a></li>
782  <li><a href="#confvar">Configuration variables</a></li>
783  <li><a href="#how">Behind the scenes</a></li>
784 </ol>
785 
786 
787 <h3><a name="usage">I. Usage</a></h3>
788 These are typical things people do with THtml:
789 <pre>
790  root[] <a href="http://root.cern.ch/root/html/THtml.html">THtml</a> html; // create a <a href="http://root.cern.ch/root/html/THtml.html">THtml</a> object
791  root[] html.LoadAllLibs(); // Load all rootmap'ed libraries
792  root[] html.MakeAll(); // generate documentation for all changed classes
793 </pre>
794 or to run on just a few classes:
795 <pre>
796  root[] <a href="http://root.cern.ch/root/html/THtml.html">THtml</a> html; // create a <a href="http://root.cern.ch/root/html/THtml.html">THtml</a> object
797  root[] html.MakeIndex(); // create auxiliary files (style sheet etc) and indices
798  root[] html.MakeClass("TMyClass"); // create documentation for TMyClass only
799 </pre>
800 To "beautify" (i.e. create links to documentation for class names etc) some text
801 file or macro, use:
802 <pre>
803  root[] html.Convert( "hsimple.C", "Histogram example" )
804 </pre>
805 
806 
807 <h3><a name="conf">II. Configuration</a></h3>
808 Most configuration options can be set as a call to THtml, or as a TEnv variable,
809 which you can set in your .rootrc.
810 
811 <h4><a name="conf:input">II.1 Input files</a></h4>
812 
813 <p>In your .rootrc, define Root.Html.SourceDir to point to directories containing
814 .cxx and .h files (see: <a href="http://root.cern.ch/root/html/TEnv.html">TEnv</a>)
815 of the classes you want to document, or call THtml::SetInputDir()</p>
816 
817 <p>Example:</p><pre>
818  Root.Html.SourceDir: .:src:include
819  Root.Html.Root: http://root.cern.ch/root/html</pre>
820 
821 
822 <h4><a name="conf:output">II.2 Output directory</a></h4>
823 
824 <p>The output directory can be specified using the Root.Html.OutputDir
825 configuration variable (default value: "htmldoc"). If that directory
826 doesn't exist <a href="http://root.cern.ch/root/html/THtml.html">THtml</a>
827 will create it.</p>
828 
829 <p>Example:</p><pre>
830  Root.Html.OutputDir: htmldoc</pre>
831 
832 <h4><a name="conf:liblink">II.3 Linking other documentation</a></h4>
833 
834 <p>When trying to document a class, THtml searches for a source file in
835 the directories set via SetInputDir(). If it cannot find it, it assumes
836 that this class must have been documented before. Based on the library
837 this class is defined in, it checks the configuration variable
838 <tt>Root.Html.LibName</tt>, and creates a link using its value.
839 Alternatively, you can set these URLs via THtml::SetLibURL().</p>
840 
841 <p>Example:<br/>
842 If a class MyClass is defined in class mylibs/libMyLib.so, and .rootrc
843 contains</p><pre>
844  Root.Html.MyLib: ../mylib/</pre>
845 <p>THtml will create a link to "../mylib/MyClass.html".</p>
846 
847 <p>The library name association can be set up using the rootmap facility.
848 For the library in the example above, which contains a dictionary
849 generated from the linkdef MyLinkdef.h, the command to generate the
850 rootmap file is</p>
851 <pre> $ rlibmap -f -r rootmap -l mylib/libMyLib.so -d libCore.so -c MyLinkdef.h</pre>
852 <p>Here, <tt>-r</tt> specifies that the entries for libMyLib should be updated,
853 <tt>-l</tt> specifies the library we're dealing with, <tt>-d</tt> its
854 dependencies, and <tt>-c</tt> its linkdef. The rootmap file must be within
855 one of the <tt>LD_LIBRARY_PATH</tt> (or <tt>PATH</tt> for Windows) directories
856 when ROOT is started, otherwise ROOT will not use it.</p>
857 
858 <h4><a name="conf:classdoc">II.4 Recognizing class documentation</a></h4>
859 
860 <p>The class documentation has to appear in the header file containing the
861 class, right in front of its declaration. It is introduced by a string
862 defined by Root.Html.Description or SetClassDocTag(). See the section on
863 <a href="#syntax">documentation syntax</a> for further details.</p>
864 
865 <p>Example:</p><pre>
866  Root.Html.Description: //____________________</pre>
867 
868 <p>The class documentation will show which include statement is to be used
869 and which library needs to be linked to access it.
870 The include file name is determined via
871 <a href="http://root.cern.ch/root/html/TClass.html#TClass:GetDeclFileName">
872 TClass::GetDeclFileName()</a>;
873 leading parts are removed if they match any of the ':' separated entries in
874 THtml::GetIncludePath().</p>
875 
876 <h4><a name="conf:tags">II.5 Author, copyright, etc.</a></h4>
877 
878 <p>During the conversion,
879 <a href="http://root.cern.ch/root/html/THtml.html">THtml</a> will look for
880 some strings ("tags") in the source file, which have to appear right in
881 front of e.g. the author's name, copyright notice, etc. These tags can be
882 defined with the following environment variables: Root.Html.Author,
883 Root.Html.LastUpdate and Root.Html.Copyright, or with
884 SetAuthorTag(), SetLastUpdateTag(), SetCopyrightTag().</p>
885 
886 <p>If the LastUpdate tag is not found, the current date and time are used.
887 This is useful when using
888 <a href="http://root.cern.ch/root/html/THtml.html#THtml:MakeAll">THtml::MakeAll()</a>'s
889 default option force=kFALSE, in which case
890 <a href="http://root.cern.ch/root/html/THtml.html">THtml</a> generates
891 documentation only for changed classes.</p>
892 
893 Authors can be a comma separated list of author entries. Each entry has
894 one of the following two formats
895 <ul><li><tt>Name (non-alpha)</tt>.
896 <p><a href="http://root.cern.ch/root/html/THtml.html">THtml</a> will generate an
897 HTML link for <tt>Name</tt>, taking the Root.Html.XWho configuration
898 variable (defaults to "http://consult.cern.ch/xwho/people?") and adding
899 all parts of the name with spaces replaces by '+'. Non-alphanumerical
900 characters are printed out behind <tt>Name</tt>.</p>
901 
902 <p>Example:</p>
903 <tt>// Author: Enrico Fermi</tt> appears in the source file.
904 <a href="http://root.cern.ch/root/html/THtml.html">THtml</a> will generate the link
905 <tt>http://consult.cern.ch/xwho/people?Enrico+Fermi</tt>. This works well for
906 people at CERN.</li>
907 
908 <li><tt>Name &lt;link&gt; Info</tt>.
909 <p><a href="http://root.cern.ch/root/html/THtml.html">THtml</a> will generate
910 an HTML link for <tt>Name</tt> as specified by <tt>link</tt> and print
911 <tt>Info</tt> behind <tt>Name</tt>.</p>
912 
913 <p>Example:</p>
914 <tt>// Author: Enrico Fermi &lt;http://www.enricos-home.it&gt;</tt> or<br/>
915 <tt>// Author: Enrico Fermi &lt;mailto:enrico@fnal.gov&gt;</tt> in the
916 source file. That's world compatible.</li>
917 </ul>
918 
919 <p>Example (with defaults given):</p><pre>
920  Root.Html.Author: // Author:
921  Root.Html.LastUpdate: // @(#)
922  Root.Html.Copyright: * Copyright
923  Root.Html.XWho: http://consult.cern.ch/xwho/people?</pre>
924 
925 
926 <h4><a name="conf:header">II.6 Header and footer</a></h4>
927 
928 <p><a href="http://root.cern.ch/root/html/THtml.html">THtml</a> generates
929 a default header and footer for all pages. You can
930 specify your own versions with the configuration variables Root.Html.Header
931 and Root.Html.Footer, or by calling SetHeader(), SetFooter().
932 Both variables default to "", using the standard Root
933 versions. If it has a "+" appended, <a href="http://root.cern.ch/root/html/THtml.html">THtml</a> will
934 write both versions (user and root) to a file, for the header in the order
935 1st root, 2nd user, and for the footer 1st user, 2nd root (the root
936 versions containing "&lt;html&gt;" and &lt;/html&gt; tags, resp).</p>
937 
938 <p>If you want to replace root's header you have to write a file containing
939 all HTML elements necessary starting with the &lt;doctype&gt; tag and ending with
940 (and including) the &lt;body&gt; tag. If you add your header it will be added
941 directly after Root's &lt;body&gt; tag. Any occurrence of the string <tt>%TITLE%</tt>
942 in the user's header file will be replaced by
943 a sensible, automatically generated title. If the header is generated for a
944 class, occurrences of <tt>%CLASS%</tt> will be replaced by the current class's name,
945 <tt>%SRCFILE%</tt> and <tt>%INCFILE%</tt> by the name of the source and header file, resp.
946 (as given by <a href="http://root.cern.ch/root/html/TClass.html#TClass:GetImplFileLine">TClass::GetImplFileName()</a>,
947 <a href="http://root.cern.ch/root/html/TClass.html#TClass:GetImplFileLine">TClass::GetDeclFileName()</a>).
948 If the header is not generated for a class, they will be replaced by "".</p>
949 
950 <p>Root's footer starts with the tag &lt;!--SIGNATURE--&gt;. It includes the
951 author(s), last update, copyright, the links to the Root home page, to the
952 user home page, to the index file (ClassIndex.html), to the top of the page
953 and <tt>this page is automatically generated</tt> infomation. It ends with the
954 tags <tt>&lt;/body&gt;&lt;/html&gt;</tt>. If you want to replace it,
955 <a href="http://root.cern.ch/root/html/THtml.html">THtml</a> will search for some
956 tags in your footer: Occurrences of the strings <tt>%AUTHOR%</tt>, <tt>%UPDATE%</tt>, and
957 <tt>%COPYRIGHT%</tt> are replaced by their
958 corresponding values before writing the html file. The <tt>%AUTHOR%</tt> tag will be
959 replaced by the exact string that follows Root.Html.Author, no link
960 generation will occur.</p>
961 
962 
963 <h4><a name="conf:search">II.7 Links to searches, home page, ViewVC</a></h4>
964 
965 <p>Additional parameters can be set by Root.Html.Homepage (address of the
966 user's home page), Root.Html.SearchEngine (search engine for the class
967 documentation), Root.Html.Search (search URL, where %u is replaced by the
968 referer and %s by the escaped search expression), and a ViewVC base URL
969 Root.Html.ViewCVS. For the latter, the file name is appended or, if
970 the URL contains %f, %f is replaced by the file name.
971 All values default to "".</p>
972 
973 <p>Examples:</p><pre>
974  Root.Html.Homepage: http://www.enricos-home.it
975  Root.Html.SearchEngine: http://root.cern.ch/root/Search.phtml
976  Root.Html.Search: http://www.google.com/search?q=%s+site%3A%u</pre>
977 
978 
979 <h4><a name="conf:charset">II.8 HTML Charset</a></h4>
980 
981 <p>XHTML 1.0 transitional recommends the specification of the charset in the
982 content type meta tag, see e.g. <a href="http://www.w3.org/TR/2002/REC-xhtml1-20020801/">http://www.w3.org/TR/2002/REC-xhtml1-20020801/</a>
983 <a href="http://root.cern.ch/root/html/THtml.html">THtml</a> generates it for the HTML output files. It defaults to ISO-8859-1, and
984 can be changed using Root.Html.Charset.</p>
985 
986 <p>Example:</p><pre>
987  Root.Html.Charset: EUC-JP</pre>
988 
989 <h3><a name="syntax">III. Documentation syntax</a></h3>
990 <h4><a name="syntax:classdesc">III.1 Class description</a></h4>
991 
992 <p>A class description block, which must be placed before the first
993 member function, has a following form:</p>
994 <pre>
995 ////////////////////////////////////////////////////////////////
996 // //
997 // TMyClass //
998 // //
999 // This is the description block. //
1000 // //
1001 ////////////////////////////////////////////////////////////////
1002 </pre>
1003 <p>The environment variable Root.Html.Description
1004 (see: <a href="http://root.cern.ch/root/html/TEnv.html">TEnv</a>) contains
1005 the delimiter string (default value: <tt>//_________________</tt>). It means
1006 that you can also write your class description block like this:</p>
1007 <pre>
1008  //_____________________________________________________________
1009  // A description of the class starts with the line above, and
1010  // will take place here !
1011  //
1012 </pre>
1013 <p>Note that <b><i>everything</i></b> until the first non-commented line is considered
1014 as a valid class description block.</p>
1015 
1016 <h4><a name="syntax:classidx">III.2 Class index</a></h4>
1017 
1018 <p>All classes to be documented will have an entry in the ClassIndex.html,
1019 showing their name with a link to their documentation page and a miniature
1020 description. This discription for e.g. the class MyClass has to be given
1021 in MyClass's header as a comment right after ClassDef(MyClass, n).</p>
1022 
1023 <h4><a name="syntax:meth">III.3 Method documentation</a></h4>
1024 <p>A member function description block starts immediately after '{'
1025 and looks like this:</p>
1026 <pre>
1027  void TWorld::HelloWorldFunc(string *text)
1028  {
1029  // This is an example of description for the
1030  // TWorld member function
1031 
1032  helloWorld.Print( text );
1033  }
1034 </pre>
1035 Like in a class description block, <b><i>everything</i></b> until the first
1036 non-commented line is considered as a valid member function
1037 description block.
1038 
1039 If the rootrc variable <tt>Root.Html.DescriptionStyle</tt> is set to
1040 <tt>Doc++</tt> THtml will also look for method documentation in front of
1041 the function implementation. This feature is not recommended; source code
1042 making use of this does not comply to the ROOT documentation standards, which
1043 means future versions of THtml might not support it anymore.
1044 
1045 <h4><a name="syntax:datamem">III.4 Data member documentation</a></h4>
1046 
1047 <p>Data members are documented by putting a C++ comment behind their
1048 declaration in the header file, e.g.</p>
1049 <pre>
1050  int fIAmADataMember; // this is a data member
1051 </pre>
1052 
1053 
1054 <h3><a name="directive">IV. Documentation directives</a></h3>
1055 <em>NOTE that THtml does not yet support nested directives
1056 (i.e. latex inside html etc)!</em>
1057 
1058 <h4><a name="directive:html">IV.1 <tt>BEGIN<!-- -->_HTML</tt> <tt>END<!-- -->_HTML</tt>: include 'raw' HTML</a></h4>
1059 
1060 <p>You can insert pure html code into your documentation comments. During the
1061 generation of the documentation, this code will be inserted as is
1062 into the html file.</p>
1063 <p>Pure html code must be surrounded by the keywords
1064 <tt>BEGIN<!-- -->_HTML</tt> and <tt>END<!-- -->_HTML</tt>, where the
1065 case is ignored.
1066 An example of pure html code is this class description you are reading right now.
1067 THtml uses a
1068 <a href="http://root.cern.ch/root/html/TDocHtmlDirective.html">TDocHtmlDirective</a>
1069 object to process this directive.</p>
1070 
1071 <h4><a name="directive:macro">IV.2 <tt>BEGIN<!-- -->_MACRO</tt> <tt>END<!-- -->_MACRO</tt>: include a picture generated by a macro</a></h4>
1072 
1073 <p>THtml can create images from scripts. You can either call an external
1074 script by surrounding it by "begin_macro"/"end_macro", or include an unnamed
1075 macro within these keywords. The macro should return a pointer to an object;
1076 this object will then be saved as a GIF file.</p>
1077 <p>Objects deriving from
1078 <a href="http://root.cern.ch/root/html/TGObject.html">TGObject</a> (GUI elements)
1079 will need to run in graphics mode (non-batch). You must specify this as a parameter:
1080 "Begin_macro(GUI)...".
1081 To create a second tab that displays the source of the macro you can specify
1082 the argument "Begin_macro(source)...".
1083 Of course you can combine them,
1084 e.g. as "Begin_macro(source,gui)...".
1085 THtml uses a
1086 <a href="http://root.cern.ch/root/html/TDocMacroDirective.html">TDocMacroDirective</a>
1087 object to process this directive.</p>
1088 <p>This is an example:</p> END_HTML
1089 BEGIN_MACRO(source)
1090 {
1091  TCanvas* macro_example_canvas = new TCanvas("macro_example_canvas", "", 150, 150);
1092  macro_example_canvas->SetBorderSize(0);
1093  macro_example_canvas->SetFillStyle(1001);
1094  macro_example_canvas->SetFillColor(kWhite);
1095  macro_example_canvas->cd();
1096  TArc* macro_example_arc = new TArc(0.5,0.32,0.11,180,360);
1097  macro_example_arc->Draw();
1098  TEllipse* macro_example_ellipsis = new TEllipse(0.42,0.58,0.014,0.014,0,360,0);
1099  macro_example_ellipsis->SetFillStyle(0);
1100  macro_example_ellipsis->Draw();
1101  macro_example_ellipsis = new TEllipse(0.58,0.58,0.014,0.014,0,360,0);
1102  macro_example_ellipsis->SetFillStyle(0);
1103  macro_example_ellipsis->Draw();
1104  macro_example_ellipsis = new TEllipse(0.50,0.48,0.22,0.32,0,360,0);
1105  macro_example_ellipsis->SetFillStyle(0);
1106  macro_example_ellipsis->Draw();
1107  TLine* macro_example_line = new TLine(0.48,0.53,0.52,0.41);
1108  macro_example_line->Draw();
1109  return macro_example_canvas;
1110 }
1111 END_MACRO
1112 
1113 BEGIN_HTML
1114 <h4><a name="directive:latex">IV.3 <tt>BEGIN<!-- -->_LATEX</tt> <tt>END<!-- -->_LATEX</tt>: include a latex picture</a></h4>
1115 
1116 <p>You can specify <a href="http://root.cern.ch/root/html/TLatex.html">TLatex</a>
1117 style text and let THtml convert it into an image by surrounding it by "Begin_Latex", "End_Latex".
1118 You can have multiple lines, and e.g. align each line at the '=' sign by passing
1119 the argument <tt>separator='='</tt>. You can also specify how to align these parts;
1120 if you want the part left of the separator to be right aligned, and the right part
1121 to be left aligned, you could specify <tt>align='rl'</tt>.
1122 THtml uses a <a href="http://root.cern.ch/root/html/TDocLatexDirective.html">TDocLatexDirective</a>
1123 object to process the directive.
1124 This is an example output with arguments <tt>separator='=', align='rl'</tt>:</p>
1125 END_HTML BEGIN_LATEX(separator='=', align='rl')#kappa(x)^{2}=sin(x)^{x}
1126 x=#chi^{2} END_LATEX
1127 
1128 BEGIN_HTML
1129 
1130 <h3><a name="index">V. Product and module index</a></h3>
1131 
1132 <p><a href="#THtml:MakeIndex">THtml::MakeIndex()</a> will generate index files for classes
1133 and types, all modules, and the product which you can set by
1134 <a href="#THtml:SetProductName">THtml::SetProductName()</a>.
1135 THtml will make use of external documentation in the module and product index,
1136 either by linking it or by including it.
1137 The files for modules are searched based on the source file directory of the
1138 module's classes.</p>
1139 
1140 <p>A filename starting with "index." will be included in the index page;
1141 all other files will be linked.
1142 Only files ending on <tt>.html</tt> or <tt>.txt</tt> will be taken into account;
1143 the text files will first be run through
1144 <a href="#THtml:Convert">THtml::Convert()</a>.
1145 You can see an example <a href="http://root.cern.ch/root/html/HIST_Index.html">here</a>;
1146 the part between "Index of HIST classes" and "Jump to" is created by parsing
1147 the module's doc directory.</p>
1148 
1149 <h3><a name="aux">VI. Auxiliary files: style sheet, JavaScript, help page</a></h3>
1150 
1151 <p>The documentation pages share a common set of javascript and CSS files. They
1152 are generated automatically when running <a href="#THtml:MakeAll">MakeAll()</a>;
1153 they can be generated on
1154 demand by calling <a href="#THtml:CreateAuxiliaryFiles">CreateAuxiliaryFiles()</a>.</p>
1155 
1156 
1157 <h3><a name="charts">VII. Class Charts</a></h3>
1158 THtml can generate a number of graphical representations for a class, which
1159 are displayed as a tabbed set of imaged ontop of the class description.
1160 It can show the inheritance, inherited and hidden members, directly and
1161 indirectly included files, and library dependencies.
1162 
1163 These graphs are generated using the <a href="http://www.graphviz.org/">Graphviz</a>
1164 package. You can install it from <a href="http://www.graphviz.org">http://www.graphviz.org</a>.
1165 You can either put it into your $PATH, or tell THtml where to find it by calling
1166 <a href="#THtml:SetDotDir">SetDotDir()</a>.
1167 
1168 
1169 <h3><a name="confvar">VIII. Configuration variables</a></h3>
1170 
1171 <p>Here is a list of all configuration variables that are known to THtml.
1172 You can set them in your .rootrc file, see
1173 <a href="http://root.cern.ch/root/html/TEnv.html">TEnv</a>.</p>
1174 
1175 <pre>
1176  Root.Html.OutputDir (default: htmldoc)
1177  Root.Html.SourceDir (default: .:src/:include/)
1178  Root.Html.Author (default: // Author:) - start tag for authors
1179  Root.Html.LastUpdate (default: // @(#)) - start tag for last update
1180  Root.Html.Copyright (default: * Copyright) - start tag for copyright notice
1181  Root.Html.Description (default: //____________________ ) - start tag for class descr
1182  Root.Html.HomePage (default: ) - URL to the user defined home page
1183  Root.Html.Header (default: ) - location of user defined header
1184  Root.Html.Footer (default: ) - location of user defined footer
1185  Root.Html.Root (default: ) - URL of Root's class documentation
1186  Root.Html.SearchEngine (default: ) - link to the search engine
1187  Root.Html.Search (defualt: ) - link to search by replacing "%s" with user input
1188  Root.Html.ViewCVS (default: ) - URL of ViewCVS base
1189  Root.Html.XWho (default: http://consult.cern.ch/xwho/people?) - URL of CERN's xWho
1190  Root.Html.Charset (default: ISO-8859-1) - HTML character set
1191 </pre>
1192 
1193 <h3><a name="how">IX. Behind the scene</a></h3>
1194 
1195 <p>Internally, THtml is just an API class that sets up the list of known
1196 classes, and forwards API invocations to the "work horses".
1197 <a href="http://root.cern.ch/root/html/TDocOutput.html">TDocOutput</a>
1198 generates the output by letting a
1199 <a href="http://root.cern.ch/root/html/TDocParser.html">TDocParser</a>
1200 object parse the sources, which in turn invokes objects deriving from
1201 <a href="http://root.cern.ch/root/html/TDocDirective.html">TDocDirective</a>
1202 to process directives.</p>
1203 
1204 END_HTML */
1205 ////////////////////////////////////////////////////////////////////////////////
1206 
1207 ClassImp(THtml);
1208 ////////////////////////////////////////////////////////////////////////////////
1209 /// Create a THtml object.
1210 /// In case output directory does not exist an error
1211 /// will be printed and gHtml stays 0 also zombie bit will be set.
1212 
1213 THtml::THtml():
1214  fCounterFormat("%12s %5s %s"),
1215  fProductName("(UNKNOWN PRODUCT)"),
1216  fThreadedClassIter(0), fThreadedClassCount(0), fMakeClassMutex(0),
1217  fGClient(0), fPathDef(0), fModuleDef(0), fFileDef(0),
1218  fLocalFiles(0), fBatch(kFALSE)
1219 {
1220  // check for source directory
1221  fPathInfo.fInputPath = gEnv->GetValue("Root.Html.SourceDir", "./:src/:include/");
1222 
1223  // check for output directory
1224  SetOutputDir(gEnv->GetValue("Root.Html.OutputDir", "htmldoc"));
1225 
1226  fLinkInfo.fXwho = gEnv->GetValue("Root.Html.XWho", "http://consult.cern.ch/xwho/people?");
1227  fLinkInfo.fROOTURL = gEnv->GetValue("Root.Html.Root", "http://root.cern.ch/root/html");
1228  fDocSyntax.fClassDocTag = gEnv->GetValue("Root.Html.Description", "//____________________");
1229  fDocSyntax.fAuthorTag = gEnv->GetValue("Root.Html.Author", "// Author:");
1230  fDocSyntax.fLastUpdateTag = gEnv->GetValue("Root.Html.LastUpdate", "// @(#)");
1231  fDocSyntax.fCopyrightTag = gEnv->GetValue("Root.Html.Copyright", "* Copyright");
1232  fOutputStyle.fHeader = gEnv->GetValue("Root.Html.Header", "");
1233  fOutputStyle.fFooter = gEnv->GetValue("Root.Html.Footer", "");
1234  fLinkInfo.fHomepage = gEnv->GetValue("Root.Html.Homepage", "");
1235  fLinkInfo.fSearchStemURL = gEnv->GetValue("Root.Html.Search", "");
1236  fLinkInfo.fSearchEngine = gEnv->GetValue("Root.Html.SearchEngine", "");
1237  fLinkInfo.fViewCVS = gEnv->GetValue("Root.Html.ViewCVS", "");
1238  fOutputStyle.fCharset = gEnv->GetValue("Root.Html.Charset", "ISO-8859-1");
1239  fDocSyntax.fDocStyle = gEnv->GetValue("Root.Html.DescriptionStyle", "");
1240 
1241  fDocEntityInfo.fClasses.SetOwner();
1242  fDocEntityInfo.fModules.SetOwner();
1243  // insert html object in the list of special ROOT objects
1244  if (!gHtml) {
1245  gHtml = this;
1246  gROOT->GetListOfSpecials()->Add(gHtml);
1247  }
1248 
1249 }
1250 
1251 
1252 ////////////////////////////////////////////////////////////////////////////////
1253 /// Default destructor
1254 
1255 THtml::~THtml()
1256 {
1257  fDocEntityInfo.fClasses.Clear();
1258  fDocEntityInfo.fModules.Clear();
1259  if (gHtml == this) {
1260  gROOT->GetListOfSpecials()->Remove(gHtml);
1261  gHtml = 0;
1262  }
1263  delete fPathDef;
1264  delete fModuleDef;
1265  delete fFileDef;
1266  delete fLocalFiles;
1267 }
1268 
1269 ////////////////////////////////////////////////////////////////////////////////
1270 /// Add path to the directories to be searched for macro files
1271 /// that are to be executed via the TDocMacroDirective
1272 /// ("Begin_Macro"/"End_Macro"); relative to the source file
1273 /// that the directive is run on.
1274 
1275 void THtml::AddMacroPath(const char* path)
1276 {
1277  const char pathDelimiter =
1278 #ifdef R__WIN32
1279  ';';
1280 #else
1281  ':';
1282 #endif
1283  fPathInfo.fMacroPath += pathDelimiter;
1284  fPathInfo.fMacroPath += path;
1285 }
1286 
1287 
1288 ////////////////////////////////////////////////////////////////////////////////
1289 /// copy CSS, javascript file, etc to the output dir
1290 
1291 void THtml::CreateAuxiliaryFiles() const
1292 {
1293  CreateJavascript();
1294  CreateStyleSheet();
1295  CopyFileFromEtcDir("HELP.html");
1296 }
1297 
1298 ////////////////////////////////////////////////////////////////////////////////
1299 /// Return the TModuleDefinition (or derived) object as set by
1300 /// SetModuleDefinition(); create and return a TModuleDefinition object
1301 /// if none was set.
1302 
1303 const THtml::TModuleDefinition& THtml::GetModuleDefinition() const
1304 {
1305  if (!fModuleDef) {
1306  fModuleDef = new TModuleDefinition();
1307  fModuleDef->SetOwner(const_cast<THtml*>(this));
1308  }
1309  return *fModuleDef;
1310 }
1311 
1312 ////////////////////////////////////////////////////////////////////////////////
1313 /// Return the TFileDefinition (or derived) object as set by
1314 /// SetFileDefinition(); create and return a TFileDefinition object
1315 /// if none was set.
1316 
1317 const THtml::TFileDefinition& THtml::GetFileDefinition() const
1318 {
1319  if (!fFileDef) {
1320  fFileDef = new TFileDefinition();
1321  fFileDef->SetOwner(const_cast<THtml*>(this));
1322  }
1323  return *fFileDef;
1324 }
1325 
1326 ////////////////////////////////////////////////////////////////////////////////
1327 /// Return the TModuleDefinition (or derived) object as set by
1328 /// SetModuleDefinition(); create and return a TModuleDefinition object
1329 /// if none was set.
1330 
1331 const THtml::TPathDefinition& THtml::GetPathDefinition() const
1332 {
1333  if (!fPathDef) {
1334  fPathDef = new TPathDefinition();
1335  fPathDef->SetOwner(const_cast<THtml*>(this));
1336  }
1337  return *fPathDef;
1338 }
1339 
1340 
1341 ////////////////////////////////////////////////////////////////////////////////
1342 /// Get the directory containing THtml's auxiliary files ($ROOTSYS/etc/html)
1343 
1344 const char* THtml::GetEtcDir() const
1345 {
1346  if (fPathInfo.fEtcDir.Length())
1347  return fPathInfo.fEtcDir;
1348 
1349  R__LOCKGUARD(GetMakeClassMutex());
1350 
1351  fPathInfo.fEtcDir = "html";
1352  gSystem->PrependPathName(TROOT::GetEtcDir(), fPathInfo.fEtcDir);
1353 
1354  return fPathInfo.fEtcDir;
1355 }
1356 
1357 
1358 ////////////////////////////////////////////////////////////////////////////////
1359 /// Return the next class to be generated for MakeClassThreaded.
1360 
1361 TClassDocInfo *THtml::GetNextClass()
1362 {
1363  if (!fThreadedClassIter) return 0;
1364 
1365  R__LOCKGUARD(GetMakeClassMutex());
1366 
1367  TClassDocInfo* classinfo = 0;
1368  while ((classinfo = (TClassDocInfo*)(*fThreadedClassIter)())
1369  && !classinfo->IsSelected()) { }
1370 
1371  if (!classinfo) {
1372  delete fThreadedClassIter;
1373  fThreadedClassIter = 0;
1374  }
1375 
1376  fCounter.Form("%5d", fDocEntityInfo.fClasses.GetSize() - fThreadedClassCount++);
1377 
1378  return classinfo;
1379 }
1380 
1381 
1382 ////////////////////////////////////////////////////////////////////////////////
1383 /// Get the documentation URL for library lib.
1384 /// If lib == 0 or no documentation URL has been set for lib, return the ROOT
1385 /// documentation URL. The return value is always != 0.
1386 
1387 const char* THtml::GetURL(const char* lib /*=0*/) const
1388 {
1389  R__LOCKGUARD(GetMakeClassMutex());
1390 
1391  if (lib && strlen(lib)) {
1392  std::map<std::string, TString>::const_iterator iUrl = fLinkInfo.fLibURLs.find(lib);
1393  if (iUrl != fLinkInfo.fLibURLs.end()) return iUrl->second;
1394  return gEnv->GetValue(TString("Root.Html.") + lib, fLinkInfo.fROOTURL);
1395  }
1396  return fLinkInfo.fROOTURL;
1397 }
1398 
1399 ////////////////////////////////////////////////////////////////////////////////
1400 /// Check whether dot is available in $PATH or in the directory set
1401 /// by SetDotPath()
1402 
1403 Bool_t THtml::HaveDot()
1404 {
1405  if (fPathInfo.fFoundDot != PathInfo_t::kDotUnknown)
1406  return (fPathInfo.fFoundDot == PathInfo_t::kDotFound);
1407 
1408  R__LOCKGUARD(GetMakeClassMutex());
1409 
1410  Info("HaveDot", "Checking for Graphviz (dot)...");
1411  TString runDot("dot");
1412  if (fPathInfo.fDotDir.Length())
1413  gSystem->PrependPathName(fPathInfo.fDotDir, runDot);
1414  runDot += " -V";
1415  if (gDebug > 3)
1416  Info("HaveDot", "Running: %s", runDot.Data());
1417  if (gSystem->Exec(runDot)) {
1418  fPathInfo.fFoundDot = PathInfo_t::kDotNotFound;
1419  return kFALSE;
1420  }
1421  fPathInfo.fFoundDot = PathInfo_t::kDotFound;
1422  return kTRUE;
1423 
1424 }
1425 
1426 ////////////////////////////////////////////////////////////////////////////////
1427 /// Inform the THtml object that one of its helper objects was deleted.
1428 /// Called by THtml::HelperBase::~HelperBase().
1429 
1430 void THtml::HelperDeleted(THtml::THelperBase* who)
1431 {
1432  THelperBase* helpers[3] = {fPathDef, fModuleDef, fFileDef};
1433  for (int i = 0; who && i < 3; ++i)
1434  if (who == helpers[i])
1435  helpers[i] = who = 0;
1436 }
1437 
1438 
1439 ////////////////////////////////////////////////////////////////////////////////
1440 /// It converts a single text file to HTML
1441 ///
1442 ///
1443 /// Input: filename - name of the file to convert
1444 /// title - title which will be placed at the top of the HTML file
1445 /// dirname - optional parameter, if it's not specified, output will
1446 /// be placed in htmldoc/examples directory.
1447 /// relpath - optional parameter pointing to the THtml generated doc
1448 /// on the server, relative to the current page.
1449 /// includeOutput - if != kNoOutput, run the script passed as filename and
1450 /// store all created canvases in PNG files that are
1451 /// shown next to the converted source. Bitwise-ORing with
1452 /// kForceOutput re-runs the script even if output PNGs exist
1453 /// that are newer than the script. If kCompiledOutput is
1454 /// passed, the script is run through ACLiC (.x filename+)
1455 /// context - line shown verbatim at the top of the page; e.g. for links.
1456 /// If context is non-empty it is expected to also print the
1457 /// title.
1458 ///
1459 /// NOTE: Output file name is the same as filename, but with extension .html
1460 ///
1461 
1462 void THtml::Convert(const char *filename, const char *title,
1463  const char *dirname /*= ""*/, const char *relpath /*= "../"*/,
1464  Int_t includeOutput /* = kNoOutput */,
1465  const char* context /* = "" */)
1466 {
1467  gROOT->GetListOfGlobals(kTRUE); // force update of this list
1468  CreateListOfClasses("*");
1469 
1470  const char *dir;
1471 
1472  // if it's not defined, make the "examples" as a default directory
1473  if (!*dirname) {
1474  gSystem->ExpandPathName(fPathInfo.fOutputDir);
1475  dir = gSystem->ConcatFileName(fPathInfo.fOutputDir, "examples");
1476  } else
1477  dir = dirname;
1478 
1479  // create directory if necessary
1480  if (gSystem->AccessPathName(dir))
1481  gSystem->MakeDirectory(dir);
1482 
1483  // find a file
1484  char *cRealFilename =
1485  gSystem->Which(fPathInfo.fInputPath, filename, kReadPermission);
1486 
1487  if (!cRealFilename) {
1488  Error("Convert", "Can't find file '%s' !", filename);
1489  return;
1490  }
1491 
1492  TString realFilename(cRealFilename);
1493  delete[] cRealFilename;
1494  cRealFilename = 0;
1495 
1496  // open source file
1497  std::ifstream sourceFile;
1498  sourceFile.open(realFilename, std::ios::in);
1499 
1500  if (!sourceFile.good()) {
1501  Error("Convert", "Can't open file '%s' !", realFilename.Data());
1502  return;
1503  }
1504 
1505  if (gSystem->AccessPathName(dir)) {
1506  Error("Convert",
1507  "Directory '%s' doesn't exist, or it's write protected !", dir);
1508  return;
1509  }
1510  char *tmp1 =
1511  gSystem->ConcatFileName(dir, gSystem->BaseName(filename));
1512 
1513  TDocOutput output(*this);
1514  if (!fGClient)
1515  gROOT->ProcessLine(TString::Format("*((TGClient**)0x%lx) = gClient;",
1516  (ULong_t)&fGClient));
1517  if (includeOutput && !fGClient)
1518  Warning("Convert", "Output requested but cannot initialize graphics: GUI and GL windows not be available");
1519  output.Convert(sourceFile, realFilename, tmp1, title, relpath, includeOutput, context, fGClient);
1520 
1521  if (tmp1)
1522  delete[]tmp1;
1523  tmp1 = 0;
1524 }
1525 
1526 ////////////////////////////////////////////////////////////////////////////////
1527 /// Return the module name for a given class.
1528 /// Use the cached information from fDocEntityInfo.fClasses.
1529 
1530 void THtml::GetModuleNameForClass(TString& module, TClass* cl) const
1531 {
1532  module = "(UNKNOWN)";
1533  if (!cl) return;
1534 
1535  TClassDocInfo* cdi = (TClassDocInfo*)fDocEntityInfo.fClasses.FindObject(cl->GetName());
1536  if (!cdi || !cdi->GetModule())
1537  return;
1538  module = cdi->GetModule()->GetName();
1539 }
1540 
1541 
1542 ////////////////////////////////////////////////////////////////////////////////
1543 /// Create the list of all known classes
1544 
1545 void THtml::CreateListOfClasses(const char* filter)
1546 {
1547  if (fDocEntityInfo.fClasses.GetSize() && fDocEntityInfo.fClassFilter == filter)
1548  return;
1549 
1550  Info("CreateListOfClasses", "Initializing - this might take a while...");
1551  // get total number of classes
1552  Int_t totalNumberOfClasses = gClassTable->Classes();
1553 
1554  // allocate memory
1555  fDocEntityInfo.fClasses.Clear();
1556  fDocEntityInfo.fModules.Clear();
1557 
1558  fDocEntityInfo.fClassFilter = filter;
1559 
1560  // start from beginning
1561  gClassTable->Init();
1562  if (filter && (!filter[0] || !strcmp(filter, "*")))
1563  filter = ".*";
1564  TString reg = filter;
1565  TPMERegexp re(reg);
1566 
1567  bool skipROOTClasses = false;
1568  std::set<std::string> rootLibs;
1569  TList classesDeclFileNotFound;
1570  TList classesImplFileNotFound;
1571 
1572  // pre-run TObject at i == -1
1573  for (Int_t i = -1; i < totalNumberOfClasses; i++) {
1574 
1575  // get class name
1576  const char *cname = 0;
1577  if (i < 0) cname = "TObject";
1578  else cname = gClassTable->Next();
1579  if (!cname)
1580  continue;
1581 
1582  if (i >= 0 && !strcmp(cname, "TObject")) {
1583  // skip the second iteration on TObject
1584  continue;
1585  }
1586 
1587  // This is a hack for until after Cint and Reflex are one.
1588  if (strstr(cname, "__gnu_cxx::")) continue;
1589  // Work around ROOT-6016
1590  if (!strcmp(cname, "timespec")) continue;
1591  // "tuple"s are synthetic in the interpreter
1592  if (!strncmp(cname, "tuple<", 6)) continue;
1593 
1594  // get class & filename - use TROOT::GetClass, as we also
1595  // want those classes without decl file name!
1596  TClass *classPtr = TClass::GetClass((const char *) cname, kTRUE);
1597  if (!classPtr) continue;
1598 
1599  std::string shortName(ShortType(cname));
1600  cname = shortName.c_str();
1601 
1602  TString s = cname;
1603  Bool_t matchesSelection = re.Match(s);
1604 
1605 
1606  TString hdr;
1607  TString hdrFS;
1608  TString src;
1609  TString srcFS;
1610  TString htmlfilename;
1611  TFileSysEntry* fse = 0;
1612 
1613  TClassDocInfo* cdi = (TClassDocInfo*) fDocEntityInfo.fClasses.FindObject(cname);
1614  if (cdi) {
1615  hdr = cdi->GetDeclFileName();
1616  hdrFS = cdi->GetDeclFileSysName();
1617  src = cdi->GetImplFileName();
1618  srcFS = cdi->GetImplFileSysName();
1619  htmlfilename = cdi->GetHtmlFileName();
1620  }
1621 
1622  if (!hdrFS.Length()) {
1623  if (!GetFileDefinition().GetDeclFileName(classPtr, hdr, hdrFS, &fse)) {
1624  // we don't even know where the class is defined;
1625  // just skip. Silence if it doesn't match the selection anyway
1626  if (i == -1 ) {
1627  skipROOTClasses = true;
1628  Info("CreateListOfClasses", "Cannot find header file for TObject at %s given the input path %s.",
1629  classPtr->GetDeclFileName(), GetInputPath().Data());
1630  Info("CreateListOfClasses", "Assuming documentation is not for ROOT classes, or you need to pass "
1631  "the proper directory to THtml::SetInputDir() so I can find %s.", classPtr->GetDeclFileName());
1632  continue;
1633  }
1634  // ignore STL
1635  if (classPtr->GetClassInfo() &&
1636  (gInterpreter->ClassInfo_Property(classPtr->GetClassInfo()) & kIsDefinedInStd))
1637  continue;
1638  if (classPtr->GetDeclFileName() && (!strncmp(classPtr->GetDeclFileName(), "prec_stl/", 9) ||
1639  strstr(classPtr->GetDeclFileName(), "include/c++/") ||
1640  !strncmp(classPtr->GetDeclFileName(), "/usr/include",12)))
1641  continue;
1642  if (classPtr->GetDeclFileName() && (
1643  !strcmp(classPtr->GetDeclFileName(), "vector") ||
1644  !strcmp(classPtr->GetDeclFileName(), "string") ||
1645  !strcmp(classPtr->GetDeclFileName(), "list") ||
1646  !strcmp(classPtr->GetDeclFileName(), "deque") ||
1647  !strcmp(classPtr->GetDeclFileName(), "map") ||
1648  !strcmp(classPtr->GetDeclFileName(), "valarray") ||
1649  !strcmp(classPtr->GetDeclFileName(), "set") ||
1650  !strcmp(classPtr->GetDeclFileName(), "typeinfo") ||
1651  !strcmp(classPtr->GetDeclFileName(), "stdlib.h") ) )
1652  {
1653  // Those are STL header, just ignore.
1654  continue;
1655  }
1656  if (skipROOTClasses) {
1657  if (classPtr->GetSharedLibs() && classPtr->GetSharedLibs()[0]) {
1658  std::string lib(classPtr->GetSharedLibs());
1659  size_t posSpace = lib.find(' ');
1660  if (posSpace != std::string::npos)
1661  lib.erase(posSpace);
1662  if (rootLibs.find(lib) == rootLibs.end()) {
1663  TString rootlibdir = TROOT::GetLibDir();
1664  TString sLib(lib);
1665  if (sLib.Index('.') == -1) {
1666  sLib += ".";
1667  sLib += gSystem->GetSoExt();
1668  }
1669  gSystem->PrependPathName(rootlibdir, sLib);
1670  if (gSystem->AccessPathName(sLib))
1671  // the library doesn't exist in $ROOTSYS/lib, so it's not
1672  // a root lib and we need to tell the user.
1673  classesDeclFileNotFound.AddLast(classPtr);
1674  else rootLibs.insert(lib);
1675  } // end "if rootLibs does not contain lib"
1676  } else {
1677  // lib name unknown
1678  static const char* rootClassesToIgnore[] =
1679  { "ColorStruct_t", "CpuInfo_t", "Event_t", "FileStat_t", "GCValues_t", "MemInfo_t",
1680  "PictureAttributes_t", "Point_t", "ProcInfo_t", "ROOT", "ROOT::Fit",
1681  "Rectangle_t", "RedirectHandle_t", "Segment_t", "SetWindowAttributes_t",
1682  "SysInfo_t", "TCint", "UserGroup_t", "WindowAttributes_t", "timespec", 0};
1683  static const char* rootClassStemsToIgnore[] =
1684  { "ROOT::Math", "TKDTree", "TMatrixT", "TParameter", "vector", 0 };
1685  static size_t rootClassStemsToIgnoreLen[] = {0, 0, 0, 0, 0};
1686  static std::set<std::string> setRootClassesToIgnore;
1687  if (setRootClassesToIgnore.empty()) {
1688  for (int ii = 0; rootClassesToIgnore[ii]; ++ii)
1689  setRootClassesToIgnore.insert(rootClassesToIgnore[ii]);
1690  for (int ii = 0; rootClassStemsToIgnore[ii]; ++ii)
1691  rootClassStemsToIgnoreLen[ii] = strlen(rootClassStemsToIgnore[ii]);
1692  }
1693  // only complain about this class if it should not be ignored:
1694  if (setRootClassesToIgnore.find(cname) == setRootClassesToIgnore.end()) {
1695  bool matched = false;
1696  for (int ii = 0; !matched && rootClassStemsToIgnore[ii]; ++ii)
1697  matched = !strncmp(cname, rootClassStemsToIgnore[ii], rootClassStemsToIgnoreLen[ii]);
1698  if (!matched)
1699  classesDeclFileNotFound.AddLast(classPtr);
1700  }
1701  } // lib name known
1702  continue;
1703  } else {
1704  if (matchesSelection && (!classPtr->GetDeclFileName() ||
1705  !strstr(classPtr->GetDeclFileName(),"prec_stl/") ||
1706  !strstr(classPtr->GetDeclFileName(), "include/c++/") ||
1707  strncmp(classPtr->GetDeclFileName(), "/usr/include",12)))
1708  classesDeclFileNotFound.AddLast(classPtr);
1709  continue;
1710  }
1711  }
1712  }
1713 
1714  Bool_t haveSource = (srcFS.Length());
1715  if (!haveSource)
1716  haveSource = GetFileDefinition().GetImplFileName(classPtr, src, srcFS, fse ? 0 : &fse);
1717 
1718  if (!haveSource) {
1719  classesImplFileNotFound.AddLast(classPtr);
1720  }
1721 
1722  if (!htmlfilename.Length())
1723  GetHtmlFileName(classPtr, htmlfilename);
1724 
1725  if (!cdi) {
1726  cdi = new TClassDocInfo(classPtr, htmlfilename, hdrFS, srcFS, hdr, src);
1727  fDocEntityInfo.fClasses.Add(cdi);
1728  } else {
1729  cdi->SetDeclFileName(hdr);
1730  cdi->SetImplFileName(src);
1731  cdi->SetDeclFileSysName(hdrFS);
1732  cdi->SetImplFileSysName(srcFS);
1733  cdi->SetHtmlFileName(htmlfilename);
1734  }
1735 
1736  cdi->SetSelected(matchesSelection);
1737 
1738  TString modulename;
1739  GetModuleDefinition().GetModule(classPtr, fse, modulename);
1740  if (!modulename.Length() || modulename == "USER")
1741  GetModuleNameForClass(modulename, classPtr);
1742 
1743  TModuleDocInfo* module = (TModuleDocInfo*) fDocEntityInfo.fModules.FindObject(modulename);
1744  if (!module) {
1745  bool moduleSelected = cdi->IsSelected();
1746 
1747  TString parentModuleName(gSystem->DirName(modulename));
1748  TModuleDocInfo* super = 0;
1749  if (parentModuleName.Length() && parentModuleName != ".") {
1750  super = (TModuleDocInfo*) fDocEntityInfo.fModules.FindObject(parentModuleName);
1751  if (!super) {
1752  // create parents:
1753  TString token;
1754  Ssiz_t pos = 0;
1755  while (parentModuleName.Tokenize(token, pos, "/")) {
1756  if (!token.Length() || token == ".") continue;
1757  super = new TModuleDocInfo(token, super);
1758  super->SetSelected(moduleSelected);
1759  fDocEntityInfo.fModules.Add(super);
1760  }
1761  }
1762  }
1763  module = new TModuleDocInfo(modulename, super);
1764  module->SetSelected(moduleSelected);
1765  fDocEntityInfo.fModules.Add(module);
1766  }
1767 
1768  if (module) {
1769  module->AddClass(cdi);
1770  cdi->SetModule(module);
1771  if (cdi->HaveSource() && cdi->IsSelected())
1772  module->SetSelected();
1773  }
1774 
1775  // clear the typedefs; we fill them later
1776  cdi->GetListOfTypedefs().Clear();
1777 
1778  if (gDebug > 0)
1779  Info("CreateListOfClasses", "Adding class %s, module %s (%sselected)",
1780  cdi->GetName(), module ? module->GetName() : "[UNKNOWN]",
1781  cdi->IsSelected() ? "" : "not ");
1782  }
1783 
1784 
1785 
1786  bool cannotFind = false;
1787  if (!classesDeclFileNotFound.IsEmpty()) {
1788  Warning("CreateListOfClasses",
1789  "Cannot find the header for the following classes [reason]:");
1790  TIter iClassesDeclFileNotFound(&classesDeclFileNotFound);
1791  TClass* iClass = 0;
1792  while ((iClass = (TClass*)iClassesDeclFileNotFound())) {
1793  if (iClass->GetDeclFileName() && iClass->GetDeclFileName()[0]) {
1794  Warning("CreateListOfClasses", " %s [header %s not found]", iClass->GetName(), iClass->GetDeclFileName());
1795  cannotFind = true;
1796  } else
1797  Warning("CreateListOfClasses", " %s [header file is unknown]", iClass->GetName());
1798  }
1799  }
1800 
1801  if (!classesImplFileNotFound.IsEmpty() && gDebug > 3) {
1802  Warning("CreateListOfClasses",
1803  "Cannot find the source file for the following classes [reason]:");
1804  TIter iClassesDeclFileNotFound(&classesImplFileNotFound);
1805  TClass* iClass = 0;
1806  while ((iClass = (TClass*)iClassesDeclFileNotFound())) {
1807  if (iClass->GetDeclFileName() && iClass->GetDeclFileName()[0]) {
1808  Info("CreateListOfClasses", " %s [source %s not found]", iClass->GetName(), iClass->GetImplFileName());
1809  cannotFind = true;
1810  } else
1811  Info("CreateListOfClasses", " %s [source file is unknown, add \"ClassImpl(%s)\" to source file if it exists]",
1812  iClass->GetName(), iClass->GetName());
1813  }
1814  }
1815  if (cannotFind) {
1816  Warning("CreateListOfClasses", "THtml cannot find all headers and sources. ");
1817  Warning("CreateListOfClasses",
1818  "You might need to adjust the input path (currently %s) by calling THtml::SetInputDir()",
1819  GetInputPath().Data());
1820  }
1821 
1822  // fill typedefs
1823  TIter iTypedef(gROOT->GetListOfTypes());
1824  TDataType* dt = 0;
1825  TDocOutput output(*this);
1826  while ((dt = (TDataType*) iTypedef())) {
1827  if (dt->GetType() != -1) continue;
1828  TClassDocInfo* cdi = (TClassDocInfo*) fDocEntityInfo.fClasses.FindObject(dt->GetFullTypeName());
1829  if (cdi) {
1830  cdi->GetListOfTypedefs().Add(dt);
1831  if (gDebug > 1)
1832  Info("CreateListOfClasses", "Adding typedef %s to class %s",
1833  dt->GetName(), cdi->GetName());
1834 
1835  bool inNamespace = true;
1836  TString surroundingNamespace(dt->GetName());
1837  Ssiz_t posTemplate = surroundingNamespace.Last('>');
1838  inNamespace = inNamespace && (posTemplate == kNPOS);
1839  if (inNamespace) {
1840  Ssiz_t posColumn = surroundingNamespace.Last(':');
1841  if (posColumn != kNPOS) {
1842  surroundingNamespace.Remove(posColumn - 1);
1843  TClass* clSurrounding = GetClass(surroundingNamespace);
1844  inNamespace = inNamespace && (!clSurrounding || IsNamespace(clSurrounding));
1845  }
1846  }
1847  if (inNamespace && cdi->GetModule()) {
1848  TString htmlfilename(dt->GetName());
1849  output.NameSpace2FileName(htmlfilename);
1850  htmlfilename += ".html";
1851  TClassDocInfo* cdiTD = new TClassDocInfo(dt, htmlfilename);
1852  cdiTD->SetModule(cdi->GetModule());
1853  cdiTD->SetSelected(cdi->IsSelected());
1854  cdi->GetModule()->AddClass(cdiTD);
1855  }
1856  }
1857  }
1858 
1859  fDocEntityInfo.fClasses.Sort();
1860  fDocEntityInfo.fModules.Sort();
1861  TIter iterModule(&fDocEntityInfo.fModules);
1862  TModuleDocInfo* mdi = 0;
1863  while ((mdi = (TModuleDocInfo*) iterModule()))
1864  mdi->GetClasses()->Sort();
1865 
1866  if (fProductName == "(UNKNOWN PRODUCT)"
1867  && fDocEntityInfo.fModules.FindObject("core/base")
1868  && fDocEntityInfo.fModules.FindObject("core/cont")
1869  && fDocEntityInfo.fModules.FindObject("core/rint")
1870  && gProgName && strstr(gProgName, "root"))
1871  // if we have these modules we're probably building the root doc
1872  fProductName = "ROOT";
1873 
1874  if (fProductName == "(UNKNOWN PRODUCT)") {
1875  Warning("CreateListOfClasses", "Product not set. You should call gHtml->SetProduct(\"MyProductName\");");
1876  } else if (fProductName != "ROOT") {
1877  if (GetViewCVS().Contains("http://root.cern.ch/"))
1878  SetViewCVS("");
1879  }
1880 
1881  if (fDocEntityInfo.fModules.GetEntries() == 1
1882  && fDocEntityInfo.fModules.At(0)->GetName()
1883  && !strcmp(fDocEntityInfo.fModules.At(0)->GetName(), "(UNKNOWN)"))
1884  // Only one module, and its name is not known.
1885  // Let's call it "MAIN":
1886  ((TModuleDocInfo*) fDocEntityInfo.fModules.At(0))->SetName("MAIN");
1887 
1888  Info("CreateListOfClasses", "Initializing - DONE.");
1889 }
1890 
1891 
1892 ////////////////////////////////////////////////////////////////////////////////
1893 /// Create index of all data types and a page for each typedef-to-class
1894 
1895 void THtml::CreateListOfTypes()
1896 {
1897  TDocOutput output(*this);
1898  output.CreateTypeIndex();
1899  output.CreateClassTypeDefs();
1900 }
1901 
1902 ////////////////////////////////////////////////////////////////////////////////
1903 /// Copy a file from $ROOTSYS/etc/html into GetOutputDir()
1904 
1905 Bool_t THtml::CopyFileFromEtcDir(const char* filename) const {
1906  R__LOCKGUARD(GetMakeClassMutex());
1907 
1908  TString outFile(filename);
1909 
1910  TString inFile(outFile);
1911  gSystem->PrependPathName(GetEtcDir(), inFile);
1912 
1913  gSystem->PrependPathName(GetOutputDir(), outFile);
1914 
1915  if (gSystem->CopyFile(inFile, outFile, kTRUE) != 0) {
1916  Warning("CopyFileFromEtcDir", "Could not copy %s to %s", inFile.Data(), outFile.Data());
1917  return kFALSE;
1918  }
1919 
1920  return kTRUE;
1921 }
1922 
1923 ////////////////////////////////////////////////////////////////////////////////
1924 /// Create the inheritance hierarchy diagram for all classes
1925 
1926 void THtml::CreateHierarchy()
1927 {
1928  TDocOutput output(*this);
1929  output.CreateHierarchy();
1930 }
1931 
1932 ////////////////////////////////////////////////////////////////////////////////
1933 /// Write the default ROOT style sheet.
1934 
1935 void THtml::CreateJavascript() const {
1936  CopyFileFromEtcDir("ROOT.js");
1937 }
1938 
1939 ////////////////////////////////////////////////////////////////////////////////
1940 /// Write the default ROOT style sheet.
1941 
1942 void THtml::CreateStyleSheet() const {
1943  CopyFileFromEtcDir("ROOT.css");
1944  CopyFileFromEtcDir("shadowAlpha.png");
1945  CopyFileFromEtcDir("shadow.gif");
1946 }
1947 
1948 
1949 
1950 ////////////////////////////////////////////////////////////////////////////////
1951 /// fill derived with all classes inheriting from cl and their inheritance
1952 /// distance to cl
1953 
1954 void THtml::GetDerivedClasses(TClass* cl, std::map<TClass*, Int_t>& derived) const
1955 {
1956  TIter iClass(&fDocEntityInfo.fClasses);
1957  TClassDocInfo* cdi = 0;
1958  while ((cdi = (TClassDocInfo*) iClass())) {
1959  TClass* candidate = dynamic_cast<TClass*>(cdi->GetClass());
1960  if (!candidate) continue;
1961  if (candidate != cl && candidate->InheritsFrom(cl)) {
1962  Int_t level = 0;
1963  TClass* currentBaseOfCandidate = candidate;
1964  while (currentBaseOfCandidate != cl) {
1965  TList* bases = currentBaseOfCandidate->GetListOfBases();
1966  if (!bases) continue;
1967  TIter iBase(bases);
1968  TBaseClass* base = 0;
1969  while ((base = (TBaseClass*) iBase())) {
1970  TClass* clBase = base->GetClassPointer();
1971  if (clBase && clBase->InheritsFrom(cl)) {
1972  ++level;
1973  currentBaseOfCandidate = clBase;
1974  }
1975  }
1976  }
1977  derived[candidate] = level;
1978  }
1979  }
1980 }
1981 
1982 ////////////////////////////////////////////////////////////////////////////////
1983 /// Return real HTML filename
1984 ///
1985 ///
1986 /// Input: classPtr - pointer to a class
1987 /// filename - string containing a full name
1988 /// of the corresponding HTML file after the function returns.
1989 ///
1990 
1991 void THtml::GetHtmlFileName(TClass * classPtr, TString& filename) const
1992 {
1993  filename.Remove(0);
1994  if (!classPtr) return;
1995 
1996  TString cFilename;
1997  if (!GetImplFileName(classPtr, kFALSE, cFilename))
1998  GetDeclFileName(classPtr, kFALSE, cFilename);
1999 
2000  // classes without Impl/DeclFileName don't have docs,
2001  // and classes without docs don't have output file names
2002  if (!cFilename.Length())
2003  return;
2004 
2005  TString libName;
2006  const char *colon = strchr(cFilename, ':');
2007  if (colon)
2008  // old version, where source file name is prepended by "TAG:"
2009  libName = TString(cFilename, colon - cFilename);
2010  else
2011  // New version, check class's libname.
2012  // If libname is dir/libMyLib.so, check Root.Html.MyLib
2013  // If libname is myOtherLib.so.2.3, check Root.Html.myOtherLib
2014  // (i.e. remove directories, "lib" prefix, and any "extension")
2015  if (classPtr->GetSharedLibs()) {
2016  // first one is the class's lib
2017  TString libname(classPtr->GetSharedLibs());
2018  Ssiz_t posSpace = libname.First(' ');
2019  if (posSpace != kNPOS)
2020  libname.Remove(posSpace, libname.Length());
2021  TString libnameBase = gSystem->BaseName(libname);
2022  if (libnameBase.BeginsWith("lib"))
2023  libnameBase.Remove(0, 3);
2024  Ssiz_t posExt = libnameBase.First('.');
2025  if (posExt != '.')
2026  libnameBase.Remove(posExt, libnameBase.Length());
2027  if (libnameBase.Length())
2028  libName = libnameBase;
2029  }
2030 
2031  filename = cFilename;
2032  TString htmlFileName;
2033  if (!filename.Length() ||
2034  !gSystem->FindFile(fPathInfo.fInputPath, filename, kReadPermission)) {
2035  htmlFileName = GetURL(libName);
2036  } else
2037  htmlFileName = "./";
2038 
2039  if (htmlFileName.Length()) {
2040  filename = htmlFileName;
2041  TString className(classPtr->GetName());
2042  TDocOutput output(*const_cast<THtml*>(this));
2043  output.NameSpace2FileName(className);
2044  gSystem->PrependPathName(filename, className);
2045  filename = className;
2046  filename.ReplaceAll("\\", "/");
2047  filename += ".html";
2048  } else filename.Remove(0);
2049 }
2050 
2051 ////////////////////////////////////////////////////////////////////////////////
2052 /// Get the html file name for a class named classname.
2053 /// Returns 0 if the class is not documented.
2054 
2055 const char* THtml::GetHtmlFileName(const char* classname) const
2056 {
2057  TClassDocInfo* cdi = (TClassDocInfo*) fDocEntityInfo.fClasses.FindObject(classname);
2058  if (cdi)
2059  return cdi->GetHtmlFileName();
2060  return 0;
2061 }
2062 
2063 ////////////////////////////////////////////////////////////////////////////////
2064 /// Return pointer to class with name.
2065 
2066 TClass *THtml::GetClass(const char *name1) const
2067 {
2068  if(!name1 || !name1[0]) return 0;
2069  // no doc for internal classes
2070  if (strstr(name1,"ROOT::")==name1) {
2071  Bool_t ret = kTRUE;
2072  if (!strncmp(name1 + 6,"Math", 4)) ret = kFALSE;
2073  if (ret) return 0;
2074  }
2075 
2076  TClassDocInfo* cdi = (TClassDocInfo*)fDocEntityInfo.fClasses.FindObject(name1);
2077  if (!cdi) return 0;
2078  TClass *cl = dynamic_cast<TClass*>(cdi->GetClass());
2079  // hack to get rid of prec_stl types
2080  // TClassEdit checks are far too slow...
2081  /*
2082  if (cl && GetDeclFileName(cl) &&
2083  (strstr(GetDeclFileName(cl),"prec_stl/") || !strstr(classPtr->GetDeclFileName(), "include/c++/") )
2084  cl = 0;
2085  */
2086  TString declFileName;
2087  if (cl && GetDeclFileName(cl, kFALSE, declFileName))
2088  return cl;
2089  return 0;
2090 }
2091 
2092 ////////////////////////////////////////////////////////////////////////////////
2093 /// Return declaration file name; return the full path if filesys is true.
2094 
2095 bool THtml::GetDeclFileName(TClass * cl, Bool_t filesys, TString& out_name) const
2096 {
2097  return GetDeclImplFileName(cl, filesys, true, out_name);
2098 }
2099 
2100 ////////////////////////////////////////////////////////////////////////////////
2101 /// Return implementation file name
2102 
2103 bool THtml::GetImplFileName(TClass * cl, Bool_t filesys, TString& out_name) const
2104 {
2105  return GetDeclImplFileName(cl, filesys, false, out_name);
2106 }
2107 
2108 ////////////////////////////////////////////////////////////////////////////////
2109 /// Combined implementation for GetDeclFileName(), GetImplFileName():
2110 /// Return declaration / implementation file name (depending on decl);
2111 /// return the full path if filesys is true.
2112 
2113 bool THtml::GetDeclImplFileName(TClass * cl, bool filesys, bool decl, TString& out_name) const
2114 {
2115  out_name = "";
2116 
2117  R__LOCKGUARD(GetMakeClassMutex());
2118  TClassDocInfo* cdi = (TClassDocInfo*) fDocEntityInfo.fClasses.FindObject(cl->GetName());
2119  // whether we need to determine the fil name
2120  bool determine = (!cdi); // no cdi
2121  if (!determine) determine |= decl && filesys && !cdi->GetDeclFileSysName()[0];
2122  if (!determine) determine |= decl && !filesys && !cdi->GetDeclFileName()[0];
2123  if (!determine) determine |= !decl && filesys && !cdi->GetImplFileSysName()[0];
2124  if (!determine) determine |= !decl && !filesys && !cdi->GetImplFileName()[0];
2125  if (determine) {
2126  TString name;
2127  TString sysname;
2128  if (decl) {
2129  if (!GetFileDefinition().GetDeclFileName(cl, name, sysname))
2130  return false;
2131  } else {
2132  if (!GetFileDefinition().GetImplFileName(cl, name, sysname))
2133  return false;
2134  }
2135  if (cdi) {
2136  if (decl) {
2137  if (!cdi->GetDeclFileName() || !cdi->GetDeclFileName()[0])
2138  cdi->SetDeclFileName(name);
2139  if (!cdi->GetDeclFileSysName() || !cdi->GetDeclFileSysName()[0])
2140  cdi->SetDeclFileSysName(sysname);
2141  } else {
2142  if (!cdi->GetImplFileName() || !cdi->GetImplFileName()[0])
2143  cdi->SetImplFileName(name);
2144  if (!cdi->GetImplFileSysName() || !cdi->GetImplFileSysName()[0])
2145  cdi->SetImplFileSysName(sysname);
2146  }
2147  }
2148 
2149  if (filesys) out_name = sysname;
2150  else out_name = name;
2151  return true;
2152  }
2153  if (filesys) {
2154  if (decl) out_name = cdi->GetDeclFileSysName();
2155  else out_name = cdi->GetImplFileSysName();
2156  } else {
2157  if (decl) out_name = cdi->GetDeclFileName();
2158  else out_name = cdi->GetImplFileName();
2159  }
2160  return true;
2161 }
2162 
2163 ////////////////////////////////////////////////////////////////////////////////
2164 /// Return the output directory as set by SetOutputDir().
2165 /// Create it if it doesn't exist and if createDir is kTRUE.
2166 
2167 const TString& THtml::GetOutputDir(Bool_t createDir /*= kTRUE*/) const
2168 {
2169  if (createDir) {
2170  R__LOCKGUARD(GetMakeClassMutex());
2171 
2172  gSystem->ExpandPathName(const_cast<THtml*>(this)->fPathInfo.fOutputDir);
2173  Long64_t sSize;
2174  Long_t sId, sFlags, sModtime;
2175  if (fPathInfo.fOutputDir.EndsWith("/") || fPathInfo.fOutputDir.EndsWith("\\"))
2176  fPathInfo.fOutputDir.Remove(fPathInfo.fOutputDir.Length() - 1);
2177  Int_t st = gSystem->GetPathInfo(fPathInfo.fOutputDir, &sId, &sSize, &sFlags, &sModtime);
2178  if (st || !(sFlags & 2)) {
2179  if (st == 0)
2180  Error("GetOutputDir", "output directory %s is an existing file",
2181  fPathInfo.fOutputDir.Data());
2182  else if (gSystem->MakeDirectory(fPathInfo.fOutputDir) == -1)
2183  Error("GetOutputDir", "output directory %s does not exist and can't create it", fPathInfo.fOutputDir.Data());
2184  }
2185  }
2186  return fPathInfo.fOutputDir;
2187 }
2188 
2189 ////////////////////////////////////////////////////////////////////////////////
2190 /// Check whether cl is a namespace
2191 
2192 Bool_t THtml::IsNamespace(const TClass*cl)
2193 {
2194  return (cl->Property() & kIsNamespace);
2195 }
2196 
2197 ////////////////////////////////////////////////////////////////////////////////
2198 /// Load all libraries known to ROOT via the rootmap system.
2199 
2200 void THtml::LoadAllLibs()
2201 {
2202  gSystem->LoadAllLibraries();
2203 }
2204 
2205 
2206 ////////////////////////////////////////////////////////////////////////////////
2207 /// Produce documentation for all the classes specified in the filter (by default "*")
2208 /// To process all classes having a name starting with XX, do:
2209 /// html.MakeAll(kFALSE,"XX*");
2210 /// If force=kFALSE (default), only the classes that have been modified since
2211 /// the previous call to this function will be generated.
2212 /// If force=kTRUE, all classes passing the filter will be processed.
2213 /// If numthreads is != -1, use numthreads threads, else decide automatically
2214 /// based on the number of CPUs.
2215 
2216 void THtml::MakeAll(Bool_t force, const char *filter, int numthreads /*= -1*/)
2217 {
2218  MakeIndex(filter);
2219 
2220  if (numthreads == 1) {
2221  // CreateListOfClasses(filter); already done by MakeIndex
2222  TClassDocInfo* classinfo = 0;
2223  TIter iClassInfo(&fDocEntityInfo.fClasses);
2224  UInt_t count = 0;
2225 
2226  while ((classinfo = (TClassDocInfo*)iClassInfo())) {
2227  if (!classinfo->IsSelected())
2228  continue;
2229  fCounter.Form("%5d", fDocEntityInfo.fClasses.GetSize() - count++);
2230  MakeClass(classinfo, force);
2231  }
2232  } else {
2233  if (numthreads == -1) {
2234  SysInfo_t sysinfo;
2235  gSystem->GetSysInfo(&sysinfo);
2236  numthreads = sysinfo.fCpus;
2237  if (numthreads < 1)
2238  numthreads = 2;
2239  }
2240  fThreadedClassCount = 0;
2241  fThreadedClassIter = new TIter(&fDocEntityInfo.fClasses);
2242  THtmlThreadInfo hti(this, force);
2243  if (!fMakeClassMutex && gGlobalMutex) {
2244  gGlobalMutex->Lock();
2245  fMakeClassMutex = gGlobalMutex->Factory(kTRUE);
2246  gGlobalMutex->UnLock();
2247  }
2248 
2249  TList threads;
2250  gSystem->Load("libThread");
2251  while (--numthreads >= 0) {
2252  TThread* thread = new TThread(MakeClassThreaded, &hti);
2253  thread->Run();
2254  threads.Add(thread);
2255  }
2256 
2257  TIter iThread(&threads);
2258  TThread* thread = 0;
2259  Bool_t wait = kTRUE;
2260  while (wait) {
2261  while (wait && (thread = (TThread*) iThread()))
2262  wait &= (thread->GetState() == TThread::kRunningState);
2263  gSystem->ProcessEvents();
2264  gSystem->Sleep(500);
2265  }
2266 
2267  iThread.Reset();
2268  while ((thread = (TThread*) iThread()))
2269  thread->Join();
2270  }
2271  fCounter.Remove(0);
2272 }
2273 
2274 
2275 ////////////////////////////////////////////////////////////////////////////////
2276 /// Make HTML files for a single class
2277 ///
2278 ///
2279 /// Input: className - name of the class to process
2280 ///
2281 
2282 void THtml::MakeClass(const char *className, Bool_t force)
2283 {
2284  CreateListOfClasses("*");
2285 
2286  TClassDocInfo* cdi = (TClassDocInfo*)fDocEntityInfo.fClasses.FindObject(className);
2287  if (!cdi) {
2288  if (!TClassEdit::IsStdClass(className)) // stl classes won't be available, so no warning
2289  Error("MakeClass", "Unknown class '%s'!", className);
2290  return;
2291  }
2292 
2293  MakeClass(cdi, force);
2294 }
2295 
2296 ////////////////////////////////////////////////////////////////////////////////
2297 /// Make HTML files for a single class
2298 ///
2299 ///
2300 /// Input: cdi - doc info for class to process
2301 ///
2302 
2303 void THtml::MakeClass(void *cdi_void, Bool_t force)
2304 {
2305  if (!fDocEntityInfo.fClasses.GetSize())
2306  CreateListOfClasses("*");
2307 
2308  TClassDocInfo* cdi = (TClassDocInfo*) cdi_void;
2309  TClass* currentClass = dynamic_cast<TClass*>(cdi->GetClass());
2310 
2311  if (!currentClass) {
2312  if (!cdi->GetClass() &&
2313  !TClassEdit::IsStdClass(cdi->GetName())) // stl classes won't be available, so no warning
2314  Error("MakeClass", "Class '%s' is known, but I cannot find its TClass object!", cdi->GetName());
2315  return;
2316  }
2317  TString htmlFile(cdi->GetHtmlFileName());
2318  if (htmlFile.Length()
2319  && (htmlFile.BeginsWith("http://")
2320  || htmlFile.BeginsWith("https://")
2321  || gSystem->IsAbsoluteFileName(htmlFile))
2322  ) {
2323  htmlFile.Remove(0);
2324  }
2325  if (htmlFile.Length()) {
2326  TClassDocOutput cdo(*this, currentClass, &cdi->GetListOfTypedefs());
2327  cdo.Class2Html(force);
2328  cdo.MakeTree(force);
2329  } else {
2330  TString what(cdi->GetName());
2331  what += " (sources not found)";
2332  Printf(fCounterFormat.Data(), "-skipped-", fCounter.Data(), what.Data());
2333  }
2334 }
2335 
2336 
2337 ////////////////////////////////////////////////////////////////////////////////
2338 /// Entry point of worker threads for multi-threaded MakeAll().
2339 /// info points to an (internal) THtmlThreadInfo object containing the current
2340 /// THtml object, and whether "force" was passed to MakeAll().
2341 /// The thread will poll GetNextClass() until no further class is available.
2342 
2343 void* THtml::MakeClassThreaded(void* info) {
2344  const THtmlThreadInfo* hti = (const THtmlThreadInfo*)info;
2345  if (!hti) return 0;
2346  TClassDocInfo* classinfo = 0;
2347  while ((classinfo = hti->GetHtml()->GetNextClass()))
2348  hti->GetHtml()->MakeClass(classinfo, hti->GetForce());
2349 
2350  return 0;
2351 }
2352 
2353 ////////////////////////////////////////////////////////////////////////////////
2354 /// Create the index files for the product, modules, all types, etc.
2355 /// By default all classes are indexed (if filter="*");
2356 /// to generate an index for all classes starting with "XX", do
2357 /// html.MakeIndex("XX*");
2358 
2359 void THtml::MakeIndex(const char *filter)
2360 {
2361  CreateListOfClasses(filter);
2362 
2363  TDocOutput output(*this);
2364  // create indices
2365  output.CreateTypeIndex();
2366  output.CreateClassTypeDefs();
2367  output.CreateModuleIndex();
2368  output.CreateClassIndex();
2369  output.CreateProductIndex();
2370 
2371  // create a class hierarchy
2372  output.CreateHierarchy();
2373 }
2374 
2375 
2376 ////////////////////////////////////////////////////////////////////////////////
2377 /// Make an inheritance tree
2378 ///
2379 ///
2380 /// Input: className - name of the class to process
2381 ///
2382 
2383 void THtml::MakeTree(const char *className, Bool_t force)
2384 {
2385  // create canvas & set fill color
2386  TClass *classPtr = GetClass(className);
2387 
2388  if (!classPtr) {
2389  Error("MakeTree", "Unknown class '%s' !", className);
2390  return;
2391  }
2392 
2393  TClassDocOutput cdo(*this, classPtr, 0);
2394  cdo.MakeTree(force);
2395 }
2396 
2397 ////////////////////////////////////////////////////////////////////////////////
2398 /// Set whether "dot" (a GraphViz utility) is available
2399 
2400 void THtml::SetFoundDot(Bool_t found) {
2401  if (found) fPathInfo.fFoundDot = PathInfo_t::kDotFound;
2402  else fPathInfo.fFoundDot = PathInfo_t::kDotNotFound;
2403 }
2404 
2405 ////////////////////////////////////////////////////////////////////////////////
2406 /// Fill the files available in the file system below fPathInfo.fInputPath
2407 
2408 void THtml::SetLocalFiles() const
2409 {
2410  if (fLocalFiles) delete fLocalFiles;
2411  fLocalFiles = new TFileSysDB(fPathInfo.fInputPath, fPathInfo.fIgnorePath + "|(\\b" + GetOutputDir(kFALSE) + "\\b)" , 6);
2412 }
2413 
2414 ////////////////////////////////////////////////////////////////////////////////
2415 /// Set the module defining object to be used; can also be a user derived
2416 /// object (a la traits).
2417 
2418 void THtml::SetModuleDefinition(const TModuleDefinition& md)
2419 {
2420  delete fModuleDef;
2421  fModuleDef = (TModuleDefinition*) md.Clone();
2422  fModuleDef->SetOwner(const_cast<THtml*>(this));
2423 }
2424 
2425 
2426 ////////////////////////////////////////////////////////////////////////////////
2427 /// Set the file defining object to be used; can also be a user derived
2428 /// object (a la traits).
2429 
2430 void THtml::SetFileDefinition(const TFileDefinition& md)
2431 {
2432  delete fFileDef;
2433  fFileDef = (TFileDefinition*) md.Clone();
2434  fFileDef->SetOwner(const_cast<THtml*>(this));
2435 }
2436 
2437 
2438 ////////////////////////////////////////////////////////////////////////////////
2439 /// Set the path defining object to be used; can also be a user derived
2440 /// object (a la traits).
2441 
2442 void THtml::SetPathDefinition(const TPathDefinition& md)
2443 {
2444  delete fPathDef;
2445  fPathDef = (TPathDefinition*) md.Clone();
2446  fPathDef->SetOwner(const_cast<THtml*>(this));
2447 }
2448 
2449 
2450 ////////////////////////////////////////////////////////////////////////////////
2451 /// Set the directory containing the source files.
2452 /// The source file for a class MyClass will be searched
2453 /// by prepending dir to the value of
2454 /// MyClass::Class()->GetImplFileName() - which can contain
2455 /// directory information!
2456 /// Also resets the class structure, in case new files can
2457 /// be found after this call.
2458 
2459 void THtml::SetInputDir(const char *dir)
2460 {
2461  fPathInfo.fInputPath = dir;
2462  gSystem->ExpandPathName(fPathInfo.fInputPath);
2463 
2464  // reset class table
2465  fDocEntityInfo.fClasses.Clear();
2466  fDocEntityInfo.fModules.Clear();
2467 }
2468 
2469 ////////////////////////////////////////////////////////////////////////////////
2470 /// Set the directory where the HTML pages shuold be written to.
2471 /// If the directory does not exist it will be created when needed.
2472 
2473 void THtml::SetOutputDir(const char *dir)
2474 {
2475  fPathInfo.fOutputDir = dir;
2476 #ifdef R__WIN32
2477  fPathInfo.fOutputDir.ReplaceAll("/","\\");
2478 #endif
2479 }
2480 
2481 ////////////////////////////////////////////////////////////////////////////////
2482 /// Explicitly set a decl file name for TClass cl.
2483 
2484 void THtml::SetDeclFileName(TClass* cl, const char* filename)
2485 {
2486  TClassDocInfo* cdi = (TClassDocInfo*) fDocEntityInfo.fClasses.FindObject(cl->GetName());
2487  if (!cdi) {
2488  cdi = new TClassDocInfo(cl, "" /*html*/, "" /*fsdecl*/, "" /*fsimpl*/, filename);
2489  fDocEntityInfo.fClasses.Add(cdi);
2490  } else
2491  cdi->SetDeclFileName(filename);
2492 }
2493 
2494 ////////////////////////////////////////////////////////////////////////////////
2495 /// Explicitly set a impl file name for TClass cl.
2496 
2497 void THtml::SetImplFileName(TClass* cl, const char* filename)
2498 {
2499  TClassDocInfo* cdi = (TClassDocInfo*) fDocEntityInfo.fClasses.FindObject(cl->GetName());
2500  if (!cdi) {
2501  cdi = new TClassDocInfo(cl, "" /*html*/, "" /*fsdecl*/, "" /*fsimpl*/, 0 /*decl*/, filename);
2502  fDocEntityInfo.fClasses.Add(cdi);
2503  } else
2504  cdi->SetImplFileName(filename);
2505 }
2506 
2507 ////////////////////////////////////////////////////////////////////////////////
2508 /// Get short type name, i.e. with default templates removed.
2509 
2510 const char* THtml::ShortType(const char* name) const
2511 {
2512  const char* tmplt = strchr(name, '<');
2513  if (!tmplt) return name;
2514  tmplt = strrchr(tmplt, ':');
2515  if (tmplt > name && tmplt[-1] == ':') {
2516  // work-around for CINT bug: template instantiation can produce bogus
2517  // typedefs e.g. in namespace ROOT::Math::ROOT::Math instead of ROOT::Math.
2518  TString namesp(name, tmplt - name - 1);
2519  // is the enclosing namespace known?
2520  if (!GetClass(namesp)) return name;
2521  }
2522  TObject* scn = fDocEntityInfo.fShortClassNames.FindObject(name);
2523  if (!scn) {
2524  scn = new TNamed(name, TClassEdit::ShortType(name, 1<<7));
2525  fDocEntityInfo.fShortClassNames.Add(scn);
2526  }
2527  return scn->GetTitle();
2528 }