22 void scandir(THtml& html,
const char *dir,
const char *title, TObjLink* toplnk);
25 void AppendLink(TString& links,
int id,
const TNamed* n)
33 static const char* tag[] = {
"<",
"^",
">"};
34 static const char* name[] = {
"prev",
"up",
"next"};
35 static const TNamed emptyName;
38 TString arrowid(
"contextheadarrow_"); arrowid += name[id];
39 TString entryid(
"contextheadentry_"); entryid += name[id];
40 TString ardivid(
"divcontextheadar_"); ardivid += name[id];
41 if (!n) n = &emptyName;
46 if (
id != 1) title = n->GetName();
47 if (title.Length()) title +=
": ";
48 title += n->GetTitle();
49 const char* mytag = tag[id];
51 if (!n->GetName()[0]) mytag =
"";
53 TString arrow = TString::Format(
"<td id=\"%s\"><div id=\"%s\">"
54 "<a class=\"contextheadarrow\" href=\"%s.html\">%s</a></div></td>",
55 arrowid.Data(), ardivid.Data(), n->GetName(), mytag);
57 TString entry = TString::Format(
"<td class=\"contextheadentry\" id=\"%s\">"
58 "<a class=\"contextheadentry\" href=\"%s.html\">%s</a></td>",
59 entryid.Data(), n->GetName(), title.Data());
62 links += entry + arrow;
64 links += arrow + entry;
68 void MakeTopLinks(TString &links,
const char* name,
const char* title,
const char* upLink,
const char* upTitle,
69 TObjLink *lnk,
const char* dir)
80 links =
"<div id=\"toplinks\"><div class=\"descrhead\">"
81 "<table class=\"descrtitle\" id=\"contexttitle\"><tr class=\"descrtitle\">";
82 TObjLink *prevlnk = lnk ? lnk->Prev() : 0;
83 TObjLink *nextlnk = lnk ? lnk->Next() : 0;
85 TNamed* prevname = prevlnk ? (TNamed*)prevlnk->GetObject() : 0;
86 AppendLink(links, 0, prevname);
89 if (upLink && upLink[0])
90 upname.SetNameTitle(upLink, upTitle);
91 AppendLink(links, 1, &upname);
93 TNamed* nextname = nextlnk ? (TNamed*)nextlnk->GetObject() : 0;
94 AppendLink(links, 2, nextname);
96 links += TString(
"</tr></table></div><h1 class=\"convert\">") + title +
"</h1></div>\n";
98 TString subtitle = dir;
100 if (!subtitle.EndsWith(
"/")) {
103 subtitle += TString(name);
104 suburl = subtitle +
"?view=markup";
106 links += TString::Format(
"<div class=\"location\"><h2>From <a href=\"http://root.cern.ch/viewvc/trunk/tutorials/%s\">$ROOTSYS/tutorials/%s</a></h2></div>",
107 suburl.Data(), subtitle.Data());
110 void writeHeader(THtml& html, ostream& out,
const char *title,
const char* relPath=
"../") {
118 TDocOutput docout(html);
119 docout.WriteHtmlHeader(out, title, relPath);
122 void writeTrailer(THtml& html, ostream& out) {
127 TDocOutput docout(html);
128 docout.WriteHtmlFooter(out);
131 void writeItem(ostream& out, Int_t numb,
const char *ref,
const char *name,
const char *title, Bool_t isnew) {
138 const char *imagenew =
"";
139 cout <<
"writingItem: " << numb <<
", ref=" << ref <<
", name=" << name <<
", title=" << title << endl;
140 if (isnew) imagenew =
" <img src=\"http://root.cern.ch/root/images/new01.gif\" alt=\"new\" align=\"top\" />";
141 out <<
"<li class=\"idxl" << numb%2 <<
"\">";
142 out <<
"<a href=\"" << ref <<
"\"><span class=\"typename\">" << numb <<
". " << name <<
"</span></a> "
143 << title << imagenew <<
"</li>" << endl;
146 void writeItemDir(THtml& html, ostream& out, TObjLink* lnk) {
156 const char *dir = lnk->GetObject()->GetName();
157 const char *title = lnk->GetObject()->GetTitle();
158 out <<
"<li class=\"idxl" << (n++)%2 <<
"\"><a href=\"" << dir <<
"/index.html\">"
159 <<
"<span class=\"typename\">" << dir <<
"</span></a>" << title <<
"</li>" << endl;
161 scandir(html, dir, title, lnk);
164 void writeTutorials(THtml& html) {
173 const char* tutorials[][2] = {
174 {
"hist",
"Histograms"},
175 {
"graphics",
"Basic Graphics"},
176 {
"graphs",
"TGraph, TGraphErrors, etc"},
177 {
"gui",
"Graphics User Interface"},
178 {
"fit",
"Fitting tutorials"},
179 {
"fitsio",
"CFITSIO interface"},
180 {
"io",
"Input/Output"},
181 {
"tree",
"Trees I/O, Queries, Graphics"},
182 {
"math",
"Math tutorials"},
183 {
"matrix",
"Matrix packages tutorials"},
184 {
"geom",
"Geometry package"},
185 {
"gl",
"OpenGL examples"},
186 {
"eve",
"Event Display"},
187 {
"fft",
"Fast Fourier Transforms"},
188 {
"foam",
"TFoam example"},
189 {
"image",
"Image Processing"},
190 {
"mlp",
"Neural Networks"},
191 {
"net",
"Network, Client/server"},
192 {
"physics",
"Physics misc"},
193 {
"proof",
"PROOF tutorials"},
194 {
"pyroot",
"Python-ROOT"},
195 {
"pythia",
"Pythia event generator"},
196 {
"quadp",
"Quadratic Programming package"},
197 {
"roofit",
"RooFit tutorials"},
198 {
"roostats",
"Roostats tutorials"},
199 {
"spectrum",
"Peak Finder, Deconvolutions"},
200 {
"splot",
"TSPlot example"},
201 {
"sql",
"SQL Data Bases interfaces"},
202 {
"thread",
"Multi-Threading examples"},
203 {
"unuran",
"The Unuran package"},
204 {
"xml",
"XML tools"},
209 ofstream fptop(
"htmldoc/tutorials/index.html");
210 writeHeader(html, fptop,
"ROOT Tutorials");
212 MakeTopLinks(topLinks, 0,
"ROOT Tutorials",
"../index",
"ROOT", 0,
"");
213 fptop << topLinks << endl;
214 fptop <<
"<ul id=\"indx\">" << endl;
222 TNamed curr(tutorials[0][0], tutorials[0][1]);
223 TNamed next(tutorials[1][0], tutorials[1][1]);
224 contextList.AddLast(&prev);
225 contextList.AddLast(&curr);
226 contextList.AddLast(&next);
227 TObjLink* lnk = contextList.FirstLink();
229 const char** iTut = tutorials[2];
231 writeItemDir(html, fptop, lnk);
234 next.SetNameTitle(iTut[0], iTut[1]);
239 fptop <<
"</ul>" << endl;
240 fptop <<
"<p><a href=\"http://root.cern.ch/drupal/content/downloading-root\">Download ROOT</a> and run the tutorials in $ROOTSYS/tutorials yourself!</p>" << endl;
241 writeTrailer(html, fptop);
244 void GetMacroTitle(
const char *fullpath, TString &comment, Bool_t &compile) {
251 FILE *fp = fopen(fullpath,
"r");
254 while (fgets(line,240,fp)) {
256 char *com = strstr(line,
"//");
258 if (strstr(line,
"Author"))
continue;
259 if (strstr(line,
"@(#)"))
continue;
260 if (strstr(line,
"****"))
continue;
261 if (strstr(line,
"////"))
continue;
262 if (strstr(line,
"===="))
continue;
263 if (strstr(line,
"...."))
continue;
264 if (strstr(line,
"----"))
continue;
265 if (strstr(line,
"____"))
continue;
266 if (strlen(com+1) < 5)
continue;
267 if (!strncmp(com,
"//+ ", 4)) {
274 if (nlines > 50)
break;
279 Bool_t IsNew(
const char *filename) {
281 gSystem->Exec(Form(
"svn info %s > MakeTutorials-tmp.log",filename));
282 FILE *fpdate = fopen(
"MakeTutorials-tmp.log",
"r");
284 Bool_t isnew = kFALSE;
286 Int_t now = 365*(today.GetYear()-1)+12*(today.GetMonth()-1) + today.GetDay();
287 Int_t year,month,day;
288 while (fgets(line,240,fpdate)) {
289 const char *com = strstr(line,
"Last Changed Date: ");
291 sscanf(&com[19],
"%d-%d-%d",&year,&month,&day);
292 Int_t filedate = 365*(year-1) + 12*(month-1) + day;
293 if (now-filedate< 6*30) isnew = kTRUE;
298 gSystem->Unlink(
"MakeTutorials-tmp.log");
302 Bool_t CreateOutput_Dir(
const char* dir) {
306 if (strstr(dir,
"net"))
return kFALSE;
307 if (strstr(dir,
"xml"))
return kFALSE;
308 if (strstr(dir,
"sql"))
return kFALSE;
309 if (strstr(dir,
"proof"))
return kFALSE;
310 if (strstr(dir,
"foam"))
return kFALSE;
311 if (strstr(dir,
"unuran"))
return kFALSE;
312 if (strstr(dir,
"roofit"))
return kFALSE;
313 if (strstr(dir,
"thread"))
return kFALSE;
316 Bool_t CreateOutput_Tutorial(
const char* tut) {
320 static const char* vetoed[] = {
332 "rs401d_FeldmanCousins",
333 "graph_edit_playback",
341 for (
const char** iVetoed = vetoed; *iVetoed; ++iVetoed)
342 if (strstr(tut, *iVetoed))
348 void scandir(THtml& html,
const char *dir,
const char *title, TObjLink* toplnk) {
352 TString fullpath(
"htmldoc/tutorials/");
354 if (!gSystem->OpenDirectory(fullpath)) gSystem->MakeDirectory(fullpath);
355 fullpath +=
"/index.html";
357 ofstream fpind(fullpath);
358 writeHeader(html, fpind, title,
"../../");
362 MakeTopLinks(topLinks, 0, title,
".",
"ROOT Tutorials", toplnk, dir);
365 topLinks.ReplaceAll(
"href=\"",
"href=\"../");
366 topLinks.ReplaceAll(
"href=\"../http://",
"href=\"http://");
367 topLinks.ReplaceAll(
"href=\"../https://",
"href=\"https://");
368 topLinks.ReplaceAll(
".html\"",
"/index.html\"");
370 topLinks.ReplaceAll(
"<h1 class=\"convert\">",
"<h1 class=\"convert\">ROOT Tutorials: ");
371 fpind << topLinks << endl;
372 fpind <<
"<ul id=\"indx\">" << endl;
374 TString outpath(
"htmldoc/tutorials/");
376 TString inpath(
"$ROOTSYS/tutorials/");
379 gSystem->ExpandPathName(inpath);
380 void *thedir = gSystem->OpenDirectory(inpath);
382 printf(
"MakeTutorials.C: error opening directory %s", inpath.Data());
385 const char *direntry;
387 while ((direntry = gSystem->GetDirEntry(thedir))) {
388 if(*direntry ==
'.')
continue;
389 const char *CC = strstr(direntry,
".C");
391 if (!CC || *(CC+2))
continue;
393 if(strstr(direntry,
"h1anal"))
continue;
394 if(strstr(direntry,
"hsimpleProxy"))
continue;
395 if(strstr(direntry,
"tv3"))
continue;
396 if(strstr(direntry,
"tvdemo"))
continue;
397 if(strstr(direntry,
"na49"))
continue;
398 if(strstr(direntry,
"fit1_C"))
continue;
399 if(strstr(direntry,
"c1.C"))
continue;
400 if(strstr(direntry,
"MDF.C"))
continue;
401 if(strstr(direntry,
"cms_calo_detail"))
continue;
402 TString atut(inpath + direntry);
405 GetMacroTitle(atut,comment, compile);
406 TNamed *named =
new TNamed(direntry,comment.Data());
407 if (compile) named->SetBit(BIT(14));
412 TObjLink *lnk = h.FirstLink();
414 TNamed* named = (TNamed*)lnk->GetObject();
415 Bool_t compile = named->TestBit(BIT(14));
416 direntry = named->GetName();
417 TString atut(inpath + direntry);
419 TString iname(direntry);
421 writeItem(fpind, numb, iname, direntry, named->GetTitle(), IsNew(atut));
422 Int_t includeOutput = THtml::kNoOutput;
423 if (!gROOT->IsBatch()) {
425 includeOutput = THtml::kCompiledOutput;
427 includeOutput = THtml::kInterpretedOutput;
428 includeOutput |= THtml::kSeparateProcessOutput;
430 if (!CreateOutput_Dir(dir) || !CreateOutput_Tutorial(direntry))
431 includeOutput = THtml::kNoOutput;
434 TString tutTitle(named->GetName());
436 tutTitle += named->GetTitle();
437 MakeTopLinks(links,named->GetName(),tutTitle,
"index",title,lnk, dir);
438 html.Convert(atut,named->GetTitle(),outpath,
"../../",includeOutput,links);
439 gROOT->GetListOfCanvases()->Delete();
441 gROOT->GetListOfFunctions()->Delete();
442 gROOT->GetListOfBrowsers()->Delete();
443 gROOT->GetListOfGeometries()->Delete();
447 TStyle::BuildStyles();
448 gROOT->SetStyle(
"Default");
451 fpind <<
"</ul>" << endl;
452 writeTrailer(html, fpind);
455 void MakeTutorials() {
459 if (!gSystem->OpenDirectory(
"htmldoc")) gSystem->MakeDirectory(
"htmldoc");
460 if (!gSystem->OpenDirectory(
"htmldoc/tutorials")) gSystem->MakeDirectory(
"htmldoc/tutorials");
461 gEnv->SetValue(
"Unix.*.Root.Html.SourceDir",
"$(ROOTSYS)");
462 gEnv->SetValue(
"Root.Html.ViewCVS",
"http://root.cern.ch/viewcvs/trunk/%f?view=log");
463 gEnv->SetValue(
"Root.Html.Search",
"http://www.google.com/search?q=%s+site%3A%u");
467 html.CreateAuxiliaryFiles();
468 writeTutorials(html);